2007-06-03 Christian Kellner <ckellner@openismus.com>
[modest] / src / widgets / modest-account-view.c
index 896712b..d6c6a3f 100644 (file)
 #include <modest-account-mgr.h>
 #include <modest-account-mgr-helpers.h>
 #include <modest-text-utils.h>
+#include <modest-runtime.h>
 
 #include <gtk/gtkcellrenderertoggle.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtktreeselection.h>
 #include <gtk/gtkliststore.h>
+#include <string.h> /* For strcmp(). */
 
 /* 'private'/'protected' functions */
 static void modest_account_view_class_init    (ModestAccountViewClass *klass);
@@ -69,6 +71,10 @@ struct _ModestAccountViewPrivate {
        ModestAccountMgr *account_mgr;
        gulong sig1, sig2;
        
+       /* When this is TRUE, we ignore configuration key changes.
+        * This is useful when making many changes. */
+       gboolean block_conf_updates;
+       
 };
 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_ACCOUNT_VIEW, \
@@ -198,7 +204,7 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
                        if (last_updated > 0) 
                                last_updated_string = modest_text_utils_get_display_date(last_updated);
                        else
-                               last_updated_string = g_strdup (_("Never"));
+                               last_updated_string = g_strdup (_("FIXME: Never"));
                        
                        if (account_data->is_enabled) {
                                gtk_list_store_insert_with_values (
@@ -209,7 +215,7 @@ update_account_view (ModestAccountMgr *account_mgr, ModestAccountView *view)
                                        MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN,    account_data->is_default,
        
                                        MODEST_ACCOUNT_VIEW_PROTO_COLUMN,
-                                       modest_protocol_info_get_protocol_name  (account_data->store_account->proto),
+                                       modest_protocol_info_get_transport_store_protocol_name (account_data->store_account->proto),
        
                                        MODEST_ACCOUNT_VIEW_LAST_UPDATED_COLUMN,  last_updated_string,
                                        -1);
@@ -229,7 +235,21 @@ on_account_changed (ModestAccountMgr *account_mgr,
                    const gchar* account, const gchar* key,
                    gboolean server_account, ModestAccountView *self)
 {      
-       update_account_view (account_mgr, self);
+       /* Never update the view in response to gconf changes.
+        * Always do it explicitly instead.
+        * This is because we have no way to avoid 10 updates when changing 
+        * 10 items, and this blocks the UI.
+        *
+        * But this block/unblock API might be useful on platforms where the 
+        * notification does not happen so long after the key was set.
+        * (We have no way to know when the last key was set, to do a final update)..
+        */
+        return;
+        
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       
+       if (!priv->block_conf_updates)
+               update_account_view (account_mgr, self);
 }
 
 
@@ -238,7 +258,9 @@ on_account_removed (ModestAccountMgr *account_mgr,
                    const gchar* account, gboolean server_account,
                    ModestAccountView *self)
 {
-       on_account_changed (account_mgr, account, NULL, server_account, self);
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       if (!priv->block_conf_updates)
+               on_account_changed (account_mgr, account, NULL, server_account, self);
 }
 
 
@@ -354,9 +376,13 @@ init_view (ModestAccountView *self)
         * which causes the model column to be updated automatically when the row is clicked.
         * Making this the default in Maemo's GTK+ is obviously a bug:
         * https://maemo.org/bugzilla/show_bug.cgi?id=146
-        */     
+        *
+        * djcb: indeed, they have been removed for post-bora, i added the ifdefs...
+                */
+#ifdef MODEST_HILDON_VERSION_0 
        g_object_set(G_OBJECT(self), "allow-checkbox-mode", FALSE, NULL);
        g_object_set(G_OBJECT(toggle_renderer), "checkbox-mode", FALSE, NULL);
+#endif /*MODEST_HILDON_VERSION_0 */
        g_signal_connect (G_OBJECT(toggle_renderer), "toggled", G_CALLBACK(on_account_default_toggled),
                          self);
        
@@ -426,3 +452,67 @@ modest_account_view_get_selected_account (ModestAccountView *self)
 
        return account_name;
 }
+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct 
+{
+               ModestAccountView* self;
+               const gchar *account_name;
+} ForEachData;
+
+static gboolean
+on_model_foreach_select_account(GtkTreeModel *model, 
+       GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
+{
+       ForEachData *state = (ForEachData*)(user_data);
+       
+       /* Select the item if it has the matching account name: */
+       gchar *this_account_name = NULL;
+       gtk_tree_model_get (model, iter, 
+               MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name, 
+               -1); 
+       if(this_account_name && state->account_name 
+               && (strcmp (this_account_name, state->account_name) == 0)) {
+               
+               GtkTreeSelection *selection = 
+                       gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
+               gtk_tree_selection_select_iter (selection, iter);
+               
+               return TRUE; /* Stop walking the tree. */
+       }
+       
+       return FALSE; /* Keep walking the tree. */
+}
+
+void modest_account_view_select_account (ModestAccountView *account_view, 
+       const gchar* account_name)
+{      
+       /* Create a state instance so we can send two items of data to the signal handler: */
+       ForEachData *state = g_new0 (ForEachData, 1);
+       state->self = account_view;
+       state->account_name = account_name;
+       
+       GtkTreeModel *model = gtk_tree_view_get_model (
+               GTK_TREE_VIEW (account_view));
+       gtk_tree_model_foreach (model, 
+               on_model_foreach_select_account, state);
+               
+       g_free (state);
+}
+
+
+
+void modest_account_view_block_conf_updates (ModestAccountView *account_view)
+{
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+       priv->block_conf_updates = TRUE;
+}
+
+void modest_account_view_unblock_conf_updates (ModestAccountView *account_view)
+{
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+       priv->block_conf_updates = FALSE;
+       
+       update_account_view (modest_runtime_get_account_mgr(), account_view);
+}