added 'recieve at get all' to 'Edit accounts' window
[claws.git] / src / account.c
index a259c564388fa6f4310d7c604582725b36692304..fde067ad110cefb850ea66571cd177505998e486 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -49,10 +49,11 @@ typedef enum
        COL_DEFAULT     = 0,
        COL_NAME        = 1,
        COL_PROTOCOL    = 2,
        COL_DEFAULT     = 0,
        COL_NAME        = 1,
        COL_PROTOCOL    = 2,
-       COL_SERVER      = 3
+       COL_SERVER      = 3,
+        COL_GETALL      = 4
 } EditAccountColumnPos;
 
 } EditAccountColumnPos;
 
-# define N_EDIT_ACCOUNT_COLS   4
+# define N_EDIT_ACCOUNT_COLS   5
 
 #define PREFSBUFSIZE           1024
 
 
 #define PREFSBUFSIZE           1024
 
@@ -76,10 +77,17 @@ static void account_down            (void);
 
 static void account_set_default                (void);
 
 
 static void account_set_default                (void);
 
+static void account_set_recv_at_get_all        (void);
+
 static void account_edit_close         (void);
 static gint account_delete_event       (GtkWidget      *widget,
                                         GdkEventAny    *event,
                                         gpointer        data);
 static void account_edit_close         (void);
 static gint account_delete_event       (GtkWidget      *widget,
                                         GdkEventAny    *event,
                                         gpointer        data);
+static void account_selected           (GtkCList       *clist,
+                                        gint            row,
+                                        gint            column,
+                                        GdkEvent       *event,
+                                        gpointer        data);
 static void account_key_pressed                (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
 static void account_key_pressed                (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
@@ -167,23 +175,22 @@ PrefsAccount *account_find_from_smtp_server(const gchar *address,
        return NULL;
 }
 
        return NULL;
 }
 
-/**
- * account_find_mail_from_address:
+/*
+ * account_find_from_address:
  * @address: Email address string.
  * @address: Email address string.
- * 
+ *
  * Find a mail (not news) account with the specified email address.
  * Find a mail (not news) account with the specified email address.
- * 
+ *
  * Return value: The found account, or NULL if not found.
  * Return value: The found account, or NULL if not found.
- **/
-PrefsAccount *account_find_mail_from_address(const gchar *address)
+ */
+PrefsAccount *account_find_from_address(const gchar *address)
 {
        GList *cur;
        PrefsAccount *ac;
 
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
 {
        GList *cur;
        PrefsAccount *ac;
 
        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 && !strcmp2(address, ac->address))
                        return ac;
        }
 
                        return ac;
        }
 
@@ -226,11 +233,11 @@ GList *account_get_list(void)
 void account_edit_open(void)
 {
        inc_autocheck_timer_remove();
 void account_edit_open(void)
 {
        inc_autocheck_timer_remove();
-       
+
        if (compose_get_compose_list()) {
                alertpanel_notice(_("Some composing windows are open.\n"
                                    "Please close all the composing windows before editing the accounts."));
        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_autocheck_timer_set();
                return;
        }
 
                return;
        }
 
@@ -262,6 +269,9 @@ void account_add(void)
        if (ac_prefs->is_default)
                account_set_as_default(ac_prefs);
 
        if (ac_prefs->is_default)
                account_set_as_default(ac_prefs);
 
+       if (ac_prefs->recv_at_getall)
+               account_set_as_recv_at_get_all(ac_prefs);
+
        account_clist_set();
 
        if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
        account_clist_set();
 
        if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
@@ -274,10 +284,13 @@ void account_add(void)
                        folder = folder_new(F_NEWS, ac_prefs->account_name,
                                            ac_prefs->nntp_server);
                }
                        folder = folder_new(F_NEWS, ac_prefs->account_name,
                                            ac_prefs->nntp_server);
                }
+
                folder->account = ac_prefs;
                ac_prefs->folder = REMOTE_FOLDER(folder);
                folder_add(folder);
                folder->account = ac_prefs;
                ac_prefs->folder = REMOTE_FOLDER(folder);
                folder_add(folder);
-               folderview_update_all();
+               if (ac_prefs->protocol == A_IMAP4)
+                       folder->create_tree(folder);
+               folderview_set_all();
        }
 }
 
        }
 }
 
@@ -309,6 +322,24 @@ PrefsAccount *account_get_default(void)
        return NULL;
 }
 
        return NULL;
 }
 
+void account_set_as_recv_at_get_all(PrefsAccount *ac_prefs)
+{
+       PrefsAccount *ap;
+       GList *cur;
+
+       for (cur = account_list; cur != NULL; cur = cur->next) {
+               ap = (PrefsAccount *)cur->data;
+               if (ap->account_name == ac_prefs->account_name) {
+                       if (ap->recv_at_getall == 0)
+                               ap->recv_at_getall = 1;
+                       else
+                               ap->recv_at_getall = 0;
+               }
+        }
+
+}
+
+
 void account_set_missing_folder(void)
 {
        PrefsAccount *ap;
 void account_set_missing_folder(void)
 {
        PrefsAccount *ap;
@@ -327,9 +358,12 @@ void account_set_missing_folder(void)
                                folder = folder_new(F_NEWS, ap->account_name,
                                                    ap->nntp_server);
                        }
                                folder = folder_new(F_NEWS, ap->account_name,
                                                    ap->nntp_server);
                        }
+
                        folder->account = ap;
                        ap->folder = REMOTE_FOLDER(folder);
                        folder_add(folder);
                        folder->account = ap;
                        ap->folder = REMOTE_FOLDER(folder);
                        folder_add(folder);
