Merge lp:~macslow/notify-osd/gsettings-port into lp:notify-osd/oneiric

Proposed by Mirco Müller on 2011-07-14
Status: Merged
Approved by: Mirco Müller on 2011-07-15
Approved revision: 443
Merged at revision: 442
Proposed branch: lp:~macslow/notify-osd/gsettings-port
Merge into: lp:notify-osd/oneiric
Diff against target: 570 lines (+73/-355)
4 files modified
configure.in (+1/-7)
src/Makefile.am (+0/-2)
src/defaults.c (+69/-343)
src/defaults.h (+3/-3)
To merge this branch: bzr merge lp:~macslow/notify-osd/gsettings-port
Reviewer Review Type Date Requested Status
Gord Allott (community) 2011-07-14 Approve on 2011-07-15
Review via email: mp+67926@code.launchpad.net

Description of the change

This is the GConf to GSettings port for NotifyOSD. It covers the pure API-change and also the schema migration. So there's no packaging magic needed to make this work.

Because with the introduction of GNOME 3 and moving away from GConf a lot of NotifyOSD's dynamic nature to adapt to settings-changes of the user had to be dropped, which on the plus-side allowed to get rid of some less-frequent executed code-paths.

NotifyOSD's keys in the GSettings-schema are monitored as is the system-wide key for the font. But the DPI key from GtkSettings can't be monitored.

To post a comment you must log in.

I don't see any gconf stuff removed from any Makefile.am or
configure.ac - so I guess you still link in libgonf. Is that on
purpose?

443. By Mirco Müller on 2011-07-14

No need for any gconf in the autotools configure.in and src/Makefile.am since we live on GSettings now

Mirco Müller (macslow) wrote :

*cough* got rid of the now superfluous GConf-bits in configure.in and src/Makefile.am

Gord Allott (gordallott) wrote :

