#include "dialog.h"
static int menu_width, item_x;
+static int info_width;
/*
* Print menu item
wrefresh(win);
}
+#define MAX_LIST_NUM 8192
+#define MAX_STR_NUM 256
+
+struct list_entry{
+ int pack_num;
+ int installed_size;
+ int packed_size;
+ int scroll;
+ char list[MAX_LIST_NUM][MAX_STR_NUM]
+};
+
+struct list_entry installed_list;
+
+static int init_installed_list()
+{
+ int i;
+ installed_list.pack_num = 0;
+ installed_list.scroll = 0;
+ installed_list.installed_size = 0;
+ installed_list.packed_size = 0;
+
+ for( i = 0 ; i < MAX_LIST_NUM ; i++ )
+ {
+ memset(&(installed_list.list[i][0]), 0, MAX_STR_NUM);
+ }
+ return 0;
+}
+
+static int read_data()
+{
+ FILE *fp;
+ int i = 0;
+ int flag = 0;
+
+ init_installed_list();
+ fp = fopen("installed_list.txt", "r");
+ if( fp == NULL ) return -1;
+
+ while(i < MAX_LIST_NUM && fgets(installed_list.list[i++],MAX_STR_NUM, fp));
+ installed_list.pack_num = i-1;
+ fclose(fp);
+
+ for ( i = installed_list.pack_num -1 ; i > 0 ; i --)
+ {
+ if((flag & 0x0f) == 0 && strstr(&(installed_list.list[i][0]), "Installed Size : "))
+ {
+ sscanf(&(installed_list.list[i][0]), "Installed Size : %d", &(installed_list.installed_size));
+ flag |= 0x0f;
+ }
+ if((flag & 0xf0) == 0 && strstr(&(installed_list.list[i][0]), "Size : "))
+ {
+ sscanf(&(installed_list.list[i][0]), "Size : %d", &(installed_list.packed_size));
+ flag |= 0xf0;
+ }
+ if( flag == 0xff)
+ {
+ break;
+ }
+ }
+ installed_list.pack_num -= 2;
+
+ return 0;
+}
+
+static void print_list(WINDOW *win, int start, int max)
+{
+ int i;
+ int pack_num = installed_list.pack_num;
+
+ for ( i = 0 ; i < max ; i++ )
+ {
+ wrefresh(win);
+ }
+
+ for ( i = 0 ; i < max && i < pack_num - start ; i++ )
+ {
+ wmove(win, i, 0);
+ wclrtoeol(win);
+ mvwaddnstr(win, i, 0, installed_list.list[start+i], strlen(installed_list.list[start+i])-1);
+ wrefresh(win);
+ }
+ for ( ; i < max ; i++)
+ {
+ wmove(win, i, 0);
+ wclrtoeol(win);
+ wrefresh(win);
+ }
+
+ return;
+}
+
+static void print_info(WINDOW *win)
+{
+ char mesg[256];
+
+ sprintf(mesg, "Package Num : %d", installed_list.pack_num);
+ wmove(win, 0, 0);
+ mvwaddnstr(win, 0, 0, mesg, strlen(mesg));
+ sprintf(mesg, "Installed Size : %d", installed_list.installed_size);
+ wmove(win, 1, 0);
+ mvwaddnstr(win, 1, 0, mesg, strlen(mesg));
+ sprintf(mesg, "Packed Size : %d", installed_list.packed_size);
+ wmove(win, 2, 0);
+ mvwaddnstr(win, 2, 0, mesg, strlen(mesg));
+
+ return;
+}
+
/*
* Display a menu for choosing among a number of options
*/
int height, width, menu_height;
int key = 0, button = 0, scroll = 0, choice = 0;
int first_item = 0, max_choice;
- WINDOW *dialog, *menu;
+ WINDOW *dialog, *menu, *info, *list;
+ int info_width, info_height;
do_resize:
height = getmaxy(stdscr);
wattrset(dialog, dlg.dialog.atr);
print_autowrap(dialog, prompt, width - 2, 1, 3);
- menu_width = width - 6;
+ info_width = width * 2 / 5;
+ info_height = 5;
+ menu_width = width - 6 - info_width;
box_y = height - menu_height - 5;
+#if 0
box_x = (width - menu_width) / 2 - 1;
+#else
+ box_x = 2;
+#endif
+
+ read_data();
+#if 1
+ int info_x, info_y;
+ int installed_size = 1024*1024;
+ int packed_size = installed_size / 2;
+ int pack_num = 100;
+
+ info_y = height - menu_height - 5;
+ info_x = menu_width + 4;
+
+ /* info menu box */
+ info = subwin(dialog, info_height, info_width,
+ y + info_y + 1, x + info_x + 1);
+ /* draw a box around the menu items */
+ draw_box(dialog, info_y, info_x, info_height, info_width,
+ dlg.menubox_border.atr, dlg.menubox.atr);
+
+ print_info(info);
+
+ /* list menu box */
+ info_width = width * 2 / 5 - 2;
+ info_height = menu_height - 5;
+
+ info_y += 5;
+ info_x = menu_width + 4;
+
+ /* info menu & list menu*/
+ list = subwin(dialog, info_height, info_width,
+ y + info_y + 1, x + info_x + 1);
+ /* draw a box around the menu items */
+ draw_box(dialog, info_y, info_x, info_height+2, info_width + 2,
+ dlg.menubox_border.atr, dlg.menubox.atr);
+
+ print_list(list, installed_list.scroll, info_height);
+#endif
/* create new window for the menu */
menu = subwin(dialog, menu_height, menu_width,
}
}
+ if(key == KEY_SRIGHT)
+ {
+ if(installed_list.scroll < installed_list.pack_num - info_height )
+ {
+ installed_list.scroll++;
+ }
+ }
+ else if(key == KEY_SLEFT)
+ {
+ if(installed_list.scroll > 0)
+ {
+ installed_list.scroll--;
+ }
+ }
+ else if(key == KEY_HOME)
+ {
+ installed_list.scroll = 0;;
+ }
+ else if(key == KEY_END)
+ {
+ installed_list.scroll = installed_list.pack_num - info_height;;
+ }
+ else if(key == KEY_SHOME)
+ {
+ if( 0 < installed_list.scroll - info_height )
+ installed_list.scroll -= info_height;
+ else
+ installed_list.scroll = 0;
+
+ }
+ else if(key == KEY_SEND)
+ {
+ if( installed_list.pack_num > installed_list.scroll + (2 *info_height) )
+ installed_list.scroll += info_height;
+ else
+ installed_list.scroll = installed_list.pack_num - info_height;
+ }
+
+
+ print_list(list, installed_list.scroll, info_height);
+
if (item_count() != 0 &&
(i < max_choice ||
key == KEY_UP || key == KEY_DOWN ||
}
}
delwin(menu);
+ delwin(list);
+ delwin(info);
delwin(dialog);
return key; /* ESC pressed */
}