From 9381d2949de3c1268e83284bd39a8ffb865ec851 Mon Sep 17 00:00:00 2001 From: Silvan Marco Fin Date: Thu, 22 Jun 2006 19:57:26 +0000 Subject: [PATCH] * added function to register password_request method with modest_tny_account_store so that it may be called, if TnyAccountIface needs a password. pmo-trunk-r338 --- src/gtk-glade/modest-ui.c | 67 ++++++++++++++++++++++------------------ src/hildon/modest-ui.c | 62 +++++++++++++++++++++---------------- src/modest-tny-account-store.c | 30 ++++++++++++++---- src/modest-tny-account-store.h | 12 +++++++ 4 files changed, 109 insertions(+), 62 deletions(-) diff --git a/src/gtk-glade/modest-ui.c b/src/gtk-glade/modest-ui.c index 7964dab..36f4f49 100644 --- a/src/gtk-glade/modest-ui.c +++ b/src/gtk-glade/modest-ui.c @@ -44,7 +44,7 @@ static void modest_ui_finalize (GObject *obj); 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 { @@ -170,7 +170,7 @@ modest_ui_new (ModestConf *modest_conf) 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) { @@ -184,10 +184,11 @@ modest_ui_new (ModestConf *modest_conf) 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); @@ -234,17 +235,19 @@ 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 *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, @@ -257,32 +260,38 @@ on_password_requested (ModestTnyAccountStore *account_store, 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; } @@ -301,8 +310,6 @@ on_account_selector_selection_changed (GtkWidget *widget, gpointer user_data) account_name="empty"; } - g_message("Value: '%s'\n", account_name); - free(account_name); } diff --git a/src/hildon/modest-ui.c b/src/hildon/modest-ui.c index 7964dab..c11e892 100644 --- a/src/hildon/modest-ui.c +++ b/src/hildon/modest-ui.c @@ -44,7 +44,7 @@ static void modest_ui_finalize (GObject *obj); 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 { @@ -170,7 +170,7 @@ modest_ui_new (ModestConf *modest_conf) 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) { @@ -184,10 +184,11 @@ modest_ui_new (ModestConf *modest_conf) 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); @@ -234,17 +235,19 @@ 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 *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, @@ -257,32 +260,39 @@ on_password_requested (ModestTnyAccountStore *account_store, 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; } diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index e9fba72..baa5c95 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -42,7 +42,7 @@ enum { /* Password Status */ enum { PW_NOT_INVALID, - PW_INVALID, + PW_INVALID }; static const gchar *transport_protocols[] = { "smtp", NULL }; @@ -61,6 +61,7 @@ struct _ModestTnyAccountStorePrivate { 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, \ @@ -142,6 +143,7 @@ modest_tny_account_store_init (ModestTnyAccountStore *obj) 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; } @@ -180,7 +182,7 @@ get_password (TnyAccountIface *account, 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, @@ -188,9 +190,16 @@ get_password (TnyAccountIface *account, 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; } @@ -274,7 +283,7 @@ tny_account_from_key (ModestTnyAccountStore *self, const gchar *key, } 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; } @@ -703,3 +712,12 @@ modest_tny_account_store_iface_init (gpointer g_iface, gpointer iface_data) 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; +} + diff --git a/src/modest-tny-account-store.h b/src/modest-tny-account-store.h index 5d723ac..e3cc541 100644 --- a/src/modest-tny-account-store.h +++ b/src/modest-tny-account-store.h @@ -7,6 +7,7 @@ #include #include #include +#include /* other include files */ @@ -22,6 +23,7 @@ G_BEGIN_DECLS typedef struct _ModestTnyAccountStore ModestTnyAccountStore; typedef struct _ModestTnyAccountStoreClass ModestTnyAccountStoreClass; +typedef TnyGetPassFunc ModestTnyGetPassFunc; struct _ModestTnyAccountStore { GObject parent; @@ -74,6 +76,16 @@ ModestAccountMgr *modest_tny_account_store_get_accout_mgr(ModestTnyAccountStore */ 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 -- 1.7.9.5