diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2008-04-03 02:37:22 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-04-03 02:37:22 +0800 |
commit | 16068d9b4191ea142a9e75a50eb8d260ed2bb406 (patch) | |
tree | 835a7909cd8b352d8c414986f1f5e27697b4de98 /mail | |
parent | ee50e5d68e4f1a793541f1ee4979818ed4940173 (diff) | |
download | gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar.gz gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar.bz2 gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar.lz gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar.xz gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.tar.zst gsoc2013-evolution-16068d9b4191ea142a9e75a50eb8d260ed2bb406.zip |
** Merge the mbarnes-composer branch
2008-04-02 Matthew Barnes <mbarnes@redhat.com>
** Merge the mbarnes-composer branch
* configure.in:
Bump libgtkhtml requirement to 3.19.1.
Add gtkhtml-editor dependency for addressbook, calendar and mail.
Remove print-message plugin; new composer implements this natively.
* tools/Makefile.am:
Remove CORBA rules for the old composer.
* addressbook/gui/widgets/Makefile.am:
Remove CORBA rules for the old composer.
* addressbook/gui/widgets/eab-gui-util.c
(eab_send_to_contact_and_email_num_list),
(eab_send_contact_list_as_attachment):
Adapt to new Bonobo-less composer widget.
* calendar/gui/Makefile.am:
Remove CORBA rules for the old composer.
* calendar/gui/itip-utils.c (comp_from), (comp_to_list),
(comp_subject), (comp_content_type), (comp_filename),
(comp_description), (append_cal_attachments), (itip_send_comp),
(reply_to_calendar_comp):
Adapt to new Bonobo-less composer widget.
* composer/Makefile.am:
Remove CORBA rules for the old composer.
* composer/e-msg-composer.c:
* composer/e-msg-composer.h:
EMsgComposer is now a subclass of GtkhtmlEditor.
Extensive refactoring and cleanup, too much to list in detail.
* composer/e-composer-header.c:
* composer/e-composer-header.h:
Add "sensitive" property along with get/set functions.
* composer/e-composer-from-header.c:
* composer/e-composer-from-header.h:
Propagate "refreshed" signal from EAccountComboBox.
Add function e_composer_from_header_get_account_list().
* composer/e-composer-private.c:
* composer/e-composer-private.h:
New files manage composer's private data.
Allows other composer files to manipulate private data.
* composer/e-msg-composer-hdrs.c:
* composer/e-msg-composer-hdrs.h:
Remove these files; replaced by EComposerHeaderTable widget.
* composer/evolution-composer.c:
* composer/evolution-composer.h:
Remove these files; composer is now a subclass of GtkhtmlEditor.
* composer/e-msg-composer-select-file.c:
* composer/e-msg-composer-select-file.h:
Remove these files; logic moved to e-msg-composer.c.
* composer/listener.c:
* composer/listener.h:
Remove these files; event handlers moved to e-msg-composer.c.
* composer/Composer.idl:
* composer/Evolution-Composer.idl:
Remove these files; composer is no longer a Bonobo object.
* mail/em-composer-prefs (sig_edit_cb),
(em_composer_prefs_new_signature):
Adapt to new Bonobo-less signature editor.
* mail/mail-signature-editor.c:
* mail/mail-signature-editor.h:
Rewrite the signature editor as a subclass of GtkhtmlEditor.
Eliminates Bonobo from the equation.
* mail/em-composer-utils.c (composer_get_message),
(em_utils_composer_send_cb), (save_draft_done),
(em_utils_composer_save_draft_cb), (create_new_composer),
(em_utils_compose_new_message),
(em_utils_compose_new_message_with_mailto), (em_utils_post_to_folder),
(em_utils_post_to_url), (edit_message), (forward_attached),
(forward_non_attached), (reply_get_composer), (composer_set_body),
(em_utils_reply_to_message), (post_reply_to_message):
Adapt to new Bonobo-less composer.
* mail/mail-component-factory.c:
Composer is no longer needs a Bonobo factory.
* mail/mail-config.c:
Fix style pattern for EMsgComposer widgets.
* plugins/groupwise/mail-send-options.c
(org_gnome_composer_send_options):
Adapt to streamlined EMsgComposer API.
* plugins/exchange-operations/Makefile.am:
Add EVOLUTION_MAIL_CFLAGS and EVOLUTION_MAIL_LIBS.
* plugins/exchange-operations/exchange-mail-send-options.c
(append_to_header), (org_gnome_exchange_send_options):
Adapt to streamlined EMsgComposer API.
* plugins/mailing-list-actions/mailing-list-actions.c
(emla_list_action_do):
Adapt to streamlined EMsgComposer API.
* po/POTFILES.in: Update file list for new composer.
* ui/evolution-composer-entries.xml:
Remove this file; obsoleted by new composer.
* widgets/misc/Makefile.am:
Add EVOLUTION_MAIL_LIBS.
* widgets/misc/e-account-combo-box.c:
* widgets/misc/e-account-combo-box.h:
New function e_account_combo_box_get_account_list().
Emit a "refreshed" signal when the EAccountList changes.
Add an internal reverse-lookup index.
* widgets/misc/e-charset-picker.c (e_charser_add_radio_actions):
New function adds radio actions to an action group.
Will eventually replace e_charset_picker_bonobo_ui_populate().
* widgets/misc/e-signature-combo-box.c:
* widgets/misc/e-signature-combo-box.h:
New function e_signature_combo_box_get_signature_list().
... separate issue ...
* configure.in:
Bump eds_minimum_version to 2.23.1 for
CAMEL_FOLDER_JUNKED_NOT_DELETED symbol.
svn path=/trunk/; revision=35313
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 26 | ||||
-rw-r--r-- | mail/em-composer-prefs.c | 19 | ||||
-rw-r--r-- | mail/em-composer-utils.c | 163 | ||||
-rw-r--r-- | mail/mail-component-factory.c | 6 | ||||
-rw-r--r-- | mail/mail-config.c | 2 | ||||
-rw-r--r-- | mail/mail-signature-editor.c | 718 | ||||
-rw-r--r-- | mail/mail-signature-editor.h | 53 |
7 files changed, 574 insertions, 413 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index f71ba1a4ea..f7b1f6af9a 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,29 @@ +2008-04-02 Matthew Barnes <mbarnes@redhat.com> + + * em-composer-prefs (sig_edit_cb), (em_composer_prefs_new_signature): + Adapt to new Bonobo-less signature editor. + + * mail-signature-editor.c: + * mail-signature-editor.h: + Rewrite the signature editor as a subclass of GtkhtmlEditor. + Eliminates Bonobo from the equation. + + * em-composer-utils.c (composer_get_message), + (em_utils_composer_send_cb), (save_draft_done), + (em_utils_composer_save_draft_cb), (create_new_composer), + (em_utils_compose_new_message), + (em_utils_compose_new_message_with_mailto), (em_utils_post_to_folder), + (em_utils_post_to_url), (edit_message), (forward_attached), + (forward_non_attached), (reply_get_composer), (composer_set_body), + (em_utils_reply_to_message), (post_reply_to_message): + Adapt to new Bonobo-less composer. + + * mail-component-factory.c: + Composer is no longer needs a Bonobo factory. + + * mail-config.c: + Fix style pattern for EMsgComposer widgets. + 2008-04-02 Milan Crha <mcrha@redhat.com> ** Fix for bug #271863 diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c index 1f90b6ee3b..8545e26fa6 100644 --- a/mail/em-composer-prefs.c +++ b/mail/em-composer-prefs.c @@ -298,16 +298,24 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs) gtk_tree_model_get (model, &iter, 1, &sig, -1); if (!sig->script) { + GtkWidget *editor; + /* normal signature */ if (!sig->filename || *sig->filename == '\0') { g_free (sig->filename); sig->filename = g_strdup (_("Unnamed")); } + editor = e_signature_editor_new (); + e_signature_editor_set_signature ( + E_SIGNATURE_EDITOR (editor), sig); + parent = gtk_widget_get_toplevel ((GtkWidget *) prefs); - parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; + if (GTK_WIDGET_TOPLEVEL (parent)) + gtk_window_set_transient_for ( + GTK_WINDOW (editor), GTK_WINDOW (parent)); - mail_signature_editor (sig, (GtkWindow *) parent, FALSE); + gtk_widget_show (editor); } else { /* signature script */ GtkWidget *entry; @@ -327,10 +335,11 @@ sig_edit_cb (GtkWidget *widget, EMComposerPrefs *prefs) void em_composer_prefs_new_signature (GtkWindow *parent, gboolean html) { - ESignature *sig; + GtkWidget *editor; - sig = mail_config_signature_new (NULL, FALSE, html); - mail_signature_editor (sig, parent, TRUE); + editor = e_signature_editor_new (); + gtk_window_set_transient_for (GTK_WINDOW (editor), parent); + gtk_widget_show (editor); } static void diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index 3b7271d021..224c417777 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -251,7 +251,7 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) { CamelMimeMessage *message = NULL; EDestination **recipients, **recipients_bcc; - gboolean send_html, confirm_html; + gboolean html_mode, send_html, confirm_html; CamelInternetAddress *cia; int hidden = 0, shown = 0; int num = 0, num_bcc = 0, num_post = 0; @@ -262,15 +262,17 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) GList *postlist; EMEvent *eme; EMEventTargetComposer *target; + EComposerHeaderTable *table; gconf = mail_config_get_gconf_client (); + table = e_msg_composer_get_header_table (composer); /* We should do all of the validity checks based on the composer, and not on the created message, as extra interaction may occur when we get the message (e.g. to get a passphrase to sign a message) */ /* get the message recipients */ - recipients = e_msg_composer_get_recipients (composer); + recipients = e_composer_header_table_get_destinations (table); cia = camel_internet_address_new (); @@ -295,7 +297,7 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) } } - recipients_bcc = e_msg_composer_get_bcc (composer); + recipients_bcc = e_composer_header_table_get_destinations_bcc (table); if (recipients_bcc) { for (i = 0; recipients_bcc[i] != NULL; i++) { const char *addr = e_destination_get_address (recipients_bcc[i]); @@ -314,7 +316,7 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) camel_object_unref (cia); - postlist = e_msg_composer_hdrs_get_post_to(e_msg_composer_get_hdrs (composer)); + postlist = e_composer_header_table_get_post_to (table); num_post = g_list_length(postlist); g_list_foreach(postlist, (GFunc)g_free, NULL); g_list_free(postlist); @@ -331,13 +333,15 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) goto finished; } + html_mode = gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (composer)); send_html = gconf_client_get_bool (gconf, "/apps/evolution/mail/composer/send_html", NULL); confirm_html = gconf_client_get_bool (gconf, "/apps/evolution/mail/prompts/unwanted_html", NULL); /* Only show this warning if our default is to send html. If it isn't, we've manually switched into html mode in the composer and (presumably) had a good reason for doing this. */ - if (e_msg_composer_get_send_html (composer) && send_html && confirm_html) { + if (html_mode && send_html && confirm_html) { + gboolean html_problem = FALSE; if (recipients) { @@ -355,7 +359,7 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) } /* Check for no subject */ - subject = e_msg_composer_get_subject (composer); + subject = e_composer_header_table_get_subject (table); if (subject == NULL || subject[0] == '\0') { if (!ask_confirm_for_empty_subject (composer)) goto finished; @@ -384,7 +388,7 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) goto finished; /* Add info about the sending account */ - account = e_msg_composer_get_preferred_account (composer); + account = e_composer_header_table_get_account (table); if (account) { /* FIXME: Why isn't this crap just in e_msg_composer_get_message? */ @@ -411,13 +415,15 @@ composer_get_message (EMsgComposer *composer, gboolean save_html_object_data) void em_utils_composer_send_cb (EMsgComposer *composer, gpointer user_data) { + EComposerHeaderTable *table; CamelMimeMessage *message; CamelMessageInfo *info; struct _send_data *send; CamelFolder *mail_folder; EAccount *account; - account = e_msg_composer_get_preferred_account (composer); + table = e_msg_composer_get_header_table (composer); + account = e_composer_header_table_get_account (table); if (!account || !account->enabled) { e_error_run((GtkWindow *)composer, "mail:send-no-account-enabled", NULL); return; @@ -466,7 +472,7 @@ save_draft_done (CamelFolder *folder, CamelMimeMessage *msg, CamelMessageInfo *i if (!ok) goto done; - e_msg_composer_set_saved (sdi->composer); + gtkhtml_editor_set_changed (GTKHTML_EDITOR (sdi->composer), FALSE); if ((emcs = sdi->emcs) == NULL) { emcs = emcs_new (); @@ -532,6 +538,7 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer, int quit, gpointer user { const char *default_drafts_folder_uri = mail_component_get_folder_uri(NULL, MAIL_COMPONENT_FOLDER_DRAFTS); CamelFolder *drafts_folder = mail_component_get_folder(NULL, MAIL_COMPONENT_FOLDER_DRAFTS); + EComposerHeaderTable *table; struct _save_draft_info *sdi; CamelFolder *folder = NULL; CamelMimeMessage *msg; @@ -544,7 +551,8 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer, int quit, gpointer user g_object_ref(composer); msg = e_msg_composer_get_message_draft (composer); - account = e_msg_composer_get_preferred_account (composer); + table = e_msg_composer_get_header_table (composer); + account = e_composer_header_table_get_account (table); sdi = g_malloc(sizeof(struct _save_draft_info)); sdi->composer = composer; @@ -587,8 +595,13 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer, int quit, gpointer user } void -em_composer_utils_setup_callbacks (EMsgComposer *composer, CamelFolder *folder, const char *uid, - guint32 flags, guint32 set, CamelFolder *drafts, const char *drafts_uid) +em_composer_utils_setup_callbacks (EMsgComposer *composer, + CamelFolder *folder, + const char *uid, + guint32 flags, + guint32 set, + CamelFolder *drafts, + const char *drafts_uid) { struct emcs_t *emcs; @@ -620,6 +633,7 @@ static EMsgComposer * create_new_composer (const char *subject, const char *fromuri) { EMsgComposer *composer; + EComposerHeaderTable *table; EAccount *account = NULL; composer = e_msg_composer_new (); @@ -629,14 +643,9 @@ create_new_composer (const char *subject, const char *fromuri) if (fromuri) account = mail_config_get_account_by_source_url(fromuri); - /* If the account corresponding to the fromuri is not enabled. - * We get the preffered account from the composer and use that - * as the account to send the mail. - */ - if (!account) - account = e_msg_composer_get_preferred_account (composer); - - e_msg_composer_set_headers (composer, account?account->name:NULL, NULL, NULL, NULL, subject); + table = e_msg_composer_get_header_table (composer); + e_composer_header_table_set_account (table, account); + e_composer_header_table_set_subject (table, subject); em_composer_utils_setup_default_callbacks (composer); @@ -653,13 +662,15 @@ void em_utils_compose_new_message (const char *fromuri) { GtkWidget *composer; + GtkhtmlEditor *editor; composer = (GtkWidget *) create_new_composer ("", fromuri); if (composer == NULL) return; - e_msg_composer_unset_changed ((EMsgComposer *)composer); - e_msg_composer_drop_editor_undo ((EMsgComposer *)composer); + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show (composer); } @@ -676,6 +687,8 @@ void em_utils_compose_new_message_with_mailto (const char *url, const char *fromuri) { EMsgComposer *composer; + GtkhtmlEditor *editor; + EComposerHeaderTable *table; EAccount *account = NULL; if (url != NULL) @@ -683,14 +696,16 @@ em_utils_compose_new_message_with_mailto (const char *url, const char *fromuri) else composer = e_msg_composer_new (); + table = e_msg_composer_get_header_table (composer); em_composer_utils_setup_default_callbacks (composer); if (fromuri && (account = mail_config_get_account_by_source_url(fromuri))) - e_msg_composer_hdrs_set_from_account(e_msg_composer_get_hdrs(composer), account->name); + e_composer_header_table_set_account_name (table, account->name); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show ((GtkWidget *) composer); gdk_window_raise (((GtkWidget *) composer)->window); @@ -708,14 +723,20 @@ void em_utils_post_to_folder (CamelFolder *folder) { EMsgComposer *composer; + GtkhtmlEditor *editor; + EComposerHeaderTable *table; EAccount *account; composer = e_msg_composer_new_with_type (E_MSG_COMPOSER_POST); + table = e_msg_composer_get_header_table (composer); if (folder != NULL) { char *url = mail_tools_folder_to_url (folder); + GList *list = g_list_prepend (NULL, url); + + e_composer_header_table_set_post_to_list (table, list); - e_msg_composer_hdrs_set_post_to (e_msg_composer_get_hdrs (composer), url); + g_list_free (list); g_free (url); url = camel_url_to_string (CAMEL_SERVICE (folder->parent_store)->url, CAMEL_URL_HIDE_ALL); @@ -723,13 +744,15 @@ em_utils_post_to_folder (CamelFolder *folder) g_free (url); if (account) - e_msg_composer_hdrs_set_from_account (e_msg_composer_get_hdrs(composer), account->name); + e_composer_header_table_set_account_name ( + table, account->name); } em_composer_utils_setup_default_callbacks (composer); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show ((GtkWidget *) composer); gdk_window_raise (((GtkWidget *) composer)->window); @@ -747,16 +770,25 @@ void em_utils_post_to_url (const char *url) { EMsgComposer *composer; + GtkhtmlEditor *editor; + EComposerHeaderTable *table; composer = e_msg_composer_new_with_type (E_MSG_COMPOSER_POST); + table = e_msg_composer_get_header_table (composer); - if (url != NULL) - e_msg_composer_hdrs_set_post_to (e_msg_composer_get_hdrs (composer), url); + if (url != NULL) { + GList *list = NULL; + + list = g_list_prepend (list, (gpointer) url); + e_composer_header_table_set_post_to_list (table, list); + g_list_free (list); + } em_composer_utils_setup_default_callbacks (composer); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show ((GtkWidget *) composer); } @@ -767,11 +799,14 @@ static void edit_message (CamelMimeMessage *message, CamelFolder *drafts, const char *uid) { EMsgComposer *composer; + GtkhtmlEditor *editor; composer = e_msg_composer_new_with_message (message); em_composer_utils_setup_callbacks (composer, NULL, NULL, 0, 0, drafts, uid); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show (GTK_WIDGET (composer)); } @@ -832,14 +867,17 @@ static void forward_attached (CamelFolder *folder, GPtrArray *messages, CamelMimePart *part, char *subject, const char *fromuri) { EMsgComposer *composer; + GtkhtmlEditor *editor; composer = create_new_composer (subject, fromuri); if (composer == NULL) return; e_msg_composer_attach (composer, part); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + + editor = GTKHTML_EDITOR (editor); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show (GTK_WIDGET (composer)); } @@ -878,6 +916,7 @@ forward_non_attached (GPtrArray *messages, int style, const char *fromuri) { CamelMimeMessage *message; EMsgComposer *composer; + GtkhtmlEditor *editor; char *subject, *text; int i; guint32 flags; @@ -905,8 +944,10 @@ forward_non_attached (GPtrArray *messages, int style, const char *fromuri) e_msg_composer_add_message_attachments(composer, message, FALSE); e_msg_composer_set_body_text (composer, text, len); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); gtk_widget_show (GTK_WIDGET (composer)); } @@ -1076,14 +1117,17 @@ void em_utils_redirect_message (CamelMimeMessage *message) { EMsgComposer *composer; + GtkhtmlEditor *editor; g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); composer = redirect_get_composer (message); gtk_widget_show (GTK_WIDGET (composer)); - e_msg_composer_unset_changed (composer); - e_msg_composer_drop_editor_undo (composer); + + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); + gtkhtml_editor_drop_undo (editor); } static void @@ -1403,6 +1447,7 @@ reply_get_composer (CamelMimeMessage *message, EAccount *account, const char *message_id, *references; EDestination **tov, **ccv; EMsgComposer *composer; + EComposerHeaderTable *table; char *subject; g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); @@ -1431,7 +1476,11 @@ reply_get_composer (CamelMimeMessage *message, EAccount *account, subject = g_strdup (""); } - e_msg_composer_set_headers (composer, account ? account->name : NULL, tov, ccv, NULL, subject); + table = e_msg_composer_get_header_table (composer); + e_composer_header_table_set_account (table, account); + e_composer_header_table_set_subject (table, subject); + e_composer_header_table_set_destinations_to (table, tov); + e_composer_header_table_set_destinations_cc (table, ccv); g_free (subject); @@ -1447,7 +1496,8 @@ reply_get_composer (CamelMimeMessage *message, EAccount *account, } post = camel_address_encode((CamelAddress *)postto); - e_msg_composer_hdrs_set_post_to_base (e_msg_composer_get_hdrs(composer), store_url ? store_url : "", post); + e_composer_header_table_set_post_to_base ( + table, store_url ? store_url : "", post); g_free(post); g_free (store_url); } @@ -1471,7 +1521,7 @@ reply_get_composer (CamelMimeMessage *message, EAccount *account, e_msg_composer_add_header (composer, "References", references); } - e_msg_composer_drop_editor_undo (composer); + gtkhtml_editor_drop_undo (GTKHTML_EDITOR (composer)); return composer; } @@ -1904,7 +1954,7 @@ composer_set_body (EMsgComposer *composer, CamelMimeMessage *message, EMFormat * break; } - e_msg_composer_drop_editor_undo (composer); + gtkhtml_editor_drop_undo (GTKHTML_EDITOR (composer)); } struct _reply_data { @@ -2019,7 +2069,8 @@ em_utils_reply_to_message(CamelFolder *folder, const char *uid, CamelMimeMessage em_composer_utils_setup_callbacks (composer, folder, uid, flags, flags, NULL, NULL); gtk_widget_show (GTK_WIDGET (composer)); - e_msg_composer_unset_changed (composer); + + gtkhtml_editor_set_changed (GTKHTML_EDITOR (composer), FALSE); } /* Posting replies... */ @@ -2033,10 +2084,13 @@ post_reply_to_message (CamelFolder *folder, const char *uid, CamelMimeMessage *m EDestination **tov = NULL; CamelFolder *real_folder; EMsgComposer *composer; + GtkhtmlEditor *editor; + EComposerHeaderTable *table; char *subject, *url; EAccount *account; char *real_uid; guint32 flags; + GList *list = NULL; if (message == NULL) return; @@ -2060,6 +2114,7 @@ post_reply_to_message (CamelFolder *folder, const char *uid, CamelMimeMessage *m get_reply_sender (message, to, NULL); composer = e_msg_composer_new_with_type (E_MSG_COMPOSER_MAIL_POST); + editor = GTKHTML_EDITOR (composer); /* construct the tov/ccv */ tov = em_utils_camel_address_to_destination (to); @@ -2074,12 +2129,19 @@ post_reply_to_message (CamelFolder *folder, const char *uid, CamelMimeMessage *m subject = g_strdup (""); } - e_msg_composer_set_headers (composer, account ? account->name : NULL, tov, NULL, NULL, subject); + table = e_msg_composer_get_header_table (composer); + e_composer_header_table_set_account (table, account); + e_composer_header_table_set_subject (table, subject); + e_composer_header_table_set_destinations_to (table, tov); g_free (subject); url = mail_tools_folder_to_url (real_folder); - e_msg_composer_hdrs_set_post_to (e_msg_composer_get_hdrs(composer), url); + list = g_list_prepend (list, url); + + e_composer_header_table_set_post_to_list (table, list); + + g_list_free (list); g_free (url); /* Add In-Reply-To and References. */ @@ -2101,7 +2163,7 @@ post_reply_to_message (CamelFolder *folder, const char *uid, CamelMimeMessage *m e_msg_composer_add_header (composer, "References", references); } - e_msg_composer_drop_editor_undo (composer); + gtkhtml_editor_drop_undo (editor); e_msg_composer_add_message_attachments (composer, message, TRUE); @@ -2110,7 +2172,8 @@ post_reply_to_message (CamelFolder *folder, const char *uid, CamelMimeMessage *m em_composer_utils_setup_callbacks (composer, real_folder, real_uid, flags, flags, NULL, NULL); gtk_widget_show (GTK_WIDGET (composer)); - e_msg_composer_unset_changed (composer); + + gtkhtml_editor_set_changed (editor, FALSE); camel_object_unref (real_folder); camel_object_unref(to); diff --git a/mail/mail-component-factory.c b/mail/mail-component-factory.c index 2abf71a323..49b894d0d7 100644 --- a/mail/mail-component-factory.c +++ b/mail/mail-component-factory.c @@ -24,8 +24,6 @@ #include <config.h> #endif -#include "em-composer-utils.h" -#include "evolution-composer.h" #include "mail-component.h" #include "em-account-prefs.h" #include "em-mailer-prefs.h" @@ -56,7 +54,6 @@ #define FACTORY_ID "OAFIID:GNOME_Evolution_Mail_Factory:" BASE_VERSION #define COMPONENT_ID "OAFIID:GNOME_Evolution_Mail_Component:" BASE_VERSION -#define COMPOSER_ID "OAFIID:GNOME_Evolution_Mail_Composer:" BASE_VERSION #define FOLDER_INFO_ID "OAFIID:GNOME_Evolution_FolderInfo:" BASE_VERSION static BonoboObject * @@ -74,9 +71,6 @@ factory(BonoboGenericFactory *factory, const char *component_id, void *closure) || strcmp (component_id, EM_COMPOSER_PREFS_CONTROL_ID) == 0 || strcmp (component_id, EM_NETWORK_PREFS_CONTROL_ID) == 0) { return mail_config_control_factory_cb (factory, component_id, CORBA_OBJECT_NIL); - } else if (strcmp(component_id, COMPOSER_ID) == 0) { - /* FIXME: how to remove need for callbacks, probably make the composer more tightly integrated with mail */ - return (BonoboObject *) evolution_composer_new (em_utils_composer_send_cb, em_utils_composer_save_draft_cb); } o = mail_importer_factory_cb(factory, component_id, NULL); diff --git a/mail/mail-config.c b/mail/mail-config.c index 3e34ea100d..a00e00e2d8 100644 --- a/mail/mail-config.c +++ b/mail/mail-config.c @@ -215,7 +215,7 @@ config_write_style (void) fprintf (rc, "widget \"*.EMFolderView.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n"); fprintf (rc, "widget \"*.EMFolderBrowser.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n"); fprintf (rc, "widget \"*.EMMessageBrowser.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n"); - fprintf (rc, "widget \"*.BonoboPlug.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n"); + fprintf (rc, "widget \"EMsgComposer.*.GtkHTML\" style \"evolution-mail-custom-fonts\"\n"); fprintf (rc, "widget \"*.EvolutionMailPrintHTMLWidget\" style \"evolution-mail-custom-fonts\"\n"); fflush (rc); fclose (rc); diff --git a/mail/mail-signature-editor.c b/mail/mail-signature-editor.c index 48e11041c0..6843c8818f 100644 --- a/mail/mail-signature-editor.c +++ b/mail/mail-signature-editor.c @@ -21,440 +21,478 @@ * */ -#include <config.h> +#include "mail-signature-editor.h" #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gstdio.h> - -#include <gtk/gtk.h> +#include <glib/gi18n.h> -#include <bonobo.h> -#include <bonobo/bonobo-stream-memory.h> +#include <e-util/e-error.h> +#include <e-util/e-signature-list.h> +#include <composer/e-msg-composer.h> -#include "e-util/e-error.h" -#include "e-util/e-signature-list.h" -#include "e-util/e-util-private.h" - -#include "e-msg-composer.h" -#include "mail-signature-editor.h" #include "mail-config.h" -#define d(x) - -#define GNOME_GTKHTML_EDITOR_CONTROL_ID "OAFIID:GNOME_GtkHTML_Editor:" GTKHTML_API_VERSION +#define E_SIGNATURE_EDITOR_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_SIGNATURE_EDITOR, ESignatureEditorPrivate)) -typedef struct _ESignatureEditor { - GtkWidget *win; - GtkWidget *control; - GtkWidget *name_entry; - GtkWidget *info_frame; - - ESignature *sig; - gboolean is_new; - gboolean html; - - GNOME_GtkHTML_Editor_Engine engine; -} ESignatureEditor; - -#define E_SIGNATURE_EDITOR(o) ((ESignatureEditor *) o) +enum { + PROP_0, + PROP_SIGNATURE +}; -#define DEFAULT_WIDTH 600 -#define DEFAULT_HEIGHT 350 +struct _ESignatureEditorPrivate { + GtkActionGroup *action_group; + ESignature *signature; + GtkWidget *entry; + gchar *original_name; +}; -enum { REPLY_YES = 0, REPLY_NO, REPLY_CANCEL }; +static const gchar *ui = +"<ui>\n" +" <menubar name='main-menu'>\n" +" <placeholder name='pre-edit-menu'>\n" +" <menu action='file-menu'>\n" +" <menuitem action='save-and-close'/>\n" +" <separator/>" +" <menuitem action='close'/>\n" +" </menu>\n" +" </placeholder>\n" +" </menubar>\n" +" <toolbar name='main-toolbar'>\n" +" <placeholder name='pre-main-toolbar'>\n" +" <toolitem action='save-and-close'/>\n" +" </placeholder>\n" +" </toolbar>\n" +"</ui>"; + +static gpointer parent_class = NULL; static void -destroy_editor (ESignatureEditor *editor) +handle_error (GError **error) { - gtk_widget_destroy (editor->win); - g_free (editor); + if (*error != NULL) { + g_warning ("%s", (*error)->message); + g_clear_error (error); + } } static void -menu_file_save_error (BonoboUIComponent *uic, CORBA_Environment *ev) -{ - char *err; - - /* errno is set if the rename() fails in menu_file_save_cb */ - - err = ev->_major != CORBA_NO_EXCEPTION ? bonobo_exception_get_text (ev) : g_strdup (g_strerror (errno)); - - e_error_run(NULL, "mail:no-save-signature", err, NULL); - g_warning ("Exception while saving signature: %s", err); - - g_free (err); -} - -static GByteArray * -get_text (Bonobo_PersistStream persist, const char *format, CORBA_Environment *ev) -{ - BonoboStream *stream; - BonoboStreamMem *stream_mem; - GByteArray *text; - - stream = bonobo_stream_mem_create (NULL, 0, FALSE, TRUE); - Bonobo_PersistStream_save (persist, (Bonobo_Stream)bonobo_object_corba_objref (BONOBO_OBJECT (stream)), - format, ev); - - if (ev->_major != CORBA_NO_EXCEPTION) - return NULL; - - stream_mem = BONOBO_STREAM_MEM (stream); - - text = g_byte_array_new (); - g_byte_array_append (text, (unsigned char *)stream_mem->buffer, stream_mem->pos); - bonobo_object_unref (BONOBO_OBJECT (stream)); - - return text; -} - -static ssize_t -write_all (int fd, const char *buf, size_t n) +action_close_cb (GtkAction *action, + ESignatureEditor *editor) { - ssize_t w, nwritten = 0; - - do { - do { - w = write (fd, buf + nwritten, n - nwritten); - } while (w == -1 && (errno == EINTR || errno == EAGAIN)); - - if (w > 0) - nwritten += w; - } while (nwritten < n && w != -1); - - if (w == -1) - return -1; + gboolean something_changed = FALSE; + const gchar *original_name; + const gchar *signature_name; + + original_name = editor->priv->original_name; + signature_name = gtk_entry_get_text (GTK_ENTRY (editor->priv->entry)); + + something_changed |= gtkhtml_editor_has_undo (GTKHTML_EDITOR (editor)); + something_changed |= (strcmp (signature_name, original_name) != 0); + + if (something_changed) { + gint response; + + response = e_error_run ( + GTK_WINDOW (editor), + "mail:ask-signature-changed", NULL); + if (response == GTK_RESPONSE_YES) { + GtkActionGroup *action_group; + + action_group = editor->priv->action_group; + action = gtk_action_group_get_action ( + action_group, "save-and-close"); + gtk_action_activate (action); + return; + } else if (response == GTK_RESPONSE_CANCEL) + return; + } - return nwritten; + gtk_widget_destroy (GTK_WIDGET (editor)); } static void -menu_file_save_cb (BonoboUIComponent *uic, void *user_data, const char *path) +action_save_and_close_cb (GtkAction *action, + ESignatureEditor *editor) { - ESignatureEditor *editor = user_data; + GtkWidget *entry; + ESignatureList *signature_list; ESignature *signature; - Bonobo_PersistStream pstream_iface; - char *dirname, *base, *filename, *name; - CORBA_Environment ev; - GByteArray *text; - int fd; - - d(printf ("editor->sig->filename = %s\n", editor->sig->filename)); - dirname = g_path_get_dirname (editor->sig->filename); - d(printf ("dirname = %s\n", dirname)); - base = g_path_get_basename (editor->sig->filename); - d(printf ("basename = %s\n", base)); - filename = g_strdup_printf ("%s/.#%s", dirname, base); - d(printf ("filename = %s\n", filename)); - g_free (dirname); - g_free (base); - - CORBA_exception_init (&ev); - pstream_iface = Bonobo_Unknown_queryInterface - (bonobo_widget_get_objref (BONOBO_WIDGET (editor->control)), - "IDL:Bonobo/PersistStream:1.0", &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - goto exception; - - if ((fd = g_open (filename, O_WRONLY | O_TRUNC | O_CREAT, 0666)) == -1) - goto exception; - - text = get_text (pstream_iface, editor->html ? "text/html" : "text/plain", &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - close (fd); - goto exception; - } + ESignature *same_name; + const gchar *filename; + gchar *signature_name; + gboolean html; + GError *error = NULL; - if (write_all (fd, (char *)text->data, text->len) == -1) { - g_byte_array_free (text, TRUE); - close (fd); - goto exception; - } + entry = editor->priv->entry; + html = gtkhtml_editor_get_html_mode (GTKHTML_EDITOR (editor)); - g_byte_array_free (text, TRUE); - close (fd); + if (editor->priv->signature == NULL) + signature = mail_config_signature_new (NULL, FALSE, html); + else { + signature = g_object_ref (editor->priv->signature); + signature->html = html; + } - if (g_rename (filename, editor->sig->filename) == -1) - goto exception; + filename = signature->filename; + gtkhtml_editor_save (GTKHTML_EDITOR (editor), filename, html, &error); - g_free (filename); + if (error != NULL) { + e_error_run ( + GTK_WINDOW (editor), + "mail:no-save-signature", + error->message, NULL); + g_clear_error (&error); + return; + } - editor->sig->html = editor->html; + signature_list = mail_config_get_signatures (); - name = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (editor->name_entry)))); + signature_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); + g_strstrip (signature_name); - if (g_str_equal(name, "") ) { - e_error_run ((GtkWindow *)editor->win, "mail:blank-signature", NULL); + /* Make sure the signature name is not blank. */ + if (*signature_name == '\0') { + e_error_run ( + GTK_WINDOW (editor), + "mail:blank-signature", NULL); + gtk_widget_grab_focus (entry); + g_free (signature_name); return; } - if ( (signature = (ESignature *)e_signature_list_find (mail_config_get_signatures (), E_SIGNATURE_FIND_NAME, name)) && !g_str_equal(signature->uid, editor->sig->uid) ) { - e_error_run ((GtkWindow *)editor->win, "mail:signature-already-exists", name, NULL); + /* Don't overwrite an existing signature of the same name. + * XXX ESignatureList misuses const. */ + same_name = (ESignature *) e_signature_list_find ( + signature_list, E_SIGNATURE_FIND_NAME, signature_name); + if (same_name != NULL && strcmp (signature->uid, same_name->uid) != 0) { + e_error_run ( + GTK_WINDOW (editor), + "mail:signature-already-exists", + signature_name, NULL); + gtk_widget_grab_focus (entry); + g_free (signature_name); return; } - if (editor->sig->name) - g_free (editor->sig->name); - - editor->sig->name = name; - - /* if the signature isn't already saved in the config, save it there now... */ - if (editor->is_new) { - mail_config_add_signature (editor->sig); - editor->is_new = FALSE; - } else { - e_signature_list_change (mail_config_get_signatures (), editor->sig); - } + g_free (signature->name); + signature->name = signature_name; - destroy_editor (editor); + if (editor->priv->signature != NULL) + e_signature_list_change (signature_list, signature); + else + mail_config_add_signature (signature); - return; - -exception: - menu_file_save_error (uic, &ev); - CORBA_exception_free (&ev); - g_unlink (filename); - g_free (filename); + gtk_widget_destroy (GTK_WIDGET (editor)); } -static void -exit_dialog_cb (int reply, ESignatureEditor *editor) -{ - switch (reply) { - case GTK_RESPONSE_YES: - menu_file_save_cb (NULL, editor, NULL); - break; - case GTK_RESPONSE_NO: - destroy_editor (editor); - break; - } -} +static GtkActionEntry entries[] = { + + { "close", + GTK_STOCK_CLOSE, + N_("_Close"), + "<Control>w", + NULL, + G_CALLBACK (action_close_cb) }, + + { "save-and-close", + GTK_STOCK_SAVE, + N_("_Save and Close"), + "<Control>Return", + NULL, + G_CALLBACK (action_save_and_close_cb) }, + + { "file-menu", + NULL, + N_("_File"), + NULL, + NULL, + NULL } +}; -static void -do_exit (ESignatureEditor *editor) +static gboolean +signature_editor_delete_event_cb (ESignatureEditor *editor, + GdkEvent *event) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - if (GNOME_GtkHTML_Editor_Engine_hasUndo (editor->engine, &ev) || GPOINTER_TO_INT( g_object_get_data( G_OBJECT(editor->win), "name-changed"))) { - int button; + GtkActionGroup *action_group; + GtkAction *action; - button = e_error_run((GtkWindow *)editor->win, "mail:ask-signature-changed", NULL); - exit_dialog_cb (button, editor); - } else - destroy_editor (editor); + action_group = editor->priv->action_group; + action = gtk_action_group_get_action (action_group, "close"); + gtk_action_activate (action); - CORBA_exception_free (&ev); + return TRUE; } -static int -delete_event_cb (GtkWidget *w, GdkEvent *event, ESignatureEditor *editor) +static void +signature_editor_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - do_exit (editor); + switch (property_id) { + case PROP_SIGNATURE: + e_signature_editor_set_signature ( + E_SIGNATURE_EDITOR (object), + g_value_get_object (value)); + return; + } - return TRUE; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -menu_file_close_cb (BonoboUIComponent *uic, gpointer data, const char *path) +signature_editor_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - ESignatureEditor *editor; + switch (property_id) { + case PROP_SIGNATURE: + g_value_set_object ( + value, e_signature_editor_get_signature ( + E_SIGNATURE_EDITOR (object))); + return; + } - editor = E_SIGNATURE_EDITOR (data); - do_exit (editor); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } static void -menu_file_save_close_cb (BonoboUIComponent *uic, gpointer data, const char *path) +signature_editor_dispose (GObject *object) { - ESignatureEditor *editor; + ESignatureEditorPrivate *priv; - editor = E_SIGNATURE_EDITOR (data); + priv = E_SIGNATURE_EDITOR_GET_PRIVATE (object); - menu_file_save_cb (uic, editor, path); -} + if (priv->action_group != NULL) { + g_object_unref (priv->action_group); + priv->action_group = NULL; + } -static BonoboUIVerb verbs [] = { + if (priv->signature != NULL) { + g_object_unref (priv->signature); + priv->signature = NULL; + } - BONOBO_UI_VERB ("FileSave", menu_file_save_cb), - BONOBO_UI_VERB ("FileClose", menu_file_close_cb), - BONOBO_UI_VERB ("FileSaveClose", menu_file_save_close_cb), + if (priv->entry != NULL) { + g_object_unref (priv->entry); + priv->entry = NULL; + } - BONOBO_UI_VERB_END -}; + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} static void -load_signature (ESignatureEditor *editor) +signature_editor_finalize (GObject *object) { - CORBA_Environment ev; + ESignatureEditorPrivate *priv; - if (editor->html) { - Bonobo_PersistFile pfile_iface; + priv = E_SIGNATURE_EDITOR_GET_PRIVATE (object); - CORBA_exception_init (&ev); - pfile_iface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (BONOBO_WIDGET (editor->control)),"IDL:Bonobo/PersistFile:1.0", &ev); - Bonobo_PersistFile_load (pfile_iface, editor->sig->filename, &ev); - CORBA_exception_free (&ev); - } else { - Bonobo_PersistStream pstream_iface; - BonoboStream *stream; - char *data, *html; + g_free (priv->original_name); - data = e_msg_composer_get_sig_file_content (editor->sig->filename, FALSE); - html = g_strdup_printf ("<PRE>\n%s", data); - g_free (data); - - CORBA_exception_init (&ev); - pstream_iface = Bonobo_Unknown_queryInterface - (bonobo_widget_get_objref (BONOBO_WIDGET (editor->control)), - "IDL:Bonobo/PersistStream:1.0",&ev); - stream = bonobo_stream_mem_create (html, strlen (html), TRUE, FALSE); - - if (stream == NULL) { - g_warning ("Couldn't create memory stream\n"); - } else { - BonoboObject *stream_object; - Bonobo_Stream corba_stream; - - stream_object = BONOBO_OBJECT (stream); - corba_stream = bonobo_object_corba_objref (stream_object); - Bonobo_PersistStream_load (pstream_iface, corba_stream, - "text/html", &ev); - } - - Bonobo_Unknown_unref (pstream_iface, &ev); - CORBA_Object_release (pstream_iface, &ev); - CORBA_exception_free (&ev); - bonobo_object_unref (BONOBO_OBJECT (stream)); - - g_free (html); - } + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); } static void -sig_name_changed (GtkWidget *w, ESignatureEditor *editor) +signature_editor_class_init (ESignatureEditorClass *class) { - g_object_set_data ( G_OBJECT(editor->win), "name-changed", GINT_TO_POINTER(1)); + GObjectClass *object_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (ESignatureEditorPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = signature_editor_set_property; + object_class->get_property = signature_editor_get_property; + object_class->dispose = signature_editor_dispose; + object_class->finalize = signature_editor_finalize; + + g_object_class_install_property ( + object_class, + PROP_SIGNATURE, + g_param_spec_object ( + "signature", + NULL, + NULL, + E_TYPE_SIGNATURE, + G_PARAM_READWRITE)); } static void -format_html_cb (BonoboUIComponent *component, - const char *path, - Bonobo_UIComponent_EventType type, - const char *state, - gpointer data) +signature_editor_init (ESignatureEditor *editor) +{ + GtkActionGroup *action_group; + GtkUIManager *manager; + GtkWidget *container; + GtkWidget *widget; + GtkWidget *vbox; + GError *error = NULL; + + editor->priv = E_SIGNATURE_EDITOR_GET_PRIVATE (editor); + vbox = GTKHTML_EDITOR (editor)->vbox; + + manager = gtkhtml_editor_get_ui_manager (GTKHTML_EDITOR (editor)); + + gtk_ui_manager_add_ui_from_string (manager, ui, -1, &error); + handle_error (&error); + + action_group = gtk_action_group_new ("signature"); + gtk_action_group_set_translation_domain ( + action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions ( + action_group, entries, + G_N_ELEMENTS (entries), editor); + gtk_ui_manager_insert_action_group (manager, action_group, 0); + editor->priv->action_group = g_object_ref (action_group); + + gtk_ui_manager_ensure_update (manager); + + gtk_window_set_title (GTK_WINDOW (editor), _("Edit Signature")); + + widget = gtk_hbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (widget), 6); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + /* Position 2 should be between the main and style toolbars. */ + gtk_box_reorder_child (GTK_BOX (vbox), widget, 2); + gtk_widget_show (widget); + container = widget; + + widget = gtk_entry_new (); + gtk_box_pack_end (GTK_BOX (container), widget, TRUE, TRUE, 0); + editor->priv->entry = g_object_ref_sink (widget); + gtk_widget_show (widget); + + widget = gtk_label_new_with_mnemonic (_("_Signature Name:")); + gtk_label_set_mnemonic_widget (GTK_LABEL (widget), editor->priv->entry); + gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + g_signal_connect ( + editor, "delete-event", + G_CALLBACK (signature_editor_delete_event_cb), NULL); + + e_signature_editor_set_signature (editor, NULL); +} +GType +e_signature_editor_get_type (void) { - ESignatureEditor *editor = (ESignatureEditor *) data; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (ESignatureEditorClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) signature_editor_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (ESignatureEditor), + 0, /* n_preallocs */ + (GInstanceInitFunc) signature_editor_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTKHTML_TYPE_EDITOR, "ESignatureEditor", + &type_info, 0); + } - if (type != Bonobo_UIComponent_STATE_CHANGED) - return; + return type; +} - editor->html = atoi (state); - bonobo_widget_set_property (BONOBO_WIDGET (editor->control), "FormatHTML", TC_CORBA_boolean, editor->html, NULL); +GtkWidget * +e_signature_editor_new (void) +{ + return g_object_new (E_TYPE_SIGNATURE_EDITOR, NULL); +} + +ESignature * +e_signature_editor_get_signature (ESignatureEditor *editor) +{ + g_return_val_if_fail (E_IS_SIGNATURE_EDITOR (editor), NULL); + + return editor->priv->signature; } void -mail_signature_editor (ESignature *sig, GtkWindow *parent, gboolean is_new) +e_signature_editor_set_signature (ESignatureEditor *editor, + ESignature *signature) { - CORBA_Environment ev; - ESignatureEditor *editor; - BonoboUIComponent *component; - BonoboUIContainer *container; - GtkWidget *vbox, *hbox, *label, *frame, *vbox1; - char *xmlfile; - - if (!sig->filename || !*sig->filename) - return; + const gchar *filename; + const gchar *signature_name; + gchar *contents; + gsize length; + GError *error = NULL; - editor = g_new0 (ESignatureEditor, 1); + g_return_if_fail (E_IS_SIGNATURE_EDITOR (editor)); - editor->sig = sig; - editor->html = sig->html; - editor->is_new = is_new; + if (signature != NULL) + g_return_if_fail (E_SIGNATURE (signature)); - editor->win = bonobo_window_new ("e-sig-editor", _("Edit signature")); - gtk_window_set_type_hint (GTK_WINDOW (editor->win), GDK_WINDOW_TYPE_HINT_DIALOG); - gtk_window_set_default_size (GTK_WINDOW (editor->win), DEFAULT_WIDTH, DEFAULT_HEIGHT); - if (parent != NULL) - gtk_window_set_transient_for (GTK_WINDOW (editor->win), parent); - g_object_set (editor->win, "allow_shrink", FALSE, "allow_grow", TRUE, NULL); + if (editor->priv->signature != NULL) { + g_object_unref (editor->priv->signature); + editor->priv->signature = NULL; + } - g_object_set_data (G_OBJECT(editor->win), "name-changed", GINT_TO_POINTER(0)); + if (signature == NULL) + goto exit; - container = bonobo_window_get_ui_container (BONOBO_WINDOW(editor->win)); + editor->priv->signature = g_object_ref (signature); - component = bonobo_ui_component_new_default (); - bonobo_ui_component_set_container (component, bonobo_object_corba_objref (BONOBO_OBJECT (container)), NULL); - bonobo_ui_component_add_verb_list_with_data (component, verbs, editor); + /* Load signature content. */ - xmlfile = g_build_filename (EVOLUTION_UIDIR, - "evolution-signature-editor.xml", - NULL); - bonobo_ui_util_set_ui (component, PREFIX, - xmlfile, - "evolution-signature-editor", NULL); - g_free (xmlfile); + filename = signature->filename; - editor->control = bonobo_widget_new_control (GNOME_GTKHTML_EDITOR_CONTROL_ID, - bonobo_ui_component_get_container (component)); + if (signature->html) + g_file_get_contents (filename, &contents, &length, &error); + else { + gchar *data; - if (editor->control == NULL) { - g_warning ("Cannot get '" GNOME_GTKHTML_EDITOR_CONTROL_ID "'."); + data = e_msg_composer_get_sig_file_content (filename, FALSE); + contents = g_strdup_printf ("<PRE>\n%s", data); + length = -1; + g_free (data); + } - destroy_editor (editor); - return; + if (error == NULL) { + gtkhtml_editor_set_html_mode ( + GTKHTML_EDITOR (editor), signature->html); + gtkhtml_editor_set_text_html ( + GTKHTML_EDITOR (editor), contents, length); + g_free (contents); + } else { + g_warning ("%s", error->message); + g_error_free (error); } - editor->engine = (GNOME_GtkHTML_Editor_Engine) Bonobo_Unknown_queryInterface - (bonobo_widget_get_objref (BONOBO_WIDGET (editor->control)), "IDL:GNOME/GtkHTML/Editor/Engine:1.0", &ev); - CORBA_exception_free(&ev); - load_signature (editor); - - bonobo_ui_component_set_prop (component, "/commands/FormatHtml", "state", editor->html ? "1" : "0", NULL); - bonobo_ui_component_add_listener (component, "FormatHtml", format_html_cb, editor); - - g_signal_connect (editor->win, "delete_event", G_CALLBACK (delete_event_cb), editor); - - vbox = gtk_vbox_new (FALSE, 0); - hbox = gtk_hbox_new (FALSE, 4); - vbox1 = gtk_vbox_new (FALSE, 3); - gtk_container_set_border_width (GTK_CONTAINER (vbox1), 3); - label = gtk_label_new (_("Enter a name for this signature.")); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0); - gtk_box_pack_start (GTK_BOX (vbox1), label, FALSE, TRUE, 0); - label = gtk_label_new (_("Name:")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); - editor->name_entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (editor->name_entry), sig->name); - g_signal_connect (editor->name_entry, "changed", G_CALLBACK (sig_name_changed), editor); - gtk_box_pack_start_defaults (GTK_BOX (hbox), editor->name_entry); - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox1); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); - gtk_widget_show_all (vbox); - gtk_box_pack_start_defaults (GTK_BOX (vbox), editor->control); - - bonobo_window_set_contents (BONOBO_WINDOW (editor->win), vbox); - bonobo_widget_set_property (BONOBO_WIDGET (editor->control), "FormatHTML", TC_CORBA_boolean, editor->html, NULL); - gtk_widget_show (GTK_WIDGET (editor->win)); - gtk_widget_show (GTK_WIDGET (editor->control)); - - if (is_new) - gtk_widget_grab_focus (editor->name_entry); +exit: + if (signature != NULL) + signature_name = signature->name; + else + signature_name = _("Unnamed"); + + /* Set the entry text before we grab focus. */ + g_free (editor->priv->original_name); + editor->priv->original_name = g_strdup (signature_name); + gtk_entry_set_text (GTK_ENTRY (editor->priv->entry), signature_name); + + /* Set the focus appropriately. If this is a new signature, draw + * the user's attention to the signature name entry. Otherwise go + * straight to the editing area. */ + if (signature == NULL) + gtk_widget_grab_focus (editor->priv->entry); else { - CORBA_exception_init (&ev); - GNOME_GtkHTML_Editor_Engine_runCommand (editor->engine, "grab-focus", &ev); - CORBA_exception_free (&ev); + GtkHTML *html; + + html = gtkhtml_editor_get_html (GTKHTML_EDITOR (editor)); + gtk_widget_grab_focus (GTK_WIDGET (html)); } + + g_object_notify (G_OBJECT (editor), "signature"); } diff --git a/mail/mail-signature-editor.h b/mail/mail-signature-editor.h index 30175a7701..8ce8725b7a 100644 --- a/mail/mail-signature-editor.h +++ b/mail/mail-signature-editor.h @@ -24,18 +24,49 @@ #ifndef MAIL_SIGNATURE_EDITOR_H #define MAIL_SIGNATURE_EDITOR_H -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ +#include <gtkhtml-editor.h> +#include <e-util/e-signature.h> -struct _ESignature; -struct _GtkWindow; +/* Standard GObject macros */ +#define E_TYPE_SIGNATURE_EDITOR \ + (e_signature_editor_get_type ()) +#define E_SIGNATURE_EDITOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_SIGNATURE_EDITOR, ESignatureEditor)) +#define E_SIGNATURE_EDITOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_SIGNATURE_EDITOR, ESignatureEditorClass)) +#define E_IS_SIGNATURE_EDITOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_SIGNATURE_EDITOR)) +#define E_IS_SIGNATURE_EDITOR_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_SIGNATURE_EDITOR)) +#define E_SIGNATURE_EDITOR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_SIGNATURE_EDITOR, ESignatureEditorClass)) -void mail_signature_editor (struct _ESignature *sig, struct _GtkWindow *parent, int is_new); +G_BEGIN_DECLS -#ifdef __cplusplus -} -#endif /* __cplusplus */ +typedef struct _ESignatureEditor ESignatureEditor; +typedef struct _ESignatureEditorClass ESignatureEditorClass; +typedef struct _ESignatureEditorPrivate ESignatureEditorPrivate; -#endif +struct _ESignatureEditor { + GtkhtmlEditor parent; + ESignatureEditorPrivate *priv; +}; + +struct _ESignatureEditorClass { + GtkhtmlEditorClass parent_class; +}; + +GType e_signature_editor_get_type (void); +GtkWidget * e_signature_editor_new (void); +ESignature * e_signature_editor_get_signature (ESignatureEditor *editor); +void e_signature_editor_set_signature (ESignatureEditor *editor, + ESignature *signature); + +G_END_DECLS + +#endif /* MAIL_SIGNATURE_EDITOR_H */ |