5 * by JH <jheinonen@users.sourceforge.net>
7 * Copyright (C) Jaakko Heinonen
22 #define MIN_EXTRA_COLUMN ADDRESS /* 2 */
23 #define MAX_EXTRA_COLUMN LAST_FIELD
26 int first_list_item = -1;
27 char *selected = NULL;
29 int extra_column = -1;
30 int extra_alternative = -1;
33 extern list_item *database;
34 extern struct abook_field abook_fields[];
36 static WINDOW *list = NULL;
39 init_extra_field(enum str_opts option)
44 option_str = opt_get_str(option);
46 if(option_str && *option_str) {
47 for(i = 0; i < ITEM_FIELDS; i++) {
48 if(!strcasecmp(option_str, abook_fields[i].key)) {
53 if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) {
64 list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
68 * init extra_column and extra alternative
71 extra_column = init_extra_field(STR_EXTRA_COLUMN);
72 extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE);
89 ui_print_number_of_items();
100 if(first_list_item < 0)
103 if(curitem < first_list_item)
104 first_list_item = curitem;
105 else if(curitem > LAST_LIST_ITEM)
106 first_list_item = max(curitem - LIST_LINES + 1, 0);
108 for( line = 0, i = first_list_item ; i <= LAST_LIST_ITEM && i < items;
111 print_list_line(i, line, i == curitem);
114 if(opt_get_bool(BOOL_SHOW_CURSOR)) {
115 wmove(list, curitem - first_list_item, 0);
116 /* need to call refresh() to update the cursor positions */
123 print_list_line(int i, int line, int highlight)
125 int extra = extra_column;
126 char tmp[MAX_EMAILSTR_LEN];
127 int real_emaillen = (extra_column > 0 || extra_alternative > 0) ?
128 EMAILLEN : COLS - EMAILPOS;
130 scrollok(list, FALSE);
132 highlight_line(list, line);
135 mvwaddch(list, line, 0, '*' );
137 mvwaddnstr(list, line, NAMEPOS, database[i][NAME],
138 bytes2width(database[i][NAME], NAMELEN));
139 if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
140 mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL],
141 bytes2width(database[i][EMAIL], real_emaillen));
143 get_first_email(tmp, i);
144 mvwaddnstr(list, line, EMAILPOS, tmp,
145 bytes2width(tmp, real_emaillen));
148 if(extra < 0 || !database[i][extra])
149 extra = extra_alternative;
151 mvwaddnstr(list, line, EXTRAPOS,
152 safe_str(database[i][extra]),
153 bytes2width(safe_str(database[i][extra]), EXTRALEN));
155 scrollok(list, TRUE);
164 #if defined(A_BOLD) && defined(A_NORMAL)
167 mvaddstr(2, NAMEPOS, abook_fields[NAME].name);
168 mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name);
170 mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name,
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 )
245 itemcpy(tmp, database[curitem]);
251 itemcpy(database[curitem], database[curitem - 1]);
252 itemcpy(database[curitem-1], tmp);
257 if( curitem >= LAST_ITEM )
259 itemcpy(database[curitem], database[curitem + 1]);
260 itemcpy(database[curitem+1], tmp);
286 highlight_line(WINDOW *win, int line)
291 * this is a tricky one
295 mvwchgat(win, line, 0, -1, A_STANDOUT, 0, NULL);
298 * buggy function: FIXME
300 scrollok(win, FALSE);
304 for(i = 0; i < COLS; i++)
306 /*wattrset(win, 0);*/
317 for(i = 0; i < items; i++)
332 for(i = 0; i < items; i++)
333 selected[i] = !selected[i];
357 for(i = 0; i < ITEM_FIELDS; i++)
358 item[i] = database[curitem][i] ? xstrdup(database[curitem][i]) :
361 if(add_item2database(item))