diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2008-03-19 12:09:55 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@src.gnome.org> | 2008-03-19 12:09:55 +0800 |
commit | d29f83381b28408b614e2073ffd31fba0f98c400 (patch) | |
tree | 7b538c4d1e103938643b121c1d3cc8179f2c0602 /mail/em-message-browser.c | |
parent | fce544011db8bc184f2dce759693649086ea5620 (diff) | |
download | gsoc2013-evolution-d29f83381b28408b614e2073ffd31fba0f98c400.tar.gz gsoc2013-evolution-d29f83381b28408b614e2073ffd31fba0f98c400.tar.zst gsoc2013-evolution-d29f83381b28408b614e2073ffd31fba0f98c400.zip |
Code cleanup, no logic changes.
2008-03-19 Matthew Barnes <mbarnes@redhat.com>
* em-folder-view.h:
* em-message-browser.h:
* em-message-browser.c:
Code cleanup, no logic changes.
svn path=/trunk/; revision=35214
Diffstat (limited to 'mail/em-message-browser.c')
-rw-r--r-- | mail/em-message-browser.c | 428 |
1 files changed, 246 insertions, 182 deletions
diff --git a/mail/em-message-browser.c b/mail/em-message-browser.c index ef6e68b390..0ef8105e4f 100644 --- a/mail/em-message-browser.c +++ b/mail/em-message-browser.c @@ -20,7 +20,6 @@ * */ - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -34,9 +33,7 @@ #undef interface #endif -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtkbutton.h> - +#include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> #include <gconf/gconf-client.h> @@ -58,6 +55,9 @@ #include "evolution-shell-component-utils.h" /* Pixmap stuff, sigh */ +#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 @@ -66,144 +66,224 @@ struct _EMMessageBrowserPrivate { GtkWidget *preview; /* container for message display */ }; -static void emmb_set_message(EMFolderView *emfv, const char *uid, int nomarkseen); -static void emmb_activate(EMFolderView *emfv, BonoboUIComponent *uic, int state); - -static EMFolderViewClass *emmb_parent; +static gpointer parent_class; +static GtkAllocation window_size = { 0, 0, 0, 0 }; static void -free_one_ui_file (gpointer data, - gpointer user_data) +emmb_close (BonoboUIComponent *uid, + gpointer data, + const gchar *path) { - g_free (data); + 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_init(GObject *o) +emmb_set_message (EMFolderView *emfv, + const gchar *uid, + gint nomarkseen) { - EMMessageBrowser *emmb = (EMMessageBrowser *)o; - struct _EMMessageBrowserPrivate *p; - - p = emmb->priv = g_malloc0(sizeof(struct _EMMessageBrowserPrivate)); - - ((EMFolderView *)emmb)->preview_active = TRUE; - - g_slist_foreach (emmb->view.ui_files, free_one_ui_file, NULL); - g_slist_free(emmb->view.ui_files); + EMMessageBrowser *emmb = EM_MESSAGE_BROWSER (emfv); + EMFolderViewClass *folder_view_class; + CamelMessageInfo *info; - emmb->view.ui_files = g_slist_append(NULL, - g_build_filename (EVOLUTION_UIDIR, - "evolution-mail-messagedisplay.xml", - NULL)); - emmb->view.ui_files = g_slist_append(emmb->view.ui_files, - g_build_filename (EVOLUTION_UIDIR, - "evolution-mail-message.xml", - NULL)); + /* 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); - /* currently: just use a scrolledwindow for preview widget */ - p->preview = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy((GtkScrolledWindow *)p->preview, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type((GtkScrolledWindow *)p->preview, GTK_SHADOW_IN); - gtk_widget_show(p->preview); + if (uid == NULL) { + gtk_widget_destroy (GTK_WIDGET (emfv)); + return; + } - gtk_container_add((GtkContainer *)p->preview, (GtkWidget *)emmb->view.preview->formathtml.html); - gtk_widget_show((GtkWidget *)emmb->view.preview->formathtml.html); + info = camel_folder_get_message_info (emfv->folder, uid); - gtk_widget_show(p->preview); + if (info != NULL) { + gtk_window_set_title ( + GTK_WINDOW (emmb->window), + camel_message_info_subject (info)); + camel_folder_free_message_info (emfv->folder, info); + } - gtk_box_pack_start ((GtkBox *)emmb, p->preview, TRUE, TRUE, 0); - gtk_box_pack_start((GtkBox *)emmb, em_format_html_get_search_dialog (emmb->view.preview), FALSE, FALSE, 0); + /* 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_finalise(GObject *o) +emmb_activate (EMFolderView *emfv, + BonoboUIComponent *uic, + gint state) { - EMMessageBrowser *emmb = (EMMessageBrowser *)o; + 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); - g_free(emmb->priv); - ((GObjectClass *)emmb_parent)->finalize(o); + /* Chain up to parent's activate() method. */ + folder_view_class->activate (emfv, uic, state); + } } static void -emmb_destroy(GtkObject *o) +emmb_list_message_selected_cb (struct _MessageList *ml, + const gchar *uid, + EMMessageBrowser *emmb) { - EMMessageBrowser *emmb = (EMMessageBrowser *)o; + EMFolderView *emfv = EM_FOLDER_VIEW (emmb); + CamelMessageInfo *info; - if (emmb->view.list) { - gtk_widget_destroy((GtkWidget *)emmb->view.list); - emmb->view.list = NULL; - } + if (uid == NULL) + return; - ((GtkObjectClass *)emmb_parent)->destroy(o); + 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_class_init(GObjectClass *klass) +emmb_window_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) { - klass->finalize = emmb_finalise; + GConfClient *client; - ((GtkObjectClass *)klass)->destroy = emmb_destroy; + /* FIXME Have GConfBridge handle this. */ - ((EMFolderViewClass *) klass)->update_message_style = FALSE; + /* save to in-memory variable for current session access */ + window_size = *allocation; - ((EMFolderViewClass *)klass)->set_message = emmb_set_message; - ((EMFolderViewClass *)klass)->activate = emmb_activate; + /* 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); } -GType -em_message_browser_get_type(void) +static int +emmb_key_press_event_cb (EMMessageBrowser *emmb, + GdkEventKey *event) { - static GType type = 0; + if (event->keyval == GDK_Escape) { + GtkWidget *toplevel; - if (type == 0) { - static const GTypeInfo info = { - sizeof(EMMessageBrowserClass), - NULL, NULL, - (GClassInitFunc)emmb_class_init, - NULL, NULL, - sizeof(EMMessageBrowser), 0, - (GInstanceInitFunc)emmb_init - }; - emmb_parent = g_type_class_ref(em_folder_view_get_type()); - type = g_type_register_static(em_folder_view_get_type(), "EMMessageBrowser", &info, 0); + 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 type; + return FALSE; } -static GtkAllocation window_size = { 0, 0, 0, 0 }; - static void -window_size_allocate (GtkWidget *widget, GtkAllocation *allocation) +emmb_destroy (GtkObject *gtk_object) { - GConfClient *gconf; + EMFolderView *emfv = EM_FOLDER_VIEW (gtk_object); - /* save to in-memory variable for current session access */ - window_size = *allocation; + if (emfv->list) { + gtk_widget_destroy (GTK_WIDGET (emfv->list)); + emfv->list = NULL; + } - /* save the setting across sessions */ - gconf = gconf_client_get_default (); - gconf_client_set_int (gconf, "/apps/evolution/mail/message_window/width", window_size.width, NULL); - gconf_client_set_int (gconf, "/apps/evolution/mail/message_window/height", window_size.height, NULL); - g_object_unref (gconf); + /* Chain up to parent's destroy() method. */ + GTK_OBJECT_CLASS (parent_class)->destroy (gtk_object); } static void -emmb_list_message_selected (struct _MessageList *ml, const char *uid, EMMessageBrowser *emmb) +emmb_class_init (EMMessageBrowserClass *class) { - EMFolderView *emfv = (EMFolderView *) emmb; - CamelMessageInfo *info; + GtkObjectClass *gtk_object_class; + EMFolderViewClass *folder_view_class; - if (uid && (info = camel_folder_get_message_info (emfv->folder, uid))) { - gtk_window_set_title ((GtkWindow *) emmb->window, camel_message_info_subject (info)); - gtk_widget_grab_focus ((GtkWidget *) (emmb->view.preview->formathtml.html)); - camel_folder_free_message_info (emfv->folder, info); - } + 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; } -GtkWidget *em_message_browser_new(void) +static void +emmb_init (EMMessageBrowser *emmb) { - EMMessageBrowser *emmb = g_object_new(em_message_browser_get_type(), NULL); + 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 @@ -212,125 +292,109 @@ GtkWidget *em_message_browser_new(void) * * The main menu of standalone message viewer. */ - ((EMFolderView *)emmb)->menu = em_menu_new("org.gnome.evolution.mail.messagebrowser"); - - return (GtkWidget *)emmb; + EM_FOLDER_VIEW (emmb)->menu = + em_menu_new ("org.gnome.evolution.mail.messagebrowser"); } -static int -messagebrowser_key_pressed (EMMessageBrowser *emmb, GdkEventKey *event, void *user_data) +GType +em_message_browser_get_type (void) { - if (event->keyval == GDK_Escape) { - gtk_widget_destroy(gtk_widget_get_toplevel((GtkWidget *)emmb)); - g_signal_stop_emission_by_name (emmb, "key-press-event"); - return TRUE; + 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 FALSE; + return type; +} + +GtkWidget * +em_message_browser_new (void) +{ + return g_object_new (EM_TYPE_MESSAGE_BROWSER, NULL); } -GtkWidget *em_message_browser_window_new(void) +GtkWidget * +em_message_browser_window_new (void) { EMMessageBrowser *emmb; BonoboUIContainer *uicont; BonoboUIComponent *uic; - emmb = (EMMessageBrowser *)em_message_browser_new(); - gtk_widget_show((GtkWidget *)emmb); + emmb = (EMMessageBrowser *) em_message_browser_new (); + gtk_widget_show (GTK_WIDGET (emmb)); + /* FIXME: title set elsewhere? */ - emmb->window = g_object_new(bonobo_window_get_type(), "title", "Evolution", NULL); - bonobo_window_set_contents((BonoboWindow *)emmb->window, (GtkWidget *)emmb); + emmb->window = g_object_new ( + BONOBO_TYPE_WINDOW, "title", "Evolution", NULL); + bonobo_window_set_contents ( + BONOBO_WINDOW (emmb->window), GTK_WIDGET (emmb)); - uicont = bonobo_window_get_ui_container((BonoboWindow *)emmb->window); - uic = bonobo_ui_component_new_default(); - bonobo_ui_component_set_container(uic, BONOBO_OBJREF(uicont), NULL); + 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((EMFolderView *)emmb, uic, TRUE); + em_folder_view_activate (EM_FOLDER_VIEW (emmb), uic, TRUE); if (window_size.width == 0) { /* initialize @window_size with the previous session's size */ - GConfClient *gconf; - GError *err = NULL; - gconf = gconf_client_get_default (); + /* FIXME Have GConfBridge handle this. */ + + GConfClient *client; + GError *error = NULL; - window_size.width = gconf_client_get_int (gconf, "/apps/evolution/mail/message_window/width", &err); - if (err != 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 (&err); + g_clear_error (&error); } - window_size.height = gconf_client_get_int (gconf, "/apps/evolution/mail/message_window/height", &err); - if (err != NULL) { + 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 (&err); + g_clear_error (&error); } - g_object_unref (gconf); - } - - gtk_window_set_default_size ((GtkWindow *) emmb->window, window_size.width, window_size.height); - g_signal_connect (emmb->window, "size-allocate", G_CALLBACK (window_size_allocate), NULL); - g_signal_connect (((EMFolderView *) emmb)->list, "message_selected", G_CALLBACK (emmb_list_message_selected), emmb); - g_signal_connect (emmb, "key-press-event" , G_CALLBACK (messagebrowser_key_pressed), NULL); - - /* cleanup? */ - - return (GtkWidget *)emmb; -} - -/* ********************************************************************** */ - -static void -emmb_set_message(EMFolderView *emfv, const char *uid, int nomarkseen) -{ - EMMessageBrowser *emmb = (EMMessageBrowser *) emfv; - CamelMessageInfo *info; - - emmb_parent->set_message(emfv, uid, nomarkseen); - - if (uid == NULL) { - gtk_widget_destroy((GtkWidget *)emfv); - return; - } - - if ((info = camel_folder_get_message_info (emfv->folder, uid))) { - gtk_window_set_title ((GtkWindow *) emmb->window, camel_message_info_subject (info)); - camel_folder_free_message_info (emfv->folder, info); + g_object_unref (client); } - /* 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); -} + gtk_window_set_default_size ( + GTK_WINDOW (emmb->window), + window_size.width, window_size.height); -static void -emmb_close(BonoboUIComponent *uid, void *data, const char *path) -{ - EMMessageBrowser *emmb = data; + 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); - gtk_widget_destroy(gtk_widget_get_toplevel((GtkWidget *)emmb)); -} - -static BonoboUIVerb emmb_verbs[] = { - BONOBO_UI_UNSAFE_VERB ("MessageBrowserClose", emmb_close), - BONOBO_UI_VERB_END -}; - -static void -emmb_activate(EMFolderView *emfv, BonoboUIComponent *uic, int state) -{ - if (state) { - emmb_parent->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 *v; - - for (v = &emmb_verbs[0]; v->cname; v++) - bonobo_ui_component_remove_verb(uic, v->cname); + /* cleanup? */ - emmb_parent->activate(emfv, uic, state); - } + return GTK_WIDGET (emmb); } |