]> git.deb.at Git - pkg/abook.git/blobdiff - edit.c
* don't unlink empty datafile, just truncate
[pkg/abook.git] / edit.c
diff --git a/edit.c b/edit.c
index f5e05845e8022e1abc94f20e4845815a5aa0c8d9..c7a62e43751a38280ec4bbc3010138c6f2a7f1cd 100644 (file)
--- a/edit.c
+++ b/edit.c
  * some extern variables
  */
 
-
-extern int curitem;
 extern int views_count;
-extern int items;
 
 WINDOW *editw;
 
@@ -51,10 +48,7 @@ editor_tab(const int tab)
                int width = strwidth(tab_name) + 5;
 
                if(x_pos + width + 1 > EDITW_COLS) {
-                       statusline_msg(_("Tab name too wide for screen"));
-                       /* Disabling this field */
-                       /* TODO should be recomputed on window resize */
-                       views_count--;
+                       statusline_addstr(_("Tab name too wide for screen"));
                        break;
                }
 
@@ -82,29 +76,33 @@ editor_tab(const int tab)
 void
 get_first_email(char *str, int item)
 {
-       char *tmp;
+       char *tmp, *emails = db_email_get(item);
 
-       if(!db_email_get(item)) {
+       if(!*emails) {
                *str = 0;
                return;
        }
 
-       strncpy(str, db_email_get(item), MAX_EMAIL_LEN);
+       strncpy(str, emails, MAX_EMAIL_LEN);
+       free(emails);
        if( (tmp = strchr(str, ',')) )
                *tmp = 0;
        else
                str[MAX_EMAIL_LEN - 1] = 0;
 }
 
+/* This only rolls emails from the 'email' field, not emails from any
+ * field of type FIELD_EMAILS.
+ * TODO: expand to ask for which field to roll if several are present? */
 static void
 roll_emails(int item, enum rotate_dir dir)
 {
-       abook_list *emails = csv_to_abook_list(db_email_get(item));
+       abook_list *emails = csv_to_abook_list(db_fget(item, EMAIL));
 
        if(!emails)
                return;
 
-       free(db_email_get(item));
+       free(db_fget(item, EMAIL));
        abook_list_rotate(&emails, dir);
        db_fput(item, EMAIL, abook_list_to_csv(emails));
        abook_list_free(&emails);
@@ -181,7 +179,7 @@ print_editor_header(int item)
 
        get_first_email(email, item);
 
-       if(*db_email_get(item))
+       if(*email)
                snprintf(header, EDITW_COLS, "%s <%s>",
                                db_name_get(item),
                                email);
@@ -363,7 +361,7 @@ edit_list(int item, int nb, int isemail)
                                &field, MAX_EMAIL_LEN))
                return; /* user cancelled ( C-g ) */
 
-       /* TODO if list item contains commas, sjould use quotes instead */
+       /* TODO if list item contains commas, should use quotes instead */
        if(field)
                fix_email_str(field);
 
@@ -513,17 +511,17 @@ edit_loop(int item)
 void
 edit_item(int item)
 {
-       if( item < 0 ) {
-               if( curitem < 0 )
+       if(item < 0) {
+               if(list_get_curitem() < 0)
                        return;
                else
-                       item = curitem;
+                       item = list_get_curitem();
        }
 
        init_editor();
 
        while((item = edit_loop(item)) >= 0)
-               curitem = item; /* hmm, this is not very clean way to go */
+               list_set_curitem(item); /* this is not very clean way to go */
 
        close_editor();
 }
@@ -534,7 +532,7 @@ add_item()
        char *field = NULL;
        list_item item = item_create();
 
-       change_field("Name: ", &field, MAX_FIELD_LEN);
+       change_field(_("Name: "), &field, MAX_FIELD_LEN);
 
        if( field == NULL )
                return;
@@ -544,8 +542,8 @@ add_item()
        add_item2database(item);
        item_free(&item);
 
-       curitem = LAST_ITEM;
+       list_set_curitem(last_item());
 
-       edit_item(LAST_ITEM);
+       edit_item(last_item());
 }