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
=== modified file 'configure.in'
--- configure.in 2011-07-13 10:07:04 +0000
+++ configure.in 2011-07-14 16:37:32 +0000
@@ -31,13 +31,7 @@
31#31#
32# glib, we need 2.16.0 for the unit-tests32# glib, we need 2.16.0 for the unit-tests
33#33#
34PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16.0 gthread-2.0 gconf-2.0 gio-2.0])34PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.16.0 gthread-2.0 gio-2.0])
35
36#
37# gconf, used by the Defaults class to get system font-face and font-size
38#
39PKG_CHECK_MODULES([GCONF], [gconf-2.0])
40
4135
42#36#
43# libwnck used by the dnd code37# libwnck used by the dnd code
4438
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2009-08-24 21:33:58 +0000
+++ src/Makefile.am 2011-07-14 16:37:32 +0000
@@ -83,7 +83,6 @@
83notify_osd_LDADD = \83notify_osd_LDADD = \
84 $(X_LIBS) \84 $(X_LIBS) \
85 $(GLIB_LIBS) \85 $(GLIB_LIBS) \
86 $(GCONF_LIBS) \
87 $(GTK_LIBS) \86 $(GTK_LIBS) \
88 $(NOTIFY_OSD_LIBS) \87 $(NOTIFY_OSD_LIBS) \
89 $(DBUS_LIBS) \88 $(DBUS_LIBS) \
@@ -95,7 +94,6 @@
95 $(GTK_CFLAGS) \94 $(GTK_CFLAGS) \
96 $(NOTIFY_OSD_CFLAGS) \95 $(NOTIFY_OSD_CFLAGS) \
97 $(GLIB_CFLAGS) \96 $(GLIB_CFLAGS) \
98 $(GCONF_CFLAGS) \
99 $(DBUS_CFLAGS) \97 $(DBUS_CFLAGS) \
100 -DWNCK_I_KNOW_THIS_IS_UNSTABLE \98 -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
101 $(WNCK_CFLAGS) \99 $(WNCK_CFLAGS) \
102100
=== modified file 'src/defaults.c'
--- src/defaults.c 2011-07-08 08:34:52 +0000
+++ src/defaults.c 2011-07-14 16:37:32 +0000
@@ -34,7 +34,6 @@
34#include <gdk/gdk.h>34#include <gdk/gdk.h>
35#include <gdk/gdkx.h>35#include <gdk/gdkx.h>
36#include <gtk/gtk.h>36#include <gtk/gtk.h>
37#include <gconf/gconf-client.h>
38#include <libwnck/libwnck.h>37#include <libwnck/libwnck.h>
3938
40#include "defaults.h"39#include "defaults.h"
@@ -146,21 +145,14 @@
146#define DEFAULT_FADE_OUT_TIMEOUT 1000145#define DEFAULT_FADE_OUT_TIMEOUT 1000
147#define DEFAULT_ON_SCREEN_TIMEOUT 10000146#define DEFAULT_ON_SCREEN_TIMEOUT 10000
148147
149/* GConf-keys to watch */
150#define GCONF_UI_FONT_NAME "/desktop/gnome/interface/font_name"
151#define GCONF_FONT_ANTIALIAS "/desktop/gnome/font_rendering/antialiasing"
152#define GCONF_FONT_DPI "/desktop/gnome/font_rendering/dpi"
153#define GCONF_FONT_HINTING "/desktop/gnome/font_rendering/hinting"
154#define GCONF_FONT_SUBPIXEL_ORDER "/desktop/gnome/font_rendering/rgba_order"
155
156/* GConf-trees to watch */
157#define GCONF_UI_TREE "/desktop/gnome/interface"
158#define GCONF_FONT_TREE "/desktop/gnome/font_rendering"
159#define GCONF_NOSD_TREE "/apps/notify-osd"
160
161/* notify-osd settings */148/* notify-osd settings */
162#define GCONF_MULTIHEAD_MODE "/apps/notify-osd/multihead_mode"149#define NOTIFY_OSD_SCHEMA "com.canonical.notify-osd"
163#define GCONF_GRAVITY "/apps/notify-osd/gravity"150#define GSETTINGS_GRAVITY_KEY "gravity"
151#define GSETTINGS_MULTIHEAD_MODE_KEY "multihead-mode"
152
153/* gnome settings */
154#define GNOME_DESKTOP_SCHEMA "org.gnome.desktop.interface"
155#define GSETTINGS_FONT_KEY "font-name"
164156
165static guint g_defaults_signals[LAST_SIGNAL] = { 0 };157static guint g_defaults_signals[LAST_SIGNAL] = { 0 };
166158
@@ -170,32 +162,21 @@
170_get_font_size_dpi (Defaults* self)162_get_font_size_dpi (Defaults* self)
171{163{
172 GString* string = NULL;164 GString* string = NULL;
173 GError* error = NULL;
174 gdouble points = 0.0f;165 gdouble points = 0.0f;
175 GString* font_face = NULL;166 GString* font_face = NULL;
176 gdouble dpi = 0.0f;167 gdouble dpi = 0.0f;
177 gdouble pixels_per_em = 0;168 gdouble pixels_per_em = 0;
178 gchar* font_name = NULL;169 gchar* font_name = NULL;
179 PangoFontDescription* desc = NULL;170 PangoFontDescription* desc = NULL;
171 GtkSettings* gtk_settings = NULL;
172 gint value = 0;
180173
181 if (!IS_DEFAULTS (self))174 if (!IS_DEFAULTS (self))
182 return;175 return;
183176
184 /* determine current system font-name/size */177 /* determine current system font-name/size */
185 error = NULL;178 font_name = g_settings_get_string (self->gnome_settings, GSETTINGS_FONT_KEY);
186 font_name = gconf_client_get_string (self->context,
187 GCONF_UI_FONT_NAME,
188 &error);
189 string = g_string_new (font_name);179 string = g_string_new (font_name);
190 if (error)
191 {
192 // if something went wrong, assume "Sans 10" and continue
193 string = g_string_assign (string, "Sans 10");
194
195 g_warning ("_get_font_size_dpi(): Got error \"%s\"\n",
196 error->message);
197 g_error_free (error);
198 }
199180
200 // extract text point-size181 // extract text point-size
201 desc = pango_font_description_from_string (font_name);182 desc = pango_font_description_from_string (font_name);
@@ -224,17 +205,9 @@
224 g_object_set (self, "system-font-size", (gdouble) points, NULL);205 g_object_set (self, "system-font-size", (gdouble) points, NULL);
225206
226 /* determine current system DPI-setting */207 /* determine current system DPI-setting */
227 error = NULL;208 gtk_settings = gtk_settings_get_default (); // not ref'ed
228 dpi = gconf_client_get_float (self->context, GCONF_FONT_DPI, &error);209 g_object_get (gtk_settings, "gtk-xft-dpi", &value, NULL);
229 if (error)210 dpi = (float) value / (float) 1024;
230 {
231 // if something went wrong, assume 96 DPI and continue
232 dpi = DEFAULT_SCREEN_DPI;
233
234 g_warning ("_get_font_size_dpi(): Got error \"%s\"\n",
235 error->message);
236 g_error_free (error);
237 }
238211
239 /* update stored DPI-value */212 /* update stored DPI-value */
240 pixels_per_em = points * dpi / 72.0f;213 pixels_per_em = points * dpi / 72.0f;
@@ -256,25 +229,13 @@
256static void229static void
257_get_gravity (Defaults* self)230_get_gravity (Defaults* self)
258{231{
259 GError* error = NULL;232 Gravity gravity = DEFAULT_GRAVITY;
260 Gravity gravity;
261233
262 if (!IS_DEFAULTS (self))234 if (!IS_DEFAULTS (self))
263 return;235 return;
264236
265 // grab current gravity-setting for notify-osd from gconf237 // grab current gravity-setting for notify-osd from GSettings
266 error = NULL;238 gravity = g_settings_get_int (self->nosd_settings, GSETTINGS_GRAVITY_KEY);
267 gravity = gconf_client_get_int (self->context, GCONF_GRAVITY, &error);
268 if (error)
269 {
270 // make sure we use a sane default for the gravity
271 gravity = DEFAULT_GRAVITY;
272
273 g_warning ("%s(): Got error \"%s\"\n",
274 G_STRFUNC,
275 error->message);
276 g_error_free (error);
277 }
278239
279 // protect against out-of-bounds values for gravity240 // protect against out-of-bounds values for gravity
280 if (gravity != GRAVITY_EAST && gravity != GRAVITY_NORTH_EAST)241 if (gravity != GRAVITY_EAST && gravity != GRAVITY_NORTH_EAST)
@@ -285,123 +246,40 @@
285}246}
286247
287static void248static void
288_font_changed (GConfClient* client,249_font_changed (GSettings* settings,
289 guint cnxn_id,250 gchar* key,
290 GConfEntry* entry,251 gpointer data)
291 gpointer data)252{
292{253 Defaults* defaults;
293 Defaults* defaults;254
294255 if (!data)
295 if (!data)256 return;
296 return;257
297258 defaults = (Defaults*) data;
298 defaults = (Defaults*) data;259 if (!IS_DEFAULTS (defaults))
299 if (!IS_DEFAULTS (defaults))260 return;
300 return;261
301262 /* grab system-wide font-face/size and DPI */
302 /* grab system-wide font-face/size and DPI */263 _get_font_size_dpi (defaults);
303 _get_font_size_dpi (defaults);264
304265 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
305 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);266}
306}267
307268static void
308static void269_gravity_changed (GSettings* settings,
309_antialias_changed (GConfClient* client,270 gchar* key,
310 guint cnxn_id,271 gpointer data)
311 GConfEntry* entry,272{
312 gpointer data)273 Defaults* defaults;
313{274
314 Defaults* defaults;275 if (!data)
315276 return;
316 if (!data)277
317 return;278 defaults = (Defaults*) data;
318279 if (!IS_DEFAULTS (defaults))
319 defaults = (Defaults*) data;280 return;
320 if (!IS_DEFAULTS (defaults))281
321 return;282 // grab gravity setting for notify-osd from gconf
322
323 /* just triggering a redraw by emitting the "value-changed" signal is
324 ** enough in this case, no need to update any stored values */
325 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
326}
327
328static void
329_dpi_changed (GConfClient* client,
330 guint cnxn_id,
331 GConfEntry* entry,
332 gpointer data)
333{
334 Defaults* defaults;
335
336 if (!data)
337 return;
338
339 defaults = (Defaults*) data;
340 if (!IS_DEFAULTS (defaults))
341 return;
342
343 /* grab system-wide font-face/size and DPI */
344 _get_font_size_dpi (defaults);
345
346 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
347}
348
349static void
350_hinting_changed (GConfClient* client,
351 guint cnxn_id,
352 GConfEntry* entry,
353 gpointer data)
354{
355 Defaults* defaults;
356
357 if (!data)
358 return;
359
360 defaults = (Defaults*) data;
361 if (!IS_DEFAULTS (defaults))
362 return;
363
364 /* just triggering a redraw by emitting the "value-changed" signal is
365 ** enough in this case, no need to update any stored values */
366 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
367}
368
369static void
370_subpixel_order_changed (GConfClient* client,
371 guint cnxn_id,
372 GConfEntry* entry,
373 gpointer data)
374{
375 Defaults* defaults;
376
377 if (!data)
378 return;
379
380 defaults = (Defaults*) data;
381 if (!IS_DEFAULTS (defaults))
382 return;
383
384 /* just triggering a redraw by emitting the "value-changed" signal is
385 ** enough in this case, no need to update any stored values */
386 g_signal_emit (defaults, g_defaults_signals[VALUE_CHANGED], 0);
387}
388
389static void
390_gravity_changed (GConfClient* client,
391 guint cnxn_id,
392 GConfEntry* entry,
393 gpointer data)
394{
395 Defaults* defaults;
396
397 if (!data)
398 return;
399
400 defaults = (Defaults*) data;
401 if (!IS_DEFAULTS (defaults))
402 return;
403
404 // grab gravity setting for notify-osd from gconf
405 _get_gravity (defaults);283 _get_gravity (defaults);
406284
407 g_signal_emit (defaults, g_defaults_signals[GRAVITY_CHANGED], 0);285 g_signal_emit (defaults, g_defaults_signals[GRAVITY_CHANGED], 0);
@@ -537,16 +415,8 @@
537415
538 defaults = DEFAULTS (gobject);416 defaults = DEFAULTS (gobject);
539417
540 gconf_client_notify_remove (defaults->context, defaults->notifier[0]);418 g_object_unref (defaults->nosd_settings);
541 gconf_client_notify_remove (defaults->context, defaults->notifier[1]);419 g_object_unref (defaults->gnome_settings);
542 gconf_client_notify_remove (defaults->context, defaults->notifier[2]);
543 gconf_client_notify_remove (defaults->context, defaults->notifier[3]);
544 gconf_client_notify_remove (defaults->context, defaults->notifier[4]);
545 gconf_client_notify_remove (defaults->context, defaults->notifier[5]);
546 gconf_client_remove_dir (defaults->context, GCONF_UI_TREE, NULL);
547 gconf_client_remove_dir (defaults->context, GCONF_FONT_TREE, NULL);
548 gconf_client_remove_dir (defaults->context, GCONF_NOSD_TREE, NULL);
549 g_object_unref (defaults->context);
550420
551 if (defaults->bubble_shadow_color)421 if (defaults->bubble_shadow_color)
552 {422 {
@@ -608,157 +478,21 @@
608}478}
609479
610static void480static void
611_handle_error (Defaults* self,
612 GError* error)
613{
614 // no sanity-checks here
615
616 gconf_client_notify_remove (self->context, self->notifier[0]);
617 gconf_client_notify_remove (self->context, self->notifier[1]);
618 gconf_client_notify_remove (self->context, self->notifier[2]);
619 gconf_client_notify_remove (self->context, self->notifier[3]);
620 gconf_client_notify_remove (self->context, self->notifier[4]);
621 gconf_client_notify_remove (self->context, self->notifier[5]);
622 gconf_client_remove_dir (self->context, GCONF_UI_TREE, NULL);
623 gconf_client_remove_dir (self->context, GCONF_FONT_TREE, NULL);
624 gconf_client_remove_dir (self->context, GCONF_NOSD_TREE, NULL);
625 g_object_unref (self->context);
626 g_warning ("%s(): Got error \"%s\"\n", G_STRFUNC, error->message);
627 g_error_free (error);
628}
629
630static void
631defaults_init (Defaults* self)481defaults_init (Defaults* self)
632{482{
633 GError* error;483 /* "connect" to the required GSettings schemas */
634484 self->nosd_settings = g_settings_new (NOTIFY_OSD_SCHEMA);
635 /* "connect" to the whole gconf-thing */485 self->gnome_settings = g_settings_new (GNOME_DESKTOP_SCHEMA);;
636 self->context = gconf_client_get_default ();486
637 if (!self->context)487 g_signal_connect (self->gnome_settings,
638 {488 "changed",
639 g_warning ("Could not get GConf client-context");489 G_CALLBACK (_font_changed),
640 return;490 self);
641 }491
642492 g_signal_connect (self->nosd_settings,
643 /* register watching all relevant GNOME UI-settings */493 "changed",
644 error = NULL;494 G_CALLBACK (_gravity_changed),
645 gconf_client_add_dir (self->context,495 self);
646 GCONF_UI_TREE,
647 GCONF_CLIENT_PRELOAD_NONE,
648 &error);
649 if (error)
650 {
651 _handle_error (self, error);
652 return;
653 }
654
655 /* register watching all font-settings */
656 error = NULL;
657 gconf_client_add_dir (self->context,
658 GCONF_FONT_TREE,
659 GCONF_CLIENT_PRELOAD_NONE,
660 &error);
661 if (error)
662 {
663 _handle_error (self, error);
664 return;
665 }
666
667 /* register watching all settings for notify-osd */
668 error = NULL;
669 gconf_client_add_dir (self->context,
670 GCONF_NOSD_TREE,
671 GCONF_CLIENT_PRELOAD_NONE,
672 &error);
673 if (error)
674 {
675 _handle_error (self, error);
676 return;
677 }
678
679 /* hook up notifier for font-name/size changes */
680 error = NULL;
681 self->notifier[0] = gconf_client_notify_add (self->context,
682 GCONF_UI_FONT_NAME,
683 _font_changed,
684 (gpointer) self,
685 NULL,
686 &error);
687 if (error)
688 {
689 _handle_error (self, error);
690 return;
691 }
692
693 /* hook up notifier for antialiasing changes */
694 error = NULL;
695 self->notifier[1] = gconf_client_notify_add (self->context,
696 GCONF_FONT_ANTIALIAS,
697 _antialias_changed,
698 (gpointer) self,
699 NULL,
700 &error);
701 if (error)
702 {
703 _handle_error (self, error);
704 return;
705 }
706
707 /* hook up notifier for DPI changes */
708 error = NULL;
709 self->notifier[2] = gconf_client_notify_add (self->context,
710 GCONF_FONT_DPI,
711 _dpi_changed,
712 (gpointer) self,
713 NULL,
714 &error);
715 if (error)
716 {
717 _handle_error (self, error);
718 return;
719 }
720
721 /* hook up notifier for hinting changes */
722 error = NULL;
723 self->notifier[3] = gconf_client_notify_add (self->context,
724 GCONF_FONT_HINTING,
725 _hinting_changed,
726 (gpointer) self,
727 NULL,
728 &error);
729 if (error)
730 {
731 _handle_error (self, error);
732 return;
733 }
734
735 /* hook up notifier for subpixel-order changes */
736 error = NULL;
737 self->notifier[4] = gconf_client_notify_add (self->context,
738 GCONF_FONT_SUBPIXEL_ORDER,
739 _subpixel_order_changed,
740 (gpointer) self,
741 NULL,
742 &error);
743 if (error)
744 {
745 _handle_error (self, error);
746 return;
747 }
748
749 // hook up notifiier for gravity changes
750 error = NULL;
751 self->notifier[5] = gconf_client_notify_add (self->context,
752 GCONF_NOSD_TREE,
753 _gravity_changed,
754 (gpointer) self,
755 NULL,
756 &error);
757 if (error)
758 {
759 _handle_error (self, error);
760 return;
761 }
762496
763 // use fixed slot-allocation for async. and sync. bubbles497 // use fixed slot-allocation for async. and sync. bubbles
764 self->slot_allocation = SLOT_ALLOCATION_FIXED;498 self->slot_allocation = SLOT_ALLOCATION_FIXED;
@@ -2326,14 +2060,13 @@
2326static gboolean2060static gboolean
2327defaults_multihead_does_focus_follow (Defaults *self)2061defaults_multihead_does_focus_follow (Defaults *self)
2328{2062{
2329 GError* error = NULL;2063 gboolean mode = FALSE;
2330 gboolean mode = FALSE;
23312064
2332 g_return_val_if_fail (self != NULL && IS_DEFAULTS (self), FALSE);2065 g_return_val_if_fail (self != NULL && IS_DEFAULTS (self), FALSE);
23332066
2334 gchar* mode_str = gconf_client_get_string (self->context,2067 gchar* mode_str = g_settings_get_string (self->nosd_settings,
2335 GCONF_MULTIHEAD_MODE,2068 GSETTINGS_MULTIHEAD_MODE_KEY);
2336 &error);2069
2337 if (mode_str != NULL)2070 if (mode_str != NULL)
2338 {2071 {
2339 if (! g_strcmp0 (mode_str, "focus-follow"))2072 if (! g_strcmp0 (mode_str, "focus-follow"))
@@ -2341,13 +2074,6 @@
23412074
2342 g_free ((gpointer) mode_str);2075 g_free ((gpointer) mode_str);
2343 }2076 }
2344 else if (error != NULL)
2345 {
2346 g_warning ("defaults_multihead_does_focus_follow(): "
2347 "Got error \"%s\"\n",
2348 error->message);
2349 g_error_free (error);
2350 }
2351 2077
2352 return mode;2078 return mode;
2353}2079}
23542080
=== modified file 'src/defaults.h'
--- src/defaults.h 2009-09-10 13:11:32 +0000
+++ src/defaults.h 2011-07-14 16:37:32 +0000
@@ -30,7 +30,7 @@
30#define __DEFAULTS_H30#define __DEFAULTS_H
3131
32#include <glib-object.h>32#include <glib-object.h>
33#include <gconf/gconf-client.h>33#include <gio/gio.h>
3434
35G_BEGIN_DECLS35G_BEGIN_DECLS
3636
@@ -74,8 +74,8 @@
74 GObject parent;74 GObject parent;
7575
76 /* private */76 /* private */
77 GConfClient* context;77 GSettings* nosd_settings;
78 guint notifier[6];78 GSettings* gnome_settings;
79 gint desktop_width;79 gint desktop_width;
80 gint desktop_height;80 gint desktop_height;
81 gint desktop_top;81 gint desktop_top;

Subscribers

People subscribed via source and target branches