* Fixes: #NB55377, #NB55441
authorSergio Villar Senin <svillar@igalia.com>
Wed, 2 May 2007 11:17:53 +0000 (11:17 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 2 May 2007 11:17:53 +0000 (11:17 +0000)
* Added "visible_server_account_id" persistent configuration key to the folder view
* Removed the double treemodel creation in the header view when refreshing

pmo-trunk-r1728

src/modest-widget-memory.c
src/widgets/modest-folder-view.c
src/widgets/modest-folder-view.h
src/widgets/modest-header-view.c

index 6c2ab5b..5fe3735 100644 (file)
@@ -29,7 +29,8 @@
 
 #include <modest-widget-memory.h>
 #include <modest-widget-memory-priv.h>
 
 #include <modest-widget-memory.h>
 #include <modest-widget-memory-priv.h>
-
+#include <modest-runtime.h>
+#include <modest-account-mgr-helpers.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-tny-folder.h>
 #include <widgets/modest-header-view.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-tny-folder.h>
 #include <widgets/modest-header-view.h>
@@ -390,20 +391,69 @@ static gboolean
 save_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
                           const gchar *name)
 {
 save_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
                           const gchar *name)
 {
-       return TRUE; /* FIXME: implement this */
+       gchar *key;
+       const gchar* account_id;
+
+       /* Restore the visible account */
+       key = _modest_widget_memory_get_keyname (name, "visible_server_account_id");
+
+       account_id = modest_folder_view_get_visible_server_account_id (folder_view);
+       if (account_id)
+               modest_conf_set_string (conf, key, account_id, NULL);
+
+       g_free (key);
+
+       return TRUE;
 }
 
 static gboolean
 }
 
 static gboolean
-restore_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
+restore_settings_folder_view (ModestConf *conf, 
+                             ModestFolderView *folder_view,
                              const gchar *name)
 {
                              const gchar *name)
 {
-       return TRUE; /* FIXME: implement this */
+       gchar *key, *account_id;
+
+       /* Restore the visible account */
+       key = _modest_widget_memory_get_keyname (name, "visible_server_account_id");
+
+       if (modest_conf_key_exists (conf, key, NULL)) {
+               account_id = modest_conf_get_string (conf, key, NULL);
+               modest_folder_view_set_visible_server_account_id (folder_view, 
+                                                                 (const gchar *) account_id);
+               g_free (account_id);
+       } else {
+               ModestAccountMgr *mgr;
+               gchar *default_acc;
+
+               /* If there is no visible account id in the
+                  configuration then pick the default account as
+                  visible account */
+               mgr = modest_runtime_get_account_mgr ();
+               default_acc = modest_account_mgr_get_default_account (mgr);
+               if (default_acc) {
+                       ModestAccountData *acc_data;
+                       const gchar *server_acc_id;
+
+                       acc_data = modest_account_mgr_get_account_data (mgr, (const gchar*) default_acc);
+                       server_acc_id = (const gchar *) acc_data->store_account->account_name;
+
+                       modest_conf_set_string (conf, key, server_acc_id, NULL);
+                       modest_folder_view_set_visible_server_account_id (folder_view, server_acc_id);
+
+                       g_free (default_acc);
+               }
+       }
+
+       g_free (key);
+
+       return TRUE;
 }
 
 
 static gboolean
 }
 
 
 static gboolean
-save_settings_msg_view (ModestConf *conf, ModestMsgView *msg_view,
-                          const gchar *name)
+save_settings_msg_view (ModestConf *conf, 
+                       ModestMsgView *msg_view,
+                       const gchar *name)
 {
        return TRUE; /* FIXME: implement this */
 }
 {
        return TRUE; /* FIXME: implement this */
 }
index a698c79..ab63d85 100644 (file)
@@ -50,6 +50,7 @@
 #include <modest-dnd.h>
 #include <modest-platform.h>
 #include <modest-account-mgr-helpers.h>
 #include <modest-dnd.h>
 #include <modest-platform.h>
 #include <modest-account-mgr-helpers.h>
+#include <modest-widget-memory.h>
 
 /* 'private'/'protected' functions */
 static void modest_folder_view_class_init  (ModestFolderViewClass *klass);
 
 /* 'private'/'protected' functions */
 static void modest_folder_view_class_init  (ModestFolderViewClass *klass);
@@ -140,6 +141,7 @@ struct _ModestFolderViewPrivate {
        guint                 timer_expander;
 
        gchar                *local_account_name;
        guint                 timer_expander;
 
        gchar                *local_account_name;
+       gchar                *visible_account_id;
        ModestFolderViewStyle style;
 };
 #define MODEST_FOLDER_VIEW_GET_PRIVATE(o)                      \
        ModestFolderViewStyle style;
 };
 #define MODEST_FOLDER_VIEW_GET_PRIVATE(o)                      \
