X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=list.c;h=6cb8ed791b8bd71065d62cd63657e7387cd50210;hb=08647c0fa571eb3a07490ab0971dc89677775537;hp=fd1c7069307a23f2b981b2094946fb6029709b9c;hpb=12a57d9405d7910566d5ff888d743d29b0716554;p=pkg%2Fabook.git diff --git a/list.c b/list.c index fd1c706..6cb8ed7 100644 --- a/list.c +++ b/list.c @@ -2,36 +2,75 @@ /* * $Id$ * - * by JH + * by JH * * Copyright (C) Jaakko Heinonen */ #include #include -#include "abook_curses.h" +#include #include "abook.h" +#include "ui.h" #include "database.h" #include "edit.h" #include "list.h" #include "misc.h" #include "options.h" +#define MIN_EXTRA_COLUMN ADDRESS /* 2 */ +#define MAX_EXTRA_COLUMN LAST_FIELD + int curitem = -1; int first_list_item = -1; char *selected = NULL; +int extra_column = -1; +int extra_alternative = -1; + extern int items; extern list_item *database; extern struct abook_field abook_fields[]; WINDOW *list = NULL; +static int +init_extra_field(char *option_name) +{ + int i, ret = -1; + char *option_str; + + assert(option_name != NULL); + + option_str = options_get_str(option_name); + + if(option_str && *option_str) { + for(i = 0; i < ITEM_FIELDS; i++) { + if(!strcasecmp(option_str, abook_fields[i].key)) { + ret = i; + break; + } + } + if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) { + ret = -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("extra_column"); + extra_alternative = init_extra_field("extra_alternative"); } void @@ -48,7 +87,7 @@ refresh_list() werase(list); - print_number_of_items(); + ui_print_number_of_items(); if( items < 1 ) { refresh(); @@ -84,10 +123,10 @@ refresh_list() void print_list_line(int i, int line) { + int extra = extra_column; char tmp[MAX_EMAILSTR_LEN]; - int extra_column = options_get_int("extra_column"); - int real_emaillen = (extra_column > 2 && extra_column < ITEM_FIELDS) ? - EMAILLEN : EMAILPOS - COLS; + int real_emaillen = (extra_column > 0 || extra_alternative > 0) ? + EMAILLEN : COLS - EMAILPOS; scrollok(list, FALSE); @@ -103,19 +142,12 @@ print_list_line(int i, int line) mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen); } - if(extra_column > 2 && extra_column < ITEM_FIELDS) { - if( !database[i][extra_column] ) { - int extra_alternative = - options_get_int("extra_alternative"); - - if(extra_alternative > 2 && - extra_alternative < ITEM_FIELDS) - extra_column = extra_alternative; - } + if(extra < 0 || !database[i][extra]) + extra = extra_alternative; + if(extra >= 0) mvwaddnstr(list, line, EXTRAPOS, - safe_str(database[i][extra_column]), + safe_str(database[i][extra]), EXTRALEN); - } scrollok(list, TRUE); } @@ -124,12 +156,10 @@ print_list_line(int i, int line) void list_headerline() { - int extra_column = options_get_int("extra_column"); - attrset(A_BOLD); mvaddstr(2, NAMEPOS, abook_fields[NAME].name); mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name); - if( extra_column > 2 && extra_column < ITEM_FIELDS ) + if(extra_column > 0) mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name, COLS-EXTRAPOS); attrset(A_NORMAL); @@ -291,3 +321,16 @@ invert_selection() selected[i] = !selected[i]; } +int +list_current_item() +{ + return curitem; +} + +int +list_is_empty() +{ + return items < 1; +} + +