2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
34 #include "mainwindow.h"
35 #include "folderview.h"
38 #include "prefs_gtk.h"
39 #include "prefs_account.h"
40 #include "prefs_common.h"
41 #include "folder_item_prefs.h"
43 #include "manage_window.h"
44 #include "stock_pixmap.h"
48 #include "alertpanel.h"
49 #include "procheader.h"
50 #include "customheader.h"
51 #include "remotefolder.h"
53 #include "filtering.h"
56 ACCOUNT_IS_DEFAULT, /* GDK_TYPE_PIXMAP! */
57 ACCOUNT_ENABLE_GET_ALL,
73 } EditAccountColumnPos;
75 # define N_EDIT_ACCOUNT_COLS 5
77 #define PREFSBUFSIZE 1024
79 PrefsAccount *cur_account;
81 static GList *account_list = NULL;
82 static gboolean account_list_dirty = FALSE;
84 static struct EditAccount {
90 static GdkPixbuf *mark_pixbuf;
92 static void account_edit_create (void);
93 static void account_destroy (PrefsAccount *ac_prefs);
94 static void account_set_as_default (PrefsAccount *ac_prefs);
95 static void account_set_menu (void);
97 static void account_edit_prefs (GtkWidget *widget, gpointer data);
98 static void account_delete (GtkWidget *widget, gpointer data);
99 static void account_clone (GtkWidget *widget, gpointer data);
101 static void account_up (GtkWidget *widget, gpointer data);
102 static void account_down (GtkWidget *widget, gpointer data);
104 static void account_set_default (GtkWidget *widget, gpointer data);
106 static void account_edit_close (GtkWidget *widget, gpointer data);
108 static gint account_delete_event (GtkWidget *widget,
111 static void account_size_allocate_cb(GtkWidget *widget,
112 GtkAllocation *allocation);
113 static gboolean account_key_pressed (GtkWidget *widget,
117 static void account_list_view_add (PrefsAccount *ac_prefs);
118 static void account_list_view_set (void);
120 static void account_list_set (void);
122 typedef struct FindAccountInStore {
126 } FindAccountInStore;
128 static GtkListStore* account_create_data_store (void);
130 static void account_list_view_insert_account_item (GtkListStore *list_store,
131 const gchar *account_name,
132 const gchar *protocol,
133 const gchar *server_name,
136 PrefsAccount *account_data);
138 static GtkWidget *account_list_view_create (void);
139 static void account_create_list_view_images (GtkWidget *list_view);
140 static void account_create_list_view_columns (GtkWidget *list_view);
142 static gint account_list_view_get_selected_account_id (GtkWidget *list_view);
143 static GtkTreePath *account_list_view_get_selected_account_path (GtkWidget *list_view);
144 static PrefsAccount *account_list_view_get_selected_account (GtkWidget *list_view);
145 static gboolean account_list_view_select_account (GtkWidget *list_view,
148 static void account_list_view_set_default_by_id(GtkWidget *list_view,
151 static gboolean set_new_default_account (GtkTreeModel *model,
156 static gboolean find_account_in_store (GtkTreeModel *model,
159 FindAccountInStore *data);
161 static void account_get_all_toggled (GtkCellRendererToggle *widget,
163 GtkWidget *list_view);
165 static void account_double_clicked (GtkTreeView *list_view,
167 GtkTreeViewColumn *column,
170 static void drag_begin (GtkTreeView *list_view,
171 GdkDragContext *context,
174 static void drag_end (GtkTreeView *list_view,
175 GdkDragContext *context,
178 static void account_row_changed_while_drag_drop (GtkTreeModel *model,
182 GtkTreeView *list_view);
184 void account_flush_state(void)
187 main_window_reflect_prefs_all();
189 account_list_dirty = FALSE;
192 void account_read_config_all(void)
194 GSList *ac_label_list = NULL, *cur;
197 gchar buf[PREFSBUFSIZE];
198 PrefsAccount *ac_prefs;
200 debug_print("Reading all config for each account...\n");
202 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
203 if ((fp = g_fopen(rcpath, "rb")) == NULL) {
204 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
210 while (fgets(buf, sizeof(buf), fp) != NULL) {
211 if (!strncmp(buf, "[Account: ", 10)) {
213 memmove(buf, buf + 1, strlen(buf));
214 buf[strlen(buf) - 1] = '\0';
215 debug_print("Found label: %s\n", buf);
216 ac_label_list = g_slist_append(ac_label_list,
222 /* read config data from file */
224 for (cur = ac_label_list; cur != NULL; cur = cur->next) {
225 ac_prefs = prefs_account_new();
226 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
227 account_list = g_list_append(account_list, ac_prefs);
228 if (ac_prefs->is_default)
229 cur_account = ac_prefs;
231 /* if default is not set, assume first account as default */
232 if (!cur_account && account_list) {
233 ac_prefs = (PrefsAccount *)account_list->data;
234 account_set_as_default(ac_prefs);
235 cur_account = ac_prefs;
239 main_window_reflect_prefs_all_now();
241 while (ac_label_list) {
242 g_free(ac_label_list->data);
243 ac_label_list = g_slist_remove(ac_label_list,
244 ac_label_list->data);
248 void account_write_config_all(void)
250 prefs_account_write_config_all(account_list);
254 * account_find_all_from_address:
255 * @ac_list: initial list of accounts. NULL to create a new one.
256 * Accounts found in the @address will be appended to this list.
257 * @address: Email address string.
259 * Find all the mail (not news) accounts within the specified address.
261 * Return value: the original accounts list with the found accounts appended.
263 GList *account_find_all_from_address(GList *ac_list, const gchar *address)
271 for (cur = account_list; cur != NULL; cur = cur->next) {
272 ac = (PrefsAccount *)cur->data;
273 if (ac->protocol != A_NNTP && ac->address &&
274 strcasestr(address, ac->address) != NULL)
275 ac_list = g_list_append(ac_list, ac);
280 PrefsAccount *account_find_from_smtp_server(const gchar *address,
281 const gchar *smtp_server)
286 g_return_val_if_fail(address != NULL, NULL);
287 g_return_val_if_fail(smtp_server != NULL, NULL);
289 for (cur = account_list; cur != NULL; cur = cur->next) {
290 ac = (PrefsAccount *)cur->data;
291 if (!strcmp2(address, ac->address) &&
292 !strcmp2(smtp_server, ac->smtp_server))
300 * account_find_from_address:
301 * @address: Email address string.
303 * Find a mail (not news) account with the specified email address.
305 * Return value: The found account, or NULL if not found.
307 PrefsAccount *account_find_from_address(const gchar *address)
312 g_return_val_if_fail(address != NULL, NULL);
314 for (cur = account_list; cur != NULL; cur = cur->next) {
315 ac = (PrefsAccount *)cur->data;
316 if (ac->protocol != A_NNTP && ac->address &&
317 g_ascii_strcasecmp(address, ac->address) == 0)
324 PrefsAccount *account_find_from_id(gint id)
329 for (cur = account_list; cur != NULL; cur = cur->next) {
330 ac = (PrefsAccount *)cur->data;
331 if (id == ac->account_id)
338 PrefsAccount *account_find_from_item(FolderItem *item)
342 g_return_val_if_fail(item != NULL, NULL);
346 FolderItem *cur_item = folder_item_parent(item);
347 while (cur_item != NULL) {
348 if (cur_item->account && cur_item->apply_sub) {
349 ac = cur_item->account;
352 cur_item = folder_item_parent(cur_item);
356 ac = item->folder->account;
361 static void account_set_menu(void)
363 main_window_set_account_menu(account_list);
366 void account_set_menu_only_toolbar(void)
368 main_window_set_account_menu_only_toolbar(account_list);
371 GList *account_get_list(void)
376 void account_edit_open(void)
380 account_list_dirty = FALSE;
382 if (compose_get_compose_list()) {
383 alertpanel_error(_("Some composing windows are open.\n"
384 "Please close all the composing "
385 "windows before editing the accounts."));
390 debug_print("Opening account edit window...\n");
392 if (!edit_account.window)
393 account_edit_create();
395 account_list_view_set();
397 manage_window_set_transient(GTK_WINDOW(edit_account.window));
398 gtk_widget_grab_focus(edit_account.close_btn);
399 gtk_widget_show(edit_account.window);
401 manage_window_focus_in(edit_account.window, NULL, NULL);
404 void account_add(void)
406 PrefsAccount *ac_prefs;
408 ac_prefs = prefs_account_open(NULL, &account_list_dirty);
410 if (!ac_prefs) return;
412 account_list = g_list_append(account_list, ac_prefs);
414 if (ac_prefs->is_default)
415 account_set_as_default(ac_prefs);
417 account_list_view_set();
419 if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
422 if (ac_prefs->protocol == A_IMAP4) {
423 folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
424 ac_prefs->recv_server);
426 folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
427 ac_prefs->nntp_server);
429 if (folder == NULL) {
430 alertpanel_error(_("Can't create folder."));
433 folder->account = ac_prefs;
434 ac_prefs->folder = folder;
436 if (ac_prefs->protocol == A_IMAP4)
437 folder->klass->create_tree(folder);
438 folderview_set_all();
443 void account_open(PrefsAccount *ac_prefs)
445 gboolean prev_default;
447 gboolean account_dirty = FALSE;
449 g_return_if_fail(ac_prefs != NULL);
451 prev_default = ac_prefs->is_default;
452 Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
455 prefs_account_open(ac_prefs, &account_dirty);
458 if (!prev_default && ac_prefs->is_default)
459 account_set_as_default(ac_prefs);
461 if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
462 folder_set_name(FOLDER(ac_prefs->folder),
463 ac_prefs->account_name);
464 folderview_set_all();
467 account_write_config_all();
469 account_flush_state();
473 static void account_set_as_default(PrefsAccount *ac_prefs)
478 for (cur = account_list; cur != NULL; cur = cur->next) {
479 ap = (PrefsAccount *)cur->data;
481 ap->is_default = FALSE;
484 ac_prefs->is_default = TRUE;
487 PrefsAccount *account_get_default(void)
492 for (cur = account_list; cur != NULL; cur = cur->next) {
493 ap = (PrefsAccount *)cur->data;
501 void account_set_missing_folder(void)
506 for (cur = account_list; cur != NULL; cur = cur->next) {
507 ap = (PrefsAccount *)cur->data;
508 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
512 if (ap->protocol == A_IMAP4) {
513 folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
516 folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
521 folder->account = ap;
524 if (ap->protocol == A_IMAP4)
525 folder->klass->create_tree(folder);
532 #define CHECK_CHANGE_FOLDER(folder) { \
533 if (folder && !strncmp(folder, old_id, strlen(old_id))) { \
534 if (strlen(folder) == strlen(old_id)) { \
536 folder = g_strdup(new_id); \
537 } else if (strlen(folder) > strlen(old_id) \
538 && folder[strlen(old_id)] == G_DIR_SEPARATOR) { \
539 gchar *new_path = g_strdup_printf("%s%s", \
540 new_id, (folder + strlen(old_id))); \
547 void account_rename_path(const gchar *old_id, const gchar *new_id)
549 GList *cur = account_list;
550 for (; cur != NULL; cur = g_list_next(cur)) {
551 PrefsAccount *ap = (PrefsAccount *)cur->data;
552 CHECK_CHANGE_FOLDER(ap->inbox);
553 CHECK_CHANGE_FOLDER(ap->local_inbox);
554 CHECK_CHANGE_FOLDER(ap->queue_folder);
555 CHECK_CHANGE_FOLDER(ap->sent_folder);
556 CHECK_CHANGE_FOLDER(ap->draft_folder);
557 CHECK_CHANGE_FOLDER(ap->trash_folder);
561 #undef CHECK_CHANGE_FOLDER
563 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
564 SpecialFolderItemType type)
566 FolderItem *item = NULL;
568 g_return_val_if_fail(ac_prefs != NULL, NULL);
572 if (ac_prefs->folder)
573 item = FOLDER(ac_prefs->folder)->inbox;
575 item = folder_get_default_inbox();
578 if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
579 item = folder_find_item_from_identifier
580 (ac_prefs->sent_folder);
583 if (ac_prefs->folder)
584 item = FOLDER(ac_prefs->folder)->outbox;
586 item = folder_get_default_outbox_for_class(F_MH);
588 item = folder_get_default_outbox();
592 if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
593 item = folder_find_item_from_identifier
594 (ac_prefs->draft_folder);
597 if (ac_prefs->folder)
598 item = FOLDER(ac_prefs->folder)->draft;
600 item = folder_get_default_draft_for_class(F_MH);
602 item = folder_get_default_draft();
606 if (ac_prefs->set_queue_folder && ac_prefs->queue_folder) {
607 item = folder_find_item_from_identifier
608 (ac_prefs->queue_folder);
611 if (ac_prefs->folder)
612 item = FOLDER(ac_prefs->folder)->queue;
614 item = folder_get_default_queue_for_class(F_MH);
616 item = folder_get_default_queue();
620 if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
621 item = folder_find_item_from_identifier
622 (ac_prefs->trash_folder);
625 if (ac_prefs->folder)
626 item = FOLDER(ac_prefs->folder)->trash;
628 item = folder_get_default_trash_for_class(F_MH);
630 item = folder_get_default_trash();
640 void account_destroy(PrefsAccount *ac_prefs)
642 g_return_if_fail(ac_prefs != NULL);
644 folder_unref_account_all(ac_prefs);
646 prefs_account_free(ac_prefs);
647 account_list = g_list_remove(account_list, ac_prefs);
649 if (cur_account == ac_prefs) cur_account = NULL;
650 if (!cur_account && account_list) {
651 cur_account = account_get_default();
653 ac_prefs = (PrefsAccount *)account_list->data;
654 account_set_as_default(ac_prefs);
655 cur_account = ac_prefs;
661 *\brief Save Gtk object size to prefs dataset
663 static void account_size_allocate_cb(GtkWidget *widget,
664 GtkAllocation *allocation)
666 g_return_if_fail(allocation != NULL);
668 prefs_common.accountswin_width = allocation->width;
669 prefs_common.accountswin_height = allocation->height;
672 static void account_edit_create(void)
678 GtkWidget *scrolledwin;
679 GtkWidget *list_view;
685 GtkWidget *clone_btn;
689 GtkWidget *default_btn;
693 GtkWidget *close_btn;
695 static GdkGeometry geometry;
697 debug_print("Creating account edit window...\n");
699 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "account");
700 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
701 gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
702 gtk_window_set_modal (GTK_WINDOW (window), TRUE);
703 g_signal_connect (G_OBJECT (window), "delete_event",
704 G_CALLBACK (account_delete_event), NULL);
706 maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
708 g_signal_connect (G_OBJECT (window), "key_press_event",
709 G_CALLBACK (account_key_pressed), NULL);
711 MANAGE_WINDOW_SIGNALS_CONNECT (window);
712 gtk_widget_realize(window);
714 vbox = gtk_vbox_new (FALSE, 10);
715 gtk_widget_show (vbox);
716 gtk_container_add (GTK_CONTAINER (window), vbox);
718 hbox = gtk_hbox_new (FALSE, 0);
719 gtk_widget_show (hbox);
720 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
722 label = gtk_label_new
723 (_("Using 'Get Mail' will retrieve messages from your Accounts "
724 "in the order given, the checkbox in the 'G' column indicates "
725 "which accounts will be included."));
726 gtk_widget_show (label);
727 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
728 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
729 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
731 hbox = gtk_hbox_new (FALSE, 8);
732 gtk_widget_show (hbox);
733 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
734 gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
736 scrolledwin = gtk_scrolled_window_new (NULL, NULL);
737 gtk_widget_show (scrolledwin);
738 gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
739 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
740 GTK_POLICY_AUTOMATIC,
741 GTK_POLICY_AUTOMATIC);
743 list_view = account_list_view_create();
744 gtk_widget_show(list_view);
745 gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
747 vbox2 = gtk_vbox_new (FALSE, 0);
748 gtk_widget_show (vbox2);
749 gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
751 add_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
752 gtk_widget_show (add_btn);
753 gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
754 g_signal_connect (G_OBJECT(add_btn), "clicked",
755 G_CALLBACK (account_add), NULL);
757 edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
758 gtk_widget_show (edit_btn);
759 gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
760 g_signal_connect (G_OBJECT(edit_btn), "clicked",
761 G_CALLBACK (account_edit_prefs), NULL);
763 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
764 gtk_widget_show (del_btn);
765 gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
766 g_signal_connect (G_OBJECT(del_btn), "clicked",
767 G_CALLBACK (account_delete), NULL);
769 clone_btn = gtk_button_new_from_stock(GTK_STOCK_COPY);
770 gtk_widget_show (clone_btn);
771 gtk_box_pack_start (GTK_BOX (vbox2), clone_btn, FALSE, FALSE, 4);
772 g_signal_connect(G_OBJECT(clone_btn), "clicked",
773 G_CALLBACK(account_clone), NULL);
775 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
776 gtk_widget_show (down_btn);
777 gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
778 g_signal_connect (G_OBJECT(down_btn), "clicked",
779 G_CALLBACK (account_down), NULL);
781 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
782 gtk_widget_show (up_btn);
783 gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
784 g_signal_connect (G_OBJECT(up_btn), "clicked",
785 G_CALLBACK (account_up), NULL);
787 hbox = gtk_hbox_new (FALSE, 8);
788 gtk_widget_show (hbox);
789 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
791 vbox2 = gtk_vbox_new(FALSE, 0);
792 gtk_widget_show (vbox2);
793 gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
795 default_btn = gtk_button_new_with_mnemonic
796 (_(" _Set as default account "));
797 gtk_widget_show (default_btn);
798 gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
799 g_signal_connect (G_OBJECT(default_btn), "clicked",
800 G_CALLBACK (account_set_default), NULL);
802 hbbox = gtk_hbutton_box_new();
803 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
804 gtk_box_set_spacing(GTK_BOX(hbbox), 5);
806 gtkut_stock_button_set_create_with_help(&hbbox, &help_btn,
807 &close_btn, GTK_STOCK_CLOSE,
808 NULL, NULL, NULL, NULL);
809 gtk_widget_show(hbbox);
811 gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
812 gtk_widget_grab_default (close_btn);
814 g_signal_connect (G_OBJECT (close_btn), "clicked",
815 G_CALLBACK (account_edit_close),
817 g_signal_connect(G_OBJECT(help_btn), "clicked",
818 G_CALLBACK(manual_open_with_anchor_cb),
819 MANUAL_ANCHOR_ACCOUNTPREFS);
821 account_create_list_view_images(list_view);
823 g_signal_connect(G_OBJECT(window), "size_allocate",
824 G_CALLBACK(account_size_allocate_cb), NULL);
826 if (!geometry.min_height) {
827 geometry.min_width = 500;
828 geometry.min_height = 380;
831 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
833 gtk_widget_set_size_request(window, prefs_common.accountswin_width,
834 prefs_common.accountswin_height);
836 edit_account.window = window;
837 edit_account.list_view = list_view;
838 edit_account.close_btn = close_btn;
840 maemo_window_full_screen_if_needed(GTK_WINDOW(edit_account.window));
844 static void account_edit_prefs(GtkWidget *widget, gpointer data)
846 PrefsAccount *ac_prefs;
848 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
851 account_open(ac_prefs);
852 account_list_view_set();
856 static gboolean account_delete_references_func(GNode *node, gpointer data)
861 g_return_val_if_fail(node->data != NULL, FALSE);
863 item = FOLDER_ITEM(node->data);
864 account = GPOINTER_TO_INT(data);
866 if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
868 if(item->prefs->default_account != account)
871 item->prefs->enable_default_account = FALSE;
872 item->prefs->default_account = 0;
873 folder_item_prefs_save_config(item);
879 #define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
880 g_strdup(ac_prefs->fld): NULL
881 #define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
882 static void account_clone(GtkWidget *widget, gpointer data)
884 PrefsAccount *ac_prefs, *ac_clon;
886 CustomHeader *cch = NULL, *ch = NULL;
888 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
889 if (ac_prefs == NULL)
892 if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
893 alertpanel_error(_("Accounts with remote folders cannot be copied."));
896 account_list_dirty = TRUE;
898 ac_clon = prefs_account_new();
900 ac_clon->account_name = g_strdup_printf(_("Copy of %s"),
901 ac_prefs->account_name);
905 ACP_FDUP(organization);
908 ACP_FASSIGN(protocol);
909 ACP_FDUP(recv_server);
910 ACP_FDUP(smtp_server);
911 ACP_FDUP(nntp_server);
912 ACP_FASSIGN(use_nntp_auth);
913 ACP_FASSIGN(use_nntp_auth_onconnect);
917 ACP_FDUP(local_mbox);
918 ACP_FASSIGN(use_mail_command);
919 ACP_FDUP(mail_command);
921 ACP_FASSIGN(ssl_pop);
922 ACP_FASSIGN(ssl_imap);
923 ACP_FASSIGN(ssl_nntp);
924 ACP_FASSIGN(ssl_smtp);
925 ACP_FASSIGN(use_nonblocking_ssl);
927 ac_clon->tmp_pass = NULL;
930 ACP_FASSIGN(use_apop_auth);
932 ACP_FASSIGN(msg_leave_time);
933 ACP_FASSIGN(recv_at_getall);
934 ACP_FASSIGN(sd_rmmail_on_download);
935 ACP_FASSIGN(enable_size_limit);
936 ACP_FASSIGN(size_limit);
937 ACP_FASSIGN(filter_on_recv);
938 ACP_FASSIGN(filterhook_on_recv);
940 ACP_FDUP(local_inbox);
941 ACP_FASSIGN(max_articles);
943 ACP_FASSIGN(imap_auth_type);
946 ACP_FASSIGN(add_customhdr);
947 ACP_FASSIGN(use_smtp_auth);
948 ACP_FASSIGN(smtp_auth_type);
949 ACP_FDUP(smtp_userid);
950 ACP_FDUP(smtp_passwd);
952 ac_clon->tmp_smtp_pass = NULL;
954 ACP_FASSIGN(pop_before_smtp);
955 ACP_FASSIGN(pop_before_smtp_timeout);
956 ACP_FASSIGN(last_pop_login_time);
958 ac_clon->customhdr_list = NULL;
959 hdrs = ac_prefs->customhdr_list;
960 while (hdrs != NULL) {
961 ch = (CustomHeader *)hdrs->data;
963 cch = g_new0(CustomHeader, 1);
964 cch->account_id = ac_clon->account_id;
965 cch->name = (ch->name != NULL) ? g_strdup(ch->name) : NULL;
966 cch->value = (ch->value != NULL) ? g_strdup(ch->value) : NULL;
968 ac_clon->customhdr_list = g_slist_append(ac_clon->customhdr_list, cch);
970 hdrs = g_slist_next(hdrs);
974 ACP_FASSIGN(sig_type);
976 ACP_FASSIGN(auto_sig);
978 ACP_FASSIGN(set_autocc);
980 ACP_FASSIGN(set_autobcc);
982 ACP_FASSIGN(set_autoreplyto);
983 ACP_FDUP(auto_replyto);
984 ACP_FASSIGN(enable_default_dictionary);
985 ACP_FDUP(default_dictionary);
986 ACP_FASSIGN(enable_default_alt_dictionary);
987 ACP_FDUP(default_alt_dictionary);
988 ACP_FASSIGN(compose_with_format);
989 ACP_FDUP(compose_subject_format);
990 ACP_FDUP(compose_body_format);
991 ACP_FASSIGN(reply_with_format);
992 ACP_FDUP(reply_quotemark);
993 ACP_FDUP(reply_body_format);
994 ACP_FASSIGN(forward_with_format);
995 ACP_FDUP(forward_quotemark);
996 ACP_FDUP(forward_body_format);
999 ACP_FDUP(default_privacy_system);
1000 ACP_FASSIGN(default_encrypt);
1001 ACP_FASSIGN(default_encrypt_reply);
1002 ACP_FASSIGN(default_sign);
1003 ACP_FASSIGN(save_encrypted_as_clear_text);
1004 ACP_FASSIGN(encrypt_to_self);
1007 ACP_FASSIGN(set_smtpport);
1008 ACP_FASSIGN(smtpport);
1009 ACP_FASSIGN(set_popport);
1010 ACP_FASSIGN(popport);
1011 ACP_FASSIGN(set_imapport);
1012 ACP_FASSIGN(imapport);
1013 ACP_FASSIGN(set_nntpport);
1014 ACP_FASSIGN(nntpport);
1015 ACP_FASSIGN(set_domain);
1017 ACP_FASSIGN(mark_crosspost_read);
1018 ACP_FASSIGN(crosspost_col);
1020 ACP_FASSIGN(set_tunnelcmd);
1021 ACP_FDUP(tunnelcmd);
1024 ACP_FASSIGN(imap_subsonly);
1025 ACP_FASSIGN(low_bandwidth);
1027 ACP_FASSIGN(set_sent_folder);
1028 ACP_FDUP(sent_folder);
1029 ACP_FASSIGN(set_queue_folder);
1030 ACP_FDUP(queue_folder);
1031 ACP_FASSIGN(set_draft_folder);
1032 ACP_FDUP(draft_folder);
1033 ACP_FASSIGN(set_trash_folder);
1034 ACP_FDUP(trash_folder);
1035 /* don't want two default accounts */
1036 ac_clon->is_default = FALSE;
1037 ACP_FASSIGN(folder);
1039 account_list = g_list_append(account_list, ac_clon);
1040 account_list_view_set();
1045 static void account_delete(GtkWidget *widget, gpointer data)
1047 PrefsAccount *ac_prefs;
1048 gchar buf[BUFFSIZE];
1053 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
1054 if (ac_prefs == NULL)
1057 g_snprintf(buf, sizeof(buf),
1058 _("Do you really want to delete the account '%s'?"),
1059 ac_prefs->account_name ? ac_prefs->account_name :
1061 if (alertpanel_full(_("Delete account"), buf,
1062 GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
1063 NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE)
1065 account_list_dirty = TRUE;
1067 if (ac_prefs->folder) {
1070 item = mainwindow_get_mainwindow()->summaryview->folder_item;
1071 if (item && item->folder == FOLDER(ac_prefs->folder))
1072 summary_clear_all(mainwindow_get_mainwindow()->summaryview);
1073 folder_destroy(FOLDER(ac_prefs->folder));
1074 folderview_set_all();
1076 account_destroy(ac_prefs);
1077 account_list_view_set();
1079 debug_print("Removing deleted account references for all the folders...\n");
1080 list = folder_get_list();
1081 for (; list != NULL; list = list->next) {
1082 folder = FOLDER(list->data);
1083 if (folder->node) /* && folder->type == F_? */
1084 g_node_traverse(folder->node, G_PRE_ORDER,
1086 account_delete_references_func,
1087 GINT_TO_POINTER(ac_prefs->account_id));
1090 debug_print("Removing filter rules relative to this account...\n");
1091 for(cur = filtering_rules ; cur != NULL ;) {
1092 FilteringProp * prop = (FilteringProp *) cur->data;
1094 if (prop && (prop->account_id == ac_prefs->account_id)) {
1095 /* get next item before we kill the current one */
1096 cur = g_slist_next(cur);
1098 /* unallocate filteringprop and unchain it from the list */
1099 filteringprop_free(prop);
1100 filtering_rules = g_slist_remove(filtering_rules, prop);
1102 cur = g_slist_next(cur);
1105 folder_write_list();
1108 static void account_up(GtkWidget *widget, gpointer data)
1110 GtkTreePath *sel = account_list_view_get_selected_account_path
1111 (edit_account.list_view),
1113 GtkTreeIter isel, iup;
1114 GtkTreeModel *model = gtk_tree_view_get_model
1115 (GTK_TREE_VIEW(edit_account.list_view));
1119 account_list_dirty = TRUE;
1121 up = gtk_tree_path_copy(sel);
1123 gtk_tree_path_free(sel);
1127 if (!gtk_tree_path_prev(up)) {
1128 gtk_tree_path_free(up);
1129 gtk_tree_path_free(sel);
1133 if (!gtk_tree_model_get_iter(model, &isel, sel)
1134 || !gtk_tree_model_get_iter(model, &iup, up)) {
1135 gtk_tree_path_free(up);
1136 gtk_tree_path_free(sel);
1140 gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &iup);
1144 gtk_tree_path_free(up);
1145 gtk_tree_path_free(sel);
1148 static void account_down(GtkWidget *widget, gpointer data)
1150 GtkTreePath *sel = account_list_view_get_selected_account_path
1151 (edit_account.list_view),
1153 GtkTreeIter isel, idn;
1154 GtkTreeModel *model = gtk_tree_view_get_model
1155 (GTK_TREE_VIEW(edit_account.list_view));
1159 account_list_dirty = TRUE;
1161 dn = gtk_tree_path_copy(sel);
1163 gtk_tree_path_free(sel);
1167 /* XXX no check possible??? however, if down but at bottom, then
1168 * nothing seems to happen much anyway, so the following seems to
1170 gtk_tree_path_next(dn);
1172 if (!gtk_tree_model_get_iter(model, &isel, sel)
1173 || !gtk_tree_model_get_iter(model, &idn, dn)) {
1174 gtk_tree_path_free(dn);
1175 gtk_tree_path_free(sel);
1179 gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &idn);
1183 gtk_tree_path_free(dn);
1184 gtk_tree_path_free(sel);
1187 static void account_set_default(GtkWidget *widget, gpointer data)
1189 PrefsAccount *ac_prefs;
1191 if (NULL == (ac_prefs = account_list_view_get_selected_account
1192 (edit_account.list_view)))
1195 /* we need to change the store variables by resetting everything
1196 * and setting the new default one */
1197 account_list_view_set_default_by_id(edit_account.list_view,
1198 ac_prefs->account_id);
1200 account_set_as_default(ac_prefs);
1201 account_list_view_set();
1203 cur_account = ac_prefs;
1204 account_flush_state();
1207 static void account_edit_close(GtkWidget *widget, gpointer data)
1210 account_write_config_all();
1212 if (!cur_account && account_list) {
1213 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
1214 account_set_as_default(ac_prefs);
1215 cur_account = ac_prefs;
1218 if (account_list_dirty)
1219 account_flush_state();
1221 gtk_widget_hide(edit_account.window);
1226 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
1229 account_edit_close(NULL, NULL);
1233 static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
1236 if (event && event->keyval == GDK_Escape)
1237 account_edit_close(NULL, NULL);
1241 static void account_list_view_add(PrefsAccount *ac_prefs)
1243 GtkTreeView *list_view = GTK_TREE_VIEW(edit_account.list_view);
1244 GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
1245 gchar *name, *protocol, *server;
1246 gboolean has_getallbox;
1249 name = ac_prefs->account_name;
1251 protocol = ac_prefs->protocol == A_POP3 ?
1252 (ac_prefs->ssl_pop == SSL_TUNNEL ?
1254 ac_prefs->ssl_pop == SSL_STARTTLS ?
1255 "POP3 (TLS)" : "POP3") :
1256 ac_prefs->protocol == A_IMAP4 ?
1257 (ac_prefs->ssl_imap == SSL_TUNNEL ?
1259 ac_prefs->ssl_imap == SSL_STARTTLS ?
1260 "IMAP4 (TLS)" : "IMAP4") :
1261 ac_prefs->protocol == A_NNTP ?
1262 (ac_prefs->ssl_nntp == SSL_TUNNEL ?
1263 "NNTP (SSL)" : "NNTP") :
1264 ac_prefs->protocol == A_LOCAL ? "Local" :
1265 ac_prefs->protocol == A_NONE ? "SMTP" : "-";
1267 protocol = ac_prefs->protocol == A_POP3 ? "POP3" :
1268 ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
1269 ac_prefs->protocol == A_LOCAL ? "Local" :
1270 ac_prefs->protocol == A_NNTP ? "NNTP" :
1271 ac_prefs->protocol == A_NONE ? "SMTP" : "-";
1273 server= ac_prefs->protocol == A_NNTP ? ac_prefs->nntp_server :
1274 ac_prefs->protocol == A_LOCAL ? "-" :
1275 ac_prefs->protocol == A_NONE ? ac_prefs->smtp_server :
1276 ac_prefs->recv_server;
1278 has_getallbox = (ac_prefs->protocol == A_POP3 ||
1279 ac_prefs->protocol == A_IMAP4 ||
1280 ac_prefs->protocol == A_NNTP ||
1281 ac_prefs->protocol == A_LOCAL);
1282 getall = has_getallbox && ac_prefs->recv_at_getall;
1284 account_list_view_insert_account_item(list_store,
1285 name, protocol, server,
1286 ac_prefs->is_default,
1291 static void account_list_view_set(void)
1294 gint prev_sel_account;
1295 GtkListStore *store;
1297 store = GTK_LIST_STORE(gtk_tree_view_get_model
1298 (GTK_TREE_VIEW(edit_account.list_view)));
1300 prev_sel_account = account_list_view_get_selected_account_id
1301 (edit_account.list_view);
1303 gtk_list_store_clear(store);
1305 for (cur = account_list; cur != NULL; cur = cur->next) {
1306 account_list_view_add((PrefsAccount *)cur->data);
1307 if ((PrefsAccount *)cur->data == cur_account)
1308 account_list_view_select_account
1309 (edit_account.list_view,
1310 cur_account->account_id);
1313 if (prev_sel_account >= 0)
1314 account_list_view_select_account(edit_account.list_view,
1318 /* set account list from CList */
1319 static void account_list_set(void)
1321 /* want to make sure we iterate *IN ORDER*, so therefore using
1322 * gtk_tree_model_XXXX_nth_child() */
1324 PrefsAccount *ac_prefs;
1325 GtkTreeModel *model = gtk_tree_view_get_model
1326 (GTK_TREE_VIEW(edit_account.list_view));
1328 while (account_list)
1329 account_list = g_list_remove(account_list, account_list->data);
1331 n_rows = gtk_tree_model_iter_n_children(model, NULL);
1333 for (row = 0; row < n_rows; row++) {
1336 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
1337 g_warning("%s(%d) - no iter found???\n", __FILE__, __LINE__);
1342 gtk_tree_model_get(model, &iter,
1343 ACCOUNT_DATA, &ac_prefs,
1346 account_list = g_list_append(account_list, ac_prefs);
1351 *\brief finds the PrefsAccounts which should be used to answer a mail
1353 *\param msginfo The message to be answered
1354 *\param reply_autosel Indicates whether reply account autoselection is on
1356 *\return PrefsAccount * the correct account, NULL if not found
1358 PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
1360 PrefsAccount *account = NULL;
1361 /* select the account set in folderitem's property (if enabled) */
1362 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
1363 account = account_find_from_id(msginfo->folder->prefs->default_account);
1365 /* select account by to: and cc: header if enabled */
1366 if (reply_autosel) {
1367 gchar * field = NULL;
1369 for (field = msginfo->to; fieldno++ < 2; field = msginfo->cc) {
1370 if (!account && field) {
1372 if (!strchr(field, ',')) {
1373 Xstrdup_a(to, field, return NULL);
1374 extract_address(to);
1375 account = account_find_from_address(to);
1377 gchar **split = g_strsplit(field, ",", -1);
1383 Xstrdup_a(to, split[i], return NULL);
1384 extract_address(to);
1385 account = account_find_from_address(to);
1392 gchar deliveredto[BUFFSIZE];
1393 if (!procheader_get_header_from_msginfo
1394 (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) {
1395 gchar *buf = deliveredto + strlen("Delivered-To:");
1396 extract_address(buf);
1397 account = account_find_from_address(buf);
1402 /* select the account for the whole folder (IMAP / NNTP) */
1404 /* FIXME: this is not right, because folder may be nested. we should
1405 * ascend the tree until we find a parent with proper account
1407 account = msginfo->folder->folder->account;
1409 /* select current account */
1410 if (!account) account = cur_account;
1416 *\brief Create data store
1418 static GtkListStore* account_create_data_store(void)
1420 return gtk_list_store_new(N_ACCOUNT_COLUMNS,
1421 GDK_TYPE_PIXBUF, /* ACCOUNT_IS_DEFAULT */
1422 G_TYPE_BOOLEAN, /* ACCOUNT_ENABLE_GET_ALL */
1423 G_TYPE_STRING, /* ACCOUNT_NAME */
1424 G_TYPE_STRING, /* ACCOUNT_PROTOCOL */
1425 G_TYPE_STRING, /* ACCOUNT_SERVER */
1426 G_TYPE_POINTER, /* ACCOUNT_DATA */
1431 *\brief Insert an account item in the list.
1433 *\return GtkTreeRowReference * A tree row reference, which is guaranteed to
1434 * stable whatever operations are performed on the list.
1436 static void account_list_view_insert_account_item(GtkListStore *list_store,
1437 const gchar *account_name,
1438 const gchar *protocol,
1439 const gchar *server_name,
1440 gboolean is_default,
1441 gboolean is_get_all,
1442 PrefsAccount *account_data)
1446 gtk_list_store_append(list_store, &iter);
1447 gtk_list_store_set(list_store, &iter,
1448 ACCOUNT_IS_DEFAULT, is_default ? mark_pixbuf : NULL,
1449 ACCOUNT_ENABLE_GET_ALL, is_get_all,
1450 ACCOUNT_NAME, account_name,
1451 ACCOUNT_PROTOCOL, protocol,
1452 ACCOUNT_SERVER, server_name,
1453 ACCOUNT_DATA, account_data,
1458 *\brief Create and set up account list view, including tasks like
1459 * creating the data store (\ref account_create_data_store()),
1460 * creating images for the list view (\ref account_create_list_view_images()),
1461 * and setting up the account list's individual columns (\ref
1462 * account_create_list_view_columns()).
1464 *\return GtkWidget * The created list view widget.
1466 static GtkWidget *account_list_view_create(void)
1468 GtkTreeView *list_view;
1469 GtkTreeSelection *selector;
1470 GtkListStore *store = account_create_data_store();
1472 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1473 g_object_unref(G_OBJECT(store));
1475 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1476 gtk_tree_view_set_reorderable(list_view, TRUE);
1478 selector = gtk_tree_view_get_selection(list_view);
1479 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1481 /* create the columns */
1482 account_create_list_view_columns(GTK_WIDGET(list_view));
1484 /* set a double click listener */
1485 g_signal_connect(G_OBJECT(list_view), "row_activated",
1486 G_CALLBACK(account_double_clicked),
1489 g_signal_connect(G_OBJECT(list_view), "drag_begin",
1490 G_CALLBACK(drag_begin),
1493 g_signal_connect(G_OBJECT(list_view), "drag_end",
1494 G_CALLBACK(drag_end),
1497 gtk_tree_view_set_reorderable(list_view, TRUE);
1498 return GTK_WIDGET(list_view);
1501 static void account_create_list_view_images(GtkWidget *list_view)
1503 stock_pixbuf_gdk(list_view, STOCK_PIXMAP_MARK, &mark_pixbuf);
1506 static void account_create_list_view_columns(GtkWidget *list_view)
1508 GtkTreeViewColumn *column;
1509 GtkCellRenderer *renderer;
1510 GtkTooltips *tooltips = gtk_tooltips_new();
1512 renderer = gtk_cell_renderer_pixbuf_new();
1513 column = gtk_tree_view_column_new_with_attributes
1514 (Q_("Accounts List Default Column Name|D"), renderer,
1515 "pixbuf", ACCOUNT_IS_DEFAULT,
1517 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1518 gtk_tree_view_column_set_alignment (column, 0.5);
1519 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), column->button,
1520 _("Default account"), NULL);
1522 renderer = gtk_cell_renderer_toggle_new();
1523 g_object_set(renderer,
1525 "activatable", TRUE,
1527 column = gtk_tree_view_column_new_with_attributes
1528 (Q_("Accounts List Get Column Name|G"), renderer,
1529 "active", ACCOUNT_ENABLE_GET_ALL,
1531 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1532 gtk_tree_view_column_set_alignment (column, 0.5);
1533 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), column->button,
1534 _("'Get Mail' retrieves mail from the checked accounts"), NULL);
1535 g_signal_connect(G_OBJECT(renderer), "toggled",
1536 G_CALLBACK(account_get_all_toggled),
1539 renderer = gtk_cell_renderer_text_new();
1540 column = gtk_tree_view_column_new_with_attributes
1541 (_("Name"), renderer,
1542 "text", ACCOUNT_NAME,
1544 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1546 renderer = gtk_cell_renderer_text_new();
1547 column = gtk_tree_view_column_new_with_attributes
1548 (_("Protocol"), renderer,
1549 "text", ACCOUNT_PROTOCOL,
1551 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1553 renderer = gtk_cell_renderer_text_new();
1554 column = gtk_tree_view_column_new_with_attributes
1555 (_("Server"), renderer,
1556 "text", ACCOUNT_SERVER,
1558 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1562 *\brief Get currently selected account (by its unique ID)
1564 static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
1566 GtkTreeSelection *selector;
1567 GtkTreeModel *model;
1569 PrefsAccount *res = NULL;
1571 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1573 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1576 gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1578 return res->account_id;
1582 *\brief Get the tree path of the currently selected account
1584 static GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_view)
1586 GtkTreeSelection *selector;
1587 GtkTreeModel *model;
1590 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1592 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1595 return gtk_tree_model_get_path(gtk_tree_view_get_model
1596 (GTK_TREE_VIEW(list_view)), &iter);
1600 *\brief Get the account data of the currently selected account
1602 static PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
1604 GtkTreeSelection *selector;
1605 GtkTreeModel *model;
1607 PrefsAccount *res = NULL;
1609 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1611 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1614 gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1620 *\brief Select a row by the account it represents
1622 *\return gboolean TRUE if found and selected, FALSE if not.
1624 static gboolean account_list_view_select_account(GtkWidget *list_view, gint account_id)
1626 FindAccountInStore fis;
1627 GtkTreeModel *model;
1629 fis.account_id = account_id;
1632 model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1634 gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc) find_account_in_store,
1638 GtkTreeSelection *selection;
1641 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1642 gtk_tree_selection_select_iter(selection, &fis.iter);
1643 path = gtk_tree_model_get_path(model, &fis.iter);
1644 /* XXX returned path may not be valid??? create new one to be sure */
1645 gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view), path, NULL, FALSE);
1646 gtk_tree_path_free(path);
1649 return fis.path != NULL;
1653 *\brief Set a new default account by its ID. (There is only one
1656 static void account_list_view_set_default_by_id(GtkWidget *list_view,
1659 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1661 gtk_tree_model_foreach
1662 (model, (GtkTreeModelForeachFunc) set_new_default_account,
1666 static gboolean set_new_default_account(GtkTreeModel *model,
1671 PrefsAccount *account = NULL;
1674 gtk_tree_model_get(model, iter,
1675 ACCOUNT_DATA, &account,
1678 if (*account_id == account->account_id)
1681 pixbuf = mark_pixbuf;
1683 gtk_list_store_set(GTK_LIST_STORE(model), iter,
1684 ACCOUNT_IS_DEFAULT, pixbuf,
1690 static gboolean find_account_in_store(GtkTreeModel *model,
1693 FindAccountInStore *data)
1695 PrefsAccount *account = NULL;
1696 gtk_tree_model_get(model, iter, ACCOUNT_DATA, &account, -1);
1698 if (data->account_id == account->account_id) {
1699 data->path = path; /* signal we found it */
1708 *\brief Triggered when "get all" column is activated or de-activated
1710 static void account_get_all_toggled(GtkCellRendererToggle *widget,
1712 GtkWidget *list_view)
1715 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1716 PrefsAccount *ac = NULL;
1719 if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
1722 gtk_tree_model_get(model, &iter,
1724 ACCOUNT_ENABLE_GET_ALL, &get_all,
1727 /* check if the account has a selectable get all checkbox anyway... */
1728 if (!(ac->protocol == A_POP3 ||
1729 ac->protocol == A_IMAP4 ||
1730 ac->protocol == A_NNTP ||
1731 ac->protocol == A_LOCAL))
1734 /* set value in store */
1735 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
1736 ACCOUNT_ENABLE_GET_ALL, !get_all,
1739 /* set value in account */
1740 ac->recv_at_getall ^= TRUE;
1743 static void account_double_clicked(GtkTreeView *list_view,
1745 GtkTreeViewColumn *column,
1748 account_edit_prefs(NULL, NULL);
1751 static void drag_begin(GtkTreeView *list_view,
1752 GdkDragContext *context,
1755 /* XXX unfortunately a completed drag & drop does not emit
1756 * a "rows_reordered" signal, but a "row_changed" signal.
1757 * So during drag and drop, listen to "row_changed", and
1758 * update the account list accordingly */
1760 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1761 g_signal_connect(G_OBJECT(model), "row_changed",
1762 G_CALLBACK(account_row_changed_while_drag_drop),
1766 static void drag_end(GtkTreeView *list_view,
1767 GdkDragContext *context,
1770 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1771 g_signal_handlers_disconnect_by_func(G_OBJECT(model),
1772 G_CALLBACK(account_row_changed_while_drag_drop),
1776 static void account_row_changed_while_drag_drop(GtkTreeModel *model,
1780 GtkTreeView *list_view)