diff options
author | Matthew Barnes <mbarnes@src.gnome.org> | 2009-01-08 02:23:46 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2009-01-08 02:23:46 +0800 |
commit | 8d8e4ac1c23905892a42b779188c852fdead7f5f (patch) | |
tree | 01609ceef7151d75f81fdc8762ac6c25215e8a51 /mail | |
parent | 13a0edc3d27cce65a0f720e98516f7ab902ad0fc (diff) | |
download | gsoc2013-evolution-8d8e4ac1c23905892a42b779188c852fdead7f5f.tar.gz gsoc2013-evolution-8d8e4ac1c23905892a42b779188c852fdead7f5f.tar.zst gsoc2013-evolution-8d8e4ac1c23905892a42b779188c852fdead7f5f.zip |
Tweak the EShell API.
Disable File -> Close Window when there's only one window.
Replace EMMessageBrowser with EMailBrowser.
svn path=/branches/kill-bonobo/; revision=37009
Diffstat (limited to 'mail')
-rw-r--r-- | mail/Makefile.am | 4 | ||||
-rw-r--r-- | mail/e-mail-browser.c | 100 | ||||
-rw-r--r-- | mail/e-mail-browser.h | 1 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 193 | ||||
-rw-r--r-- | mail/e-mail-reader.h | 8 | ||||
-rw-r--r-- | mail/e-mail-shell-module-settings.c | 2 | ||||
-rw-r--r-- | mail/e-mail-shell-module.c | 9 | ||||
-rw-r--r-- | mail/em-account-editor.c | 2 | ||||
-rw-r--r-- | mail/em-composer-prefs.c | 2 | ||||
-rw-r--r-- | mail/em-folder-view.c | 5 | ||||
-rw-r--r-- | mail/em-format-html.c | 1 | ||||
-rw-r--r-- | mail/em-mailer-prefs.c | 2 | ||||
-rw-r--r-- | mail/em-message-browser.c | 397 | ||||
-rw-r--r-- | mail/em-message-browser.h | 74 |
14 files changed, 313 insertions, 487 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am index e0e1e5982e..1ce0ae79ad 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -121,8 +121,6 @@ libevolution_module_mail_la_SOURCES = \ em-mailer-prefs.h \ em-menu.c \ em-menu.h \ - em-message-browser.c \ - em-message-browser.h \ em-network-prefs.c \ em-network-prefs.h \ em-popup.c \ @@ -205,7 +203,6 @@ libevolution_module_mail_la_LIBADD = \ # em-inline-filter.h \ # em-junk-hook.h \ # em-menu.h \ -# em-message-browser.h \ # em-popup.h \ # em-stripsig-filter.h \ # em-sync-stream.h \ @@ -269,7 +266,6 @@ libevolution_module_mail_la_LIBADD = \ # em-inline-filter.c \ # em-junk-hook.c \ # em-menu.c \ -# em-message-browser.c \ # em-migrate.c \ # em-migrate.h \ # em-popup.c \ diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c index 13647c1f62..e6c1072304 100644 --- a/mail/e-mail-browser.c +++ b/mail/e-mail-browser.c @@ -29,6 +29,7 @@ #include "e-util/gconf-bridge.h" #include "mail/e-mail-reader.h" +#include "mail/e-mail-reader-utils.h" #include "mail/e-mail-shell-module.h" #include "mail/em-folder-tree-model.h" #include "mail/em-format-html-display.h" @@ -78,7 +79,7 @@ static void action_close_cb (GtkAction *action, EMailBrowser *browser) { - gtk_widget_destroy (GTK_WIDGET (browser)); + e_mail_browser_close (browser); } static GtkActionEntry mail_browser_entries[] = { @@ -187,6 +188,35 @@ mail_browser_connect_proxy_cb (EMailBrowser *browser, } static void +mail_browser_message_selected_cb (EMailBrowser *browser, + const gchar *uid) +{ + EMFormatHTMLDisplay *html_display; + MessageList *message_list; + CamelMessageInfo *info; + EMailReader *reader; + + if (uid == NULL) + return; + + reader = E_MAIL_READER (browser); + html_display = e_mail_reader_get_html_display (reader); + message_list = e_mail_reader_get_message_list (reader); + info = camel_folder_get_message_info (message_list->folder, uid); + + if (info == NULL) + return; + + gtk_window_set_title ( + GTK_WINDOW (browser), + camel_message_info_subject (info)); + gtk_widget_grab_focus ( + GTK_WIDGET (((EMFormatHTML *) html_display)->html)); + + camel_folder_free_message_info (message_list->folder, info); +} + +static void mail_browser_set_shell_module (EMailBrowser *browser, EShellModule *shell_module) { @@ -367,6 +397,20 @@ mail_browser_constructed (GObject *object) gtk_widget_show (widget); } +static gboolean +mail_browser_key_press_event (GtkWidget *widget, + GdkEventKey *event) +{ + if (event->keyval == GDK_Escape) { + e_mail_browser_close (E_MAIL_BROWSER (widget)); + return TRUE; + } + + /* Chain up to parent's key_press_event() method. */ + return GTK_WIDGET_CLASS (parent_class)-> + key_press_event (widget, event); +} + static GtkActionGroup * mail_browser_get_action_group (EMailReader *reader) { @@ -419,9 +463,45 @@ mail_browser_get_window (EMailReader *reader) } static void +mail_browser_set_message (EMailReader *reader, + const gchar *uid, + gboolean mark_read) +{ + EMailReaderIface *iface; + MessageList *message_list; + CamelMessageInfo *info; + CamelFolder *folder; + + /* Chain up to parent's set_message() method. */ + iface = g_type_default_interface_peek (E_TYPE_MAIL_READER); + iface->set_message (reader, uid, mark_read); + + if (uid == NULL) { + e_mail_browser_close (E_MAIL_BROWSER (reader)); + return; + } + + message_list = e_mail_reader_get_message_list (reader); + + folder = message_list->folder; + info = camel_folder_get_message_info (folder, uid); + + if (info != NULL) { + gtk_window_set_title ( + GTK_WINDOW (reader), + camel_message_info_subject (info)); + camel_folder_free_message_info (folder, info); + } + + if (mark_read) + e_mail_reader_mark_as_read (reader, uid); +} + +static void mail_browser_class_init (EMailBrowserClass *class) { GObjectClass *object_class; + GtkWidgetClass *widget_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EMailBrowserPrivate)); @@ -432,6 +512,9 @@ mail_browser_class_init (EMailBrowserClass *class) object_class->dispose = mail_browser_dispose; object_class->constructed = mail_browser_constructed; + widget_class = GTK_WIDGET_CLASS (class); + widget_class->key_press_event = mail_browser_key_press_event; + g_object_class_install_property ( object_class, PROP_SHELL_MODULE, @@ -453,6 +536,7 @@ mail_browser_iface_init (EMailReaderIface *iface) iface->get_message_list = mail_browser_get_message_list; iface->get_shell_module = mail_browser_get_shell_module; iface->get_window = mail_browser_get_window; + iface->set_message = mail_browser_set_message; } static void @@ -473,9 +557,15 @@ mail_browser_init (EMailBrowser *browser) browser->priv->message_list = message_list_new (); g_object_ref_sink (browser->priv->message_list); + g_signal_connect_swapped ( + browser->priv->message_list, "message-selected", + G_CALLBACK (mail_browser_message_selected_cb), browser); + bridge = gconf_bridge_get (); prefix = "/apps/evolution/mail/mail_browser"; gconf_bridge_bind_window_size (bridge, prefix, GTK_WINDOW (browser)); + + gtk_window_set_title (GTK_WINDOW (browser), _("Evolution")); } GType @@ -523,6 +613,14 @@ e_mail_browser_new (EShellModule *shell_module) "shell-module", shell_module, NULL); } +void +e_mail_browser_close (EMailBrowser *browser) +{ + g_return_if_fail (E_IS_MAIL_BROWSER (browser)); + + gtk_widget_destroy (GTK_WIDGET (browser)); +} + GtkUIManager * e_mail_browser_get_ui_manager (EMailBrowser *browser) { diff --git a/mail/e-mail-browser.h b/mail/e-mail-browser.h index 5bac3896a8..35040f0ab0 100644 --- a/mail/e-mail-browser.h +++ b/mail/e-mail-browser.h @@ -61,6 +61,7 @@ struct _EMailBrowserClass { GType e_mail_browser_get_type (void); GtkWidget * e_mail_browser_new (EShellModule *shell_module); +void e_mail_browser_close (EMailBrowser *browser); GtkUIManager * e_mail_browser_get_ui_manager (EMailBrowser *browser); G_END_DECLS diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index 4c09f96c55..93279c2bfe 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -24,6 +24,7 @@ #include <glib/gi18n.h> #include <gdk/gdkkeysyms.h> #include <gtkhtml/gtkhtml.h> +#include <gtkhtml/gtkhtml-stream.h> #ifdef HAVE_XFREE #include <X11/XF86keysym.h> @@ -31,11 +32,13 @@ #include "e-util/e-util.h" #include "e-util/gconf-bridge.h" +#include "shell/e-shell.h" #include "widgets/misc/e-charset-picker.h" #include "mail/e-mail-reader-utils.h" #include "mail/e-mail-shell-module.h" #include "mail/em-composer-utils.h" +#include "mail/em-event.h" #include "mail/em-folder-selector.h" #include "mail/em-folder-tree.h" #include "mail/em-utils.h" @@ -1485,6 +1488,164 @@ mail_reader_key_press_cb (EMailReader *reader, return TRUE; } +static gboolean +mail_reader_message_read_cb (EMailReader *reader) +{ + MessageList *message_list; + const gchar *uid; + + message_list = e_mail_reader_get_message_list (reader); + + uid = g_object_get_data (G_OBJECT (reader), "mark-read-uid"); + g_return_if_fail (uid != NULL); + + if (g_strcmp0 (message_list->cursor_uid, uid) == 0) + e_mail_reader_mark_as_read (reader, uid); +} + +static void +mail_reader_message_loaded_cb (CamelFolder *folder, + const gchar *message_uid, + CamelMimeMessage *message, + gpointer user_data, + CamelException *ex) +{ + EMailReader *reader = user_data; + EMFormatHTMLDisplay *html_display; + MessageList *message_list; + EShellModule *shell_module; + EShellSettings *shell_settings; + EShell *shell; + EMEvent *event; + EMEventTargetMessage *target; + gboolean mark_read; + gint timeout_interval; + gpointer data; + + html_display = e_mail_reader_get_html_display (reader); + message_list = e_mail_reader_get_message_list (reader); + + shell_module = e_mail_reader_get_shell_module (reader); + shell = e_shell_module_get_shell (shell_module); + shell_settings = e_shell_get_shell_settings (shell); + + /* If the user picked a different message in the time it took + * to fetch this message, then don't bother rendering it. */ + if (g_strcmp0 (message_list->cursor_uid, message_uid) != 0) + return; + + /** @Event: message.reading + * @Title: Viewing a message + * @Target: EMEventTargetMessage + * + * message.reading is emitted whenever a user views a message. + */ + event = em_event_peek (); + target = em_event_target_new_message ( + event, folder, message, message_uid, 0); + e_event_emit ( + (EEvent *) event, "message.reading", + (EEventTarget *) target); + + em_format_format ( + (EMFormat *) html_display, folder, message_uid, message); + + /* Reset the shell view icon. */ + e_shell_event (shell, "mail-icon", "evolution-mail"); + + /* Determine whether to mark the message as read. */ + g_object_get ( + shell_settings, + "mail-mark-seen", &mark_read, + "mail-mark-seen-timeout", &timeout_interval, NULL); + + g_object_set_data_full ( + G_OBJECT (reader), "mark-read-uid", + g_strdup (message_uid), (GDestroyNotify) g_free); + + if (message_list->seen_id > 0) + g_source_remove (message_list->seen_id); + + if (mark_read) { + message_list->seen_id = g_timeout_add ( + timeout_interval, (GSourceFunc) + mail_reader_message_read_cb, reader); + + } else if (camel_exception_is_set (ex)) { + GtkHTMLStream *stream; + + /* Display the error inline and clear the exception. */ + stream = gtk_html_begin ( + ((EMFormatHTML *) html_display)->html); + gtk_html_stream_printf ( + stream, "<h2>%s</h2><p>%s</p>", + _("Unable to retrieve message"), + ex->desc); + gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); + camel_exception_clear (ex); + } + + /* We referenced this in the call to mail_get_messagex(). */ + g_object_unref (reader); +} + +static gboolean +mail_reader_message_selected_timeout_cb (EMailReader *reader) +{ + EMFormatHTMLDisplay *html_display; + MessageList *message_list; + const gchar *cursor_uid; + const gchar *format_uid; + const gchar *key; + + html_display = e_mail_reader_get_html_display (reader); + message_list = e_mail_reader_get_message_list (reader); + + cursor_uid = message_list->cursor_uid; + format_uid = ((EMFormat *) html_display)->uid; + + if (cursor_uid != NULL) { + if (g_strcmp0 (cursor_uid, format_uid) != 0) + mail_get_messagex ( + message_list->folder, cursor_uid, + mail_reader_message_loaded_cb, + g_object_ref (reader), + mail_msg_fast_ordered_push); + } else + em_format_format ((EMFormat *) html_display, NULL, NULL, NULL); + + key = "message-selected-timeout"; + g_object_set_data (G_OBJECT (reader), key, NULL); + + return FALSE; +} + +static void +mail_reader_message_selected_cb (EMailReader *reader, + const gchar *uid) +{ + const gchar *key; + guint source_id; + gpointer data; + + /* XXX This is kludgy, but we have no other place to store + * timeout state information. */ + + key = "message-selected-timeout"; + data = g_object_get_data (G_OBJECT (reader), key); + source_id = GPOINTER_TO_UINT (data); + + if (source_id > 0) + g_source_remove (source_id); + + source_id = g_timeout_add ( + 100, (GSourceFunc) + mail_reader_message_selected_timeout_cb, reader); + + data = GUINT_TO_POINTER (source_id); + g_object_set_data (G_OBJECT (reader), key, data); +} + static void mail_reader_set_folder (EMailReader *reader, CamelFolder *folder, @@ -1509,6 +1670,18 @@ mail_reader_set_folder (EMailReader *reader, } static void +mail_reader_set_message (EMailReader *reader, + const gchar *uid, + gboolean mark_read) +{ + MessageList *message_list; + gpointer data; + + message_list = e_mail_reader_get_message_list (reader); + message_list_select_uid (message_list, uid); +} + +static void mail_reader_init_charset_actions (EMailReader *reader) { GtkActionGroup *action_group; @@ -1541,6 +1714,7 @@ static void mail_reader_class_init (EMailReaderIface *iface) { iface->set_folder = mail_reader_set_folder; + iface->set_message = mail_reader_set_message; } GType @@ -1626,6 +1800,10 @@ e_mail_reader_init (EMailReader *reader) /* Connect signals. */ g_signal_connect_swapped ( + message_list, "message-selected", + G_CALLBACK (mail_reader_message_selected_cb), reader); + + g_signal_connect_swapped ( message_list->tree, "double-click", G_CALLBACK (mail_reader_double_click_cb), reader); @@ -1730,6 +1908,21 @@ e_mail_reader_set_folder (EMailReader *reader, } void +e_mail_reader_set_message (EMailReader *reader, + const gchar *uid, + gboolean mark_read) +{ + EMailReaderIface *iface; + + g_return_if_fail (E_IS_MAIL_READER (reader)); + + iface = E_MAIL_READER_GET_IFACE (reader); + g_return_if_fail (iface->set_message != NULL); + + iface->set_message (reader, uid, mark_read); +} + +void e_mail_reader_create_charset_menu (EMailReader *reader, GtkUIManager *ui_manager, guint merge_id) diff --git a/mail/e-mail-reader.h b/mail/e-mail-reader.h index 5dcf8d0266..4fba37056f 100644 --- a/mail/e-mail-reader.h +++ b/mail/e-mail-reader.h @@ -64,14 +64,15 @@ struct _EMailReaderIface { void (*set_folder) (EMailReader *reader, CamelFolder *folder, const gchar *folder_uri); + void (*set_message) (EMailReader *reader, + const gchar *uid, + gboolean mark_read); }; GType e_mail_reader_get_type (void); void e_mail_reader_init (EMailReader *reader); GtkActionGroup * e_mail_reader_get_action_group (EMailReader *reader); -CamelFolder * e_mail_reader_get_folder (EMailReader *reader); -const gchar * e_mail_reader_get_folder_uri (EMailReader *reader); gboolean e_mail_reader_get_hide_deleted (EMailReader *reader); EMFormatHTMLDisplay * e_mail_reader_get_html_display (EMailReader *reader); @@ -81,6 +82,9 @@ GtkWindow * e_mail_reader_get_window (EMailReader *reader); void e_mail_reader_set_folder (EMailReader *reader, CamelFolder *folder, const gchar *folder_uri); +void e_mail_reader_set_message (EMailReader *reader, + const gchar *uid, + gboolean mark_read); void e_mail_reader_create_charset_menu (EMailReader *reader, GtkUIManager *ui_manager, diff --git a/mail/e-mail-shell-module-settings.c b/mail/e-mail-shell-module-settings.c index 04388a92f5..0bd72c27bc 100644 --- a/mail/e-mail-shell-module-settings.c +++ b/mail/e-mail-shell-module-settings.c @@ -26,7 +26,7 @@ e_mail_shell_module_init_settings (EShell *shell) { EShellSettings *shell_settings; - shell_settings = e_shell_get_settings (shell); + shell_settings = e_shell_get_shell_settings (shell); /* XXX Default values should match the GConf schema. * Yes it's redundant, but we're stuck with GConf. */ diff --git a/mail/e-mail-shell-module.c b/mail/e-mail-shell-module.c index aef48d2636..1185e13575 100644 --- a/mail/e-mail-shell-module.c +++ b/mail/e-mail-shell-module.c @@ -687,10 +687,13 @@ mail_shell_module_prepare_for_offline_cb (EShell *shell, EActivity *activity, EShellModule *shell_module) { - GtkWidget *parent; + GList *shell_windows; + GtkWidget *parent = NULL; gboolean synchronize = FALSE; - parent = e_shell_get_focused_window (shell); + shell_windows = e_shell_get_shell_windows (shell); + if (shell_windows != NULL) + parent = GTK_WIDGET (shell_windows->data); if (e_shell_get_network_available (shell)) synchronize = em_utils_prompt_user ( @@ -871,7 +874,7 @@ e_shell_module_init (GTypeModule *type_module) mail_shell_module_init_preferences (shell); g_object_get ( - e_shell_get_settings (shell), + e_shell_get_shell_settings (shell), "mail-enable-search-folders", &enable_search_folders, NULL); if (enable_search_folders) diff --git a/mail/em-account-editor.c b/mail/em-account-editor.c index 866d503292..a29f408231 100644 --- a/mail/em-account-editor.c +++ b/mail/em-account-editor.c @@ -667,7 +667,7 @@ emae_signature_new(GtkWidget *w, EMAccountEditor *emae) gboolean html_mode; shell = e_shell_get_default (); - shell_settings = e_shell_get_settings (shell); + shell_settings = e_shell_get_shell_settings (shell); parent = gtk_widget_get_toplevel (w); g_object_get ( diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c index dfc50edf0e..52bbd98479 100644 --- a/mail/em-composer-prefs.c +++ b/mail/em-composer-prefs.c @@ -857,7 +857,7 @@ em_composer_prefs_construct (EMComposerPrefs *prefs, bridge = gconf_bridge_get (); client = mail_config_get_gconf_client (); - shell_settings = e_shell_get_settings (shell); + shell_settings = e_shell_get_shell_settings (shell); gladefile = g_build_filename (EVOLUTION_GLADEDIR, "mail-config.glade", diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c index 3433453889..e940b841a4 100644 --- a/mail/em-folder-view.c +++ b/mail/em-folder-view.c @@ -90,7 +90,6 @@ #include "em-folder-browser.h" #include "em-mailer-prefs.h" #include "em-folder-browser.h" -#include "em-message-browser.h" #include "message-list.h" #include "em-utils.h" #include "em-composer-utils.h" @@ -528,6 +527,7 @@ em_folder_view_open_selected(EMFolderView *emfv) } } +#if 0 /* KILL-BONOBO */ /* TODO: have an em_utils_open_messages call? */ for (i=0; i<views->len; i++) { EMMessageBrowser *emmb; @@ -547,6 +547,7 @@ em_folder_view_open_selected(EMFolderView *emfv) em_utils_handle_receipt (emfv->folder, uids->pdata[i], NULL); g_free(views->pdata[i]); } +#endif g_ptr_array_free(views, TRUE); message_list_free_uids(emfv->list, uids); @@ -664,6 +665,7 @@ emfv_popup_open(EPopup *ep, EPopupItem *pitem, void *data) static void emfv_popup_source(EPopup *ep, EPopupItem *pitem, void *data) { +#if 0 /* KILL-BONOBO */ EMFolderView *emfv = data; EMMessageBrowser *emmb; GPtrArray *uids; @@ -678,6 +680,7 @@ emfv_popup_source(EPopup *ep, EPopupItem *pitem, void *data) gtk_widget_show(emmb->window); message_list_free_uids(emfv->list, uids); +#endif } //#define DelInVFolderCheckName "DelInVFolderCheck" diff --git a/mail/em-format-html.c b/mail/em-format-html.c index 8aed5e814c..99377cce74 100644 --- a/mail/em-format-html.c +++ b/mail/em-format-html.c @@ -159,7 +159,6 @@ efh_init(GObject *o) gtk_html_set_default_content_type(efh->html, "text/html; charset=utf-8"); gtk_html_set_editable(efh->html, FALSE); - g_signal_connect(efh->html, "destroy", G_CALLBACK(efh_gtkhtml_destroy), efh); g_signal_connect(efh->html, "url_requested", G_CALLBACK(efh_url_requested), efh); g_signal_connect(efh->html, "object_requested", G_CALLBACK(efh_object_requested), efh); diff --git a/mail/em-mailer-prefs.c b/mail/em-mailer-prefs.c index e1f512ee57..e0044ed082 100644 --- a/mail/em-mailer-prefs.c +++ b/mail/em-mailer-prefs.c @@ -1108,7 +1108,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs, char *gladefile; prefs->shell = g_object_ref (shell); - shell_settings = e_shell_get_settings (shell); + shell_settings = e_shell_get_shell_settings (shell); gladefile = g_build_filename (EVOLUTION_GLADEDIR, "mail-config.glade", diff --git a/mail/em-message-browser.c b/mail/em-message-browser.c deleted file mode 100644 index 8b3ff99152..0000000000 --- a/mail/em-message-browser.c +++ /dev/null @@ -1,397 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Michael Zucchi <notzed@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#ifdef G_OS_WIN32 -/* Work around 'DATADIR' and 'interface' lossage in <windows.h> */ -#define DATADIR crap_DATADIR -#include <windows.h> -#undef DATADIR -#undef interface -#endif - -#include <gdk/gdkkeysyms.h> - -#include <gconf/gconf-client.h> - -#include <camel/camel-folder.h> - -#include <bonobo/bonobo-main.h> -#include <bonobo/bonobo-object.h> -#include <bonobo/bonobo-window.h> -#include <bonobo/bonobo-generic-factory.h> -#include <bonobo/bonobo-ui-component.h> -#include <bonobo/bonobo-ui-util.h> - -#include "e-util/e-util-private.h" - -#include "em-format-html-display.h" -#include "em-message-browser.h" -#include "em-menu.h" - -#define EM_MESSAGE_BROWSER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), EM_TYPE_MESSAGE_BROWSER, EMMessageBrowserPrivate)) - -#define DEFAULT_WIDTH 600 -#define DEFAULT_HEIGHT 400 - -struct _EMMessageBrowserPrivate { - GtkWidget *preview; /* container for message display */ -}; - -static gpointer parent_class; -static GtkAllocation window_size = { 0, 0, 0, 0 }; - -static void -emmb_close (BonoboUIComponent *uid, - gpointer data, - const gchar *path) -{ - EMMessageBrowser *emmb = data; - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (emmb)); - gtk_widget_destroy (toplevel); -} - -static BonoboUIVerb emmb_verbs[] = { - BONOBO_UI_UNSAFE_VERB ("MessageBrowserClose", emmb_close), - BONOBO_UI_VERB_END -}; - -static void -emmb_set_message (EMFolderView *emfv, - const gchar *uid, - gint nomarkseen) -{ - EMMessageBrowser *emmb = EM_MESSAGE_BROWSER (emfv); - EMFolderViewClass *folder_view_class; - CamelMessageInfo *info; - - /* Chain up to parent's set_message() method. */ - folder_view_class = EM_FOLDER_VIEW_CLASS (parent_class); - folder_view_class->set_message (emfv, uid, nomarkseen); - - if (uid == NULL) { - gtk_widget_destroy (GTK_WIDGET (emfv)); - return; - } - - info = camel_folder_get_message_info (emfv->folder, uid); - - if (info != NULL) { - gtk_window_set_title ( - GTK_WINDOW (emmb->window), - camel_message_info_subject (info)); - camel_folder_free_message_info (emfv->folder, info); - } - - /* Well we don't know if it got displayed (yet) ... but whatever ... */ - if (!nomarkseen) - camel_folder_set_message_flags ( - emfv->folder, uid, - CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); -} - -static void -emmb_activate (EMFolderView *emfv, - BonoboUIComponent *uic, - gint state) -{ - EMFolderViewClass *folder_view_class; - - folder_view_class = EM_FOLDER_VIEW_CLASS (parent_class); - - if (state) { - /* Chain up to parent's activate() method. */ - folder_view_class->activate (emfv, uic, state); - - bonobo_ui_component_add_verb_list_with_data ( - uic, emmb_verbs, emfv); - bonobo_ui_component_set_prop( - uic, "/commands/EditPaste", "sensitive", "0", NULL); - } else { - const BonoboUIVerb *verb; - - for (verb = &emmb_verbs[0]; verb->cname; verb++) - bonobo_ui_component_remove_verb (uic, verb->cname); - - /* Chain up to parent's activate() method. */ - folder_view_class->activate (emfv, uic, state); - } -} - -static void -emmb_list_message_selected_cb (struct _MessageList *ml, - const gchar *uid, - EMMessageBrowser *emmb) -{ - EMFolderView *emfv = EM_FOLDER_VIEW (emmb); - CamelMessageInfo *info; - - if (uid == NULL) - return; - - info = camel_folder_get_message_info (emfv->folder, uid); - if (info == NULL) - return; - - gtk_window_set_title ( - GTK_WINDOW (emmb->window), - camel_message_info_subject (info)); - gtk_widget_grab_focus ( - GTK_WIDGET (emfv->preview->formathtml.html)); - - camel_folder_free_message_info (emfv->folder, info); -} - -static void -emmb_window_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GConfClient *client; - - /* FIXME Have GConfBridge handle this. */ - - /* save to in-memory variable for current session access */ - window_size = *allocation; - - /* save the setting across sessions */ - client = gconf_client_get_default (); - gconf_client_set_int ( - client, "/apps/evolution/mail/message_window/width", - window_size.width, NULL); - gconf_client_set_int ( - client, "/apps/evolution/mail/message_window/height", - window_size.height, NULL); - g_object_unref (client); -} - -static int -emmb_key_press_event_cb (EMMessageBrowser *emmb, - GdkEventKey *event) -{ - if (event->keyval == GDK_Escape) { - GtkWidget *toplevel; - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (emmb)); - gtk_widget_destroy (toplevel); - g_signal_stop_emission_by_name (emmb, "key-press-event"); - - return TRUE; - } - - return FALSE; -} - -static void -emmb_destroy (GtkObject *gtk_object) -{ - EMFolderView *emfv = EM_FOLDER_VIEW (gtk_object); - - if (emfv->list) { - gtk_widget_destroy (GTK_WIDGET (emfv->list)); - emfv->list = NULL; - } - - /* Chain up to parent's destroy() method. */ - GTK_OBJECT_CLASS (parent_class)->destroy (gtk_object); -} - -static void -emmb_class_init (EMMessageBrowserClass *class) -{ - GtkObjectClass *gtk_object_class; - EMFolderViewClass *folder_view_class; - - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (EMMessageBrowserPrivate)); - - gtk_object_class = GTK_OBJECT_CLASS (class); - gtk_object_class->destroy = emmb_destroy; - - folder_view_class = EM_FOLDER_VIEW_CLASS (class); - folder_view_class->update_message_style = FALSE; - folder_view_class->set_message = emmb_set_message; - folder_view_class->activate = emmb_activate; -} - -static void -emmb_init (EMMessageBrowser *emmb) -{ - EMFolderView *emfv = EM_FOLDER_VIEW (emmb); - GtkWidget *widget; - gchar *filename; - - emmb->priv = EM_MESSAGE_BROWSER_GET_PRIVATE (emmb); - - emfv->preview_active = TRUE; - - g_slist_foreach (emfv->ui_files, (GFunc) g_free, NULL); - g_slist_free (emfv->ui_files); - emfv->ui_files = NULL; - - filename = g_build_filename ( - EVOLUTION_UIDIR, "evolution-mail-messagedisplay.xml", NULL); - emfv->ui_files = g_slist_append (emfv->ui_files, filename); - - filename = g_build_filename ( - EVOLUTION_UIDIR, "evolution-mail-message.xml", NULL); - emfv->ui_files = g_slist_append (emfv->ui_files, filename); - - widget = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (widget), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type ( - GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN); - gtk_widget_show (widget); - emmb->priv->preview = widget; - - widget = GTK_WIDGET (emfv->preview->formathtml.html); - gtk_container_add (GTK_CONTAINER (emmb->priv->preview), widget); - gtk_widget_show (widget); - - gtk_box_pack_start ( - GTK_BOX (emmb), emmb->priv->preview, TRUE, TRUE, 0); - gtk_box_pack_start( - GTK_BOX (emmb), em_format_html_get_search_dialog ( - emfv->preview), FALSE, FALSE, 0); - - /** @HookPoint-EMMenu: Standalone Message View Menu - * @Id: org.gnome.evolution.mail.messagebrowser - * @Class: org.gnome.evolution.mail.bonobomenu:1.0 - * @Target: EMMenuTargetSelect - * - * The main menu of standalone message viewer. - */ - EM_FOLDER_VIEW (emmb)->menu = - em_menu_new ("org.gnome.evolution.mail.messagebrowser"); -} - -GType -em_message_browser_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) { - static const GTypeInfo type_info = { - sizeof (EMMessageBrowserClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) emmb_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMMessageBrowser), - 0, /* n_preallocs */ - (GInstanceInitFunc) emmb_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - EM_TYPE_FOLDER_VIEW, "EMMessageBrowser", - &type_info, 0); - } - - return type; -} - -GtkWidget * -em_message_browser_new (void) -{ - return g_object_new (EM_TYPE_MESSAGE_BROWSER, NULL); -} - -GtkWidget * -em_message_browser_window_new (void) -{ - EMMessageBrowser *emmb; - BonoboUIContainer *uicont; - BonoboUIComponent *uic; - - emmb = (EMMessageBrowser *) em_message_browser_new (); - gtk_widget_show (GTK_WIDGET (emmb)); - - /* FIXME: title set elsewhere? */ - emmb->window = g_object_new ( - BONOBO_TYPE_WINDOW, "title", "Evolution", NULL); - bonobo_window_set_contents ( - BONOBO_WINDOW (emmb->window), GTK_WIDGET (emmb)); - - uic = bonobo_ui_component_new_default (); - uicont = bonobo_window_get_ui_container (BONOBO_WINDOW (emmb->window)); - bonobo_ui_component_set_container (uic, BONOBO_OBJREF (uicont), NULL); - - em_folder_view_activate (EM_FOLDER_VIEW (emmb), uic, TRUE); - - if (window_size.width == 0) { - /* initialize @window_size with the previous session's size */ - - /* FIXME Have GConfBridge handle this. */ - - GConfClient *client; - GError *error = NULL; - - client = gconf_client_get_default (); - - window_size.width = gconf_client_get_int ( - client, "/apps/evolution/mail/message_window/width", - &error); - if (error != NULL) { - window_size.width = DEFAULT_WIDTH; - g_clear_error (&error); - } - - window_size.height = gconf_client_get_int ( - client, "/apps/evolution/mail/message_window/height", - &error); - if (error != NULL) { - window_size.height = DEFAULT_HEIGHT; - g_clear_error (&error); - } - - g_object_unref (client); - } - - gtk_window_set_default_size ( - GTK_WINDOW (emmb->window), - window_size.width, window_size.height); - - g_signal_connect ( - emmb->window, "size-allocate", - G_CALLBACK (emmb_window_size_allocate), NULL); - g_signal_connect ( - EM_FOLDER_VIEW (emmb)->list, "message_selected", - G_CALLBACK (emmb_list_message_selected_cb), emmb); - g_signal_connect ( - emmb, "key-press-event", - G_CALLBACK (emmb_key_press_event_cb), NULL); - - /* cleanup? */ - - return GTK_WIDGET (emmb); -} diff --git a/mail/em-message-browser.h b/mail/em-message-browser.h deleted file mode 100644 index cf00a74a75..0000000000 --- a/mail/em-message-browser.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef EM_MESSAGE_BROWSER_H -#define EM_MESSAGE_BROWSER_H - -#include <gtk/gtk.h> -#include "em-folder-view.h" - -/* Standard GObject macros */ -#define EM_TYPE_MESSAGE_BROWSER \ - (em_message_browser_get_type ()) -#define EM_MESSAGE_BROWSER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), EM_TYPE_MESSAGE_BROWSER, EMMessageBrowser)) -#define EM_MESSAGE_BROWSER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), EM_TYPE_MESSAGE_BROWSER, EMMessageBrowserClass)) -#define EM_IS_MESSAGE_BROWSER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), EM_TYPE_MESSAGE_BROWSER)) -#define EM_IS_MESSAGE_BROWSER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), EM_TYPE_MESSAGE_BROWSER)) -#define EM_MESSAGE_BROWSER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), EM_TYPE_MESSAGE_BROWSER, EMMessageBrowserClass)) - -G_BEGIN_DECLS - -typedef struct _EMMessageBrowser EMMessageBrowser; -typedef struct _EMMessageBrowserClass EMMessageBrowserClass; -typedef struct _EMMessageBrowserPrivate EMMessageBrowserPrivate; - -struct _EMMessageBrowser { - EMFolderView parent; - - /* container, if setup */ - GtkWidget *window; - - EMMessageBrowserPrivate *priv; -}; - -struct _EMMessageBrowserClass { - EMFolderViewClass parent_class; -}; - -GType em_message_browser_get_type (void); - -GtkWidget * em_message_browser_new (void); - -/* Also sets up a bonobo container window w/ docks and so on. */ -GtkWidget * em_message_browser_window_new (void); - -G_END_DECLS - -#endif /* EM_MESSAGE_BROWSER_H */ |