From 7f5d49e9973a8b6e5262db3ebfdf3cc0afddb710 Mon Sep 17 00:00:00 2001 From: jmalonzo Date: Fri, 18 May 2007 05:49:28 +0000 Subject: [PATCH] fix proxy change detection git-svn-id: svn+ssh://svn.gnome.org/svn/straw/trunk@291 141a2093-ea25-0410-9ad2-d44d734a8f13 --- src/lib/Config.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/lib/Config.py b/src/lib/Config.py index fdf2212..5072505 100644 --- a/src/lib/Config.py +++ b/src/lib/Config.py @@ -221,7 +221,7 @@ class GconfProxyConfig(ProxyConfig): client.notify_add(self.GCONF_HTTP_PROXY_USER, self.proxy_auth_username_changed) client.notify_add(self.GCONF_HTTP_PROXY_PASSWORD, self.proxy_auth_password_changed) - self.use = client.get_bool(self.GCONF_HTTP_PROXY_USE) + self.active = client.get_bool(self.GCONF_HTTP_PROXY_USE) self.host = client.get_string(self.GCONF_HTTP_PROXY_HOST) self.port = client.get_int(self.GCONF_HTTP_PROXY_PORT) self.auth = client.get_bool(self.GCONF_HTTP_PROXY_AUTHENTICATION) @@ -229,23 +229,24 @@ class GconfProxyConfig(ProxyConfig): self.username = client.get_string(self.GCONF_HTTP_PROXY_USER) self.password = client.get_string(self.GCONF_HTTP_PROXY_PASSWORD) + # here be gconf logic def proxy_mode_changed(self, client, notify_id, entry, *args): - self.use = entry.value.get_bool() + self.active = entry.value.get_bool() def proxy_host_changed(self, client, notify_id, entry, *args): value = entry.value.get_string() if value: self.host = value else: - self.use = 0 + self.active = False def proxy_port_changed(self, client, notify_id, entry, *args): value = entry.value.get_int() if value: self.port = value else: - self.use = 0 + self.active = False def proxy_auth_changed(self, client, notify_id, entry, *args): value = entry.value.get_bool() @@ -265,11 +266,14 @@ class EnvironmentProxyConfig(ProxyConfig): def __init__(self): ProxyConfig.__init__(self) - _read_env() + self._read_env() def _read_env(self): proxy = None proxies = urllib.getproxies() + if not proxies: + return + for key, value in proxies.iteritems(): proxy = proxies.get(key) user, authority = urllib.splituser(proxy) @@ -281,7 +285,6 @@ class EnvironmentProxyConfig(ProxyConfig): self.auth = True return - class Config(object, Event.SignalEmitter): _straw_config_file = os.path.join(straw_home(), "config") @@ -308,12 +311,12 @@ class Config(object, Event.SignalEmitter): self._proxy = None def initialize_proxy(self): - # GConfProxyConfig has precedence over EnvironmentProxyConfig - pcchoices = (GconfProxyConfig, EnvironmentProxyConfig) - for p in pcchoices: - self._proxy = p() - if self._proxy.active: - break + # EnvironmentProxy has precedence + self._proxy = EnvironmentProxyConfig() + if not self._proxy.active: + # .. default to GConfProxyConfig so we can listen for network + # setting changes (e.g, changes in network preference) + self._proxy = GconfProxyConfig() def initialize_options(self): # Call this after calling Config's constructor -- 2.11.4.GIT