Modified the signature of the connection changed handler
authorSergio Villar Senin <svillar@igalia.com>
Wed, 31 Jan 2007 16:04:49 +0000 (16:04 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 31 Jan 2007 16:04:49 +0000 (16:04 +0000)
Block handlers when pressing the button in the connection changed handler
Removed the subscription handling code in the folder view widget

pmo-trunk-r769

src/modest-runtime.c
src/modest-ui-actions.h
src/modest-ui-priv.h
src/modest-ui.c
src/widgets/modest-folder-view.c

index c51fbd6..91fd637 100644 (file)
@@ -118,7 +118,7 @@ modest_runtime_init (void)
        debug_logging_init();
 
        g_thread_init(NULL);
        debug_logging_init();
 
        g_thread_init(NULL);
-       gdk_threads_init (); 
+       gdk_threads_init ();
 
        my_singletons = modest_singletons_new ();
        if (!my_singletons) {
 
        my_singletons = modest_singletons_new ();
        if (!my_singletons) {
index 64eb000..afe204d 100644 (file)
@@ -66,10 +66,6 @@ void     _modest_ui_actions_on_folder_selection_changed (ModestFolderView *folde
                                                         gboolean selected,
                                                         ModestMainWindow *main_window);
 
                                                         gboolean selected,
                                                         ModestMainWindow *main_window);
 
-void     _modest_ui_actions_on_connection_changed       (TnyDevice *device, 
-                                                        gboolean online,
-                                                        ModestMainWindow *main_window);
-
 void     _modest_ui_actions_on_online_toggle_toggled    (GtkToggleButton *toggle,
                                                         ModestMainWindow *main_window);
 
 void     _modest_ui_actions_on_online_toggle_toggled    (GtkToggleButton *toggle,
                                                         ModestMainWindow *main_window);
 
index ed631e0..60d122b 100644 (file)
@@ -41,6 +41,7 @@ typedef struct _ModestUIPrivate ModestUIPrivate;
 struct _ModestUIPrivate {
        ModestWindow         *main_window;
        GtkUIManager         *ui_manager;
 struct _ModestUIPrivate {
        ModestWindow         *main_window;
        GtkUIManager         *ui_manager;
+       guint                 toggle_button_signal;
 };
 
 G_END_DECLS
 };
 
 G_END_DECLS
index 9db7ce6..cd09c1e 100644 (file)
@@ -99,8 +99,13 @@ static void     reply_forward          (GtkWidget *widget,
 static gchar*   ask_for_folder_name    (GtkWindow *parent_window,
                                        const gchar *title);
 
 static gchar*   ask_for_folder_name    (GtkWindow *parent_window,
                                        const gchar *title);
 
-static void     _modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, 
-                                                        gpointer user_data);
+static void     _modest_ui_actions_on_connection_changed    (TnyDevice *device,
+                                                            gboolean online,
+                                                            ModestUI *modest_ui);
+
+
+static void     _modest_ui_actions_on_accounts_reloaded     (TnyAccountStore *store, 
+                                                            gpointer user_data);
 
 GType
 modest_ui_get_type (void)
 
 GType
 modest_ui_get_type (void)
@@ -361,10 +366,12 @@ connect_signals (ModestUI *self)
        /* Device */
        g_signal_connect (G_OBJECT(device), "connection_changed",
                          G_CALLBACK(_modest_ui_actions_on_connection_changed), 
        /* Device */
        g_signal_connect (G_OBJECT(device), "connection_changed",
                          G_CALLBACK(_modest_ui_actions_on_connection_changed), 
-                         priv->main_window);
-       g_signal_connect (G_OBJECT(toggle), "toggled",
-                         G_CALLBACK(_modest_ui_actions_on_online_toggle_toggled),
-                         priv->main_window);
+                         self);
+
+       priv->toggle_button_signal=
+               g_signal_connect (G_OBJECT(toggle), "toggled",
+                                 G_CALLBACK(_modest_ui_actions_on_online_toggle_toggled),
+                                 priv->main_window);
                
        /* Destroy window */
        g_signal_connect (G_OBJECT(priv->main_window), 
                
        /* Destroy window */
        g_signal_connect (G_OBJECT(priv->main_window), 
@@ -375,7 +382,7 @@ connect_signals (ModestUI *self)
        /* Init toggle in correct state */
        _modest_ui_actions_on_connection_changed (device,
                                                 tny_device_is_online (device),
        /* Init toggle in correct state */
        _modest_ui_actions_on_connection_changed (device,
                                                 tny_device_is_online (device),
-                                                MODEST_MAIN_WINDOW (priv->main_window));
+                                                self);
 }
 
 
 }
 
 
@@ -890,18 +897,22 @@ statusbar_push (ModestWidgetFactory *factory, guint context_id, const gchar *msg
 }
 /****************************************************************************/
 
 }
 /****************************************************************************/
 
-void
-_modest_ui_actions_on_connection_changed (TnyDevice *device, gboolean online,
-                                         ModestMainWindow *main_window)
+static void
+_modest_ui_actions_on_connection_changed (TnyDevice *device, 
+                                         gboolean online,
+                                         ModestUI *self)
 {
        GtkWidget *online_toggle;
        ModestHeaderView *header_view;
        ModestWidgetFactory *widget_factory;
 {
        GtkWidget *online_toggle;
        ModestHeaderView *header_view;
        ModestWidgetFactory *widget_factory;
+       ModestUIPrivate *priv;
        GtkWidget *icon;
        const gchar *icon_name;
 
        g_return_if_fail (device);
        GtkWidget *icon;
        const gchar *icon_name;
 
        g_return_if_fail (device);
-       g_return_if_fail (main_window);
+       g_return_if_fail (self);
+
+       priv = MODEST_UI_GET_PRIVATE (self);
 
        icon_name = online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT;
        icon      = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
 
        icon_name = online ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT;
        icon      = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
@@ -910,20 +921,26 @@ _modest_ui_actions_on_connection_changed (TnyDevice *device, gboolean online,
        header_view   = modest_widget_factory_get_header_view (widget_factory);
        online_toggle = modest_widget_factory_get_online_toggle (widget_factory);
 
        header_view   = modest_widget_factory_get_header_view (widget_factory);
        online_toggle = modest_widget_factory_get_online_toggle (widget_factory);
 
-       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(online_toggle),
-                                     online);
+       /* Block handlers in order to avoid unnecessary calls */
+       g_signal_handler_block (G_OBJECT (online_toggle), priv->toggle_button_signal);
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(online_toggle), online);
+       g_signal_handler_unblock (G_OBJECT (online_toggle), priv->toggle_button_signal);
+
        gtk_button_set_image (GTK_BUTTON(online_toggle), icon);
        statusbar_push (widget_factory, 0, 
                        online ? _("Modest went online") : _("Modest went offline"));
        
        /* If Modest has became online and the header view has a
           header selected then show it */
        gtk_button_set_image (GTK_BUTTON(online_toggle), icon);
        statusbar_push (widget_factory, 0, 
                        online ? _("Modest went online") : _("Modest went offline"));
        
        /* If Modest has became online and the header view has a
           header selected then show it */
-       if (online) {
-               GtkTreeSelection *selected;
+       /* FIXME: there is a race condition if some account needs to
+          ask the user for a password */
 
 
-               selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
-               _modest_header_view_change_selection (selected, header_view);
-       }
+/*     if (online) { */
+/*             GtkTreeSelection *selected; */
+
+/*             selected = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); */
+/*             _modest_header_view_change_selection (selected, header_view); */
+/*     } */
 }
 
 void
 }
 
 void
