* Added the show_initial_window method
authorSergio Villar Senin <svillar@igalia.com>
Tue, 25 Nov 2008 16:44:35 +0000 (16:44 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 25 Nov 2008 16:44:35 +0000 (16:44 +0000)
* ModestWindowMgr is now the responsible of showing the accounts wizard if there is no account

pmo-drop-split-view-r6405

src/hildon2/modest-hildon2-window-mgr.c
src/hildon2/modest-main-window.c
src/hildon2/modest-msg-view-window.c
src/maemo/modest-main-window.c
src/modest-main.c
src/modest-ui-actions.c
src/widgets/modest-window-mgr.c
src/widgets/modest-window-mgr.h

index f7251f7..d79fcc4 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <string.h>
+#include <hildon/hildon-program.h>
 #include "modest-hildon2-window-mgr.h"
 #include "modest-msg-edit-window.h"
 #include "modest-main-window.h"
@@ -39,7 +40,8 @@
 #include "modest-ui-actions.h"
 #include "modest-debug.h"
 #include "modest-tny-folder.h"
-#include <hildon/hildon-program.h>
+#include "modest-folder-window.h"
+#include "modest-accounts-window.h"
 
 /* 'private'/'protected' functions */
 static void modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass);
@@ -74,19 +76,20 @@ static GList *modest_hildon2_window_mgr_get_window_list (ModestWindowMgr *self);
 static gboolean modest_hildon2_window_mgr_close_all_windows (ModestWindowMgr *self);
 static gboolean window_can_close (ModestWindow *window);
 static gboolean window_has_modals (ModestWindow *window);
+static ModestWindow *modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self);
 
 typedef struct _ModestHildon2WindowMgrPrivate ModestHildon2WindowMgrPrivate;
 struct _ModestHildon2WindowMgrPrivate {
        GList        *window_list;
        GMutex       *queue_lock;
        GQueue       *modal_windows;
-       
+
        gboolean     fullscreen_mode;
-       
+
        GHashTable   *destroy_handlers;
        GHashTable   *viewer_handlers;
        GSList       *window_state_uids;
-       
+
        guint        closing_time;
 
        GSList       *modal_handler_uids;
@@ -144,6 +147,7 @@ modest_hildon2_window_mgr_class_init (ModestHildon2WindowMgrClass *klass)
        mgr_class->find_registered_header = modest_hildon2_window_mgr_find_registered_header;
        mgr_class->get_window_list = modest_hildon2_window_mgr_get_window_list;
        mgr_class->close_all_windows = modest_hildon2_window_mgr_close_all_windows;
+       mgr_class->show_initial_window = modest_hildon2_window_mgr_show_initial_window;
 
        g_type_class_add_private (gobject_class, sizeof(ModestHildon2WindowMgrPrivate));
 
@@ -719,3 +723,28 @@ modest_hildon2_window_mgr_set_modal (ModestWindowMgr *self,
        gtk_window_set_destroy_with_parent (window, TRUE);
 }
 
+static ModestWindow *
+modest_hildon2_window_mgr_show_initial_window (ModestWindowMgr *self)
+{
+       ModestWindow *window = NULL;
+       ModestAccountMgr *mgr;
+       GSList *account_names;
+       gint count;
+
+       mgr = modest_runtime_get_account_mgr ();
+       account_names = modest_account_mgr_account_names (mgr, TRUE);
+       count = g_slist_length (account_names);
+
+       if (count > 1) {
+               window = MODEST_WINDOW (modest_accounts_window_new ());
+       } else {
+               window = MODEST_WINDOW (modest_folder_window_new (NULL));
+               if (count == 1)
+                       modest_folder_window_set_account (MODEST_FOLDER_WINDOW (window),
+                                                         account_names->data);
+       }
+       modest_account_mgr_free_account_names (account_names);
+       modest_window_mgr_register_window (self, window, NULL);
+
+       return window;
+}
index 16203c0..45e178d 100644 (file)
@@ -1081,7 +1081,7 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
 {
        ShowHelper *helper = (ShowHelper *) user_data;
        ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
-       
+
        priv->folder_view = MODEST_FOLDER_VIEW (modest_platform_create_folder_view (NULL));
        modest_main_window_set_contents_style (MODEST_MAIN_WINDOW (self), 
                                               MODEST_MAIN_WINDOW_CONTENTS_STYLE_FOLDERS);
@@ -1096,21 +1096,21 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
                                                  TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
 
-       /* Load previous osso state, for instance if we are being restored from 
+       /* Load previous osso state, for instance if we are being restored from
         * hibernation:  */
        modest_osso_load_state ();
 
-       /* Restore window & widget settings */  
+       /* Restore window & widget settings */
        priv->wait_for_settings = TRUE;
        restore_settings (MODEST_MAIN_WINDOW(self), TRUE);
        priv->wait_for_settings = FALSE;
 
        /* Check if accounts exist and show the account wizard if not */
-       gboolean accounts_exist = 
+       gboolean accounts_exist =
                modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
 
        if (!accounts_exist) {
-               /* This is necessary to have the main window shown behind the dialog 
+               /* This is necessary to have the main window shown behind the dialog
                It's an ugly hack... jschmid */
                gtk_widget_show_all(GTK_WIDGET(self));
                modest_ui_actions_on_accounts (NULL, MODEST_WINDOW(self));
index d7c6848..a94d6bb 100644 (file)
@@ -1447,10 +1447,12 @@ modest_msg_view_window_toggle_find_toolbar (GtkToggleAction *toggle,
 
        /* update the toggle buttons status */
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/FindInMessage");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), is_active);
+       if (action)
+               modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), is_active);
+
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/ToolsFindInMessageMenu");
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), is_active);
-       
+       if (action)
+               modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action), is_active);
 }
 
 static void