+                       if (ap->protocol == A_IMAP4)
+                               folder->create_tree(folder);
                }
        }
 }
                }
        }
 }
@@ -372,6 +406,8 @@ static void account_edit_create(void)
 
        GtkWidget *default_btn;
 
 
        GtkWidget *default_btn;
 
+        GtkWidget *recvatgetall_btn;
+
        GtkWidget *hbbox;
        GtkWidget *close_btn;
 
        GtkWidget *hbbox;
        GtkWidget *close_btn;
 
@@ -411,6 +447,7 @@ static void account_edit_create(void)
        titles[COL_NAME]     = _("Name");
        titles[COL_PROTOCOL] = _("Protocol");
        titles[COL_SERVER]   = _("Server");
        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);
 
        clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
        gtk_widget_show (clist);
@@ -419,12 +456,16 @@ static void account_edit_create(void)
        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_SERVER  , 100);
        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_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++)
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
                                       GTK_CAN_FOCUS);
 
        gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
 
        for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
                                       GTK_CAN_FOCUS);
 
+       gtk_signal_connect (GTK_OBJECT (clist), "select_row",
+                           GTK_SIGNAL_FUNC (account_selected), NULL);
+
        vbox2 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox2);
        gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
        vbox2 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox2);
        gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
@@ -467,13 +508,19 @@ static void account_edit_create(void)
        gtk_widget_show (vbox2);
        gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
 
        gtk_widget_show (vbox2);
        gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
 
-       default_btn = gtk_button_new_with_label (_(" Set as usually used account "));
+       default_btn = gtk_button_new_with_label (_(" Set as default account "));
        gtk_widget_show (default_btn);
        gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
        gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
                            GTK_SIGNAL_FUNC (account_set_default), NULL);
 
        gtk_widget_show (default_btn);
        gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
        gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
                            GTK_SIGNAL_FUNC (account_set_default), NULL);
 
-       gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
+       recvatgetall_btn = gtk_button_new_with_label (_(" Enable/Disable 'Receive at Get all' "));
+       gtk_widget_show (recvatgetall_btn);
+       gtk_box_pack_start (GTK_BOX (vbox2), recvatgetall_btn, TRUE, FALSE, 0);
+       gtk_signal_connect (GTK_OBJECT(recvatgetall_btn), "clicked",
+                           GTK_SIGNAL_FUNC (account_set_recv_at_get_all), NULL);
+
+        gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
                                NULL, NULL, NULL, NULL);
        gtk_widget_show(hbbox);
        gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
                                NULL, NULL, NULL, NULL);
        gtk_widget_show(hbbox);
        gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
@@ -588,6 +635,20 @@ static void account_set_default(void)
        main_window_reflect_prefs_all();
 }
 
        main_window_reflect_prefs_all();
 }
 
+static void account_set_recv_at_get_all(void)
+{
+       GtkCList *clist = GTK_CLIST(edit_account.clist);
+       gint row;
+       PrefsAccount *ac_prefs;
+
+       if (!clist->selection) return;
+
+       row = GPOINTER_TO_INT(clist->selection->data);
+       ac_prefs = gtk_clist_get_row_data(clist, row);
+       account_set_as_recv_at_get_all(ac_prefs);
+       account_clist_set();
+}
+
 static void account_edit_close(void)
 {
        account_list_set();
 static void account_edit_close(void)
 {
        account_list_set();
@@ -614,6 +675,13 @@ static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
        return TRUE;
 }
 
        return TRUE;
 }
 
+static void account_selected(GtkCList *clist, gint row, gint column,
+                            GdkEvent *event, gpointer data)
+{
+       if (event && event->type == GDK_2BUTTON_PRESS)
+               account_edit_prefs();
+}
+
 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                gpointer data)
 {
 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                gpointer data)
 {
@@ -629,14 +697,31 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
 
        text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
        text[COL_NAME] = ac_prefs->account_name;
 
        text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
        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" :
                             ac_prefs->protocol == A_LOCAL ? "Local" :
                             ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
        text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
                             ac_prefs->protocol == A_APOP  ? "APOP"  :
                             ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
                             ac_prefs->protocol == A_LOCAL ? "Local" :
                             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)") :
+                            ac_prefs->protocol == A_LOCAL ? "Local" :
+                            ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
+#endif
        text[COL_SERVER] = ac_prefs->protocol == A_NNTP
                ? ac_prefs->nntp_server : ac_prefs->recv_server;
 
        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 {
        if (row < 0)
                row = gtk_clist_append(clist, text);
        else {
@@ -644,6 +729,7 @@ static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
                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_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]);
        }
 
        gtk_clist_set_row_data(clist, row, ac_prefs);
        }
 
        gtk_clist_set_row_data(clist, row, ac_prefs);
@@ -670,12 +756,16 @@ static void account_clist_set(void)
                gint row;
 
                row = account_clist_set_row((PrefsAccount *)cur->data, -1);
                gint row;
 
                row = account_clist_set_row((PrefsAccount *)cur->data, -1);
-               if ((PrefsAccount *)cur->data == cur_account)
+               if ((PrefsAccount *)cur->data == cur_account) {
                        gtk_clist_select_row(clist, row, -1);
                        gtk_clist_select_row(clist, row, -1);
+                       gtkut_clist_set_focus_row(clist, row);
+               }
        }
 
        }
 
-       if (prev_row >= 0)
+       if (prev_row >= 0) {
                gtk_clist_select_row(clist, prev_row, -1);
                gtk_clist_select_row(clist, prev_row, -1);
+               gtkut_clist_set_focus_row(clist, prev_row);
+       }
 
        gtk_clist_thaw(clist);
 }
 
        gtk_clist_thaw(clist);
 }