@@ -953,15 +970,13 @@ _modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,
        gchar *txt, *item;
        gboolean online;
        TnyDevice *device;
        gchar *txt, *item;
        gboolean online;
        TnyDevice *device;
-       TnyPlatformFactory *factory;
        TnyAccountStore *account_store;
 
        item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
 
        /* Get device. Do not ask the platform factory for it, because
           it returns always a new one */
        TnyAccountStore *account_store;
 
        item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
 
        /* Get device. Do not ask the platform factory for it, because
           it returns always a new one */
-       factory = modest_tny_platform_factory_get_instance ();
-       account_store = tny_platform_factory_new_account_store (factory);
+       account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
        device = tny_account_store_get_device (account_store);
 
        if (g_main_depth > 0)   
        device = tny_account_store_get_device (account_store);
 
        if (g_main_depth > 0)   
index 923f4a3..aefadb1 100644 (file)
@@ -56,10 +56,8 @@ static gboolean     update_model             (ModestFolderView *self,
 static gboolean     update_model_empty       (ModestFolderView *self);
 
 static void         on_selection_changed     (GtkTreeSelection *sel, gpointer data);
 static gboolean     update_model_empty       (ModestFolderView *self);
 
 static void         on_selection_changed     (GtkTreeSelection *sel, gpointer data);
-static void         on_subscription_changed  (TnyStoreAccount *store_account, TnyFolder *folder,
-                                             ModestFolderView *self);
-
-static void         modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self);
+/* static void         on_subscription_changed  (TnyStoreAccount *store_account, TnyFolder *folder, */
+/*                                           ModestFolderView *self); */
 
 static gint         cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
                              gpointer user_data);
 
 static gint         cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
                              gpointer user_data);