@@ -1463,7 +1465,7 @@ modest_msg_view_window_find_toolbar_close (GtkWidget *widget,
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE (obj);
-       
+
        toggle = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/FindInMessage"));
        gtk_toggle_action_set_active (toggle, FALSE);
        modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view));
@@ -2217,7 +2219,7 @@ modest_msg_view_window_show_toolbar (ModestWindow *self,
        GtkWidget *reply_button = NULL, *menu = NULL;
        const gchar *action_name;
        GtkAction *action;
-       
+
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
 
@@ -2232,17 +2234,18 @@ modest_msg_view_window_show_toolbar (ModestWindow *self,
                priv->next_toolitem = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarMessageNext");
                priv->prev_toolitem = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarMessageBack");
                toolbar_resize (MODEST_MSG_VIEW_WINDOW (self));
-               
+
                /* Add to window */
                hildon_window_add_toolbar (HILDON_WINDOW (self), 
                                           GTK_TOOLBAR (parent_priv->toolbar));
 
-               /* Set reply button tap and hold menu */        
+               /* Set reply button tap and hold menu */
                reply_button = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
                                                          "/ToolBar/ToolbarMessageReply");
                menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
                                                  "/ToolbarReplyCSM");
-               gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0);
+               if (menu && reply_button)
+                       gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0);
        }
 
        if (show_toolbar) {
@@ -2272,8 +2275,9 @@ modest_msg_view_window_show_toolbar (ModestWindow *self,
                action_name = "/MenuBar/ViewMenu/ViewShowToolbarMenu/ViewShowToolbarNormalScreenMenu";
 
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, action_name);
-       modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
-                                                           show_toolbar);
+       if (action)
+               modest_utils_toggle_action_set_active_block_notify (GTK_TOGGLE_ACTION (action),
+                                                                   show_toolbar);
 }
 
 static void 
index bab4bfd..e63d715 100644 (file)
@@ -1114,7 +1114,8 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        ShowHelper *helper = (ShowHelper *) user_data;
        GtkWidget *folder_win = helper->folder_win;
        ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
-       
+       ModestAccountMgr *mgr;
+
        priv->folder_view = MODEST_FOLDER_VIEW (modest_platform_create_folder_view (NULL));
        wrap_in_scrolled_window (folder_win, GTK_WIDGET(priv->folder_view));
 
