5 * by JH <jheinonen@users.sourceforge.net>
7 * Copyright (C) Jaakko Heinonen
21 #define MIN_EXTRA_COLUMN ADDRESS /* 2 */
22 #define MAX_EXTRA_COLUMN LAST_FIELD
25 int first_list_item = -1;
26 char *selected = NULL;
28 int extra_column = -1;
29 int extra_alternative = -1;
32 extern list_item *database;
33 extern struct abook_field abook_fields[];
38 init_extra_field(enum str_opts option)
43 option_str = opt_get_str(option);
45 if(option_str && *option_str) {
46 for(i = 0; i < ITEM_FIELDS; i++) {
47 if(!strcasecmp(option_str, abook_fields[i].key)) {
52 if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) {
63 list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
67 * init extra_column and extra alternative
70 extra_column = init_extra_field(STR_EXTRA_COLUMN);
71 extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE);
88 ui_print_number_of_items();
99 if(first_list_item < 0)
102 if(curitem < first_list_item)
103 first_list_item = curitem;
104 else if(curitem > LAST_LIST_ITEM)
105 first_list_item = max(curitem - LIST_LINES + 1, 0);
107 for( line = 0, i = first_list_item ; i <= LAST_LIST_ITEM && i < items;
110 print_list_line(i, line, i == curitem);
117 print_list_line(int i, int line, int highlight)
119 int extra = extra_column;
120 char tmp[MAX_EMAILSTR_LEN];
121 int real_emaillen = (extra_column > 0 || extra_alternative > 0) ?
122 EMAILLEN : COLS - EMAILPOS;
124 scrollok(list, FALSE);
126 highlight_line(list, line);
129 mvwaddch(list, line, 0, '*' );
131 mvwaddnstr(list, line, NAMEPOS, database[i][NAME], NAMELEN);
132 if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
133 mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL],
136 get_first_email(tmp, i);
137 mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen);
140 if(extra < 0 || !database[i][extra])
141 extra = extra_alternative;
143 mvwaddnstr(list, line, EXTRAPOS,
144 safe_str(database[i][extra]),
147 scrollok(list, TRUE);
159 /* hmm, maybe something here */
161 mvaddstr(2, NAMEPOS, abook_fields[NAME].name);
162 mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name);
164 mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name,
185 if(curitem > items - 2)
200 curitem = curitem == first_list_item ?
201 ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
209 if(curitem > items - 2)
212 curitem = curitem == LAST_LIST_ITEM ?
213 ((curitem += LIST_LINES) > LAST_ITEM ? LAST_ITEM : curitem) :
214 min(LAST_LIST_ITEM, LAST_ITEM);
223 memset(selected, 0, items);
229 memset(selected, 1, items);
233 move_curitem(int direction)
237 if( curitem < 0 || curitem > LAST_ITEM )
240 itemcpy(tmp, database[curitem]);
246 itemcpy(database[curitem], database[curitem - 1]);
247 itemcpy(database[curitem-1], tmp);
252 if( curitem >= LAST_ITEM )
254 itemcpy(database[curitem], database[curitem + 1]);
255 itemcpy(database[curitem+1], tmp);
281 highlight_line(WINDOW *win, int line)
286 * this is a tricky one
290 mvwchgat(win, line, 0, -1, A_STANDOUT, 0, NULL);
293 * buggy function: FIXME
295 scrollok(win, FALSE);
299 for(i = 0; i < COLS; i++)
301 /*wattrset(win, 0);*/
312 for(i = 0; i < items; i++)
327 for(i = 0; i < items; i++)
328 selected[i] = !selected[i];