@@ -76,7 +74,6 @@ struct _ModestFolderViewPrivate {
        TnyFolder           *cur_folder;
 
        gulong               sig1, sig2;
        TnyFolder           *cur_folder;
 
        gulong               sig1, sig2;
-       gulong              *store_accounts_handlers;
        GMutex              *lock;
        GtkTreeSelection    *cur_selection;
        TnyFolderStoreQuery *query;
        GMutex              *lock;
        GtkTreeSelection    *cur_selection;
        TnyFolderStoreQuery *query;
@@ -299,34 +296,6 @@ modest_folder_view_init (ModestFolderView *obj)
 }
 
 static void
 }
 
 static void
-modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self)
-{
-       TnyIterator *iter;
-       ModestFolderViewPrivate *priv;
-       GtkTreeModel *model;
-       GtkTreeModelSort *sortable;
-       gint i = 0;
-
-       sortable = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (self));
-       if (!sortable)
-               return; 
-
-       model = gtk_tree_model_sort_get_model (sortable);
-       if (!model)
-               return; 
-
-       priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (self);  
-       iter = tny_list_create_iterator (TNY_LIST (model));
-       while (!tny_iterator_is_done (iter)) {
-               g_signal_handler_disconnect (G_OBJECT (tny_iterator_get_current (iter)),
-                                            priv->store_accounts_handlers [i++]);
-               tny_iterator_next (iter);
-       }
-       g_object_unref (G_OBJECT (iter));
-}
-
-
-static void
 modest_folder_view_finalize (GObject *obj)
 {
        ModestFolderViewPrivate *priv;
 modest_folder_view_finalize (GObject *obj)
 {
        ModestFolderViewPrivate *priv;
@@ -347,12 +316,6 @@ modest_folder_view_finalize (GObject *obj)
                priv->lock = NULL;
        }
 
                priv->lock = NULL;
        }
 
-       if (priv->store_accounts_handlers) {
-               modest_folder_view_disconnect_store_account_handlers (GTK_TREE_VIEW (obj));
-               g_free (priv->store_accounts_handlers);
-               priv->store_accounts_handlers = NULL;
-       }
-
        if (priv->query) {
                g_object_unref (G_OBJECT (priv->query));
                priv->query = NULL;
        if (priv->query) {
                g_object_unref (G_OBJECT (priv->query));
                priv->query = NULL;
@@ -433,53 +396,12 @@ update_model_empty (ModestFolderView *self)
        g_return_val_if_fail (self, FALSE);
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
 
        g_return_val_if_fail (self, FALSE);
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
 
-       /* Disconnect old handlers */
-       if (priv->store_accounts_handlers) {
-               modest_folder_view_disconnect_store_account_handlers (GTK_TREE_VIEW (self));
-               g_free (priv->store_accounts_handlers);
-               priv->store_accounts_handlers = NULL;
-       }
-
        g_signal_emit (G_OBJECT(self), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
                       NULL, TRUE);
        return TRUE;
 }
 
 
        g_signal_emit (G_OBJECT(self), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
                       NULL, TRUE);
        return TRUE;
 }
 
 