@@ -1136,18 +1137,10 @@ modest_main_window_on_show (GtkWidget *self, gpointer user_data)
        restore_settings (MODEST_MAIN_WINDOW(self), TRUE);
        priv->wait_for_settings = FALSE;
 
-       /* Check if accounts exist and show the account wizard if not */
-       gboolean accounts_exist = 
-               modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
-
-       if (!accounts_exist) {
-               /* This is necessary to have the main window shown behind the dialog 
-               It's an ugly hack... jschmid */
-               gtk_widget_show_all(GTK_WIDGET(self));
-               modest_ui_actions_on_accounts (NULL, MODEST_WINDOW(self));
-       } else {
+       /* Update the menus if there are accounts */
+       mgr = modest_runtime_get_account_mgr();
+       if (modest_account_mgr_has_accounts(mgr, TRUE))
                update_menus (MODEST_MAIN_WINDOW (self));
-       }
 
        /* Never call this function again (NOTE that it could happen
           as we hide the main window instead of closing it while
index 5e3a9c8..552a62d 100644 (file)
@@ -61,18 +61,18 @@ on_idle_exit_modest (gpointer data)
 
                /* Disconnect signals. Will be freed by the destroy notify */
                handlers = (MainSignalHandlers *) data;
-               g_signal_handler_disconnect (modest_runtime_get_mail_operation_queue (), 
+               g_signal_handler_disconnect (modest_runtime_get_mail_operation_queue (),
                                             handlers->queue_handler);
-               g_signal_handler_disconnect (modest_runtime_get_window_mgr (), 
+               g_signal_handler_disconnect (modest_runtime_get_window_mgr (),
                                             handlers->window_list_handler);
-               g_signal_handler_disconnect (modest_runtime_get_account_store (), 
-                                            handlers->get_password_handler);           
+               g_signal_handler_disconnect (modest_runtime_get_account_store (),
+                                            handlers->get_password_handler);
                g_free (handlers);
 
                /* Wait for remaining tasks */
                while (gtk_events_pending ())
                        gtk_main_iteration ();
-               
+
                gtk_main_quit ();
        } else {
                ModestMailOperation *mail_op;
@@ -81,7 +81,7 @@ on_idle_exit_modest (gpointer data)
                modest_mail_operation_shutdown (mail_op, modest_runtime_get_account_store ());
                g_object_unref (mail_op);
        }
-               
+
        gdk_threads_leave ();
 
        return FALSE;
@@ -129,8 +129,8 @@ main (int argc, char *argv[])
 
        if (!show_ui_without_top_application_method) {
                g_print ("modest: use 'modest showui' to start from cmdline  with UI\n");
-       }       
-               
+       }
+
        if (!g_thread_supported())
                g_thread_init (NULL);
 
@@ -142,7 +142,7 @@ main (int argc, char *argv[])
                retval = 1;
                goto cleanup;
        }
