[banshee/gtk3] Configuration: remove static helper methods from ConfigurationClient
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/gtk3] Configuration: remove static helper methods from ConfigurationClient
- Date: Tue, 12 Mar 2013 01:47:57 +0000 (UTC)
commit 22e84027cde9aeb6105ac1e9eacc03432f63d9d4
Author: Andres G. Aragoneses <knocte gmail com>
Date: Tue Mar 12 01:47:18 2013 +0000
Configuration: remove static helper methods from ConfigurationClient
If someone needs to do some refactoring around IConfigurationClient it is
very painful because there are a lot of duplicated methods: the static ones
in class ConfigurationClient and the extension methods in the file
IConfigurationClient.cs. So, with this commit we remove the static methods
to unify the API a bit. Instead, we now use the ConfigurationClient
singleton instance everywhere.
To avoid the redundancy of calling this "ConfigurationClient.Client", we
now rename the singleton to be named "Instance", as it is done in other
parts of the code with other singleton instances.
No change of behaviour in this commit.
.../Banshee.Configuration/ConfigurationClient.cs | 63 ++++----------------
.../Banshee.Configuration/SchemaEntry.cs | 6 +-
.../Banshee.MediaProfiles/ProfileConfiguration.cs | 12 ++--
.../Banshee.Services/Banshee.Sources/Source.cs | 4 +-
.../PersistentColumnController.cs | 10 ++--
.../Banshee.Gui/PersistentPaneController.cs | 4 +-
.../Banshee.Gui/SourceActions.cs | 4 +-
7 files changed, 31 insertions(+), 72 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs
b/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs
index 7534c04..52c9719 100644
--- a/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs
+++ b/src/Core/Banshee.Core/Banshee.Configuration/ConfigurationClient.cs
@@ -36,12 +36,12 @@ namespace Banshee.Configuration
{
public static class ConfigurationClient
{
- private static IConfigurationClient client;
+ private static IConfigurationClient instance;
private static void Initialize ()
{
lock (typeof (ConfigurationClient)) {
- if (client != null) {
+ if (instance != null) {
return;
}
@@ -49,8 +49,8 @@ namespace Banshee.Configuration
foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (
"/Banshee/Platform/ConfigurationClient")) {
try {
- client = (IConfigurationClient)node.CreateInstance (typeof
(IConfigurationClient));
- if (client != null) {
+ instance = (IConfigurationClient)node.CreateInstance (typeof
(IConfigurationClient));
+ if (instance != null) {
break;
}
} catch (Exception e) {
@@ -58,65 +58,24 @@ namespace Banshee.Configuration
}
}
- if (client == null) {
- client = new XmlConfigurationClient ();
+ if (instance == null) {
+ instance = new XmlConfigurationClient ();
}
} else {
- client = new MemoryConfigurationClient ();
+ instance = new MemoryConfigurationClient ();
}
- Log.DebugFormat ("Configuration client extension loaded ({0})", client.GetType ().FullName);
+ Log.DebugFormat ("Configuration client extension loaded ({0})", instance.GetType
().FullName);
}
}
- public static IConfigurationClient Client {
+ public static IConfigurationClient Instance {
get {
- if (client == null) {
+ if (instance == null) {
Initialize ();
}
- return client;
+ return instance;
}
}
-
- public static T Get<T>(SchemaEntry<T> entry)
- {
- return Get<T>(entry.Namespace, entry.Key, entry.DefaultValue);
- }
-
- public static T Get<T>(SchemaEntry<T> entry, T fallback)
- {
- return Get<T>(entry.Namespace, entry.Key, fallback);
- }
-
- public static T Get<T>(string key, T fallback)
- {
- return Get<T>(null, key, fallback);
- }
-
- public static T Get<T>(string namespce, string key, T fallback)
- {
- T result;
- return TryGet<T> (namespce, key, out result) ? result : fallback;
- }
-
- public static bool TryGet<T> (string @namespace, string key, out T result)
- {
- return Client.TryGet<T> (@namespace, key, out result);
- }
-
- public static void Set<T> (SchemaEntry<T> entry, T value)
- {
- Set (entry.Namespace, entry.Key, value);
- }
-
- public static void Set<T> (string key, T value)
- {
- Set (null, key, value);
- }
-
- public static void Set<T> (string @namespace, string key, T value)
- {
- Client.Set<T> (@namespace, key, value);
- }
}
}
diff --git a/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
b/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
index c981516..52334a2 100644
--- a/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
+++ b/src/Core/Banshee.Core/Banshee.Configuration/SchemaEntry.cs
@@ -69,12 +69,12 @@ namespace Banshee.Configuration
public T Get ()
{
- return ConfigurationClient.Get<T> (this);
+ return ConfigurationClient.Instance.Get<T> (this);
}
public T Get (T fallback)
{
- return ConfigurationClient.Get<T> (this, fallback);
+ return ConfigurationClient.Instance.Get<T> (this, fallback);
}
public bool Set (T value)
@@ -86,7 +86,7 @@ namespace Banshee.Configuration
}
}
- ConfigurationClient.Set<T> (this, value);
+ ConfigurationClient.Instance.Set<T> (this, value);
return true;
}
diff --git a/src/Core/Banshee.Services/Banshee.MediaProfiles/ProfileConfiguration.cs
b/src/Core/Banshee.Services/Banshee.MediaProfiles/ProfileConfiguration.cs
index 58471e1..615ccbe 100644
--- a/src/Core/Banshee.Services/Banshee.MediaProfiles/ProfileConfiguration.cs
+++ b/src/Core/Banshee.Services/Banshee.MediaProfiles/ProfileConfiguration.cs
@@ -51,7 +51,7 @@ namespace Banshee.MediaProfiles
public static ProfileConfiguration LoadActive (MediaProfileManager manager, string id)
{
- string profile_id = ConfigurationClient.Get<string>(MakeConfNamespace(id), "active_profile",
string.Empty);
+ string profile_id = ConfigurationClient.Instance.Get<string> (MakeConfNamespace (id),
"active_profile", string.Empty);
if(profile_id == string.Empty) {
return null;
@@ -69,7 +69,7 @@ namespace Banshee.MediaProfiles
public static void SaveActiveProfile(Profile profile, string id)
{
- ConfigurationClient.Set<string>(MakeConfNamespace(id), "active_profile", profile.Id);
+ ConfigurationClient.Instance.Set<string> (MakeConfNamespace (id), "active_profile", profile.Id);
}
public ProfileConfiguration(Profile profile, string id)
@@ -80,8 +80,8 @@ namespace Banshee.MediaProfiles
protected virtual void Load()
{
- foreach(string variable in ConfigurationClient.Get<string[]>(ConfNamespace, "variables", new
string[0])) {
- Add(variable, ConfigurationClient.Get<string>(ConfNamespace, variable, string.Empty));
+ foreach (string variable in ConfigurationClient.Instance.Get<string[]> (ConfNamespace,
"variables", new string [0])) {
+ Add(variable, ConfigurationClient.Instance.Get<string> (ConfNamespace, variable,
string.Empty));
}
}
@@ -90,9 +90,9 @@ namespace Banshee.MediaProfiles
List<string> variable_names = new List<string>(Count);
foreach(KeyValuePair<string, string> variable in this) {
variable_names.Add(variable.Key);
- ConfigurationClient.Set<string>(ConfNamespace, variable.Key, variable.Value);
+ ConfigurationClient.Instance.Set<string> (ConfNamespace, variable.Key, variable.Value);
}
- ConfigurationClient.Set<string[]>(ConfNamespace, "variables", variable_names.ToArray());
+ ConfigurationClient.Instance.Set<string[]> (ConfNamespace, "variables", variable_names.ToArray
());
}
public void Add(string variable, string value)
diff --git a/src/Core/Banshee.Services/Banshee.Sources/Source.cs
b/src/Core/Banshee.Services/Banshee.Sources/Source.cs
index a1b065a..198e148 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/Source.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/Source.cs
@@ -713,8 +713,8 @@ namespace Banshee.Sources
}
public virtual int CurrentStatusFormat {
- get { return ConfigurationClient.Get<int> (String.Format ("sources.{0}", ParentConfigurationId),
"status_format", 0); }
- set { ConfigurationClient.Set<int> (String.Format ("sources.{0}", ParentConfigurationId),
"status_format", value); }
+ get { return ConfigurationClient.Instance.Get<int> (String.Format ("sources.{0}",
ParentConfigurationId), "status_format", 0); }
+ set { ConfigurationClient.Instance.Set<int> (String.Format ("sources.{0}",
ParentConfigurationId), "status_format", value); }
}
public SchemaEntry<T> CreateSchema<T> (string name)
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/PersistentColumnController.cs
b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/PersistentColumnController.cs
index 497d466..5c887f9 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/PersistentColumnController.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/PersistentColumnController.cs
@@ -181,26 +181,26 @@ namespace Banshee.Collection.Gui
T result;
if (source_ns != parent_source_ns) {
- if (!ConfigurationClient.TryGet<T> (conf_ns, key, out result) &&
- val != null && val.Equals (ConfigurationClient.Get<T> (parent_source_ns + ns, key,
default(T)))) {
+ if (!ConfigurationClient.Instance.TryGet<T> (conf_ns, key, out result) && val != null &&
+ val.Equals (ConfigurationClient.Instance.Get<T> (parent_source_ns + ns, key, default
(T)))) {
conf_ns = null;
}
}
if (conf_ns != null) {
- ConfigurationClient.Set<T> (conf_ns, key, val);
+ ConfigurationClient.Instance.Set<T> (conf_ns, key, val);
}
}
private T Get<T> (string ns, string key, T fallback)
{
T result;
- if (ConfigurationClient.TryGet<T> (source_ns + ns, key, out result)) {
+ if (ConfigurationClient.Instance.TryGet<T> (source_ns + ns, key, out result)) {
return result;
}
if (source_ns != parent_source_ns) {
- return ConfigurationClient.Get<T> (parent_source_ns + ns, key, fallback);
+ return ConfigurationClient.Instance.Get<T> (parent_source_ns + ns, key, fallback);
}
return fallback;
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentPaneController.cs
b/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentPaneController.cs
index 51e5bfa..ac712ad 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentPaneController.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/PersistentPaneController.cs
@@ -86,7 +86,7 @@ namespace Banshee.Gui
}
pane = value;
- pane.Position = ConfigurationClient.Get<int> (@namespace, key, fallback);
+ pane.Position = ConfigurationClient.Instance.Get<int> (@namespace, key, fallback);
//pane.MoveHandle += OnPaneMoved;
//pane.AcceptPosition += delegate { Console.WriteLine ("accept pos called, pos = {0}",
pane.Position); };
pane.SizeAllocated += OnPaneMoved;
@@ -114,7 +114,7 @@ namespace Banshee.Gui
return true;
} else {
if (pane.Position != last_position) {
- ConfigurationClient.Set<int> (@namespace, key, pane.Position);
+ ConfigurationClient.Instance.Set<int> (@namespace, key, pane.Position);
last_position = pane.Position;
}
timer_id = 0;
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
index 8752670..1bd6d4a 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/SourceActions.cs
@@ -420,7 +420,7 @@ namespace Banshee.Gui
private static bool ConfirmUnmap (IUnmapableSource source)
{
string key = "no_confirm_unmap_" + source.GetType ().Name.ToLower ();
- bool do_not_ask = ConfigurationClient.Get<bool> ("sources", key, false);
+ bool do_not_ask = ConfigurationClient.Instance.Get<bool> ("sources", key, false);
if (do_not_ask) {
return true;
@@ -450,7 +450,7 @@ namespace Banshee.Gui
try {
if (dialog.Run () == (int)Gtk.ResponseType.Ok) {
- ConfigurationClient.Set<bool> ("sources", key, do_not_ask);
+ ConfigurationClient.Instance.Set<bool> ("sources", key, do_not_ask);
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]