From 8ef67be83b1b65ad112585d7e1ecefd8beb46b69 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Wed, 13 May 2009 17:01:11 +0200 Subject: [PATCH] Caches accounts window, editor and view in startup. * src/hildon2/modest-accounts-window.[ch] (new method modest_accounts_window_pre_create): offer a way to precreate the accounts window before using it, to increase the effort done in prestart stage. * src/widgets/modest-window-mgr.[ch]: added new virtual method create_caches. This is used for creating the window caches we need, instead of doing this in specific maemo code. In common implementation we load cached instances of view and editor. * src/widgets/modest-hildon2-window-mgr.c: added implementation of create_caches that pre creates accounts window. * src/modest-main.c: added a call to window mgr create_caches in startup process. --- src/hildon2/modest-accounts-window.c | 84 ++++++++++++++++++++----------- src/hildon2/modest-accounts-window.h | 9 ++++ src/hildon2/modest-hildon2-window-mgr.c | 13 +++++ src/modest-main.c | 7 ++- src/widgets/modest-window-mgr.c | 18 ++++++- src/widgets/modest-window-mgr.h | 10 ++++ 6 files changed, 110 insertions(+), 31 deletions(-) diff --git a/src/hildon2/modest-accounts-window.c b/src/hildon2/modest-accounts-window.c index c172f9b..b05e8dc 100644 --- a/src/hildon2/modest-accounts-window.c +++ b/src/hildon2/modest-accounts-window.c @@ -105,6 +105,7 @@ struct _ModestAccountsWindowPrivate { /* globals */ static GtkWindowClass *parent_class = NULL; +static GtkWidget *pre_created_accounts_window = NULL; /************************************************************************/ @@ -237,15 +238,13 @@ connect_signals (ModestAccountsWindow *self) * after disconnecting all signals, in destroy stage */ } -ModestWindow * -modest_accounts_window_new (void) +static ModestWindow * +modest_accounts_window_new_real (void) { ModestAccountsWindow *self = NULL; ModestAccountsWindowPrivate *priv = NULL; - HildonProgram *app; GdkPixbuf *window_icon; GdkPixbuf *new_message_pixbuf; - GtkWidget *action_area_box; guint accel_key; GdkModifierType accel_mods; GtkAccelGroup *accel_group; @@ -293,22 +292,16 @@ modest_accounts_window_new (void) G_CALLBACK (on_queue_changed), self); - priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ())); - - action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view)); priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL); hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message")); hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf)); - gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0); gtk_widget_show_all (priv->new_message_button); - hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE); g_object_unref (new_message_pixbuf); setup_menu (self); - gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view); gtk_box_pack_start (GTK_BOX (priv->box), priv->pannable, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (box_alignment), priv->box); gtk_container_add (GTK_CONTAINER (self), box_alignment); @@ -317,18 +310,9 @@ modest_accounts_window_new (void) gtk_widget_show (priv->box); gtk_widget_show (box_alignment); - connect_signals (MODEST_ACCOUNTS_WINDOW (self)); - - /* Load previous osso state, for instance if we are being restored from - * hibernation: */ - modest_osso_load_state (); - /* Get device name */ modest_maemo_utils_get_device_name (); - app = hildon_program_get_instance (); - hildon_program_add_window (app, HILDON_WINDOW (self)); - /* Set window icon */ window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG); if (window_icon) { @@ -336,6 +320,46 @@ modest_accounts_window_new (void) g_object_unref (window_icon); } + accel_group = gtk_accel_group_new (); + gtk_accelerator_parse ("n", &accel_key, &accel_mods); + gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group, + accel_key, accel_mods, 0); + gtk_window_add_accel_group (GTK_WINDOW (self), accel_group); + + return MODEST_WINDOW(self); +} + +ModestWindow * +modest_accounts_window_new (void) +{ + GtkWidget *action_area_box; + ModestWindow *self; + ModestAccountsWindowPrivate *priv = NULL; + HildonProgram *app; + + if (pre_created_accounts_window) { + self = MODEST_WINDOW (pre_created_accounts_window); + pre_created_accounts_window = NULL; + } else { + self = modest_accounts_window_new_real (); + } + priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self); + priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ())); + + action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view)); + gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0); + hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE); + gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view); + + connect_signals (MODEST_ACCOUNTS_WINDOW (self)); + + /* Load previous osso state, for instance if we are being restored from + * hibernation: */ + modest_osso_load_state (); + + app = hildon_program_get_instance (); + hildon_program_add_window (app, HILDON_WINDOW (self)); + /* Dont't restore settings here, * because it requires a gtk_widget_show(), * and we don't want to do that until later, @@ -345,19 +369,14 @@ modest_accounts_window_new (void) g_signal_connect (G_OBJECT (self), "map-event", G_CALLBACK (_modest_accounts_window_map_event), G_OBJECT (self)); - update_progress_hint (self); + update_progress_hint (MODEST_ACCOUNTS_WINDOW (self)); - row_count_changed (self); - - accel_group = gtk_accel_group_new (); - gtk_accelerator_parse ("n", &accel_key, &accel_mods); - gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group, - accel_key, accel_mods, 0); - gtk_window_add_accel_group (GTK_WINDOW (self), accel_group); + row_count_changed (MODEST_ACCOUNTS_WINDOW (self)); - return MODEST_WINDOW(self); + return self; } + ModestAccountView * modest_accounts_window_get_account_view (ModestAccountsWindow *self) { @@ -632,3 +651,12 @@ on_queue_changed (ModestMailOperationQueue *queue, } } +void +modest_accounts_window_pre_create (void) +{ + static gboolean pre_created = FALSE; + if (!pre_created) { + pre_created = TRUE; + pre_created_accounts_window = GTK_WIDGET (modest_accounts_window_new_real ()); + } +} diff --git a/src/hildon2/modest-accounts-window.h b/src/hildon2/modest-accounts-window.h index 476c0d8..f0af61c 100644 --- a/src/hildon2/modest-accounts-window.h +++ b/src/hildon2/modest-accounts-window.h @@ -83,6 +83,15 @@ ModestWindow* modest_accounts_window_new (); */ ModestAccountView *modest_accounts_window_get_account_view (ModestAccountsWindow *self); +/** + * modest_accounts_window_pre_create: + * + * Creates an instance of #ModestAccountsWindow that will be used in the next call + * to modest_accounts_window_new (). Should be called in the initialisation process + * + */ +void modest_accounts_window_pre_create (void); + G_END_DECLS #endif diff --git a/src/hildon2/modest-hildon2-window-mgr.c b/src/hildon2/modest-hildon2-window-mgr.c index b55ce9d..95b6937 100644 --- a/src/hildon2/modest-hildon2-window-mgr.c +++ b/src/hildon2/modest-hildon2-window-mgr.c @@ -89,6 +89,7 @@ static gboolean window_has_modals (ModestWindow *window); static ModestWindow *modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self); static ModestWindow *modest_hildon2_window_mgr_get_current_top (ModestWindowMgr *self); static gboolean modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self); +static void modest_hildon2_window_mgr_create_caches (ModestWindowMgr *self); static void osso_display_event_cb (osso_display_state_t state, gpointer data); static void on_account_removed (TnyAccountStore *acc_store, @@ -173,6 +174,7 @@ modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass) mgr_class->show_initial_window = modest_hildon2_window_mgr_show_initial_window; mgr_class->get_current_top = modest_hildon2_window_mgr_get_current_top; mgr_class->screen_is_on = modest_hildon2_window_mgr_screen_is_on; + mgr_class->create_caches = modest_hildon2_window_mgr_create_caches; g_type_class_add_private (gobject_class, sizeof(ModestHildon2WindowMgrPrivate)); @@ -1048,6 +1050,17 @@ modest_hildon2_window_mgr_screen_is_on (ModestWindowMgr *self) return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE; } +static void +modest_hildon2_window_mgr_create_caches (ModestWindowMgr *self) +{ + g_return_if_fail (MODEST_IS_HILDON2_WINDOW_MGR (self)); + + modest_accounts_window_pre_create (); + + MODEST_WINDOW_MGR_CLASS(parent_class)->create_caches (self); + +} + static void osso_display_event_cb (osso_display_state_t state, gpointer data) diff --git a/src/modest-main.c b/src/modest-main.c index 6165b45..796560e 100644 --- a/src/modest-main.c +++ b/src/modest-main.c @@ -145,6 +145,8 @@ main (int argc, char *argv[]) GError *error; GOptionContext *context; + ModestWindowMgr *mgr; + context = g_option_context_new ("- Modest email client"); g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); @@ -211,6 +213,10 @@ main (int argc, char *argv[]) G_CALLBACK (modest_ui_actions_on_password_requested), NULL); + /* Create cached windows */ + mgr = modest_runtime_get_window_mgr (); + modest_window_mgr_create_caches (mgr); + /* Usually, we only show the UI when we get the "top_application" D-Bus method. * This allows modest to start via D-Bus activation to provide a service, * without showing the UI. @@ -219,7 +225,6 @@ main (int argc, char *argv[]) */ if (show_ui_without_top_application_method) { ModestWindow *window; - ModestWindowMgr *mgr; modest_runtime_set_allow_shutdown (TRUE); mgr = modest_runtime_get_window_mgr(); diff --git a/src/widgets/modest-window-mgr.c b/src/widgets/modest-window-mgr.c index a410589..1dbd75f 100644 --- a/src/widgets/modest-window-mgr.c +++ b/src/widgets/modest-window-mgr.c @@ -73,6 +73,7 @@ static GList *modest_window_mgr_get_window_list_default (ModestWindowMgr *self); static ModestWindow *modest_window_mgr_show_initial_window_default (ModestWindowMgr *self); static ModestWindow *modest_window_mgr_get_current_top_default (ModestWindowMgr *self); static gboolean modest_window_mgr_screen_is_on_default (ModestWindowMgr *self); +static void modest_window_mgr_create_caches_default (ModestWindowMgr *self); static void modest_window_mgr_on_queue_changed (ModestMailOperationQueue *queue, ModestMailOperation *mail_op, ModestMailOperationQueueNotification type, @@ -169,6 +170,7 @@ modest_window_mgr_class_init (ModestWindowMgrClass *klass) mgr_class->show_initial_window = modest_window_mgr_show_initial_window_default; mgr_class->get_current_top = modest_window_mgr_get_current_top_default; mgr_class->screen_is_on = modest_window_mgr_screen_is_on_default; + mgr_class->create_caches = modest_window_mgr_create_caches_default; g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate)); @@ -561,8 +563,6 @@ modest_window_mgr_register_window_default (ModestWindowMgr *self, return FALSE; } else { priv->main_window = window; - load_new_view (self); - load_new_editor (self); } } @@ -973,6 +973,19 @@ modest_window_mgr_screen_is_on_default (ModestWindowMgr *self) return TRUE; } +void +modest_window_mgr_create_caches (ModestWindowMgr *mgr) +{ + MODEST_WINDOW_MGR_GET_CLASS (mgr)->create_caches (mgr); +} + +static void +modest_window_mgr_create_caches_default (ModestWindowMgr *self) +{ + load_new_editor (self); + load_new_view (self); +} + static gboolean tny_list_find (TnyList *list, GObject *item) { @@ -1126,3 +1139,4 @@ modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self, return account_ops; } + diff --git a/src/widgets/modest-window-mgr.h b/src/widgets/modest-window-mgr.h index f0a3a7c..6e7fa12 100644 --- a/src/widgets/modest-window-mgr.h +++ b/src/widgets/modest-window-mgr.h @@ -83,6 +83,7 @@ struct _ModestWindowMgrClass { ModestWindow * (*show_initial_window) (ModestWindowMgr *self); ModestWindow * (*get_current_top) (ModestWindowMgr *self); gboolean (*screen_is_on) (ModestWindowMgr *self); + void (*create_caches) (ModestWindowMgr *self); /* Signals */ void (*window_list_empty) (ModestWindowMgr *self); void (*progress_list_changed) (ModestWindowMgr *self); @@ -464,6 +465,15 @@ gboolean modest_window_mgr_has_progress_operation (ModestWindowMgr *self); gboolean modest_window_mgr_has_progress_operation_on_account (ModestWindowMgr *self, const gchar *account_name); +/** + * modest_window_mgr_create_caches: + * @self: a #ModestWindowMgr + * + * creates cached windows. This is called in modest main, just before the show-ui + * code. So it should be valid for the two startup ways (with --show-ui and without). + */ +void modest_window_mgr_create_caches (ModestWindowMgr *self); + G_END_DECLS #endif /* __MODEST_WINDOW_MGR_H__ */ -- 1.7.9.5