Do

Merge lp:~psybers/do/gconf-notify into lp:do

Proposed by Robert Dyer
Status: Superseded
Proposed branch: lp:~psybers/do/gconf-notify
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~psybers/do/gconf-notify
Reviewer Review Type Date Requested Status
Do Core Team Pending
Review via email: mp+10833@code.launchpad.net

This proposal has been superseded by a proposal from 2009-08-28.

To post a comment you must log in.
Revision history for this message
Robert Dyer (psybers) wrote :

This lets the preferences objects be notified by GConf when things change.

A lot of places we cache the .get() from preferences in a field and then the property's get{} returns that. This is done for performance (in places) and makes perfect sense. However, we can now do that *and* be notified by GConf when a setting changed and thus update our cached copy! Horray!

lp:~psybers/do/gconf-notify updated
1300. By Robert Dyer <rdyer@yamuna>

removing unneeded null check

1301. By Robert Dyer <rdyer@yamuna>

Updating BezelDrawingArea to use the new preferences event.

1302. By Robert Dyer <rdyer@yamuna>

making the docklet service use the new prefs event

1303. By Robert Dyer <rdyer@yamuna>

removing debug statements

1304. By Robert Dyer <rdyer@yamuna>

Fixing problem with the theme resetting to itself sometimes.

1305. By Robert Dyer <rdyer@yamuna>

