2007-05-17 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Thu, 17 May 2007 11:09:12 +0000 (11:09 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Thu, 17 May 2007 11:09:12 +0000 (11:09 +0000)
* src/widgets/modest-account-view.c:
        * src/widgets/modest-account-view.h:
        Added modest_account_view_select_account() which will be useful later
        to asynchronously re-select the edited account.

pmo-trunk-r1900

ChangeLog2
src/maemo/modest-account-view-window.c
src/widgets/modest-account-view.c
src/widgets/modest-account-view.h

index c0e78fe..ca0ddab 100644 (file)
@@ -1,5 +1,12 @@
 2007-05-17  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/widgets/modest-account-view.c:
+       * src/widgets/modest-account-view.h:
+       Added modest_account_view_select_account() which will be useful later 
+       to asynchronously re-select the edited account.
+
+2007-05-17  Murray Cumming  <murrayc@murrayc.com>
+
        * src/maemo/modest-account-settings-dialog.c:
        (modest_account_settings_dialog_set_account_name): 
        Automatically choose the port numbers based on the secure authentication 
index 0307e4e..9fed7b7 100644 (file)
@@ -247,7 +247,10 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
        g_free (account_name);
        
        /* Update the view: */
-       modest_account_view_unblock_conf_updates (priv->account_view);  
+       modest_account_view_unblock_conf_updates (priv->account_view);
+       
+       /* TODO: Call modest_account_view_select_account() when 
+        * the view has actually been update. */
 }
 
 static void
index 0ad2462..d6c6a3f 100644 (file)
@@ -39,6 +39,7 @@
 #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);
@@ -452,6 +453,55 @@ 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)
 {
index ba5992c..94e314f 100644 (file)
@@ -87,6 +87,16 @@ ModestAccountView*   modest_account_view_new         (ModestAccountMgr *account_
  **/
 gchar*   modest_account_view_get_selected_account    (ModestAccountView *account_view);
 
+/**
+ * modest_account_view_set_selected_account:
+ * @account_view: a #ModestAccountView
+ * @account_name: The name of the account to select.
+ * 
+ * Sets the currently selected account.
+ **/
+void modest_account_view_select_account (ModestAccountView *account_view, 
+       const gchar* account_name);
+
 /** 
  * modest_account_view_block_conf_updates
  * @account_view: a #ModestAccountView