/*
* $Id$
*
- * by JH <jheinonen@bigfoot.com>
+ * by JH <jheinonen@users.sourceforge.net>
*
* Copyright (C) Jaakko Heinonen
*/
#include <stdio.h>
#include <string.h>
+#include <assert.h>
#include "abook.h"
#include "ui.h"
#include "database.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
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);
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);
}
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);
selected[i] = !selected[i];
}
-inline int
+int
list_current_item()
{
return curitem;
}
-inline int
+int
list_is_empty()
{
- return items < 1 ? 1 : 0;
+ return items < 1;
}