* Fixed a reference leak in the main window
authorSergio Villar Senin <svillar@igalia.com>
Tue, 12 Jun 2007 08:09:04 +0000 (08:09 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 12 Jun 2007 08:09:04 +0000 (08:09 +0000)
* The update_model function of the folder view is now public
* The main window now unregisters some signals that was causing a lot of problems
* The Move to dialog now shows contents even if the main window do not exists. Fixes NB#59468

pmo-trunk-r2169

src/modest-main.c
src/modest-ui-actions.c
src/widgets/modest-folder-view.c
src/widgets/modest-window-mgr.c

index 5d048dc..bd59104 100644 (file)
@@ -227,6 +227,7 @@ start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const
        } else {
                ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
                modest_window_mgr_register_window (mgr, win);
+               g_object_unref (win);
        }
        
        gtk_widget_show_all (GTK_WIDGET (win));
index 5dd4f0b..a767534 100644 (file)
@@ -55,6 +55,7 @@
 #include <widgets/modest-account-view-window.h>
 #include <widgets/modest-details-dialog.h>
 #include <widgets/modest-attachments-view.h>
+#include "widgets/modest-folder-view.h"
 #include "widgets/modest-global-settings-dialog.h"
 #include "modest-connection-specific-smtp-window.h"
 #include "modest-account-mgr-helpers.h"
@@ -2519,8 +2520,18 @@ create_move_to_dialog (ModestWindow *win,
 
        /* Create folder view */
        *tree_view = modest_folder_view_new (NULL);
-       gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
-                                gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
+
+       /* It could happen that we're trying to move a message from a
+          window (msg window for example) after the main window was
+          closed, so we can not just get the model of the folder
+          view */
+       if (MODEST_IS_FOLDER_VIEW (folder_view))
+               gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
+                                        gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
+       else
+               modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view), 
+                                                TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
+
        gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
 
        /* Add scroll to dialog */
@@ -2751,8 +2762,11 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
 
        /* Get the folder view */
        main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
-       folder_view = modest_main_window_get_child_widget (main_window,
-                                                          MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       if (main_window)
+               folder_view = modest_main_window_get_child_widget (main_window,
+                                                                  MODEST_WIDGET_TYPE_FOLDER_VIEW);
+       else
+               folder_view = NULL;
 
        /* Create and run the dialog */
        dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);  
@@ -2793,7 +2807,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
                                                         tranasfer_msgs_from_viewer_cb,
                                                         NULL);
                        g_object_unref (G_OBJECT (mail_op));
-               } 
+               }
                g_object_unref (headers);
                g_object_unref (folder_store);
        }
index 2d54403..0cf01ef 100644 (file)
@@ -66,9 +66,6 @@ static void         tny_account_store_view_init (gpointer g,
 static void         modest_folder_view_set_account_store (TnyAccountStoreView *self, 
                                                          TnyAccountStore     *account_store);
 
-static gboolean     update_model           (ModestFolderView *self,
-                                           ModestTnyAccountStore *account_store);
-
 static void         on_selection_changed   (GtkTreeSelection *sel, gpointer data);
 
 static void         on_account_update      (TnyAccountStore *account_store, 
@@ -583,8 +580,8 @@ static void
 on_account_update (TnyAccountStore *account_store, const gchar *account,
                   gpointer user_data)
 {
-       if (!update_model (MODEST_FOLDER_VIEW(user_data), 
-                          MODEST_TNY_ACCOUNT_STORE(account_store)))
+       if (!modest_folder_view_update_model (MODEST_FOLDER_VIEW(user_data), 
+                                             account_store))
                g_printerr ("modest: failed to update model for changes in '%s'",
                            account);
 }
@@ -596,8 +593,7 @@ on_accounts_reloaded   (TnyAccountStore *account_store,
        ModestConf *conf = modest_runtime_get_conf ();
 
        modest_widget_memory_save (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
-       update_model (MODEST_FOLDER_VIEW (user_data), 
-                     MODEST_TNY_ACCOUNT_STORE(account_store));
+       modest_folder_view_update_model (MODEST_FOLDER_VIEW (user_data), account_store);
        modest_widget_memory_restore (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
@@ -705,18 +701,9 @@ filter_row (GtkTreeModel *model,
        return retval;
 }
 
-/*
-static void on_tnylist_accounts_debug_print(gpointer data,  gpointer user_data)
-{
-       TnyAccount* account = TNY_ACCOUNT(data);
-       const gchar *prefix = (const gchar*)(user_data);
-       
-       printf("%s account id=%s\n", prefix, tny_account_get_id (account));
-}
-*/
-
-static gboolean
-update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
+gboolean
+modest_folder_view_update_model (ModestFolderView *self,
+                                TnyAccountStore *account_store)
 {
        ModestFolderViewPrivate *priv;
        GtkTreeModel *model /* , *old_model */;
index 93fce0c..b6ffd3f 100644 (file)
@@ -265,6 +265,10 @@ modest_window_mgr_unregister_window (ModestWindowMgr *self,
                return;
        }
 
+       /* If it's the main window unset it */
+       if (priv->main_window == window)
+               priv->main_window = NULL;
+
        /* Remove from list. Remove the reference to the window */
        g_object_unref (win->data);
        priv->window_list = g_list_remove_link (priv->window_list, win);