adding some docs

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs'
2--- Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-08-20 08:27:24 +0000
3+++ Do.Interface.Linux.Docky/src/Docky.Interface/Docky.Interface.Items/ClockDockItem.cs 2009-08-28 05:42:11 +0000
4@@ -107,6 +107,20 @@
5 cal_painter = new CalendarPainter (this);
6 Core.DockServices.PainterService.RegisterPainter (cal_painter);
7 GLib.Timeout.Add (1000, ClockUpdateTimer);
8+ prefs.PreferencesChanged += HandlePreferencesChanged;
9+ }
10+
11+ void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e)
12+ {
13+ if (e.Key == "ClockTheme")
14+ current_theme = (string)e.OldValue;
15+ if (e.Key == "ShowDate")
16+ show_date = (bool)e.OldValue;
17+ if (e.Key == "ShowDigital")
18+ digital = (bool)e.OldValue;
19+ if (e.Key == "ShowMilitary")
20+ show_military = (bool)e.OldValue;
21+ RedrawIcon();
22 }
23
24 bool ClockUpdateTimer ()
25
26=== modified file 'Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs'
27--- Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs 2009-06-19 04:32:13 +0000
28+++ Do.Interface.Linux.Docky/src/Docky.Utilities/DockPreferences.cs 2009-08-28 06:46:50 +0000
29@@ -56,6 +56,28 @@
30 return true;
31 });
32 }
33+ prefs.PreferencesChanged += HandlePreferencesChanged;
34+ }
35+
36+ static void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e) {
37+ if (e.Key == "IndicateMultipleWindows")
38+ SetIndicateMultipleWindows ((bool)e.Value);
39+ if (e.Key == "ZoomPercent")
40+ SetZoomPercent ((double)e.Value);
41+ if (e.Key == "EnableZoom")
42+ SetZoomEnabled ((bool)e.Value);
43+ if (e.Key == "IconSize")
44+ SetIconSize ((int)e.Value);
45+ if (e.Key == "SummonTime")
46+ SetSummonTime (new TimeSpan (0, 0, 0, 0, (int)e.Value));
47+ if (e.Key == "AutomaticIcons")
48+ SetAutomaticIcons ((int)e.Value);
49+ if (e.Key == "Monitor")
50+ SetMonitor (Math.Max (0, (int)e.Value));
51+ if (e.Key == "Orientation")
52+ SetOrientation ((DockOrientation) Enum.Parse (typeof (DockOrientation), (string)e.Value));
53+ if (e.Key == "AutohideType")
54+ SetAutohideType ((AutohideType) Enum.Parse (typeof (AutohideType), (string)e.Value));
55 }
56
57 public static int TextWidth {
58@@ -70,34 +92,52 @@
59 public static bool IndicateMultipleWindows {
60 get { return indicate_multiple_windows; }
61 set {
62- prefs.Set ("IndicateMultipleWindows", value);
63- indicate_multiple_windows = value;
64+ if (SetIndicateMultipleWindows (value))
65+ prefs.Set ("IndicateMultipleWindows", value);
66 }
67 }
68+ static bool SetIndicateMultipleWindows (bool val)
69+ {
70+ if (indicate_multiple_windows == val) return false;
71+ indicate_multiple_windows = val;
72+ return true;
73+ }
74
75 static double zoom_percent = Math.Round (prefs.Get ("ZoomPercent", 2.0), 1);
76 public static double ZoomPercent {
77 get { return ZoomEnabled ? zoom_percent : 1; }
78 set {
79- if (value < 1)
80- value = 1;
81- prefs.Set ("ZoomPercent", value);
82- zoom_percent = value;
83- if (IconSizeChanged != null)
84- IconSizeChanged ();
85+ if (SetZoomPercent (value))
86+ prefs.Set ("ZoomPercent", value);
87 }
88 }
89+ static bool SetZoomPercent (double val)
90+ {
91+ if (val < 1)
92+ val = 1;
93+ if (zoom_percent == val) return false;
94+ zoom_percent = val;
95+ if (IconSizeChanged != null)
96+ IconSizeChanged ();
97+ return true;
98+ }
99
100 static bool enable_zoom = prefs.Get ("EnableZoom", true);
101 public static bool ZoomEnabled {
102 get { return enable_zoom; }
103 set {
104- prefs.Set ("EnableZoom", value);
105- enable_zoom = value;
106- if (IconSizeChanged != null)
107- IconSizeChanged ();
108+ if (SetZoomEnabled (value))
109+ prefs.Set ("EnableZoom", value);
110 }
111 }
112+ static bool SetZoomEnabled (bool val)
113+ {
114+ if (enable_zoom == val) return false;
115+ enable_zoom = val;
116+ if (IconSizeChanged != null)
117+ IconSizeChanged ();
118+ return true;
119+ }
120
121 public static int FullIconSize {
122 get {
123@@ -120,20 +160,25 @@
124 public static int IconSize {
125 get { return Math.Min (icon_size, MaxIconSize); }
126 set {
127- if (value < 24)
128- value = 24;
129- if (value > 128)
130- value = 128;
131-
132- if (value == icon_size)
133- return;
134-
135- prefs.Set ("IconSize", value);
136- icon_size = value;
137- if (IconSizeChanged != null)
138- IconSizeChanged ();
139+ if (SetIconSize (value))
140+ prefs.Set ("IconSize", value);
141 }
142 }
143+ static bool SetIconSize (int val)
144+ {
145+ if (val < 24)
146+ val = 24;
147+ if (val > 128)
148+ val = 128;
149+
150+ if (val == icon_size)
151+ return false;
152+
153+ icon_size = val;
154+ if (IconSizeChanged != null)
155+ IconSizeChanged ();
156+ return true;
157+ }
158
159 /// <summary>
160 /// Currently returns ZoomPercent. This is useful in the future case where we wish to optimize for best
161@@ -151,24 +196,36 @@
162 public static TimeSpan SummonTime {
163 get { return summon_time; }
164 set {
165- prefs.Set ("SummonTime", value.TotalMilliseconds);
166- summon_time = value;
167+ if (SetSummonTime (value))
168+ prefs.Set ("SummonTime", value.TotalMilliseconds);
169 }
170 }
171+ static bool SetSummonTime (TimeSpan val)
172+ {
173+ if (summon_time == val) return false;
174+ summon_time = val;
175+ return true;
176+ }
177
178 static int automatic_icons = prefs.Get ("AutomaticIcons", 5);
179 public static int AutomaticIcons {
180 get { return automatic_icons; }
181 set {
182- if (value < 0)
183- value = 0;
184- prefs.Set ("AutomaticIcons", value);
185- automatic_icons = value;
186-
187- if (AutomaticIconsChanged != null)
188- AutomaticIconsChanged ();
189+ if (SetAutomaticIcons (value))
190+ prefs.Set ("AutomaticIcons", value);
191 }
192 }
193+ static bool SetAutomaticIcons (int val)
194+ {
195+ if (val < 0)
196+ val = 0;
197+ if (automatic_icons == val) return false;
198+ automatic_icons = val;
199+
200+ if (AutomaticIconsChanged != null)
201+ AutomaticIconsChanged ();
202+ return true;
203+ }
204
205 static int monitor = Math.Max (0, prefs.Get ("Monitor", 0));
206 public static int Monitor {
207@@ -177,19 +234,25 @@
208 return monitor;
209 }
210 set {
211- if (monitor == value)
212- return;
213-
214- if (value >= Gdk.Screen.Default.NMonitors || value < 0)
215- value = 0;
216- monitor = value;
217- prefs.Set ("Monitor", value);
218-
219- Interface.LayoutUtils.Recalculate ();
220- if (MonitorChanged != null)
221- MonitorChanged ();
222+ if (SetMonitor (value))
223+ prefs.Set ("Monitor", value);
224 }
225 }
226+ static bool SetMonitor (int val)
227+ {
228+ if (val >= Gdk.Screen.Default.NMonitors || val < 0)
229+ val = 0;
230+
231+ if (monitor == val)
232+ return false;
233+
234+ monitor = val;
235+
236+ Interface.LayoutUtils.Recalculate ();
237+ if (MonitorChanged != null)
238+ MonitorChanged ();
239+ return true;
240+ }
241
242 static DockOrientation orientation = (DockOrientation) Enum.Parse (typeof (DockOrientation), prefs.Get ("Orientation", DockOrientation.Bottom.ToString ()));
243 public static DockOrientation Orientation {
244@@ -200,27 +263,37 @@
245 return orientation;
246 }
247 set {
248- if (orientation == value)
249- return;
250- orientation = value;
251- prefs.Set ("Orientation", value.ToString ());
252- if (OrientationChanged != null)
253- OrientationChanged ();
254+ if (SetOrientation (value))
255+ prefs.Set ("Orientation", value.ToString ());
256 }
257 }
258+ static bool SetOrientation (DockOrientation val)
259+ {
260+ if (orientation == val)
261+ return false;
262+ orientation = val;
263+ if (OrientationChanged != null)
264+ OrientationChanged ();
265+ return true;
266+ }
267
268 static AutohideType hide = (AutohideType) Enum.Parse (typeof (AutohideType), prefs.Get ("AutohideType", AutohideType.None.ToString ()));
269 public static AutohideType AutohideType {
270 get { return hide; }
271 set {
272- if (hide == value)
273- return;
274- hide = value;
275- prefs.Set ("AutohideType", value.ToString ());
276- if (AutohideChanged != null)
277- AutohideChanged ();
278+ if (SetAutohideType (value))
279+ prefs.Set ("AutohideType", value.ToString ());
280 }
281 }
282+ static bool SetAutohideType (AutohideType val)
283+ {
284+ if (hide == val)
285+ return false;
286+ hide = val;
287+ if (AutohideChanged != null)
288+ AutohideChanged ();
289+ return true;
290+ }
291
292 #region blacklists
293 static List<string> item_blacklist = DeserializeBlacklist ();
294
295=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs'
296--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs 2009-01-18 00:47:28 +0000
297+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/GConfPreferencesService.cs 2009-08-28 06:44:14 +0000
298@@ -38,6 +38,12 @@
299 {
300 RootPath = rootPath;
301 client = new GConf.Client ();
302+ client.AddNotify (RootPath, new GConf.NotifyEventHandler (HandleGConfChanged));
303+ }
304+
305+ void HandleGConfChanged (object sender, GConf.NotifyEventArgs args)
306+ {
307+ OnPreferencesChanged (args.Key.Substring(RootPath.Length + 1), null, args.Value);
308 }
309
310 string AbsolutePathForKey (string key)
311@@ -46,9 +52,23 @@
312 return key;
313 return string.Format ("{0}/{1}", RootPath, key);
314 }
315-
316+
317+ bool IgnoreNextEvent { get; set; }
318+
319+ void OnPreferencesChanged (string key, object oldValue, object newValue)
320+ {
321+ if (IgnoreNextEvent) {
322+ IgnoreNextEvent = false;
323+ return;
324+ }
325+ if (PreferencesChanged == null) return;
326+ PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue));
327+ }
328+
329 #region IPreferencesService
330
331+ public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged;
332+
333 public bool Set<T> (string key, T val)
334 {
335 bool success = true;
336@@ -59,6 +79,7 @@
337 Log.Debug (e.StackTrace);
338 success = false;
339 }
340+ IgnoreNextEvent = success;
341 return success;
342 }
343
344
345=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs'
346--- Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs 2009-01-18 00:47:28 +0000
347+++ Do.Platform/src/Do.Platform/Do.Platform.Common/DictionaryPreferencesService.cs 2009-08-28 05:42:11 +0000
348@@ -35,8 +35,16 @@
349 Store = new Dictionary<string, object> ();
350 }
351
352+ void OnPreferencesChanged (string key, object oldValue, object newValue)
353+ {
354+ if (PreferencesChanged == null) return;
355+ PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue));
356+ }
357+
358 #region IPreferencesService
359
360+ public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged;
361+
362 public bool Set<T> (string key, T val)
363 {
364 Store [key] = val;
365
366=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs'
367--- Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs 2008-12-18 18:39:06 +0000
368+++ Do.Platform/src/Do.Platform/Do.Platform.Default/PreferencesService.cs 2009-08-28 05:42:11 +0000
369@@ -29,6 +29,8 @@
370
371 #region IPreferencesService
372
373+ public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged;
374+
375 public bool Set<T> (string key, T val)
376 {
377 Log.Debug ("Default IPreferencesService cannot set key \"{0}\".", key);
378
379=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs'
380--- Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs 2009-01-08 18:12:28 +0000
381+++ Do.Platform/src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs 2009-08-28 06:40:00 +0000
382@@ -38,12 +38,19 @@
383 {
384 Service = service;
385 SecureService = new SecurePreferencesServiceWrapper (secureService);
386- }
387-
388- void OnPreferencesChanged (string key, object oldValue)
389+ Service.PreferencesChanged += HandlePreferencesChanged;
390+ }
391+
392+ void HandlePreferencesChanged (object o, PreferencesChangedEventArgs e)
393+ {
394+ if (e.Key.Length <= OwnerString.Length + 1 || e.Key.Substring(0, OwnerString.Length) != OwnerString) return;
395+ OnPreferencesChanged (e.Key.Substring(OwnerString.Length + 1), e.OldValue, e.Value);
396+ }
397+
398+ void OnPreferencesChanged (string key, object oldValue, object newValue)
399 {
400 if (PreferencesChanged == null) return;
401- PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue));
402+ PreferencesChanged (this, new PreferencesChangedEventArgs (key, oldValue, newValue));
403 }
404
405 #region IPreferences
406@@ -109,7 +116,7 @@
407 oldValue = default (T);
408
409 if (service.Set (keypath, val)) {
410- OnPreferencesChanged (key, oldValue);
411+ OnPreferencesChanged (key, oldValue, val);
412 return true;
413 }
414 return false;
415
416=== modified file 'Do.Platform/src/Do.Platform/IPreferencesService.cs'
417--- Do.Platform/src/Do.Platform/IPreferencesService.cs 2008-12-18 18:39:06 +0000
418+++ Do.Platform/src/Do.Platform/IPreferencesService.cs 2009-08-28 05:42:11 +0000
419@@ -28,7 +28,9 @@
420
421 public interface IPreferencesService : IService
422 {
423+ event EventHandler<PreferencesChangedEventArgs> PreferencesChanged;
424+
425 bool Set<T> (string key, T val);
426 bool TryGet<T> (string key, out T val);
427 }
428-}
429\ No newline at end of file
430+}
431
432=== modified file 'Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs'
433--- Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs 2008-12-18 18:39:06 +0000
434+++ Do.Platform/src/Do.Platform/PreferencesChangedEventArgs.cs 2009-08-28 05:42:11 +0000
435@@ -26,12 +26,14 @@
436 {
437 public string Key { get; private set; }
438 public object OldValue { get; private set; }
439+ public object Value { get; private set; }
440
441- public PreferencesChangedEventArgs (string key, object oldValue)
442+ public PreferencesChangedEventArgs (string key, object oldValue, object newValue)
443 {
444 Key = key;
445 OldValue = oldValue;
446+ Value = newValue;
447 }
448 }
449
450-}
451\ No newline at end of file
452+}
453
454=== modified file 'Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs'
455--- Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs 2008-12-18 18:39:06 +0000
456+++ Do.Platform/src/Do.Platform/SecurePreferencesWrapper.cs 2009-08-28 05:42:11 +0000
457@@ -36,6 +36,8 @@
458 {
459 SecureService = secureService;
460 }
461+
462+ public event EventHandler<PreferencesChangedEventArgs> PreferencesChanged;
463
464 public bool Set<T> (string key, T val)
465 {
466
467=== modified file 'Do/src/Do.Core/Controller.cs'
468--- Do/src/Do.Core/Controller.cs 2009-08-19 07:27:08 +0000
469+++ Do/src/Do.Core/Controller.cs 2009-08-28 05:42:11 +0000
470@@ -175,7 +175,8 @@
471
472 void OnThemeChanged (object sender, PreferencesChangedEventArgs e)
473 {
474- string oldTheme = e.OldValue as string, newTheme = Do.Preferences.Theme;
475+ if (e.Value == null) return;
476+ string oldTheme = e.OldValue as string, newTheme = e.Value as string;
477
478 // Only change the theme of the old and new themes are different.
479 if (oldTheme != newTheme) {