2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2013 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/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
30 #include <gdk/gdkkeysyms.h>
35 #include "mainwindow.h"
36 #include "folderview.h"
39 #include "prefs_gtk.h"
40 #include "prefs_account.h"
41 #include "prefs_common.h"
42 #include "folder_item_prefs.h"
44 #include "manage_window.h"
45 #include "stock_pixmap.h"
49 #include "alertpanel.h"
50 #include "procheader.h"
51 #include "customheader.h"
52 #include "remotefolder.h"
54 #include "filtering.h"
55 #include "prefs_actions.h"
59 ACCOUNT_ENABLE_GET_ALL,
75 } EditAccountColumnPos;
77 # define N_EDIT_ACCOUNT_COLS 5
79 PrefsAccount *cur_account;
81 static GList *account_list = NULL;
82 static gboolean account_list_dirty = FALSE;
84 static struct EditAccount {
90 static void account_edit_create (void);
91 static void account_destroy (PrefsAccount *ac_prefs);
92 static void account_set_as_default (PrefsAccount *ac_prefs);
93 static void account_set_menu (void);
95 static void account_edit_prefs (GtkWidget *widget, gpointer data);
96 static void account_delete (GtkWidget *widget, gpointer data);
97 static void account_clone (GtkWidget *widget, gpointer data);
99 static void account_up (GtkWidget *widget, gpointer data);
100 static void account_down (GtkWidget *widget, gpointer data);
102 static void account_set_default (GtkWidget *widget, gpointer data);
104 static void account_edit_close (GtkWidget *widget, gpointer data);
106 static gint account_delete_event (GtkWidget *widget,
109 static void account_size_allocate_cb(GtkWidget *widget,
110 GtkAllocation *allocation);
111 static gboolean account_key_pressed (GtkWidget *widget,
114 static gboolean account_search_func_cb (GtkTreeModel *model, gint column,
115 const gchar *key, GtkTreeIter *iter,
116 gpointer search_data);
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_columns (GtkWidget *list_view);
141 static gint account_list_view_get_selected_account_id (GtkWidget *list_view);
142 static GtkTreePath *account_list_view_get_selected_account_path (GtkWidget *list_view);
143 static PrefsAccount *account_list_view_get_selected_account (GtkWidget *list_view);
144 static gboolean account_list_view_select_account (GtkWidget *list_view,
147 static void account_list_view_set_default_by_id(GtkWidget *list_view,
150 static gboolean set_new_default_account (GtkTreeModel *model,
155 static gboolean find_account_in_store (GtkTreeModel *model,
158 FindAccountInStore *data);
160 static void account_get_all_toggled (GtkCellRendererToggle *widget,
162 GtkWidget *list_view);
164 static void account_double_clicked (GtkTreeView *list_view,
166 GtkTreeViewColumn *column,
169 static void drag_begin (GtkTreeView *list_view,
170 GdkDragContext *context,
173 static void drag_end (GtkTreeView *list_view,
174 GdkDragContext *context,
177 static void account_row_changed_while_drag_drop (GtkTreeModel *model,
181 GtkTreeView *list_view);
183 static void account_flush_state(void)
186 main_window_reflect_prefs_all();
188 account_list_dirty = FALSE;
191 void account_read_config_all(void)
193 GSList *ac_label_list = NULL, *cur;
196 gchar buf[PREFSBUFSIZE];
197 PrefsAccount *ac_prefs;
199 debug_print("Reading all config for each account...\n");
201 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
202 if ((fp = g_fopen(rcpath, "rb")) == NULL) {
203 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
209 while (fgets(buf, sizeof(buf), fp) != NULL) {
210 if (!strncmp(buf, "[Account: ", 10)) {
212 memmove(buf, buf + 1, strlen(buf));
213 buf[strlen(buf) - 1] = '\0';
214 debug_print("Found label: %s\n", buf);
215 ac_label_list = g_slist_append(ac_label_list,
221 /* read config data from file */
223 for (cur = ac_label_list; cur != NULL; cur = cur->next) {
224 ac_prefs = prefs_account_new();
225 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
226 account_list = g_list_append(account_list, ac_prefs);
227 if (ac_prefs->is_default)
228 cur_account = ac_prefs;
230 /* if default is not set, assume first account as default */
231 if (!cur_account && account_list) {
232 ac_prefs = (PrefsAccount *)account_list->data;
233 account_set_as_default(ac_prefs);
234 cur_account = ac_prefs;
238 main_window_reflect_prefs_all_now();
240 while (ac_label_list) {
241 g_free(ac_label_list->data);
242 ac_label_list = g_slist_remove(ac_label_list,
243 ac_label_list->data);
247 void account_write_config_all(void)
249 prefs_account_write_config_all(account_list);
253 * account_find_all_from_address:
254 * @ac_list: initial list of accounts. NULL to create a new one.
255 * Accounts found in the @address will be appended to this list.
256 * @address: Email address string.
258 * Find all the mail (not news) accounts within the specified address.
260 * Return value: the original accounts list with the found accounts appended.
262 GList *account_find_all_from_address(GList *ac_list, const gchar *address)
270 for (cur = account_list; cur != NULL; cur = cur->next) {
271 ac = (PrefsAccount *)cur->data;
272 if (ac->protocol != A_NNTP && ac->address &&
273 strcasestr(address, ac->address) != NULL)
274 ac_list = g_list_append(ac_list, ac);
279 PrefsAccount *account_find_from_smtp_server(const gchar *address,
280 const gchar *smtp_server)
285 cm_return_val_if_fail(address != NULL, NULL);
286 cm_return_val_if_fail(smtp_server != NULL, NULL);
288 for (cur = account_list; cur != NULL; cur = cur->next) {
289 ac = (PrefsAccount *)cur->data;
290 if (!strcmp2(address, ac->address) &&
291 !strcmp2(smtp_server, ac->smtp_server))
299 * account_find_from_address:
300 * @address: Email address string.
302 * Find a mail (not news if newsgroups_ok is FALSE) account with the specified email address.
304 * Return value: The found account, or NULL if not found.
306 PrefsAccount *account_find_from_address(const gchar *address, gboolean newsgroups_ok)
311 cm_return_val_if_fail(address != NULL, NULL);
313 for (cur = account_list; cur != NULL; cur = cur->next) {
314 ac = (PrefsAccount *)cur->data;
315 if ((ac->protocol != A_NNTP || newsgroups_ok) && ac->address &&
316 g_ascii_strcasecmp(address, ac->address) == 0)
323 PrefsAccount *account_find_from_id(gint id)
328 for (cur = account_list; cur != NULL; cur = cur->next) {
329 ac = (PrefsAccount *)cur->data;
330 if (id == ac->account_id)
337 PrefsAccount *account_find_from_item(FolderItem *item)
341 cm_return_val_if_fail(item != NULL, NULL);
345 FolderItem *cur_item = folder_item_parent(item);
346 while (cur_item != NULL) {
347 if (cur_item->account && cur_item->apply_sub) {
348 ac = cur_item->account;
351 cur_item = folder_item_parent(cur_item);
355 ac = item->folder->account;
360 static void account_set_menu(void)
362 main_window_set_account_menu(account_list);
365 void account_set_menu_only_toolbar(void)
367 main_window_set_account_menu_only_toolbar(account_list);
370 GList *account_get_list(void)
375 void account_edit_focus(void)
377 manage_window_set_transient(GTK_WINDOW(edit_account.window));
378 gtk_widget_grab_focus(edit_account.close_btn);
379 gtk_widget_show(edit_account.window);
380 gtk_window_set_modal(GTK_WINDOW(edit_account.window), TRUE);
381 manage_window_focus_in(edit_account.window, NULL, NULL);
384 void account_edit_open(gpointer a, gpointer b)
388 account_list_dirty = FALSE;
390 if (compose_get_compose_list()) {
391 alertpanel_error(_("Some composing windows are open.\n"
392 "Please close all the composing "
393 "windows before editing the accounts."));
398 debug_print("Opening account edit window...\n");
400 if (!edit_account.window)
401 account_edit_create();
403 account_list_view_set();
405 account_edit_focus();
408 void account_add(void)
410 PrefsAccount *ac_prefs;
412 ac_prefs = prefs_account_open(NULL, &account_list_dirty);
414 if (!ac_prefs) return;
416 account_edit_focus();
418 account_list = g_list_append(account_list, ac_prefs);
420 if (ac_prefs->is_default)
421 account_set_as_default(ac_prefs);
423 account_list_view_set();
425 if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
428 if (ac_prefs->protocol == A_IMAP4) {
429 folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
430 ac_prefs->recv_server);
432 folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
433 ac_prefs->nntp_server);
435 if (folder == NULL) {
436 alertpanel_error(_("Can't create folder."));
439 folder->account = ac_prefs;
440 ac_prefs->folder = folder;
442 if (ac_prefs->protocol == A_IMAP4)
443 folder->klass->create_tree(folder);
444 folderview_set_all();
449 void account_open(PrefsAccount *ac_prefs)
451 gboolean prev_default;
452 gchar *ac_name, *old_prefix, *new_prefix;
453 gboolean account_dirty = FALSE;
455 cm_return_if_fail(ac_prefs != NULL);
457 prev_default = ac_prefs->is_default;
458 Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
461 prefs_account_open(ac_prefs, &account_dirty);
463 account_edit_focus();
466 if (!prev_default && ac_prefs->is_default)
467 account_set_as_default(ac_prefs);
469 if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
470 old_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
471 folder_set_name(FOLDER(ac_prefs->folder),
472 ac_prefs->account_name);
473 folderview_set_all();
474 folder_prefs_save_config_recursive(FOLDER(ac_prefs->folder));
475 new_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
477 account_rename_path(old_prefix, new_prefix);
478 prefs_filtering_rename_path(old_prefix, new_prefix);
479 prefs_actions_rename_path(old_prefix, new_prefix);
485 account_write_config_all();
487 account_flush_state();
491 static void account_set_as_default(PrefsAccount *ac_prefs)
496 for (cur = account_list; cur != NULL; cur = cur->next) {
497 ap = (PrefsAccount *)cur->data;
499 ap->is_default = FALSE;
502 ac_prefs->is_default = TRUE;
505 PrefsAccount *account_get_default(void)
510 for (cur = account_list; cur != NULL; cur = cur->next) {
511 ap = (PrefsAccount *)cur->data;
519 void account_set_missing_folder(void)
524 for (cur = account_list; cur != NULL; cur = cur->next) {
525 ap = (PrefsAccount *)cur->data;
526 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
530 if (ap->protocol == A_IMAP4) {
531 folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
534 folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
539 folder->account = ap;
542 if (ap->protocol == A_IMAP4)
543 folder->klass->create_tree(folder);
550 #define CHECK_CHANGE_FOLDER(folder) { \
551 if (folder && !strncmp(folder, old_id, strlen(old_id))) { \
552 if (strlen(folder) == strlen(old_id)) { \
554 folder = g_strdup(new_id); \
555 } else if (strlen(folder) > strlen(old_id) \
556 && folder[strlen(old_id)] == G_DIR_SEPARATOR) { \
557 gchar *new_path = g_strdup_printf("%s%s", \
558 new_id, (folder + strlen(old_id))); \
565 void account_rename_path(const gchar *old_id, const gchar *new_id)
567 GList *cur = account_list;
568 for (; cur != NULL; cur = g_list_next(cur)) {
569 PrefsAccount *ap = (PrefsAccount *)cur->data;
570 CHECK_CHANGE_FOLDER(ap->inbox);
571 CHECK_CHANGE_FOLDER(ap->local_inbox);
572 CHECK_CHANGE_FOLDER(ap->queue_folder);
573 CHECK_CHANGE_FOLDER(ap->sent_folder);
574 CHECK_CHANGE_FOLDER(ap->draft_folder);
575 CHECK_CHANGE_FOLDER(ap->trash_folder);
579 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
580 SpecialFolderItemType type)
582 FolderItem *item = NULL;
584 cm_return_val_if_fail(ac_prefs != NULL, NULL);
588 if (ac_prefs->folder)
589 item = FOLDER(ac_prefs->folder)->inbox;
591 item = folder_get_default_inbox();
594 if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
595 item = folder_find_item_from_identifier
596 (ac_prefs->sent_folder);
599 if (ac_prefs->folder)
600 item = FOLDER(ac_prefs->folder)->outbox;
602 item = folder_get_default_outbox_for_class(F_MH);
604 item = folder_get_default_outbox();
608 if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
609 item = folder_find_item_from_identifier
610 (ac_prefs->draft_folder);
613 if (ac_prefs->folder)
614 item = FOLDER(ac_prefs->folder)->draft;
616 item = folder_get_default_draft_for_class(F_MH);
618 item = folder_get_default_draft();
622 if (ac_prefs->set_queue_folder && ac_prefs->queue_folder) {
623 item = folder_find_item_from_identifier
624 (ac_prefs->queue_folder);
627 if (ac_prefs->folder)
628 item = FOLDER(ac_prefs->folder)->queue;
630 item = folder_get_default_queue_for_class(F_MH);
632 item = folder_get_default_queue();
636 if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
637 item = folder_find_item_from_identifier
638 (ac_prefs->trash_folder);
641 if (ac_prefs->folder)
642 item = FOLDER(ac_prefs->folder)->trash;
644 item = folder_get_default_trash_for_class(F_MH);
646 item = folder_get_default_trash();
656 void account_destroy(PrefsAccount *ac_prefs)
658 cm_return_if_fail(ac_prefs != NULL);
660 folder_unref_account_all(ac_prefs);
662 account_list = g_list_remove(account_list, ac_prefs);
664 if (cur_account == ac_prefs) cur_account = NULL;
665 if (!cur_account && account_list) {
666 cur_account = account_get_default();
668 ac_prefs = (PrefsAccount *)account_list->data;
669 account_set_as_default(ac_prefs);
670 cur_account = ac_prefs;
676 *\brief Save Gtk object size to prefs dataset
678 static void account_size_allocate_cb(GtkWidget *widget,
679 GtkAllocation *allocation)
681 cm_return_if_fail(allocation != NULL);
683 prefs_common.accountswin_width = allocation->width;
684 prefs_common.accountswin_height = allocation->height;
687 static void account_edit_create(void)
693 GtkWidget *scrolledwin;
694 GtkWidget *list_view;
700 GtkWidget *clone_btn;
704 GtkWidget *default_btn;
706 GtkWidget *confirm_area;
708 GtkWidget *close_btn;
710 static GdkGeometry geometry;
712 debug_print("Creating account edit window...\n");
714 window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "account");
715 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
716 gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
717 g_signal_connect (G_OBJECT (window), "delete_event",
718 G_CALLBACK (account_delete_event), NULL);
719 g_signal_connect (G_OBJECT (window), "key_press_event",
720 G_CALLBACK (account_key_pressed), NULL);
721 MANAGE_WINDOW_SIGNALS_CONNECT (window);
722 gtk_widget_realize(window);
724 vbox = gtk_vbox_new (FALSE, 10);
725 gtk_widget_show (vbox);
726 gtk_container_add (GTK_CONTAINER (window), vbox);
728 hbox = gtk_hbox_new (FALSE, 0);
729 gtk_widget_show (hbox);
730 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
732 label = gtk_label_new
733 (_("Using 'Get Mail' will retrieve messages from your Accounts "
734 "in the order given, the checkbox indicates which accounts "
735 "will be included. Bold text indicates the default account."));
736 gtk_widget_show (label);
737 gtk_widget_set_size_request(GTK_WIDGET(label),
738 prefs_common.accountswin_width-8, -1);
739 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
740 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
741 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
743 hbox = gtk_hbox_new (FALSE, 8);
744 gtk_widget_show (hbox);
745 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
746 gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
748 scrolledwin = gtk_scrolled_window_new (NULL, NULL);
749 gtk_widget_show (scrolledwin);
750 gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
751 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
752 GTK_POLICY_AUTOMATIC,
753 GTK_POLICY_AUTOMATIC);
755 list_view = account_list_view_create();
756 gtk_widget_show(list_view);
757 gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
759 vbox2 = gtk_vbox_new (FALSE, 0);
760 gtk_widget_show (vbox2);
761 gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
763 add_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
764 gtk_widget_show (add_btn);
765 gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
766 g_signal_connect (G_OBJECT(add_btn), "clicked",
767 G_CALLBACK (account_add), NULL);
769 edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
770 gtk_widget_show (edit_btn);
771 gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
772 g_signal_connect (G_OBJECT(edit_btn), "clicked",
773 G_CALLBACK (account_edit_prefs), NULL);
775 del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
776 gtk_widget_show (del_btn);
777 gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
778 g_signal_connect (G_OBJECT(del_btn), "clicked",
779 G_CALLBACK (account_delete), NULL);
781 clone_btn = gtk_button_new_from_stock(GTK_STOCK_COPY);
782 gtk_widget_show (clone_btn);
783 gtk_box_pack_start (GTK_BOX (vbox2), clone_btn, FALSE, FALSE, 4);
784 g_signal_connect(G_OBJECT(clone_btn), "clicked",
785 G_CALLBACK(account_clone), NULL);
787 down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
788 gtk_widget_show (down_btn);
789 gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
790 g_signal_connect (G_OBJECT(down_btn), "clicked",
791 G_CALLBACK (account_down), NULL);
793 up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
794 gtk_widget_show (up_btn);
795 gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
796 g_signal_connect (G_OBJECT(up_btn), "clicked",
797 G_CALLBACK (account_up), NULL);
799 hbox = gtk_hbox_new (FALSE, 8);
800 gtk_widget_show (hbox);
801 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
803 default_btn = gtk_button_new_with_mnemonic
804 (_(" _Set as default account "));
805 gtk_widget_show (default_btn);
806 gtk_box_pack_start (GTK_BOX (hbox), default_btn, FALSE, FALSE, 0);
807 g_signal_connect (G_OBJECT(default_btn), "clicked",
808 G_CALLBACK (account_set_default), NULL);
810 gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
811 &close_btn, GTK_STOCK_CLOSE,
812 NULL, NULL, NULL, NULL);
813 gtk_widget_show(confirm_area);
815 gtk_box_pack_end (GTK_BOX (hbox), confirm_area, FALSE, FALSE, 0);
816 gtk_widget_grab_default (close_btn);
818 g_signal_connect (G_OBJECT (close_btn), "clicked",
819 G_CALLBACK (account_edit_close),
821 g_signal_connect(G_OBJECT(help_btn), "clicked",
822 G_CALLBACK(manual_open_with_anchor_cb),
823 MANUAL_ANCHOR_ACCOUNTPREFS);
826 g_signal_connect(G_OBJECT(window), "size_allocate",
827 G_CALLBACK(account_size_allocate_cb), NULL);
829 if (!geometry.min_height) {
830 geometry.min_width = 500;
831 geometry.min_height = 380;
834 gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
836 gtk_widget_set_size_request(window, prefs_common.accountswin_width,
837 prefs_common.accountswin_height);
839 gtk_window_move(GTK_WINDOW(window), 48, 48);
842 edit_account.window = window;
843 edit_account.list_view = list_view;
844 edit_account.close_btn = close_btn;
847 static void account_edit_prefs(GtkWidget *widget, gpointer data)
849 PrefsAccount *ac_prefs;
851 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
854 account_open(ac_prefs);
855 account_list_view_set();
859 static gboolean account_delete_references_func(GNode *node, gpointer data)
864 cm_return_val_if_fail(node->data != NULL, FALSE);
866 item = FOLDER_ITEM(node->data);
867 account = GPOINTER_TO_INT(data);
869 if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
871 if(item->prefs->default_account != account)
874 item->prefs->enable_default_account = FALSE;
875 item->prefs->default_account = 0;
876 folder_item_prefs_save_config(item);
882 #define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
883 g_strdup(ac_prefs->fld): NULL
884 #define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
885 static void account_clone(GtkWidget *widget, gpointer data)
887 PrefsAccount *ac_prefs, *ac_clon;
889 CustomHeader *cch = NULL, *ch = NULL;
891 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
892 if (ac_prefs == NULL)
895 if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
896 alertpanel_error(_("Accounts with remote folders cannot be copied."));
899 account_list_dirty = TRUE;
901 ac_clon = prefs_account_new();
903 ac_clon->account_name = g_strdup_printf(_("Copy of %s"),
904 ac_prefs->account_name);
908 ACP_FDUP(organization);
911 ACP_FASSIGN(protocol);
912 ACP_FDUP(recv_server);
913 ACP_FDUP(smtp_server);
914 ACP_FDUP(nntp_server);
915 ACP_FASSIGN(use_nntp_auth);
916 ACP_FASSIGN(use_nntp_auth_onconnect);
920 ACP_FDUP(local_mbox);
921 ACP_FASSIGN(use_mail_command);
922 ACP_FDUP(mail_command);
924 ACP_FASSIGN(ssl_pop);
925 ACP_FASSIGN(ssl_imap);
926 ACP_FASSIGN(ssl_nntp);
927 ACP_FASSIGN(ssl_smtp);
928 ACP_FASSIGN(use_nonblocking_ssl);
931 ACP_FASSIGN(use_apop_auth);
933 ACP_FASSIGN(msg_leave_time);
934 ACP_FASSIGN(msg_leave_hour);
935 ACP_FASSIGN(recv_at_getall);
936 ACP_FASSIGN(sd_rmmail_on_download);
937 ACP_FASSIGN(enable_size_limit);
938 ACP_FASSIGN(size_limit);
939 ACP_FASSIGN(filter_on_recv);
940 ACP_FASSIGN(filterhook_on_recv);
942 ACP_FDUP(local_inbox);
943 ACP_FASSIGN(max_articles);
945 ACP_FASSIGN(imap_auth_type);
948 ACP_FASSIGN(gen_msgid);
949 ACP_FASSIGN(gen_xmailer);
950 ACP_FASSIGN(add_customhdr);
951 ACP_FASSIGN(use_smtp_auth);
952 ACP_FASSIGN(smtp_auth_type);
953 ACP_FDUP(smtp_userid);
954 ACP_FDUP(smtp_passwd);
956 ACP_FASSIGN(pop_before_smtp);
957 ACP_FASSIGN(pop_before_smtp_timeout);
958 ACP_FASSIGN(last_pop_login_time);
960 ac_clon->customhdr_list = NULL;
961 hdrs = ac_prefs->customhdr_list;
962 while (hdrs != NULL) {
963 ch = (CustomHeader *)hdrs->data;
965 cch = g_new0(CustomHeader, 1);
966 cch->account_id = ac_clon->account_id;
967 cch->name = (ch->name != NULL) ? g_strdup(ch->name) : NULL;
968 cch->value = (ch->value != NULL) ? g_strdup(ch->value) : NULL;
970 ac_clon->customhdr_list = g_slist_append(ac_clon->customhdr_list, cch);
972 hdrs = g_slist_next(hdrs);
976 ACP_FASSIGN(sig_type);
978 ACP_FASSIGN(auto_sig);
980 ACP_FASSIGN(set_autocc);
982 ACP_FASSIGN(set_autobcc);
984 ACP_FASSIGN(set_autoreplyto);
985 ACP_FDUP(auto_replyto);
986 ACP_FASSIGN(enable_default_dictionary);
987 ACP_FDUP(default_dictionary);
988 ACP_FASSIGN(enable_default_alt_dictionary);
989 ACP_FDUP(default_alt_dictionary);
990 ACP_FASSIGN(compose_with_format);
991 ACP_FDUP(compose_subject_format);
992 ACP_FDUP(compose_body_format);
993 ACP_FASSIGN(reply_with_format);
994 ACP_FDUP(reply_quotemark);
995 ACP_FDUP(reply_body_format);
996 ACP_FASSIGN(forward_with_format);
997 ACP_FDUP(forward_quotemark);
998 ACP_FDUP(forward_body_format);
1001 ACP_FDUP(default_privacy_system);
1002 ACP_FASSIGN(default_encrypt);
1003 ACP_FASSIGN(default_encrypt_reply);
1004 ACP_FASSIGN(default_sign);
1005 ACP_FASSIGN(default_sign_reply);
1006 ACP_FASSIGN(save_encrypted_as_clear_text);
1007 ACP_FASSIGN(encrypt_to_self);
1010 ACP_FASSIGN(set_smtpport);
1011 ACP_FASSIGN(smtpport);
1012 ACP_FASSIGN(set_popport);
1013 ACP_FASSIGN(popport);
1014 ACP_FASSIGN(set_imapport);
1015 ACP_FASSIGN(imapport);
1016 ACP_FASSIGN(set_nntpport);
1017 ACP_FASSIGN(nntpport);
1018 ACP_FASSIGN(set_domain);
1020 ACP_FASSIGN(mark_crosspost_read);
1021 ACP_FASSIGN(crosspost_col);
1024 ACP_FASSIGN(set_tunnelcmd);
1025 ACP_FDUP(tunnelcmd);
1029 ACP_FASSIGN(imap_subsonly);
1030 ACP_FASSIGN(low_bandwidth);
1032 ACP_FASSIGN(set_sent_folder);
1033 ACP_FDUP(sent_folder);
1034 ACP_FASSIGN(set_queue_folder);
1035 ACP_FDUP(queue_folder);
1036 ACP_FASSIGN(set_draft_folder);
1037 ACP_FDUP(draft_folder);
1038 ACP_FASSIGN(set_trash_folder);
1039 ACP_FDUP(trash_folder);
1040 /* don't want two default accounts */
1041 ac_clon->is_default = FALSE;
1042 ACP_FASSIGN(folder);
1044 account_list = g_list_append(account_list, ac_clon);
1045 account_list_view_set();
1050 static void account_delete(GtkWidget *widget, gpointer data)
1052 PrefsAccount *ac_prefs;
1053 gchar buf[BUFFSIZE];
1058 ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
1059 if (ac_prefs == NULL)
1062 g_snprintf(buf, sizeof(buf),
1063 _("Do you really want to delete the account '%s'?"),
1064 ac_prefs->account_name ? ac_prefs->account_name :
1066 if (alertpanel_full(_("Delete account"), buf,
1067 GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
1068 NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE)
1070 account_list_dirty = TRUE;
1072 if (ac_prefs->folder) {
1075 item = mainwindow_get_mainwindow()->summaryview->folder_item;
1076 if (item && item->folder == FOLDER(ac_prefs->folder))
1077 summary_clear_all(mainwindow_get_mainwindow()->summaryview);
1078 folder_destroy(FOLDER(ac_prefs->folder));
1079 folderview_set_all();
1081 account_destroy(ac_prefs);
1082 account_list_view_set();
1084 debug_print("Removing deleted account references for all the folders...\n");
1085 list = folder_get_list();
1086 for (; list != NULL; list = list->next) {
1087 folder = FOLDER(list->data);
1088 if (folder->node) /* && folder->type == F_? */
1089 g_node_traverse(folder->node, G_PRE_ORDER,
1091 account_delete_references_func,
1092 GINT_TO_POINTER(ac_prefs->account_id));
1095 debug_print("Removing filter rules relative to this account...\n");
1096 for(cur = filtering_rules ; cur != NULL ;) {
1097 FilteringProp * prop = (FilteringProp *) cur->data;
1099 if (prop && (prop->account_id == ac_prefs->account_id)) {
1100 /* get next item before we kill the current one */
1101 cur = g_slist_next(cur);
1103 /* unallocate filteringprop and unchain it from the list */
1104 filteringprop_free(prop);
1105 filtering_rules = g_slist_remove(filtering_rules, prop);
1107 cur = g_slist_next(cur);
1110 folder_write_list();
1113 static void account_up(GtkWidget *widget, gpointer data)
1115 GtkTreePath *sel = account_list_view_get_selected_account_path
1116 (edit_account.list_view),
1118 GtkTreeIter isel, iup;
1119 GtkTreeModel *model = gtk_tree_view_get_model
1120 (GTK_TREE_VIEW(edit_account.list_view));
1124 account_list_dirty = TRUE;
1126 up = gtk_tree_path_copy(sel);
1128 gtk_tree_path_free(sel);
1132 if (!gtk_tree_path_prev(up)) {
1133 gtk_tree_path_free(up);
1134 gtk_tree_path_free(sel);
1138 if (!gtk_tree_model_get_iter(model, &isel, sel)
1139 || !gtk_tree_model_get_iter(model, &iup, up)) {
1140 gtk_tree_path_free(up);
1141 gtk_tree_path_free(sel);
1145 gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &iup);
1149 gtk_tree_path_free(up);
1150 gtk_tree_path_free(sel);
1153 static void account_down(GtkWidget *widget, gpointer data)
1155 GtkTreePath *sel = account_list_view_get_selected_account_path
1156 (edit_account.list_view),
1158 GtkTreeIter isel, idn;
1159 GtkTreeModel *model = gtk_tree_view_get_model
1160 (GTK_TREE_VIEW(edit_account.list_view));
1164 account_list_dirty = TRUE;
1166 dn = gtk_tree_path_copy(sel);
1168 gtk_tree_path_free(sel);
1172 /* XXX no check possible??? however, if down but at bottom, then
1173 * nothing seems to happen much anyway, so the following seems to
1175 gtk_tree_path_next(dn);
1177 if (!gtk_tree_model_get_iter(model, &isel, sel)
1178 || !gtk_tree_model_get_iter(model, &idn, dn)) {
1179 gtk_tree_path_free(dn);
1180 gtk_tree_path_free(sel);
1184 gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &idn);
1188 gtk_tree_path_free(dn);
1189 gtk_tree_path_free(sel);
1192 static void account_set_default(GtkWidget *widget, gpointer data)
1194 PrefsAccount *ac_prefs;
1196 if (NULL == (ac_prefs = account_list_view_get_selected_account
1197 (edit_account.list_view)))
1200 /* we need to change the store variables by resetting everything
1201 * and setting the new default one */
1202 account_list_view_set_default_by_id(edit_account.list_view,
1203 ac_prefs->account_id);
1205 account_set_as_default(ac_prefs);
1206 account_list_view_set();
1208 cur_account = ac_prefs;
1209 account_flush_state();
1212 static void account_edit_close(GtkWidget *widget, gpointer data)
1215 account_write_config_all();
1217 if (!cur_account && account_list) {
1218 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
1219 account_set_as_default(ac_prefs);
1220 cur_account = ac_prefs;
1223 if (account_list_dirty)
1224 account_flush_state();
1226 gtk_widget_hide(edit_account.window);
1227 gtk_window_set_modal(GTK_WINDOW(edit_account.window), FALSE);
1231 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
1234 account_edit_close(NULL, NULL);
1238 static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
1241 if (event && event->keyval == GDK_KEY_Escape)
1242 account_edit_close(NULL, NULL);
1246 static gboolean account_search_func_cb (GtkTreeModel *model, gint column, const gchar *key,
1247 GtkTreeIter *iter, gpointer search_data)
1252 gtk_tree_model_get (model, iter, ACCOUNT_DATA, &ac, -1);
1254 if (!ac->name || !key) return FALSE;
1256 retval = (strncmp (key, ac->account_name, strlen(key)) != 0);
1258 debug_print("selecting row\n");
1259 account_list_view_select_account(edit_account.list_view, ac->account_id);
1263 static void account_list_view_add(PrefsAccount *ac_prefs)
1265 GtkTreeView *list_view = GTK_TREE_VIEW(edit_account.list_view);
1266 GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
1267 gchar *name, *protocol, *server;
1268 gboolean has_getallbox;
1271 name = ac_prefs->account_name;
1273 protocol = ac_prefs->protocol == A_POP3 ?
1274 (ac_prefs->ssl_pop == SSL_TUNNEL ?
1276 ac_prefs->ssl_pop == SSL_STARTTLS ?
1277 "POP3 (TLS)" : "POP3") :
1278 ac_prefs->protocol == A_IMAP4 ?
1279 (ac_prefs->ssl_imap == SSL_TUNNEL ?
1281 ac_prefs->ssl_imap == SSL_STARTTLS ?
1282 "IMAP4 (TLS)" : "IMAP4") :
1283 ac_prefs->protocol == A_NNTP ?
1284 (ac_prefs->ssl_nntp == SSL_TUNNEL ?
1285 "NNTP (SSL)" : "NNTP") :
1286 ac_prefs->protocol == A_LOCAL ? "Local" :
1287 ac_prefs->protocol == A_NONE ? "SMTP" : "-";
1289 protocol = ac_prefs->protocol == A_POP3 ? "POP3" :
1290 ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
1291 ac_prefs->protocol == A_LOCAL ? "Local" :
1292 ac_prefs->protocol == A_NNTP ? "NNTP" :
1293 ac_prefs->protocol == A_NONE ? "SMTP" : "-";
1295 server= ac_prefs->protocol == A_NNTP ? ac_prefs->nntp_server :
1296 ac_prefs->protocol == A_LOCAL ? "-" :
1297 ac_prefs->protocol == A_NONE ? ac_prefs->smtp_server :
1298 ac_prefs->recv_server;
1300 has_getallbox = (ac_prefs->protocol == A_POP3 ||
1301 ac_prefs->protocol == A_IMAP4 ||
1302 ac_prefs->protocol == A_NNTP ||
1303 ac_prefs->protocol == A_LOCAL);
1304 getall = has_getallbox && ac_prefs->recv_at_getall;
1306 account_list_view_insert_account_item(list_store,
1307 name, protocol, server,
1308 ac_prefs->is_default,
1313 static void account_list_view_set(void)
1316 gint prev_sel_account;
1317 GtkListStore *store;
1319 store = GTK_LIST_STORE(gtk_tree_view_get_model
1320 (GTK_TREE_VIEW(edit_account.list_view)));
1322 prev_sel_account = account_list_view_get_selected_account_id
1323 (edit_account.list_view);
1325 gtk_list_store_clear(store);
1327 for (cur = account_list; cur != NULL; cur = cur->next) {
1328 account_list_view_add((PrefsAccount *)cur->data);
1329 if ((PrefsAccount *)cur->data == cur_account)
1330 account_list_view_select_account
1331 (edit_account.list_view,
1332 cur_account->account_id);
1335 if (prev_sel_account >= 0)
1336 account_list_view_select_account(edit_account.list_view,
1340 /* set account list from CList */
1341 static void account_list_set(void)
1343 /* want to make sure we iterate *IN ORDER*, so therefore using
1344 * gtk_tree_model_XXXX_nth_child() */
1346 PrefsAccount *ac_prefs;
1347 GtkTreeModel *model = gtk_tree_view_get_model
1348 (GTK_TREE_VIEW(edit_account.list_view));
1350 while (account_list)
1351 account_list = g_list_remove(account_list, account_list->data);
1353 n_rows = gtk_tree_model_iter_n_children(model, NULL);
1355 for (row = 0; row < n_rows; row++) {
1358 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
1359 g_warning("%s(%d) - no iter found???\n", __FILE__, __LINE__);
1364 gtk_tree_model_get(model, &iter,
1365 ACCOUNT_DATA, &ac_prefs,
1368 account_list = g_list_append(account_list, ac_prefs);
1373 *\brief finds the PrefsAccounts which should be used to answer a mail
1375 *\param msginfo The message to be answered
1376 *\param reply_autosel Indicates whether reply account autoselection is on
1378 *\return PrefsAccount * the correct account, NULL if not found
1380 PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
1382 PrefsAccount *account = NULL;
1383 /* select the account set in folderitem's property (if enabled) */
1384 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
1385 account = account_find_from_id(msginfo->folder->prefs->default_account);
1387 /* select account by to: and cc: header if enabled */
1388 if (reply_autosel) {
1389 gchar * field = NULL;
1391 for (field = msginfo->to; fieldno++ < 2; field = msginfo->cc) {
1392 if (!account && field) {
1394 if (!strchr(field, ',')) {
1395 Xstrdup_a(to, field, return NULL);
1396 extract_address(to);
1397 account = account_find_from_address(to, FALSE);
1399 gchar **split = g_strsplit(field, ",", -1);
1405 Xstrdup_a(to, split[i], return NULL);
1406 extract_address(to);
1407 account = account_find_from_address(to, FALSE);
1414 gchar deliveredto[BUFFSIZE];
1415 if (!procheader_get_header_from_msginfo
1416 (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) {
1417 gchar *buf = deliveredto + strlen("Delivered-To:");
1418 extract_address(buf);
1419 account = account_find_from_address(buf, FALSE);
1424 /* select the account for the whole folder (IMAP / NNTP) */
1426 /* FIXME: this is not right, because folder may be nested. we should
1427 * ascend the tree until we find a parent with proper account
1429 account = msginfo->folder->folder->account;
1431 /* select current account */
1432 if (!account) account = cur_account;
1438 *\brief Create data store
1440 static GtkListStore* account_create_data_store(void)
1442 return gtk_list_store_new(N_ACCOUNT_COLUMNS,
1443 G_TYPE_INT, /* ACCOUNT_IS_DEFAULT */
1444 G_TYPE_BOOLEAN, /* ACCOUNT_ENABLE_GET_ALL */
1445 G_TYPE_STRING, /* ACCOUNT_NAME */
1446 G_TYPE_STRING, /* ACCOUNT_PROTOCOL */
1447 G_TYPE_STRING, /* ACCOUNT_SERVER */
1448 G_TYPE_POINTER, /* ACCOUNT_DATA */
1453 *\brief Insert an account item in the list.
1455 *\return GtkTreeRowReference * A tree row reference, which is guaranteed to
1456 * stable whatever operations are performed on the list.
1458 static void account_list_view_insert_account_item(GtkListStore *list_store,
1459 const gchar *account_name,
1460 const gchar *protocol,
1461 const gchar *server_name,
1462 gboolean is_default,
1463 gboolean is_get_all,
1464 PrefsAccount *account_data)
1468 gtk_list_store_append(list_store, &iter);
1469 gtk_list_store_set(list_store, &iter,
1470 ACCOUNT_IS_DEFAULT, is_default ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
1471 ACCOUNT_ENABLE_GET_ALL, is_get_all,
1472 ACCOUNT_NAME, account_name,
1473 ACCOUNT_PROTOCOL, protocol,
1474 ACCOUNT_SERVER, server_name,
1475 ACCOUNT_DATA, account_data,
1480 *\brief Create and set up account list view, including tasks like
1481 * creating the data store (\ref account_create_data_store()),
1482 * and setting up the account list's individual columns (\ref
1483 * account_create_list_view_columns()).
1485 *\return GtkWidget * The created list view widget.
1487 static GtkWidget *account_list_view_create(void)
1489 GtkTreeView *list_view;
1490 GtkTreeSelection *selector;
1491 GtkListStore *store = account_create_data_store();
1493 list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1494 g_object_unref(G_OBJECT(store));
1496 g_object_set(list_view, "allow-checkbox-mode", FALSE, NULL);
1498 gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1499 gtk_tree_view_set_reorderable(list_view, TRUE);
1501 selector = gtk_tree_view_get_selection(list_view);
1502 gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1504 /* create the columns */
1505 account_create_list_view_columns(GTK_WIDGET(list_view));
1507 /* set a double click listener */
1508 g_signal_connect(G_OBJECT(list_view), "row_activated",
1509 G_CALLBACK(account_double_clicked),
1512 g_signal_connect(G_OBJECT(list_view), "drag_begin",
1513 G_CALLBACK(drag_begin),
1516 g_signal_connect(G_OBJECT(list_view), "drag_end",
1517 G_CALLBACK(drag_end),
1520 gtk_tree_view_set_reorderable(list_view, TRUE);
1521 return GTK_WIDGET(list_view);
1524 static void account_create_list_view_columns(GtkWidget *list_view)
1526 GtkTreeViewColumn *column;
1527 GtkCellRenderer *renderer;
1529 renderer = gtk_cell_renderer_toggle_new();
1530 g_object_set(renderer,
1532 "activatable", TRUE,
1534 column = gtk_tree_view_column_new_with_attributes
1535 (C_("Accounts List Get Column Name", "G"), renderer,
1536 "active", ACCOUNT_ENABLE_GET_ALL,
1538 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1539 gtk_tree_view_column_set_alignment (column, 0.5);
1540 CLAWS_SET_TIP(gtk_tree_view_column_get_widget(column),
1541 _("'Get Mail' retrieves mail from the checked accounts"));
1542 g_signal_connect(G_OBJECT(renderer), "toggled",
1543 G_CALLBACK(account_get_all_toggled),
1546 renderer = gtk_cell_renderer_text_new();
1547 column = gtk_tree_view_column_new_with_attributes
1548 (_("Name"), renderer,
1549 "text", ACCOUNT_NAME,
1550 "weight", ACCOUNT_IS_DEFAULT,
1552 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1554 renderer = gtk_cell_renderer_text_new();
1555 column = gtk_tree_view_column_new_with_attributes
1556 (_("Protocol"), renderer,
1557 "text", ACCOUNT_PROTOCOL,
1558 "weight", ACCOUNT_IS_DEFAULT,
1560 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1562 renderer = gtk_cell_renderer_text_new();
1563 column = gtk_tree_view_column_new_with_attributes
1564 (_("Server"), renderer,
1565 "text", ACCOUNT_SERVER,
1566 "weight", ACCOUNT_IS_DEFAULT,
1568 gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view), ACCOUNT_NAME);
1569 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view), account_search_func_cb , NULL, NULL);
1570 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);
1574 *\brief Get currently selected account (by its unique ID)
1576 static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
1578 GtkTreeSelection *selector;
1579 GtkTreeModel *model;
1581 PrefsAccount *res = NULL;
1583 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1585 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1588 gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1590 return res->account_id;
1594 *\brief Get the tree path of the currently selected account
1596 static GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_view)
1598 GtkTreeSelection *selector;
1599 GtkTreeModel *model;
1602 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1604 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1607 return gtk_tree_model_get_path(gtk_tree_view_get_model
1608 (GTK_TREE_VIEW(list_view)), &iter);
1612 *\brief Get the account data of the currently selected account
1614 static PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
1616 GtkTreeSelection *selector;
1617 GtkTreeModel *model;
1619 PrefsAccount *res = NULL;
1621 selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1623 if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1626 gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1632 *\brief Select a row by the account it represents
1634 *\return gboolean TRUE if found and selected, FALSE if not.
1636 static gboolean account_list_view_select_account(GtkWidget *list_view, gint account_id)
1638 FindAccountInStore fis;
1639 GtkTreeModel *model;
1641 fis.account_id = account_id;
1644 model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1646 gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc) find_account_in_store,
1650 GtkTreeSelection *selection;
1653 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1654 gtk_tree_selection_select_iter(selection, &fis.iter);
1655 path = gtk_tree_model_get_path(model, &fis.iter);
1656 /* XXX returned path may not be valid??? create new one to be sure */
1657 gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view), path, NULL, FALSE);
1658 gtk_tree_path_free(path);
1661 return fis.path != NULL;
1665 *\brief Set a new default account by its ID. (There is only one
1668 static void account_list_view_set_default_by_id(GtkWidget *list_view,
1671 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1673 gtk_tree_model_foreach
1674 (model, (GtkTreeModelForeachFunc) set_new_default_account,
1678 static gboolean set_new_default_account(GtkTreeModel *model,
1683 PrefsAccount *account = NULL;
1686 gtk_tree_model_get(model, iter,
1687 ACCOUNT_DATA, &account,
1690 if (*account_id == account->account_id)
1691 weight = PANGO_WEIGHT_NORMAL;
1693 weight = PANGO_WEIGHT_BOLD;
1695 gtk_list_store_set(GTK_LIST_STORE(model), iter,
1696 ACCOUNT_IS_DEFAULT, weight, -1);
1701 static gboolean find_account_in_store(GtkTreeModel *model,
1704 FindAccountInStore *data)
1706 PrefsAccount *account = NULL;
1707 gtk_tree_model_get(model, iter, ACCOUNT_DATA, &account, -1);
1709 if (data->account_id == account->account_id) {
1710 data->path = path; /* signal we found it */
1719 *\brief Triggered when "get all" column is activated or de-activated
1721 static void account_get_all_toggled(GtkCellRendererToggle *widget,
1723 GtkWidget *list_view)
1726 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1727 PrefsAccount *ac = NULL;
1730 if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
1733 gtk_tree_model_get(model, &iter,
1735 ACCOUNT_ENABLE_GET_ALL, &get_all,
1738 /* check if the account has a selectable get all checkbox anyway... */
1739 if (!(ac->protocol == A_POP3 ||
1740 ac->protocol == A_IMAP4 ||
1741 ac->protocol == A_NNTP ||
1742 ac->protocol == A_LOCAL))
1745 /* set value in store */
1746 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
1747 ACCOUNT_ENABLE_GET_ALL, !get_all,
1750 /* set value in account */
1751 ac->recv_at_getall ^= TRUE;
1754 static void account_double_clicked(GtkTreeView *list_view,
1756 GtkTreeViewColumn *column,
1759 account_edit_prefs(NULL, NULL);
1762 static void drag_begin(GtkTreeView *list_view,
1763 GdkDragContext *context,
1766 /* XXX unfortunately a completed drag & drop does not emit
1767 * a "rows_reordered" signal, but a "row_changed" signal.
1768 * So during drag and drop, listen to "row_changed", and
1769 * update the account list accordingly */
1771 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1772 g_signal_connect(G_OBJECT(model), "row_changed",
1773 G_CALLBACK(account_row_changed_while_drag_drop),
1777 static void drag_end(GtkTreeView *list_view,
1778 GdkDragContext *context,
1781 GtkTreeModel *model = gtk_tree_view_get_model(list_view);
1782 g_signal_handlers_disconnect_by_func(G_OBJECT(model),
1783 G_CALLBACK(account_row_changed_while_drag_drop),
1787 static void account_row_changed_while_drag_drop(GtkTreeModel *model,
1791 GtkTreeView *list_view)
1796 gchar *account_get_signature_str(PrefsAccount *account)
1798 gchar *sig_body = NULL;
1799 gchar *sig_str = NULL;
1800 gchar *utf8_sig_str = NULL;
1802 cm_return_val_if_fail(account != NULL, NULL);
1804 if (!account->sig_path)
1807 if (account->sig_type == SIG_FILE) {
1808 if (!is_file_or_fifo_exist(account->sig_path)) {
1809 g_warning("can't open signature file: %s\n",
1815 if (account->sig_type == SIG_COMMAND)
1816 sig_body = get_command_output(account->sig_path);
1820 tmp = file_read_to_str(account->sig_path);
1823 sig_body = normalize_newlines(tmp);
1827 if (account->sig_sep) {
1828 sig_str = g_strconcat("\n", account->sig_sep, "\n", sig_body,
1832 sig_str = g_strconcat("\n", sig_body, NULL);
1835 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
1836 utf8_sig_str = sig_str;
1838 utf8_sig_str = conv_codeset_strdup
1839 (sig_str, conv_get_locale_charset_str_no_utf8(),
1845 return utf8_sig_str;
1848 PrefsAccount *account_get_cur_account (void)