[evolution-rss] make authentication dialog non-blocking
- From: Lucian Langa <lucilanga src gnome org>
- To: svn-commits-list gnome org
- Subject: [evolution-rss] make authentication dialog non-blocking
- Date: Thu, 2 Jul 2009 20:55:16 +0000 (UTC)
commit 8ddc88d4bd6c1b6f029203591371cd59b0c4a9dc
Author: Lucian Langa <lucilanga gnome org>
Date: Thu Jul 2 23:54:52 2009 +0300
make authentication dialog non-blocking
src/network-soup.c | 15 ++++++--
src/rss-config-factory.c | 49 +++++++++++++++++++++++---
src/rss-ui.glade | 6 ++--
src/rss.c | 87 ++++++++++++++++++++++++++-------------------
src/rss.h | 6 +++-
5 files changed, 113 insertions(+), 50 deletions(-)
---
diff --git a/src/network-soup.c b/src/network-soup.c
index 3081d4d..b7d5c46 100644
--- a/src/network-soup.c
+++ b/src/network-soup.c
@@ -383,10 +383,17 @@ authenticate (SoupSession *session,
//won't try again
rf->soup_auth_retry = FALSE;
if (!read_up(data)) {
- if (web_auth_dialog(data))
- rf->soup_auth_retry = FALSE;
- else
- rf->soup_auth_retry = TRUE;
+ //we will continue after user has made a decision on
+ //web auth dialog
+ soup_session_pause_message(session, msg);
+ RSS_AUTH *auth_info = g_new0(RSS_AUTH, 1);
+ auth_info->url = data;
+ auth_info->soup_auth = auth;
+ auth_info->retrying = retrying;
+ auth_info->session = session;
+ auth_info->message = msg;
+ web_auth_dialog(auth_info);
+ return;
}
#if LIBSOUP_VERSION < 2003000
*username = g_strdup(g_hash_table_lookup(rf->hruser, data));
diff --git a/src/rss-config-factory.c b/src/rss-config-factory.c
index 6946c84..d1e15a8 100644
--- a/src/rss-config-factory.c
+++ b/src/rss-config-factory.c
@@ -347,6 +347,17 @@ del_messages_cb (GtkWidget *widget, add_feed *data)
data->del_messages = adj;
}
+void
+disable_widget_cb(GtkWidget *widget, GladeXML *data)
+{
+ GtkWidget *authuser = (GtkWidget *)glade_xml_get_widget (data, "auth_user");
+ GtkWidget *authpass = (GtkWidget *)glade_xml_get_widget (data, "auth_pass");
+ GtkWidget *useauth = (GtkWidget *)glade_xml_get_widget (data, "use_auth");
+ gboolean auth_enabled = gtk_toggle_button_get_active(useauth);
+
+ gtk_widget_set_sensitive(authuser, auth_enabled);
+ gtk_widget_set_sensitive(authpass, auth_enabled);
+}
add_feed *
build_dialog_add(gchar *url, gchar *feed_text)
@@ -514,12 +525,17 @@ build_dialog_add(gchar *url, gchar *feed_text)
GtkWidget *authuser = (GtkWidget *)glade_xml_get_widget (gui, "auth_user");
GtkWidget *authpass = (GtkWidget *)glade_xml_get_widget (gui, "auth_pass");
+ GtkWidget *useauth = (GtkWidget *)glade_xml_get_widget (gui, "use_auth");
- if (url) {
- read_up(url);
+ if (url && read_up(url)) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (useauth), 1);
gtk_entry_set_text(GTK_ENTRY(authuser), g_hash_table_lookup(rf->hruser, url));
gtk_entry_set_text(GTK_ENTRY(authpass), g_hash_table_lookup(rf->hrpass, url));
}
+ gboolean auth_enabled = gtk_toggle_button_get_active(useauth);
+ gtk_widget_set_sensitive(authuser, auth_enabled);
+ gtk_widget_set_sensitive(authpass, auth_enabled);
+ g_signal_connect(useauth, "toggled", G_CALLBACK(disable_widget_cb), gui);
GtkWidget *ok = (GtkWidget *)glade_xml_get_widget (gui, "ok_button");
gtk_dialog_add_action_widget (GTK_DIALOG (dialog1), ok, GTK_RESPONSE_OK);
@@ -2040,9 +2056,9 @@ void rss_folder_factory_commit (EPlugin *epl, EConfigTarget *target)
feed->feed_url = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry1)));
fhtml = gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON (checkbutton1));
- fhtml ^= 1;
- feed->fetch_html = fhtml;
- feed->enabled = gtk_toggle_button_get_active(
+ fhtml ^= 1;
+ feed->fetch_html = fhtml;
+ feed->enabled = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(checkbutton2));
feed->validate = gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(checkbutton3));
@@ -2092,6 +2108,29 @@ void rss_folder_factory_commit (EPlugin *epl, EConfigTarget *target)
else
feed->renamed = 1;
process_dialog_edit(feed, url, ofolder);
+
+ GtkWidget *authuser = (GtkWidget *)glade_xml_get_widget (feed->gui, "auth_user");
+ GtkWidget *authpass = (GtkWidget *)glade_xml_get_widget (feed->gui, "auth_pass");
+ GtkWidget *useauth = (GtkWidget *)glade_xml_get_widget (feed->gui, "use_auth");
+
+ gchar *user = gtk_entry_get_text(GTK_ENTRY(authuser));
+ gchar *pass = gtk_entry_get_text(GTK_ENTRY(authpass));
+ gboolean auth_enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (useauth));
+
+ if (user)
+ g_hash_table_remove(rf->hruser, url);
+
+ if (pass)
+ g_hash_table_remove(rf->hrpass, url);
+
+ if (auth_enabled) {
+ g_hash_table_insert(rf->hruser, url,
+ g_strdup(gtk_entry_get_text (GTK_ENTRY (authuser))));
+ g_hash_table_insert(rf->hrpass, url,
+ g_strdup(gtk_entry_get_text (GTK_ENTRY (authpass))));
+ save_up(url);
+ } else
+ del_up(url);
}
GtkWidget *
diff --git a/src/rss-ui.glade b/src/rss-ui.glade
index 942fc1f..5f183f2 100644
--- a/src/rss-ui.glade
+++ b/src/rss-ui.glade
@@ -947,9 +947,9 @@
<property name="modal">True</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
- <property name="local_only">False</property>
- <property name="action">save</property>
<property name="show_hidden">True</property>
+ <property name="action">save</property>
+ <property name="local_only">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="vbox26">
<property name="visible">True</property>
@@ -1479,7 +1479,7 @@ days</property>
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
- <widget class="GtkCheckButton" id="proxy_auth">
+ <widget class="GtkCheckButton" id="use_auth">
<property name="label" translatable="yes">Use authentication</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
diff --git a/src/rss.c b/src/rss.c
index d2c9d3b..c285c1f 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -561,6 +561,46 @@ textcb(NetStatusType status, gpointer statusdata, gpointer data)
}
}
+void
+user_pass_cb(RSS_AUTH *auth_info, gint response, GtkDialog *dialog)
+{
+ gchar *user = NULL, *pass = NULL;
+ switch (response) {
+ case GTK_RESPONSE_OK:
+ if (auth_info->user)
+ g_hash_table_remove(rf->hruser, auth_info->url);
+
+ g_hash_table_insert(rf->hruser, auth_info->url,
+ g_strdup(gtk_entry_get_text (GTK_ENTRY (auth_info->username))));
+
+ if (auth_info->pass)
+ g_hash_table_remove(rf->hrpass, auth_info->url);
+
+ g_hash_table_insert(rf->hrpass, auth_info->url,
+ g_strdup(gtk_entry_get_text (GTK_ENTRY (auth_info->password))));
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (auth_info->rememberpass)))
+ save_up(auth_info->url);
+ else
+ del_up(auth_info->url);
+
+ rf->soup_auth_retry = FALSE;
+ auth_info->user = g_hash_table_lookup(rf->hruser, auth_info->url);
+ auth_info->pass = g_hash_table_lookup(rf->hrpass, auth_info->url);
+ if (!auth_info->retrying)
+ soup_auth_authenticate (auth_info->soup_auth,
+ auth_info->user,
+ auth_info->pass);
+ break;
+ default:
+ rf->soup_auth_retry = TRUE;
+ break;
+ }
+ soup_session_unpause_message(auth_info->session, auth_info->message);
+ gtk_widget_destroy(dialog);
+ g_free(auth_info);
+
+}
GtkDialog *
create_user_pass_dialog(RSS_AUTH *auth)
@@ -584,7 +624,7 @@ create_user_pass_dialog(RSS_AUTH *auth)
gtk_dialog_set_default_response (
GTK_DIALOG (widget), GTK_RESPONSE_OK);
gtk_window_set_resizable (GTK_WINDOW (widget), FALSE);
- gtk_window_set_transient_for (GTK_WINDOW (widget), widget->parent);
+// gtk_window_set_transient_for (GTK_WINDOW (widget), widget->parent);
gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ON_PARENT);
gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
GtkWidget *password_dialog = GTK_WIDGET (widget);
@@ -713,11 +753,12 @@ create_user_pass_dialog(RSS_AUTH *auth)
GTK_TABLE (container), checkbutton1,
1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+ gtk_widget_show_all(password_dialog);
return GTK_DIALOG(password_dialog);
}
-gboolean
-web_auth_dialog(gchar *url)
+void
+web_auth_dialog(RSS_AUTH *auth_info)
{
GtkDialog *dialog;
guint resp;
@@ -727,41 +768,13 @@ web_auth_dialog(gchar *url)
if (!rf->hrpass)
rf->hrpass = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
- RSS_AUTH *auth_info = g_new0(RSS_AUTH, 1);
- auth_info->user = g_hash_table_lookup(rf->hruser, url);
- auth_info->pass = g_hash_table_lookup(rf->hruser, url);
- auth_info->url = url;
+ auth_info->user = g_hash_table_lookup(rf->hruser, auth_info->url);
+ auth_info->pass = g_hash_table_lookup(rf->hruser, auth_info->url);
dialog = create_user_pass_dialog(auth_info);
- gint result = gtk_dialog_run(GTK_DIALOG(dialog));
- switch (result) {
- case GTK_RESPONSE_OK:
- if (auth_info->user)
- g_hash_table_remove(rf->hruser, url);
-
- g_hash_table_insert(rf->hruser, url,
- g_strdup(gtk_entry_get_text (GTK_ENTRY (auth_info->username))));
-
- if (auth_info->pass)
- g_hash_table_remove(rf->hrpass, url);
-
- g_hash_table_insert(rf->hrpass, url,
- g_strdup(gtk_entry_get_text (GTK_ENTRY (auth_info->password))));
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (auth_info->rememberpass)))
- save_up(url);
- else
- del_up(url);
-
- resp = 0;
- break;
- default:
- g_print("destroy\n");
- resp = 1;
- break;
- }
- gtk_widget_destroy (GTK_WIDGET(dialog));
- g_free(auth_info);
- return resp;
+ g_signal_connect_swapped (dialog,
+ "response",
+ G_CALLBACK (user_pass_cb),
+ auth_info);
}
gboolean
diff --git a/src/rss.h b/src/rss.h
index 051f0f4..0387f79 100644
--- a/src/rss.h
+++ b/src/rss.h
@@ -277,6 +277,10 @@ typedef struct rss_auth {
gchar *url;
gchar *user;
gchar *pass;
+ SoupAuth *soup_auth;
+ SoupSession *session;
+ SoupMessage *message;
+ gboolean retrying;
GtkWidget *username;
GtkWidget *password;
GtkWidget *rememberpass;
@@ -341,7 +345,7 @@ gchar *rss_component_peek_base_directory(MailComponent *component);
void custom_feed_timeout(void);
CamelFolder *check_feed_folder(gchar *folder_name);
gboolean setup_feed(add_feed *feed);
-gboolean web_auth_dialog(gchar *url);
+void web_auth_dialog(RSS_AUTH *auth_info);
gchar *get_main_folder(void);
gpointer lookup_key(gpointer key);
void rss_delete_feed(gchar *name, gboolean folder);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]