#include <stdio.h>
#include <string.h>
#include "abook.h"
+#include <assert.h>
#include "ui.h"
#include "database.h"
#include "edit.h"
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);
-
- /*
- * init extra_column and extra alternative
- */
+ option_str = opt_get_str(option);
- 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
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);
}
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];
EMAILLEN : COLS - EMAILPOS;
scrollok(list, FALSE);
+ if(highlight)
+ highlight_line(list, line);
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 {
EXTRALEN);
scrollok(list, TRUE);
+ if(highlight)
+ wstandend(list);
}
void
list_headerline()
{
+#ifdef A_BOLD
attrset(A_BOLD);
+#else
+ /* hmm, maybe something here */
+#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);
+#ifdef A_BOLD
attrset(A_NORMAL);
+#endif
}
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
/*