diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-08-14 08:49:46 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-08-14 08:56:33 +0800 |
commit | 6cb0cbd0be5791aa0af1f78ce44c7a6563611d8f (patch) | |
tree | 8ac6832a905017845b3095112b83bb14da112617 /composer/e-msg-composer.c | |
parent | caed9460b2d518005abe34035d5b414ff07c0212 (diff) | |
download | gsoc2013-evolution-6cb0cbd0be5791aa0af1f78ce44c7a6563611d8f.tar.gz gsoc2013-evolution-6cb0cbd0be5791aa0af1f78ce44c7a6563611d8f.tar.zst gsoc2013-evolution-6cb0cbd0be5791aa0af1f78ce44c7a6563611d8f.zip |
Pass an EShell to EMsgComposer instances.
Reduce the composer's dependency on e_shell_get_default().
Diffstat (limited to 'composer/e-msg-composer.c')
-rw-r--r-- | composer/e-msg-composer.c | 281 |
1 files changed, 173 insertions, 108 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index e56bab9362..4a6c6b267f 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -75,7 +75,8 @@ enum { PROP_0, - PROP_FOCUS_TRACKER + PROP_FOCUS_TRACKER, + PROP_SHELL }; enum { @@ -1272,19 +1273,19 @@ is_top_signature (EMsgComposer *composer) if (priv->is_from_message) return FALSE; - shell = e_shell_get_default (); + shell = e_msg_composer_get_shell (composer); shell_settings = e_shell_get_shell_settings (shell); return e_shell_settings_get_boolean (shell_settings, "composer-top-signature"); } static gboolean -add_signature_delim (void) +add_signature_delim (EMsgComposer *composer) { EShell *shell; EShellSettings *shell_settings; - shell = e_shell_get_default (); + shell = e_msg_composer_get_shell (composer); shell_settings = e_shell_get_shell_settings (shell); return !e_shell_settings_get_boolean (shell_settings, "composer-no-signature-delim"); @@ -1313,7 +1314,7 @@ get_signature_html (EMsgComposer *composer) if (!signature) return NULL; - add_delim = add_signature_delim (); + add_delim = add_signature_delim (composer); if (!e_signature_get_autogenerated (signature)) { const gchar *filename; @@ -1468,12 +1469,14 @@ autosave_load_draft_cb (EMsgComposer *composer, } static EMsgComposer * -autosave_load_draft (const gchar *filename) +autosave_load_draft (EShell *shell, + const gchar *filename) { CamelStream *stream; - CamelMimeMessage *msg; + CamelMimeMessage *message; EMsgComposer *composer; + g_return_val_if_fail (E_IS_SHELL (shell), NULL); g_return_val_if_fail (filename != NULL, NULL); stream = camel_stream_fs_new_with_name ( @@ -1481,12 +1484,12 @@ autosave_load_draft (const gchar *filename) if (stream == NULL) return NULL; - msg = camel_mime_message_new (); + message = camel_mime_message_new (); camel_data_wrapper_construct_from_stream ( - CAMEL_DATA_WRAPPER (msg), stream, NULL); + CAMEL_DATA_WRAPPER (message), stream, NULL); g_object_unref (stream); - composer = e_msg_composer_new_with_message (msg); + composer = e_msg_composer_new_with_message (shell, message); if (composer) { /* Mark the message as changed so it gets autosaved again, * then we can safely remove the old autosave file in the @@ -1708,61 +1711,18 @@ msg_composer_notify_header_cb (EMsgComposer *composer) gtkhtml_editor_set_changed (editor, TRUE); } -static void -msg_composer_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) { - case PROP_FOCUS_TRACKER: - g_value_set_object ( - value, e_msg_composer_get_focus_tracker ( - E_MSG_COMPOSER (object))); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -msg_composer_dispose (GObject *object) -{ - EMsgComposer *composer = E_MSG_COMPOSER (object); - - e_composer_private_dispose (composer); - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -static void -msg_composer_finalize (GObject *object) -{ - EMsgComposer *composer = E_MSG_COMPOSER (object); - - e_composer_autosave_unregister (composer); - e_composer_private_finalize (composer); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); -} - static gboolean -msg_composer_delete_event_cb (GtkWidget *widget, gpointer user_data) +msg_composer_delete_event_cb (EMsgComposer *composer) { EShell *shell; - shell = e_shell_get_default (); + shell = e_msg_composer_get_shell (composer); if (g_list_length (e_shell_get_watched_windows (shell)) == 1) { /* This is the last watched window, use the quit * mechanism to have a draft saved properly */ e_shell_quit (shell, E_SHELL_QUIT_ACTION); } else { - /* This is needed for the ACTION macro. */ - EMsgComposer *composer = E_MSG_COMPOSER (widget); - /* There are more watched windows opened, * invoke only a close action */ gtk_action_activate (ACTION (CLOSE)); @@ -1792,10 +1752,6 @@ msg_composer_quit_requested_cb (EShell *shell, EMsgComposer *composer) { if (e_msg_composer_is_exiting (composer)) { - EShell *shell; - - shell = e_shell_get_default (); - g_signal_handlers_disconnect_by_func ( shell, msg_composer_quit_requested_cb, composer); g_signal_handlers_disconnect_by_func ( @@ -1807,6 +1763,82 @@ msg_composer_quit_requested_cb (EShell *shell, } static void +msg_composer_set_shell (EMsgComposer *composer, + EShell *shell) +{ + g_return_if_fail (E_IS_SHELL (shell)); + g_return_if_fail (composer->priv->shell == NULL); + + composer->priv->shell = shell; + + g_object_add_weak_pointer ( + G_OBJECT (shell), &composer->priv->shell); +} + +static void +msg_composer_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_SHELL: + msg_composer_set_shell ( + E_MSG_COMPOSER (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +msg_composer_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_FOCUS_TRACKER: + g_value_set_object ( + value, e_msg_composer_get_focus_tracker ( + E_MSG_COMPOSER (object))); + return; + + case PROP_SHELL: + g_value_set_object ( + value, e_msg_composer_get_shell ( + E_MSG_COMPOSER (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +msg_composer_dispose (GObject *object) +{ + EMsgComposer *composer = E_MSG_COMPOSER (object); + + e_composer_private_dispose (composer); + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +msg_composer_finalize (GObject *object) +{ + EMsgComposer *composer = E_MSG_COMPOSER (object); + + e_composer_autosave_unregister (composer); + e_composer_private_finalize (composer); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void msg_composer_constructed (GObject *object) { EShell *shell; @@ -1827,9 +1859,14 @@ msg_composer_constructed (GObject *object) editor = GTKHTML_EDITOR (object); composer = E_MSG_COMPOSER (object); - shell = e_shell_get_default (); + shell = e_msg_composer_get_shell (composer); shell_settings = e_shell_get_shell_settings (shell); + if (e_shell_get_express_mode (shell)) { + GtkWindow *parent = e_shell_get_active_window (shell); + gtk_window_set_transient_for (GTK_WINDOW (composer), parent); + } + e_composer_private_constructed (composer); html = gtkhtml_editor_get_html (editor); @@ -1840,16 +1877,19 @@ msg_composer_constructed (GObject *object) gtk_window_set_title (GTK_WINDOW (composer), _("Compose Message")); gtk_window_set_icon_name (GTK_WINDOW (composer), "mail-message-new"); - g_signal_connect (object, "delete-event", + g_signal_connect ( + object, "delete-event", G_CALLBACK (msg_composer_delete_event_cb), NULL); e_shell_adapt_window_size (shell, GTK_WINDOW (composer)); e_shell_watch_window (shell, GTK_WINDOW (object)); - g_signal_connect (shell, "quit-requested", + g_signal_connect ( + shell, "quit-requested", G_CALLBACK (msg_composer_quit_requested_cb), composer); - g_signal_connect (shell, "prepare-for-quit", + g_signal_connect ( + shell, "prepare-for-quit", G_CALLBACK (msg_composer_prepare_for_quit_cb), composer); /* Restore Persistent State */ @@ -1962,6 +2002,7 @@ msg_composer_destroy (GtkObject *object) composer->priv->address_dialog = NULL; } + /* FIXME Our EShell is already unreferenced. */ shell = e_shell_get_default (); g_signal_handlers_disconnect_by_func ( @@ -2238,6 +2279,7 @@ msg_composer_class_init (EMsgComposerClass *class) g_type_class_add_private (class, sizeof (EMsgComposerPrivate)); object_class = G_OBJECT_CLASS (class); + object_class->set_property = msg_composer_set_property; object_class->get_property = msg_composer_get_property; object_class->dispose = msg_composer_dispose; object_class->finalize = msg_composer_finalize; @@ -2271,6 +2313,17 @@ msg_composer_class_init (EMsgComposerClass *class) E_TYPE_FOCUS_TRACKER, G_PARAM_READABLE)); + g_object_class_install_property ( + object_class, + PROP_SHELL, + g_param_spec_object ( + "shell", + "Shell", + "The EShell singleton", + E_TYPE_SHELL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + signals[SEND] = g_signal_new ( "send", G_OBJECT_CLASS_TYPE (class), @@ -2300,14 +2353,7 @@ msg_composer_class_init (EMsgComposerClass *class) static void msg_composer_init (EMsgComposer *composer) { - EShell *shell = e_shell_get_default (); - composer->priv = E_MSG_COMPOSER_GET_PRIVATE (composer); - - if (e_shell_get_express_mode (shell)) { - GtkWindow *window = e_shell_get_active_window(shell); - gtk_window_set_transient_for (GTK_WINDOW(composer), window); - } } GType @@ -2340,34 +2386,20 @@ e_msg_composer_get_type (void) /** * e_msg_composer_new: + * @shell: an #EShell * * Create a new message composer widget. * * Returns: A pointer to the newly created widget **/ EMsgComposer * -e_msg_composer_new (void) +e_msg_composer_new (EShell *shell) { + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + return g_object_new ( E_TYPE_MSG_COMPOSER, - "html", e_web_view_new (), NULL); -} - -/** - * e_msg_composer_get_lite: - * - * Used within the composer to see if it should be made suitable for small - * screens. - * - * Return value: whether the surrounding #EShell is in small screen mode. - */ -gboolean -e_msg_composer_get_lite (void) -{ - EShell *shell; - - shell = e_shell_get_default (); - return e_shell_get_small_screen_mode (shell); + "html", e_web_view_new (), "shell", shell, NULL); } EFocusTracker * @@ -2823,6 +2855,7 @@ set_signature_gui (EMsgComposer *composer) /** * e_msg_composer_new_with_message: + * @shell: an #EShell * @message: The message to use as the source * * Create a new message composer widget. @@ -2832,7 +2865,8 @@ set_signature_gui (EMsgComposer *composer) * Returns: A pointer to the newly created widget **/ EMsgComposer * -e_msg_composer_new_with_message (CamelMimeMessage *message) +e_msg_composer_new_with_message (EShell *shell, + CamelMimeMessage *message) { CamelInternetAddress *to, *cc, *bcc; GList *To = NULL, *Cc = NULL, *Bcc = NULL, *postto = NULL; @@ -2851,12 +2885,14 @@ e_msg_composer_new_with_message (CamelMimeMessage *message) struct _camel_header_raw *xev; gint len, i; + g_return_val_if_fail (E_IS_SHELL (shell), NULL); + for (headers = CAMEL_MIME_PART (message)->headers;headers;headers = headers->next) { if (!strcmp (headers->name, "X-Evolution-PostTo")) postto = g_list_append (postto, g_strstrip (g_strdup (headers->value))); } - composer = e_msg_composer_new (); + composer = e_msg_composer_new (shell); priv = E_MSG_COMPOSER_GET_PRIVATE (composer); table = e_msg_composer_get_header_table (composer); @@ -3154,6 +3190,7 @@ disable_editor (EMsgComposer *composer) /** * e_msg_composer_new_redirect: + * @shell: an #EShell * @message: The message to use as the source * * Create a new message composer widget. @@ -3161,16 +3198,18 @@ disable_editor (EMsgComposer *composer) * Returns: A pointer to the newly created widget **/ EMsgComposer * -e_msg_composer_new_redirect (CamelMimeMessage *message, +e_msg_composer_new_redirect (EShell *shell, + CamelMimeMessage *message, const gchar *resent_from) { EMsgComposer *composer; EComposerHeaderTable *table; const gchar *subject; + g_return_val_if_fail (E_IS_SHELL (shell), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); - composer = e_msg_composer_new_with_message (message); + composer = e_msg_composer_new_with_message (shell, message); table = e_msg_composer_get_header_table (composer); subject = camel_mime_message_get_subject (message); @@ -3202,11 +3241,9 @@ e_msg_composer_get_session (EMsgComposer *composer) EShellSettings *shell_settings; CamelSession *session; - /* FIXME EMsgComposer should own a reference to EShell. */ - g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); - shell = e_shell_get_default (); + shell = e_msg_composer_get_shell (composer); shell_settings = e_shell_get_shell_settings (shell); session = e_shell_settings_get_pointer (shell_settings, "mail-session"); @@ -3216,6 +3253,22 @@ e_msg_composer_get_session (EMsgComposer *composer) } /** + * e_msg_composer_get_shell: + * @composer: an #EMsgComposer + * + * Returns the #EShell that was passed to e_msg_composer_new(). + * + * Returns: the #EShell + **/ +EShell * +e_msg_composer_get_shell (EMsgComposer *composer) +{ + g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); + + return E_SHELL (composer->priv->shell); +} + +/** * e_msg_composer_send: * @composer: an #EMsgComposer * @@ -3443,21 +3496,22 @@ handle_mailto (EMsgComposer *composer, const gchar *mailto) /** * e_msg_composer_new_from_url: + * @shell: an #EShell * @url: a mailto URL * * Create a new message composer widget, and fill in fields as * defined by the provided URL. **/ EMsgComposer * -e_msg_composer_new_from_url (const gchar *url) +e_msg_composer_new_from_url (EShell *shell, + const gchar *url) { EMsgComposer *composer; + g_return_val_if_fail (E_IS_SHELL (shell), NULL); g_return_val_if_fail (g_ascii_strncasecmp (url, "mailto:", 7) == 0, NULL); - composer = e_msg_composer_new (); - if (!composer) - return NULL; + composer = e_msg_composer_new (shell); handle_mailto (composer, url); @@ -3815,12 +3869,15 @@ CamelMimeMessage * e_msg_composer_get_message_print (EMsgComposer *composer, gboolean save_html_object_data) { + EShell *shell; GtkhtmlEditor *editor; EMsgComposer *temp_composer; CamelMimeMessage *msg; gboolean html_content; gchar *flags; + g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); + editor = GTKHTML_EDITOR (composer); html_content = gtkhtml_editor_get_html_mode (editor); @@ -3828,7 +3885,8 @@ e_msg_composer_get_message_print (EMsgComposer *composer, if (msg == NULL) return NULL; - temp_composer = e_msg_composer_new_with_message (msg); + shell = e_msg_composer_get_shell (composer); + temp_composer = e_msg_composer_new_with_message (shell, msg); g_object_unref (msg); /* Override composer flags. */ @@ -4140,12 +4198,14 @@ e_msg_composer_can_close (EMsgComposer *composer, } EMsgComposer * -e_msg_composer_load_from_file (const gchar *filename) +e_msg_composer_load_from_file (EShell *shell, + const gchar *filename) { CamelStream *stream; - CamelMimeMessage *msg; + CamelMimeMessage *message; EMsgComposer *composer; + g_return_val_if_fail (E_IS_SHELL (shell), NULL); g_return_val_if_fail (filename != NULL, NULL); stream = camel_stream_fs_new_with_name ( @@ -4153,12 +4213,12 @@ e_msg_composer_load_from_file (const gchar *filename) if (stream == NULL) return NULL; - msg = camel_mime_message_new (); + message = camel_mime_message_new (); camel_data_wrapper_construct_from_stream ( - CAMEL_DATA_WRAPPER (msg), stream, NULL); + CAMEL_DATA_WRAPPER (message), stream, NULL); g_object_unref (stream); - composer = e_msg_composer_new_with_message (msg); + composer = e_msg_composer_new_with_message (shell, message); if (composer != NULL) gtk_widget_show (GTK_WIDGET (composer)); @@ -4166,12 +4226,17 @@ e_msg_composer_load_from_file (const gchar *filename) } void -e_msg_composer_check_autosave (GtkWindow *parent) +e_msg_composer_check_autosave (EShell *shell) { + GtkWindow *parent; GList *orphans = NULL; gint response; GError *error = NULL; + g_return_if_fail (E_IS_SHELL (shell)); + + parent = e_shell_get_active_window (shell); + /* Look for orphaned autosave files. */ orphans = e_composer_autosave_find_orphans (&error); if (orphans == NULL) { @@ -4193,7 +4258,7 @@ e_msg_composer_check_autosave (GtkWindow *parent) if (response == GTK_RESPONSE_YES) { /* FIXME: composer is never used */ - composer = autosave_load_draft (filename); + composer = autosave_load_draft (shell, filename); } else { g_unlink (filename); } |