+1 looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.in'
2--- configure.in 2011-07-13 10:07:04 +0000
3+++ configure.in 2011-07-14 16:37:32 +0000
4@@ -31,13 +31,7 @@
5 #
6 # glib, we need 2.16.0 for the unit-tests
7 #
8-PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16.0 gthread-2.0 gconf-2.0 gio-2.0])
9-
10-#
11-# gconf, used by the Defaults class to get system font-face and font-size
12-#
13-PKG_CHECK_MODULES([GCONF], [gconf-2.0])
14-
15+PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16.0 gthread-2.0 gio-2.0])
16
17 #
18 # libwnck used by the dnd code
19
20=== modified file 'src/Makefile.am'
21--- src/Makefile.am 2009-08-24 21:33:58 +0000
22+++ src/Makefile.am 2011-07-14 16:37:32 +0000
23@@ -83,7 +83,6 @@
24 notify_osd_LDADD = \
25 $(X_LIBS) \
26 $(GLIB_LIBS) \
27- $(GCONF_LIBS) \
28 $(GTK_LIBS) \
29 $(NOTIFY_OSD_LIBS) \
30 $(DBUS_LIBS) \
31@@ -95,7 +94,6 @@
32 $(GTK_CFLAGS) \
33 $(NOTIFY_OSD_CFLAGS) \
34 $(GLIB_CFLAGS) \
35- $(GCONF_CFLAGS) \
36 $(DBUS_CFLAGS) \
37 -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
38 $(WNCK_CFLAGS) \
39
40=== modified file 'src/defaults.c'
41--- src/defaults.c 2011-07-08 08:34:52 +0000
42+++ src/defaults.c 2011-07-14 16:37:32 +0000
43@@ -34,7 +34,6 @@
44 #include <gdk/gdk.h>
45 #include <gdk/gdkx.h>
46 #include <gtk/gtk.h>
47-#include <gconf/gconf-client.h>
48 #include <libwnck/libwnck.h>
49
50 #include "defaults.h"
51@@ -146,21 +145,14 @@
52 #define DEFAULT_FADE_OUT_TIMEOUT 1000
53 #define DEFAULT_ON_SCREEN_TIMEOUT 10000
54
55-/* GConf-keys to watch */
56-#define GCONF_UI_FONT_NAME "/desktop/gnome/interface/font_name"
57-#define GCONF_FONT_ANTIALIAS "/desktop/gnome/font_rendering/antialiasing"
58-#define GCONF_FONT_DPI "/desktop/gnome/font_rendering/dpi"
59-#define GCONF_FONT_HINTING "/desktop/gnome/font_rendering/hinting"
60-#define GCONF_FONT_SUBPIXEL_ORDER "/desktop/gnome/font_rendering/rgba_order"
61-
62-/* GConf-trees to watch */
63-#define GCONF_UI_TREE "/desktop/gnome/interface"
64-#define GCONF_FONT_TREE "/desktop/gnome/font_rendering"
65-#define GCONF_NOSD_TREE "/apps/notify-osd"
66-
67 /* notify-osd settings */
68-#define GCONF_MULTIHEAD_MODE "/apps/notify-osd/multihead_mode"
69-#define GCONF_GRAVITY "/apps/notify-osd/gravity"
70+#define NOTIFY_OSD_SCHEMA "com.canonical.notify-osd"
71+#define GSETTINGS_GRAVITY_KEY "gravity"
72+#define GSETTINGS_MULTIHEAD_MODE_KEY "multihead-mode"
73+
74+/* gnome settings */
75+#define GNOME_DESKTOP_SCHEMA "org.gnome.desktop.interface"
76+#define GSETTINGS_FONT_KEY "font-name"
77
78 static guint g_defaults_signals[LAST_SIGNAL] = { 0 };
79
80@@ -170,32 +162,21 @@
81 _get_font_size_dpi (Defaults* self)
82 {
83 GString* string = NULL;
84- GError* error = NULL;
85 gdouble points = 0.0f;
86 GString* font_face = NULL;
87 gdouble dpi = 0.0f;
88 gdouble pixels_per_em = 0;
89 gchar* font_name = NULL;
90 PangoFontDescription* desc = NULL;
91+ GtkSettings* gtk_settings = NULL;
92+ gint value = 0;
93
94 if (!IS_DEFAULTS (self))
95 return;
96
97 /* determine current system font-name/size */
98- error = NULL;
99- font_name = gconf_client_get_string (self->context,
100- GCONF_UI_FONT_NAME,
101- &error);
102+ font_name = g_settings_get_string (self->gnome_settings, GSETTINGS_FONT_KEY);
103 string = g_string_new (font_name);
104- if (error)
105- {
106- // if something went wrong, assume "Sans 10" and continue
107- string = g_string_assign (string, "Sans 10");
108-
109- g_warning ("_get_font_size_dpi(): Got error \"%s\"\n",
110- error->message);
111- g_error_free (error);
112- }
113
114 // extract text point-size
115 desc = pango_font_description_from_string (font_name);
116@@ -224,17 +205,9 @@
117 g_object_set (self, "system-font-size", (gdouble) points, NULL);
118
119 /* determine current system DPI-setting */
120- error = NULL;
121- dpi = gconf_client_get_float (self->context, GCONF_FONT_DPI, &error);
122- if (error)
123- {
124- // if something went wrong, assume 96 DPI and continue
125- dpi = DEFAULT_SCREEN_DPI;
126-
127- g_warning ("_get_font_size_dpi(): Got error \"%s\"\n",
128- error->message);
129- g_error_free (error);
130- }
131+ gtk_settings = gtk_settings_get_default (); // not ref'ed
132+ g_object_get (gtk_settings, "gtk-xft-dpi", &value, NULL);
133+ dpi = (float) value / (float) 1024;
134
135 /* update stored DPI-value */
136 pixels_per_em = points * dpi / 72.0f;
137@@ -256,25 +229,13 @@
138 static void
139 _get_gravity (Defaults* self)
140 {
141- GError* error = NULL;
142- Gravity gravity;
143+ Gravity gravity = DEFAULT_GRAVITY;
144
145 if (!IS_DEFAULTS (self))
146 return;
147
148- // grab current gravity-setting for notify-osd from gconf
149- error = NULL;
150- gravity = gconf_client_get_int (self->context, GCONF_GRAVITY, &error);
151- if (error)
152- {
153- // make sure we use a sane default for the gravity
154- gravity = DEFAULT_GRAVITY;
155-
156- g_warning ("%s(): Got error \"%s\"\n",
157- G_STRFUNC,
158- error->message);
159- g_error_free (error);
160- }
161+ // grab current gravity-setting for notify-osd from GSettings
162+ gravity = g_settings_get_int (self->nosd_settings, GSETTINGS_GRAVITY_KEY);
163
164 // protect against out-of-bounds values for gravity
165 if (gravity != GRAVITY_EAST && gravity != GRAVITY_NORTH_EAST)
166@@ -285,123 +246,40 @@
167 }
168
169 static void
170-_font_changed (GConfClient* client,
171- guint cnxn_id,
172- GConfEntry* entry,
173- gpointer data)
174-{
175- Defaults* defaults;
176-
177- if (!data)
178- return;
179-
180- defaults = (Defaults*) data;
181- if (!IS_DEFAULTS (defaults))
182- return;
183-
184- /* grab system-wide font-face/size and DPI */
185- _get_font_size_dpi (defaults);
186-
187- g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
188-}
189-
190-static void
191-_antialias_changed (GConfClient* client,
192- guint cnxn_id,
193- GConfEntry* entry,
194- gpointer data)
195-{
196- Defaults* defaults;
197-
198- if (!data)
199- return;
200-
201- defaults = (Defaults*) data;
202- if (!IS_DEFAULTS (defaults))
203- return;
204-
205- /* just triggering a redraw by emitting the "value-changed" signal is
206- ** enough in this case, no need to update any stored values */
207- g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
208-}
209-
210-static void
211-_dpi_changed (GConfClient* client,
212- guint cnxn_id,
213- GConfEntry* entry,
214- gpointer data)
215-{
216- Defaults* defaults;
217-
218- if (!data)
219- return;
220-
221- defaults = (Defaults*) data;
222- if (!IS_DEFAULTS (defaults))
223- return;
224-
225- /* grab system-wide font-face/size and DPI */
226- _get_font_size_dpi (defaults);
227-
228- g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
229-}
230-
231-static void
232-_hinting_changed (GConfClient* client,
233- guint cnxn_id,
234- GConfEntry* entry,
235- gpointer data)
236-{
237- Defaults* defaults;
238-
239- if (!data)
240- return;
241-
242- defaults = (Defaults*) data;
243- if (!IS_DEFAULTS (defaults))
244- return;
245-
246- /* just triggering a redraw by emitting the "value-changed" signal is
247- ** enough in this case, no need to update any stored values */
248- g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
249-}
250-
251-static void
252-_subpixel_order_changed (GConfClient* client,
253- guint cnxn_id,
254- GConfEntry* entry,
255- gpointer data)
256-{
257- Defaults* defaults;
258-
259- if (!data)
260- return;
261-
262- defaults = (Defaults*) data;
263- if (!IS_DEFAULTS (defaults))
264- return;
265-
266- /* just triggering a redraw by emitting the "value-changed" signal is
267- ** enough in this case, no need to update any stored values */
268- g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
269-}
270-
271-static void
272-_gravity_changed (GConfClient* client,
273- guint cnxn_id,
274- GConfEntry* entry,
275- gpointer data)
276-{
277- Defaults* defaults;
278-
279- if (!data)
280- return;
281-
282- defaults = (Defaults*) data;
283- if (!IS_DEFAULTS (defaults))
284- return;
285-
286- // grab gravity setting for notify-osd from gconf
287+_font_changed (GSettings* settings,
288+ gchar* key,
289+ gpointer data)
290+{
291+ Defaults* defaults;
292+
293+ if (!data)
294+ return;
295+
296+ defaults = (Defaults*) data;
297+ if (!IS_DEFAULTS (defaults))
298+ return;
299+
300+ /* grab system-wide font-face/size and DPI */
301+ _get_font_size_dpi (defaults);
302+
303+ g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
304+}
305+
306+static void
307+_gravity_changed (GSettings* settings,
308+ gchar* key,
309+ gpointer data)
310+{
311+ Defaults* defaults;
312+
313+ if (!data)
314+ return;
315+
316+ defaults = (Defaults*) data;
317+ if (!IS_DEFAULTS (defaults))
318+ return;
319+
320+ // grab gravity setting for notify-osd from gconf
321 _get_gravity (defaults);
322
323 g_signal_emit (defaults, g_defaults_signals[GRAVITY_CHANGED], 0);
324@@ -537,16 +415,8 @@
325
326 defaults = DEFAULTS (gobject);
327
328- gconf_client_notify_remove (defaults->context, defaults->notifier[0]);
329- gconf_client_notify_remove (defaults->context, defaults->notifier[1]);
330- gconf_client_notify_remove (defaults->context, defaults->notifier[2]);
331- gconf_client_notify_remove (defaults->context, defaults->notifier[3]);
332- gconf_client_notify_remove (defaults->context, defaults->notifier[4]);
333- gconf_client_notify_remove (defaults->context, defaults->notifier[5]);
334- gconf_client_remove_dir (defaults->context, GCONF_UI_TREE, NULL);
335- gconf_client_remove_dir (defaults->context, GCONF_FONT_TREE, NULL);
336- gconf_client_remove_dir (defaults->context, GCONF_NOSD_TREE, NULL);
337- g_object_unref (defaults->context);
338+ g_object_unref (defaults->nosd_settings);
339+ g_object_unref (defaults->gnome_settings);
340
341 if (defaults->bubble_shadow_color)
342 {
343@@ -608,157 +478,21 @@
344 }
345
346 static void
347-_handle_error (Defaults* self,
348- GError* error)
349-{
350- // no sanity-checks here
351-
352- gconf_client_notify_remove (self->context, self->notifier[0]);
353- gconf_client_notify_remove (self->context, self->notifier[1]);
354- gconf_client_notify_remove (self->context, self->notifier[2]);
355- gconf_client_notify_remove (self->context, self->notifier[3]);
356- gconf_client_notify_remove (self->context, self->notifier[4]);
357- gconf_client_notify_remove (self->context, self->notifier[5]);
358- gconf_client_remove_dir (self->context, GCONF_UI_TREE, NULL);
359- gconf_client_remove_dir (self->context, GCONF_FONT_TREE, NULL);
360- gconf_client_remove_dir (self->context, GCONF_NOSD_TREE, NULL);
361- g_object_unref (self->context);
362- g_warning ("%s(): Got error \"%s\"\n", G_STRFUNC, error->message);
363- g_error_free (error);
364-}
365-
366-static void
367 defaults_init (Defaults* self)
368 {
369- GError* error;
370-
371- /* "connect" to the whole gconf-thing */
372- self->context = gconf_client_get_default ();
373- if (!self->context)
374- {
375- g_warning ("Could not get GConf client-context");
376- return;
377- }
378-
379- /* register watching all relevant GNOME UI-settings */
380- error = NULL;
381- gconf_client_add_dir (self->context,
382- GCONF_UI_TREE,
383- GCONF_CLIENT_PRELOAD_NONE,
384- &error);
385- if (error)
386- {
387- _handle_error (self, error);
388- return;
389- }
390-
391- /* register watching all font-settings */
392- error = NULL;
393- gconf_client_add_dir (self->context,
394- GCONF_FONT_TREE,
395- GCONF_CLIENT_PRELOAD_NONE,
396- &error);
397- if (error)
398- {
399- _handle_error (self, error);
400- return;
401- }
402-
403- /* register watching all settings for notify-osd */
404- error = NULL;
405- gconf_client_add_dir (self->context,
406- GCONF_NOSD_TREE,
407- GCONF_CLIENT_PRELOAD_NONE,
408- &error);
409- if (error)
410- {
411- _handle_error (self, error);
412- return;
413- }
414-
415- /* hook up notifier for font-name/size changes */
416- error = NULL;
417- self->notifier[0] = gconf_client_notify_add (self->context,
418- GCONF_UI_FONT_NAME,
419- _font_changed,
420- (gpointer) self,
421- NULL,
422- &error);
423- if (error)
424- {
425- _handle_error (self, error);
426- return;
427- }
428-
429- /* hook up notifier for antialiasing changes */
430- error = NULL;
431- self->notifier[1] = gconf_client_notify_add (self->context,
432- GCONF_FONT_ANTIALIAS,
433- _antialias_changed,
434- (gpointer) self,
435- NULL,
436- &error);
437- if (error)
438- {
439- _handle_error (self, error);
440- return;
441- }
442-
443- /* hook up notifier for DPI changes */
444- error = NULL;
445- self->notifier[2] = gconf_client_notify_add (self->context,
446- GCONF_FONT_DPI,
447- _dpi_changed,
448- (gpointer) self,
449- NULL,
450- &error);
451- if (error)
452- {
453- _handle_error (self, error);
454- return;
455- }
456-
457- /* hook up notifier for hinting changes */
458- error = NULL;
459- self->notifier[3] = gconf_client_notify_add (self->context,
460- GCONF_FONT_HINTING,
461- _hinting_changed,
462- (gpointer) self,
463- NULL,
464- &error);
465- if (error)
466- {
467- _handle_error (self, error);
468- return;
469- }
470-
471- /* hook up notifier for subpixel-order changes */
472- error = NULL;
473- self->notifier[4] = gconf_client_notify_add (self->context,
474- GCONF_FONT_SUBPIXEL_ORDER,
475- _subpixel_order_changed,
476- (gpointer) self,
477- NULL,
478- &error);
479- if (error)
480- {
481- _handle_error (self, error);
482- return;
483- }
484-
485- // hook up notifiier for gravity changes
486- error = NULL;
487- self->notifier[5] = gconf_client_notify_add (self->context,
488- GCONF_NOSD_TREE,
489- _gravity_changed,
490- (gpointer) self,
491- NULL,
492- &error);
493- if (error)
494- {
495- _handle_error (self, error);
496- return;
497- }
498+ /* "connect" to the required GSettings schemas */
499+ self->nosd_settings = g_settings_new (NOTIFY_OSD_SCHEMA);
500+ self->gnome_settings = g_settings_new (GNOME_DESKTOP_SCHEMA);;
501+
502+ g_signal_connect (self->gnome_settings,
503+ "changed",
504+ G_CALLBACK (_font_changed),
505+ self);
506+
507+ g_signal_connect (self->nosd_settings,
508+ "changed",
509+ G_CALLBACK (_gravity_changed),
510+ self);
511
512 // use fixed slot-allocation for async. and sync. bubbles
513 self->slot_allocation = SLOT_ALLOCATION_FIXED;
514@@ -2326,14 +2060,13 @@
515 static gboolean
516 defaults_multihead_does_focus_follow (Defaults *self)
517 {
518- GError* error = NULL;
519- gboolean mode = FALSE;
520+ gboolean mode = FALSE;
521
522 g_return_val_if_fail (self != NULL && IS_DEFAULTS (self), FALSE);
523
524- gchar* mode_str = gconf_client_get_string (self->context,
525- GCONF_MULTIHEAD_MODE,
526- &error);
527+ gchar* mode_str = g_settings_get_string (self->nosd_settings,
528+ GSETTINGS_MULTIHEAD_MODE_KEY);
529+
530 if (mode_str != NULL)
531 {
532 if (! g_strcmp0 (mode_str, "focus-follow"))
533@@ -2341,13 +2074,6 @@
534
535 g_free ((gpointer) mode_str);
536 }
537- else if (error != NULL)
538- {
539- g_warning ("defaults_multihead_does_focus_follow(): "
540- "Got error \"%s\"\n",
541- error->message);
542- g_error_free (error);
543- }
544
545 return mode;
546 }
547
548=== modified file 'src/defaults.h'
549--- src/defaults.h 2009-09-10 13:11:32 +0000
550+++ src/defaults.h 2011-07-14 16:37:32 +0000
551@@ -30,7 +30,7 @@
552 #define __DEFAULTS_H
553
554 #include <glib-object.h>
555-#include <gconf/gconf-client.h>
556+#include <gio/gio.h>
557
558 G_BEGIN_DECLS
559
560@@ -74,8 +74,8 @@
561 GObject parent;
562
563 /* private */
564- GConfClient* context;
565- guint notifier[6];
566+ GSettings* nosd_settings;
567+ GSettings* gnome_settings;
568 gint desktop_width;
569 gint desktop_height;
570 gint desktop_top;

Subscribers

People subscribed via source and target branches