@@ -449,9 +451,10 @@ modest_folder_view_init (ModestFolderView *obj)
        
        priv->timer_expander = 0;
        priv->account_store  = NULL;
        
        priv->timer_expander = 0;
        priv->account_store  = NULL;
-       priv->cur_folder_store     = NULL;
        priv->query          = NULL;
        priv->style          = MODEST_FOLDER_VIEW_STYLE_SHOW_ALL;
        priv->query          = NULL;
        priv->style          = MODEST_FOLDER_VIEW_STYLE_SHOW_ALL;
+       priv->cur_folder_store   = NULL;
+       priv->visible_account_id = NULL;
 
        /* Initialize the local account name */
        conf = modest_runtime_get_conf();
 
        /* Initialize the local account name */
        conf = modest_runtime_get_conf();
@@ -463,6 +466,9 @@ modest_folder_view_init (ModestFolderView *obj)
        /* Setup drag and drop */
        setup_drag_and_drop (GTK_TREE_VIEW(obj));
 
        /* Setup drag and drop */
        setup_drag_and_drop (GTK_TREE_VIEW(obj));
 
+       /* Restore conf */
+       modest_widget_memory_restore (conf, G_OBJECT (obj), "folder-view");
+
        /* Connect signals */
        g_signal_connect (G_OBJECT (obj), 
                          "key-press-event", 
        /* Connect signals */
        g_signal_connect (G_OBJECT (obj), 
                          "key-press-event", 
@@ -522,6 +528,7 @@ modest_folder_view_finalize (GObject *obj)
                g_signal_handler_disconnect (G_OBJECT(sel), priv->changed_signal);
 
        g_free (priv->local_account_name);
                g_signal_handler_disconnect (G_OBJECT(sel), priv->changed_signal);
 
        g_free (priv->local_account_name);
+       g_free (priv->visible_account_id);
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -660,28 +667,20 @@ filter_row (GtkTreeModel *model,
                            -1);
 
        if (type == TNY_FOLDER_TYPE_ROOT) {
                            -1);
 
        if (type == TNY_FOLDER_TYPE_ROOT) {
-               ModestAccountData *acc_data;
                TnyAccount *acc;
                const gchar *account_id;
                TnyAccount *acc;
                const gchar *account_id;
-               ModestAccountMgr *mgr;
 
                acc = TNY_ACCOUNT (instance);
 
                acc = TNY_ACCOUNT (instance);
-               account_id = tny_account_get_id (acc); /* Non human-readable name, not the title */
-               mgr = modest_runtime_get_account_mgr ();
-               
-               /* TODO: This does not work because acc is the _server_account, 
-                * and this code assumes that it is the normal account, which uses a server account.
-                * Maybe we need some way to get the parent account from the server account.
-                */
-               acc_data = modest_account_mgr_get_account_data (mgr, account_id);
-               if (acc_data) {
-                       if (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) &&
-                           strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
-                               /* Show only the default account */
-                               if (!acc_data->is_default)
-                                       retval = FALSE;
-                       }
-                       modest_account_mgr_free_account_data (mgr, acc_data);
+               account_id = tny_account_get_id (acc);
+
+               if (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) &&
+                   strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) { 
+                       ModestFolderViewPrivate *priv;
+                       
+                       /* Show only the visible account id */
+                       priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data);
+                       if (priv->visible_account_id && strcmp (account_id, priv->visible_account_id))
+                               retval = FALSE;
                }
        }
 
                }
        }
 
@@ -731,7 +730,7 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
                        filter_model = gtk_tree_model_filter_new (sortable, NULL);
                        gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model),
                                                                filter_row,
                        filter_model = gtk_tree_model_filter_new (sortable, NULL);
                        gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (filter_model),
                                                                filter_row,
-                                                               NULL,
+                                                               self,
                                                                NULL);
                }
 
                                                                NULL);
                }
 
@@ -1403,25 +1402,27 @@ on_configuration_key_changed (ModestConf* conf,
 {
        ModestFolderViewPrivate *priv;
 
 {
        ModestFolderViewPrivate *priv;
 
-       if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME))
+       if (!key)
                return;
 
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
 
                return;
 
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
 
-       g_free (priv->local_account_name);
+       if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) {
+               g_free (priv->local_account_name);
 
 
-       if (event == MODEST_CONF_EVENT_KEY_UNSET)
-               priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
-       else
-               priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(),
-                                                                  MODEST_CONF_DEVICE_NAME, NULL);
+               if (event == MODEST_CONF_EVENT_KEY_UNSET)
+                       priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
+               else
+                       priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(),
+                                                                          MODEST_CONF_DEVICE_NAME, NULL);
 
 
-       /* Force a redraw */
+               /* Force a redraw */
 #if GTK_CHECK_VERSION(2, 8, 0) /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
 #if GTK_CHECK_VERSION(2, 8, 0) /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
