Cancel account operations on disposing folder window.
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 1 Oct 2009 15:11:02 +0000 (17:11 +0200)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 7 Oct 2009 09:25:58 +0000 (11:25 +0200)
src/hildon2/modest-folder-window.c
src/widgets/modest-folder-view.c
src/widgets/modest-folder-view.h

index ff85b6b..3b7604a 100644 (file)
@@ -47,6 +47,7 @@
 #include <hildon/hildon-banner.h>
 #include <hildon/hildon-button.h>
 #include <tny-account-store-view.h>
+#include <tny-gtk-folder-list-store.h>
 #include <modest-header-window.h>
 #include <modest-ui-dimming-rules.h>
 #include <modest-ui-dimming-manager.h>
@@ -65,6 +66,7 @@ typedef enum {
 static void modest_folder_window_class_init  (ModestFolderWindowClass *klass);
 static void modest_folder_window_init        (ModestFolderWindow *obj);
 static void modest_folder_window_finalize    (GObject *obj);
+static void modest_folder_window_dispose     (GObject *obj);
 
 static void connect_signals (ModestFolderWindow *self);
 static void modest_folder_window_disconnect_signals (ModestWindow *self);
@@ -167,6 +169,7 @@ modest_folder_window_class_init (ModestFolderWindowClass *klass)
 
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_folder_window_finalize;
+       gobject_class->dispose = modest_folder_window_dispose;
 
        g_type_class_add_private (gobject_class, sizeof(ModestFolderWindowPrivate));
        
@@ -215,6 +218,41 @@ modest_folder_window_finalize (GObject *obj)
 }
 
 static void
+modest_folder_window_dispose (GObject *obj)
+{
+       ModestFolderWindowPrivate *priv;
+
+       priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
+       if (priv->folder_view) {
+               TnyList *list;
+
+               list = modest_folder_view_get_model_tny_list (MODEST_FOLDER_VIEW (priv->folder_view));
+
+               if (list) {
+                       TnyIterator *iter;
+
+                       iter = tny_list_create_iterator (list);
+                       while (!tny_iterator_is_done (iter)) {
+                               GObject *item = tny_iterator_get_current (iter);
+
+                               if (TNY_IS_ACCOUNT (item)) {
+                                       if (TNY_IS_FOLDER_STORE (item) && 
+                                           modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (item))) {
+                                               tny_account_cancel (TNY_ACCOUNT (item));
+                                       }
+                               }
+                               g_object_unref (item);
+                               tny_iterator_next (iter);
+                       }
+                       g_object_unref (iter);
+               }
+               g_object_unref (list);
+       }       
+
+       G_OBJECT_CLASS(parent_class)->dispose (obj);
+}
+
+static void
 modest_folder_window_disconnect_signals (ModestWindow *self)
 {
        ModestFolderWindowPrivate *priv;
index c0f7598..bed885b 100644 (file)
@@ -4333,3 +4333,21 @@ on_activity_changed (TnyGtkFolderListStore *store,
                       activity);
 }
 #endif
+
+TnyList *
+modest_folder_view_get_model_tny_list (ModestFolderView *self)
+{
+       GtkTreeModel *model;
+       TnyList *ret_value;
+
+       ret_value = NULL;
+       model = NULL;
+
+       if (get_inner_models (MODEST_FOLDER_VIEW (self), NULL, NULL, (GtkTreeModel **) &model)) {
+               ret_value = TNY_LIST (model);
+               g_object_ref (ret_value);
+       }
+
+       return ret_value;
+
+}
index 3c475ff..1b098aa 100644 (file)
@@ -371,6 +371,16 @@ void modest_folder_view_show_message_count (ModestFolderView *self,
  */
 gboolean modest_folder_view_get_activity (ModestFolderView *self);
 
+/**
+ * modest_folder_view_get_model_tny_list:
+ * @self: a #ModestFolderView
+ *
+ * obtains the #TnyList model containing the accounts in the folder view.
+ *
+ * Returns: a caller owner #TnyList
+ */
+TnyList *modest_folder_view_get_model_tny_list (ModestFolderView *self);
+
 G_END_DECLS
 
 #endif /* __MODEST_FOLDER_VIEW_H__ */