[banshee/gsettings: 2/7] Port proxy configuration to GSettings



commit 2775f1668a278f3a54b442dccb834312daeba8ce
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sat Oct 12 19:33:39 2013 +0200

    Port proxy configuration to GSettings

 build/build.environment.mk                         |    3 +-
 build/m4/banshee/gnome-sharp.m4                    |    8 --
 configure.ac                                       |    1 -
 src/Backends/Banshee.Gnome/Banshee.Gnome.csproj    |    3 +-
 .../Banshee.GnomeBackend/GnomeService.cs           |   14 ++--
 .../{GConfProxy.cs => ProxyConfiguration.cs}       |   83 +++++++++++---------
 src/Backends/Banshee.Gnome/Makefile.am             |    4 +-
 7 files changed, 56 insertions(+), 60 deletions(-)
---
diff --git a/build/build.environment.mk b/build/build.environment.mk
index 48cae63..95a0251 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -15,7 +15,6 @@ LINK_ICSHARP_ZIP_LIB = -r:ICSharpCode.SharpZipLib
 LINK_MONO_ZEROCONF = $(MONO_ZEROCONF_LIBS)
 LINK_GLIB = $(GLIBSHARP_LIBS)
 LINK_GTK = $(GTKSHARP_LIBS)
-LINK_GCONF = $(GCONFSHARP_LIBS)
 LINK_GIO = $(GIOSHARP_LIBS)
 LINK_GUDEV = $(GUDEV_SHARP_LIBS)
 LINK_DBUS = $(DBUS_SHARP_LIBS) $(DBUS_SHARP_GLIB_LIBS)
@@ -169,7 +168,7 @@ REF_EXTENSION_WIKIPEDIA= $(LINK_BANSHEE_WEBBROWSER_DEPS)
 
 # Backends
 REF_BACKEND_GIO = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_GIO) $(LINK_GUDEV)
-REF_BACKEND_GNOME = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_BANSHEE_THICKCLIENT_DEPS) $(LINK_GCONF)
+REF_BACKEND_GNOME = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_BANSHEE_THICKCLIENT_DEPS)
 REF_BACKEND_GSTREAMER = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_GLIB)
 REF_BACKEND_UNIX = $(LINK_BANSHEE_CORE_DEPS) $(LINK_MONO_POSIX)
 REF_BACKEND_OSX = $(LINK_BANSHEE_SERVICES_DEPS) $(LINK_BANSHEE_THICKCLIENT_DEPS) $(MONOMAC_LIBS)
diff --git a/configure.ac b/configure.ac
index 0077700..86bd1ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -135,7 +135,6 @@ PKG_CHECK_MODULES(SQLITE, sqlite3 >= 3.4)
 dnl GNOME (optional)
 AC_ARG_ENABLE(gnome, AC_HELP_STRING([--disable-gnome], [Disable GNOME support]), , enable_gnome="yes")
 if test "x$enable_gnome" = "xyes"; then
-       BANSHEE_CHECK_GNOME_SHARP
        GLIB_GSETTINGS
        AM_CONDITIONAL(ENABLE_GNOME, true)
 else
diff --git a/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj b/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
index 8152c5a..58496a9 100644
--- a/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
+++ b/src/Backends/Banshee.Gnome/Banshee.Gnome.csproj
@@ -85,13 +85,12 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Banshee.GnomeBackend\GConfConfigurationClient.cs" />
     <Compile Include="Banshee.GnomeBackend\GnomeService.cs" />
     <Compile Include="Banshee.GnomeBackend\Brasero.cs" />
     <Compile Include="Banshee.GnomeBackend\DiscDuplicator.cs" />
     <Compile Include="Banshee.GnomeBackend\GnomeScreensaverManager.cs" />
-    <Compile Include="Banshee.GnomeBackend\GConfProxy.cs" />
     <Compile Include="Banshee.GnomeBackend\GSettingsConfigurationClient.cs" />
