* Removed an invalid separator in the File menu
authorSergio Villar Senin <svillar@igalia.com>
Thu, 14 Dec 2006 12:15:04 +0000 (12:15 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 14 Dec 2006 12:15:04 +0000 (12:15 +0000)
* Added a function to unset account keys
* Modified a marshaller
* Added some documentation to ModestConf
* Added support to remember the password
* Fixed the problem with the password dialog
* Fixed a problem when trying to read messages being offline

pmo-trunk-r555

src/gtk/modest-main-window.c
src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-conf.h
src/modest-marshal.list
src/modest-tny-account-store.c
src/modest-widget-factory.c

index c458eed..164286f 100644 (file)
@@ -438,11 +438,11 @@ static GtkItemFactoryEntry menu_items[] = {
        { "/_Edit",             NULL,                   NULL,           0, "<Branch>", NULL },
        { "/Edit/_Undo",        "<CTRL>Z",              NULL,           0, "<StockItem>", GTK_STOCK_UNDO },
        { "/Edit/_Redo",        "<shift><CTRL>Z",       NULL,           0, "<StockItem>", GTK_STOCK_REDO },
-       { "/File/sep1",         NULL,                   NULL,           0, "<Separator>", NULL },
+       { "/Edit/sep1",         NULL,                   NULL,           0, "<Separator>", NULL },
        { "/Edit/Cut",          "<control>X",           NULL,           0, "<StockItem>", GTK_STOCK_CUT  },
        { "/Edit/Copy",         "<CTRL>C",              NULL,           0, "<StockItem>", GTK_STOCK_COPY },
        { "/Edit/Paste",        NULL,                   NULL,           0, "<StockItem>", GTK_STOCK_PASTE},
-       { "/Edit/sep1",         NULL,                   NULL,           0, "<Separator>", NULL },
+       { "/Edit/sep2",         NULL,                   NULL,           0, "<Separator>", NULL },
        { "/Edit/Delete",       "<CTRL>Q",              NULL,           0, "<Item>" ,NULL},
        { "/Edit/Select all",   "<CTRL>A",              NULL,           0, "<Item>" ,NULL},
        { "/Edit/Deelect all",  "<Shift><CTRL>A",       NULL,           0, "<Item>" ,NULL},
index 2e76db1..7132df1 100644 (file)
@@ -832,6 +832,32 @@ modest_account_mgr_get_list (ModestAccountMgr *self,
        return retval;
 }
 
+
+gboolean 
+modest_account_mgr_unset (ModestAccountMgr *self,
+                         const gchar *name,
+                         const gchar *key,
+                         gboolean server_account,
+                         GError **err)
+{
+       ModestAccountMgrPrivate *priv;
+
+       gchar *keyname;
+       gboolean retval;
+
+       g_return_val_if_fail (self, FALSE);
+        g_return_val_if_fail (name, FALSE);
+        g_return_val_if_fail (key, FALSE);
+
+       keyname = get_account_keyname (name, key, server_account);
+
+       priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       retval = modest_conf_remove_key (priv->modest_conf, keyname, err);
+
+       g_free (keyname);
+       return retval;
+}
+
 /* must be freed by caller */
 static gchar *
 get_account_keyname (const gchar * accname, const gchar * name, gboolean server_account)
index c0bc632..7cdfbc0 100644 (file)
@@ -335,7 +335,7 @@ gboolean    modest_account_mgr_get_bool       (ModestAccountMgr *self,
  * @server_account: if TRUE, this is a server account
  * @err: a GError ptr, or NULL to ignore.
  * 
- * set a config string for an account
+ * set a config string for an account.
  *
  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
  * @err gives details in case of error
@@ -388,12 +388,46 @@ gboolean  modest_account_mgr_set_bool       (ModestAccountMgr *self,
                                                   GError **err);
 
 
+/**
+ * modest_account_mgr_get_list:
+ * @self: a ModestAccountMgr instance
+ * @name: the name of the account
+ * @key: the key of the value to get
+ * @list_type: the type of the members of the list
+ * @server_account: if TRUE, this is a server account
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * get a config list of values of type @list_type of an account
+ *
+ * Returns: a newly allocated list of elements
+ * @err gives details in case of error
+ */
 GSList*                modest_account_mgr_get_list       (ModestAccountMgr *self,
                                                   const gchar *name,
                                                   const gchar *key,
                                                   ModestConfValueType list_type,
                                                   gboolean server_account,
                                                   GError **err);
+
+/**
+ * modest_account_mgr_unset:
+ * @self: a ModestAccountMgr instance
+ * @name: the name of the account
+ * @key: the key of the value to unset
+ * @server_account: if TRUE, this is a server account
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * unsets the config value of an account and all their children keys
+ *
+ * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
+ * @err gives details in case of error
+ */
+gboolean        modest_account_mgr_unset           (ModestAccountMgr *self,
+                                                  const gchar *name,
+                                                  const gchar *key,
+                                                  gboolean server_account,
+                                                  GError **err);
+
 G_END_DECLS
 
 #endif /* __MODEST_ACCOUNT_MGR_H__ */
index 55ee3ab..49f6954 100644 (file)
@@ -134,6 +134,20 @@ gint         modest_conf_get_int     (ModestConf* self, const gchar* key, GError
 gboolean     modest_conf_get_bool    (ModestConf* self, const gchar* key, GError **err);
 
 
+/** 
+ * modest_conf_get_list:
+ * @self: a ModestConf instance
+ * @key: the key of the value to retrieve
+ * @list_type: the type of the elements of the list
+ * @err: a GError ptr, or NULL to ignore.
+ * 
+ * get a list of values from the configuration system
+ *  
+ * Returns: a list with the values for the key, or NULL in case of error
+ * @err gives details in case of error
+ */
+GSList *     modest_conf_get_list    (ModestConf* self, const gchar* key, 
+                                     ModestConfValueType list_type, GError **err);
 
 /**
  * modest_conf_set_string:
index 37ba844..187d0bb 100644 (file)
@@ -5,4 +5,4 @@ VOID:STRING,INT
 VOID:STRING,INT,INT
 VOID:STRING,BOOL
 VOID:STRING,STRING,BOOL
-VOID:STRING,POINTER,POINTER
+VOID:STRING,POINTER,POINTER,POINTER
index 9fe32a4..bce0157 100644 (file)
@@ -140,8 +140,8 @@ modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass)
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET(ModestTnyAccountStoreClass, password_requested),
                              NULL, NULL,
-                             modest_marshal_VOID__STRING_POINTER_POINTER,
-                             G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER);
+                             modest_marshal_VOID__STRING_POINTER_POINTER_POINTER,
+                             G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);
        
        signals[ACCOUNT_UPDATE_SIGNAL] =
                g_signal_new ("account_update",
@@ -226,8 +226,8 @@ 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... */
-       pwd = g_hash_table_lookup (priv->password_hash, key);
-       already_asked = (pwd != NULL);
+       already_asked = g_hash_table_lookup_extended (priv->password_hash, 
+                                                     key, NULL, (gpointer *) &pwd);
 
        /* if the password is not already there, try ModestConf */
        if (!already_asked) {
@@ -242,20 +242,23 @@ get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
 
                /* we don't have it yet. we emit a signal to get the password somewhere */
                const gchar* name = tny_account_get_name (account);
+               gboolean remember;
                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);
+                              name, &pwd, cancel, &remember);
+
+               if (!*cancel) {
+                       if (remember)
+                               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
+                          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 {
@@ -277,10 +280,26 @@ forget_password (TnyAccount *account) {
        ModestTnyAccountStore *self;
        ModestTnyAccountStorePrivate *priv;
        const TnyAccountStore *account_store;
+       gchar *pwd;
+       const gchar *key;
 
         account_store = TNY_ACCOUNT_STORE(get_account_store_for_account (account));
        self = MODEST_TNY_ACCOUNT_STORE (account_store);
         priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+       key  = tny_account_get_id (account);
+
+       /* Do not remove the key, this will allow us to detect that we
+          have already asked for it at least once */
+       pwd = g_hash_table_lookup (priv->password_hash, key);
+       if (pwd) {
+               memset (pwd, 0, strlen (pwd));
+               g_hash_table_insert (priv->password_hash, g_strdup (key), NULL);
+       }
+
+       /* Remove from configuration system */
+       modest_account_mgr_unset (priv->account_mgr,
+                                 key, MODEST_ACCOUNT_PASSWORD,
+                                 TRUE, NULL);
 }
 
 
index d501599..f3f7aef 100644 (file)
@@ -72,7 +72,7 @@ static void on_connection_changed (TnyDevice *device, gboolean online,
 static void on_online_toggle_toggled (GtkToggleButton *toggle, ModestWidgetFactory *factory);
 
 static void on_password_requested (ModestTnyAccountStore *account_store, const gchar* account_name,
-                                  gchar **password, gboolean *cancel, ModestWidgetFactory *self);
+                                  gchar **password, gboolean *cancel, gboolean *remember, ModestWidgetFactory *self);
 
 static void on_item_not_found     (ModestHeaderView* header_view, ModestItemType type,
                                   ModestWidgetFactory *self);
@@ -730,7 +730,9 @@ on_item_not_found (ModestHeaderView* header_view, ModestItemType type,
                                                 GTK_BUTTONS_OK,
                                                 _("The %s you selected cannot be found"),
                                                 item);
+               gdk_threads_enter ();
                gtk_dialog_run (GTK_DIALOG(dialog));
+               gdk_threads_leave ();
        } else {
 
                dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
@@ -750,8 +752,10 @@ on_item_not_found (ModestHeaderView* header_view, ModestItemType type,
                g_free (txt);
 
                gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
+               gdk_threads_enter ();
                if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
                        tny_device_force_online (device);
+               gdk_threads_leave ();
        }
        gtk_widget_destroy (dialog);
 }
@@ -760,7 +764,7 @@ on_item_not_found (ModestHeaderView* header_view, ModestItemType type,
 
 static void
 on_password_requested (ModestTnyAccountStore *account_store, const gchar* account_name,
-                      gchar **password, gboolean *cancel, ModestWidgetFactory *self)
+                      gchar **password, gboolean *cancel, gboolean *remember, ModestWidgetFactory *self)
 {
        gchar *txt;
        GtkWidget *dialog, *entry, *remember_pass_check;
@@ -799,6 +803,11 @@ on_password_requested (ModestTnyAccountStore *account_store, const gchar* accoun
                *password = NULL;
                *cancel   = TRUE;
        }
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
+               *remember = TRUE;
+       else
+               *remember = FALSE;
+
        gtk_widget_destroy (dialog);
 }