-       
+
        if (!gtk_init_check (&argc, &argv)) {
                g_printerr ("modest: failed to initialize gtk\n");
                retval = 1;
@@ -157,21 +157,21 @@ main (int argc, char *argv[])
 
        handlers = g_malloc0 (sizeof (MainSignalHandlers));
        /* Connect to the "queue-emtpy" signal */
-       handlers->queue_handler = 
+       handlers->queue_handler =
                g_signal_connect (modest_runtime_get_mail_operation_queue (),
                                  "queue-empty",
                                  G_CALLBACK (on_queue_empty),
                                  handlers);
 
        /* Connect to the "window-list-emtpy" signal */
-       handlers->window_list_handler = 
+       handlers->window_list_handler =
                g_signal_connect (modest_runtime_get_window_mgr (),
                                  "window-list-empty",
                                  G_CALLBACK (on_window_list_empty),
                                  handlers);
 
        /* Connect to the "password-requested" signal */
-       handlers->get_password_handler = 
+       handlers->get_password_handler =
                g_signal_connect (modest_runtime_get_account_store (),
                                  "password_requested",
                                  G_CALLBACK (modest_ui_actions_on_password_requested),
@@ -185,42 +185,19 @@ main (int argc, char *argv[])
         */
        if (show_ui_without_top_application_method) {
                ModestWindow *window;
+               ModestWindowMgr *mgr;
 
-#ifdef MODEST_TOOLKIT_HILDON2
-               ModestAccountMgr *mgr;
-               GSList *account_names;
-               gint count;
-
-               mgr = modest_runtime_get_account_mgr ();
-               account_names = modest_account_mgr_account_names (mgr,TRUE);
-               count = g_slist_length (account_names);
-
-               if (count > 1) {
-                       window = MODEST_WINDOW (modest_accounts_window_new ());
-               } else {
-                       window = MODEST_WINDOW (modest_folder_window_new (NULL));
-                       if (count == 1)
-                               modest_folder_window_set_account (MODEST_FOLDER_WINDOW (window),
-                                                                 account_names->data);
-               }
-               modest_account_mgr_free_account_names (account_names);
-               modest_window_mgr_register_window (modest_runtime_get_window_mgr (), window, NULL);
-               gtk_widget_show (GTK_WIDGET (window));
-#else
-
-               /* this will create & register the window */
-               window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), 
-                                                           TRUE);
+               mgr = modest_runtime_get_window_mgr();
+               window = modest_window_mgr_show_initial_window (mgr);
                if (!window) {
                        g_printerr ("modest: failed to get main window instance\n");
                        retval = 1;
                        goto cleanup;
                }
-#endif
                /* Remove new mail notifications if exist */
                modest_platform_remove_new_mail_notifications (FALSE);
        }
-       
+
        gtk_main ();
 
 cleanup:
index 6750eb6..b06ad4b 100644 (file)
 #include "modest-account-mgr-helpers.h"
 #include "modest-mail-operation.h"
 #include "modest-text-utils.h"
-
-#ifdef MODEST_HAVE_EASYSETUP
-#ifdef MODEST_TOOLKIT_HILDON2
-#include "modest-easysetup-wizard-dialog.h"
-#else
-#include "easysetup/modest-easysetup-wizard-dialog.h"
-#endif
-#endif /* MODEST_HAVE_EASYSETUP */
-
 #include <modest-widget-memory.h>
 #include <tny-error.h>
 #include <tny-simple-list.h>
@@ -653,19 +644,19 @@ modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
 }
 
 void
-modest_ui_actions_on_accounts (GtkAction *action, 
+modest_ui_actions_on_accounts (GtkAction *action,
                               ModestWindow *win)
 {
        /* This is currently only implemented for Maemo */
        if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
-               if (!modest_ui_actions_run_account_setup_wizard (win)) 
+               if (!modest_ui_actions_run_account_setup_wizard (win))
                        g_debug ("%s: wizard was already running", __FUNCTION__);
-               
+
                return;
        } else {
                /* Show the list of accounts */
                GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
-               
+
                /* The accounts dialog must be modal */
                modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
                modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win)); 
@@ -680,7 +671,7 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
         * possiblities.
         */
 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
-       
+
        /* Create the window if necessary: */
        GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
        modest_connection_specific_smtp_window_fill_with_connections (
index 6da29ad..39ff23f 100644 (file)
@@ -66,6 +66,7 @@ static gboolean modest_window_mgr_find_registered_header_default (ModestWindowMg
                                                                  TnyHeader *header,
                                                                  ModestWindow **win);
 static GList *modest_window_mgr_get_window_list_default (ModestWindowMgr *self);
+static ModestWindow *modest_window_mgr_show_initial_window_default (ModestWindowMgr *self);
 
 /* list my signals  */
 enum {
@@ -145,6 +146,7 @@ modest_window_mgr_class_init (ModestWindowMgrClass *klass)
        mgr_class->close_all_windows = modest_window_mgr_close_all_windows_default;
        mgr_class->find_registered_header = modest_window_mgr_find_registered_header_default;
        mgr_class->get_window_list = modest_window_mgr_get_window_list_default;
+       mgr_class->show_initial_window = modest_window_mgr_show_initial_window_default;
 
        g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate));
 