+    <Compile Include="Banshee.GnomeBackend\ProxyConfiguration.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="Banshee.Gnome.addin.xml">
diff --git a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs 
b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
index b6a18f0..71d5207 100644
--- a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
+++ b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GnomeService.cs
@@ -35,7 +35,7 @@ namespace Banshee.GnomeBackend
 {
     public class GnomeService : IExtensionService, IDisposable
     {
-        private GConfProxy gconf_proxy;
+        private ProxyConfiguration proxy;
 
         private Brasero brasero;
         internal Brasero Brasero {
@@ -50,10 +50,10 @@ namespace Banshee.GnomeBackend
         {
             try {
                 // FIXME: this needs to be deferred/delayed initialized
-                gconf_proxy = new GConfProxy ();
+                proxy = new ProxyConfiguration ();
             } catch (Exception e) {
-                Hyena.Log.Exception ("GConfProxy", e);
-                gconf_proxy = null;
+                Hyena.Log.Exception ("ProxyConfiguration", e);
+                proxy = null;
             }
 
             try {
@@ -75,9 +75,9 @@ namespace Banshee.GnomeBackend
                 brasero = null;
             }
 
-            if (gconf_proxy != null) {
-                gconf_proxy.Dispose ();
-                gconf_proxy = null;
+            if (proxy != null) {
+                proxy.Dispose ();
+                proxy = null;
             }
 
             if (Browser.OpenHandler == (Banshee.Web.Browser.OpenUrlHandler) OpenUrl) {
diff --git a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GConfProxy.cs 
b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/ProxyConfiguration.cs
similarity index 59%
rename from src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GConfProxy.cs
rename to src/Backends/Banshee.Gnome/Banshee.GnomeBackend/ProxyConfiguration.cs
index 4e8b761..e9a5638 100644
--- a/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/GConfProxy.cs
+++ b/src/Backends/Banshee.Gnome/Banshee.GnomeBackend/ProxyConfiguration.cs
@@ -1,14 +1,16 @@
 // 
-// GConfProxy.cs
+// ProxyConfiguration.cs
 // 
 // Author:
 //   Iain Lane <laney ubuntu com>
 //   Ting Z Zhou <ting z zhou intel com>
 //   Aaron Bockover <abockover novell com>
+//   Bertrand Lorentz <bertrand lorentz gmail com>
 // 
 // Copyright 2010 Iain Lane
 // Copyright 2010 Intel Corp
 // Copyright 2010 Novell, Inc.
+// Copyright 2013 Bertrand Lorentz
 // 
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
@@ -31,46 +33,50 @@
 using System;
 using System.Net;
 
+using GLib;
+
 using Hyena;
 
 namespace Banshee.GnomeBackend
 {
-    public class GConfProxy : IDisposable
+    public class ProxyConfiguration : IDisposable
     {
-        private const string PROXY = "/system/proxy";
+        private const string PROXY = "org.gnome.system.proxy";
         private const string PROXY_MODE = "mode";
-        private const string PROXY_AUTO_URL = "autoconfig_url";
-        private const string HTTP_PROXY = "/system/http_proxy";
-        private const string PROXY_USE_PROXY = "use_http_proxy";
-        private const string PROXY_USE_AUTH = "use_authentication";
+        private const string PROXY_AUTO_URL = "autoconfig-url";
+        private const string HTTP_PROXY = "org.gnome.system.proxy.http";
+        private const string PROXY_USE_PROXY = "enabled";
+        private const string PROXY_USE_AUTH = "use-authentication";
         private const string PROXY_HOST = "host";
         private const string PROXY_PORT = "port";
-        private const string PROXY_USER = "authentication_user";
-        private const string PROXY_PASSWORD = "authentication_password";
+        private const string PROXY_USER = "authentication-user";
+        private const string PROXY_PASSWORD = "authentication-password";
         private const string PROXY_BYPASS_LIST = "ignore_hosts";
 
-        private GConf.Client gconf_client;
+        private Settings settings;
+        private Settings settings_http;
         private uint refresh_id;
 
-        public GConfProxy ()
+        public ProxyConfiguration ()
         {
-            gconf_client = new GConf.Client ();
-            gconf_client.AddNotify (PROXY, OnGConfNotify);
-            gconf_client.AddNotify (HTTP_PROXY, OnGConfNotify);
+            settings = new Settings (PROXY);
+            settings_http = new Settings (HTTP_PROXY);
+            settings.ChangeEvent += OnSettingsChange;
+            //settings.AddNotify (HTTP_PROXY, OnGConfNotify);
 
             RefreshProxy ();
         }
 
         public void Dispose ()
         {
-            if (gconf_client != null) {
-                gconf_client.RemoveNotify (PROXY, OnGConfNotify);
-                gconf_client.RemoveNotify (HTTP_PROXY, OnGConfNotify);
-                gconf_client = null;
+            if (settings != null) {
+                settings.ChangeEvent -= OnSettingsChange;
+                //gconf_client.RemoveNotify (HTTP_PROXY, OnGConfNotify);
+                settings = null;
             }
         }
 
-        private void OnGConfNotify (object o, GConf.NotifyEventArgs args)
+        private void OnSettingsChange (object o, ChangeEventArgs args)
         {
             if (refresh_id > 0) {
                 return;
@@ -82,23 +88,24 @@ namespace Banshee.GnomeBackend
             // to any of the GNOME proxy settings. Also, at any given
             // point in the modification of the settings, the state may
             // be invalid, so retain the previous good configuration.
+            // TODO: Timeout still needed ?
             refresh_id = GLib.Timeout.Add (5000, RefreshProxy);
         }
 
         private bool RefreshProxy ()
         {
-            Log.Information ("Updating web proxy from GConf");
+            Hyena.Log.Information ("Updating web proxy from GConf");
             try {
-                HttpWebRequest.DefaultWebProxy = GetProxyFromGConf ();
+                HttpWebRequest.DefaultWebProxy = GetProxyFromSettings ();
             } catch {
-                Log.Warning ("Not updating proxy settings. Invalid state");
+                Hyena.Log.Warning ("Not updating proxy settings. Invalid state");
             }
 
             refresh_id = 0;
             return false;
         }
 
-        private T Get<T> (string @namespace, string key)
+        /*private T Get<T> (string @namespace, string key)
         {
             try {
                 return (T)gconf_client.Get (@namespace == null
@@ -107,22 +114,22 @@ namespace Banshee.GnomeBackend
             } catch {
                 return default (T);
             }
-        }
+        }*/
 
-        private WebProxy GetProxyFromGConf ()
+        private WebProxy GetProxyFromSettings ()
         {
-            var proxy_mode = Get<string> (PROXY, PROXY_MODE);
-            var proxy_auto_url = Get<string> (PROXY, PROXY_AUTO_URL);
-            var use_proxy = Get<bool> (HTTP_PROXY, PROXY_USE_PROXY);
-            var use_auth = Get<bool> (null, HTTP_PROXY);
-            var proxy_host = Get<string> (HTTP_PROXY, PROXY_HOST);
-            var proxy_port = Get<int> (HTTP_PROXY, PROXY_PORT);
-            var proxy_user = Get<string> (null, HTTP_PROXY);
-            var proxy_password = Get<string> (null, HTTP_PROXY);
-            var proxy_bypass_list = Get<string[]> (HTTP_PROXY, PROXY_BYPASS_LIST);
+            var proxy_mode = settings.GetString (PROXY_MODE);
+            var proxy_auto_url = settings.GetString (PROXY_AUTO_URL);
+            var use_proxy = settings_http.GetBoolean (PROXY_USE_PROXY);
+            var use_auth = settings_http.GetBoolean (PROXY_USE_AUTH);
+            var proxy_host = settings_http.GetString (PROXY_HOST);
+            var proxy_port = settings_http.GetInt (PROXY_PORT);
+            var proxy_user = settings_http.GetString (PROXY_USER);
+            var proxy_password = settings_http.GetString (PROXY_PASSWORD);
+            var proxy_bypass_list = settings_http.GetStrv (PROXY_BYPASS_LIST);
 
             if (!use_proxy || proxy_mode == "none" || String.IsNullOrEmpty (proxy_host)) {
-                Log.Debug ("Direct connection, no proxy in use");
+                Hyena.Log.Debug ("Direct connection, no proxy in use");
                 return null;
             }
 
@@ -131,9 +138,9 @@ namespace Banshee.GnomeBackend
             if (proxy_mode == "auto") {
                 if (!String.IsNullOrEmpty (proxy_auto_url)) {
                     proxy.Address = new Uri (proxy_auto_url);
-                    Log.Debug ("Automatic proxy connection", proxy.Address.AbsoluteUri);
+                    Hyena.Log.Debug ("Automatic proxy connection", proxy.Address.AbsoluteUri);
                 } else {
-                    Log.Warning ("Direct connection, no proxy in use. Proxy mode was 'auto' but no automatic 
configuration URL was found.");
+                    Hyena.Log.Warning ("Direct connection, no proxy in use. Proxy mode was 'auto' but no 
automatic configuration URL was found.");
                     return null;
                 }
             } else {
@@ -141,7 +148,7 @@ namespace Banshee.GnomeBackend
                 proxy.Credentials = use_auth
                     ? new NetworkCredential (proxy_user, proxy_password)
                     : null;
-                Log.Debug ("Manual proxy connection", proxy.Address.AbsoluteUri);
+                Hyena.Log.Debug ("Manual proxy connection", proxy.Address.AbsoluteUri);
             }
 
             if (proxy_bypass_list == null) {
diff --git a/src/Backends/Banshee.Gnome/Makefile.am b/src/Backends/Banshee.Gnome/Makefile.am
index ba2da7f..342d425 100644
--- a/src/Backends/Banshee.Gnome/Makefile.am
+++ b/src/Backends/Banshee.Gnome/Makefile.am
@@ -6,10 +6,10 @@ INSTALL_DIR = $(BACKENDS_INSTALL_DIR)
 SOURCES =  \
        Banshee.GnomeBackend/Brasero.cs \
        Banshee.GnomeBackend/DiscDuplicator.cs \
-       Banshee.GnomeBackend/GConfProxy.cs \
        Banshee.GnomeBackend/GnomeScreensaverManager.cs \
        Banshee.GnomeBackend/GnomeService.cs \
-       Banshee.GnomeBackend/GSettingsConfigurationClient.cs
+       Banshee.GnomeBackend/GSettingsConfigurationClient.cs \
+       Banshee.GnomeBackend/ProxyConfiguration.cs
 
 RESOURCES =  \
        Banshee.Gnome.addin.xml \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]