diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2007-12-02 09:41:04 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2007-12-02 09:41:04 +0800 |
commit | 8266bb685a189d8560450ff161efdd5629849f11 (patch) | |
tree | f86f9368649f2a036730a704fb97c12160c10365 /composer/e-msg-composer.c | |
parent | 253452654a4bc2fdd44f61446890ccf556c82958 (diff) | |
download | gsoc2013-evolution-8266bb685a189d8560450ff161efdd5629849f11.tar.gz gsoc2013-evolution-8266bb685a189d8560450ff161efdd5629849f11.tar.zst gsoc2013-evolution-8266bb685a189d8560450ff161efdd5629849f11.zip |
** Fixes part of bug #495123
2007-12-01 Matthew Barnes <mbarnes@redhat.com>
** Fixes part of bug #495123
* composer/e-msg-composer.c:
* composer/e-msg-composer-hdrs.h:
* composer/e-msg-composer-hdrs.c:
Move signature handling to e-msg-composer-hdrs.c.
Use an ESignatureComboBox.
* composer/e-composer-from-header.h:
* composer/e-composer-from-header.c:
Clean up the GtkHBox hack. The signature combo is now packed
directly into the GtkTable.
* composer/e-composer-name-header.c:
* composer/e-composer-text-header.c:
Code cleanup.
* widgets/misc/Makefile.am:
Add e-signature-combo-box.[ch].
* widget/misc/e-account-combo-box.c (account_combo_box_refresh_cb):
Make sure the EAccount isn't lost while swapping models.
* widget/misc/e-signature-combo-box.c:
* widget/misc/e-signature-combo-box.h:
New widget renders an ESignatureList as a combo box. Also listens
for changes to the ESignatureList and updates itself accordingly.
svn path=/trunk/; revision=34620
Diffstat (limited to 'composer/e-msg-composer.c')
-rw-r--r-- | composer/e-msg-composer.c | 310 |
1 files changed, 58 insertions, 252 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 087e36ce39..8c47ceaaec 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -88,6 +88,7 @@ #include "e-util/e-util-private.h" #include "e-util/e-util.h" #include <mail/em-event.h> +#include "e-signature-combo-box.h" #include <camel/camel-session.h> #include <camel/camel-charset-map.h> @@ -188,7 +189,7 @@ struct _EMsgComposerPrivate { char *mime_type, *mime_body, *charset; char *autosave_file; - int autosave_fd; + int autosave_fd; guint32 enable_autosave : 1; guint32 attachment_bar_visible : 1; @@ -214,12 +215,6 @@ struct _EMsgComposerPrivate { guint32 in_signature_insert : 1; - struct _ESignature *signature; - struct _GtkOptionMenu *sig_menu; - guint sig_added_id; - guint sig_removed_id; - guint sig_changed_id; - CamelMimeMessage *redirect; guint notify_id; @@ -1247,23 +1242,27 @@ decode_signature_name (const char *name) static char * get_signature_html (EMsgComposer *composer) { - EMsgComposerPrivate *p = composer->priv; + EMsgComposerHdrs *hdrs; char *text = NULL, *html = NULL; + ESignature *signature; gboolean format_html; - if (!p->signature) + hdrs = E_MSG_COMPOSER_HDRS (composer->priv->hdrs); + signature = e_msg_composer_hdrs_get_signature (hdrs); + + if (!signature) return NULL; - if (!p->signature->autogen) { - if (!p->signature->filename) + if (!signature->autogen) { + if (!signature->filename) return NULL; - format_html = p->signature->html; + format_html = signature->html; - if (p->signature->script) { - text = mail_config_signature_run_script (p->signature->filename); + if (signature->script) { + text = mail_config_signature_run_script (signature->filename); } else { - text = e_msg_composer_get_sig_file_content (p->signature->filename, format_html); + text = e_msg_composer_get_sig_file_content (signature->filename, format_html); } } else { EAccountIdentity *id; @@ -1271,8 +1270,7 @@ get_signature_html (EMsgComposer *composer) char *address; char *name; - id = e_msg_composer_hdrs_get_from_account ( - E_MSG_COMPOSER_HDRS (p->hdrs))->id; + id = e_msg_composer_hdrs_get_from_account (hdrs)->id; address = id->address ? camel_text_to_html (id->address, CONVERT_SPACES, 0) : NULL; name = id->name ? camel_text_to_html (id->name, CONVERT_SPACES, 0) : NULL; organization = id->organization ? camel_text_to_html (id->organization, CONVERT_SPACES, 0) : NULL; @@ -1296,8 +1294,8 @@ get_signature_html (EMsgComposer *composer) if (text) { char *encoded_uid = NULL; - if (p->signature) - encoded_uid = encode_signature_name (p->signature->uid); + if (signature) + encoded_uid = encode_signature_name (signature->uid); /* The signature dash convention ("-- \n") is specified in the * "Son of RFC 1036": http://www.chemie.fu-berlin.de/outerspace/netnews/son-of-1036.html, @@ -1606,7 +1604,7 @@ autosave_load_draft (const char *filename) static gboolean autosave_is_owned (AutosaveManager *am, const char *file) { - return g_hash_table_lookup (am->table, file) != NULL; + return g_hash_table_lookup (am->table, file) != NULL; } static void @@ -2011,7 +2009,7 @@ menu_send_options_cb (BonoboUIComponent *component, void *data, const char *path EMsgComposer *composer = data; target = em_event_target_new_composer (e, composer, EM_EVENT_COMPOSER_SEND_OPTION); - e_msg_composer_set_send_options (composer, FALSE); + e_msg_composer_set_send_options (composer, FALSE); e_event_emit((EEvent *)e, "composer.selectsendoption", (EEventTarget *)target); if (!composer->priv->send_invoked) { e_error_run ((GtkWindow *)composer, "mail-composer:send-options-support", NULL); @@ -2296,176 +2294,6 @@ static EPixmap pixcache [] = { static void -signature_activate_cb (GtkWidget *menu, EMsgComposer *composer) -{ - GtkWidget *active; - ESignature *sig; - EMsgComposerPrivate *p = composer->priv; - - active = gtk_menu_get_active (GTK_MENU (menu)); - sig = g_object_get_data ((GObject *) active, "sig"); - - if (p->signature != sig) { - p->signature = sig; - e_msg_composer_show_sig_file (composer); - } -} - -static void -signature_added (ESignatureList *signatures, ESignature *sig, EMsgComposer *composer) -{ - GtkWidget *menu, *item; - EMsgComposerPrivate *p = composer->priv; - - menu = gtk_option_menu_get_menu (p->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); -} - -static void -signature_removed (ESignatureList *signatures, ESignature *sig, EMsgComposer *composer) -{ - GtkWidget *menu; - ESignature *cur; - GList *items; - EMsgComposerPrivate *p = composer->priv; - - if (p->signature == sig) { - p->signature = NULL; - e_msg_composer_show_sig_file (composer); - } - - menu = gtk_option_menu_get_menu (p->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 -menu_item_set_label (GtkMenuItem *item, const char *label) -{ - GtkWidget *widget; - - widget = gtk_bin_get_child ((GtkBin *) item); - if (GTK_IS_LABEL (widget)) - gtk_label_set_text ((GtkLabel *) widget, label); -} - -static void -signature_changed (ESignatureList *signatures, ESignature *sig, EMsgComposer *composer) -{ - GtkWidget *menu; - ESignature *cur; - GList *items; - EMsgComposerPrivate *p = composer->priv; - - menu = gtk_option_menu_get_menu (p->sig_menu); - items = GTK_MENU_SHELL (menu)->children; - while (items != NULL) { - cur = g_object_get_data (items->data, "sig"); - if (cur == sig) { - menu_item_set_label (items->data, sig->name); - break; - } - items = items->next; - } -} - -static void -sig_select_item (EMsgComposer *composer) -{ - ESignature *cur; - GtkWidget *menu; - GList *items; - int i = 0; - EMsgComposerPrivate *p = composer->priv; - - if (!p->signature) { - gtk_option_menu_set_history (p->sig_menu, 0); - return; - } - - menu = gtk_option_menu_get_menu (p->sig_menu); - items = GTK_MENU_SHELL (menu)->children; - while (items != NULL) { - cur = g_object_get_data ((GObject *) items->data, "sig"); - if (cur == p->signature) { - gtk_option_menu_set_history (p->sig_menu, i); - return; - } - items = items->next; - i++; - } -} - -static void -setup_signatures_menu (EMsgComposer *composer) -{ - GtkWidget *hbox, *hspace, *label; - ESignatureList *signatures; - GtkWidget *menu, *item; - ESignature *sig; - EIterator *it; - EMsgComposerPrivate *p = composer->priv; - - hbox = e_msg_composer_hdrs_get_from_hbox (E_MSG_COMPOSER_HDRS (p->hdrs)); - - label = gtk_label_new_with_mnemonic (_("Si_gnature:")); - gtk_widget_show (label); - - p->sig_menu = (GtkOptionMenu *) gtk_option_menu_new (); - - gtk_label_set_mnemonic_widget ((GtkLabel *) label, (GtkWidget *)p->sig_menu); - - gtk_box_pack_end_defaults (GTK_BOX (hbox), (GtkWidget *) p->sig_menu); - gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, TRUE, 0); - hspace = gtk_hbox_new (FALSE, 0); - gtk_widget_show (hspace); - gtk_box_pack_start (GTK_BOX (hbox), hspace, FALSE, FALSE, 0); - - menu = gtk_menu_new (); - gtk_widget_show (menu); - gtk_option_menu_set_menu (p->sig_menu, menu); - - item = gtk_menu_item_new_with_label (_("None")); - gtk_widget_show (item); - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - signatures = mail_config_get_signatures (); - it = e_list_get_iterator ((EList *) signatures); - - while (e_iterator_is_valid (it)) { - sig = (ESignature *) e_iterator_get (it); - signature_added (signatures, sig, composer); - e_iterator_next (it); - } - - g_object_unref (it); - - g_signal_connect (menu, "selection-done", G_CALLBACK (signature_activate_cb), composer); - - gtk_widget_show ((GtkWidget *) p->sig_menu); - - p->sig_added_id = g_signal_connect (signatures, "signature-added", G_CALLBACK (signature_added), composer); - p->sig_removed_id = g_signal_connect (signatures, "signature-removed", G_CALLBACK (signature_removed), composer); - p->sig_changed_id = g_signal_connect (signatures, "signature-changed", G_CALLBACK (signature_changed), composer); -} - -static void setup_ui (EMsgComposer *composer) { EMMenuTargetWidget *target; @@ -2672,7 +2500,7 @@ attachment_bar_changed_cb (EAttachmentBar *bar, /* Mark the composer as changed so it prompts about unsaved - changes on close */ + changes on close */ e_msg_composer_set_changed (composer); } static void @@ -2851,11 +2679,8 @@ from_changed_cb (EMsgComposerHdrs *hdrs, void *data) static void composer_finalise (GObject *object) { - EMsgComposer *composer; - EMsgComposerPrivate *p; - - composer = E_MSG_COMPOSER (object); - p = composer->priv; + EMsgComposer *composer = E_MSG_COMPOSER (object); + EMsgComposerPrivate *p = composer->priv; if (p->extra_hdr_names) { int i; @@ -2908,7 +2733,6 @@ destroy (GtkObject *object) EMsgComposer *composer = (EMsgComposer *)object; EMsgComposerPrivate *p = composer->priv; CORBA_Environment ev; - ESignatureList *signatures; CORBA_exception_init (&ev); @@ -2939,7 +2763,7 @@ destroy (GtkObject *object) } /* FIXME? I assume the Bonobo widget will get destroyed - normally? */ + normally? */ if (p->address_dialog != NULL) { gtk_widget_destroy (p->address_dialog); p->address_dialog = NULL; @@ -2981,23 +2805,6 @@ destroy (GtkObject *object) p->eeditor_listener = NULL; } - signatures = mail_config_get_signatures (); - - if (p->sig_added_id != 0) { - g_signal_handler_disconnect (signatures, p->sig_added_id); - p->sig_added_id = 0; - } - - if (p->sig_removed_id != 0) { - g_signal_handler_disconnect (signatures, p->sig_removed_id); - p->sig_removed_id = 0; - } - - if (p->sig_changed_id != 0) { - g_signal_handler_disconnect (signatures, p->sig_changed_id); - p->sig_changed_id = 0; - } - if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); } @@ -3925,14 +3732,14 @@ button_press_event (GtkWidget *widget, GdkEventButton *event) static gint key_press_event(GtkWidget *widget, GdkEventKey *event) { - EAttachmentBar *bar = E_ATTACHMENT_BAR(widget); + EAttachmentBar *bar = E_ATTACHMENT_BAR(widget); - if (event->keyval == GDK_Delete) { - e_attachment_bar_remove_selected (bar); - return TRUE; - } + if (event->keyval == GDK_Delete) { + e_attachment_bar_remove_selected (bar); + return TRUE; + } - return FALSE; + return FALSE; } static EMsgComposer * @@ -3999,10 +3806,11 @@ create_composer (int visible_mask) G_CALLBACK (hdrs_changed_cb), composer); g_signal_connect (p->hdrs, "from_changed", G_CALLBACK (from_changed_cb), composer); + g_signal_connect_swapped ( + p->hdrs, "signature_changed", + G_CALLBACK (e_msg_composer_show_sig_file), composer); gtk_widget_show (p->hdrs); - setup_signatures_menu (composer); - from_changed_cb((EMsgComposerHdrs *)p->hdrs, composer); /* Editor component. */ @@ -4047,7 +3855,7 @@ create_composer (int visible_mask) gtk_box_pack_start (GTK_BOX (vbox), p->eeditor, TRUE, TRUE, 0); /* Attachment editor, wrapped into an EScrollFrame. It's - hidden in an EExpander. */ + hidden in an EExpander. */ p->attachment_scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (p->attachment_scrolled_window), @@ -4143,22 +3951,18 @@ create_composer (int visible_mask) static void set_editor_signature (EMsgComposer *composer) { - EAccountIdentity *id; - EMsgComposerPrivate *p = composer->priv; + EMsgComposerHdrs *hdrs; + ESignature *signature; EAccount *account; + const gchar *uid; - account = e_msg_composer_hdrs_get_from_account ( - E_MSG_COMPOSER_HDRS (p->hdrs)); - + hdrs = E_MSG_COMPOSER_HDRS (composer->priv->hdrs); + account = e_msg_composer_hdrs_get_from_account (hdrs); g_return_if_fail (account != NULL); - id = account->id; - if (id->sig_uid) - p->signature = mail_config_get_signature_by_uid (id->sig_uid); - else - p->signature = NULL; - - sig_select_item (composer); + uid = account->id->sig_uid; + signature = uid ? mail_config_get_signature_by_uid (uid) : NULL; + e_msg_composer_hdrs_set_signature (hdrs, signature); } /** @@ -4238,7 +4042,7 @@ e_msg_composer_set_pending_body (EMsgComposer *composer, char *text, ssize_t len char *old; old = g_object_get_data ((GObject *) composer, "body:text"); - g_free (old); + g_free (old); g_object_set_data ((GObject *) composer, "body:text", text); g_object_set_data ((GObject *) composer, "body:len", GSIZE_TO_POINTER (len)); } @@ -4246,7 +4050,7 @@ e_msg_composer_set_pending_body (EMsgComposer *composer, char *text, ssize_t len static void e_msg_composer_flush_pending_body (EMsgComposer *composer, gboolean apply) { - char *body; + char *body; ssize_t len; body = g_object_get_data ((GObject *) composer, "body:text"); @@ -4368,9 +4172,9 @@ handle_multipart_signed (EMsgComposer *composer, CamelMultipart *multipart, int multipart = CAMEL_MULTIPART (content); /* Note: depth is preserved here because we're not - counting multipart/signed as a multipart, instead - we want to treat the content part as our mime part - here. */ + counting multipart/signed as a multipart, instead + we want to treat the content part as our mime part + here. */ if (CAMEL_IS_MULTIPART_SIGNED (content)) { /* handle the signed content and configure the composer to sign outgoing messages */ @@ -4427,9 +4231,9 @@ handle_multipart_encrypted (EMsgComposer *composer, CamelMimePart *multipart, in CamelMultipart *content_multipart = CAMEL_MULTIPART (content); /* Note: depth is preserved here because we're not - counting multipart/encrypted as a multipart, instead - we want to treat the content part as our mime part - here. */ + counting multipart/encrypted as a multipart, instead + we want to treat the content part as our mime part + here. */ if (CAMEL_IS_MULTIPART_SIGNED (content)) { /* handle the signed content and configure the composer to sign outgoing messages */ @@ -4577,8 +4381,10 @@ set_signature_gui (EMsgComposer *composer) { CORBA_Environment ev; EMsgComposerPrivate *p = composer->priv; + EMsgComposerHdrs *hdrs; + ESignature *signature = NULL; - p->signature = NULL; + hdrs = E_MSG_COMPOSER_HDRS (composer->priv->hdrs); CORBA_exception_init (&ev); if (GNOME_GtkHTML_Editor_Engine_searchByData (p->eeditor_engine, 1, "ClueFlow", "signature", "1", &ev)) { @@ -4588,17 +4394,17 @@ set_signature_gui (EMsgComposer *composer) if (ev._major == CORBA_NO_EXCEPTION && str) { if (!strncmp (str, "uid:", 4)) { name = decode_signature_name (str + 4); - p->signature = mail_config_get_signature_by_uid (name); + signature = mail_config_get_signature_by_uid (name); g_free (name); } else if (!strncmp (str, "name:", 5)) { name = decode_signature_name (str + 4); - p->signature = mail_config_get_signature_by_name (name); + signature = mail_config_get_signature_by_name (name); g_free (name); } CORBA_free (str); } - sig_select_item (composer); + e_msg_composer_hdrs_set_signature (hdrs, signature); } CORBA_exception_free (&ev); } @@ -5037,7 +4843,7 @@ handle_mailto (EMsgComposer *composer, const char *mailto) "attachment"); } gtk_widget_show (priv->attachment_expander); - gtk_widget_show (priv->attachment_scrolled_window); + gtk_widget_show (priv->attachment_scrolled_window); } else if (!g_ascii_strcasecmp (header, "from")) { /* Ignore */ } else if (!g_ascii_strcasecmp (header, "reply-to")) { @@ -5193,7 +4999,7 @@ void e_msg_composer_set_body_text (EMsgComposer *composer, const char *text, ssize_t len) { g_return_if_fail (E_IS_MSG_COMPOSER (composer)); - g_return_if_fail (text != NULL); + g_return_if_fail (text != NULL); set_editor_text (composer, text, len, TRUE, *text == '\0'); } @@ -6447,7 +6253,7 @@ e_msg_composer_get_raw_message_text (EMsgComposer *composer) data = get_text (p->persist_stream_interface, "text/plain"); if (data) - return (const gchar *)data->data; + return (const gchar *)data->data; return NULL; } |