]> git.deb.at Git - pkg/abook.git/blobdiff - list.c
Imported Debian patch 0.5.6-6
[pkg/abook.git] / list.c
diff --git a/list.c b/list.c
index 7d5536c7fc75587b80d8d80b0ad661b728a935e7..1c250850402f7399d78a5f1a9abf26e2bd1819f9 100644 (file)
--- a/list.c
+++ b/list.c
@@ -1,6 +1,6 @@
 
 /*
- * $Id: list.c,v 1.15 2002/01/29 11:58:13 jheinonen Exp $
+ * $Id: list.c,v 1.27 2005/09/17 10:10:26 jheinonen Exp $
  *
  * by JH <jheinonen@users.sourceforge.net>
  *
 #include "ui.h"
 #include "database.h"
 #include "edit.h"
+#include "gettext.h"
 #include "list.h"
 #include "misc.h"
 #include "options.h"
+#include "xmalloc.h"
 
 #define MIN_EXTRA_COLUMN       ADDRESS /* 2 */
 #define MAX_EXTRA_COLUMN       LAST_FIELD
@@ -32,17 +34,15 @@ extern int items;
 extern list_item *database;
 extern struct abook_field abook_fields[];
 
-WINDOW *list = NULL;
+static 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 +69,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
@@ -84,17 +84,17 @@ void
 refresh_list()
 {
        int i, line;
-       
+
        werase(list);
 
        ui_print_number_of_items();
-       
-       if( items < 1 ) {
+
+       if(list_is_empty()) {
                refresh();
                wrefresh(list);
                return;
        }
-       
+
        if(curitem < 0)
                curitem = 0;
 
@@ -112,6 +112,11 @@ refresh_list()
                print_list_line(i, line, i == curitem);
         }
 
+       if(opt_get_bool(BOOL_SHOW_CURSOR)) {
+               wmove(list, curitem - first_list_item, 0);
+               /* need to call refresh() to update the cursor positions */
+               refresh();
+       }
         wrefresh(list);
 }
 
@@ -127,45 +132,45 @@ 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"  ) )
+
+       mvwaddnstr(list, line, NAMEPOS, database[i][NAME],
+               bytes2width(database[i][NAME], NAMELEN));
+       if(opt_get_bool(BOOL_SHOW_ALL_EMAILS))
                mvwaddnstr(list, line, EMAILPOS, database[i][EMAIL],
-                               real_emaillen);
+                               bytes2width(database[i][EMAIL], real_emaillen));
        else {
                get_first_email(tmp, i);
-               mvwaddnstr(list, line, EMAILPOS, tmp, real_emaillen);
+               mvwaddnstr(list, line, EMAILPOS, tmp,
+                       bytes2width(tmp, real_emaillen));
        }
 
        if(extra < 0 || !database[i][extra])
                extra = extra_alternative;
        if(extra >= 0)
                mvwaddnstr(list, line, EXTRAPOS,
-                               safe_str(database[i][extra]),
-                               EXTRALEN);
+                       safe_str(database[i][extra]),
+                       bytes2width(safe_str(database[i][extra]), EXTRALEN));
 
        scrollok(list, TRUE);
        if(highlight)
                wstandend(list);
 }
-       
+
 
 void
 list_headerline()
 {
-#ifdef A_BOLD
+#if defined(A_BOLD) && defined(A_NORMAL)
        attrset(A_BOLD);
-#else
-       /* hmm, maybe something here */
 #endif
-       mvaddstr(2, NAMEPOS, abook_fields[NAME].name);
-       mvaddstr(2, EMAILPOS, abook_fields[EMAIL].name);
+       mvaddstr(2, NAMEPOS, gettext(abook_fields[NAME].name));
+       mvaddstr(2, EMAILPOS, gettext(abook_fields[EMAIL].name));
        if(extra_column > 0)
-               mvaddnstr(2, EXTRAPOS, abook_fields[extra_column].name,
+               mvaddnstr(2, EXTRAPOS, gettext(abook_fields[extra_column].name),
                                COLS-EXTRAPOS);
-#ifdef A_BOLD
+#if defined(A_BOLD) && defined(A_NORMAL)
        attrset(A_NORMAL);
 #endif
 }
@@ -173,7 +178,7 @@ list_headerline()
 void
 scroll_up()
 {
-       if( curitem < 1 )
+       if(curitem < 1)
                return;
 
        curitem--;
@@ -184,7 +189,7 @@ scroll_up()
 void
 scroll_down()
 {
-       if( curitem > items - 2 )
+       if(curitem > items - 2)
                return;
 
        curitem++;
@@ -196,19 +201,19 @@ scroll_down()
 void
 page_up()
 {
-       if( curitem < 1 )
+       if(curitem < 1)
                return;
-       
+
        curitem = curitem == first_list_item ?
                ((curitem -= LIST_LINES) < 0 ? 0 : curitem) : first_list_item;
-       
+
        refresh_list();
 }
 
 void
 page_down()
 {
-       if( curitem > items - 2 )
+       if(curitem > items - 2)
                return;
 
        curitem = curitem == LAST_LIST_ITEM ?
@@ -218,17 +223,16 @@ page_down()
        refresh_list();
 }
 
-
 void
 select_none()
 {
-        memset( selected, 0, items );
+        memset(selected, 0, items);
 }
 
 void
 select_all()
 {
-        memset( selected, 1, items );
+        memset(selected, 1, items);
 }
 
 void
@@ -265,7 +269,7 @@ goto_home()
 {
        if(items > 0)
                curitem = 0;
-       
+
        refresh_list();
 }
 
@@ -323,7 +327,7 @@ invert_selection()
 {
        int i;
 
-       if( items < 1 )
+       if(items < 1)
                return;
 
        for(i = 0; i < items; i++)
@@ -342,4 +346,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] ? xstrdup(database[curitem][i]) :
+                       NULL;
+
+       if(add_item2database(item))
+               return 1;
+
+       curitem = LAST_ITEM;
+       refresh_list();
+
+       return 0;
+}
+