X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=list.c;h=b208054d7cdfa71991a570d914f7c5273784fb3a;hb=a4028acb18fd04cbf03ddbd976115aeb04ddd867;hp=32c12ed8b8466c0c6aa3ee72573c619bf8f7a2e5;hpb=d4cd6aada86c2d1c3e046b91a271184e659716fa;p=pkg%2Fabook.git diff --git a/list.c b/list.c index 32c12ed..b208054 100644 --- a/list.c +++ b/list.c @@ -10,6 +10,7 @@ #include #include #include "abook.h" +#include #include "ui.h" #include "database.h" #include "edit.h" @@ -33,47 +34,41 @@ extern struct abook_field abook_fields[]; WINDOW *list = NULL; -void -init_list() +static int +init_extra_field(enum str_opts option) { - int i; - char *e_column_str = options_get_str("extra_column"); - char *e_alternative_str = options_get_str("extra_alternative"); + int i, ret = -1; + char *option_str; - list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); - scrollok(list, TRUE); + option_str = opt_get_str(option); - /* - * init extra_column and extra alternative - */ - - if(e_column_str && *e_column_str) { + if(option_str && *option_str) { for(i = 0; i < ITEM_FIELDS; i++) { - if(!strcasecmp(e_column_str, abook_fields[i].key)) { - extra_column = i; + if(!strcasecmp(option_str, abook_fields[i].key)) { + ret = i; break; } } - if(extra_column < MIN_EXTRA_COLUMN || - extra_column > MAX_EXTRA_COLUMN) { - extra_column = -1; + if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) { + ret = -1; } } - if(e_alternative_str && *e_alternative_str) { - for(i = 0; i < ITEM_FIELDS; i++) { - if(!strcasecmp(e_alternative_str, - abook_fields[i].key)) { - extra_alternative = i; - break; - } - } - if(extra_alternative < MIN_EXTRA_COLUMN || - extra_alternative > MAX_EXTRA_COLUMN) { - extra_alternative = -1; - } - } + return ret; +} + +void +init_list() +{ + list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); + scrollok(list, TRUE); + /* + * init extra_column and extra alternative + */ + + extra_column = init_extra_field(STR_EXTRA_COLUMN); + extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE); } void @@ -87,17 +82,17 @@ void refresh_list() { int i, line; - + werase(list); ui_print_number_of_items(); - - if( items < 1 ) { + + if(list_is_empty()) { refresh(); wrefresh(list); return; } - + if(curitem < 0) curitem = 0; @@ -112,19 +107,19 @@ refresh_list() for( line = 0, i = first_list_item ; i <= LAST_LIST_ITEM && i < items; line++, i++ ) { - if(i == curitem) - highlight_line(list, line); - - print_list_line(i, line); - - wstandend(list); + print_list_line(i, line, i == curitem); } + if(opt_get_bool(BOOL_SHOW_CURSOR)) { + wmove(list, curitem - first_list_item, 0); + /* need to call refresh() to update the cursor positions */ + refresh(); + } wrefresh(list); } void -print_list_line(int i, int line) +print_list_line(int i, int line, int highlight) { int extra = extra_column; char tmp[MAX_EMAILSTR_LEN]; @@ -132,46 +127,56 @@ print_list_line(int i, int line) EMAILLEN : COLS - EMAILPOS; scrollok(list, FALSE); + if(highlight) + highlight_line(list, line); - if( selected[i] ) + if(selected[i]) mvwaddch(list, line, 0, '*' ); - - mvwaddnstr(list, line, NAMEPOS, database[i][NAME], NAMELEN); - if( options_get_int( "show_all_emails" ) ) + + mvwaddnstr(list, line, NAMEPOS, database[i][NAME], + bytes2width(database[i][NAME], NAMELEN)); + if(opt_get_bool(BOOL_SHOW_ALL_EMAILS)) mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL], - real_emaillen); + bytes2width(database[i][EMAIL], real_emaillen)); else { get_first_email(tmp, i); - mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen); + mvwaddnstr(list, line, EMAILPOS, tmp, + bytes2width(tmp, real_emaillen)); } if(extra < 0 || !database[i][extra]) extra = extra_alternative; if(extra >= 0) mvwaddnstr(list, line, EXTRAPOS, - safe_str(database[i][extra]), - EXTRALEN); + safe_str(database[i][extra]), + bytes2width(safe_str(database[i][extra]), EXTRALEN)); scrollok(list, TRUE); + if(highlight) + wstandend(list); } - + void list_headerline() { +#if defined(A_BOLD) && defined(A_NORMAL) attrset(A_BOLD); +#endif mvaddstr(2, NAMEPOS, abook_fields[NAME].name); mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name); if(extra_column > 0) mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name, COLS-EXTRAPOS); +#if defined(A_BOLD) && defined(A_NORMAL) attrset(A_NORMAL); +#endif } void scroll_up() { - if( curitem < 1 ) + if(curitem < 1) return; curitem--; @@ -182,7 +187,7 @@ scroll_up() void scroll_down() { - if( curitem > items - 2 ) + if(curitem > items - 2) return; curitem++; @@ -194,19 +199,19 @@ scroll_down() void page_up() { - if( curitem < 1 ) + if(curitem < 1) return; - + curitem = curitem == first_list_item ? ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item; - + refresh_list(); } void page_down() { - if( curitem > items - 2 ) + if(curitem > items - 2) return; curitem = curitem == LAST_LIST_ITEM ? @@ -216,17 +221,16 @@ page_down() refresh_list(); } - void select_none() { - memset( selected, 0, items ); + memset(selected, 0, items); } void select_all() { - memset( selected, 1, items ); + memset(selected, 1, items); } void @@ -263,7 +267,7 @@ goto_home() { if(items > 0) curitem = 0; - + refresh_list(); } @@ -281,8 +285,12 @@ void highlight_line(WINDOW *win, int line) { wstandout(win); - -#ifdef mvwchgat + + /* + * this is a tricky one + */ +#if 0 +/*#ifdef mvwchgat*/ mvwchgat(win, line, 0, -1, A_STANDOUT, 0, NULL); #else /* @@ -317,7 +325,7 @@ invert_selection() { int i; - if( items < 1 ) + if(items < 1) return; for(i = 0; i < items; i++) @@ -336,4 +344,25 @@ list_is_empty() return items < 1; } - +int +duplicate_item() +{ + int i; + list_item item; + + if(curitem < 0) + return 1; + + for(i = 0; i < ITEM_FIELDS; i++) + item[i] = database[curitem][i] ? strdup(database[curitem][i]) : + NULL; + + if(add_item2database(item)) + return 1; + + curitem = LAST_ITEM; + refresh_list(); + + return 0; +} +