5 * by JH <jheinonen@users.sourceforge.net>
7 * Copyright (C) Jaakko Heinonen
25 int first_list_item = -1;
26 char *selected = NULL;
28 int extra_column = -1;
29 int extra_alternative = -1;
32 extern abook_field_list *fields_list;
34 static WINDOW *list = NULL;
38 init_extra_field(enum str_opts option)
43 option_str = opt_get_str(option);
45 if(option_str && *option_str) {
46 find_field_number(option_str, &ret);
48 if(!strcmp(option_str, "name") || !strcmp(option_str, "email"))
58 list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
62 * init extra_column and extra alternative
65 extra_column = init_extra_field(STR_EXTRA_COLUMN);
66 extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE);
83 ui_print_number_of_items();
94 if(first_list_item < 0)
97 if(curitem < first_list_item)
98 first_list_item = curitem;
99 else if(curitem > LAST_LIST_ITEM)
100 first_list_item = max(curitem - LIST_LINES + 1, 0);
102 for( line = 0, i = first_list_item ; i <= LAST_LIST_ITEM && i < items;
105 print_list_line(i, line, i == curitem);
108 if(opt_get_bool(BOOL_SHOW_CURSOR)) {
109 wmove(list, curitem - first_list_item, 0);
110 /* need to call refresh() to update the cursor positions */
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, db_name_get(i),
132 bytes2width(db_name_get(i), NAMELEN));
134 if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
135 mvwaddnstr(list, line, EMAILPOS, db_email_get(i),
136 bytes2width(db_email_get(i), real_emaillen));
138 get_first_email(tmp, i);
139 mvwaddnstr(list, line, EMAILPOS, tmp,
140 bytes2width(tmp, real_emaillen));
143 if(extra < 0 || !db_fget_byid(i, extra))
144 extra = extra_alternative;
146 mvwaddnstr(list, line, EXTRAPOS,
147 safe_str(db_fget_byid(i, extra)),
148 bytes2width(safe_str(db_fget_byid(i, extra)),
151 scrollok(list, TRUE);
161 #if defined(A_BOLD) && defined(A_NORMAL)
165 mvaddstr(2, NAMEPOS, find_field("name", NULL)->name);
166 mvaddstr(2, EMAILPOS, find_field("email", NULL)->name);
167 if(extra_column > 0) {
168 get_field_keyname(extra_column, NULL, &str);
169 mvaddnstr(2, EXTRAPOS, str, COLS - EXTRAPOS);
172 #if defined(A_BOLD) && defined(A_NORMAL)
191 if(curitem > items - 2)
206 curitem = curitem == first_list_item ?
207 ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
215 if(curitem > items - 2)
218 curitem = curitem == LAST_LIST_ITEM ?
219 ((curitem += LIST_LINES) > LAST_ITEM ? LAST_ITEM : curitem) :
220 min(LAST_LIST_ITEM, LAST_ITEM);
228 memset(selected, 0, items);
234 memset(selected, 1, items);
238 move_curitem(int direction)
242 if( curitem < 0 || curitem > LAST_ITEM )
246 item_copy(tmp, db_item_get(curitem));
252 item_copy(db_item_get(curitem),
253 db_item_get(curitem - 1));
254 item_copy(db_item_get(curitem-1), tmp);
259 if( curitem >= LAST_ITEM )
261 item_copy(db_item_get(curitem),
262 db_item_get(curitem + 1));
263 item_copy(db_item_get(curitem + 1), tmp);
291 highlight_line(WINDOW *win, int line)
296 * this is a tricky one
300 mvwchgat(win, line, 0, -1, A_STANDOUT, 0, NULL);
303 * buggy function: FIXME
305 scrollok(win, FALSE);
309 for(i = 0; i < COLS; i++)
311 /*wattrset(win, 0);*/
322 for(i = 0; i < items; i++)
337 for(i = 0; i < items; i++)
338 selected[i] = !selected[i];
361 item = item_create();
362 item_duplicate(item, db_item_get(curitem));
363 if(add_item2database(item)) {