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;
31 extern abook_field_list *fields_list;
33 static WINDOW *list = NULL;
37 init_extra_field(enum str_opts option)
42 option_str = opt_get_str(option);
44 if(option_str && *option_str) {
45 find_field_number(option_str, &ret);
47 if(!strcmp(option_str, "name") || !strcmp(option_str, "email"))
57 list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
61 * init extra_column and extra alternative
64 extra_column = init_extra_field(STR_EXTRA_COLUMN);
65 extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE);
82 ui_print_number_of_items();
93 if(first_list_item < 0)
96 if(curitem < first_list_item)
97 first_list_item = curitem;
98 else if(curitem > LAST_LIST_ITEM)
99 first_list_item = max(curitem - LIST_LINES + 1, 0);
101 for(line = 0, i = first_list_item;
102 i <= LAST_LIST_ITEM && i < db_n_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 > db_n_items() - 2)
206 curitem = curitem == first_list_item ?
207 ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
215 if(curitem > db_n_items() - 2)
218 if(curitem == LAST_LIST_ITEM) {
219 if((curitem += LIST_LINES) > last_item())
220 curitem = last_item();
222 curitem = min(LAST_LIST_ITEM, last_item());
231 memset(selected, 0, db_n_items());
237 memset(selected, 1, db_n_items());
241 list_set_selection(int item, int value)
243 assert(is_valid_item(item));
245 selected[item] = !!value;
249 list_invert_curitem_selection()
251 assert(is_valid_item(curitem));
253 selected[curitem] = !selected[curitem];
257 move_curitem(int direction)
261 if(curitem < 0 || curitem > last_item())
265 item_copy(tmp, db_item_get(curitem));
271 item_copy(db_item_get(curitem),
272 db_item_get(curitem - 1));
273 item_copy(db_item_get(curitem-1), tmp);
278 if(curitem >= last_item())
280 item_copy(db_item_get(curitem),
281 db_item_get(curitem + 1));
282 item_copy(db_item_get(curitem + 1), tmp);
304 curitem = last_item();
310 highlight_line(WINDOW *win, int line)
315 * this is a tricky one
319 mvwchgat(win, line, 0, -1, A_STANDOUT, 0, NULL);
322 * buggy function: FIXME
324 scrollok(win, FALSE);
328 for(i = 0; i < COLS; i++)
330 /*wattrset(win, 0);*/
341 for(i = 0; i < db_n_items(); i++)
356 for(i = 0; i < db_n_items(); i++)
357 selected[i] = !selected[i];
363 return db_n_items() < 1;
373 list_set_curitem(int i)
386 item = item_create();
387 item_duplicate(item, db_item_get(curitem));
388 if(add_item2database(item)) {
394 curitem = last_item();