[frogr] Remove the option to explicitly enable/disable the default proxy
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Remove the option to explicitly enable/disable the default proxy
- Date: Sun, 25 May 2014 16:16:34 +0000 (UTC)
commit e53b5d701438acfbb921825b6281864cfb7ca730
Author: Mario Sanchez Prada <msanchez gnome org>
Date: Sat May 24 22:22:59 2014 +0900
Remove the option to explicitly enable/disable the default proxy
Since libsoup 2.34, any SoupSession will automatically pick the global
configuration settings for the system, so this is not needed anymore.
src/flicksoup/fsp-session.c | 113 ++++++++++++++++++++++---------------------
src/flicksoup/fsp-session.h | 7 ++-
src/frogr-config.c | 31 ------------
src/frogr-config.h | 4 --
src/frogr-controller.c | 62 ++++++++++++------------
src/frogr-controller.h | 2 +-
src/frogr-settings-dialog.c | 49 ++++---------------
7 files changed, 103 insertions(+), 165 deletions(-)
---
diff --git a/src/flicksoup/fsp-session.c b/src/flicksoup/fsp-session.c
index 5258f16..a41744f 100644
--- a/src/flicksoup/fsp-session.c
+++ b/src/flicksoup/fsp-session.c
@@ -66,7 +66,7 @@ struct _FspSessionPrivate
gchar *tmp_token;
gchar *tmp_token_secret;
- gboolean using_gnome_proxy;
+ gboolean using_default_proxy;
SoupURI *proxy_uri;
SoupSession *soup_session;
};
@@ -489,8 +489,7 @@ fsp_session_init (FspSession *self)
self->priv->token_secret = NULL;
self->priv->tmp_token = NULL;
self->priv->tmp_token_secret = NULL;
-
- self->priv->using_gnome_proxy = FALSE;
+ self->priv->using_default_proxy = TRUE;
self->priv->proxy_uri = NULL;
#ifdef SOUP_VERSION_2_42
@@ -1651,77 +1650,79 @@ fsp_session_new (const gchar *api_key,
NULL));
}
+void
+fsp_session_set_default_proxy (FspSession *self,
+ gboolean enabled)
+{
+ g_return_val_if_fail (FSP_IS_SESSION (self), FALSE);
+
+ /* Ensure we clean the URI of a custom proxy, if present */
+ if (self->priv->proxy_uri)
+ soup_uri_free (self->priv->proxy_uri);
+ self->priv->proxy_uri = NULL;
+
+ /* Explicitly enable or disable the feature in the session */
+ if (enabled)
+ soup_session_add_feature_by_type (self->priv->soup_session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
+ else
+ soup_session_remove_feature_by_type (self->priv->soup_session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
+
+ self->priv->using_default_proxy = enabled;
+}
+
gboolean
-fsp_session_set_http_proxy (FspSession *self,
- gboolean use_gnome_proxy,
+fsp_session_set_custom_proxy (FspSession *self,
const char *host, const char *port,
const char *username, const char *password)
{
SoupURI *proxy_uri = NULL;
- gboolean using_gnome_proxy_before = FALSE;
+ gboolean was_using_default_proxy = FALSE;
g_return_val_if_fail (FSP_IS_SESSION (self), FALSE);
- /* We're gonna need this to make a good decision later */
- using_gnome_proxy_before = self->priv->using_gnome_proxy;
-
- if (using_gnome_proxy_before != use_gnome_proxy)
+ if (host != NULL)
{
- void (*soup_feature_func) (SoupSession *, GType) = NULL;
- if (use_gnome_proxy)
- soup_feature_func = soup_session_add_feature_by_type;
- else
- soup_feature_func = soup_session_remove_feature_by_type;
-
- /* Add or remove the feature */
- soup_feature_func (self->priv->soup_session,
- SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
- }
- self->priv->using_gnome_proxy = use_gnome_proxy;
+ const gchar *actual_user = NULL;
+ const gchar *actual_password = NULL;
+ guint actual_port = 0;
- if (!self->priv->using_gnome_proxy)
- {
- /* If using the GNOME proxy we just forget about the rest. */
- if (host != NULL)
- {
- const gchar *actual_user = NULL;
- const gchar *actual_password = NULL;
- guint actual_port = 0;
-
- /* Ensure no garbage is used for username */
- if (username == NULL || *username == '\0')
- actual_user = NULL;
- else
- actual_user = username;
+ /* Ensure no garbage is used for username */
+ if (username == NULL || *username == '\0')
+ actual_user = NULL;
+ else
+ actual_user = username;
- /* Ensure no garbage is used for password */
- if (password == NULL || *password == '\0')
- actual_password = NULL;
- else
- actual_password = password;
-
- /* We need a numeric port */
- actual_port = (guint) g_ascii_strtoll ((gchar *) port, NULL, 10);
-
- /* Build the actual SoupURI object */
- proxy_uri = soup_uri_new (NULL);
- soup_uri_set_scheme (proxy_uri, SOUP_URI_SCHEME_HTTP);
- soup_uri_set_host (proxy_uri, host);
- soup_uri_set_port (proxy_uri, actual_port);
- soup_uri_set_user (proxy_uri, actual_user);
- soup_uri_set_password (proxy_uri, actual_password);
- soup_uri_set_path (proxy_uri, "");
- }
+ /* Ensure no garbage is used for password */
+ if (password == NULL || *password == '\0')
+ actual_password = NULL;
+ else
+ actual_password = password;
+
+ /* We need a numeric port */
+ actual_port = (guint) g_ascii_strtoll ((gchar *) port, NULL, 10);
+
+ /* Build the actual SoupURI object */
+ proxy_uri = soup_uri_new (NULL);
+ soup_uri_set_scheme (proxy_uri, SOUP_URI_SCHEME_HTTP);
+ soup_uri_set_host (proxy_uri, host);
+ soup_uri_set_port (proxy_uri, actual_port);
+ soup_uri_set_user (proxy_uri, actual_user);
+ soup_uri_set_password (proxy_uri, actual_password);
+ soup_uri_set_path (proxy_uri, "");
}
- /* Set/unset the proxy */
+ /* Set the custom proxy (even if no valid data was provided) */
g_object_set (G_OBJECT (self->priv->soup_session),
SOUP_SESSION_PROXY_URI,
proxy_uri,
NULL);
+ was_using_default_proxy = self->priv->using_default_proxy;
+ self->priv->using_default_proxy = FALSE;
+
/* Update internal values if needed */
- if ((!self->priv->proxy_uri && proxy_uri)
+ if (was_using_default_proxy
+ || (!self->priv->proxy_uri && proxy_uri)
|| (self->priv->proxy_uri && !proxy_uri)
|| (self->priv->proxy_uri && proxy_uri && !soup_uri_equal (self->priv->proxy_uri, proxy_uri)))
{
@@ -1735,7 +1736,7 @@ fsp_session_set_http_proxy (FspSession *self,
return TRUE;
}
- return using_gnome_proxy_before != use_gnome_proxy;
+ return FALSE;
}
const gchar *
diff --git a/src/flicksoup/fsp-session.h b/src/flicksoup/fsp-session.h
index 298fd91..40b1f4c 100644
--- a/src/flicksoup/fsp-session.h
+++ b/src/flicksoup/fsp-session.h
@@ -65,12 +65,13 @@ FspSession *
fsp_session_new (const gchar *api_key,
const gchar *secret,
const gchar *token);
+void
+fsp_session_set_default_proxy (FspSession *self,
+ gboolean enabled);
gboolean
-fsp_session_set_http_proxy (FspSession *self,
- gboolean use_gnome_proxy,
+fsp_session_set_custom_proxy (FspSession *self,
const char *host, const char *port,
const char *username, const char *password);
-
const gchar *
fsp_session_get_api_key (FspSession *self);
diff --git a/src/frogr-config.c b/src/frogr-config.c
index 95a2270..ace284e 100644
--- a/src/frogr-config.c
+++ b/src/frogr-config.c
@@ -71,7 +71,6 @@ struct _FrogrConfigPrivate
gboolean use_dark_theme;
gboolean use_proxy;
- gboolean use_gnome_proxy;
gchar *proxy_host;
gchar *proxy_port;
gchar *proxy_username;
@@ -508,12 +507,6 @@ _load_proxy_data_xml (FrogrConfig *self,
g_strstrip (priv->proxy_password);
}
- if (!xmlStrcmp (node->name, (const xmlChar*) "use-gnome-proxy"))
- {
- content = xmlNodeGetContent (node);
- priv->use_gnome_proxy = !xmlStrcmp (content, (const xmlChar*) "1");
- }
-
if (content)
xmlFree (content);
}
@@ -727,7 +720,6 @@ _save_settings (FrogrConfig *self)
_xml_add_string_child (node, "proxy-port", priv->proxy_port);
_xml_add_string_child (node, "proxy-username", priv->proxy_username);
_xml_add_string_child (node, "proxy-password", priv->proxy_password);
- _xml_add_bool_child (node, "use-gnome-proxy", priv->use_gnome_proxy);
xmlAddChild (root, node);
xml_path = g_build_filename (priv->config_dir, SETTINGS_FILENAME, NULL);
@@ -990,7 +982,6 @@ frogr_config_init (FrogrConfig *self)
priv->mainview_enable_tooltips = TRUE;
priv->use_dark_theme = TRUE;
priv->use_proxy = FALSE;
- priv->use_gnome_proxy = FALSE;
priv->proxy_host = NULL;
priv->proxy_port = NULL;
priv->proxy_username = NULL;
@@ -1518,28 +1509,6 @@ frogr_config_get_use_proxy (FrogrConfig *self)
}
void
-frogr_config_set_use_gnome_proxy (FrogrConfig *self, gboolean value)
-{
- FrogrConfigPrivate * priv = NULL;
-
- g_return_if_fail (FROGR_IS_CONFIG (self));
-
- priv = FROGR_CONFIG_GET_PRIVATE (self);
- priv->use_gnome_proxy = value;
-}
-
-gboolean
-frogr_config_get_use_gnome_proxy (FrogrConfig *self)
-{
- FrogrConfigPrivate *priv = NULL;
-
- g_return_val_if_fail (FROGR_IS_CONFIG (self), FALSE);
-
- priv = FROGR_CONFIG_GET_PRIVATE (self);
- return priv->use_gnome_proxy;
-}
-
-void
frogr_config_set_proxy_host (FrogrConfig *self, const gchar *host)
{
FrogrConfigPrivate * priv = NULL;
diff --git a/src/frogr-config.h b/src/frogr-config.h
index 0e06bba..3dc3bbc 100644
--- a/src/frogr-config.h
+++ b/src/frogr-config.h
@@ -154,10 +154,6 @@ void frogr_config_set_use_proxy (FrogrConfig *self, gboolean value);
gboolean frogr_config_get_use_proxy (FrogrConfig *self);
-void frogr_config_set_use_gnome_proxy (FrogrConfig *self, gboolean value);
-
-gboolean frogr_config_get_use_gnome_proxy (FrogrConfig *self);
-
void frogr_config_set_proxy_host (FrogrConfig *self, const gchar *host);
const gchar *frogr_config_get_proxy_host (FrogrConfig *self);
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 108f618..c54a299 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -365,16 +365,12 @@ _g_application_startup_cb (GApplication *app, gpointer data)
/* Set HTTP proxy if needed */
if (frogr_config_get_use_proxy (priv->config))
{
- const gboolean use_gnome_proxy = frogr_config_get_use_gnome_proxy (priv->config);
const gchar *host = frogr_config_get_proxy_host (priv->config);
const gchar *port = frogr_config_get_proxy_port (priv->config);
const gchar *username = frogr_config_get_proxy_username (priv->config);
const gchar *password = frogr_config_get_proxy_password (priv->config);
- frogr_controller_set_proxy (self, use_gnome_proxy,
- host, port, username, password);
+ frogr_controller_set_proxy (self, FALSE, host, port, username, password);
}
- else
- frogr_controller_set_proxy (self, FALSE, NULL, NULL, NULL, NULL);
}
static void
@@ -2645,7 +2641,7 @@ frogr_controller_get_state (FrogrController *self)
void
frogr_controller_set_proxy (FrogrController *self,
- gboolean use_gnome_proxy,
+ gboolean use_default_proxy,
const char *host, const char *port,
const char *username, const char *password)
{
@@ -2656,34 +2652,38 @@ frogr_controller_set_proxy (FrogrController *self,
priv = FROGR_CONTROLLER_GET_PRIVATE (self);
+ if (use_default_proxy)
+ {
+ DEBUG ("Using default proxy settings");
+ fsp_session_set_default_proxy (priv->session, TRUE);
+
+ if (!priv->photosets_fetched || !priv->groups_fetched || !priv->tags_fetched)
+ _fetch_everything (self, FALSE);
+
+ return;
+ }
+
/* The host is mandatory to set up a proxy */
- if (!use_gnome_proxy && (host == NULL || *host == '\0')) {
- proxy_changed = fsp_session_set_http_proxy (priv->session, FALSE,
- NULL, NULL, NULL, NULL);
+ if (host == NULL || *host == '\0') {
+ proxy_changed = fsp_session_set_custom_proxy (priv->session, NULL, NULL, NULL, NULL);
DEBUG ("%s", "Not enabling the HTTP proxy");
} else {
- if (!use_gnome_proxy)
- {
- gchar *auth_part = NULL;
- gboolean has_username = FALSE;
- gboolean has_password = FALSE;
-
- has_username = (username != NULL && *username != '\0');
- has_password = (password != NULL && *password != '\0');
-
- if (has_username && has_password)
- auth_part = g_strdup_printf ("%s:%s@", username, password);
-
- DEBUG ("Using HTTP proxy: %s%s:%s", auth_part ? auth_part : "", host, port);
- g_free (auth_part);
- }
- else
- DEBUG ("Using GNOME general proxy settings");
-
- proxy_changed = fsp_session_set_http_proxy (priv->session,
- use_gnome_proxy,
- host, port,
- username, password);
+ gchar *auth_part = NULL;
+ gboolean has_username = FALSE;
+ gboolean has_password = FALSE;
+
+ has_username = (username != NULL && *username != '\0');
+ has_password = (password != NULL && *password != '\0');
+
+ if (has_username && has_password)
+ auth_part = g_strdup_printf ("%s:%s@", username, password);
+
+ DEBUG ("Using HTTP proxy: %s%s:%s", auth_part ? auth_part : "", host, port);
+ g_free (auth_part);
+
+ proxy_changed = fsp_session_set_custom_proxy (priv->session,
+ host, port,
+ username, password);
}
/* Re-fetch information if needed after changing proxy configuration */
diff --git a/src/frogr-controller.h b/src/frogr-controller.h
index 177896b..91ef443 100644
--- a/src/frogr-controller.h
+++ b/src/frogr-controller.h
@@ -80,7 +80,7 @@ GSList *frogr_controller_get_all_accounts (FrogrController *self);
FrogrControllerState frogr_controller_get_state (FrogrController *self);
void frogr_controller_set_proxy (FrogrController *self,
- gboolean use_gnome_proxy,
+ gboolean use_default_proxy,
const char *host, const char *port,
const char *username, const char *password);
diff --git a/src/frogr-settings-dialog.c b/src/frogr-settings-dialog.c
index 7c56b13..40cba4f 100644
--- a/src/frogr-settings-dialog.c
+++ b/src/frogr-settings-dialog.c
@@ -63,7 +63,6 @@ typedef struct _FrogrSettingsDialogPrivate {
GtkWidget *proxy_username_entry;
GtkWidget *proxy_password_label;
GtkWidget *proxy_password_entry;
- GtkWidget *use_gnome_proxy_cb;
GtkWidget *enable_tags_autocompletion_cb;
GtkWidget *keep_file_extensions_cb;
@@ -85,8 +84,6 @@ typedef struct _FrogrSettingsDialogPrivate {
FspContentType content_type;
gboolean use_proxy;
- gboolean use_gnome_proxy;
-
gchar *proxy_host;
gchar *proxy_port;
gchar *proxy_username;
@@ -426,13 +423,6 @@ _add_connection_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
gtk_grid_attach (GTK_GRID (grid), entry, 1, 3, 1, 1);
priv->proxy_password_entry = entry;
- /* Use GNOME General Proxy Settings */
-
- cbutton = gtk_check_button_new_with_mnemonic (_("_Use GNOME General Proxy Settings"));
- gtk_widget_set_hexpand (GTK_WIDGET (cbutton), TRUE);
- gtk_grid_attach (GTK_GRID (grid), cbutton, 1, 4, 1, 1);
- priv->use_gnome_proxy_cb = cbutton;
-
gtk_box_pack_start (GTK_BOX (vbox), grid, FALSE, FALSE, 0);
/* Connect signals */
@@ -440,10 +430,6 @@ _add_connection_page (FrogrSettingsDialog *self, GtkNotebook *notebook)
G_CALLBACK (_on_button_toggled),
self);
- g_signal_connect (G_OBJECT (priv->use_gnome_proxy_cb), "toggled",
- G_CALLBACK (_on_button_toggled),
- self);
-
g_signal_connect (G_OBJECT (priv->proxy_port_entry), "insert-text",
G_CALLBACK (_proxy_port_inserted_cb),
NULL);
@@ -524,7 +510,6 @@ _fill_dialog_with_data (FrogrSettingsDialog *self)
priv->import_tags = frogr_config_get_import_tags_from_metadata (priv->config);
priv->use_dark_theme = frogr_config_get_use_dark_theme (priv->config);
priv->use_proxy = frogr_config_get_use_proxy (priv->config);
- priv->use_gnome_proxy = frogr_config_get_use_gnome_proxy (priv->config);
g_free (priv->proxy_host);
priv->proxy_host = g_strdup (frogr_config_get_proxy_host (priv->config));
@@ -590,8 +575,6 @@ _fill_dialog_with_data (FrogrSettingsDialog *self)
priv->use_dark_theme);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_proxy_cb),
priv->use_proxy);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->use_gnome_proxy_cb),
- priv->use_gnome_proxy);
if (priv->proxy_host)
gtk_entry_set_text (GTK_ENTRY (priv->proxy_host_entry), priv->proxy_host);
@@ -632,7 +615,6 @@ _save_data (FrogrSettingsDialog *self)
frogr_config_set_use_dark_theme (priv->config, priv->use_dark_theme);
frogr_config_set_use_proxy (priv->config, priv->use_proxy);
- frogr_config_set_use_gnome_proxy (priv->config, priv->use_gnome_proxy);
g_free (priv->proxy_host);
priv->proxy_host = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->proxy_host_entry)));
@@ -669,7 +651,6 @@ static void
_update_ui (FrogrSettingsDialog *self)
{
FrogrSettingsDialogPrivate *priv = NULL;
- gboolean using_manual_proxy = FALSE;
priv = FROGR_SETTINGS_DIALOG_GET_PRIVATE (self);
@@ -680,16 +661,14 @@ _update_ui (FrogrSettingsDialog *self)
/* Sensititveness of proxy settings related widgets */
- using_manual_proxy = priv->use_proxy && !priv->use_gnome_proxy;
- gtk_widget_set_sensitive (priv->use_gnome_proxy_cb, priv->use_proxy);
- gtk_widget_set_sensitive (priv->proxy_host_label, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_host_entry, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_port_label, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_port_entry, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_username_label, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_username_entry, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_password_label, using_manual_proxy);
- gtk_widget_set_sensitive (priv->proxy_password_entry, using_manual_proxy);
+ gtk_widget_set_sensitive (priv->proxy_host_label, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_host_entry, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_port_label, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_port_entry, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_username_label, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_username_entry, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_password_label, priv->use_proxy);
+ gtk_widget_set_sensitive (priv->proxy_password_entry, priv->use_proxy);
}
static void
@@ -799,12 +778,6 @@ _on_button_toggled (GtkToggleButton *button, gpointer data)
DEBUG ("Enable HTTP Proxy: %s", active ? "YES" : "NO");
}
- if (GTK_WIDGET (button) == priv->use_gnome_proxy_cb)
- {
- priv->use_gnome_proxy = active;
- DEBUG ("Use GNOME General Proxy Settings: %s", active ? "YES" : "NO");
- }
-
_update_ui (self);
}
@@ -868,11 +841,11 @@ static void _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data
/* Update proxy status */
if (priv->use_proxy)
frogr_controller_set_proxy (priv->controller,
- priv->use_gnome_proxy,
+ FALSE,
priv->proxy_host, priv->proxy_port,
priv->proxy_username, priv->proxy_password);
else
- frogr_controller_set_proxy (priv->controller, FALSE, NULL, NULL, NULL, NULL);
+ frogr_controller_set_proxy (priv->controller, TRUE, NULL, NULL, NULL, NULL);
/* Update dark theme related stuff */
frogr_controller_set_use_dark_theme (priv->controller, priv->use_dark_theme);
@@ -953,7 +926,6 @@ frogr_settings_dialog_init (FrogrSettingsDialog *self)
priv->import_tags_cb = NULL;
priv->use_dark_theme_cb = NULL;
priv->use_proxy_cb = NULL;
- priv->use_gnome_proxy_cb = NULL;
priv->proxy_host_label = NULL;
priv->proxy_host_entry = NULL;
priv->proxy_port_label = NULL;
@@ -975,7 +947,6 @@ frogr_settings_dialog_init (FrogrSettingsDialog *self)
priv->import_tags = TRUE;
priv->use_dark_theme = TRUE;
priv->use_proxy = FALSE;
- priv->use_gnome_proxy = FALSE;
priv->proxy_host = NULL;
priv->proxy_port = NULL;
priv->proxy_username = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]