-       GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 
-                                               TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
-       gtk_tree_view_column_queue_resize (tree_column);
+               GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 
+                                                                           TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
+               gtk_tree_view_column_queue_resize (tree_column);
 #endif
 #endif
+       }
 }
 
 void 
 }
 
 void 
@@ -1436,3 +1437,35 @@ modest_folder_view_set_style (ModestFolderView *self,
 
        priv->style = style;
 }
 
        priv->style = style;
 }
+
+void
+modest_folder_view_set_visible_server_account_id (ModestFolderView *self,
+                                                 const gchar *account_id)
+{
+       ModestFolderViewPrivate *priv;
+       ModestConf *conf;
+
+       g_return_if_fail (self);
+       
+       priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+       if (priv->visible_account_id)
+               g_free (priv->visible_account_id);
+       priv->visible_account_id = g_strdup (account_id);
+
+       /* Save preferences */
+       conf = modest_runtime_get_conf ();
+       modest_widget_memory_save (conf, G_OBJECT (self), "folder-view");
+}
+
+const gchar *
+modest_folder_view_get_visible_server_account_id (ModestFolderView *self)
+{
+       ModestFolderViewPrivate *priv;
+
+       g_return_val_if_fail (self, NULL);
+       
+       priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+       return (const gchar *) priv->visible_account_id;
+}
index 4cffc5d..d275837 100644 (file)
@@ -159,6 +159,29 @@ const gchar* modest_folder_view_get_selected_display_name (ModestFolderView *sel
 void         modest_folder_view_set_style         (ModestFolderView *self,
                                                   ModestFolderViewStyle style);
 
 void         modest_folder_view_set_style         (ModestFolderView *self,
                                                   ModestFolderViewStyle style);
 
+/**
+ * modest_folder_view_set_visible_server_account_id:
+ * @self: a #ModestFolderView
+ * @account_id: the remote server account id
+ * 
+ * sets the server account id (value returned by tny_account_get_id())
+ * to the string passed as argument. The remote server with the
+ * specified id will be the unique visible account if the folder view
+ * is configured in MODEST_FOLDER_VIEW_STYLE_SHOW_ONE
+ **/
+void         modest_folder_view_set_visible_server_account_id (ModestFolderView *self,
+                                                              const gchar *account_id);
+
+/**
+ * modest_folder_view_get_visible_server_account_id:
+ * @self: a #ModestFolderView
+ * 
+ * gets the account id of the currently visible server account id
+ * 
+ * Return value: the visible server account id or NULL if none set
+ **/
+const gchar* modest_folder_view_get_visible_server_account_id (ModestFolderView *self);
+
 G_END_DECLS
 
 #endif /* __MODEST_FOLDER_VIEW_H__ */
 G_END_DECLS
 
 #endif /* __MODEST_FOLDER_VIEW_H__ */
index 8d5f2a4..d997f30 100644 (file)
@@ -74,8 +74,11 @@ struct _ModestHeaderViewPrivate {
 
        TnyFolderMonitor     *monitor;
        GMutex               *monitor_lock;
 
        TnyFolderMonitor     *monitor;
        GMutex               *monitor_lock;
-       gint sort_colid[2][TNY_FOLDER_TYPE_NUM];
-       gint sort_type[2][TNY_FOLDER_TYPE_NUM];
+
+       gint                  sort_colid[2][TNY_FOLDER_TYPE_NUM];
+       gint                  sort_type[2][TNY_FOLDER_TYPE_NUM];
+
+
 };
 
 #define MODEST_HEADER_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
 };
 
 #define MODEST_HEADER_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -209,7 +212,7 @@ static void
 remove_all_columns (ModestHeaderView *obj)
 {
        GList *columns, *cursor;
 remove_all_columns (ModestHeaderView *obj)
 {
        GList *columns, *cursor;
-
+       
        columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(obj));
 
        for (cursor = columns; cursor; cursor = cursor->next)
        columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(obj));
 
        for (cursor = columns; cursor; cursor = cursor->next)
@@ -395,7 +398,6 @@ modest_header_view_set_columns (ModestHeaderView *self, const GList *columns, Tn
                gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);              
        }       
        
                gtk_tree_view_append_column (GTK_TREE_VIEW(self), column);              
        }       
        
-       
        return TRUE;
 }
 
        return TRUE;
 }
 
@@ -444,7 +446,7 @@ modest_header_view_finalize (GObject *obj)
                g_object_unref (G_OBJECT (priv->folder));
                priv->folder   = NULL;
        }
                g_object_unref (G_OBJECT (priv->folder));
                priv->folder   = NULL;
        }
-       
+
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
@@ -699,68 +701,6 @@ modest_header_view_set_model (GtkTreeView *header_view, GtkTreeModel *model)
        return;
 }
 
        return;
 }
 
