diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 20 | ||||
-rw-r--r-- | mail/em-composer-prefs.c | 274 | ||||
-rw-r--r-- | mail/em-composer-prefs.h | 13 | ||||
-rw-r--r-- | mail/em-mailer-prefs.c | 7 | ||||
-rw-r--r-- | mail/importers/netscape-importer.c | 13 | ||||
-rw-r--r-- | mail/mail-account-gui.c | 251 | ||||
-rw-r--r-- | mail/mail-account-gui.h | 9 | ||||
-rw-r--r-- | mail/mail-config.c | 442 | ||||
-rw-r--r-- | mail/mail-config.h | 65 | ||||
-rw-r--r-- | mail/mail-ops.c | 1 | ||||
-rw-r--r-- | mail/mail-signature-editor.c | 40 | ||||
-rw-r--r-- | mail/mail-signature-editor.h | 7 |
12 files changed, 443 insertions, 699 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 7957b65061..43ef1251a6 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,6 +1,24 @@ +2004-04-01 Jeffrey Stedfast <fejj@ximian.com> + + * importers/netscape-importer.c (netscape_import_accounts): + Updated for signature API changes. + + * mail-account-gui.c: Same. + + * mail-signature-editor.c: Same. + + * em-composer-prefs.c: Same. + + * mail-config.c: Rewrote the signature stuff to use ESignatureList + instead. Much cleaner and less broken. + + * em-mailer-prefs.c (em_mailer_prefs_construct): Always make the + Add/Remove Header buttons de-sensitised at the start. Fixes bug + #56284. + 2004-04-01 Eric Zhao <eric.zhao@sun.com> - * mail-account-gui.c: (transport_type_changed): Commented grabbing + * mail-account-gui.c (transport_type_changed): Commented grabbing focus on hostname edit, fix the focus issue of Account Assistant. 2004-03-31 Jeffrey Stedfast <fejj@ximian.com> diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c index e822f20b11..d36a80097b 100644 --- a/mail/em-composer-prefs.c +++ b/mail/em-composer-prefs.c @@ -30,6 +30,9 @@ #include <unistd.h> #include <fcntl.h> +#include "e-util/e-signature.h" +#include "e-util/e-signature-list.h" + #include "em-composer-prefs.h" #include "composer/e-msg-composer.h" @@ -57,7 +60,6 @@ static void em_composer_prefs_init (EMComposerPrefs *dialog); static void em_composer_prefs_destroy (GtkObject *obj); static void em_composer_prefs_finalise (GObject *obj); -static void sig_event_client (MailConfigSigEvent event, MailConfigSignature *sig, EMComposerPrefs *prefs); static GtkVBoxClass *parent_class = NULL; @@ -97,11 +99,18 @@ em_composer_prefs_class_init (EMComposerPrefsClass *klass) } static void -em_composer_prefs_init (EMComposerPrefs *composer_prefs) +em_composer_prefs_init (EMComposerPrefs *prefs) +{ + prefs->enabled_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) mark_xpm); + gdk_pixbuf_render_pixmap_and_mask (prefs->enabled_pixbuf, &prefs->mark_pixmap, &prefs->mark_bitmap, 128); + + prefs->sig_hash = g_hash_table_new (g_direct_hash, g_direct_equal); +} + +static void +row_free (ESignature *sig, GtkTreeRowReference *row, gpointer user_data) { - composer_prefs->enabled_pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) mark_xpm); - gdk_pixbuf_render_pixmap_and_mask (composer_prefs->enabled_pixbuf, - &composer_prefs->mark_pixmap, &composer_prefs->mark_bitmap, 128); + gtk_tree_row_reference_free (row); } static void @@ -114,6 +123,9 @@ em_composer_prefs_finalise (GObject *obj) gdk_pixmap_unref (prefs->mark_pixmap); g_object_unref (prefs->mark_bitmap); + g_hash_table_foreach (prefs->sig_hash, (GHFunc) row_free, NULL); + g_hash_table_destroy (prefs->sig_hash); + G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -121,8 +133,24 @@ static void em_composer_prefs_destroy (GtkObject *obj) { EMComposerPrefs *prefs = (EMComposerPrefs *) obj; - - mail_config_signature_unregister_client ((MailConfigSignatureClient) sig_event_client, prefs); + ESignatureList *signatures; + + signatures = mail_config_get_signatures (); + + if (prefs->sig_added_id != 0) { + g_signal_handler_disconnect (signatures, prefs->sig_added_id); + prefs->sig_added_id = 0; + } + + if (prefs->sig_removed_id != 0) { + g_signal_handler_disconnect (signatures, prefs->sig_removed_id); + prefs->sig_removed_id = 0; + } + + if (prefs->sig_changed_id != 0) { + g_signal_handler_disconnect (signatures, prefs->sig_changed_id); + prefs->sig_changed_id = 0; + } GTK_OBJECT_CLASS (parent_class)->destroy (obj); } @@ -172,7 +200,7 @@ option_menu_connect (GtkOptionMenu *omenu, gpointer user_data) } static void -sig_load_preview (EMComposerPrefs *prefs, MailConfigSignature *sig) +sig_load_preview (EMComposerPrefs *prefs, ESignature *sig) { char *str; @@ -182,7 +210,7 @@ sig_load_preview (EMComposerPrefs *prefs, MailConfigSignature *sig) } if (sig->script) - str = mail_config_signature_run_script (sig->script); + str = mail_config_signature_run_script (sig->filename); else str = e_msg_composer_get_sig_file_content (sig->filename, sig->html); if (!str) @@ -208,13 +236,94 @@ sig_load_preview (EMComposerPrefs *prefs, MailConfigSignature *sig) } static void +signature_added (ESignatureList *signatures, ESignature *sig, EMComposerPrefs *prefs) +{ + GtkTreeRowReference *row; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + + /* autogen signature is special */ + if (sig->autogen) + return; + + model = gtk_tree_view_get_model (prefs->sig_list); + gtk_list_store_append ((GtkListStore *) model, &iter); + gtk_list_store_set ((GtkListStore *) model, &iter, 0, sig->name, 1, sig, -1); + + path = gtk_tree_model_get_path (model, &iter); + row = gtk_tree_row_reference_new (model, path); + gtk_tree_path_free (path); + + g_hash_table_insert (prefs->sig_hash, sig, row); +} + +static void +signature_removed (ESignatureList *signatures, ESignature *sig, EMComposerPrefs *prefs) +{ + GtkTreeRowReference *row; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + + if (!(row = g_hash_table_lookup (prefs->sig_hash, sig))) + return; + + g_hash_table_remove (prefs->sig_hash, sig); + + model = gtk_tree_view_get_model (prefs->sig_list); + path = gtk_tree_row_reference_get_path (row); + gtk_tree_row_reference_free (row); + + if (!gtk_tree_model_get_iter (model, &iter, path)) { + gtk_tree_path_free (path); + return; + } + + gtk_list_store_remove ((GtkListStore *) model, &iter); +} + +static void +signature_changed (ESignatureList *signatures, ESignature *sig, EMComposerPrefs *prefs) +{ + GtkTreeSelection *selection; + GtkTreeRowReference *row; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + ESignature *cur; + + if (!(row = g_hash_table_lookup (prefs->sig_hash, sig))) + return; + + model = gtk_tree_view_get_model (prefs->sig_list); + path = gtk_tree_row_reference_get_path (row); + + if (!gtk_tree_model_get_iter (model, &iter, path)) { + gtk_tree_path_free (path); + return; + } + + gtk_tree_path_free (path); + + gtk_list_store_set ((GtkListStore *) model, &iter, 0, sig->name, -1); + + selection = gtk_tree_view_get_selection (prefs->sig_list); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 1, &cur, -1); + if (cur == sig) + sig_load_preview (prefs, sig); + } +} + +static void sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs) { GtkTreeSelection *selection; - MailConfigSignature *sig; GtkTreeModel *model; GtkWidget *parent; GtkTreeIter iter; + ESignature *sig; selection = gtk_tree_view_get_selection (prefs->sig_list); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) @@ -222,7 +331,7 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs) gtk_tree_model_get (model, &iter, 1, &sig, -1); - if (sig->script == NULL) { + if (!sig->script) { /* normal signature */ if (!sig->filename || *sig->filename == '\0') { g_free (sig->filename); @@ -238,41 +347,38 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs) GtkWidget *entry; entry = glade_xml_get_widget (prefs->sig_script_gui, "fileentry_add_script_script"); - gnome_file_entry_set_filename((GnomeFileEntry *)entry, sig->script); - + gnome_file_entry_set_filename ((GnomeFileEntry *) entry, sig->filename); + entry = glade_xml_get_widget (prefs->sig_script_gui, "entry_add_script_name"); gtk_entry_set_text (GTK_ENTRY (entry), sig->name); - g_object_set_data ((GObject *) entry, "script", sig); + g_object_set_data ((GObject *) entry, "sig", sig); gtk_window_present ((GtkWindow *) prefs->sig_script_dialog); } } -MailConfigSignature * +void em_composer_prefs_new_signature (GtkWindow *parent, gboolean html, const char *script) { - MailConfigSignature *sig; + ESignature *sig; - sig = mail_config_signature_new (html, script); + sig = mail_config_signature_new (script, script ? TRUE : FALSE, html); mail_signature_editor (sig, parent, TRUE); - - return sig; } static void sig_delete_cb (GtkWidget *widget, EMComposerPrefs *prefs) { - MailConfigSignature *sig; - GtkTreeModel *model; GtkTreeSelection *selection; + GtkTreeModel *model; GtkTreeIter iter; + ESignature *sig; selection = gtk_tree_view_get_selection (prefs->sig_list); if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, 1, &sig, -1); - gtk_list_store_remove ((GtkListStore *) model, &iter); - mail_config_signature_delete (sig); + mail_config_remove_signature (sig); } } @@ -303,26 +409,26 @@ sig_add_script_response (GtkWidget *widget, int button, EMComposerPrefs *prefs) if (button == GTK_RESPONSE_ACCEPT) { entry = glade_xml_get_widget (prefs->sig_script_gui, "fileentry_add_script_script"); script = gnome_file_entry_get_full_path((GnomeFileEntry *)entry, FALSE); - + entry = glade_xml_get_widget (prefs->sig_script_gui, "entry_add_script_name"); name = gtk_entry_get_text (GTK_ENTRY (entry)); if (script && *script) { struct stat st; - if (!stat (script, &st) && S_ISREG (st.st_mode) && access (script, X_OK) == 0) { - MailConfigSignature *sig; + if (stat (script, &st) && S_ISREG (st.st_mode) && access (script, X_OK) == 0) { GtkWidget *parent; + ESignature *sig; parent = gtk_widget_get_toplevel ((GtkWidget *) prefs); parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; - if ((sig = g_object_get_data ((GObject *) entry, "script"))) { + if ((sig = g_object_get_data ((GObject *) entry, "sig"))) { /* we're just editing an existing signature script */ - mail_config_signature_set_name (sig, name); + g_free (sig->name); + sig->name = g_strdup (name); + e_signature_list_change (mail_config_get_signatures (), sig); } else { - sig = em_composer_prefs_new_signature ((GtkWindow *) parent, TRUE, script); - mail_config_signature_set_name (sig, name); - mail_config_signature_add (sig); + em_composer_prefs_new_signature ((GtkWindow *) parent, TRUE, script); } gtk_widget_hide (prefs->sig_script_dialog); @@ -354,7 +460,7 @@ sig_add_script_cb (GtkWidget *widget, EMComposerPrefs *prefs) entry = glade_xml_get_widget (prefs->sig_script_gui, "entry_add_script_name"); gtk_entry_set_text (GTK_ENTRY (entry), _("Unnamed")); - g_object_set_data ((GObject *) entry, "script", NULL); + g_object_set_data ((GObject *) entry, "sig", NULL); gtk_window_present ((GtkWindow *) prefs->sig_script_dialog); } @@ -362,9 +468,9 @@ sig_add_script_cb (GtkWidget *widget, EMComposerPrefs *prefs) static void sig_selection_changed (GtkTreeSelection *selection, EMComposerPrefs *prefs) { - MailConfigSignature *sig; GtkTreeModel *model; GtkTreeIter iter; + ESignature *sig; int state; state = gtk_tree_selection_get_selected (selection, &model, &iter); @@ -378,28 +484,35 @@ sig_selection_changed (GtkTreeSelection *selection, EMComposerPrefs *prefs) } static void -sig_fill_list (GtkTreeView *list) +sig_fill_list (EMComposerPrefs *prefs) { - GSList *l; + ESignatureList *signatures; GtkListStore *model; - GtkTreeIter iter; + EIterator *it; - model = (GtkListStore *) gtk_tree_view_get_model (list); + model = (GtkListStore *) gtk_tree_view_get_model (prefs->sig_list); gtk_list_store_clear (model); - for (l = mail_config_get_signature_list (); l; l = l->next) { - MailConfigSignature *sig = l->data; - char *name = NULL, *val; + signatures = mail_config_get_signatures (); + it = e_list_get_iterator ((EList *) signatures); + + while (e_iterator_is_valid (it)) { + ESignature *sig; - gtk_list_store_append (model, &iter); + sig = (ESignature *) e_iterator_get (it); + signature_added (signatures, sig, prefs); - if (sig->script) - name = val = g_strconcat (sig->name, " ", _("[script]"), NULL); - else - val = sig->name; - gtk_list_store_set (model, &iter, 0, val, 1, sig, -1); - g_free (name); + e_iterator_next (it); } + + g_object_unref (it); + + gtk_widget_set_sensitive ((GtkWidget *) prefs->sig_edit, FALSE); + gtk_widget_set_sensitive ((GtkWidget *) prefs->sig_delete, FALSE); + + prefs->sig_added_id = g_signal_connect (signatures, "signature-added", G_CALLBACK (signature_added), prefs); + prefs->sig_removed_id = g_signal_connect (signatures, "signature-removed", G_CALLBACK (signature_removed), prefs); + prefs->sig_changed_id = g_signal_connect (signatures, "signature-changed", G_CALLBACK (signature_changed), prefs); } static void @@ -429,54 +542,6 @@ url_requested (GtkHTML *html, const char *url, GtkHTMLStream *handle) gtk_html_end (html, handle, status); } -static void -sig_event_client (MailConfigSigEvent event, MailConfigSignature *sig, EMComposerPrefs *prefs) -{ - MailConfigSignature *current; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - char path[16]; - - switch (event) { - case MAIL_CONFIG_SIG_EVENT_ADDED: - d(printf ("signature ADDED\n")); - - model = gtk_tree_view_get_model (prefs->sig_list); - gtk_list_store_append ((GtkListStore *) model, &iter); - gtk_list_store_set ((GtkListStore *) model, &iter, 0, sig->name, 1, sig, -1); - break; - case MAIL_CONFIG_SIG_EVENT_NAME_CHANGED: - d(printf ("signature NAME CHANGED\n")); - - /* this is one bizarro interface */ - model = gtk_tree_view_get_model (prefs->sig_list); - sprintf (path, "%d", sig->id); - if (gtk_tree_model_get_iter_from_string (model, &iter, path)) { - char *val, *name = NULL; - - if (sig->script) - name = val = g_strconcat (sig->name, " ", _("[script]"), NULL); - else - val = sig->name; - - gtk_list_store_set ((GtkListStore *) model, &iter, 0, val, -1); - g_free (name); - } - break; - case MAIL_CONFIG_SIG_EVENT_CONTENT_CHANGED: - d(printf ("signature CONTENT CHANGED\n")); - selection = gtk_tree_view_get_selection (prefs->sig_list); - if (gtk_tree_selection_get_selected (selection, &model, &iter)) { - gtk_tree_model_get (model, &iter, 1, ¤t, -1); - if (sig == current) - sig_load_preview (prefs, sig); - } - break; - default: - ; - } -} /* * @@ -820,7 +885,6 @@ em_composer_prefs_construct (EMComposerPrefs *prefs) GladeXML *gui; GtkListStore *model; GtkTreeSelection *selection; - gboolean bool, locked; int style; char *buf; @@ -924,16 +988,16 @@ em_composer_prefs_construct (EMComposerPrefs *prefs) /* Signatures */ dialog = (GtkDialog *) gtk_dialog_new (); - + gtk_widget_realize ((GtkWidget *) dialog); gtk_container_set_border_width ((GtkContainer *)dialog->action_area, 12); gtk_container_set_border_width ((GtkContainer *)dialog->vbox, 0); - + prefs->sig_script_dialog = (GtkWidget *) dialog; gtk_dialog_add_buttons (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_has_separator (dialog, FALSE); - gtk_window_set_title ((GtkWindow *) dialog, _("Add script signature")); + gtk_window_set_title ((GtkWindow *) dialog, _("Add signature script")); g_signal_connect (dialog, "response", G_CALLBACK (sig_add_script_response), prefs); widget = glade_xml_get_widget (prefs->sig_script_gui, "vbox_add_script_signature"); gtk_box_pack_start ((GtkBox *) dialog->vbox, widget, TRUE, TRUE, 0); @@ -941,8 +1005,8 @@ em_composer_prefs_construct (EMComposerPrefs *prefs) prefs->sig_add = GTK_BUTTON (glade_xml_get_widget (gui, "cmdSignatureAdd")); g_signal_connect (prefs->sig_add, "clicked", G_CALLBACK (sig_add_cb), prefs); - glade_xml_signal_connect_data (gui, "cmdSignatureAddScriptClicked", - G_CALLBACK (sig_add_script_cb), prefs); + prefs->sig_add_script = GTK_BUTTON (glade_xml_get_widget (gui, "cmdSignatureAddScript")); + g_signal_connect (prefs->sig_add_script, "clicked", G_CALLBACK (sig_add_script_cb), prefs); prefs->sig_edit = GTK_BUTTON (glade_xml_get_widget (gui, "cmdSignatureEdit")); g_signal_connect (prefs->sig_edit, "clicked", G_CALLBACK (sig_edit_cb), prefs); @@ -961,11 +1025,7 @@ em_composer_prefs_construct (EMComposerPrefs *prefs) gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (selection, "changed", G_CALLBACK (sig_selection_changed), prefs); - sig_fill_list (prefs->sig_list); - if (mail_config_get_signature_list () == NULL) { - gtk_widget_set_sensitive ((GtkWidget *) prefs->sig_delete, FALSE); - gtk_widget_set_sensitive ((GtkWidget *) prefs->sig_edit, FALSE); - } + sig_fill_list (prefs); /* preview GtkHTML widget */ widget = glade_xml_get_widget (gui, "scrolled-sig"); @@ -973,8 +1033,6 @@ em_composer_prefs_construct (EMComposerPrefs *prefs) g_signal_connect (prefs->sig_preview, "url_requested", G_CALLBACK (url_requested), NULL); gtk_widget_show (GTK_WIDGET (prefs->sig_preview)); gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (prefs->sig_preview)); - - mail_config_signature_register_client ((MailConfigSignatureClient) sig_event_client, prefs); } diff --git a/mail/em-composer-prefs.h b/mail/em-composer-prefs.h index 70b5eb15eb..a255893c87 100644 --- a/mail/em-composer-prefs.h +++ b/mail/em-composer-prefs.h @@ -53,6 +53,8 @@ extern "C" { typedef struct _EMComposerPrefs EMComposerPrefs; typedef struct _EMComposerPrefsClass EMComposerPrefsClass; +struct _ESignature; + struct _EMComposerPrefs { GtkVBox parent_object; @@ -94,14 +96,19 @@ struct _EMComposerPrefs { /* Signatures */ GtkTreeView *sig_list; + GHashTable *sig_hash; GtkButton *sig_add; + GtkButton *sig_add_script; GtkButton *sig_edit; GtkButton *sig_delete; GtkHTML *sig_preview; - gboolean sig_switch; - int sig_row; + GladeXML *sig_script_gui; GtkWidget *sig_script_dialog; + + guint sig_added_id; + guint sig_removed_id; + guint sig_changed_id; }; struct _EMComposerPrefsClass { @@ -118,7 +125,7 @@ GtkWidget *em_composer_prefs_new (void); void em_composer_prefs_apply (EMComposerPrefs *prefs); -MailConfigSignature *em_composer_prefs_new_signature (GtkWindow *parent, gboolean html, const char *script); +void em_composer_prefs_new_signature (GtkWindow *parent, gboolean html, const char *script); /* needed by global config */ #define EM_COMPOSER_PREFS_CONTROL_ID "OAFIID:GNOME_Evolution_Mail_ComposerPrefs_ConfigControl:" BASE_VERSION diff --git a/mail/em-mailer-prefs.c b/mail/em-mailer-prefs.c index b2743c7740..19ade2393d 100644 --- a/mail/em-mailer-prefs.c +++ b/mail/em-mailer-prefs.c @@ -679,11 +679,13 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs) /* headers */ locked = !gconf_client_key_is_writable (prefs->gconf, "/apps/evolution/mail/display/headers", NULL); + /* always de-sensitised until the user types something in the entry */ prefs->add_header = GTK_BUTTON (glade_xml_get_widget (gui, "cmdHeadersAdd")); - gtk_widget_set_sensitive ((GtkWidget *) prefs->add_header, !locked); + gtk_widget_set_sensitive ((GtkWidget *) prefs->add_header, FALSE); + /* always de-sensitised until the user selects a header in the list */ prefs->remove_header = GTK_BUTTON (glade_xml_get_widget (gui, "cmdHeadersRemove")); - gtk_widget_set_sensitive ((GtkWidget *) prefs->remove_header, !locked); + gtk_widget_set_sensitive ((GtkWidget *) prefs->remove_header, FALSE); prefs->entry_header = GTK_ENTRY (glade_xml_get_widget (gui, "txtHeaders")); gtk_widget_set_sensitive ((GtkWidget *) prefs->entry_header, !locked); @@ -783,7 +785,6 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs) } g_slist_free (header_add_list); - emmp_header_remove_sensitivity (prefs); /* Junk prefs */ prefs->check_incoming = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkCheckIncomingMail")); diff --git a/mail/importers/netscape-importer.c b/mail/importers/netscape-importer.c index 1e60e7f3c5..7b72c28d24 100644 --- a/mail/importers/netscape-importer.c +++ b/mail/importers/netscape-importer.c @@ -57,6 +57,7 @@ #include <filter/filter-int.h> #include "e-util/e-account-list.h" +#include "e-util/e-signature-list.h" #include "mail/mail-mt.h" #include "mail/mail-config.h" @@ -1482,13 +1483,13 @@ netscape_import_accounts (NsImporter *importer) nstr = netscape_get_string ("mail.signature_file"); if (nstr != NULL) { - MailConfigSignature *sig; + ESignature *sig; char *cmd; - - sig = mail_config_signature_new(FALSE, NULL); - mail_config_signature_add(sig); - account->id->def_signature = sig->id; - account->id->auto_signature = FALSE; + + sig = mail_config_signature_new (NULL, FALSE, FALSE); + mail_config_add_signature (sig); + account->id->sig_uid = g_strdup (sig->uid); + /* HACK: yeah this is a hack, who cares? */ cmd = g_strdup_printf("cp \'%s\' \'%s\'", nstr, sig->filename); system(cmd); 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); diff --git a/mail/mail-account-gui.h b/mail/mail-account-gui.h index 2b47039c77..044b1e4689 100644 --- a/mail/mail-account-gui.h +++ b/mail/mail-account-gui.h @@ -69,10 +69,11 @@ typedef struct _MailAccountGui { struct _GtkEntry *organization; /* signatures */ - struct _GtkWidget *sig_option_menu; - - struct _MailConfigSignature *def_signature; - gboolean auto_signature; + struct _GtkOptionMenu *sig_menu; + guint sig_added_id; + guint sig_removed_id; + guint sig_changed_id; + const char *sig_uid; /* incoming mail */ MailAccountGuiService source; diff --git a/mail/mail-config.c b/mail/mail-config.c index 97c223feb3..54a19d049d 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -48,9 +48,11 @@ #include <gal/util/e-util.h> #include <gal/widgets/e-gui-utils.h> + #include <e-util/e-url.h> #include <e-util/e-passwords.h> #include <e-util/e-account-list.h> +#include <e-util/e-signature-list.h> #include "mail-component.h" #include "mail-session.h" @@ -73,10 +75,7 @@ typedef struct { gboolean corrupt; EAccountList *accounts; - - GSList *signatures; - int sig_nextid; - gboolean signature_info; + ESignatureList *signatures; GSList *labels; guint label_notify_id; @@ -94,218 +93,18 @@ static guint config_write_timeout = 0; #define MAIL_CONFIG_RC "/gtkrc-mail-fonts" #define MAIL_CONFIG_RC_DIR ".evolution/mail/config" -/* signatures */ -MailConfigSignature * -signature_copy (const MailConfigSignature *sig) -{ - MailConfigSignature *ns; - - g_return_val_if_fail (sig != NULL, NULL); - - ns = g_new (MailConfigSignature, 1); - - ns->id = sig->id; - ns->name = g_strdup (sig->name); - ns->filename = g_strdup (sig->filename); - ns->script = g_strdup (sig->script); - ns->html = sig->html; - - return ns; -} - -void -signature_destroy (MailConfigSignature *sig) -{ - g_free (sig->name); - g_free (sig->filename); - g_free (sig->script); - g_free (sig); -} - -static char * -xml_get_prop (xmlNodePtr node, const char *name) -{ - char *buf, *val; - - buf = xmlGetProp (node, name); - val = g_strdup (buf); - xmlFree (buf); - - return val; -} - -static char * -xml_get_content (xmlNodePtr node) -{ - char *buf, *val; - - buf = xmlNodeGetContent (node); - val = g_strdup (buf); - xmlFree (buf); - - return val; -} - void mail_config_save_accounts (void) { e_account_list_save (config->accounts); } -static MailConfigSignature * -signature_new_from_xml (char *in, int id) -{ - MailConfigSignature *sig; - xmlNodePtr node, cur; - xmlDocPtr doc; - char *buf; - - if (!(doc = xmlParseDoc (in))) - return NULL; - - node = doc->children; - if (strcmp (node->name, "signature") != 0) { - xmlFreeDoc (doc); - return NULL; - } - - sig = g_new0 (MailConfigSignature, 1); - sig->name = xml_get_prop (node, "name"); - sig->id = id; - - buf = xml_get_prop (node, "format"); - if (!strcmp (buf, "text/html")) - sig->html = TRUE; - else - sig->html = FALSE; - g_free (buf); - - cur = node->children; - while (cur) { - if (!strcmp (cur->name, "filename")) { - g_free (sig->filename); - sig->filename = xml_get_content (cur); - } else if (!strcmp (cur->name, "script")) { - g_free (sig->script); - sig->script = xml_get_content (cur); - } - - cur = cur->next; - } - - xmlFreeDoc (doc); - - return sig; -} - -static void -config_read_signatures (void) -{ - GSList *list, *l, *tail, *n; - int i = 0; - - config->signatures = NULL; - - tail = NULL; - list = gconf_client_get_list (config->gconf, "/apps/evolution/mail/signatures", - GCONF_VALUE_STRING, NULL); - - l = list; - while (l != NULL) { - MailConfigSignature *sig; - - if ((sig = signature_new_from_xml ((char *) l->data, i++))) { - n = g_slist_alloc (); - n->next = NULL; - n->data = sig; - - if (tail == NULL) - config->signatures = n; - else - tail->next = n; - tail = n; - } - - n = l->next; - g_slist_free_1 (l); - l = n; - } - - config->sig_nextid = i + 1; -} - -static char * -signature_to_xml (MailConfigSignature *sig) +void +mail_config_save_signatures (void) { - char *xmlbuf, *tmp; - xmlNodePtr root; - xmlDocPtr doc; - int n; - - doc = xmlNewDoc ("1.0"); - - root = xmlNewDocNode (doc, NULL, "signature", NULL); - xmlDocSetRootElement (doc, root); - - xmlSetProp (root, "name", sig->name); - xmlSetProp (root, "format", sig->html ? "text/html" : "text/plain"); - - if (sig->filename) - xmlNewTextChild (root, NULL, "filename", sig->filename); - - if (sig->script) - xmlNewTextChild (root, NULL, "script", sig->script); - - xmlDocDumpMemory (doc, (xmlChar **) &xmlbuf, &n); - xmlFreeDoc (doc); - - /* remap to glib memory */ - tmp = g_malloc (n + 1); - memcpy (tmp, xmlbuf, n); - tmp[n] = '\0'; - xmlFree (xmlbuf); - - return tmp; + e_signature_list_save (config->signatures); } -static void -config_write_signatures (void) -{ - GSList *list, *tail, *n, *l; - char *xmlbuf; - - list = NULL; - tail = NULL; - - l = config->signatures; - while (l != NULL) { - if ((xmlbuf = signature_to_xml ((MailConfigSignature *) l->data))) { - n = g_slist_alloc (); - n->data = xmlbuf; - n->next = NULL; - - if (tail == NULL) - list = n; - else - tail->next = n; - tail = n; - } - - l = l->next; - } - - gconf_client_set_list (config->gconf, "/apps/evolution/mail/signatures", GCONF_VALUE_STRING, list, NULL); - - l = list; - while (l != NULL) { - n = l->next; - g_free (l->data); - g_slist_free_1 (l); - l = n; - } - - gconf_client_suggest_sync (config->gconf, NULL); -} static void config_clear_labels (void) @@ -516,7 +315,9 @@ gconf_mime_types_changed (GConfClient *client, guint cnxn_id, void mail_config_init (void) { + ESignature *sig = NULL; char *filename; + EIterator *it; if (config) return; @@ -526,11 +327,7 @@ mail_config_init (void) config->mime_types = g_ptr_array_new (); mail_config_clear (); - - /* - EPFIXME: This kludge needs to go away. - filename = g_build_filename (evolution_dir, MAIL_CONFIG_RC, NULL); - */ + filename = g_build_filename (g_get_home_dir (), MAIL_CONFIG_RC_DIR, MAIL_CONFIG_RC, NULL); gtk_rc_parse (filename); g_free (filename); @@ -543,7 +340,7 @@ mail_config_init (void) gconf_style_changed, NULL, NULL, NULL); config->spell_notify_id = gconf_client_notify_add (config->gconf, "/GNOME/Spell", gconf_style_changed, NULL, NULL, NULL); - + gconf_client_add_dir (config->gconf, "/apps/evolution/mail/labels", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); config->label_notify_id = @@ -557,12 +354,22 @@ mail_config_init (void) gconf_mime_types_changed, NULL, NULL, NULL); config_cache_labels (); - config_read_signatures (); config_cache_mime_types (); config->accounts = e_account_list_new (config->gconf); + config->signatures = e_signature_list_new (config->gconf); + + /* if the list is empty, add an "Autogenerated" signature item */ + it = e_list_get_iterator ((EList *) config->signatures); + if (!e_iterator_is_valid (it)) { + sig = e_signature_new (); + sig->name = g_strdup ("Autogenerated"); + sig->autogen = TRUE; + mail_config_add_signature (sig); + } } + void mail_config_clear (void) { @@ -574,16 +381,15 @@ mail_config_clear (void) config->accounts = NULL; } + if (config->signatures) { + g_object_unref (config->signatures); + config->signatures = NULL; + } + config_clear_labels (); config_clear_mime_types (); } -void -mail_config_write_account_sig (EAccount *account, int id) -{ - /* FIXME: what is this supposed to do? */ - ; -} void mail_config_write (void) @@ -591,8 +397,8 @@ mail_config_write (void) if (!config) return; - config_write_signatures (); e_account_list_save (config->accounts); + e_signature_list_save (config->signatures); gconf_client_suggest_sync (config->gconf, NULL); } @@ -1185,16 +991,8 @@ mail_config_check_service (const char *url, CamelProviderType type, GList **auth return ret; } -static gboolean -do_config_write (gpointer data) -{ - config_write_timeout = 0; - mail_config_write (); - return FALSE; -} - -GSList * -mail_config_get_signature_list (void) +ESignatureList * +mail_config_get_signatures (void) { return config->signatures; } @@ -1241,175 +1039,55 @@ get_new_signature_filename (void) } -MailConfigSignature * -mail_config_signature_new (gboolean html, const char *script) +ESignature * +mail_config_signature_new (const char *filename, gboolean script, gboolean html) { - MailConfigSignature *sig; - - sig = g_new0 (MailConfigSignature, 1); + ESignature *sig; - sig->id = config->sig_nextid++; + sig = e_signature_new (); sig->name = g_strdup (_("Unnamed")); - if (script) - sig->script = g_strdup (script); - else - sig->filename = get_new_signature_filename (); + sig->script = script; sig->html = html; - return sig; -} - - -void -mail_config_signature_add (MailConfigSignature *sig) -{ - g_assert (g_slist_find (config->signatures, sig) == NULL); - - config->signatures = g_slist_append (config->signatures, sig); - config_write_signatures (); - mail_config_signature_emit_event (MAIL_CONFIG_SIG_EVENT_ADDED, sig); -} - -static void -delete_unused_signature_file (const char *filename) -{ - char *signatures_dir; - int len; - - signatures_dir = g_strconcat (mail_component_peek_base_directory (mail_component_peek ()), - "/signatures", NULL); - - /* remove signature file if it's in evolution dir and no other signature uses it */ - len = strlen (signatures_dir); - if (filename && !strncmp (filename, signatures_dir, len)) { - gboolean only_one = TRUE; - GSList *node; - - node = config->signatures; - while (node != NULL) { - MailConfigSignature *sig = node->data; - - if (sig->filename && !strcmp (filename, sig->filename)) { - only_one = FALSE; - break; - } - - node = node->next; - } - - if (only_one) - unlink (filename); - } - - g_free (signatures_dir); -} - -void -mail_config_signature_delete (MailConfigSignature *sig) -{ - EAccount *account; - EIterator *iter; - GSList *node, *next; - gboolean after = FALSE; - int index; - - index = g_slist_index (config->signatures, sig); - - iter = e_list_get_iterator ((EList *) config->accounts); - while (e_iterator_is_valid (iter)) { - account = (EAccount *) e_iterator_get (iter); - - if (account->id->def_signature == index) - account->id->def_signature = -1; - else if (account->id->def_signature > index) - account->id->def_signature--; - - e_iterator_next (iter); - } - - g_object_unref (iter); - - node = config->signatures; - while (node != NULL) { - next = node->next; - - if (after) { - ((MailConfigSignature *) node->data)->id--; - } else if (node->data == sig) { - config->signatures = g_slist_remove_link (config->signatures, node); - config->sig_nextid--; - after = TRUE; - } - - node = next; - } + if (filename == NULL) + sig->filename = get_new_signature_filename (); + else + sig->filename = g_strdup (filename); - config_write_signatures (); - delete_unused_signature_file (sig->filename); - /* printf ("signatures: %d\n", config->signatures); */ - mail_config_signature_emit_event (MAIL_CONFIG_SIG_EVENT_DELETED, sig); - signature_destroy (sig); + return sig; } -void -mail_config_signature_set_filename (MailConfigSignature *sig, const char *filename) +ESignature * +mail_config_get_signature_by_uid (const char *uid) { - char *old_filename = sig->filename; - - sig->filename = g_strdup (filename); - if (old_filename) { - delete_unused_signature_file (old_filename); - g_free (old_filename); - } - config_write_signatures (); + return (ESignature *) e_signature_list_find (config->signatures, E_SIGNATURE_FIND_UID, uid); } -void -mail_config_signature_set_name (MailConfigSignature *sig, const char *name) +ESignature * +mail_config_get_signature_by_name (const char *name) { - g_free (sig->name); - sig->name = g_strdup (name); - - config_write_signatures (); - - mail_config_signature_emit_event (MAIL_CONFIG_SIG_EVENT_NAME_CHANGED, sig); + return (ESignature *) e_signature_list_find (config->signatures, E_SIGNATURE_FIND_NAME, name); } -static GList *clients = NULL; - -/* uh...the following code is snot. this needs to be fixed. I just don't feel like doing it right now. */ - void -mail_config_signature_register_client (MailConfigSignatureClient client, gpointer data) +mail_config_add_signature (ESignature *signature) { - clients = g_list_append (clients, client); - clients = g_list_append (clients, data); + e_signature_list_add (config->signatures, signature); + mail_config_save_signatures (); } void -mail_config_signature_unregister_client (MailConfigSignatureClient client, gpointer data) +mail_config_remove_signature (ESignature *signature) { - GList *link; + if (signature->filename && !signature->script) + unlink (signature->filename); - if ((link = g_list_find (clients, data)) != NULL) { - clients = g_list_remove_link (clients, link->prev); - clients = g_list_remove_link (clients, link); - } -} - -void -mail_config_signature_emit_event (MailConfigSigEvent event, MailConfigSignature *sig) -{ - GList *l, *next; - - for (l = clients; l; l = next) { - next = l->next->next; - (*((MailConfigSignatureClient) l->data)) (event, sig, l->next->data); - } + e_signature_list_remove (config->signatures, signature); + mail_config_save_signatures (); } -gchar * -mail_config_signature_run_script (gchar *script) +char * +mail_config_signature_run_script (const char *script) { int result, status; int in_fds[2]; @@ -1514,13 +1192,3 @@ mail_config_signature_run_script (gchar *script) return content; } } - -void -mail_config_signature_set_html (MailConfigSignature *sig, gboolean html) -{ - if (sig->html != html) { - sig->html = html; - config_write_signatures (); - mail_config_signature_emit_event (MAIL_CONFIG_SIG_EVENT_HTML_CHANGED, sig); - } -} diff --git a/mail/mail-config.h b/mail/mail-config.h index 67ae283b72..3618e9465c 100644 --- a/mail/mail-config.h +++ b/mail/mail-config.h @@ -32,6 +32,9 @@ struct _EAccount; struct _EAccountList; struct _EAccountService; +struct _ESignature; +struct _ESignatureList; + struct _GConfClient; struct _GtkWindow; @@ -98,10 +101,6 @@ typedef struct { #define LABEL_DEFAULTS_NUM 5 extern MailConfigLabel label_defaults[5]; -/* signatures */ -MailConfigSignature *signature_copy (const MailConfigSignature *sig); -void signature_destroy (MailConfigSignature *sig); - /* Configuration */ void mail_config_init (void); void mail_config_clear (void); @@ -122,30 +121,37 @@ const char **mail_config_get_allowable_mime_types (void); void mail_config_service_set_save_passwd (struct _EAccountService *service, gboolean save_passwd); -gboolean mail_config_find_account (struct _EAccount *account); -struct _EAccount *mail_config_get_default_account (void); -struct _EAccount *mail_config_get_account_by_name (const char *account_name); -struct _EAccount *mail_config_get_account_by_uid (const char *uid); -struct _EAccount *mail_config_get_account_by_source_url (const char *url); -struct _EAccount *mail_config_get_account_by_transport_url (const char *url); -struct _EAccountList *mail_config_get_accounts (void); -void mail_config_add_account (struct _EAccount *account); -void mail_config_remove_account (struct _EAccount *account); +/* accounts */ +gboolean mail_config_find_account (struct _EAccount *account); +struct _EAccount *mail_config_get_default_account (void); +struct _EAccount *mail_config_get_account_by_name (const char *account_name); +struct _EAccount *mail_config_get_account_by_uid (const char *uid); +struct _EAccount *mail_config_get_account_by_source_url (const char *url); +struct _EAccount *mail_config_get_account_by_transport_url (const char *url); -void mail_config_set_default_account (struct _EAccount *account); +struct _EAccountList *mail_config_get_accounts (void); +void mail_config_add_account (struct _EAccount *account); +void mail_config_remove_account (struct _EAccount *account); +void mail_config_set_default_account (struct _EAccount *account); struct _EAccountIdentity *mail_config_get_default_identity (void); struct _EAccountService *mail_config_get_default_transport (void); void mail_config_save_accounts (void); -GSList *mail_config_get_signature_list (void); -MailConfigSignature *mail_config_signature_new (gboolean html, const char *script); -void mail_config_signature_add (MailConfigSignature *sig); -void mail_config_signature_delete (MailConfigSignature *sig); -void mail_config_signature_set_name (MailConfigSignature *sig, const char *name); -void mail_config_signature_set_html (MailConfigSignature *sig, gboolean html); -void mail_config_signature_set_filename (MailConfigSignature *sig, const char *filename); +/* signatures */ +struct _ESignature *mail_config_signature_new (const char *filename, gboolean script, gboolean html); +struct _ESignature *mail_config_get_signature_by_uid (const char *uid); +struct _ESignature *mail_config_get_signature_by_name (const char *name); + +struct _ESignatureList *mail_config_get_signatures (void); +void mail_config_add_signature (struct _ESignature *signature); +void mail_config_remove_signature (struct _ESignature *signature); + +void mail_config_save_signatures (void); + +char *mail_config_signature_run_script (const char *script); + /* uri's got changed by the store, etc */ void mail_config_uri_renamed (GCompareFunc uri_cmp, const char *old, const char *new); @@ -162,23 +168,6 @@ GType evolution_mail_config_get_type (void); gboolean evolution_mail_config_factory_init (void); -typedef enum { - MAIL_CONFIG_SIG_EVENT_NAME_CHANGED, - MAIL_CONFIG_SIG_EVENT_CONTENT_CHANGED, - MAIL_CONFIG_SIG_EVENT_HTML_CHANGED, - MAIL_CONFIG_SIG_EVENT_ADDED, - MAIL_CONFIG_SIG_EVENT_DELETED -} MailConfigSigEvent; - -typedef void (*MailConfigSignatureClient)(MailConfigSigEvent, MailConfigSignature *sig, gpointer data); - -void mail_config_signature_register_client (MailConfigSignatureClient client, gpointer data); -void mail_config_signature_unregister_client (MailConfigSignatureClient client, gpointer data); -void mail_config_signature_emit_event (MailConfigSigEvent event, MailConfigSignature *sig); - -void mail_config_write_account_sig (struct _EAccount *account, int i); -char *mail_config_signature_run_script (char *script); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 043c04ef6e..5cf845e93c 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -38,6 +38,7 @@ #include <camel/camel-vtrash-folder.h> #include <camel/camel-vee-store.h> #include "mail-component.h" +#include "mail-config.h" #include "mail-tools.h" #include "mail-ops.h" #include "mail-vfolder.h" diff --git a/mail/mail-signature-editor.c b/mail/mail-signature-editor.c index 2237c1c70c..864f69bf1f 100644 --- a/mail/mail-signature-editor.c +++ b/mail/mail-signature-editor.c @@ -26,15 +26,18 @@ #include <config.h> #endif +#include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> -#include <string.h> +#include <gtk/gtk.h> + #include <bonobo.h> #include <bonobo/bonobo-stream-memory.h> +#include <e-util/e-signature-list.h> #include <e-util/e-dialog-utils.h> #include "e-msg-composer.h" @@ -44,19 +47,18 @@ #define d(x) -struct _ESignatureEditor { +typedef struct _ESignatureEditor { GtkWidget *win; GtkWidget *control; GtkWidget *name_entry; GtkWidget *info_frame; - MailConfigSignature *sig; + ESignature *sig; gboolean is_new; gboolean html; GNOME_GtkHTML_Editor_Engine engine; -}; -typedef struct _ESignatureEditor ESignatureEditor; +} ESignatureEditor; #define E_SIGNATURE_EDITOR(o) ((ESignatureEditor *) o) @@ -181,14 +183,15 @@ menu_file_save_cb (BonoboUIComponent *uic, void *user_data, const char *path) g_free (filename); - mail_config_signature_set_html (editor->sig, editor->html); - + editor->sig->html = editor->html; + /* if the signature isn't already saved in the config, save it there now... */ if (editor->is_new) { - mail_config_signature_add (editor->sig); + mail_config_add_signature (editor->sig); editor->is_new = FALSE; - } else - mail_config_signature_emit_event (MAIL_CONFIG_SIG_EVENT_CONTENT_CHANGED, editor->sig); + } else { + e_signature_list_change (mail_config_get_signatures (), editor->sig); + } return; @@ -256,7 +259,7 @@ delete_event_cb (GtkWidget *w, GdkEvent *event, ESignatureEditor *editor) } static void -menu_file_close_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) +menu_file_close_cb (BonoboUIComponent *uic, gpointer data, const char *path) { ESignatureEditor *editor; @@ -265,7 +268,7 @@ menu_file_close_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) } static void -menu_file_save_close_cb (BonoboUIComponent *uic, gpointer data, const gchar *path) +menu_file_save_close_cb (BonoboUIComponent *uic, gpointer data, const char *path) { ESignatureEditor *editor; @@ -340,12 +343,11 @@ sig_name_changed (GtkWidget *w, ESignatureEditor *editor) name = gtk_entry_get_text (GTK_ENTRY (editor->name_entry)); - if (editor->is_new) { - g_free (editor->sig->name); - editor->sig->name = g_strdup (name); - } else { - mail_config_signature_set_name (editor->sig, name); - } + g_free (editor->sig->name); + editor->sig->name = g_strdup (name); + + if (!editor->is_new) + e_signature_list_change (mail_config_get_signatures (), editor->sig); } static void @@ -366,7 +368,7 @@ format_html_cb (BonoboUIComponent *component, } void -mail_signature_editor (MailConfigSignature *sig, GtkWindow *parent, gboolean is_new) +mail_signature_editor (ESignature *sig, GtkWindow *parent, gboolean is_new) { CORBA_Environment ev; ESignatureEditor *editor; diff --git a/mail/mail-signature-editor.h b/mail/mail-signature-editor.h index 9dd58aade2..6ce4881607 100644 --- a/mail/mail-signature-editor.h +++ b/mail/mail-signature-editor.h @@ -29,11 +29,10 @@ extern "C" { #pragma } #endif /* __cplusplus */ -#include <glib.h> -#include <gtk/gtkwindow.h> -#include <mail-config.h> +struct _ESignature; +struct _GtkWindow; -void mail_signature_editor (MailConfigSignature *sig, GtkWindow *parent, gboolean is_new); +void mail_signature_editor (struct _ESignature *sig, struct _GtkWindow *parent, int is_new); #ifdef __cplusplus } |