Some debug output to help me with testing.
[modest] / src / widgets / modest-folder-view.c
index af6cc94..80870b6 100644 (file)
@@ -41,6 +41,7 @@
 #include <tny-folder.h>
 #include <tny-camel-folder.h>
 #include <tny-simple-list.h>
+#include <modest-tny-account.h>
 #include <modest-tny-folder.h>
 #include <modest-tny-local-folders-account.h>
 #include <modest-tny-outbox-account.h>
@@ -249,6 +250,59 @@ modest_folder_view_class_init (ModestFolderViewClass *klass)
                              G_TYPE_NONE, 1, G_TYPE_STRING);
 }
 
+static gboolean on_model_foreach_set_name(GtkTreeModel *model, GtkTreePath *path,  GtkTreeIter *iter, gpointer data)
+{
+       GObject *instance = NULL;
+       
+       gtk_tree_model_get (model, iter,
+                           TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+                           -1);
+                           
+       if (!instance)
+               return FALSE; /* keep walking */
+                       
+       if (!TNY_IS_ACCOUNT (instance)) {
+               g_object_unref (instance);
+               return FALSE; /* keep walking */        
+       }    
+       
+       /* Check if this is the looked-for account: */
+       TnyAccount *this_account = TNY_ACCOUNT (instance);
+       TnyAccount *account = TNY_ACCOUNT (data);
+       
+       const gchar *this_account_id = tny_account_get_id(this_account);
+       const gchar *account_id = tny_account_get_id(account);
+       if (this_account_id && account_id && 
+               (strcmp (this_account_id, account_id) == 0)) {
+                       
+               /* Tell the model that the data has changed, so that
+                * it calls the cell_data_func callbacks again: */
+               gtk_tree_model_row_changed (model, path, iter);
+               
+               g_object_unref (instance);
+               return TRUE; /* stop walking */
+       }
+       
+       g_object_unref (instance);
+       return FALSE; /* keep walking */
+}
+
+void on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
+{
+       printf ("DEBUG: %s: account name=%s\n", __FUNCTION__, tny_account_get_name (TNY_ACCOUNT(account)));
+
+       ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+       
+       /* If this has been called then it means that the account name has 
+        * changed, so we tell the model that the data has changed, so that 
+        * it calls the cell_data_func callbacks again: */
+        GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+        if (!model)
+               return;
+        
+        gtk_tree_model_foreach(model, on_model_foreach_set_name, self);
+}
+
 static void
 text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                 GtkTreeModel *tree_model,  GtkTreeIter *iter,  gpointer data)
@@ -281,8 +335,8 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                return;
        }
 
-       
-       priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (data);
+       ModestFolderView *self = MODEST_FOLDER_VIEW (data);
+       priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (self);
        
        gchar *item_name = NULL;
        gint item_weight = 400;
@@ -318,7 +372,7 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                if (modest_tny_account_is_virtual_local_folders (
                                TNY_ACCOUNT (instance))) {
                        item_name = g_strdup (priv->local_account_name);
-                       item_weight = 400;
+                       item_weight = 800;
                } else {
                        item_name = g_strdup (fname);
                        item_weight = 800;
@@ -343,6 +397,14 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                
        }
        
+       /* If it is a Memory card account, make sure that we have the correct name: */
+       if (TNY_IS_STORE_ACCOUNT (instance) && 
+               modest_tny_account_is_memory_card_account (TNY_ACCOUNT (instance))) {
+               /* Get the account name asynchronously: */
+               modest_tny_account_get_mmc_account_name (TNY_STORE_ACCOUNT (instance), 
+                       on_get_mmc_account_name, self);
+       }
+                       
        g_object_unref (G_OBJECT (instance));
        g_free (fname);
 }
@@ -573,6 +635,10 @@ modest_folder_view_finalize (GObject *obj)
        }
 
        if (priv->cur_folder_store) {
+               if (TNY_IS_FOLDER(priv->cur_folder_store))
+                       tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), TRUE, NULL);
+                       /* expunge the message */
+
                g_object_unref (priv->cur_folder_store);
                priv->cur_folder_store = NULL;
        }
@@ -708,7 +774,13 @@ modest_folder_view_on_map (ModestFolderView *self,
        /* This won't happen often */
        if (G_UNLIKELY (priv->reselect)) {
                /* Select the first inbox or the local account if not found */
-               modest_folder_view_select_first_inbox_or_local (self);
+
+               /* TODO: this could cause a lock at startup, so we
+                  comment it for the moment. We know that this will
+                  be a bug, because the INBOX is not selected, but we
+                  need to rewrite some parts of Modest to avoid the
+                  deathlock situation */
+/*             modest_folder_view_select_first_inbox_or_local (self); */
                priv->reselect = FALSE;
        }
        return FALSE;
@@ -843,7 +915,11 @@ modest_folder_view_update_model (ModestFolderView *self,
        /* Notify that there is no folder selected */
        g_signal_emit (G_OBJECT(self), 
                       signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
-                      NULL, TRUE);
+                      NULL, FALSE);
+       if (priv->cur_folder_store) {
+               g_object_unref (priv->cur_folder_store);
+               priv->cur_folder_store = NULL;
+       }
 
        /* FIXME: the local accounts are not shown when the query
           selects only the subscribed folders. */
@@ -939,6 +1015,10 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        
        /* Current folder was unselected */
        if (priv->cur_folder_store) {
+               if (TNY_IS_FOLDER(priv->cur_folder_store))
+                       tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), TRUE, NULL);
+               /* expunge the message */
+
                g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
                               priv->cur_folder_store, FALSE);
                g_object_unref (priv->cur_folder_store);
@@ -1362,9 +1442,18 @@ on_drag_data_received (GtkWidget *widget,
                   won't longer exist. We can not wait for the end of
                   the operation, because the operation won't start if
                   the folder is in use */
-               if (source_widget == widget)
+               if (source_widget == widget) {
+                       ModestFolderViewPrivate *priv;
+
+                       priv = MODEST_FOLDER_VIEW_GET_PRIVATE (widget);
+                       if (priv->cur_folder_store) {
+                               g_object_unref (priv->cur_folder_store);
+                               priv->cur_folder_store = NULL;
+                       }
+
                        g_signal_emit (G_OBJECT (widget), 
-                                      signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0, NULL, TRUE);
+                                      signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0, NULL, FALSE);
+               }
        }
 
        /* Check if the get_data failed */