so that it may be called, if TnyAccountIface needs a password.
pmo-trunk-r338
static void modest_ui_window_destroy (GtkWidget *win, GdkEvent *event, gpointer data);
static void modest_ui_last_window_closed (GObject *obj, gpointer data);
-static void on_password_requested (ModestTnyAccountStore *account_store, const gchar *account_name, gpointer user_data);
+gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
/* list my signals */
enum {
g_warning ("could not create ModestAccountMgr instance");
g_object_unref (obj);
return NULL;
- }
+ }
modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
if (!modest_id_mgr) {
if (!account_store_iface) {
g_warning ("could not initialze ModestTnyAccountStore");
return NULL;
- }
- g_signal_connect (account_store_iface, "password_requested",
- G_CALLBACK(on_password_requested),
- NULL);
+ }
+
+ modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
+ on_password_requested);
+
g_signal_connect (account_store_iface, "accounts_reloaded",
G_CALLBACK(on_accounts_reloaded), priv);
}
-static void
-on_password_requested (ModestTnyAccountStore *account_store,
- const gchar *account_name,
- gpointer user_data) {
+gchar *
+on_password_requested (TnyAccountIface *account,
+ const gchar *prompt,
+ gboolean *cancel) {
GtkWidget *passdialog;
GtkWidget *vbox;
+ GtkWidget *infoscroll;
GtkWidget *infolabel;
- GtkWidget *passentry;
- gint retval;
- const gchar *infostring = g_strconcat(_("Please enter the password for "), account_name, ".", NULL);
+ GtkWidget *passentry;
+ GtkTextBuffer *infobuffer;
+ gchar *retval;
+ gint result;
passdialog = gtk_dialog_new_with_buttons(_("Password"),
NULL,
vbox = gtk_vbox_new(FALSE, 0);
- infolabel = gtk_label_new(infostring);
+ infobuffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_set_text(infobuffer, prompt, -1);
+ infoscroll = gtk_scrolled_window_new(NULL, NULL);
+ infolabel = gtk_text_view_new_with_buffer(infobuffer);
+ gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
passentry = gtk_entry_new();
- gtk_entry_set_visibility(passentry, FALSE);
+ gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infolabel, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
gtk_widget_show_all(passdialog);
- retval = gtk_dialog_run (GTK_DIALOG(passdialog));
+ result = gtk_dialog_run (GTK_DIALOG(passdialog));
- switch (retval) {
+ switch (result) {
case GTK_RESPONSE_ACCEPT:
- modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store),
- account_name,
- "password",
- gtk_entry_get_text(GTK_ENTRY(passentry)),
- NULL);
+ retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
+ *cancel=FALSE;
break;
- case GTK_RESPONSE_CANCEL:
- /* FIXME:
- * What happens, if canceled?"
- */
+ default:
+ retval = g_strdup("");;
+ *cancel=TRUE;
break;
}
- gtk_widget_destroy (passdialog);
+ gtk_widget_hide(passdialog);
+ gtk_widget_destroy(passdialog);
+ while (gtk_events_pending()){
+ gtk_main_iteration();
+ }
+
+ return retval;
}
account_name="empty";
}
- g_message("Value: '%s'\n", account_name);
-
free(account_name);
}
static void modest_ui_window_destroy (GtkWidget *win, GdkEvent *event, gpointer data);
static void modest_ui_last_window_closed (GObject *obj, gpointer data);
-static void on_password_requested (ModestTnyAccountStore *account_store, const gchar *account_name, gpointer user_data);
+gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
/* list my signals */
enum {
g_warning ("could not create ModestAccountMgr instance");
g_object_unref (obj);
return NULL;
- }
+ }
modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
if (!modest_id_mgr) {
if (!account_store_iface) {
g_warning ("could not initialze ModestTnyAccountStore");
return NULL;
- }
- g_signal_connect (account_store_iface, "password_requested",
- G_CALLBACK(on_password_requested),
- NULL);
+ }
+
+ modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
+ on_password_requested);
+
g_signal_connect (account_store_iface, "accounts_reloaded",
G_CALLBACK(on_accounts_reloaded), priv);
}
-static void
-on_password_requested (ModestTnyAccountStore *account_store,
- const gchar *account_name,
- gpointer user_data) {
+gchar *
+on_password_requested (TnyAccountIface *account,
+ const gchar *prompt,
+ gboolean *cancel) {
GtkWidget *passdialog;
GtkWidget *vbox;
+ GtkWidget *infoscroll;
GtkWidget *infolabel;
GtkWidget *passentry;
- gint retval;
- const gchar *infostring = g_strconcat(_("Please enter the password for "), account_name, ".", NULL);
+ GtkTextBuffer *infobuffer;
+ gchar *retval;
+ gint result;
passdialog = gtk_dialog_new_with_buttons(_("Password"),
NULL,
vbox = gtk_vbox_new(FALSE, 0);
- infolabel = gtk_label_new(infostring);
+ infobuffer = gtk_text_buffer_new (NULL);
+ gtk_text_buffer_set_text(infobuffer, prompt, -1);
+ infoscroll = gtk_scrolled_window_new(NULL, NULL);
+ infolabel = gtk_text_view_new_with_buffer(infobuffer);
+ gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
passentry = gtk_entry_new();
- gtk_entry_set_visibility(passentry, FALSE);
+ gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infolabel, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
gtk_widget_show_all(passdialog);
- retval = gtk_dialog_run (GTK_DIALOG(passdialog));
+ result = gtk_dialog_run (GTK_DIALOG(passdialog));
- switch (retval) {
+ switch (result) {
case GTK_RESPONSE_ACCEPT:
- modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store),
- account_name,
- "password",
- gtk_entry_get_text(GTK_ENTRY(passentry)),
- NULL);
+ retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
+ *cancel=FALSE;
break;
- case GTK_RESPONSE_CANCEL:
- /* FIXME:
- * What happens, if canceled?"
- */
+ default:
+ retval = g_strdup("");;
+ *cancel=TRUE;
break;
}
+ gtk_widget_hide(passdialog);
gtk_widget_destroy (passdialog);
+ while (gtk_events_pending()){
+ g_message("iterating over pending events");
+ gtk_main_iteration();
+ }
+
+ return retval;
}
/* Password Status */
enum {
PW_NOT_INVALID,
- PW_INVALID,
+ PW_INVALID
};
static const gchar *transport_protocols[] = { "smtp", NULL };
ModestAccountMgr *modest_acc_mgr;
gint pw_invalid;
+ ModestTnyGetPassFunc get_pass_func;
};
#define MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
MODEST_TYPE_TNY_ACCOUNT_STORE, \
priv->tny_session_camel = NULL;
/* Meaning: if not indicated otherwise, we have valid password data */
priv->pw_invalid = PW_NOT_INVALID;
+ priv->get_pass_func = NULL;
}
account_store = tny_account_iface_get_account_store(account);
self = MODEST_TNY_ACCOUNT_STORE (account_store);
- priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+ priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
if (priv->pw_invalid==PW_NOT_INVALID) {
retval = modest_account_mgr_get_server_account_string (priv->modest_acc_mgr,
MODEST_ACCOUNT_PASSWORD,
NULL);
} else {
- g_signal_emit(G_OBJECT(self), signals[PASSWORD_REQUESTED_SIGNAL], 0, key);
- priv->pw_invalid=PW_NOT_INVALID;
- retval=NULL;
+ retval = priv->get_pass_func(account, prompt, cancel);
+ if (!*cancel)
+ {
+ priv->pw_invalid=PW_NOT_INVALID;
+ modest_account_mgr_set_server_account_string(priv->modest_acc_mgr,
+ key,
+ MODEST_ACCOUNT_PASSWORD,
+ retval,
+ NULL);
+ }
}
return retval;
}
}
tny_account_iface_set_pass_func (tny_account, get_password);
- tny_account_iface_set_forget_pass_func (tny_account, forget_password);
+ tny_account_iface_set_forget_pass_func (tny_account, forget_password);
return tny_account;
}
klass->get_device_func =
modest_tny_account_store_get_device;
}
+
+void
+modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self, ModestTnyGetPassFunc func) {
+
+ ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ priv->get_pass_func=func;
+}
+
#include <glib-object.h>
#include <tny-account-store.h>
#include <tny-session-camel.h>
+#include <tny-shared.h>
/* other include files */
typedef struct _ModestTnyAccountStore ModestTnyAccountStore;
typedef struct _ModestTnyAccountStoreClass ModestTnyAccountStoreClass;
+typedef TnyGetPassFunc ModestTnyGetPassFunc;
struct _ModestTnyAccountStore {
GObject parent;
*/
TnySessionCamel* tny_account_store_get_session (TnyAccountStore *self);
+/**
+ * tny_account_store_set_get_pass_func:
+ * @self: a TnyAccountStore instance
+ * key: a key
+ * func: a function
+ *
+ * set the password function to function
+ */
+void
+modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *, ModestTnyGetPassFunc);
G_END_DECLS