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"
60 ACCOUNT_ENABLE_GET_ALL
,
76 } EditAccountColumnPos
;
78 # define N_EDIT_ACCOUNT_COLS 5
80 PrefsAccount
*cur_account
;
82 static GList
*account_list
= NULL
;
83 static gboolean account_list_dirty
= FALSE
;
85 static struct EditAccount
{
91 static void account_edit_create (void);
92 static void account_destroy (PrefsAccount
*ac_prefs
);
93 static void account_set_as_default (PrefsAccount
*ac_prefs
);
94 static void account_set_menu (void);
96 static void account_edit_prefs (GtkWidget
*widget
, gpointer data
);
97 static void account_delete (GtkWidget
*widget
, gpointer data
);
98 static void account_clone (GtkWidget
*widget
, gpointer data
);
100 static void account_up (GtkWidget
*widget
, gpointer data
);
101 static void account_down (GtkWidget
*widget
, gpointer data
);
103 static void account_set_default (GtkWidget
*widget
, gpointer data
);
105 static void account_edit_close (GtkWidget
*widget
, gpointer data
);
107 static gint
account_delete_event (GtkWidget
*widget
,
110 static void account_size_allocate_cb(GtkWidget
*widget
,
111 GtkAllocation
*allocation
);
112 static gboolean
account_key_pressed (GtkWidget
*widget
,
115 static gboolean
account_search_func_cb (GtkTreeModel
*model
, gint column
,
116 const gchar
*key
, GtkTreeIter
*iter
,
117 gpointer search_data
);
118 static void account_list_view_add (PrefsAccount
*ac_prefs
);
119 static void account_list_view_set (void);
121 static void account_list_set (void);
123 typedef struct FindAccountInStore
{
127 } FindAccountInStore
;
129 static GtkListStore
* account_create_data_store (void);
131 static void account_list_view_insert_account_item (GtkListStore
*list_store
,
132 const gchar
*account_name
,
133 const gchar
*protocol
,
134 const gchar
*server_name
,
137 PrefsAccount
*account_data
);
139 static GtkWidget
*account_list_view_create (void);
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 static 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, sizeof(buf
) - 1);
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 cm_return_val_if_fail(address
!= NULL
, NULL
);
287 cm_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 if newsgroups_ok is FALSE) 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
, gboolean newsgroups_ok
)
312 cm_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
|| newsgroups_ok
) && 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 cm_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_focus(void)
378 manage_window_set_transient(GTK_WINDOW(edit_account
.window
));
379 gtk_widget_grab_focus(edit_account
.close_btn
);
380 gtk_widget_show(edit_account
.window
);
381 gtk_window_set_modal(GTK_WINDOW(edit_account
.window
), TRUE
);
382 manage_window_focus_in(edit_account
.window
, NULL
, NULL
);
385 void account_edit_open(gpointer a
, gpointer b
)
389 account_list_dirty
= FALSE
;
391 if (compose_get_compose_list()) {
392 alertpanel_error(_("Some composing windows are open.\n"
393 "Please close all the composing "
394 "windows before editing the accounts."));
399 debug_print("Opening account edit window...\n");
401 if (!edit_account
.window
)
402 account_edit_create();
404 account_list_view_set();
406 account_edit_focus();
409 void account_add(void)
411 PrefsAccount
*ac_prefs
;
413 ac_prefs
= prefs_account_open(NULL
, &account_list_dirty
);
415 if (!ac_prefs
) return;
417 account_edit_focus();
419 account_list
= g_list_append(account_list
, ac_prefs
);
421 if (ac_prefs
->is_default
)
422 account_set_as_default(ac_prefs
);
424 account_list_view_set();
426 if (ac_prefs
->protocol
== A_IMAP4
|| ac_prefs
->protocol
== A_NNTP
) {
429 if (ac_prefs
->protocol
== A_IMAP4
) {
430 folder
= folder_new(folder_get_class_from_string("imap"), ac_prefs
->account_name
,
431 ac_prefs
->recv_server
);
433 folder
= folder_new(folder_get_class_from_string("news"), ac_prefs
->account_name
,
434 ac_prefs
->nntp_server
);
436 if (folder
== NULL
) {
437 alertpanel_error(_("Can't create folder."));
440 folder
->account
= ac_prefs
;
441 ac_prefs
->folder
= folder
;
443 if (ac_prefs
->protocol
== A_IMAP4
)
444 folder
->klass
->create_tree(folder
);
445 folderview_set_all();
450 void account_open(PrefsAccount
*ac_prefs
)
452 gboolean prev_default
;
453 gchar
*ac_name
, *old_prefix
, *new_prefix
;
454 gboolean account_dirty
= FALSE
;
456 cm_return_if_fail(ac_prefs
!= NULL
);
458 prev_default
= ac_prefs
->is_default
;
459 Xstrdup_a(ac_name
, ac_prefs
->account_name
? ac_prefs
->account_name
: "",
462 prefs_account_open(ac_prefs
, &account_dirty
);
464 account_edit_focus();
467 if (!prev_default
&& ac_prefs
->is_default
)
468 account_set_as_default(ac_prefs
);
470 if (ac_prefs
->folder
&& strcmp2(ac_name
, ac_prefs
->account_name
) != 0) {
471 old_prefix
= folder_get_identifier(FOLDER(ac_prefs
->folder
));
472 folder_set_name(FOLDER(ac_prefs
->folder
),
473 ac_prefs
->account_name
);
474 folderview_set_all();
475 folder_prefs_save_config_recursive(FOLDER(ac_prefs
->folder
));
476 new_prefix
= folder_get_identifier(FOLDER(ac_prefs
->folder
));
478 account_rename_path(old_prefix
, new_prefix
);
479 prefs_filtering_rename_path(old_prefix
, new_prefix
);
480 prefs_actions_rename_path(old_prefix
, new_prefix
);
486 account_write_config_all();
488 account_flush_state();
492 static void account_set_as_default(PrefsAccount
*ac_prefs
)
497 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
498 ap
= (PrefsAccount
*)cur
->data
;
500 ap
->is_default
= FALSE
;
503 ac_prefs
->is_default
= TRUE
;
506 PrefsAccount
*account_get_default(void)
511 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
512 ap
= (PrefsAccount
*)cur
->data
;
520 void account_set_missing_folder(void)
525 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
526 ap
= (PrefsAccount
*)cur
->data
;
527 if ((ap
->protocol
== A_IMAP4
|| ap
->protocol
== A_NNTP
) &&
531 if (ap
->protocol
== A_IMAP4
) {
532 folder
= folder_new(folder_get_class_from_string("imap"), ap
->account_name
,
535 folder
= folder_new(folder_get_class_from_string("news"), ap
->account_name
,
540 folder
->account
= ap
;
543 if (ap
->protocol
== A_IMAP4
)
544 folder
->klass
->create_tree(folder
);
551 #define CHECK_CHANGE_FOLDER(folder) { \
552 if (folder && !strncmp(folder, old_id, strlen(old_id))) { \
553 if (strlen(folder) == strlen(old_id)) { \
555 folder = g_strdup(new_id); \
556 } else if (strlen(folder) > strlen(old_id) \
557 && folder[strlen(old_id)] == G_DIR_SEPARATOR) { \
558 gchar *new_path = g_strdup_printf("%s%s", \
559 new_id, (folder + strlen(old_id))); \
566 void account_rename_path(const gchar
*old_id
, const gchar
*new_id
)
568 GList
*cur
= account_list
;
569 for (; cur
!= NULL
; cur
= g_list_next(cur
)) {
570 PrefsAccount
*ap
= (PrefsAccount
*)cur
->data
;
571 CHECK_CHANGE_FOLDER(ap
->inbox
);
572 CHECK_CHANGE_FOLDER(ap
->local_inbox
);
573 CHECK_CHANGE_FOLDER(ap
->queue_folder
);
574 CHECK_CHANGE_FOLDER(ap
->sent_folder
);
575 CHECK_CHANGE_FOLDER(ap
->draft_folder
);
576 CHECK_CHANGE_FOLDER(ap
->trash_folder
);
580 FolderItem
*account_get_special_folder(PrefsAccount
*ac_prefs
,
581 SpecialFolderItemType type
)
583 FolderItem
*item
= NULL
;
585 cm_return_val_if_fail(ac_prefs
!= NULL
, NULL
);
589 if (ac_prefs
->folder
)
590 item
= FOLDER(ac_prefs
->folder
)->inbox
;
592 item
= folder_get_default_inbox();
595 if (ac_prefs
->set_sent_folder
&& ac_prefs
->sent_folder
) {
596 item
= folder_find_item_from_identifier
597 (ac_prefs
->sent_folder
);
600 if (ac_prefs
->folder
)
601 item
= FOLDER(ac_prefs
->folder
)->outbox
;
603 item
= folder_get_default_outbox_for_class(F_MH
);
605 item
= folder_get_default_outbox();
609 if (ac_prefs
->set_draft_folder
&& ac_prefs
->draft_folder
) {
610 item
= folder_find_item_from_identifier
611 (ac_prefs
->draft_folder
);
614 if (ac_prefs
->folder
)
615 item
= FOLDER(ac_prefs
->folder
)->draft
;
617 item
= folder_get_default_draft_for_class(F_MH
);
619 item
= folder_get_default_draft();
623 if (ac_prefs
->set_queue_folder
&& ac_prefs
->queue_folder
) {
624 item
= folder_find_item_from_identifier
625 (ac_prefs
->queue_folder
);
628 if (ac_prefs
->folder
)
629 item
= FOLDER(ac_prefs
->folder
)->queue
;
631 item
= folder_get_default_queue_for_class(F_MH
);
633 item
= folder_get_default_queue();
637 if (ac_prefs
->set_trash_folder
&& ac_prefs
->trash_folder
) {
638 item
= folder_find_item_from_identifier
639 (ac_prefs
->trash_folder
);
642 if (ac_prefs
->folder
)
643 item
= FOLDER(ac_prefs
->folder
)->trash
;
645 item
= folder_get_default_trash_for_class(F_MH
);
647 item
= folder_get_default_trash();
657 void account_destroy(PrefsAccount
*ac_prefs
)
659 cm_return_if_fail(ac_prefs
!= NULL
);
661 folder_unref_account_all(ac_prefs
);
663 account_list
= g_list_remove(account_list
, ac_prefs
);
665 if (cur_account
== ac_prefs
) cur_account
= NULL
;
666 if (!cur_account
&& account_list
) {
667 cur_account
= account_get_default();
669 ac_prefs
= (PrefsAccount
*)account_list
->data
;
670 account_set_as_default(ac_prefs
);
671 cur_account
= ac_prefs
;
677 *\brief Save Gtk object size to prefs dataset
679 static void account_size_allocate_cb(GtkWidget
*widget
,
680 GtkAllocation
*allocation
)
682 cm_return_if_fail(allocation
!= NULL
);
684 prefs_common
.accountswin_width
= allocation
->width
;
685 prefs_common
.accountswin_height
= allocation
->height
;
688 static void account_edit_create(void)
694 GtkWidget
*scrolledwin
;
695 GtkWidget
*list_view
;
701 GtkWidget
*clone_btn
;
705 GtkWidget
*default_btn
;
707 GtkWidget
*confirm_area
;
709 GtkWidget
*close_btn
;
711 static GdkGeometry geometry
;
713 debug_print("Creating account edit window...\n");
715 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "account");
716 gtk_container_set_border_width (GTK_CONTAINER (window
), 8);
717 gtk_window_set_title (GTK_WINDOW (window
), _("Edit accounts"));
718 g_signal_connect (G_OBJECT (window
), "delete_event",
719 G_CALLBACK (account_delete_event
), NULL
);
720 g_signal_connect (G_OBJECT (window
), "key_press_event",
721 G_CALLBACK (account_key_pressed
), NULL
);
722 MANAGE_WINDOW_SIGNALS_CONNECT (window
);
723 gtk_widget_realize(window
);
725 vbox
= gtk_vbox_new (FALSE
, 10);
726 gtk_widget_show (vbox
);
727 gtk_container_add (GTK_CONTAINER (window
), vbox
);
729 hbox
= gtk_hbox_new (FALSE
, 0);
730 gtk_widget_show (hbox
);
731 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
733 label
= gtk_label_new
734 (_("Using 'Get Mail' will retrieve messages from your Accounts "
735 "in the order given, the checkbox indicates which accounts "
736 "will be included. Bold text indicates the default account."));
737 gtk_widget_show (label
);
738 gtk_widget_set_size_request(GTK_WIDGET(label
),
739 prefs_common
.accountswin_width
-8, -1);
740 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 4);
741 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_LEFT
);
742 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
744 hbox
= gtk_hbox_new (FALSE
, 8);
745 gtk_widget_show (hbox
);
746 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, TRUE
, TRUE
, 0);
747 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 2);
749 scrolledwin
= gtk_scrolled_window_new (NULL
, NULL
);
750 gtk_widget_show (scrolledwin
);
751 gtk_box_pack_start (GTK_BOX (hbox
), scrolledwin
, TRUE
, TRUE
, 0);
752 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin
),
753 GTK_POLICY_AUTOMATIC
,
754 GTK_POLICY_AUTOMATIC
);
756 list_view
= account_list_view_create();
757 gtk_widget_show(list_view
);
758 gtk_container_add(GTK_CONTAINER(scrolledwin
), list_view
);
760 vbox2
= gtk_vbox_new (FALSE
, 0);
761 gtk_widget_show (vbox2
);
762 gtk_box_pack_start (GTK_BOX (hbox
), vbox2
, FALSE
, FALSE
, 0);
764 add_btn
= gtk_button_new_from_stock(GTK_STOCK_NEW
);
765 gtk_widget_show (add_btn
);
766 gtk_box_pack_start (GTK_BOX (vbox2
), add_btn
, FALSE
, FALSE
, 4);
767 g_signal_connect (G_OBJECT(add_btn
), "clicked",
768 G_CALLBACK (account_add
), NULL
);
770 edit_btn
= gtk_button_new_from_stock (GTK_STOCK_EDIT
);
771 gtk_widget_show (edit_btn
);
772 gtk_box_pack_start (GTK_BOX (vbox2
), edit_btn
, FALSE
, FALSE
, 4);
773 g_signal_connect (G_OBJECT(edit_btn
), "clicked",
774 G_CALLBACK (account_edit_prefs
), NULL
);
776 del_btn
= gtk_button_new_from_stock(GTK_STOCK_DELETE
);
777 gtk_widget_show (del_btn
);
778 gtk_box_pack_start (GTK_BOX (vbox2
), del_btn
, FALSE
, FALSE
, 4);
779 g_signal_connect (G_OBJECT(del_btn
), "clicked",
780 G_CALLBACK (account_delete
), NULL
);
782 clone_btn
= gtk_button_new_from_stock(GTK_STOCK_COPY
);
783 gtk_widget_show (clone_btn
);
784 gtk_box_pack_start (GTK_BOX (vbox2
), clone_btn
, FALSE
, FALSE
, 4);
785 g_signal_connect(G_OBJECT(clone_btn
), "clicked",
786 G_CALLBACK(account_clone
), NULL
);
788 down_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_DOWN
);
789 gtk_widget_show (down_btn
);
790 gtk_box_pack_end (GTK_BOX (vbox2
), down_btn
, FALSE
, FALSE
, 4);
791 g_signal_connect (G_OBJECT(down_btn
), "clicked",
792 G_CALLBACK (account_down
), NULL
);
794 up_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_UP
);
795 gtk_widget_show (up_btn
);
796 gtk_box_pack_end (GTK_BOX (vbox2
), up_btn
, FALSE
, FALSE
, 4);
797 g_signal_connect (G_OBJECT(up_btn
), "clicked",
798 G_CALLBACK (account_up
), NULL
);
800 hbox
= gtk_hbox_new (FALSE
, 8);
801 gtk_widget_show (hbox
);
802 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
804 default_btn
= gtk_button_new_with_mnemonic
805 (_(" _Set as default account "));
806 gtk_widget_show (default_btn
);
807 gtk_box_pack_start (GTK_BOX (hbox
), default_btn
, FALSE
, FALSE
, 0);
808 g_signal_connect (G_OBJECT(default_btn
), "clicked",
809 G_CALLBACK (account_set_default
), NULL
);
811 gtkut_stock_button_set_create_with_help(&confirm_area
, &help_btn
,
812 &close_btn
, GTK_STOCK_CLOSE
,
813 NULL
, NULL
, NULL
, NULL
);
814 gtk_widget_show(confirm_area
);
816 gtk_box_pack_end (GTK_BOX (hbox
), confirm_area
, FALSE
, FALSE
, 0);
817 gtk_widget_grab_default (close_btn
);
819 g_signal_connect (G_OBJECT (close_btn
), "clicked",
820 G_CALLBACK (account_edit_close
),
822 g_signal_connect(G_OBJECT(help_btn
), "clicked",
823 G_CALLBACK(manual_open_with_anchor_cb
),
824 MANUAL_ANCHOR_ACCOUNTPREFS
);
827 g_signal_connect(G_OBJECT(window
), "size_allocate",
828 G_CALLBACK(account_size_allocate_cb
), NULL
);
830 if (!geometry
.min_height
) {
831 geometry
.min_width
= 500;
832 geometry
.min_height
= 380;
835 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
837 gtk_widget_set_size_request(window
, prefs_common
.accountswin_width
,
838 prefs_common
.accountswin_height
);
840 gtk_window_move(GTK_WINDOW(window
), 48, 48);
843 edit_account
.window
= window
;
844 edit_account
.list_view
= list_view
;
845 edit_account
.close_btn
= close_btn
;
848 static void account_edit_prefs(GtkWidget
*widget
, gpointer data
)
850 PrefsAccount
*ac_prefs
;
852 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
855 account_open(ac_prefs
);
856 account_list_view_set();
860 static gboolean
account_delete_references_func(GNode
*node
, gpointer data
)
865 cm_return_val_if_fail(node
->data
!= NULL
, FALSE
);
867 item
= FOLDER_ITEM(node
->data
);
868 account
= GPOINTER_TO_INT(data
);
870 if(!item
->prefs
) /* && item->prefs->stype == F_NORMAL */
872 if(item
->prefs
->default_account
!= account
)
875 item
->prefs
->enable_default_account
= FALSE
;
876 item
->prefs
->default_account
= 0;
877 folder_item_prefs_save_config(item
);
883 #define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
884 g_strdup(ac_prefs->fld): NULL
885 #define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
886 static void account_clone(GtkWidget
*widget
, gpointer data
)
888 PrefsAccount
*ac_prefs
, *ac_clon
;
890 CustomHeader
*cch
= NULL
, *ch
= NULL
;
892 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
893 if (ac_prefs
== NULL
)
896 if (ac_prefs
->protocol
== A_IMAP4
|| ac_prefs
->protocol
== A_NNTP
) {
897 alertpanel_error(_("Accounts with remote folders cannot be copied."));
900 account_list_dirty
= TRUE
;
902 ac_clon
= prefs_account_new();
904 ac_clon
->account_name
= g_strdup_printf(_("Copy of %s"),
905 ac_prefs
->account_name
);
909 ACP_FDUP(organization
);
912 ACP_FASSIGN(protocol
);
913 ACP_FDUP(recv_server
);
914 ACP_FDUP(smtp_server
);
915 ACP_FDUP(nntp_server
);
916 ACP_FASSIGN(use_nntp_auth
);
917 ACP_FASSIGN(use_nntp_auth_onconnect
);
921 ACP_FDUP(local_mbox
);
922 ACP_FASSIGN(use_mail_command
);
923 ACP_FDUP(mail_command
);
925 ACP_FASSIGN(ssl_pop
);
926 ACP_FASSIGN(ssl_imap
);
927 ACP_FASSIGN(ssl_nntp
);
928 ACP_FASSIGN(ssl_smtp
);
929 ACP_FASSIGN(use_nonblocking_ssl
);
932 ACP_FASSIGN(use_apop_auth
);
934 ACP_FASSIGN(msg_leave_time
);
935 ACP_FASSIGN(msg_leave_hour
);
936 ACP_FASSIGN(recv_at_getall
);
937 ACP_FASSIGN(sd_rmmail_on_download
);
938 ACP_FASSIGN(enable_size_limit
);
939 ACP_FASSIGN(size_limit
);
940 ACP_FASSIGN(filter_on_recv
);
941 ACP_FASSIGN(filterhook_on_recv
);
943 ACP_FDUP(local_inbox
);
944 ACP_FASSIGN(max_articles
);
946 ACP_FASSIGN(imap_auth_type
);
949 ACP_FASSIGN(gen_msgid
);
950 ACP_FASSIGN(gen_xmailer
);
951 ACP_FASSIGN(add_customhdr
);
952 ACP_FASSIGN(use_smtp_auth
);
953 ACP_FASSIGN(smtp_auth_type
);
954 ACP_FDUP(smtp_userid
);
955 ACP_FDUP(smtp_passwd
);
957 ACP_FASSIGN(pop_before_smtp
);
958 ACP_FASSIGN(pop_before_smtp_timeout
);
959 ACP_FASSIGN(last_pop_login_time
);
961 ac_clon
->customhdr_list
= NULL
;
962 hdrs
= ac_prefs
->customhdr_list
;
963 while (hdrs
!= NULL
) {
964 ch
= (CustomHeader
*)hdrs
->data
;
966 cch
= g_new0(CustomHeader
, 1);
967 cch
->account_id
= ac_clon
->account_id
;
968 cch
->name
= (ch
->name
!= NULL
) ? g_strdup(ch
->name
) : NULL
;
969 cch
->value
= (ch
->value
!= NULL
) ? g_strdup(ch
->value
) : NULL
;
971 ac_clon
->customhdr_list
= g_slist_append(ac_clon
->customhdr_list
, cch
);
973 hdrs
= g_slist_next(hdrs
);
977 ACP_FASSIGN(sig_type
);
979 ACP_FASSIGN(auto_sig
);
981 ACP_FASSIGN(set_autocc
);
983 ACP_FASSIGN(set_autobcc
);
985 ACP_FASSIGN(set_autoreplyto
);
986 ACP_FDUP(auto_replyto
);
987 ACP_FASSIGN(enable_default_dictionary
);
988 ACP_FDUP(default_dictionary
);
989 ACP_FASSIGN(enable_default_alt_dictionary
);
990 ACP_FDUP(default_alt_dictionary
);
991 ACP_FASSIGN(compose_with_format
);
992 ACP_FDUP(compose_subject_format
);
993 ACP_FDUP(compose_body_format
);
994 ACP_FASSIGN(reply_with_format
);
995 ACP_FDUP(reply_quotemark
);
996 ACP_FDUP(reply_body_format
);
997 ACP_FASSIGN(forward_with_format
);
998 ACP_FDUP(forward_quotemark
);
999 ACP_FDUP(forward_body_format
);
1002 ACP_FDUP(default_privacy_system
);
1003 ACP_FASSIGN(default_encrypt
);
1004 ACP_FASSIGN(default_encrypt_reply
);
1005 ACP_FASSIGN(default_sign
);
1006 ACP_FASSIGN(default_sign_reply
);
1007 ACP_FASSIGN(save_encrypted_as_clear_text
);
1008 ACP_FASSIGN(encrypt_to_self
);
1011 ACP_FASSIGN(set_smtpport
);
1012 ACP_FASSIGN(smtpport
);
1013 ACP_FASSIGN(set_popport
);
1014 ACP_FASSIGN(popport
);
1015 ACP_FASSIGN(set_imapport
);
1016 ACP_FASSIGN(imapport
);
1017 ACP_FASSIGN(set_nntpport
);
1018 ACP_FASSIGN(nntpport
);
1019 ACP_FASSIGN(set_domain
);
1021 ACP_FASSIGN(mark_crosspost_read
);
1022 ACP_FASSIGN(crosspost_col
);
1025 ACP_FASSIGN(set_tunnelcmd
);
1026 ACP_FDUP(tunnelcmd
);
1030 ACP_FASSIGN(imap_subsonly
);
1031 ACP_FASSIGN(low_bandwidth
);
1033 ACP_FASSIGN(set_sent_folder
);
1034 ACP_FDUP(sent_folder
);
1035 ACP_FASSIGN(set_queue_folder
);
1036 ACP_FDUP(queue_folder
);
1037 ACP_FASSIGN(set_draft_folder
);
1038 ACP_FDUP(draft_folder
);
1039 ACP_FASSIGN(set_trash_folder
);
1040 ACP_FDUP(trash_folder
);
1041 /* don't want two default accounts */
1042 ac_clon
->is_default
= FALSE
;
1043 ACP_FASSIGN(folder
);
1045 account_list
= g_list_append(account_list
, ac_clon
);
1046 account_list_view_set();
1051 static void account_delete(GtkWidget
*widget
, gpointer data
)
1053 PrefsAccount
*ac_prefs
;
1054 gchar buf
[BUFFSIZE
];
1059 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
1060 if (ac_prefs
== NULL
)
1063 g_snprintf(buf
, sizeof(buf
),
1064 _("Do you really want to delete the account '%s'?"),
1065 ac_prefs
->account_name
? ac_prefs
->account_name
:
1067 if (alertpanel_full(_("Delete account"), buf
,
1068 GTK_STOCK_CANCEL
, GTK_STOCK_DELETE
, NULL
, FALSE
,
1069 NULL
, ALERT_WARNING
, G_ALERTDEFAULT
) != G_ALERTALTERNATE
)
1071 account_list_dirty
= TRUE
;
1073 if (ac_prefs
->folder
) {
1076 item
= mainwindow_get_mainwindow()->summaryview
->folder_item
;
1077 if (item
&& item
->folder
== FOLDER(ac_prefs
->folder
))
1078 summary_clear_all(mainwindow_get_mainwindow()->summaryview
);
1079 folder_destroy(FOLDER(ac_prefs
->folder
));
1080 folderview_set_all();
1082 account_destroy(ac_prefs
);
1083 account_list_view_set();
1085 debug_print("Removing deleted account references for all the folders...\n");
1086 list
= folder_get_list();
1087 for (; list
!= NULL
; list
= list
->next
) {
1088 folder
= FOLDER(list
->data
);
1089 if (folder
->node
) /* && folder->type == F_? */
1090 g_node_traverse(folder
->node
, G_PRE_ORDER
,
1092 account_delete_references_func
,
1093 GINT_TO_POINTER(ac_prefs
->account_id
));
1096 debug_print("Removing filter rules relative to this account...\n");
1097 for(cur
= filtering_rules
; cur
!= NULL
;) {
1098 FilteringProp
* prop
= (FilteringProp
*) cur
->data
;
1100 if (prop
&& (prop
->account_id
== ac_prefs
->account_id
)) {
1101 /* get next item before we kill the current one */
1102 cur
= g_slist_next(cur
);
1104 /* unallocate filteringprop and unchain it from the list */
1105 filteringprop_free(prop
);
1106 filtering_rules
= g_slist_remove(filtering_rules
, prop
);
1108 cur
= g_slist_next(cur
);
1111 folder_write_list();
1114 static void account_up(GtkWidget
*widget
, gpointer data
)
1116 GtkTreePath
*sel
= account_list_view_get_selected_account_path
1117 (edit_account
.list_view
),
1119 GtkTreeIter isel
, iup
;
1120 GtkTreeModel
*model
= gtk_tree_view_get_model
1121 (GTK_TREE_VIEW(edit_account
.list_view
));
1125 account_list_dirty
= TRUE
;
1127 up
= gtk_tree_path_copy(sel
);
1129 gtk_tree_path_free(sel
);
1133 if (!gtk_tree_path_prev(up
)) {
1134 gtk_tree_path_free(up
);
1135 gtk_tree_path_free(sel
);
1139 if (!gtk_tree_model_get_iter(model
, &isel
, sel
)
1140 || !gtk_tree_model_get_iter(model
, &iup
, up
)) {
1141 gtk_tree_path_free(up
);
1142 gtk_tree_path_free(sel
);
1146 gtk_list_store_swap(GTK_LIST_STORE(model
), &isel
, &iup
);
1150 gtk_tree_path_free(up
);
1151 gtk_tree_path_free(sel
);
1154 static void account_down(GtkWidget
*widget
, gpointer data
)
1156 GtkTreePath
*sel
= account_list_view_get_selected_account_path
1157 (edit_account
.list_view
),
1159 GtkTreeIter isel
, idn
;
1160 GtkTreeModel
*model
= gtk_tree_view_get_model
1161 (GTK_TREE_VIEW(edit_account
.list_view
));
1165 account_list_dirty
= TRUE
;
1167 dn
= gtk_tree_path_copy(sel
);
1169 gtk_tree_path_free(sel
);
1173 /* XXX no check possible??? however, if down but at bottom, then
1174 * nothing seems to happen much anyway, so the following seems to
1176 gtk_tree_path_next(dn
);
1178 if (!gtk_tree_model_get_iter(model
, &isel
, sel
)
1179 || !gtk_tree_model_get_iter(model
, &idn
, dn
)) {
1180 gtk_tree_path_free(dn
);
1181 gtk_tree_path_free(sel
);
1185 gtk_list_store_swap(GTK_LIST_STORE(model
), &isel
, &idn
);
1189 gtk_tree_path_free(dn
);
1190 gtk_tree_path_free(sel
);
1193 static void account_set_default(GtkWidget
*widget
, gpointer data
)
1195 PrefsAccount
*ac_prefs
;
1197 if (NULL
== (ac_prefs
= account_list_view_get_selected_account
1198 (edit_account
.list_view
)))
1201 /* we need to change the store variables by resetting everything
1202 * and setting the new default one */
1203 account_list_view_set_default_by_id(edit_account
.list_view
,
1204 ac_prefs
->account_id
);
1206 account_set_as_default(ac_prefs
);
1207 account_list_view_set();
1209 cur_account
= ac_prefs
;
1210 account_flush_state();
1213 static void account_edit_close(GtkWidget
*widget
, gpointer data
)
1216 account_write_config_all();
1218 if (!cur_account
&& account_list
) {
1219 PrefsAccount
*ac_prefs
= (PrefsAccount
*)account_list
->data
;
1220 account_set_as_default(ac_prefs
);
1221 cur_account
= ac_prefs
;
1224 if (account_list_dirty
)
1225 account_flush_state();
1227 gtk_widget_hide(edit_account
.window
);
1228 gtk_window_set_modal(GTK_WINDOW(edit_account
.window
), FALSE
);
1232 static gint
account_delete_event(GtkWidget
*widget
, GdkEventAny
*event
,
1235 account_edit_close(NULL
, NULL
);
1239 static gboolean
account_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1242 if (event
&& event
->keyval
== GDK_KEY_Escape
)
1243 account_edit_close(NULL
, NULL
);
1247 static gboolean
account_search_func_cb (GtkTreeModel
*model
, gint column
, const gchar
*key
,
1248 GtkTreeIter
*iter
, gpointer search_data
)
1253 gtk_tree_model_get (model
, iter
, ACCOUNT_DATA
, &ac
, -1);
1255 if (!ac
->name
|| !key
) return FALSE
;
1257 retval
= (strncmp (key
, ac
->account_name
, strlen(key
)) != 0);
1259 debug_print("selecting row\n");
1260 account_list_view_select_account(edit_account
.list_view
, ac
->account_id
);
1264 static void account_list_view_add(PrefsAccount
*ac_prefs
)
1266 GtkTreeView
*list_view
= GTK_TREE_VIEW(edit_account
.list_view
);
1267 GtkListStore
*list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(list_view
));
1268 gchar
*name
, *protocol
, *server
;
1269 gboolean has_getallbox
;
1272 name
= ac_prefs
->account_name
;
1274 protocol
= ac_prefs
->protocol
== A_POP3
?
1275 (ac_prefs
->ssl_pop
== SSL_TUNNEL
?
1277 ac_prefs
->ssl_pop
== SSL_STARTTLS
?
1278 "POP3 (TLS)" : "POP3") :
1279 ac_prefs
->protocol
== A_IMAP4
?
1280 (ac_prefs
->ssl_imap
== SSL_TUNNEL
?
1282 ac_prefs
->ssl_imap
== SSL_STARTTLS
?
1283 "IMAP4 (TLS)" : "IMAP4") :
1284 ac_prefs
->protocol
== A_NNTP
?
1285 (ac_prefs
->ssl_nntp
== SSL_TUNNEL
?
1286 "NNTP (SSL)" : "NNTP") :
1287 ac_prefs
->protocol
== A_LOCAL
? "Local" :
1288 ac_prefs
->protocol
== A_NONE
? "SMTP" : "-";
1290 protocol
= ac_prefs
->protocol
== A_POP3
? "POP3" :
1291 ac_prefs
->protocol
== A_IMAP4
? "IMAP4" :
1292 ac_prefs
->protocol
== A_LOCAL
? "Local" :
1293 ac_prefs
->protocol
== A_NNTP
? "NNTP" :
1294 ac_prefs
->protocol
== A_NONE
? "SMTP" : "-";
1296 server
= ac_prefs
->protocol
== A_NNTP
? ac_prefs
->nntp_server
:
1297 ac_prefs
->protocol
== A_LOCAL
? "-" :
1298 ac_prefs
->protocol
== A_NONE
? ac_prefs
->smtp_server
:
1299 ac_prefs
->recv_server
;
1301 has_getallbox
= (ac_prefs
->protocol
== A_POP3
||
1302 ac_prefs
->protocol
== A_IMAP4
||
1303 ac_prefs
->protocol
== A_NNTP
||
1304 ac_prefs
->protocol
== A_LOCAL
);
1305 getall
= has_getallbox
&& ac_prefs
->recv_at_getall
;
1307 account_list_view_insert_account_item(list_store
,
1308 name
, protocol
, server
,
1309 ac_prefs
->is_default
,
1314 static void account_list_view_set(void)
1317 gint prev_sel_account
;
1318 GtkListStore
*store
;
1320 store
= GTK_LIST_STORE(gtk_tree_view_get_model
1321 (GTK_TREE_VIEW(edit_account
.list_view
)));
1323 prev_sel_account
= account_list_view_get_selected_account_id
1324 (edit_account
.list_view
);
1326 gtk_list_store_clear(store
);
1328 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
1329 account_list_view_add((PrefsAccount
*)cur
->data
);
1330 if ((PrefsAccount
*)cur
->data
== cur_account
)
1331 account_list_view_select_account
1332 (edit_account
.list_view
,
1333 cur_account
->account_id
);
1336 if (prev_sel_account
>= 0)
1337 account_list_view_select_account(edit_account
.list_view
,
1341 /* set account list from CList */
1342 static void account_list_set(void)
1344 /* want to make sure we iterate *IN ORDER*, so therefore using
1345 * gtk_tree_model_XXXX_nth_child() */
1347 PrefsAccount
*ac_prefs
;
1348 GtkTreeModel
*model
= gtk_tree_view_get_model
1349 (GTK_TREE_VIEW(edit_account
.list_view
));
1351 while (account_list
)
1352 account_list
= g_list_remove(account_list
, account_list
->data
);
1354 n_rows
= gtk_tree_model_iter_n_children(model
, NULL
);
1356 for (row
= 0; row
< n_rows
; row
++) {
1359 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
)) {
1360 g_warning("%s(%d) - no iter found???\n", __FILE__
, __LINE__
);
1365 gtk_tree_model_get(model
, &iter
,
1366 ACCOUNT_DATA
, &ac_prefs
,
1369 account_list
= g_list_append(account_list
, ac_prefs
);
1374 *\brief finds the PrefsAccounts which should be used to answer a mail
1376 *\param msginfo The message to be answered
1377 *\param reply_autosel Indicates whether reply account autoselection is on
1379 *\return PrefsAccount * the correct account, NULL if not found
1381 PrefsAccount
*account_get_reply_account(MsgInfo
*msginfo
, gboolean reply_autosel
)
1383 PrefsAccount
*account
= NULL
;
1384 /* select the account set in folderitem's property (if enabled) */
1385 if (msginfo
->folder
->prefs
&& msginfo
->folder
->prefs
->enable_default_account
)
1386 account
= account_find_from_id(msginfo
->folder
->prefs
->default_account
);
1388 /* select account by to: and cc: header if enabled */
1389 if (reply_autosel
) {
1390 gchar
* field
= NULL
;
1392 for (field
= msginfo
->to
; fieldno
++ < 2; field
= msginfo
->cc
) {
1393 if (!account
&& field
) {
1394 gchar
*f
= g_strdup(field
);
1400 next
= strchr_with_skip_quote(cur
, '"', ',');
1403 Xstrdup_a(to
, cur
, return NULL
);
1404 extract_address(to
);
1405 account
= account_find_from_address(to
, FALSE
);
1416 gchar deliveredto
[BUFFSIZE
];
1417 if (!procheader_get_header_from_msginfo
1418 (msginfo
, deliveredto
,sizeof deliveredto
, "Delivered-To:")) {
1419 gchar
*buf
= deliveredto
+ strlen("Delivered-To:");
1420 extract_address(buf
);
1421 account
= account_find_from_address(buf
, FALSE
);
1426 /* select the account for the whole folder (IMAP / NNTP) */
1428 /* FIXME: this is not right, because folder may be nested. we should
1429 * ascend the tree until we find a parent with proper account
1431 account
= msginfo
->folder
->folder
->account
;
1433 /* select current account */
1434 if (!account
) account
= cur_account
;
1440 *\brief Create data store
1442 static GtkListStore
* account_create_data_store(void)
1444 return gtk_list_store_new(N_ACCOUNT_COLUMNS
,
1445 G_TYPE_INT
, /* ACCOUNT_IS_DEFAULT */
1446 G_TYPE_BOOLEAN
, /* ACCOUNT_ENABLE_GET_ALL */
1447 G_TYPE_STRING
, /* ACCOUNT_NAME */
1448 G_TYPE_STRING
, /* ACCOUNT_PROTOCOL */
1449 G_TYPE_STRING
, /* ACCOUNT_SERVER */
1450 G_TYPE_POINTER
, /* ACCOUNT_DATA */
1455 *\brief Insert an account item in the list.
1457 *\return GtkTreeRowReference * A tree row reference, which is guaranteed to
1458 * stable whatever operations are performed on the list.
1460 static void account_list_view_insert_account_item(GtkListStore
*list_store
,
1461 const gchar
*account_name
,
1462 const gchar
*protocol
,
1463 const gchar
*server_name
,
1464 gboolean is_default
,
1465 gboolean is_get_all
,
1466 PrefsAccount
*account_data
)
1470 gtk_list_store_append(list_store
, &iter
);
1471 gtk_list_store_set(list_store
, &iter
,
1472 ACCOUNT_IS_DEFAULT
, is_default
? PANGO_WEIGHT_BOLD
: PANGO_WEIGHT_NORMAL
,
1473 ACCOUNT_ENABLE_GET_ALL
, is_get_all
,
1474 ACCOUNT_NAME
, account_name
,
1475 ACCOUNT_PROTOCOL
, protocol
,
1476 ACCOUNT_SERVER
, server_name
,
1477 ACCOUNT_DATA
, account_data
,
1482 *\brief Create and set up account list view, including tasks like
1483 * creating the data store (\ref account_create_data_store()),
1484 * and setting up the account list's individual columns (\ref
1485 * account_create_list_view_columns()).
1487 *\return GtkWidget * The created list view widget.
1489 static GtkWidget
*account_list_view_create(void)
1491 GtkTreeView
*list_view
;
1492 GtkTreeSelection
*selector
;
1493 GtkListStore
*store
= account_create_data_store();
1495 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
)));
1496 g_object_unref(G_OBJECT(store
));
1498 g_object_set(list_view
, "allow-checkbox-mode", FALSE
, NULL
);
1500 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
1501 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1503 selector
= gtk_tree_view_get_selection(list_view
);
1504 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
1506 /* create the columns */
1507 account_create_list_view_columns(GTK_WIDGET(list_view
));
1509 /* set a double click listener */
1510 g_signal_connect(G_OBJECT(list_view
), "row_activated",
1511 G_CALLBACK(account_double_clicked
),
1514 g_signal_connect(G_OBJECT(list_view
), "drag_begin",
1515 G_CALLBACK(drag_begin
),
1518 g_signal_connect(G_OBJECT(list_view
), "drag_end",
1519 G_CALLBACK(drag_end
),
1522 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1523 return GTK_WIDGET(list_view
);
1526 static void account_create_list_view_columns(GtkWidget
*list_view
)
1528 GtkTreeViewColumn
*column
;
1529 GtkCellRenderer
*renderer
;
1531 renderer
= gtk_cell_renderer_toggle_new();
1532 g_object_set(renderer
,
1534 "activatable", TRUE
,
1536 column
= gtk_tree_view_column_new_with_attributes
1537 (C_("Accounts List Get Column Name", "G"), renderer
,
1538 "active", ACCOUNT_ENABLE_GET_ALL
,
1540 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1541 gtk_tree_view_column_set_alignment (column
, 0.5);
1542 CLAWS_SET_TIP(gtk_tree_view_column_get_widget(column
),
1543 _("'Get Mail' retrieves mail from the checked accounts"));
1544 g_signal_connect(G_OBJECT(renderer
), "toggled",
1545 G_CALLBACK(account_get_all_toggled
),
1548 renderer
= gtk_cell_renderer_text_new();
1549 column
= gtk_tree_view_column_new_with_attributes
1550 (_("Name"), renderer
,
1551 "text", ACCOUNT_NAME
,
1552 "weight", ACCOUNT_IS_DEFAULT
,
1554 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1556 renderer
= gtk_cell_renderer_text_new();
1557 column
= gtk_tree_view_column_new_with_attributes
1558 (_("Protocol"), renderer
,
1559 "text", ACCOUNT_PROTOCOL
,
1560 "weight", ACCOUNT_IS_DEFAULT
,
1562 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1564 renderer
= gtk_cell_renderer_text_new();
1565 column
= gtk_tree_view_column_new_with_attributes
1566 (_("Server"), renderer
,
1567 "text", ACCOUNT_SERVER
,
1568 "weight", ACCOUNT_IS_DEFAULT
,
1570 gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view
), ACCOUNT_NAME
);
1571 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view
), account_search_func_cb
, NULL
, NULL
);
1572 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1576 *\brief Get currently selected account (by its unique ID)
1578 static gint
account_list_view_get_selected_account_id(GtkWidget
*list_view
)
1580 GtkTreeSelection
*selector
;
1581 GtkTreeModel
*model
;
1583 PrefsAccount
*res
= NULL
;
1585 selector
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1587 if (!gtk_tree_selection_get_selected(selector
, &model
, &iter
))
1590 gtk_tree_model_get(model
, &iter
, ACCOUNT_DATA
, &res
, -1);
1592 return res
->account_id
;
1596 *\brief Get the tree path of the currently selected account
1598 static GtkTreePath
*account_list_view_get_selected_account_path(GtkWidget
*list_view
)
1600 GtkTreeSelection
*selector
;
1601 GtkTreeModel
*model
;
1604 selector
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1606 if (!gtk_tree_selection_get_selected(selector
, &model
, &iter
))
1609 return gtk_tree_model_get_path(gtk_tree_view_get_model
1610 (GTK_TREE_VIEW(list_view
)), &iter
);
1614 *\brief Get the account data of the currently selected account
1616 static PrefsAccount
*account_list_view_get_selected_account(GtkWidget
*list_view
)
1618 GtkTreeSelection
*selector
;
1619 GtkTreeModel
*model
;
1621 PrefsAccount
*res
= NULL
;
1623 selector
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1625 if (!gtk_tree_selection_get_selected(selector
, &model
, &iter
))
1628 gtk_tree_model_get(model
, &iter
, ACCOUNT_DATA
, &res
, -1);
1634 *\brief Select a row by the account it represents
1636 *\return gboolean TRUE if found and selected, FALSE if not.
1638 static gboolean
account_list_view_select_account(GtkWidget
*list_view
, gint account_id
)
1640 FindAccountInStore fis
;
1641 GtkTreeModel
*model
;
1643 fis
.account_id
= account_id
;
1646 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1648 gtk_tree_model_foreach(model
, (GtkTreeModelForeachFunc
) find_account_in_store
,
1652 GtkTreeSelection
*selection
;
1655 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1656 gtk_tree_selection_select_iter(selection
, &fis
.iter
);
1657 path
= gtk_tree_model_get_path(model
, &fis
.iter
);
1658 /* XXX returned path may not be valid??? create new one to be sure */
1659 gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view
), path
, NULL
, FALSE
);
1660 gtk_tree_path_free(path
);
1663 return fis
.path
!= NULL
;
1667 *\brief Set a new default account by its ID. (There is only one
1670 static void account_list_view_set_default_by_id(GtkWidget
*list_view
,
1673 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1675 gtk_tree_model_foreach
1676 (model
, (GtkTreeModelForeachFunc
) set_new_default_account
,
1680 static gboolean
set_new_default_account(GtkTreeModel
*model
,
1685 PrefsAccount
*account
= NULL
;
1688 gtk_tree_model_get(model
, iter
,
1689 ACCOUNT_DATA
, &account
,
1692 if (*account_id
== account
->account_id
)
1693 weight
= PANGO_WEIGHT_NORMAL
;
1695 weight
= PANGO_WEIGHT_BOLD
;
1697 gtk_list_store_set(GTK_LIST_STORE(model
), iter
,
1698 ACCOUNT_IS_DEFAULT
, weight
, -1);
1703 static gboolean
find_account_in_store(GtkTreeModel
*model
,
1706 FindAccountInStore
*data
)
1708 PrefsAccount
*account
= NULL
;
1709 gtk_tree_model_get(model
, iter
, ACCOUNT_DATA
, &account
, -1);
1711 if (data
->account_id
== account
->account_id
) {
1712 data
->path
= path
; /* signal we found it */
1721 *\brief Triggered when "get all" column is activated or de-activated
1723 static void account_get_all_toggled(GtkCellRendererToggle
*widget
,
1725 GtkWidget
*list_view
)
1728 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1729 PrefsAccount
*ac
= NULL
;
1732 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
1735 gtk_tree_model_get(model
, &iter
,
1737 ACCOUNT_ENABLE_GET_ALL
, &get_all
,
1740 /* check if the account has a selectable get all checkbox anyway... */
1741 if (!(ac
->protocol
== A_POP3
||
1742 ac
->protocol
== A_IMAP4
||
1743 ac
->protocol
== A_NNTP
||
1744 ac
->protocol
== A_LOCAL
))
1747 /* set value in store */
1748 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
1749 ACCOUNT_ENABLE_GET_ALL
, !get_all
,
1752 /* set value in account */
1753 ac
->recv_at_getall
^= TRUE
;
1756 static void account_double_clicked(GtkTreeView
*list_view
,
1758 GtkTreeViewColumn
*column
,
1761 account_edit_prefs(NULL
, NULL
);
1764 static void drag_begin(GtkTreeView
*list_view
,
1765 GdkDragContext
*context
,
1768 /* XXX unfortunately a completed drag & drop does not emit
1769 * a "rows_reordered" signal, but a "row_changed" signal.
1770 * So during drag and drop, listen to "row_changed", and
1771 * update the account list accordingly */
1773 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1774 g_signal_connect(G_OBJECT(model
), "row_changed",
1775 G_CALLBACK(account_row_changed_while_drag_drop
),
1779 static void drag_end(GtkTreeView
*list_view
,
1780 GdkDragContext
*context
,
1783 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1784 g_signal_handlers_disconnect_by_func(G_OBJECT(model
),
1785 G_CALLBACK(account_row_changed_while_drag_drop
),
1789 static void account_row_changed_while_drag_drop(GtkTreeModel
*model
,
1793 GtkTreeView
*list_view
)
1798 gchar
*account_get_signature_str(PrefsAccount
*account
)
1800 gchar
*sig_body
= NULL
;
1801 gchar
*sig_str
= NULL
;
1802 gchar
*utf8_sig_str
= NULL
;
1804 cm_return_val_if_fail(account
!= NULL
, NULL
);
1806 if (!account
->sig_path
)
1809 if (account
->sig_type
== SIG_FILE
) {
1810 if (!is_file_or_fifo_exist(account
->sig_path
)) {
1811 g_warning("can't open signature file: %s\n",
1817 if (account
->sig_type
== SIG_COMMAND
)
1818 sig_body
= get_command_output(account
->sig_path
);
1822 tmp
= file_read_to_str(account
->sig_path
);
1825 sig_body
= normalize_newlines(tmp
);
1829 if (account
->sig_sep
) {
1830 sig_str
= g_strconcat("\n", account
->sig_sep
, "\n", sig_body
,
1834 sig_str
= g_strconcat("\n", sig_body
, NULL
);
1837 if (g_utf8_validate(sig_str
, -1, NULL
) == TRUE
)
1838 utf8_sig_str
= sig_str
;
1840 utf8_sig_str
= conv_codeset_strdup
1841 (sig_str
, conv_get_locale_charset_str_no_utf8(),
1847 return utf8_sig_str
;
1850 PrefsAccount
*account_get_cur_account (void)
1855 gboolean
password_get(const gchar
*user
,
1856 const gchar
*server
,
1857 const gchar
*protocol
,
1861 PasswordRequest req
;
1863 /* all have to be set */
1864 cm_return_val_if_fail(user
!= NULL
, FALSE
);
1865 cm_return_val_if_fail(server
!= NULL
, FALSE
);
1866 cm_return_val_if_fail(protocol
!= NULL
, FALSE
);
1867 cm_return_val_if_fail(port
!= 0, FALSE
);
1870 req
.server
= server
;
1871 req
.protocol
= protocol
;
1874 if (hooks_invoke(PASSWORD_GET_HOOKLIST
, &req
)) {
1875 *password
= req
.password
;