made search for accounts by email address not case sensitive
[claws.git] / src / account.c
index fde067ad110cefb850ea66571cd177505998e486..79341794d50add6ce1f1eaf9e8d19a673c8a5deb 100644 (file)
@@ -37,6 +37,7 @@
 #include "account.h"
 #include "prefs.h"
 #include "prefs_account.h"
+#include "prefs_folder_item.h"
 #include "compose.h"
 #include "manage_window.h"
 #include "inc.h"
 #include "utils.h"
 #include "alertpanel.h"
 
+#include "pixmaps/mark.xpm"
+
 typedef enum
 {
        COL_DEFAULT     = 0,
-       COL_NAME        = 1,
-       COL_PROTOCOL    = 2,
-       COL_SERVER      = 3,
-        COL_GETALL      = 4
+       COL_GETALL      = 1,
+       COL_NAME        = 2,
+       COL_PROTOCOL    = 3,
+       COL_SERVER      = 4
 } EditAccountColumnPos;
 
 # define N_EDIT_ACCOUNT_COLS   5
@@ -67,6 +70,9 @@ static struct EditAccount {
        GtkWidget *close_btn;
 } edit_account;
 
+static GdkPixmap *markxpm;
+static GdkBitmap *markxpmmask;
+
 static void account_edit_create                (void);
 
 static void account_edit_prefs         (void);
@@ -190,7 +196,7 @@ PrefsAccount *account_find_from_address(const gchar *address)
 
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
-               if (ac->protocol != A_NNTP && !strcmp2(address, ac->address))
+               if (ac->protocol != A_NNTP && strcasestr(address, ac->address))
                        return ac;
        }
 
@@ -232,12 +238,12 @@ GList *account_get_list(void)
 
 void account_edit_open(void)
 {
-       inc_autocheck_timer_remove();
+       inc_lock();
 
        if (compose_get_compose_list()) {
                alertpanel_notice(_("Some composing windows are open.\n"
                                    "Please close all the composing windows before editing the accounts."));
-               inc_autocheck_timer_set();
+               inc_unlock();
                return;
        }
 
@@ -260,7 +266,6 @@ void account_add(void)
        PrefsAccount *ac_prefs;
 
        ac_prefs = prefs_account_open(NULL);
-       inc_autocheck_timer_remove();
 
        if (!ac_prefs) return;
 
@@ -426,6 +431,7 @@ static void account_edit_create(void)
                            GTK_SIGNAL_FUNC (manage_window_focus_in), NULL);
        gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
                            GTK_SIGNAL_FUNC (manage_window_focus_out), NULL);
+       gtk_widget_realize(window);
 
        vbox = gtk_vbox_new (FALSE, 12);
        gtk_widget_show (vbox);
@@ -443,20 +449,20 @@ static void account_edit_create(void)
                                        GTK_POLICY_AUTOMATIC,
                                        GTK_POLICY_AUTOMATIC);
 
-       titles[COL_DEFAULT]  = "";
+       titles[COL_DEFAULT]  = "D";
+       titles[COL_GETALL]   = "G";
        titles[COL_NAME]     = _("Name");
        titles[COL_PROTOCOL] = _("Protocol");
        titles[COL_SERVER]   = _("Server");
-        titles[COL_GETALL]   = _("Get all");
 
        clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
        gtk_widget_show (clist);
        gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
-       gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 16);
+       gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 10);
+       gtk_clist_set_column_width (GTK_CLIST(clist), COL_GETALL  , 10);
        gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME    , 100);
-       gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 70);
+       gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 100);
        gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER  , 100);
-       gtk_clist_set_column_width (GTK_CLIST(clist), COL_GETALL  , 20);
        gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
 
        for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
@@ -530,6 +536,8 @@ static void account_edit_create(void)
                            GTK_SIGNAL_FUNC (account_edit_close),
                            NULL);
 
+       PIXMAP_CREATE(clist, markxpm, markxpmmask, mark_xpm);
+
        edit_account.window    = window;
        edit_account.clist     = clist;
        edit_account.close_btn = close_btn;
@@ -551,7 +559,6 @@ static void account_edit_prefs(void)
        Xstrdup_a(ac_name, ac_prefs->account_name, return);
 
        prefs_account_open(ac_prefs);
-       inc_autocheck_timer_remove();
 
        if (!prev_default && ac_prefs->is_default)
                account_set_as_default(ac_prefs);
@@ -566,12 +573,34 @@ static void account_edit_prefs(void)
        account_clist_set();
 }
 
