X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=list.c;h=7197723d03fcad6f03f8b5165146e8add20f65e8;hb=35c85955699b227956e399a76b4a78ab48aa0c18;hp=5bb6753a4d7be745bd82e6cc565427e629c68cd3;hpb=b8966ec4ee3c9d035850ff49aaf5485081fe0d20;p=pkg%2Fabook.git diff --git a/list.c b/list.c index 5bb6753..7197723 100644 --- a/list.c +++ b/list.c @@ -35,14 +35,12 @@ extern struct abook_field abook_fields[]; WINDOW *list = NULL; static int -init_extra_field(char *option_name) +init_extra_field(enum str_opts option) { int i, ret = -1; char *option_str; - assert(option_name != NULL); - - option_str = options_get_str(option_name); + option_str = opt_get_str(option); if(option_str && *option_str) { for(i = 0; i < ITEM_FIELDS; i++) { @@ -69,8 +67,8 @@ init_list() * init extra_column and extra alternative */ - extra_column = init_extra_field("extra_column"); - extra_alternative = init_extra_field("extra_alternative"); + extra_column = init_extra_field(STR_EXTRA_COLUMN); + extra_alternative = init_extra_field(STR_EXTRA_ALTERNATIVE); } void @@ -89,7 +87,7 @@ refresh_list() ui_print_number_of_items(); - if( items < 1 ) { + if(items < 1) { refresh(); wrefresh(list); return; @@ -127,11 +125,11 @@ print_list_line(int i, int line, int highlight) 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" ) ) + if(opt_get_bool(BOOL_SHOW_ALL_EMAILS)) mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL], real_emaillen); else { @@ -173,7 +171,7 @@ list_headerline() void scroll_up() { - if( curitem < 1 ) + if(curitem < 1) return; curitem--; @@ -184,7 +182,7 @@ scroll_up() void scroll_down() { - if( curitem > items - 2 ) + if(curitem > items - 2) return; curitem++; @@ -196,7 +194,7 @@ scroll_down() void page_up() { - if( curitem < 1 ) + if(curitem < 1) return; curitem = curitem == first_list_item ? @@ -208,7 +206,7 @@ page_up() void page_down() { - if( curitem > items - 2 ) + if(curitem > items - 2) return; curitem = curitem == LAST_LIST_ITEM ? @@ -222,13 +220,13 @@ page_down() void select_none() { - memset( selected, 0, items ); + memset(selected, 0, items); } void select_all() { - memset( selected, 1, items ); + memset(selected, 1, items); } void @@ -323,7 +321,7 @@ invert_selection() { int i; - if( items < 1 ) + if(items < 1) return; for(i = 0; i < items; i++) @@ -342,4 +340,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; +} +