-static void
-update_store_account_handlers (ModestFolderView *self, TnyList *account_list)
-{
-       ModestFolderViewPrivate *priv;
-       TnyIterator *iter;
-       guint len;
-       
-       priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
-
-       /* Listen to subscription changes */
-       len = tny_list_get_length (TNY_LIST (account_list));
-
-       g_assert (priv->store_accounts_handlers == NULL); /* don't leak */
-       priv->store_accounts_handlers = g_malloc0 (sizeof (guint) * len);
-       iter = tny_list_create_iterator (account_list);
-       
-       if (!tny_iterator_is_done (iter)) {
-               gint i = 0;
-
-               do  {
-                       
-                       priv->store_accounts_handlers [i++] =
-                               g_signal_connect (G_OBJECT (tny_iterator_get_current (iter)),
-                                                 "subscription_changed",
-                                                 G_CALLBACK (on_subscription_changed),
-                                                 self);
-                       tny_iterator_next (iter);
-               } while (!tny_iterator_is_done (iter));
-       }
-       g_object_unref (G_OBJECT (iter));       
-}
-
-
-
 /* this feels dirty; any other way to expand all the root items? */
 static void
 expand_root_items (ModestFolderView *self)
 /* this feels dirty; any other way to expand all the root items? */
 static void
 expand_root_items (ModestFolderView *self)
@@ -506,11 +428,12 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
 
        g_return_val_if_fail (account_store, FALSE);
 
 
        g_return_val_if_fail (account_store, FALSE);
 
-       update_model_empty (self);
-
        priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
        
        priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
        
-       model        = tny_gtk_folder_store_tree_model_new (FALSE, NULL);
+       /* Notify that there is no folder selected */
+       update_model_empty (self);
+       
+       model        = tny_gtk_folder_store_tree_model_new (TRUE, NULL);
        account_list = TNY_LIST(model);
 
        tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
        account_list = TNY_LIST(model);
 
        tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
@@ -524,10 +447,11 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
                gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
                                                 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, 
                                                 cmp_rows, NULL, NULL);
                gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
                                                 TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, 
                                                 cmp_rows, NULL, NULL);
+
+               /* Set new model */
                gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
                expand_root_items (self); /* expand all account folders */
        
                gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
                expand_root_items (self); /* expand all account folders */
        
-               update_store_account_handlers (self, account_list);
        }
        
        g_object_unref (model);
        }
        
        g_object_unref (model);
@@ -578,19 +502,19 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
 
 }
 
 
 }
 
-static void 
-on_subscription_changed  (TnyStoreAccount *store_account, 
-                         TnyFolder *folder,
-                         ModestFolderView *self)
-{
-       /* TODO: probably we won't need a full reload, just the store
-          account or even the parent of the folder */
+/* static void  */
+/* on_subscription_changed  (TnyStoreAccount *store_account,  */
+/*                       TnyFolder *folder, */
+/*                       ModestFolderView *self) */
+/* { */
+/*     /\* TODO: probably we won't need a full reload, just the store */
+/*        account or even the parent of the folder *\/ */
 
 
-       ModestFolderViewPrivate *priv;
+/*     ModestFolderViewPrivate *priv; */
 
 
-       priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
-       update_model (self, MODEST_TNY_ACCOUNT_STORE (priv->account_store));
-}
+/*     priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self); */
+/*     update_model (self, MODEST_TNY_ACCOUNT_STORE (priv->account_store)); */
+/* } */
 
 
 gboolean
 
 
 gboolean