f-spot r4644 - in trunk: . src src/Platform/Gnome src/Platform/Null
- From: sdelcroix svn gnome org
- To: svn-commits-list gnome org
- Subject: f-spot r4644 - in trunk: . src src/Platform/Gnome src/Platform/Null
- Date: Fri, 28 Nov 2008 13:11:05 +0000 (UTC)
Author: sdelcroix
Date: Fri Nov 28 13:11:05 2008
New Revision: 4644
URL: http://svn.gnome.org/viewvc/f-spot?rev=4644&view=rev
Log:
use the WebProxy everywhere
2008-11-28 Stephane Delcroix <sdelcroix novell com>
this patch is based on the work done by Anton Keks on bgo#432745
* src/Platform/Gnome/PreferenceBackend.cs: internal Get<T> () method
* src/Preferences.cs: use shorter keys, move GetWebProxy in WebProxy
* src/Platform/Gnome/WebProxy.cs: set the WebRequestDefaultProxy
according to gnome settings.
* src/main.cs: Init () the Platform.WebProxy
* src/Platform/Null/WebProxy.cs: dummy WebProxy
Added:
trunk/src/Platform/Gnome/WebProxy.cs
trunk/src/Platform/Null/WebProxy.cs
Modified:
trunk/ChangeLog
trunk/src/FormClient.cs
trunk/src/Makefile.am
trunk/src/Platform/Gnome/PreferenceBackend.cs
trunk/src/Preferences.cs
trunk/src/main.cs
Modified: trunk/src/FormClient.cs
==============================================================================
--- trunk/src/FormClient.cs (original)
+++ trunk/src/FormClient.cs Fri Nov 28 13:11:05 2008
@@ -237,8 +237,6 @@
//Request.UserAgent = "F-Spot Gallery Remote Client";
Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";
- Request.Proxy = WebProxy.GetDefaultProxy ();
-
if (multipart) {
GenerateBoundary ();
Request.ContentType = "multipart/form-data; boundary=" + boundary;
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Fri Nov 28 13:11:05 2008
@@ -79,13 +79,15 @@
$(srcdir)/Platform/Gnome/Desktop.cs \
$(srcdir)/Platform/Gnome/PreferenceBackend.cs \
$(srcdir)/Platform/Gnome/ScreenSaver.cs \
- $(srcdir)/Platform/Gnome/ThumbnailFactory.cs
+ $(srcdir)/Platform/Gnome/ThumbnailFactory.cs \
+ $(srcdir)/Platform/Gnome/WebProxy.cs
NULL_PLATFORM_CSDISTFILES = \
$(srcdir)/Platform/Null/Desktop.cs \
$(srcdir)/Platform/Null/PreferenceBackend.cs \
$(srcdir)/Platform/Null/ScreenSaver.cs \
- $(srcdir)/Platform/Gnome/ThumbnailFactory.cs
+ $(srcdir)/Platform/Null/ThumbnailFactory.cs \
+ $(srcdir)/Platform/Gnome/WebProxy.cs
F_SPOT_CSDISTFILES = \
$(srcdir)/AsyncPixbufLoader.cs \
Modified: trunk/src/Platform/Gnome/PreferenceBackend.cs
==============================================================================
--- trunk/src/Platform/Gnome/PreferenceBackend.cs (original)
+++ trunk/src/Platform/Gnome/PreferenceBackend.cs Fri Nov 28 13:11:05 2008
@@ -84,6 +84,17 @@
}
}
+ internal T Get<T> (string key)
+ {
+ T value = default(T);
+ try {
+ value = (T) Get (key);
+ } catch (NoSuchKeyException) {
+ } catch (InvalidCastException) {
+ }
+ return value;
+ }
+
public void Set (string key, object o)
{
Client.Set (key, o);
Added: trunk/src/Platform/Gnome/WebProxy.cs
==============================================================================
--- (empty file)
+++ trunk/src/Platform/Gnome/WebProxy.cs Fri Nov 28 13:11:05 2008
@@ -0,0 +1,99 @@
+/*
+ * FSpot.Platform.Gnome.WebProxy.cs
+ *
+ * Author(s):
+ * Anton Keks <anton azib net>
+ * Stephane Delcroix <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+using FSpot.Utils;
+
+namespace FSpot.Platform
+{
+ public class WebProxy {
+
+ const string PROXY = "/system/http_proxy/";
+ const string PROXY_USE_PROXY = PROXY + "use_http_proxy";
+ const string PROXY_HOST = PROXY + "host";
+ const string PROXY_PORT = PROXY + "port";
+ const string PROXY_USER = PROXY + "authentication_user";
+ const string PROXY_PASSWORD = PROXY + "authentication_password";
+ const string PROXY_BYPASS_LIST = PROXY + "ignore_hosts";
+
+ public static void Init ()
+ {
+ LoadPreference (PROXY_USE_PROXY);
+ }
+
+ static void OnPreferenceChanged (object sender, NotifyEventArgs args)
+ {
+ LoadPreference (args.Key);
+ }
+
+ static void LoadPreference (string key)
+ {
+ switch (key) {
+ case PROXY_USE_PROXY :
+ case PROXY_HOST :
+ case PROXY_PORT :
+ case PROXY_USER :
+ case PROXY_PASSWORD :
+ case PROXY_BYPASS_LIST :
+ System.Net.WebRequest.DefaultWebProxy = GetWebProxy () ?? new System.Net.WebProxy ();
+ break;
+ }
+ }
+
+ static System.Net.WebProxy GetWebProxy ()
+ {
+ System.Net.WebProxy proxy;
+
+ if (!Backend.Get<bool> (PROXY_USE_PROXY))
+ return null;
+
+ try {
+ string host = Backend.Get<string> (PROXY_HOST);
+ int port = Backend.Get<int> (PROXY_PORT);
+
+ string uri = "http://" + host + ":" + port.ToString ();
+ proxy = new System.Net.WebProxy (uri);
+
+ string [] bypass_list = Backend.Get<string[]> (PROXY_BYPASS_LIST);
+ if (bypass_list != null) {
+ for (int i = 0; i < bypass_list.Length; i++) {
+ bypass_list [i] = "http://" + bypass_list [i];
+ }
+ proxy.BypassList = bypass_list;
+ }
+
+ string username = Backend.Get<string> (PROXY_USER);
+ string password = Backend.Get<string> (PROXY_PASSWORD);
+
+ proxy.Credentials = new System.Net.NetworkCredential (username, password);
+ } catch (Exception e) {
+ Log.Warning ("Failed to set the web proxy settings");
+ Log.DebugException (e);
+ return null;
+ }
+
+ return proxy;
+ }
+
+ static PreferenceBackend backend;
+ static EventHandler<NotifyEventArgs> changed_handler;
+ static PreferenceBackend Backend {
+ get {
+ if (backend == null) {
+ backend = new PreferenceBackend ();
+ changed_handler = new EventHandler<NotifyEventArgs> (OnPreferenceChanged);
+ backend.AddNotify (PROXY, changed_handler);
+ }
+ return backend;
+ }
+ }
+ }
+}
+
Added: trunk/src/Platform/Null/WebProxy.cs
==============================================================================
--- (empty file)
+++ trunk/src/Platform/Null/WebProxy.cs Fri Nov 28 13:11:05 2008
@@ -0,0 +1,22 @@
+/*
+ * FSpot.Null.Gnome.WebProxy.cs
+ *
+ * Author(s):
+ * Stephane Delcroix <stephane delcroix org>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+using FSpot.Utils;
+
+namespace FSpot.Platform
+{
+ public class WebProxy {
+ public static void Init ()
+ {
+ Log.Information ("No WebProxy in the Null Platform");
+ }
+ }
+}
+
Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs (original)
+++ trunk/src/Preferences.cs Fri Nov 28 13:11:05 2008
@@ -12,76 +12,70 @@
public const string APP_FSPOT_EXPORT = APP_FSPOT + "export/";
public const string APP_FSPOT_EXPORT_TOKENS = APP_FSPOT_EXPORT + "tokens/";
- public const string GTK_RC = "/apps/f-spot/ui/gtkrc";
+ public const string GTK_RC = APP_FSPOT + "ui/gtkrc";
- public const string MAIN_WINDOW_MAXIMIZED = "/apps/f-spot/ui/maximized";
- public const string MAIN_WINDOW_X = "/apps/f-spot/ui/main_window_x";
- public const string MAIN_WINDOW_Y = "/apps/f-spot/ui/main_window_y";
- public const string MAIN_WINDOW_WIDTH = "/apps/f-spot/ui/main_window_width";
- public const string MAIN_WINDOW_HEIGHT = "/apps/f-spot/ui/main_window_height";
-
- public const string IMPORT_WINDOW_WIDTH = "/apps/f-spot/ui/import_window_width";
- public const string IMPORT_WINDOW_HEIGHT = "/apps/f-spot/ui/import_window_height";
- public const string IMPORT_WINDOW_PANE_POSITION = "/apps/f-spot/ui/import_window_pane_position";
-
- public const string VIEWER_WIDTH = "/apps/f-spot/ui/viewer_width";
- public const string VIEWER_HEIGHT = "/apps/f-spot/ui/viewer_height";
- public const string VIEWER_MAXIMIZED = "/apps/f-spot/ui/viewer_maximized";
- public const string VIEWER_SHOW_TOOLBAR = "/apps/f-spot/ui/viewer_show_toolbar";
- public const string VIEWER_SHOW_FILENAMES = "/apps/f-spot/ui/viewer_show_filenames";
- public const string VIEWER_INTERPOLATION = "/apps/f-spot/viewer/interpolation";
- public const string VIEWER_TRANS_COLOR = "/apps/f-spot/viewer/trans_color";
- public const string VIEWER_TRANSPARENCY = "/apps/f-spot/viewer/transparency";
- public const string CUSTOM_CROP_RATIOS = "/apps/f-spot/viewer/custom_crop_ratios";
-
- public const string COLOR_MANAGEMENT_ENABLED = "/apps/f-spot/ui/color_management_enabled";
- public const string COLOR_MANAGEMENT_USE_X_PROFILE = "/apps/f-spot/ui/color_management_use_x_profile";
- public const string COLOR_MANAGEMENT_DISPLAY_PROFILE = "/apps/f-spot/ui/color_management_display_profile";
- public const string COLOR_MANAGEMENT_OUTPUT_PROFILE = "/apps/f-spot/ui/color_management_output_profile";
-
- public const string SHOW_TOOLBAR = "/apps/f-spot/ui/show_toolbar";
- public const string SHOW_SIDEBAR = "/apps/f-spot/ui/show_sidebar";
- public const string SHOW_TIMELINE = "/apps/f-spot/ui/show_timeline";
- public const string SHOW_FILMSTRIP = "/apps/f-spot/ui/show_filmstrip";
- public const string SHOW_TAGS = "/apps/f-spot/ui/show_tags";
- public const string SHOW_DATES = "/apps/f-spot/ui/show_dates";
- public const string EXPANDED_TAGS = "/apps/f-spot/ui/expanded_tags";
- public const string SHOW_RATINGS = "/apps/f-spot/ui/show_ratings";
- public const string TAG_ICON_SIZE = "/apps/f-spot/ui/tag_icon_size";
-
- public const string GLASS_POSITION = "/apps/f-spot/ui/glass_position";
- public const string GROUP_ADAPTOR = "/apps/f-spot/ui/group_adaptor";
- public const string GROUP_ADAPTOR_ORDER_ASC = "/apps/f-spot/ui/group_adaptor_sort_asc";
-
- public const string SIDEBAR_POSITION = "/apps/f-spot/ui/sidebar_size";
- public const string ZOOM = "/apps/f-spot/ui/zoom";
-
- public const string EXPORT_EMAIL_SIZE = "/apps/f-spot/export/email/size";
- public const string EXPORT_EMAIL_ROTATE = "/apps/f-spot/export/email/auto_rotate";
- public const string EXPORT_EMAIL_DELETE_TIMEOUT_SEC = "/apps/f-spot/export/email/delete_timeout_seconds";
-
- public const string IMPORT_GUI_ROLL_HISTORY = "/apps/f-spot/import/gui_roll_history";
+ public const string MAIN_WINDOW_MAXIMIZED = APP_FSPOT + "ui/maximized";
+ public const string MAIN_WINDOW_X = APP_FSPOT + "ui/main_window_x";
+ public const string MAIN_WINDOW_Y = APP_FSPOT + "ui/main_window_y";
+ public const string MAIN_WINDOW_WIDTH = APP_FSPOT + "ui/main_window_width";
+ public const string MAIN_WINDOW_HEIGHT = APP_FSPOT + "ui/main_window_height";
+
+ public const string IMPORT_WINDOW_WIDTH = APP_FSPOT + "ui/import_window_width";
+ public const string IMPORT_WINDOW_HEIGHT = APP_FSPOT + "ui/import_window_height";
+ public const string IMPORT_WINDOW_PANE_POSITION = APP_FSPOT + "ui/import_window_pane_position";
+
+ public const string VIEWER_WIDTH = APP_FSPOT + "ui/viewer_width";
+ public const string VIEWER_HEIGHT = APP_FSPOT + "ui/viewer_height";
+ public const string VIEWER_MAXIMIZED = APP_FSPOT + "ui/viewer_maximized";
+ public const string VIEWER_SHOW_TOOLBAR = APP_FSPOT + "ui/viewer_show_toolbar";
+ public const string VIEWER_SHOW_FILENAMES = APP_FSPOT + "ui/viewer_show_filenames";
+ public const string VIEWER_INTERPOLATION = APP_FSPOT + "viewer/interpolation";
+ public const string VIEWER_TRANS_COLOR = APP_FSPOT + "viewer/trans_color";
+ public const string VIEWER_TRANSPARENCY = APP_FSPOT + "viewer/transparency";
+ public const string CUSTOM_CROP_RATIOS = APP_FSPOT + "viewer/custom_crop_ratios";
+
+ public const string COLOR_MANAGEMENT_ENABLED = APP_FSPOT + "ui/color_management_enabled";
+ public const string COLOR_MANAGEMENT_USE_X_PROFILE = APP_FSPOT + "ui/color_management_use_x_profile";
+ public const string COLOR_MANAGEMENT_DISPLAY_PROFILE = APP_FSPOT + "ui/color_management_display_profile";
+ public const string COLOR_MANAGEMENT_OUTPUT_PROFILE = APP_FSPOT + "ui/color_management_output_profile";
+
+ public const string SHOW_TOOLBAR = APP_FSPOT + "ui/show_toolbar";
+ public const string SHOW_SIDEBAR = APP_FSPOT + "ui/show_sidebar";
+ public const string SHOW_TIMELINE = APP_FSPOT + "ui/show_timeline";
+ public const string SHOW_FILMSTRIP = APP_FSPOT + "ui/show_filmstrip";
+ public const string SHOW_TAGS = APP_FSPOT + "ui/show_tags";
+ public const string SHOW_DATES = APP_FSPOT + "ui/show_dates";
+ public const string EXPANDED_TAGS = APP_FSPOT + "ui/expanded_tags";
+ public const string SHOW_RATINGS = APP_FSPOT + "ui/show_ratings";
+ public const string TAG_ICON_SIZE = APP_FSPOT + "ui/tag_icon_size";
+
+ public const string GLASS_POSITION = APP_FSPOT + "ui/glass_position";
+ public const string GROUP_ADAPTOR = APP_FSPOT + "ui/group_adaptor";
+ public const string GROUP_ADAPTOR_ORDER_ASC = APP_FSPOT + "ui/group_adaptor_sort_asc";
+
+ public const string SIDEBAR_POSITION = APP_FSPOT + "ui/sidebar_size";
+ public const string ZOOM = APP_FSPOT + "ui/zoom";
+
+ public const string EXPORT_EMAIL_SIZE = APP_FSPOT + "export/email/size";
+ public const string EXPORT_EMAIL_ROTATE = APP_FSPOT + "export/email/auto_rotate";
+ public const string EXPORT_EMAIL_DELETE_TIMEOUT_SEC = APP_FSPOT + "export/email/delete_timeout_seconds";
+
+ public const string IMPORT_GUI_ROLL_HISTORY = APP_FSPOT + "import/gui_roll_history";
- public const string SCREENSAVER_TAG = "/apps/f-spot/screensaver/tag_id";
+ public const string SCREENSAVER_TAG = APP_FSPOT + "screensaver/tag_id";
- public const string STORAGE_PATH = "/apps/f-spot/import/storage_path";
+ public const string STORAGE_PATH = APP_FSPOT + "import/storage_path";
- public const string METADATA_EMBED_IN_IMAGE = "/apps/f-spot/metadata/embed_in_image";
+ public const string METADATA_EMBED_IN_IMAGE = APP_FSPOT + "metadata/embed_in_image";
- public const string EDIT_REDEYE_THRESHOLD = "/apps/f-spot/edit/redeye_threshold";
+ public const string EDIT_REDEYE_THRESHOLD = APP_FSPOT + "edit/redeye_threshold";
public const string GNOME_SCREENSAVER_THEME = "/apps/gnome-screensaver/themes";
public const string GNOME_SCREENSAVER_MODE = "/apps/gnome-screensaver/mode";
- public const string GNOME_MAILTO_COMMAND = "/desktop/gnome/url-handlers/mailto/command";
- public const string GNOME_MAILTO_ENABLED = "/desktop/gnome/url-handlers/mailto/enabled";
-
- public const string PROXY_USE_PROXY = "/system/http_proxy/use_http_proxy";
- public const string PROXY_HOST = "/system/http_proxy/host";
- public const string PROXY_PORT = "/system/http_proxy/port";
- public const string PROXY_USER = "/system/http_proxy/authentication_user";
- public const string PROXY_PASSWORD = "/system/http_proxy/authentication_password";
- public const string PROXY_BYPASS_LIST = "/system/http_proxy/ignore_hosts";
+ public const string GNOME_MAILTO = "/desktop/gnome/url-handlers/mailto/";
+ public const string GNOME_MAILTO_COMMAND = GNOME_MAILTO + "command";
+ public const string GNOME_MAILTO_ENABLED = GNOME_MAILTO + "enabled";
public const string GSD_THUMBS_MAX_AGE = "/desktop/gnome/thumbnail_cache/maximum_age";
public const string GSD_THUMBS_MAX_SIZE = "/desktop/gnome/thumbnail_cache/maximum_size";
@@ -94,15 +88,15 @@
if (backend == null) {
backend = new PreferenceBackend ();
changed_handler = new EventHandler<NotifyEventArgs> (OnSettingChanged);
- backend.AddNotify ("/apps/f-spot", changed_handler);
- backend.AddNotify ("/apps/gnome-screensaver/themes", changed_handler);
- backend.AddNotify ("/apps/gnome-screensaver/mode", changed_handler);
- backend.AddNotify ("/desktop/gnome/url-handlers/mailto", changed_handler);
- backend.AddNotify ("/system/http_proxy", changed_handler);
+ backend.AddNotify (APP_FSPOT, changed_handler);
+ backend.AddNotify (GNOME_SCREENSAVER_THEME, changed_handler);
+ backend.AddNotify (GNOME_SCREENSAVER_MODE, changed_handler);
+ backend.AddNotify (GNOME_MAILTO, changed_handler);
}
return backend;
}
}
+
private static Dictionary<string, object> cache = new Dictionary<string, object>();
static object GetDefault (string key)
@@ -165,12 +159,6 @@
case EDIT_REDEYE_THRESHOLD:
return -15;
- case PROXY_USE_PROXY:
- return false;
- case PROXY_PORT:
- return 0;
- case PROXY_USER:
- case PROXY_PASSWORD:
case GTK_RC:
return String.Empty;
default:
@@ -254,45 +242,9 @@
}
}
- if (SettingChanged != null) {
+ if (SettingChanged != null)
SettingChanged (sender, args);
- }
}
- public static WebProxy GetProxy ()
- {
- WebProxy proxy = null;
-
- if (Preferences.Get<bool> (PROXY_USE_PROXY))
- return null;
-
- try {
- string host;
- int port;
-
- host = Preferences.Get<string> (PROXY_HOST);
- port = Preferences.Get<int> (PROXY_PORT);
-
- string uri = "http://" + host + ":" + port.ToString ();
- proxy = new WebProxy (uri);
-
- string [] bypass_list = Preferences.Get<string[]> (PROXY_BYPASS_LIST);
- if (bypass_list != null) {
- for (int i = 0; i < bypass_list.Length; i++) {
- bypass_list [i] = "http://" + bypass_list [i];
- }
- proxy.BypassList = bypass_list;
- }
-
- string username = Preferences.Get<string> (PROXY_USER);
- string password = Preferences.Get<string> (PROXY_PASSWORD);
-
- proxy.Credentials = new NetworkCredential (username, password);
- } catch (Exception) {
- proxy = null;
- }
-
- return proxy;
- }
}
}
Modified: trunk/src/main.cs
==============================================================================
--- trunk/src/main.cs (original)
+++ trunk/src/main.cs Fri Nov 28 13:11:05 2008
@@ -295,6 +295,9 @@
if (!is_main)
return 0;
+ // init web proxy globally
+ Platform.WebProxy.Init ();
+
#if GSD_2_24
Log.Information ("Hack for gnome-settings-daemon engaged");
int max_age, max_size;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]