+static void account_delete_references_recursive(const GNode *node, const gint account)
+{
+       /* the son */
+       if (node->data) {
+               FolderItem *item = node->data;
+               if (item->prefs) /* && item->prefs->stype == F_NORMAL */
+                       if (item->prefs->default_account == account) {
+                               item->prefs->enable_default_account = FALSE;
+                               item->prefs->default_account = 0;
+                               prefs_folder_item_save_config(item);
+                       }
+       }
+       /* its children (vertical dive) */
+       if (node->children)
+               account_delete_references_recursive(node->children, account);
+       /* its brothers (horizontal dive) */
+       if (node->next)
+               account_delete_references_recursive(node->next, account);
+}
+
 static void account_delete(void)
 {
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        PrefsAccount *ac_prefs;
        gint row;
-
+       GList *list;
+       Folder *folder;
+       
        if (!clist->selection) return;
 
        if (alertpanel(_("Delete account"),
@@ -587,6 +616,14 @@ static void account_delete(void)
        }
        account_destroy(ac_prefs);
        account_clist_set();
+
+       debug_print(_("Removing deleted account references for all the folders...\n"));
+       list = folder_get_list();
+       for (; list != NULL; list = list->next) {
+               folder = FOLDER(list->data);
+               if (folder->node)  /* && folder->type == F_? */
+                       account_delete_references_recursive(folder->node, ac_prefs->account_id);
+       }
 }
 
 static void account_up(void)
@@ -645,6 +682,9 @@ static void account_set_recv_at_get_all(void)
 
        row = GPOINTER_TO_INT(clist->selection->data);
        ac_prefs = gtk_clist_get_row_data(clist, row);
+
+       if ((ac_prefs->protocol != A_POP3) && (ac_prefs->protocol != A_APOP)) return;
+       
        account_set_as_recv_at_get_all(ac_prefs);
        account_clist_set();
 }
@@ -665,7 +705,7 @@ static void account_edit_close(void)
 
        gtk_widget_hide(edit_account.window);
 
-       inc_autocheck_timer_set();
+       inc_unlock();
 }
 
 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
@@ -696,42 +736,47 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
        gchar *text[N_EDIT_ACCOUNT_COLS];
 
        text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
+       text[COL_GETALL] = (ac_prefs->protocol == A_POP3 ||
+                           ac_prefs->protocol == A_APOP) &&
+                           ac_prefs->recv_at_getall ? "*" : "";
        text[COL_NAME] = ac_prefs->account_name;
-#if !USE_SSL
-       text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
-                            ac_prefs->protocol == A_APOP  ? "APOP"  :
-                            ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
+#if USE_SSL
+       text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3 ?
+                            (ac_prefs->ssl_pop ? "POP3 (SSL)" : "POP3") :
+                            ac_prefs->protocol == A_APOP ?
+                            (ac_prefs->ssl_pop ?
+                             "POP3 (APOP, SSL)" : "POP3 (APOP)") :
+                            ac_prefs->protocol == A_IMAP4 ?
+                            (ac_prefs->ssl_imap ? "IMAP4 (SSL)" : "IMAP4") :
                             ac_prefs->protocol == A_LOCAL ? "Local" :
-                            ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
+                            ac_prefs->protocol == A_NNTP ? "NNTP"  :  "";
 #else
-       text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? (!ac_prefs->ssl_pop ? "POP3" : "POP3 (SSL)") :
-                            ac_prefs->protocol == A_APOP  ? (!ac_prefs->ssl_pop ? "APOP" : "APOP (SSL)") :
-                            ac_prefs->protocol == A_IMAP4 ? (!ac_prefs->ssl_imap ? "IMAP4" : "IMAP4 (SSL)") :
+       text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3" :
+                            ac_prefs->protocol == A_APOP  ? "POP3 (APOP)" :
+                            ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
                             ac_prefs->protocol == A_LOCAL ? "Local" :
-                            ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
+                            ac_prefs->protocol == A_NNTP  ? "NNTP" : "";
 #endif
        text[COL_SERVER] = ac_prefs->protocol == A_NNTP
                ? ac_prefs->nntp_server : ac_prefs->recv_server;
 
-       if (!ac_prefs->protocol == A_POP3) {
-       text[COL_GETALL] = ac_prefs->recv_at_getall == 1  ? _("No")  :
-                          ac_prefs->recv_at_getall == 0  ? _("No")   : "";
-        }
-        else {
-       text[COL_GETALL] = ac_prefs->recv_at_getall == 1  ? _("Yes")  :
-                          ac_prefs->recv_at_getall == 0  ? _("No")   : "";
-       }
-
        if (row < 0)
                row = gtk_clist_append(clist, text);
        else {
                gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
+               gtk_clist_set_text(clist, row, COL_GETALL, text[COL_GETALL]);
                gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
                gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
                gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
-               gtk_clist_set_text(clist, row, COL_GETALL, text[COL_GETALL]);
        }
 
+       if (*text[COL_DEFAULT])
+               gtk_clist_set_pixmap(clist, row, COL_DEFAULT,
+                                    markxpm, markxpmmask);
+       if (*text[COL_GETALL])
+               gtk_clist_set_pixmap(clist, row, COL_GETALL,
+                                    markxpm, markxpmmask);
+
        gtk_clist_set_row_data(clist, row, ac_prefs);
 
        return row;