aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-account-gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/mail-account-gui.c')
-rw-r--r--mail/mail-account-gui.c251
1 files changed, 125 insertions, 126 deletions
diff --git a/mail/mail-account-gui.c b/mail/mail-account-gui.c
index 4b34e26bae..03f277dfc2 100644
--- a/mail/mail-account-gui.c
+++ b/mail/mail-account-gui.c
@@ -35,6 +35,7 @@
#include <e-util/e-account-list.h>
#include <e-util/e-dialog-utils.h>
+#include <e-util/e-signature-list.h>
#include "em-account-prefs.h"
#include "em-folder-selection-button.h"
@@ -1277,65 +1278,113 @@ construct_ssl_menu (MailAccountGuiService *service)
}
static void
-clear_menu (GtkWidget *menu)
+signature_added (ESignatureList *signatures, ESignature *sig, MailAccountGui *gui)
{
- while (GTK_MENU_SHELL (menu)->children)
- gtk_container_remove (GTK_CONTAINER (menu), GTK_MENU_SHELL (menu)->children->data);
+ GtkWidget *menu, *item;
+
+ menu = gtk_option_menu_get_menu (gui->sig_menu);
+ if (sig->autogen)
+ item = gtk_menu_item_new_with_label (_("Autogenerated"));
+ else
+ item = gtk_menu_item_new_with_label (sig->name);
+ g_object_set_data ((GObject *) item, "sig", sig);
+ gtk_widget_show (item);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ gtk_option_menu_set_history (gui->sig_menu, g_list_length (GTK_MENU_SHELL (menu)->children));
}
-static inline int
-sig_get_index (MailConfigSignature *sig)
+static void
+signature_removed (ESignatureList *signatures, ESignature *sig, MailAccountGui *gui)
+{
+ GtkWidget *menu;
+ ESignature *cur;
+ GList *items;
+
+ if (gui->sig_uid == sig->uid)
+ gui->sig_uid = NULL;
+
+ menu = gtk_option_menu_get_menu (gui->sig_menu);
+ items = GTK_MENU_SHELL (menu)->children;
+ while (items != NULL) {
+ cur = g_object_get_data (items->data, "sig");
+ if (cur == sig) {
+ gtk_widget_destroy (items->data);
+ break;
+ }
+ items = items->next;
+ }
+}
+
+static void
+signature_changed (ESignatureList *signatures, ESignature *sig, MailAccountGui *gui)
{
- return sig ? sig->id + 2 : 0;
+ GtkWidget *menu;
+ ESignature *cur;
+ GList *items;
+
+ menu = gtk_option_menu_get_menu (gui->sig_menu);
+ items = GTK_MENU_SHELL (menu)->children;
+ while (items != NULL) {
+ cur = g_object_get_data (items->data, "sig");
+ if (cur == sig) {
+ gtk_label_set ((GtkLabel *) ((GtkBin *) items->data)->child, sig->name);
+ break;
+ }
+ items = items->next;
+ }
}
-static inline int
-sig_gui_get_index (MailAccountGui *gui)
+static void
+clear_menu (GtkWidget *menu)
{
- if (gui->auto_signature)
- return 1;
- return sig_get_index (gui->def_signature);
+ while (GTK_MENU_SHELL (menu)->children)
+ gtk_container_remove (GTK_CONTAINER (menu), GTK_MENU_SHELL (menu)->children->data);
}
static void
-sig_fill_options (MailAccountGui *gui)
+sig_fill_menu (MailAccountGui *gui)
{
+ ESignatureList *signatures;
GtkWidget *menu;
- GtkWidget *mi;
- GSList *l;
- MailConfigSignature *sig;
+ EIterator *it;
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (gui->sig_option_menu));
+ menu = gtk_option_menu_get_menu (gui->sig_menu);
+ clear_menu (menu);
- if (menu)
- clear_menu (menu);
- else
- menu = gtk_menu_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_menu_item_new_with_label (_("None")));
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_menu_item_new_with_label (_("None")));
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_menu_item_new_with_label (_("Autogenerated")));
- /* gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtk_menu_item_new_with_label (_("Random"))); */
+ signatures = mail_config_get_signatures ();
+ it = e_list_get_iterator ((EList *) signatures);
- for (l = mail_config_get_signature_list (); l; l = l->next) {
- sig = l->data;
- mi = gtk_menu_item_new_with_label (sig->name);
- g_object_set_data ((GObject *) mi, "sig", sig);
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ while (e_iterator_is_valid (it)) {
+ ESignature *sig;
+
+ sig = (ESignature *) e_iterator_get (it);
+ signature_added (signatures, sig, gui);
+ e_iterator_next (it);
}
+
+ g_object_unref (it);
+
+ gui->sig_added_id = g_signal_connect (signatures, "signature-added", G_CALLBACK (signature_added), gui);
+ gui->sig_removed_id = g_signal_connect (signatures, "signature-removed", G_CALLBACK (signature_removed), gui);
+ gui->sig_changed_id = g_signal_connect (signatures, "signature-changed", G_CALLBACK (signature_changed), gui);
+
+ gtk_option_menu_set_history (gui->sig_menu, 0);
}
static void
-sig_changed (GtkWidget *w, MailAccountGui *gui)
+sig_changed (GtkWidget *menu, MailAccountGui *gui)
{
GtkWidget *active;
- int index;
+ ESignature *sig;
- active = gtk_menu_get_active (GTK_MENU (w));
- index = g_list_index (GTK_MENU_SHELL (w)->children, active);
+ active = gtk_menu_get_active (GTK_MENU (menu));
+ sig = g_object_get_data ((GObject *) active, "sig");
- gui->def_signature = (MailConfigSignature *) g_object_get_data (G_OBJECT (active), "sig");
- gui->auto_signature = index == 1 ? TRUE : FALSE;
+ gui->sig_uid = sig ? sig->uid : NULL;
}
static void
@@ -1364,102 +1413,54 @@ sig_add_new_signature (GtkWidget *w, MailAccountGui *gui)
parent = gtk_widget_get_toplevel (w);
parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
- gui->def_signature = em_composer_prefs_new_signature ((GtkWindow *) parent, send_html, NULL);
- gui->auto_signature = FALSE;
-
- gtk_option_menu_set_history (GTK_OPTION_MENU (gui->sig_option_menu), sig_gui_get_index (gui));
+ em_composer_prefs_new_signature ((GtkWindow *) parent, send_html, NULL);
}
static void
-setup_signatures (MailAccountGui *gui)
+select_account_signature (MailAccountGui *gui)
{
- MailConfigSignature *sig;
- GSList *signatures;
+ ESignature *sig, *cur;
+ GtkWidget *menu;
+ GList *items;
+ int i = 0;
- signatures = mail_config_get_signature_list ();
- sig = g_slist_nth_data (signatures, gui->account->id->def_signature);
+ if (!gui->account->id->sig_uid || !(sig = mail_config_get_signature_by_uid (gui->account->id->sig_uid)))
+ return;
- gui->def_signature = sig;
- gui->auto_signature = gui->account->id->auto_signature;
- gtk_option_menu_set_history (GTK_OPTION_MENU (gui->sig_option_menu), sig_gui_get_index (gui));
-}
-
-static void
-sig_event_client (MailConfigSigEvent event, MailConfigSignature *sig, MailAccountGui *gui)
-{
- switch (event) {
- case MAIL_CONFIG_SIG_EVENT_ADDED: {
- GtkWidget *menu;
- GtkWidget *mi;
-
- d(printf ("accounts ADDED\n"));
- mi = gtk_menu_item_new_with_label (sig->name);
- g_object_set_data ((GObject *) mi, "sig", sig);
- gtk_widget_show (mi);
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (gui->sig_option_menu));
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
-
- break;
- }
- case MAIL_CONFIG_SIG_EVENT_NAME_CHANGED: {
- GtkWidget *menu;
- GtkWidget *mi;
-
- d(printf ("gui NAME CHANGED\n"));
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (gui->sig_option_menu));
- gtk_widget_ref (menu);
- gtk_option_menu_remove_menu (GTK_OPTION_MENU (gui->sig_option_menu));
- mi = g_list_nth_data (GTK_MENU_SHELL (menu)->children, sig_get_index (sig));
- gtk_label_set_text (GTK_LABEL (GTK_BIN (mi)->child), sig->name);
- gtk_option_menu_set_menu (GTK_OPTION_MENU (gui->sig_option_menu), menu);
- gtk_widget_unref (menu);
- gtk_option_menu_set_history (GTK_OPTION_MENU (gui->sig_option_menu),
- sig_gui_get_index (gui));
-
- break;
- }
- case MAIL_CONFIG_SIG_EVENT_DELETED: {
- GtkWidget *menu;
- GtkWidget *mi;
-
- d(printf ("gui DELETED\n"));
-
- if (sig == gui->def_signature) {
- gui->def_signature = NULL;
- gui->auto_signature = TRUE;
- gtk_option_menu_set_history (GTK_OPTION_MENU (gui->sig_option_menu),
- sig_gui_get_index (gui));
+ menu = gtk_option_menu_get_menu (gui->sig_menu);
+ items = GTK_MENU_SHELL (menu)->children;
+ while (items != NULL) {
+ cur = g_object_get_data (items->data, "sig");
+ if (cur == sig) {
+ gtk_option_menu_set_history (gui->sig_menu, i);
+ break;
}
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (gui->sig_option_menu));
- mi = g_list_nth_data (GTK_MENU_SHELL (menu)->children, sig_get_index (sig));
- gtk_container_remove (GTK_CONTAINER (menu), mi);
-
- break;
- }
- default:
- ;
+ items = items->next;
+ i++;
}
}
static void
prepare_signatures (MailAccountGui *gui)
{
- gui->sig_option_menu = glade_xml_get_widget (gui->xml, "sigOption");
- sig_fill_options (gui);
- g_signal_connect (gtk_option_menu_get_menu (GTK_OPTION_MENU (gui->sig_option_menu)),
+ GtkWidget *button;
+
+ gui->sig_menu = (GtkOptionMenu *) glade_xml_get_widget (gui->xml, "sigOption");
+ sig_fill_menu (gui);
+
+ g_signal_connect (gtk_option_menu_get_menu (gui->sig_menu),
"selection-done", G_CALLBACK(sig_changed), gui);
- glade_xml_signal_connect_data (gui->xml, "sigAddNewClicked",
- G_CALLBACK (sig_add_new_signature), gui);
+ button = glade_xml_get_widget (gui->xml, "sigAddNew");
+ g_signal_connect (button, "clicked", G_CALLBACK (sig_add_new_signature), gui);
if (!gui->dialog) {
gtk_widget_hide (glade_xml_get_widget (gui->xml, "sigLabel"));
gtk_widget_hide (glade_xml_get_widget (gui->xml, "sigOption"));
gtk_widget_hide (glade_xml_get_widget (gui->xml, "sigAddNew"));
- } else {
- mail_config_signature_register_client ((MailConfigSignatureClient) sig_event_client, gui);
}
+
+ select_account_signature (gui);
}
#if defined (HAVE_NSS)
@@ -1568,15 +1569,13 @@ mail_account_gui_new (EAccount *account, EMAccountPrefs *dialog)
if (!mail_config_get_default_account ()
|| (account == mail_config_get_default_account ()))
gtk_toggle_button_set_active (gui->default_account, TRUE);
-
+
/* Identity */
gui->full_name = GTK_ENTRY (glade_xml_get_widget (gui->xml, "identity_full_name"));
gui->email_address = GTK_ENTRY (glade_xml_get_widget (gui->xml, "identity_address"));
gui->reply_to = GTK_ENTRY (glade_xml_get_widget (gui->xml, "identity_reply_to"));
gui->organization = GTK_ENTRY (glade_xml_get_widget (gui->xml, "identity_organization"));
- prepare_signatures (gui);
-
if (account->id->name)
gtk_entry_set_text (gui->full_name, account->id->name);
if (account->id->address)
@@ -1586,7 +1585,7 @@ mail_account_gui_new (EAccount *account, EMAccountPrefs *dialog)
if (account->id->organization)
gtk_entry_set_text (gui->organization, account->id->organization);
- setup_signatures (gui);
+ prepare_signatures (gui);
/* Source */
gui->source.provider_type = CAMEL_PROVIDER_STORE;
@@ -1650,8 +1649,8 @@ mail_account_gui_new (EAccount *account, EMAccountPrefs *dialog)
else
gui->drafts_folder_uri = g_strdup(mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_DRAFTS));
em_folder_selection_button_set_selection((EMFolderSelectionButton *)gui->drafts_folder_button, gui->drafts_folder_uri);
- gtk_widget_show (gui->drafts_folder_button);
-
+ gtk_widget_show ((GtkWidget *) gui->drafts_folder_button);
+
/* Sent folder */
gui->sent_folder_button = GTK_BUTTON (glade_xml_get_widget (gui->xml, "sent_button"));
g_signal_connect (gui->sent_folder_button, "selected", G_CALLBACK (folder_selected), &gui->sent_folder_uri);
@@ -1660,8 +1659,8 @@ mail_account_gui_new (EAccount *account, EMAccountPrefs *dialog)
else
gui->sent_folder_uri = g_strdup(mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_SENT));
em_folder_selection_button_set_selection((EMFolderSelectionButton *)gui->sent_folder_button, gui->sent_folder_uri);
- gtk_widget_show (gui->sent_folder_button);
-
+ gtk_widget_show ((GtkWidget *) gui->sent_folder_button);
+
/* Special Folders "Reset Defaults" button */
gui->restore_folders_button = (GtkButton *)glade_xml_get_widget (gui->xml, "default_folders_button");
g_signal_connect (gui->restore_folders_button, "clicked", G_CALLBACK (default_folders_clicked), gui);
@@ -1960,7 +1959,7 @@ mail_account_gui_setup (MailAccountGui *gui, GtkWidget *top)
gtk_widget_set_sensitive((GtkWidget *)gui->restore_folders_button,
e_account_writable(gui->account, E_ACCOUNT_SENT_FOLDER_URI)
|| e_account_writable(gui->account, E_ACCOUNT_DRAFTS_FOLDER_URI));
- gtk_widget_set_sensitive((GtkWidget *)gui->sig_option_menu, e_account_writable(gui->account, E_ACCOUNT_ID_DEF_SIGNATURE));
+ gtk_widget_set_sensitive((GtkWidget *)gui->sig_menu, e_account_writable(gui->account, E_ACCOUNT_ID_SIGNATURE));
gtk_widget_set_sensitive(glade_xml_get_widget(gui->xml, "sigAddNew"),
gconf_client_key_is_writable(mail_config_get_gconf_client(),
"/apps/evolution/mail/signatures", NULL));
@@ -2064,7 +2063,6 @@ mail_account_gui_save (MailAccountGui *gui)
gboolean is_new = FALSE;
const char *new_name;
gboolean is_storage;
- GSList *signatures;
if (!mail_account_gui_identity_complete (gui, NULL) ||
!mail_account_gui_source_complete (gui, NULL) ||
@@ -2099,9 +2097,7 @@ mail_account_gui_save (MailAccountGui *gui)
new->id->organization = g_strdup (gtk_entry_get_text (gui->organization));
/* signatures */
- signatures = mail_config_get_signature_list ();
- new->id->def_signature = g_slist_index (signatures, gui->def_signature);
- new->id->auto_signature = gui->auto_signature;
+ new->id->sig_uid = g_strdup (gui->sig_uid);
/* source */
save_service (&gui->source, gui->extra_config, new->source);
@@ -2185,7 +2181,6 @@ mail_account_gui_save (MailAccountGui *gui)
mail_config_set_default_account (account);
mail_config_save_accounts ();
- mail_config_write_account_sig (account, -1);
mail_autoreceive_setup ();
@@ -2195,12 +2190,16 @@ mail_account_gui_save (MailAccountGui *gui)
void
mail_account_gui_destroy (MailAccountGui *gui)
{
- if (gui->dialog)
- mail_config_signature_unregister_client ((MailConfigSignatureClient) sig_event_client, gui);
+ ESignatureList *signatures;
g_object_unref (gui->xml);
g_object_unref (gui->account);
+ signatures = mail_config_get_signatures ();
+ g_signal_handler_disconnect (signatures, gui->sig_added_id);
+ g_signal_handler_disconnect (signatures, gui->sig_removed_id);
+ g_signal_handler_disconnect (signatures, gui->sig_changed_id);
+
if (gui->extra_config)
g_hash_table_destroy (gui->extra_config);