From d4cd6aada86c2d1c3e046b91a271184e659716fa Mon Sep 17 00:00:00 2001 From: Jaakko Heinonen Date: Thu, 11 Oct 2001 15:49:19 +0000 Subject: [PATCH] Don't handle extra_column/extra_alternative as numbers in abookrc --- ChangeLog | 2 ++ configure | 2 +- configure.in | 2 +- edit.c | 25 +++++++++---------- edit.h | 6 +++++ list.c | 65 +++++++++++++++++++++++++++++++++++++------------- sample.abookrc | 16 ++++++------- 7 files changed, 80 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index c78b6d4..ddf9b20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 0.4.15 - new options --add-email and --add-email-quiet - proper mutt alias import filter + - minor editor update + - don't handle extra_column and extra_alternative as numbers in abookrc - mail.vim update in contrib directory 0.4.14 diff --git a/configure b/configure index 3364110..d463338 100755 --- a/configure +++ b/configure @@ -785,7 +785,7 @@ fi # Define the identity of the package. PACKAGE=abook -VERSION=0.4.15pre1 +VERSION=0.4.15pre2 cat >> confdefs.h < 70 ? 8:4; - const int start_y = 5; int i, j; int y, x; @@ -159,11 +157,13 @@ editor_print_data(int tab, int item) char emails[MAX_EMAILS][MAX_EMAIL_LEN]; split_emailstr(item, emails); getyx(editw, y, x); - mvwaddstr(editw, y+1, pos_x, "E-mail addresses:"); + mvwaddstr(editw, y+1, TAB_START_X, "E-mail addresses:"); for(k = 0; k < MAX_EMAILS; k++) { getyx(editw, y, x); - mvwprintw(editw, y+1, pos_x, - "%c -\t\t%s", '2' + k, emails[k] ); + mvwprintw(editw, y+1, TAB_START_X, + "%c -", '2' + k); + mvwprintw(editw, y +1, TAB_COLON_POS, + ": %s", emails[k]); } continue; } @@ -171,13 +171,14 @@ editor_print_data(int tab, int item) if(j > 1) { getyx(editw, y, x); y++; } else - y = start_y; + y = TAB_START_Y; - mvwprintw(editw, y, pos_x, "%d - %s", + mvwprintw(editw, y, TAB_START_X, "%d - %s", j, abook_fields[i].name); - mvwaddch(editw, y, 28, ':'); - mvwaddstr(editw, y, 30, safe_str(database[item][i])); + mvwaddch(editw, y, TAB_COLON_POS, ':'); + mvwaddstr(editw, y, TAB_COLON_POS + 2, + safe_str(database[item][i])); j++; } @@ -268,7 +269,7 @@ edit_emails(char c, int item) my_free(database[item][EMAIL]); - for(i=0; i 6) + if(n < 1 || n > MAX_TAB_LINES) return 0; edit_undo(item, BACKUP_ITEM); diff --git a/edit.h b/edit.h index 1b8c8f6..d686f9d 100644 --- a/edit.h +++ b/edit.h @@ -14,6 +14,12 @@ void add_item(); #define TABLINE 2 +#define MAX_TAB_LINES 7 + +#define TAB_COLON_POS 28 +#define TAB_START_Y 5 +#define TAB_START_X (EDITW_COLS > 70 ? 8:4) + enum { TAB_CONTACT, TAB_ADDRESS, diff --git a/list.c b/list.c index b3e12de..32c12ed 100644 --- a/list.c +++ b/list.c @@ -17,10 +17,16 @@ #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[]; @@ -30,8 +36,44 @@ WINDOW *list = NULL; void init_list() { + int i; + char *e_column_str = options_get_str("extra_column"); + char *e_alternative_str = options_get_str("extra_alternative"); + list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); scrollok(list, TRUE); + + /* + * init extra_column and extra alternative + */ + + if(e_column_str && *e_column_str) { + for(i = 0; i < ITEM_FIELDS; i++) { + if(!strcasecmp(e_column_str, abook_fields[i].key)) { + extra_column = i; + break; + } + } + if(extra_column < MIN_EXTRA_COLUMN || + extra_column > MAX_EXTRA_COLUMN) { + extra_column = -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; + } + } + } void @@ -84,9 +126,9 @@ 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) ? + int real_emaillen = (extra_column > 0 || extra_alternative > 0) ? EMAILLEN : COLS - EMAILPOS; scrollok(list, FALSE); @@ -103,19 +145,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 +159,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); diff --git a/sample.abookrc b/sample.abookrc index 3096cf1..847e4ff 100644 --- a/sample.abookrc +++ b/sample.abookrc @@ -11,15 +11,15 @@ show_all_emails=true emailpos=25 # Field to be used in the extra column -extra_column=7 +extra_column=phone # frequently used values: -# -1 = disabled -# 7 = Home Phone -# 8 = Work Phone -# 9 = Fax -# 10 = Mobile Phone -# 11 = Nick / Alias -# 12 = URL +# -1 disabled +# phone Home Phone +# workphone Work Phone +# fax Fax +# mobile Mobile Phone +# nick Nick / Alias +# url URL # Specify an alternative field to be displayed in the extra # column if there is no data for the field specified in -- 2.39.2