@@ -805,7 +807,7 @@ modest_window_mgr_get_msg_view_window (ModestWindowMgr *self)
        return result;
 }
 
-void           
+void
 modest_window_mgr_register_banner (ModestWindowMgr *self)
 {
        ModestWindowMgrPrivate *priv;
@@ -814,10 +816,9 @@ modest_window_mgr_register_banner (ModestWindowMgr *self)
        priv = MODEST_WINDOW_MGR_GET_PRIVATE (self);
 
        priv->banner_counter++;
-       
 }
 
-void           
+void
 modest_window_mgr_unregister_banner (ModestWindowMgr *self)
 {
        ModestWindowMgrPrivate *priv;
@@ -829,3 +830,34 @@ modest_window_mgr_unregister_banner (ModestWindowMgr *self)
        if (modest_window_mgr_num_windows (self) == 0)
                g_signal_emit (self, signals[WINDOW_LIST_EMPTY_SIGNAL], 0);
 }
+
+ModestWindow *
+modest_window_mgr_show_initial_window (ModestWindowMgr *self)
+{
+       ModestWindow *window = NULL;
+
+       /* Call the children */
+       window = MODEST_WINDOW_MGR_GET_CLASS (self)->show_initial_window (self);
+
+       if (window) {
+               ModestAccountMgr *mgr;
+
+               /* Show the initial window */
+               gtk_widget_show (GTK_WIDGET (window));
+
+               /* If there are no accounts then show the account wizard */
+               mgr = modest_runtime_get_account_mgr();
+               if (!modest_account_mgr_has_accounts (mgr, TRUE))
+                       modest_ui_actions_run_account_setup_wizard (window);
+       }
+
+       return window;
+}
+
+static ModestWindow *
+modest_window_mgr_show_initial_window_default (ModestWindowMgr *self)
+{
+       /* By default it returns the main window creating it if
+          needed */
+       return modest_window_mgr_get_main_window (self, TRUE);
+}
index 0f0bcf0..6c555b4 100644 (file)
@@ -54,8 +54,8 @@ struct _ModestWindowMgrClass {
        GObjectClass parent_class;
 
        /* Virtuals */
-       gboolean              (*register_window)                (ModestWindowMgr *self, 
-                                                                ModestWindow *window, 
+       gboolean              (*register_window)                (ModestWindowMgr *self,
+                                                                ModestWindow *window,
                                                                 ModestWindow *parent);
        void                  (*unregister_window)              (ModestWindowMgr *self,
                                                                 ModestWindow *window);
@@ -73,11 +73,11 @@ struct _ModestWindowMgrClass {
        void                  (*set_modal)                      (ModestWindowMgr *self,
                                                                 GtkWindow *window,
                                                                 GtkWindow *parent);
-       gboolean              (*find_registered_header)         (ModestWindowMgr *self, 
+       gboolean              (*find_registered_header)         (ModestWindowMgr *self,
                                                                 TnyHeader *header,
                                                                 ModestWindow **win);
        GList *               (*get_window_list)                (ModestWindowMgr *self);
-                                        
+       ModestWindow *        (*show_initial_window)            (ModestWindowMgr *self);
 
        /* Signals */
        void (*window_list_empty) (ModestWindowMgr *self);
@@ -379,8 +379,20 @@ GtkWidget *   modest_window_mgr_get_msg_view_window (ModestWindowMgr *self);
  * Returns: a #ModestMsgEditWindow
  */
 GtkWidget *   modest_window_mgr_get_msg_edit_window (ModestWindowMgr *self);
-       
+
+/**
+ * modest_window_mgr_show_initial_window:
+ * @self: a #ModestWindowMgr
+ *
+ * This function determines which is the window that should be
+ * initially launched. After that it shows that window. If there is no
+ * account available this function also launches the account setup
+ * wizard.
+ *
+ * Returns: the initial window. NULL if something goes wrong
+ **/
+ModestWindow* modest_window_mgr_show_initial_window (ModestWindowMgr *self);
+
 G_END_DECLS
 
 #endif /* __MODEST_WINDOW_MGR_H__ */
-