[blam/gtk3: 2/3] Bring back config
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam/gtk3: 2/3] Bring back config
- Date: Sun, 13 Oct 2013 02:05:52 +0000 (UTC)
commit ef93b7acb024f71f6f1bdba180653ec5276ddaa5
Author: Carlos Martín Nieto <cmn dwim me>
Date: Sun Oct 13 03:17:29 2013 +0200
Bring back config
blam.csproj | 1 -
org.gnome.blam.gschema.xml | 85 +++++++++++++++++++++++++++++++++++++
src/Blam.cs | 16 +++----
src/Conf.cs | 44 +++----------------
src/Dialogs.cs | 44 +++++++------------
src/GLibSynchronizationContext.cs | 71 -------------------------------
src/Spinnable.cs | 8 ++--
src/ThemeManager.cs | 3 +-
src/Togglable.cs | 6 +-
9 files changed, 122 insertions(+), 156 deletions(-)
---
diff --git a/blam.csproj b/blam.csproj
index bf68195..5f51159 100644
--- a/blam.csproj
+++ b/blam.csproj
@@ -98,7 +98,6 @@
<Compile Include="src\Channel.cs" />
<Compile Include="src\Blam.cs" />
<Compile Include="src\BuilderExtensions.cs" />
- <Compile Include="src\GLibSynchronizationContext.cs" />
<Compile Include="src\TreeSelectionExtensions.cs" />
<Compile Include="src\TreeViewExtensions.cs" />
<Compile Include="src\EntryExtensions.cs" />
diff --git a/org.gnome.blam.gschema.xml b/org.gnome.blam.gschema.xml
new file mode 100644
index 0000000..bd72379
--- /dev/null
+++ b/org.gnome.blam.gschema.xml
@@ -0,0 +1,85 @@
+<schemalist>
+ <schema id="org.gnome.blam" path="/apps/blam/">
+ <child name="ui" schema="org.gnome.blam.ui"/>
+ <child name="preferences" schema="org.gnome.blam.preferences"/>
+ </schema>
+ <schema id="org.gnome.blam.ui" path="/apps/blam/ui/">
+ <key name="main-window-state" type="s">
+ <default>'normal'</default>
+ <summary>State of the main window</summary>
+ <description>The state of the main window, valid values are 'normal' and 'maximized'.</description>
+ </key>
+ <key name="main-window-width" type="i">
+ <default>600</default>
+ <summary>Width of the main window</summary>
+ <description>The width of the main window.</description>
+ </key>
+ <key name="main-window-height" type="i">
+ <default>400</default>
+ <summary>Height of main window</summary>
+ <description>The height of the main window.</description>
+ </key>
+ <key name="main-window-position-x" type="i">
+ <default>-1</default>
+ <summary>X position of main window</summary>
+ <description>The stored position of the main window, the X coordinate.</description>
+ </key>
+ <key name="main-window-position-y" type="i">
+ <default>-1</default>
+ <summary>Y position of main window</summary>
+ <description>The stored position of the main window, the Y coordinate.</description>
+ </key>
+ <key name="channel-list-width" type="i">
+ <default>180</default>
+ <summary>Width of channel list</summary>
+ <description>The width of the channel list.</description>
+ </key>
+ <key name="item-list-height" type="i">
+ <default>100</default>
+ <summary>Height of entry list</summary>
+ <description>The height of the entry list.</description>
+ </key>
+ </schema>
+ <schema id="org.gnome.blam.preferences" path="/apps/blam/preferences/">
+ <key name="reverse-entries" type="b">
+ <default>false</default>
+ <summary>Reverse the entries in the entry list</summary>
+ <description>Show the newest entries at the top of the entry list.</description>
+ </key>
+ <key name="auto-refresh" type="b">
+ <default>false</default>
+ <summary>Automatically refresh channels</summary>
+ <description>Automatically refresh all channels at a regular interval.</description>
+ </key>
+ <key name="auto-refresh-rate" type="i">
+ <default>15</default>
+ <summary>Automatically refresh channels interval</summary>
+ <description>The refresh rate for when to refresh all channels.</description>
+ </key>
+ <key name="ignore-cert-errors" type="b">
+ <default>false</default>
+ <summary>Ignore SSL certificate errors</summary>
+ <description>Ignore the certificate errors and continue connecting to the host</description>
+ </key>
+ <key name="theme" type="s">
+ <default>'planet'</default>
+ <summary>Current theme</summary>
+ <description>The theme used to render the entries.</description>
+ </key>
+ <key name="refresh-on-startup" type="b">
+ <default>false</default>
+ <summary>Refresh channels on startup</summary>
+ <description>Refresh all channels when the application starts.</description>
+ </key>
+ <key name="mark-read-delay" type="b">
+ <default>false</default>
+ <summary>Delay marking items as read</summary>
+ <description>Wait the specified number of seconds before marking an entry as read</description>
+ </key>
+ <key name="mark-read-delay-time" type="i">
+ <default>3</default>
+ <summary>Time to delay marking items as read</summary>
+ <description>The number of seconds to wait before marking an entry as read (if enabled)</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/src/Blam.cs b/src/Blam.cs
index 278b1d9..0055eb3 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -35,7 +35,6 @@ namespace Blam
public BlamApplication()
{
ItemStore.Load();
- SynchronizationContext.SetSynchronizationContext(new
GLib.GLibSynchronizationContext());
var bld = new Builder();
bld.AddFromResource("blam.ui");
@@ -176,27 +175,26 @@ namespace Blam
{
int width, height;
int position_x, position_y;
- string state;
- width = Conf.Get("ui/main_window_width", 600);
- height = Conf.Get("ui/main_window_height", 400);
+ width = Conf.UI.GetInt("main-window-width");
+ height = Conf.UI.GetInt("main-window-height");
MainWindow.Resize(width, height);
- position_x = Conf.Get("ui/main_window_position_x", -1);
- position_y = Conf.Get("ui/main_window_position_y", -1);
+ position_x = Conf.UI.GetInt("main-window-position-x");
+ position_y = Conf.UI.GetInt("main-window-position-y");
if (position_x >= 0 && position_y >= 0) {
MainWindow.Move(position_x, position_y);
}
- width = Conf.Get("ui/channel_list_width", 180);
+ width = Conf.UI.GetInt("channel-list-width");
mainPaned.Position = width;
- height = Conf.Get("ui/item_list_height", 100);
+ height = Conf.UI.GetInt("item-list-height");
itemPaned.Position = height;
- if (Conf.Get("ui/main_window_state", "normal") == "maximized")
+ if (Conf.UI.GetString("main-window-state") == "maximized")
MainWindow.Maximize();
}
diff --git a/src/Conf.cs b/src/Conf.cs
index cb6f69a..ce7104c 100644
--- a/src/Conf.cs
+++ b/src/Conf.cs
@@ -1,53 +1,21 @@
//
-// Author:
-// Mikael Hallendal <micke imendio com>
+// (c) 2013 Carlos Martín Nieto <cmn dwim me>
//
-// (C) 2004 Imendio HB
-//
-//using GConf;
+using GLib;
using System;
namespace Blam
{
public static class Conf
{
- static string confBase = "/apps/blam";
- //static GConf.Client client;
+ public static Settings Preferences { get; private set; }
+ public static Settings UI { get; private set; }
static Conf()
{
- //client = new GConf.Client();
+ Preferences = new Settings("org.gnome.blam.preferences");
+ UI = new Settings("org.gnome.blam.ui");
}
-
- public static string FullKey(string key)
- {
- if (key.StartsWith("/")) {
- return key;
- }
-
- return confBase + "/" + key;
- }
-
- public static T Get<T>(string key, T def)
- {
- return def;
- }
-#if false
- T res;
- try {
- res = (T) client.Get(FullKey(key));
- } catch {
- res = def;
- }
-
- return res;
- }
-
- public static void Set(string key, object value)
- {
- client.Set(FullKey(key), value);
- }
- #endif
}
}
diff --git a/src/Dialogs.cs b/src/Dialogs.cs
index b90a402..62e3f72 100644
--- a/src/Dialogs.cs
+++ b/src/Dialogs.cs
@@ -242,22 +242,6 @@ namespace Blam
class PreferencesDialog : Modal
{
- public class Preference {
- public static string REVERSE_ENTRIES = "behaviour/reverse_entries";
- public static string REFRESH_AT_START = "behaviour/refresh_at_start";
- public static string AUTO_REFRESH = "behaviour/auto_refresh";
- public static string AUTO_REFRESH_RATE = "behaviour/auto_refresh_rate";
- public static string IGNORE_SSL_ERR = "behaviour/ignore_ssl_err";
- public static string BEHAVIOUR_PATH = Conf.FullKey("behaviour");
- public static string FONT_PATH = "/desktop/gnome/interface";
- public static string VARIABLE_FONT = "/desktop/gnome/interface/font_name";
- public static string FIXED_FONT =
"/desktop/gnome/interface/monospace_font_name";
- public static string THEME = "ui/theme";
- public static string SHOW_ITEM_LIST = "ui/show_item_list";
- public static string MARK_ITEMS_READ_TIMEOUT = "behaviour/set_item_read_timeout";
- public static string MARK_ITEMS_READ = "behaviour/set_item_read";
- }
-
Togglable reverseEntries;
Togglable autoRefresh;
Spinnable autoRefreshInterval;
@@ -270,31 +254,35 @@ namespace Blam
public PreferencesDialog(Gtk.Window parent)
: base(parent, "preferences")
{
- reverseEntries = new Togglable(bld, "reverse-entries", Preference.REVERSE_ENTRIES);
- autoRefresh = new Togglable(bld, "auto-refresh", Preference.AUTO_REFRESH);
- autoRefreshInterval = new Spinnable(bld, "auto-refresh-interval",
Preference.AUTO_REFRESH_RATE, 15, 1);
- ignoreCertErrors = new Togglable(bld, "ignore-cert-errors",
Preference.IGNORE_SSL_ERR);
- refreshOnStartup = new Togglable(bld, "refresh-on-startup",
Preference.REFRESH_AT_START);
- markReadDelay = new Togglable(bld, "mark-read-delay", Preference.MARK_ITEMS_READ);
- markReadDelayTime = new Spinnable(bld,"mark-read-delay-time",
Preference.MARK_ITEMS_READ_TIMEOUT, 3000, 1000);
+ reverseEntries = new Togglable(bld, "reverse-entries", "reverse-entries");
+ autoRefresh = new Togglable(bld, "auto-refresh", "auto-refresh");
+ autoRefreshInterval = new Spinnable(bld, "auto-refresh-interval",
"auto-refresh-rate");
+ ignoreCertErrors = new Togglable(bld, "ignore-cert-errors", "ignore-cert-errors");
+ refreshOnStartup = new Togglable(bld, "refresh-on-startup", "refresh-on-startup");
+ markReadDelay = new Togglable(bld, "mark-read-delay", "mark-read-delay");
+ markReadDelayTime = new Spinnable(bld,"mark-read-delay-time", "mark-read-delay-time");
}
public new void Run()
{
- var changes = Observable.Merge(
+ var toggles = Observable.Merge(
reverseEntries.Toggle,
autoRefresh.Toggle,
- autoRefreshInterval.Change,
ignoreCertErrors.Toggle,
refreshOnStartup.Toggle,
- markReadDelay.Toggle,
+ markReadDelay.Toggle);
+
+ var nums = Observable.Merge(
+ autoRefreshInterval.Change,
markReadDelayTime.Change);
- //var sub = changes.Subscribe(kv => Conf.Set(kv.Key, kv.Value));
+ var toggleSub = toggles.Subscribe(kv => Conf.Preferences.SetBoolean(kv.Key,
kv.Value));
+ var numSub = nums.Subscribe(kv => Conf.Preferences.SetInt(kv.Key, kv.Value));
base.Run();
- //sub.Dispose();
+ toggleSub.Dispose();
+ numSub.Dispose();
}
}
diff --git a/src/Spinnable.cs b/src/Spinnable.cs
index 4a16b48..854207a 100644
--- a/src/Spinnable.cs
+++ b/src/Spinnable.cs
@@ -9,16 +9,16 @@ namespace Blam
{
SpinButton button;
- public IObservable<KeyValuePair<string, object>> Change { get; private set; }
+ public IObservable<KeyValuePair<string, int>> Change { get; private set; }
- public Spinnable(Builder bld, string name, string option, int def, int div)
+ public Spinnable(Builder bld, string name, string option)
{
button = bld.GetObject<SpinButton>(name);
- button.Value = Conf.Get(option, def) / div;
+ button.Value = Conf.Preferences.GetInt(option);
Change = Observable.FromEventPattern(button, "Changed")
.Select(x => ((SpinButton)x.Sender).ValueAsInt)
- .Select(v => new KeyValuePair<string, object>(option, v * div));
+ .Select(v => new KeyValuePair<string, int>(option, v));
}
}
}
diff --git a/src/ThemeManager.cs b/src/ThemeManager.cs
index bf61dc3..f307d70 100644
--- a/src/ThemeManager.cs
+++ b/src/ThemeManager.cs
@@ -18,7 +18,6 @@ namespace Blam
{
using Theme = Imendio.Blam.Theme;
using Defines = Imendio.Blam.Defines;
- using Preference = PreferencesDialog.Preference;
public class ThemeManager : INotifyPropertyChanged
{
@@ -44,7 +43,7 @@ namespace Blam
loadThemes(Defines.PERSONAL_THEME_DIR);
loadThemes(Defines.THEME_DIR);
- var themePath = Conf.Get(Preference.THEME, Defines.DEFAULT_THEME);
+ var themePath = Conf.Preferences.GetString("theme");
var theme = themes.Find(t => t.Path.Equals(themePath));
// if the user's theme isn't found, take the first of the list and fallback
// to an empty theme if the list is empty
diff --git a/src/Togglable.cs b/src/Togglable.cs
index ff97471..5fd85dd 100644
--- a/src/Togglable.cs
+++ b/src/Togglable.cs
@@ -9,16 +9,16 @@ namespace Blam
{
ToggleButton button;
- public IObservable<KeyValuePair<string, object>> Toggle { get; private set; }
+ public IObservable<KeyValuePair<string, bool>> Toggle { get; private set; }
public Togglable(Builder bld, string name, string option)
{
button = bld.GetObject<ToggleButton>(name);
- button.Active = Conf.Get(option, false);
+ button.Active = Conf.Preferences.GetBoolean(option);
Toggle = Observable.FromEventPattern(button, "Toggled")
.Select(x => ((ToggleButton)x.Sender).Active)
- .Select(v => new KeyValuePair<string, object>(option, v));
+ .Select(v => new KeyValuePair<string, bool>(option, v));
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]