-static void
-on_progress_changed (ModestMailOperation *mail_op,
-                    ModestHeaderView *self)
-{
-       TnyFolderType type;
-       GtkTreeModel *sortable; 
-       ModestHeaderViewPrivate *priv;
-       GList *cols, *cursor;
-       TnyList *headers;
-       guint sort_colid;
-       GtkSortType sort_type;
-
-       if (!modest_mail_operation_is_finished (mail_op))
-               return;
-
-       if (modest_mail_operation_get_error (mail_op))
-               return;
-       
-       priv = MODEST_HEADER_VIEW_GET_PRIVATE(self);
-
-       headers = TNY_LIST (tny_gtk_header_list_model_new ());
-
-       tny_gtk_header_list_model_set_folder (TNY_GTK_HEADER_LIST_MODEL(headers),
-                                             priv->folder, TRUE);
-
-       sortable = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL(headers));
-       g_object_unref (G_OBJECT (headers));
-       
-       /* install our special sorting functions */
-       cursor = cols = gtk_tree_view_get_columns (GTK_TREE_VIEW(self));
-       while (cursor) {
-               gint col_id = GPOINTER_TO_INT (g_object_get_data(G_OBJECT(cursor->data),
-                                                                MODEST_HEADER_VIEW_COLUMN));
-               gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(sortable),
-                                                col_id,
-                                                (GtkTreeIterCompareFunc) cmp_rows,
-                                                cursor->data, NULL);
-               cursor = g_list_next(cursor);
-       }
-       g_list_free (cols);
-
-       /* Restore sort column id */
-       type  = modest_tny_folder_guess_folder_type (priv->folder);
-       sort_colid = modest_header_view_get_sort_column_id (self, type); 
-       sort_type = modest_header_view_get_sort_type (self, type); 
-       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
-                                             sort_colid,
-                                             sort_type);
-
-       /* Set new model */
-       modest_header_view_set_model (GTK_TREE_VIEW (self), sortable);
-       g_object_unref (G_OBJECT (sortable));
-
-       /* Add a folder observer */
-       g_mutex_lock (priv->monitor_lock);
-       priv->monitor = TNY_FOLDER_MONITOR (tny_folder_monitor_new (priv->folder));
-       tny_folder_monitor_add_list (priv->monitor, TNY_LIST (headers));
-       tny_folder_monitor_start (priv->monitor);
-       g_mutex_unlock (priv->monitor_lock);
-
-}
-
 TnyFolder*
 modest_header_view_get_folder (ModestHeaderView *self)
 {
 TnyFolder*
 modest_header_view_get_folder (ModestHeaderView *self)
 {
@@ -817,7 +757,7 @@ modest_header_view_set_folder_intern (ModestHeaderView *self, TnyFolder *folder)
                                                 cursor->data, NULL);
                cursor = g_list_next(cursor);
        }
                                                 cursor->data, NULL);
                cursor = g_list_next(cursor);
        }
-       g_list_free (cols);
+       g_list_free (cols);     
 
        /* Restore sort column id */
        type  = modest_tny_folder_guess_folder_type (folder);
 
        /* Restore sort column id */
        type  = modest_tny_folder_guess_folder_type (folder);
@@ -916,6 +856,7 @@ modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder)
        if (folder) {
                ModestMailOperation *mail_op;
 
        if (folder) {
                ModestMailOperation *mail_op;
 
+               /* Set folder in the model */
                modest_header_view_set_folder_intern (self, folder);
 
                /* Pick my reference. Nothing to do with the mail operation */
                modest_header_view_set_folder_intern (self, folder);
 
                /* Pick my reference. Nothing to do with the mail operation */
@@ -929,10 +870,6 @@ modest_header_view_set_folder (ModestHeaderView *self, TnyFolder *folder)
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                                 mail_op);
 
-               /* Register a mail operation observer */
-               g_signal_connect (mail_op, "progress-changed", 
-                                 G_CALLBACK (on_progress_changed), self);
-
                /* Refresh the folder asynchronously */
                modest_mail_operation_refresh_folder (mail_op, folder);
 
                /* Refresh the folder asynchronously */
                modest_mail_operation_refresh_folder (mail_op, folder);
 
@@ -1050,7 +987,7 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
        gint sort_colid;
        static int counter = 0;
 
        gint sort_colid;
        static int counter = 0;
 
-       g_return_val_if_fail (G_IS_OBJECT(user_data), 0);
+       g_return_val_if_fail (GTK_IS_TREE_VIEW_COLUMN(user_data), 0);
        col_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(user_data), MODEST_HEADER_VIEW_COLUMN));
        
        if (!(++counter % 100)) {
        col_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(user_data), MODEST_HEADER_VIEW_COLUMN));
        
        if (!(++counter % 100)) {