* Added gtk_threads_init
authorSergio Villar Senin <svillar@igalia.com>
Wed, 13 Dec 2006 18:18:15 +0000 (18:18 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 13 Dec 2006 18:18:15 +0000 (18:18 +0000)
* Modified the password dialog code
* Fixed some leaks

pmo-trunk-r554

src/modest-main.c
src/modest-tny-account-store.c
src/modest-widget-factory.c
src/widgets/modest-folder-view.c

index 69e6424..2f85ae8 100644 (file)
@@ -105,6 +105,7 @@ main (int argc, char *argv[])
 
        g_type_init ();         
        g_thread_init (NULL);
+       gdk_threads_init ();
 
        context = g_option_context_new (NULL);
        g_option_context_add_main_entries (context, options, NULL);
index 4a8f2b2..9fe32a4 100644 (file)
@@ -207,7 +207,6 @@ set_account_store_for_account (TnyAccount *account, ModestTnyAccountStore *store
        g_object_set_data (G_OBJECT(account), "account_store", (gpointer)store);
 }
 
-
 static gchar*
 get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 {
@@ -219,7 +218,7 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
        gboolean already_asked;
        
        g_return_val_if_fail (account, NULL);
-       
+
        key           = tny_account_get_id (account);
        account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
 
@@ -227,34 +226,48 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
        /* is it in the hash? if it's already there, it must be wrong... */
-       already_asked = g_hash_table_lookup (priv->password_hash, key) != NULL;
+       pwd = g_hash_table_lookup (priv->password_hash, key);
+       already_asked = (pwd != NULL);
 
        /* if the password is not already there, try ModestConf */
-/*     if (!already_asked)  */
+       if (!already_asked) {
                pwd  = modest_account_mgr_get_string (priv->account_mgr,
                                                      key, MODEST_ACCOUNT_PASSWORD,
                                                      TRUE, NULL);
+               g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup (pwd));
+       }
+
+       /* if it was already asked, it must have been wrong, so ask again */
+       if (already_asked || !pwd || strlen(pwd) == 0) {
+
+               /* we don't have it yet. we emit a signal to get the password somewhere */
+               const gchar* name = tny_account_get_name (account);
+               pwd = NULL;
+
+               gdk_threads_enter ();
+       
+               g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
+                              name, &pwd, cancel);
+
+               if (!*cancel) {/* TODO: if remember the password */
+                       modest_account_mgr_set_string (priv->account_mgr,
+                                                      key, MODEST_ACCOUNT_PASSWORD,
+                                                      pwd, TRUE, NULL);
+                       /* We need to dup the string even knowing that
+                          it's already a dup of the contents of an
+                          entry, because it if it's wrong then camel
+                          will free it */
+                       g_hash_table_insert (priv->password_hash, g_strdup (key), g_strdup(pwd));
+               } else {
+                       g_hash_table_remove (priv->password_hash, key);
+                       g_free (pwd);
+                       pwd = NULL;
+               }
+               gdk_threads_leave ();
+       } else
+               *cancel = FALSE;
 
-/*     /\* if it was already asked, it must have been wrong, so ask again *\/ */
-/*     if (!already_asked || !pwd || strlen(pwd) == 0) { */
-
-/*             /\* we don't have it yet. we emit a signal to get the password somewhere *\/ */
-/*             const gchar* name = tny_account_get_name (account); */
-/*             *cancel = TRUE; */
-/*             pwd     = NULL; */
-/*             g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, */
-/*                            name, &pwd, cancel); */
-/*             if (!*cancel) /\* remember the password *\/ */
-/*                     modest_account_mgr_set_string (priv->account_mgr, */
-/*                                                    key, MODEST_ACCOUNT_PASSWORD, */
-/*                                                    pwd, TRUE, NULL); */
-/*     } else */
-/*             *cancel = FALSE; */
-
-/*     g_hash_table_insert (priv->password_hash, key, pwd); */
-
-               /* FIXME: pwd needs to be freed somehow */
-       return pwd; 
+       return pwd;
 }
 
 
index 242df59..d501599 100644 (file)
@@ -793,7 +793,7 @@ on_password_requested (ModestTnyAccountStore *account_store, const gchar* accoun
        gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
        
        if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-               *password = g_strdup(gtk_entry_get_text (GTK_ENTRY(entry)));
+               *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
                *cancel   = FALSE;
        } else {
                *password = NULL;
index b636eec..be893a7 100644 (file)
@@ -357,11 +357,12 @@ modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self)
 
        priv =  MODEST_FOLDER_VIEW_GET_PRIVATE (self);  
        iter = tny_list_create_iterator (TNY_LIST (model));
-       do {
+       while (!tny_iterator_is_done (iter)) {
                g_signal_handler_disconnect (G_OBJECT (tny_iterator_get_current (iter)),
                                             priv->store_accounts_handlers [i++]);
                tny_iterator_next (iter);
-       } while (!tny_iterator_is_done (iter));
+       }
+       g_object_unref (G_OBJECT (iter));
 }
 
 
@@ -520,24 +521,24 @@ update_model_empty (ModestFolderView *self)
 static void
 update_store_account_handlers (ModestFolderView *self, TnyList *account_list)
 {
-       gint size;
        ModestFolderViewPrivate *priv;
        TnyIterator *iter;
+       guint len;
        
        priv =  MODEST_FOLDER_VIEW_GET_PRIVATE(self);
 
        /* Listen to subscription changes */
-       size = tny_list_get_length (TNY_LIST (account_list)) * sizeof (gulong);
+       len = tny_list_get_length (TNY_LIST (account_list));
 
        g_assert (priv->store_accounts_handlers == NULL); /* don't leak */
-       priv->store_accounts_handlers = g_malloc0 (size);
+       priv->store_accounts_handlers = g_malloc0 (sizeof (guint) * len);
        iter = tny_list_create_iterator (account_list);
        
-       if (!tny_iterator_is_done (iter))       
-               priv->view_is_empty = FALSE; 
-       else {
+       if (!tny_iterator_is_done (iter)) {
                gint i = 0;
-               while (!tny_iterator_is_done (iter)) {
+
+               priv->view_is_empty = FALSE;
+               do  {
                        
                        priv->store_accounts_handlers [i++] =
                                g_signal_connect (G_OBJECT (tny_iterator_get_current (iter)),
@@ -545,9 +546,9 @@ update_store_account_handlers (ModestFolderView *self, TnyList *account_list)
                                                  G_CALLBACK (on_subscription_changed),
                                                  self);
                        tny_iterator_next (iter);
-                       }
-       }       
-       g_object_unref (iter);                         
+               } while (!tny_iterator_is_done (iter));
+       }
+       g_object_unref (G_OBJECT (iter));       
 }
 
 
@@ -612,14 +613,14 @@ on_selection_changed (GtkTreeSelection *sel, gpointer user_data)
        }
        
        tree_view = MODEST_FOLDER_VIEW (user_data);
-       gtk_tree_model_get (model, &iter, 
-                           TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type, 
-                           TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder, 
+       gtk_tree_model_get (model, &iter,
+                           TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
+                           TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
                            -1);
 
        if (type == TNY_FOLDER_TYPE_ROOT)
-               return; 
-       
+               return;
+
        /* emit 2 signals: one for the unselection of the old one,
         * and one for the selection of the new on */
        g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,