2007-05-08 Murray Cumming <murrayc@murrayc.com>
+ * src/modest-account-mgr-helpers.h:
+ * src/modest-account-mgr-helpers.c:
+ Added modest_account_mgr_get_display_name(),
+ modest_server_account_get_username(),
+ modest_server_account_set_username(),
+ modest_server_account_set_password(),
+ modest_server_account_get_hostname() functions so we do not need to
+ use the conf API directly.
+
+ * src/maemo/modest-main-window.c: (connect_signals):
+ Actually connect ot the ModestAccountStore::request-password signal,
+ so that we show the dialog when the password is requested by Tinymail,
+ for isntance if it is empty.
+
+ * src/modest-marshal.list:
+ * src/modest-tny-account-store.c:
+ (modest_tny_account_store_class_init), (get_password),
+ (modest_tny_account_store_alert):
+ * src/modest-tny-account-store.h:
+ * src/modest-ui-actions.h:
+ * src/modest-ui-actions.c:
+ (modest_ui_actions_on_password_requested):
+ Change the signal parameters, so it is obvious that we are providing
+ the non human-readable server name, and receiving both the username
+ and password, though changing of the username is not yet implemented.
+ Change the dialog UI to match the Maemo UI specifications, with #idfefing
+ for the GNOME version.
+
+ This should fix the projects.maemo.org bug NB#56209, though it does not
+ work on Bora, because the gconf_client_get() for the password fails
+ immediately after we save it with gconf_client_set().
+
+2007-05-08 Murray Cumming <murrayc@murrayc.com>
+
* configure.ac:
* src/Makefile.am: Reverted the use of AM_CONDITIONAL(), because it
caused an undefined symbol error:
G_CALLBACK (on_account_update),
self);
+ /* Account store */
+ g_signal_connect (G_OBJECT (modest_runtime_get_account_store()), "password_requested",
+ G_CALLBACK (modest_ui_actions_on_password_requested), self);
+
/* Device */
g_signal_connect (G_OBJECT(modest_runtime_get_device()), "connection_changed",
G_CALLBACK(on_connection_changed), self);
return result;
}
+gchar* modest_account_mgr_get_display_name (ModestAccountMgr *self,
+ const gchar* name)
+{
+ return modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_DISPLAY_NAME, FALSE);
+}
+
+
gchar* modest_account_mgr_get_signature (ModestAccountMgr *self, const gchar* name,
gboolean* use_signature)
return result;
}
-
+gchar*
+modest_server_account_get_username (ModestAccountMgr *self, const gchar* account_name)
+{
+ return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_USERNAME,
+ TRUE /* server account */);
+}
+
+void
+modest_server_account_set_username (ModestAccountMgr *self, const gchar* account_name,
+ const gchar* username)
+{
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_USERNAME,
+ username, TRUE /* server account */);
+}
+
+void
+modest_server_account_set_password (ModestAccountMgr *self, const gchar* account_name,
+ const gchar* password)
+{
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_PASSWORD,
+ password, TRUE /* server account */);
+}
+
+gchar*
+modest_server_account_get_hostname (ModestAccountMgr *self, const gchar* account_name)
+{
+ return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_HOSTNAME,
+ TRUE /* server account */);
+}
+
static ModestProtocol
get_secure_auth_for_conf_string(const gchar* value)
gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
/**
+ * modest_account_mgr_get_display_name:
+ * @self: a ModestAccountMgr instance
+ * @name: the account name to check
+ *
+ * Return the human-readable account title for this account, or NULL.
+ */
+gchar* modest_account_mgr_get_display_name (ModestAccountMgr *self,
+ const gchar* name);
+
+
+/**
* modest_account_mgr_set_signature
* @self: a ModestAccountMgr instance
* @name: the account name to check
*/
gchar* modest_account_mgr_get_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
const gchar* connection_name);
-
+
+
+/**
+ * modest_server_account_get_username:
+ * @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
+ *
+ * Gets the username this server account.
+ *
+ * Returns: The username.
+ */
+gchar*
+modest_server_account_get_username (ModestAccountMgr *self, const gchar* account_name);
+
+/**
+ * modest_server_account_set_username:
+ * @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
+ * @username: The new username.
+ *
+ * Sets the username this server account.
+ */
+void
+modest_server_account_set_username (ModestAccountMgr *self, const gchar* account_name,
+ const gchar* username);
+
+/**
+ * modest_server_account_set_password:
+ * @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
+ * @password: The new password.
+ *
+ * Sets the password this server account.
+ */
+void
+modest_server_account_set_password (ModestAccountMgr *self, const gchar* account_name,
+ const gchar* password);
+
+
+/**
+ * modest_server_account_modest_server_account_get_hostnameget_username:
+ * @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
+ *
+ * Gets the hostname this server account.
+ *
+ * Returns: The hostname.
+ */
+gchar*
+modest_server_account_get_hostname (ModestAccountMgr *self, const gchar* account_name);
+
+
/**
* modest_server_account_get_secure_auth:
* @self: a ModestAccountMgr instance
VOID:POINTER,POINTER
VOID:POINTER,POINTER,POINTER
-VOID:STRING,POINTER,POINTER,POINTER
+VOID:STRING,POINTER,POINTER,POINTER,POINTER
VOID:POINTER,BOOL
VOID:STRING,INT
VOID:STRING,INT,INT
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(ModestTnyAccountStoreClass, password_requested),
NULL, NULL,
- modest_marshal_VOID__STRING_POINTER_POINTER_POINTER,
- G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER,
+ modest_marshal_VOID__STRING_POINTER_POINTER_POINTER_POINTER,
+ G_TYPE_NONE, 5, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER,
G_TYPE_POINTER);
}
"account_store"));
}
+/* This callback will be called by Tinymail when it needs the password.
+ * Note that TnyAccount here will be the server account. */
static gchar*
get_password (TnyAccount *account, const gchar *prompt, gboolean *cancel)
{
- /* printf("DEBUG: %s\n", __FUNCTION__); */
-
const gchar *key;
const TnyAccountStore *account_store;
ModestTnyAccountStore *self;
ModestTnyAccountStorePrivate *priv;
+ gchar *username = NULL;
gchar *pwd = NULL;
gpointer pwd_ptr;
gboolean already_asked;
/* if the password is not already there, try ModestConf */
if (!already_asked) {
pwd = modest_account_mgr_get_string (priv->account_mgr,
- key, MODEST_ACCOUNT_PASSWORD,TRUE);
+ key, MODEST_ACCOUNT_PASSWORD, TRUE);
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. Get the password from the user */
- const gchar* name = tny_account_get_name (account);
+ const gchar* account_id = tny_account_get_id (account);
gboolean remember = FALSE;
pwd = NULL;
g_signal_emit (G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0,
- name, &pwd, cancel, &remember);
+ account_id, /* server_account_name */
+ &username, &pwd, cancel, &remember);
if (!*cancel) {
if (remember)
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;
}
+
+ g_free (username);
+ username = NULL;
+
+ g_free (pwd);
+ pwd = NULL;
+
} else
*cancel = FALSE;
const GError *error)
{
g_return_val_if_fail (error, FALSE);
+ g_return_val_if_fail (error->domain == TNY_ACCOUNT_ERROR, FALSE);
printf("DEBUG: %s: error->message=%s\n", __FUNCTION__, error->message);
switch (error->code)
{
case TNY_ACCOUNT_ERROR_TRY_CONNECT:
- /* Use a Logical ID: */
prompt = _("Modest account not yet fully configured");
break;
default:
const gchar *account_name,
gpointer user_data);
void (*password_requested) (ModestTnyAccountStore *self,
- const gchar *account_name,
+ const gchar *server_account_name,
+ gchar **username,
gchar **password,
gboolean *remember,
gboolean *cancel,
#ifdef MODEST_PLATFORM_MAEMO
#include "maemo/modest-osso-state-saving.h"
+#include "maemo/modest-maemo-ui-constants.h"
#endif /* MODEST_PLATFORM_MAEMO */
void
modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
- const gchar* account_name,
+ const gchar* server_account_name,
+ gchar **username,
gchar **password,
gboolean *cancel,
gboolean *remember,
ModestMainWindow *main_window)
{
- /* printf("DEBUG: %s\n", __FUNCTION__); */
- gchar *txt;
- GtkWidget *dialog, *entry, *remember_pass_check;
-
- dialog = gtk_dialog_new_with_buttons (_("Password requested"),
+ g_return_if_fail(server_account_name);
+ /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
+
+#ifdef MODEST_PLATFORM_MAEMO
+ /* Maemo uses a different (awkward) button order,
+ * It should probably just use gtk_alternative_dialog_button_order ().
+ */
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
+ NULL,
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ NULL);
+#else
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
NULL,
GTK_DIALOG_MODAL,
GTK_STOCK_CANCEL,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
NULL);
+#endif /* MODEST_PLATFORM_MAEMO */
+
gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
- txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
+ gchar *server_name = modest_server_account_get_hostname (
+ modest_runtime_get_account_mgr(), server_account_name);
+
+ /* This causes a warning because the logical ID has no %s in it,
+ * though the translation does, but there is not much we can do about that: */
+ gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
FALSE, FALSE, 0);
g_free (txt);
+ g_free (server_name);
+ server_name = NULL;
- entry = gtk_entry_new_with_max_length (40);
- gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
- gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
+ /* username: */
+ gchar *initial_username = modest_server_account_get_username (
+ modest_runtime_get_account_mgr(), server_account_name);
- gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
- TRUE, FALSE, 0);
-
+ GtkWidget *entry_username = gtk_entry_new ();
+ if (initial_username)
+ gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
+ /* TODO: Allow the username to be changed here. */
+ gtk_widget_set_sensitive (entry_username, FALSE);
+
+#ifdef MODEST_PLATFORM_MAEMO
+ /* Auto-capitalization is the default, so let's turn it off: */
+ hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
+
+ /* Create a size group to be used by all captions.
+ * Note that HildonCaption does not create a default size group if we do not specify one.
+ * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
+ GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+ GtkWidget *caption = hildon_caption_new (sizegroup,
+ _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
+ gtk_widget_show (entry_username);
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
+ FALSE, FALSE, MODEST_MARGIN_HALF);
+ gtk_widget_show (caption);
+#else
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
+ TRUE, FALSE, 0);
+#endif /* MODEST_PLATFORM_MAEMO */
+
+ /* password: */
+ GtkWidget *entry_password = gtk_entry_new ();
+ gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
+ gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), 0x2022); /* bullet unichar */
+
+#ifdef MODEST_PLATFORM_MAEMO
+ /* Auto-capitalization is the default, so let's turn it off: */
+ hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password), HILDON_GTK_INPUT_MODE_FULL);
+
+ caption = hildon_caption_new (sizegroup,
+ _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
+ gtk_widget_show (entry_password);
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
+ FALSE, FALSE, MODEST_MARGIN_HALF);
+ gtk_widget_show (caption);
+#else
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
+ TRUE, FALSE, 0);
+#endif /* MODEST_PLATFORM_MAEMO */
+
+/* This is not in the Maemo UI spec:
remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
TRUE, FALSE, 0);
+*/
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)));
- *cancel = FALSE;
+ if (username)
+ *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
+
+ if (password) {
+ *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
+
+ /* TODO: It is strange that we must return this as well as set it in gconf.
+ * That would only be useful if there was a remember-password preference,
+ * but there is no such preference at this time. */
+ modest_server_account_set_password (
+ modest_runtime_get_account_mgr(), server_account_name,
+ *password);
+ }
+
+ if (cancel)
+ *cancel = FALSE;
} else {
- *password = NULL;
- *cancel = TRUE;
+ if (username)
+ *username = NULL;
+
+ if (password)
+ *password = NULL;
+
+ if (cancel)
+ *cancel = TRUE;
}
+/* This is not in the Maemo UI spec:
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
*remember = TRUE;
else
*remember = FALSE;
+*/
gtk_widget_destroy (dialog);
}
ModestMainWindow *main_window);
void modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
- const gchar* account_name,
- gchar **password, gboolean *cancel,
+ const gchar* server_account_name,
+ gchar **username, gchar **password, gboolean *cancel,
gboolean *remember, ModestMainWindow *main_window);
void modest_ui_actions_on_undo (GtkAction *action,