]> git.deb.at Git - pkg/abook.git/blobdiff - ui.c
Merge branch 'dh'
[pkg/abook.git] / ui.c
diff --git a/ui.c b/ui.c
index 0fc8273d3ab8bb754bf8e9ee0768d1405323565f..6fe2f0f47079ff9692441b62356cff8e416683ef 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ui.c,v 1.54 2005/10/05 11:03:36 jheinonen Exp $
+ * $Id: ui.c,v 1.58 2006/09/06 02:24:33 cduval Exp $
  *
  * by JH <jheinonen@users.sourceforge.net>
  *
@@ -38,7 +38,6 @@
  * external variables
  */
 
-extern int items, curitem;
 extern char *datafile;
 
 extern bool alternative_datafile;
@@ -281,7 +280,7 @@ statusline_askchoice(const char *msg, const char *choices, short dflt)
        char *s;
        int ch;
 
-       assert((dflt < 0) || (dflt > strlen(choices)));
+       assert((dflt >= 0) && (dflt <= strlen(choices)));
 
        if(dflt) {
                s = strdup_printf("%s [%c]", msg, choices[dflt - 1]);
@@ -306,7 +305,7 @@ statusline_askchoice(const char *msg, const char *choices, short dflt)
 }
 
 char *
-ui_readline(char *prompt, char *s, size_t limit, bool use_completion)
+ui_readline(const char *prompt, char *s, size_t limit, bool use_completion)
 {
        int y, x;
        char *ret;
@@ -327,7 +326,7 @@ ui_readline(char *prompt, char *s, size_t limit, bool use_completion)
 }
 
 int
-statusline_ask_boolean(char *msg, int def)
+statusline_ask_boolean(const char *msg, int def)
 {
        int ret;
        char *msg2 = strconcat(msg,  def ? _(" (Y/n)?") : _(" (y/N)?"), NULL);
@@ -363,7 +362,7 @@ refresh_statusline()
 }
 
 char *
-ask_filename(char *prompt)
+ask_filename(const char *prompt)
 {
        char *buf = NULL;
 
@@ -433,7 +432,6 @@ display_help(int help)
  */
 
 extern char *selected;
-extern int curitem;
 
 void
 get_commands()
@@ -454,7 +452,7 @@ get_commands()
                        case 'q': return;
                        case 'Q': quit_abook(QUIT_DONTSAVE);    break;
                        case 'P': print_stderr(selected_items() ?
-                                                 -1 : list_current_item());
+                                                 -1 : list_get_curitem());
                                  return;
                        case '?':
                                  display_help(HELP_MAIN);
@@ -491,15 +489,15 @@ get_commands()
 
                        case 'o': ui_open_datafile();   break;
 
-                       case 's': sort_by_field(NAME);  break;
+                       case 's': sort_by_field("name");break;
                        case 'S': sort_surname();       break;
-                       case 'F': sort_by_field(-1);    break;
+                       case 'F': sort_by_field(NULL);  break;
 
                        case '/': ui_find(0);           break;
                        case '\\': ui_find(1);          break;
 
-                       case ' ': if(curitem >= 0) {
-                                  selected[curitem] = !selected[curitem];
+                       case ' ': if(list_get_curitem() >= 0) {
+                                  list_invert_curitem_selection();
                                   ui_print_number_of_items();
                                   refresh_list();
                                  }
@@ -519,13 +517,13 @@ get_commands()
                                break;
 
                        case 'm': launch_mutt(selected_items() ?
-                                                 -1 : list_current_item());
+                                                 -1 : list_get_curitem());
                                  refresh_screen();
                                  break;
 
                        case 'p': ui_print_database(); break;
 
-                       case 'v': launch_wwwbrowser(list_current_item());
+                       case 'v': launch_wwwbrowser(list_get_curitem());
                                  refresh_screen();
                                  break;
                }
@@ -569,26 +567,31 @@ ui_find(int next)
        } else {
                char *s;
                s = ui_readline("/", findstr, MAX_FIELD_LEN - 1, 0);
-               strncpy(findstr, s, MAX_FIELD_LEN);
-               free(s);
                refresh_screen();
+               if(s == NULL) {
+                       return; /* user cancelled (ctrl-G) */
+               } else {
+                       strncpy(findstr, s, MAX_FIELD_LEN);
+                       free(s);
+               }
        }
 
-       if( (item = find_item(findstr, curitem + !!next, search_fields)) < 0 &&
+       if( (item = find_item(findstr, list_get_curitem() + !!next,
+                       search_fields)) < 0 &&
                        (item = find_item(findstr, 0, search_fields)) >= 0)
                statusline_addstr(_("Search hit bottom, continuing at top"));
 
        if(item >= 0) {
-               curitem = item;
+               list_set_curitem(item);
                refresh_list();
        }
 }
 
-
 void
 ui_print_number_of_items()
 {
-       char *str = strdup_printf("     " "|%3d/%3d", selected_items(), items);
+       char *str = strdup_printf("     " "|%3d/%3d",
+               selected_items(), db_n_items());
 
        mvaddstr(0, COLS-strlen(str), str);
 
@@ -600,7 +603,7 @@ ui_read_database()
 {
        char *msg;
 
-       if(items > 0) {
+       if(!list_is_empty()) {
                msg = strdup_printf(_("Your current data will be lost - "
                                "Press '%c' to continue"),
                                *(S_("keybinding for yes|y")));
@@ -675,7 +678,7 @@ ui_open_datafile()
 
        load_database(filename);
 
-       if(items == 0) {
+       if(list_is_empty()) {
                statusline_msg(_("Sorry, the specified file appears not to be a valid abook addressbook"));
                load_database(datafile);
        } else {