[gnome-applets] stickynotes: port to GSettings



commit 8ff396c8ad595ac4f342521a9ddfcfbe5e2578db
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Sep 21 00:14:46 2014 +0300

    stickynotes: port to GSettings

 po/POTFILES.in                                     |    2 +-
 po/POTFILES.skip                                   |    1 +
 stickynotes/Makefile.am                            |   27 ++--
 stickynotes/gsettings.h                            |   21 +++
 ...ome.gnome-applets.stickynotes.gschema.xml.in.in |   69 +++++++++
 stickynotes/stickynotes.c                          |  101 ++++++-------
 stickynotes/stickynotes.schemas.in                 |  161 --------------------
 stickynotes/stickynotes_applet.c                   |  118 ++++++---------
 stickynotes/stickynotes_applet.h                   |    7 +-
 stickynotes/stickynotes_applet_callbacks.c         |  111 +++++---------
 stickynotes/stickynotes_applet_callbacks.h         |    2 +-
 11 files changed, 241 insertions(+), 379 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b31fff7..83bc9a6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -79,11 +79,11 @@ multiload/properties.c
 [type: gettext/ini]stickynotes/org.gnome.applets.StickyNotesApplet.panel-applet.in.in
 stickynotes/stickynotes.c
 [type: gettext/glade]stickynotes/stickynotes.ui
-stickynotes/stickynotes.schemas.in
 stickynotes/stickynotes_applet.c
 stickynotes/stickynotes_applet_callbacks.c
 stickynotes/stickynotes_callbacks.c
 [type: gettext/ini]trashapplet/org.gnome.applets.TrashApplet.panel-applet.in.in
+stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in.in
 trashapplet/src/trashapplet.c
 trashapplet/src/trash-empty.c
 [type: gettext/glade]trashapplet/trashapplet-empty-progress.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 658f709..cf47ef0 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -22,4 +22,5 @@ mixer/org.gnome.applets.MixerApplet.panel-applet.in
 modemlights/org.gnome.applets.ModemApplet.panel-applet.in
 multiload/org.gnome.applets.MultiLoadApplet.panel-applet.in
 stickynotes/org.gnome.applets.StickyNotesApplet.panel-applet.in
+stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in
 trashapplet/org.gnome.applets.TrashApplet.panel-applet.in
diff --git a/stickynotes/Makefile.am b/stickynotes/Makefile.am
index f823fc3..e935301 100644
--- a/stickynotes/Makefile.am
+++ b/stickynotes/Makefile.am
@@ -6,7 +6,7 @@ ui_files = stickynotes-applet-menu.xml
 builder_files = stickynotes.ui
 applet_in_files = org.gnome.applets.StickyNotesApplet.panel-applet.in
 service_in_files = org.gnome.panel.applet.StickyNotesAppletFactory.service.in
-schemas_in_files = stickynotes.schemas.in
+gsettings_schemas_in_in = org.gnome.gnome-applets.stickynotes.gschema.xml.in.in
 
 if BUILD_STICKYNOTES_APPLET
 AM_CPPFLAGS =                                  \
@@ -31,7 +31,8 @@ stickynotes_applet_SOURCES = \
        stickynotes.c \
        stickynotes_callbacks.c \
        stickynotes_applet.c \
-       stickynotes_applet_callbacks.c
+       stickynotes_applet_callbacks.c \
+       gsettings.h
 
 stickynotes_applet_LDADD =     \
        $(GNOME_APPLETS_LIBS)   \
@@ -44,10 +45,15 @@ builder_DATA = $(builder_files)
 uidir = $(pkgdatadir)/ui
 ui_DATA = $(ui_files)
 
-schemasdir = @GCONF_SCHEMA_FILE_DIR@
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+ INTLTOOL_XML_NOMERGE_RULE@
 
- INTLTOOL_SCHEMAS_RULE@
+gsettings_schemas_in = $(gsettings_schemas_in_in:.xml.in.in=.xml.in)
+gsettings_SCHEMAS = $(gsettings_schemas_in:.xml.in=.xml)
+
+%.gschema.xml.in: %.gschema.xml.in.in Makefile
+       $(AM_V_GEN) $(SED) -e 's^\ GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@
+
+ GSETTINGS_RULES@
 
 appletdir   = $(LIBPANEL_APPLET_DIR)
 applet_DATA = $(applet_in_files:.panel-applet.in=.panel-applet)
@@ -68,16 +74,15 @@ org.gnome.panel.applet.StickyNotesAppletFactory.service: $(service_in_files)
             -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
             $< > $@
 
-CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) $(schemas_DATA)
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) \
+       $(gsettings_SCHEMAS_in) \
+       $(gsettings_SCHEMAS) \
+       *.gschema.valid
 
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
-       GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
-       $(GCONFTOOL) --makefile-install-rule $(schemas_DATA)
-endif
 endif
 
 EXTRA_DIST = \
+       $(gsettings_schemas_in_in) \
             $(builder_files) \
             $(ui_files) \
             $(schemas_in_files) \
diff --git a/stickynotes/gsettings.h b/stickynotes/gsettings.h
new file mode 100644
index 0000000..fb5052a
--- /dev/null
+++ b/stickynotes/gsettings.h
@@ -0,0 +1,21 @@
+#ifndef STICKYNOTES_GSETTINGS_H
+#define STICKYNOTES_GSETTINGS_H
+
+#define STICKYNOTES_SCHEMA "org.gnome.gnome-applets.stickynotes"
+
+#define KEY_DEFAULT_WIDTH      "default-width"
+#define KEY_DEFAULT_HEIGHT     "default-height"
+#define KEY_DEFAULT_COLOR      "default-color"
+#define KEY_DEFAULT_FONT_COLOR "default-font-color"
+#define KEY_DEFAULT_FONT       "default-font"
+
+#define KEY_STICKY           "sticky"
+#define KEY_LOCKED           "locked"
+#define KEY_DATE_FORMAT      "date-format"
+#define KEY_USE_SYSTEM_COLOR "use-system-color"
+#define KEY_USE_SYSTEM_FONT  "use-system-font"
+#define KEY_FORCE_DEFAULT    "force-default"
+#define KEY_DESKTOP_HIDE     "desktop-hide"
+#define KEY_CONFIRM_DELETION "confirm-deletion"
+
+#endif
diff --git a/stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in.in 
b/stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in.in
new file mode 100644
index 0000000..d86e85b
--- /dev/null
+++ b/stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in.in
@@ -0,0 +1,69 @@
+<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+       <schema id="org.gnome.gnome-applets.stickynotes">
+               <key name="default-width" type="i">
+                       <default>100</default>
+                       <_summary>Default width for new notes</_summary>
+                       <_description>Default width for new sticky notes in pixels.</_description>
+               </key>
+               <key name="default-height" type="i">
+                       <default>100</default>
+                       <_summary>Default height for new notes</_summary>
+                       <_description>Default height for new notes</_description>
+               </key>
+               <key name="default-color" type="s">
+                       <default>'rgb(236,248,51)'</default>
+                       <_summary>Default color for new notes</_summary>
+                       <_description>Default color for new sticky notes. This can be standard name, 
hexadecimal value, RGB color or RGBA color.</_description>
+               </key>
+               <key name="default-font-color" type="s">
+                       <default>'rgb(0,0,0)'</default>
+                       <_summary>Default color for font</_summary>
+                       <_description>Default font color for new sticky notes.This can be standard name, 
hexadecimal value, RGB color or RGBA color.</_description>
+               </key>
+               <key name="default-font" type="s">
+                       <default>'Sans 10'</default>
+                       <_summary>Default font for new notes</_summary>
+                       <_description>Default font for new sticky notes. This should be a Pango Font Name, 
for example "Sans Italic 10".</_description>
+               </key>
+               <key name="sticky" type="b">
+                       <default>true</default>
+                       <_summary>Sticky notes' workspace stickyness</_summary>
+                       <_description>Specifies whether the sticky notes are visible on ALL workspaces on the 
desktop, or not.</_description>
+               </key>
+               <key name="locked" type="b">
+                       <default>false</default>
+                       <_summary>Sticky notes' locked state</_summary>
+                       <_description>Specifies whether the sticky notes are locked (non-editable) or 
not.</_description>
+               </key>
+               <key name="date-format" type="s">
+                       <default>'%x'</default>
+                       <_summary>Date format of note's title</_summary>
+                       <_description>By default, sticky notes are given the current date as the title when 
they are created. This format is used; anything that can be parsed by strftime() is valid.</_description>
+               </key>
+               <key name="use-system-color" type="b">
+                       <default>true</default>
+                       <_summary>Whether to use the default system color</_summary>
+                       <_description>If this option is disabled, a custom color can be used as the default 
color for all sticky notes.</_description>
+               </key>
+               <key name="use-system-font" type="b">
+                       <default>true</default>
+                       <_summary>Whether to use the default system font</_summary>
+                       <_description>If this option is disabled, a custom font can be used as the default 
font for all sticky notes.</_description>
+               </key>
+               <key name="force-default" type="b">
+                       <default>false</default>
+                       <_summary>Whether to force the default color and font on all notes</_summary>
+                       <_description>If this option is enabled, the custom colors and fonts that have been 
assigned to individual notes will be ignored.</_description>
+               </key>
+               <key name="desktop-hide" type="b">
+                       <default>true</default>
+                       <_summary>Whether to hide all notes when the desktop is selected</_summary>
+                       <_description>If this option is enabled, selecting the desktop in any way will 
automatically hide all the open notes.</_description>
+               </key>
+               <key name="confirm-deletion" type="b">
+                       <default>true</default>
+                       <_summary>Whether to ask for confirmation when deleting a note</_summary>
+                       <_description>Empty notes are always deleted without confirmation.</_description>
+               </key>
+       </schema>
+</schemalist>
diff --git a/stickynotes/stickynotes.c b/stickynotes/stickynotes.c
index c1b10f4..2436acf 100644
--- a/stickynotes/stickynotes.c
+++ b/stickynotes/stickynotes.c
@@ -29,6 +29,7 @@
 #include "stickynotes_callbacks.h"
 #include "util.h"
 #include "stickynotes_applet.h"
+#include "gsettings.h"
 
 /* Stop gcc complaining about xmlChar's signedness */
 #define XML_CHAR(str) ((xmlChar *) (str))
@@ -169,16 +170,13 @@ stickynote_new_aux (GdkScreen *screen, gint x, gint y, gint w, gint h)
        note->h = h;
 
        /* Customize the window */
-       if (gconf_client_get_bool(stickynotes->gconf,
-                               GCONF_PATH "/settings/sticky", NULL))
+       if (g_settings_get_boolean (stickynotes->settings, KEY_STICKY))
                gtk_window_stick(GTK_WINDOW(note->w_window));
 
        if (w == 0 || h == 0)
                gtk_window_resize (GTK_WINDOW(note->w_window),
-                               gconf_client_get_int(stickynotes->gconf,
-                                       GCONF_PATH "/defaults/width", NULL),
-                               gconf_client_get_int(stickynotes->gconf,
-                                       GCONF_PATH "/defaults/height", NULL));
+                               g_settings_get_int (stickynotes->settings, KEY_DEFAULT_WIDTH),
+                               g_settings_get_int (stickynotes->settings, KEY_DEFAULT_HEIGHT));
        else
                gtk_window_resize (GTK_WINDOW(note->w_window),
                                note->w,
@@ -319,8 +317,7 @@ void stickynote_free(StickyNote *note)
 /* Change the sticky note title and color */
 void stickynote_change_properties (StickyNote *note)
 {
-       GdkColor color;
-       GdkColor font_color;
+       GdkRGBA color, font_color;
        char *color_str = NULL;
 
        gtk_entry_set_text(GTK_ENTRY(note->w_entry),
@@ -333,34 +330,28 @@ void stickynote_change_properties (StickyNote *note)
                color_str = g_strdup (note->color);
        else
        {
-               color_str = gconf_client_get_string (
-                                   stickynotes->gconf,
-                                   GCONF_PATH "/defaults/color", NULL);
+               color_str = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_COLOR);
        }
 
-       if (color_str)
+       if (!IS_STRING_EMPTY (color_str))
        {
-               gdk_color_parse (color_str, &color);
+               gdk_rgba_parse (&color, color_str);
                g_free (color_str);
-               gtk_color_button_set_color (GTK_COLOR_BUTTON (note->w_color),
-                                   &color);
+               gtk_color_button_set_rgba (GTK_COLOR_BUTTON (note->w_color), &color);
        }
 
        if (note->font_color)
                color_str = g_strdup (note->font_color);
        else
        {
-               color_str = gconf_client_get_string (
-                                   stickynotes->gconf,
-                                   GCONF_PATH "/defaults/font_color", NULL);
+               color_str = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_FONT_COLOR);
        }
 
-       if (color_str)
+       if (!IS_STRING_EMPTY (color_str))
        {
-               gdk_color_parse (color_str, &font_color);
+               gdk_rgba_parse (&font_color, color_str);
                g_free (color_str);
-               gtk_color_button_set_color (GTK_COLOR_BUTTON (note->w_font_color),
-                                   &font_color);
+               gtk_color_button_set_rgba (GTK_COLOR_BUTTON (note->w_font_color), &font_color);
        }
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(note->w_def_font),
@@ -398,9 +389,11 @@ void stickynote_set_title(StickyNote *note, const gchar *title)
        /* If title is NULL, use the current date as the title. */
        if (!title) {
                gchar *date_title, *tmp;
-               gchar *date_format = gconf_client_get_string(stickynotes->gconf, GCONF_PATH 
"/settings/date_format", NULL);
-               if (!date_format)
+               gchar *date_format = g_settings_get_string (stickynotes->settings, KEY_DATE_FORMAT);
+               if (IS_STRING_EMPTY (date_format)) {
+                       g_free (date_format);
                        date_format = g_strdup ("%x");
+               }
                tmp = get_current_date (date_format);
                date_title = g_locale_to_utf8 (tmp, -1, NULL, NULL, NULL);
 
@@ -425,6 +418,7 @@ stickynote_set_color (StickyNote  *note,
                      gboolean     save)
 {
        char *color_str_actual, *font_color_str_actual;
+       gboolean force_default, use_system_color;
        GtkRcStyle *rc_style;
 
        if (save) {
@@ -448,33 +442,27 @@ stickynote_set_color (StickyNote  *note,
                                note->color != NULL);
        }
 
+       force_default = g_settings_get_boolean (stickynotes->settings, KEY_FORCE_DEFAULT);
+       use_system_color = g_settings_get_boolean (stickynotes->settings, KEY_USE_SYSTEM_COLOR);
+
        /* If "force_default" is enabled or color_str is NULL,
         * then we use the default color instead of color_str. */
-       if (!color_str || gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default", NULL))
+       if (!color_str || force_default)
        {
-               if (gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_color", NULL))
+               if (use_system_color)
                        color_str_actual = NULL;
                else
-                       color_str_actual = gconf_client_get_string (
-                                       stickynotes->gconf,
-                                       GCONF_PATH "/defaults/color", NULL);
+                       color_str_actual = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_COLOR);
        }
        else
                color_str_actual = g_strdup (color_str);
 
-       if (!font_color_str || gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default", NULL))
+       if (!font_color_str || force_default)
        {
-               if (gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_color", NULL))
+               if (use_system_color)
                        font_color_str_actual = NULL;
                else
-                       font_color_str_actual = gconf_client_get_string (
-                                       stickynotes->gconf,
-                                       GCONF_PATH "/defaults/font_color",
-                                       NULL);
+                       font_color_str_actual = g_settings_get_string (stickynotes->settings, 
KEY_DEFAULT_FONT_COLOR);
        }
        else
                font_color_str_actual = g_strdup (font_color_str);
@@ -484,19 +472,22 @@ stickynote_set_color (StickyNote  *note,
        /* Do not use custom colors if "use_system_color" is enabled */
        if (color_str_actual) {
                /* Custom colors */
+               GdkRGBA color;
                GdkColor colors[6];
 
                /* Make 4 shades of the color, getting darker from the
                 * original, plus black and white */
                gint i;
 
+               gdk_rgba_parse (&color, color_str_actual);
+
                for (i = 0; i <= 3; i++)
                {
                        gdk_color_parse (color_str_actual, &colors[i]);
 
-                       colors[i].red = (colors[i].red * (10 - i)) / 10;
-                       colors[i].green = (colors[i].green * (10 - i)) / 10;
-                       colors[i].blue = (colors[i].blue * (10 - i)) / 10;
+                       colors[i].red = (color.red * (10 - i)) / 10;
+                       colors[i].green = (color.green * (10 - i)) / 10;
+                       colors[i].blue = (color.blue * (10 - i)) / 10;
                }
                gdk_color_parse ("black", &colors[4]);
                gdk_color_parse ("white", &colors[5]);
@@ -535,9 +526,14 @@ stickynote_set_color (StickyNote  *note,
 
        if (font_color_str_actual)
        {
+               GdkRGBA color;
                GdkColor font_color;
 
-               gdk_color_parse (font_color_str_actual, &font_color);
+               gdk_rgba_parse (&color, font_color_str_actual);
+
+               font_color.red = color.red;
+               font_color.green = color.green;
+               font_color.blue = color.blue;
 
                gtk_widget_modify_text (note->w_window,
                                GTK_STATE_NORMAL, &font_color);
@@ -583,17 +579,12 @@ stickynote_set_font (StickyNote *note, const gchar *font_str, gboolean save)
 
        /* If "force_default" is enabled or font_str is NULL,
         * then we use the default font instead of font_str. */
-       if (!font_str || gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default", NULL))
+       if (!font_str || g_settings_get_boolean (stickynotes->settings, KEY_FORCE_DEFAULT))
        {
-               if (gconf_client_get_bool (stickynotes->gconf,
-                                       GCONF_PATH "/settings/use_system_font",
-                                       NULL))
+               if (g_settings_get_boolean (stickynotes->settings, KEY_USE_SYSTEM_FONT))
                        font_str_actual = NULL;
                else
-                       font_str_actual = gconf_client_get_string (
-                                       stickynotes->gconf,
-                                       GCONF_PATH "/defaults/font", NULL);
+                       font_str_actual = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_FONT);
        }
        else
                font_str_actual = g_strdup (font_str);
@@ -651,8 +642,7 @@ stickynote_set_visible (StickyNote *note, gboolean visible)
                        gtk_window_move (GTK_WINDOW (note->w_window),
                                        note->x, note->y);
                /* Put the note on all workspaces if necessary. */
-               if (gconf_client_get_bool(stickynotes->gconf,
-                                       GCONF_PATH "/settings/sticky", NULL))
+               if (g_settings_get_boolean (stickynotes->settings, KEY_STICKY))
                        gtk_window_stick(GTK_WINDOW(note->w_window));
                else if (note->workspace > 0)
                {
@@ -718,7 +708,7 @@ void stickynotes_remove(StickyNote *note)
        gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(note->w_window));
 
        if (stickynote_get_empty(note)
-           || !gconf_client_get_bool(stickynotes->gconf, GCONF_PATH "/settings/confirm_deletion", NULL)
+           || !g_settings_get_boolean (stickynotes->settings, KEY_CONFIRM_DELETION)
            || gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
                stickynote_free(note);
 
@@ -777,8 +767,7 @@ stickynotes_save_now (void)
                xid = GDK_WINDOW_XID (gtk_widget_get_window (note->w_window));
                wnck_win = wnck_window_get (xid);
 
-               if (!gconf_client_get_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/sticky", NULL) &&
+               if (!g_settings_get_boolean (stickynotes->settings, KEY_STICKY) &&
                        wnck_win)
                        note->workspace = 1 +
                                wnck_workspace_get_number (
diff --git a/stickynotes/stickynotes_applet.c b/stickynotes/stickynotes_applet.c
index 0a13a3b..12e0834 100644
--- a/stickynotes/stickynotes_applet.c
+++ b/stickynotes/stickynotes_applet.c
@@ -22,6 +22,7 @@
 #include "stickynotes_applet.h"
 #include "stickynotes_applet_callbacks.h"
 #include "stickynotes.h"
+#include "gsettings.h"
 
 #include <gtk/gtk.h>
 
@@ -141,6 +142,7 @@ stickynotes_applet_init (PanelApplet *panel_applet)
 
        stickynotes->notes = NULL;
        stickynotes->applets = NULL;
+       stickynotes->settings = panel_applet_settings_new (panel_applet, STICKYNOTES_SCHEMA);
        stickynotes->last_timeout_data = 0;
 
        g_set_application_name (_("Sticky Notes"));
@@ -164,21 +166,13 @@ stickynotes_applet_init (PanelApplet *panel_applet)
                        gdk_pixbuf_get_height (stickynotes->icon_normal));
        stickynotes_make_prelight_icon (stickynotes->icon_prelight,
                        stickynotes->icon_normal, 30);
-       stickynotes->gconf = gconf_client_get_default();
        stickynotes->visible = TRUE;
 
        stickynotes_applet_init_icons();
        stickynotes_applet_init_prefs();
 
-       /* Watch GConf values */
-       gconf_client_add_dir (stickynotes->gconf, GCONF_PATH,
-                       GCONF_CLIENT_PRELOAD_NONE, NULL);
-       gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/defaults",
-                       (GConfClientNotifyFunc) preferences_apply_cb,
-                       NULL, NULL, NULL);
-       gconf_client_notify_add (stickynotes->gconf, GCONF_PATH "/settings",
-                       (GConfClientNotifyFunc) preferences_apply_cb,
-                       NULL, NULL, NULL);
+       g_signal_connect (stickynotes->settings, "changed",
+                         G_CALLBACK (preferences_apply_cb), NULL);
 
        /* Max height for large notes*/
        stickynotes->max_height = 0.8*gdk_screen_get_height( gdk_screen_get_default() );
@@ -289,8 +283,7 @@ void stickynotes_applet_init_prefs(void)
                g_object_unref(group);
        }
 
-       if (!gconf_client_key_is_writable(stickynotes->gconf,
-                               GCONF_PATH "/defaults/width", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_WIDTH))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                        stickynotes->builder, "width_label")),
@@ -299,8 +292,7 @@ void stickynotes_applet_init_prefs(void)
                                        stickynotes->builder, "width_spin")),
                                FALSE);
        }
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/height", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_HEIGHT))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                        stickynotes->builder, "height_label")),
@@ -309,16 +301,14 @@ void stickynotes_applet_init_prefs(void)
                                        stickynotes->builder, "height_spin")),
                                FALSE);
        }
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/color", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_COLOR))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                        stickynotes->builder, "prefs_color_label")),
                                FALSE);
                gtk_widget_set_sensitive (stickynotes->w_prefs_color, FALSE);
        }
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/font_color", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_FONT_COLOR))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                        stickynotes->builder, "prefs_font_color_label")),
@@ -326,27 +316,22 @@ void stickynotes_applet_init_prefs(void)
                gtk_widget_set_sensitive (stickynotes->w_prefs_font_color,
                                FALSE);
        }
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_color", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_USE_SYSTEM_COLOR))
                gtk_widget_set_sensitive (stickynotes->w_prefs_sys_color,
                                FALSE);
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/font", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_FONT))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                        stickynotes->builder, "prefs_font_label")),
                                FALSE);
                gtk_widget_set_sensitive (stickynotes->w_prefs_font, FALSE);
        }
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_font", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_USE_SYSTEM_FONT))
                gtk_widget_set_sensitive (stickynotes->w_prefs_sys_font,
                                FALSE);
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/sticky", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_STICKY))
                gtk_widget_set_sensitive (stickynotes->w_prefs_sticky, FALSE);
-       if (!gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default", NULL))
+       if (!g_settings_is_writable (stickynotes->settings, KEY_FORCE_DEFAULT))
                gtk_widget_set_sensitive (stickynotes->w_prefs_force, FALSE);
 
        stickynotes_applet_update_prefs();
@@ -462,55 +447,46 @@ void stickynotes_applet_update_icon(StickyNotesApplet *applet)
 void
 stickynotes_applet_update_prefs (void)
 {
-       int height;
+       gint width, height;
        gboolean sys_color, sys_font, sticky, force_default, desktop_hide;
        char *font_str;
        char *color_str, *font_color_str;
-       GdkColor color, font_color;
-
-       gint width = gconf_client_get_int(stickynotes->gconf,
-                       GCONF_PATH "/defaults/width", NULL);
+       GdkRGBA color, font_color;
 
+       width = g_settings_get_int (stickynotes->settings, KEY_DEFAULT_WIDTH);
        width = MAX (width, 1);
-       height = gconf_client_get_int (stickynotes->gconf,
-                       GCONF_PATH "/defaults/height", NULL);
+
+       height = g_settings_get_int (stickynotes->settings, KEY_DEFAULT_HEIGHT);
        height = MAX (height, 1);
 
-       sys_color = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/use_system_color", NULL);
-       sys_font = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/use_system_font", NULL);
-       sticky = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/sticky", NULL);
-       force_default = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/force_default", NULL);
-       font_str = gconf_client_get_string (stickynotes->gconf,
-                       GCONF_PATH "/defaults/font", NULL);
-       desktop_hide = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/desktop_hide", NULL);
-
-       if (!font_str)
-       {
+       sys_color = g_settings_get_boolean (stickynotes->settings, KEY_USE_SYSTEM_COLOR);
+       sys_font = g_settings_get_boolean (stickynotes->settings, KEY_USE_SYSTEM_FONT);
+       sticky = g_settings_get_boolean (stickynotes->settings, KEY_STICKY);
+       force_default = g_settings_get_boolean (stickynotes->settings, KEY_FORCE_DEFAULT);
+       desktop_hide = g_settings_get_boolean (stickynotes->settings, KEY_DESKTOP_HIDE);
+
+       font_str = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_FONT);
+       if (IS_STRING_EMPTY (font_str)) {
+               g_free (font_str);
                font_str = g_strdup ("Sans 10");
        }
 
-       color_str = gconf_client_get_string (stickynotes->gconf,
-                       GCONF_PATH "/defaults/color", NULL);
-       if (!color_str)
-       {
+       color_str = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_COLOR);
+       if (IS_STRING_EMPTY (color_str)) {
+               g_free (color_str);
                color_str = g_strdup ("#ECF833");
        }
-       font_color_str = gconf_client_get_string (stickynotes->gconf,
-                       GCONF_PATH "/defaults/font_color", NULL);
-       if (!font_color_str)
-       {
+
+       font_color_str = g_settings_get_string (stickynotes->settings, KEY_DEFAULT_FONT_COLOR);
+       if (IS_STRING_EMPTY (font_color_str)) {
+               g_free (font_color_str);
                font_color_str = g_strdup ("#000000");
        }
 
-       gdk_color_parse (color_str, &color);
+       gdk_rgba_parse (&color, color_str);
        g_free (color_str);
 
-       gdk_color_parse (font_color_str, &font_color);
+       gdk_rgba_parse (&font_color, font_color_str);
        g_free (font_color_str);
 
        gtk_adjustment_set_value (stickynotes->w_prefs_width, width);
@@ -531,17 +507,13 @@ stickynotes_applet_update_prefs (void)
                        GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop),
                        desktop_hide);
 
-       gtk_color_button_set_color (
-                       GTK_COLOR_BUTTON (stickynotes->w_prefs_color), &color);
-       gtk_color_button_set_color (
-                       GTK_COLOR_BUTTON (stickynotes->w_prefs_font_color),
-                       &font_color);
+       gtk_color_button_set_rgba (GTK_COLOR_BUTTON (stickynotes->w_prefs_color), &color);
+       gtk_color_button_set_rgba (GTK_COLOR_BUTTON (stickynotes->w_prefs_font_color), &font_color);
        gtk_font_button_set_font_name (
                        GTK_FONT_BUTTON (stickynotes->w_prefs_font), font_str);
        g_free (font_str);
 
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/color", NULL))
+       if (g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_COLOR))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                stickynotes->builder, "prefs_color_label")),
@@ -549,8 +521,7 @@ stickynotes_applet_update_prefs (void)
                gtk_widget_set_sensitive (stickynotes->w_prefs_color,
                                !sys_color);
        }
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/prefs_font_color", NULL))
+       if (g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_FONT_COLOR))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                stickynotes->builder, "prefs_font_color_label")),
@@ -558,8 +529,7 @@ stickynotes_applet_update_prefs (void)
                gtk_widget_set_sensitive (stickynotes->w_prefs_font_color,
                                !sys_color);
        }
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/font", NULL))
+       if (g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_FONT))
        {
                gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (
                                stickynotes->builder, "prefs_font_label")),
@@ -574,14 +544,14 @@ void stickynotes_applet_update_menus(void)
        GList *l;
        gboolean inconsistent = FALSE;
 
-       gboolean locked = gconf_client_get_bool(stickynotes->gconf, GCONF_PATH "/settings/locked", NULL);
-       gboolean locked_writable = gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH 
"/settings/locked", NULL);
+       gboolean locked = g_settings_get_boolean (stickynotes->settings, KEY_LOCKED);
+       gboolean locked_writable = g_settings_is_writable (stickynotes->settings, KEY_LOCKED);
 
        for (l = stickynotes->notes; l != NULL; l = l->next) {
                StickyNote *note = l->data;
-
                if (note->locked != locked) {
                        inconsistent = TRUE;
+
                        break;
                }
        }
diff --git a/stickynotes/stickynotes_applet.h b/stickynotes/stickynotes_applet.h
index 779491f..c14eac0 100644
--- a/stickynotes/stickynotes_applet.h
+++ b/stickynotes/stickynotes_applet.h
@@ -25,12 +25,11 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gtk/gtk.h>
 #include <panel-applet.h>
-#include <gconf/gconf-client.h>
 
+#define IS_STRING_EMPTY(x) ((x) == NULL || (x)[0] == '\0')
 
-#define GCONF_PATH     "/apps/stickynotes_applet"
 #define BUILDER_PATH   GTK_BUILDERDIR "/stickynotes.ui"
-#define XML_PATH       "/.gnome2/stickynotes_applet"
+#define XML_PATH       "/.config/gnome-applets/stickynotes"
 #define ICON_PATH      STICKYNOTES_ICONDIR
 
 #define STICKYNOTES_STOCK_LOCKED       "stickynotes-stock-locked"
@@ -62,7 +61,7 @@ typedef struct
        GdkPixbuf *icon_normal;         /* Normal applet icon */
        GdkPixbuf *icon_prelight;       /* Prelighted applet icon */
 
-       GConfClient *gconf;             /* GConf Client */
+       GSettings *settings;
 
        gint max_height;
        guint last_timeout_data;
diff --git a/stickynotes/stickynotes_applet_callbacks.c b/stickynotes/stickynotes_applet_callbacks.c
index 2aa8aaf..fb74e4a 100644
--- a/stickynotes/stickynotes_applet_callbacks.c
+++ b/stickynotes/stickynotes_applet_callbacks.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include "stickynotes_applet_callbacks.h"
 #include "stickynotes.h"
+#include "gsettings.h"
 #include <gdk/gdkkeysyms.h>
 #include <X11/Xatom.h>
 #include <gdk/gdkx.h>
@@ -142,8 +143,7 @@ static GdkFilterReturn desktop_window_event_filter (GdkXEvent *xevent,
                                                    GdkEvent  *event,
                                                    gpointer   data)
 {
-       gboolean desktop_hide = gconf_client_get_bool (stickynotes->gconf,
-                       GCONF_PATH "/settings/desktop_hide", NULL);
+       gboolean desktop_hide = g_settings_get_boolean (stickynotes->settings, KEY_DESKTOP_HIDE);
        if (desktop_hide  &&
            (((XEvent*)xevent)->xany.type == PropertyNotify) &&
            (((XEvent*)xevent)->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WM_USER_TIME"))) {
@@ -324,8 +324,8 @@ void menu_toggle_lock_cb(GtkAction *action, StickyNotesApplet *applet)
 {
        gboolean locked = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
-       if (gconf_client_key_is_writable(stickynotes->gconf, GCONF_PATH "/settings/locked", NULL))
-               gconf_client_set_bool(stickynotes->gconf, GCONF_PATH "/settings/locked", locked, NULL);
+       if (g_settings_is_writable (stickynotes->settings, KEY_LOCKED))
+               g_settings_set_boolean (stickynotes->settings, KEY_LOCKED, locked);
 }
 
 /* Menu Callback : Configure preferences */
@@ -402,67 +402,37 @@ preferences_save_cb (gpointer data)
        gboolean desktop_hide = gtk_toggle_button_get_active (
                        GTK_TOGGLE_BUTTON (stickynotes->w_prefs_desktop));
 
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/width", NULL))
-               gconf_client_set_int (stickynotes->gconf,
-                               GCONF_PATH "/defaults/width", width, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/defaults/height", NULL))
-               gconf_client_set_int (stickynotes->gconf,
-                               GCONF_PATH "/defaults/height", height, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_color", NULL))
-               gconf_client_set_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_color",
-                               sys_color, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_font", NULL))
-               gconf_client_set_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/use_system_font",
-                               sys_font, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/sticky", NULL))
-               gconf_client_set_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/sticky", sticky, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default", NULL))
-               gconf_client_set_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/force_default",
-                               force_default, NULL);
-       if (gconf_client_key_is_writable (stickynotes->gconf,
-                               GCONF_PATH "/settings/desktop_hide", NULL))
-               gconf_client_set_bool (stickynotes->gconf,
-                               GCONF_PATH "/settings/desktop_hide",
-                               desktop_hide, NULL);
+       if (g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_WIDTH))
+               g_settings_set_int (stickynotes->settings, KEY_DEFAULT_WIDTH, width);
+       if (g_settings_is_writable (stickynotes->settings, KEY_DEFAULT_HEIGHT))
+               g_settings_set_int (stickynotes->settings, KEY_DEFAULT_HEIGHT, height);
+       if (g_settings_is_writable (stickynotes->settings, KEY_USE_SYSTEM_COLOR))
+               g_settings_set_boolean (stickynotes->settings, KEY_USE_SYSTEM_COLOR, sys_color);
+       if (g_settings_is_writable (stickynotes->settings, KEY_USE_SYSTEM_FONT))
+               g_settings_set_boolean (stickynotes->settings, KEY_USE_SYSTEM_FONT, sys_font);
+       if (g_settings_is_writable (stickynotes->settings, KEY_STICKY))
+               g_settings_set_boolean (stickynotes->settings, KEY_STICKY, sticky);
+       if (g_settings_is_writable (stickynotes->settings, KEY_FORCE_DEFAULT))
+               g_settings_set_boolean (stickynotes->settings, KEY_FORCE_DEFAULT, force_default);
+       if (g_settings_is_writable (stickynotes->settings, KEY_DESKTOP_HIDE))
+               g_settings_set_boolean (stickynotes->settings, KEY_DESKTOP_HIDE, desktop_hide);
 }
 
 /* Preferences Callback : Change color. */
 void
 preferences_color_cb (GtkWidget *button, gpointer data)
 {
-       GdkColor color, font_color;
+       GdkRGBA color, font_color;
        char *color_str, *font_color_str;
 
-       gtk_color_button_get_color (
-                       GTK_COLOR_BUTTON (stickynotes->w_prefs_color), &color);
-       gtk_color_button_get_color (
-                       GTK_COLOR_BUTTON (stickynotes->w_prefs_font_color),
-                       &font_color);
-
-       color_str = g_strdup_printf ("#%.2x%.2x%.2x",
-                       color.red / 256,
-                       color.green / 256,
-                       color.blue / 256);
-       font_color_str = g_strdup_printf ("#%.2x%.2x%.2x",
-                       font_color.red / 256,
-                       font_color.green / 256,
-                       font_color.blue / 256);
-
-       gconf_client_set_string (stickynotes->gconf,
-                       GCONF_PATH "/defaults/color", color_str, NULL);
-       gconf_client_set_string (stickynotes->gconf,
-                       GCONF_PATH "/defaults/font_color", font_color_str,
-                       NULL);
+       gtk_color_button_get_rgba (GTK_COLOR_BUTTON (stickynotes->w_prefs_color), &color);
+       gtk_color_button_get_rgba (GTK_COLOR_BUTTON (stickynotes->w_prefs_font_color), &font_color);
+
+       color_str = gdk_rgba_to_string (&color);
+       font_color_str = gdk_rgba_to_string (&font_color);
+
+       g_settings_set_string (stickynotes->settings, KEY_DEFAULT_COLOR, color_str);
+       g_settings_set_string (stickynotes->settings, KEY_DEFAULT_FONT_COLOR, font_color_str);
 
        g_free (color_str);
        g_free (font_color_str);
@@ -474,19 +444,20 @@ void preferences_font_cb (GtkWidget *button, gpointer data)
        const char *font_str;
 
        font_str = gtk_font_button_get_font_name (GTK_FONT_BUTTON (button));
-       gconf_client_set_string(stickynotes->gconf,
-                       GCONF_PATH "/defaults/font", font_str, NULL);
+       g_settings_set_string (stickynotes->settings, KEY_DEFAULT_FONT, font_str);
 }
 
 /* Preferences Callback : Apply to existing notes. */
-void preferences_apply_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data)
+void preferences_apply_cb (GSettings   *settings,
+                           const gchar *key,
+                           gpointer     user_data)
 {
        GList *l;
        StickyNote *note;
 
-       if (!strcmp (entry->key, GCONF_PATH "/settings/sticky"))
+       if (!strcmp (key, KEY_STICKY))
        {
-               if (gconf_value_get_bool(entry->value))
+               if (g_settings_get_boolean (settings, key))
                        for (l = stickynotes->notes; l; l = l->next)
                        {
                                note = l->data;
@@ -501,20 +472,18 @@ void preferences_apply_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry,
                        }
        }
 
-       else if (!strcmp (entry->key, GCONF_PATH "/settings/locked"))
+       else if (!strcmp (key, KEY_LOCKED))
        {
                for (l = stickynotes->notes; l; l = l->next)
                {
                        note = l->data;
-                       stickynote_set_locked (note,
-                                       gconf_value_get_bool (entry->value));
+                       stickynote_set_locked (note, g_settings_get_boolean (settings, key));
                }
                stickynotes_save();
        }
 
-       else if (!strcmp (entry->key,
-                               GCONF_PATH "/settings/use_system_color") ||
-                !strcmp (entry->key, GCONF_PATH "/defaults/color"))
+       else if (!strcmp (key, KEY_USE_SYSTEM_COLOR) ||
+                !strcmp (key, KEY_DEFAULT_COLOR))
        {
                for (l = stickynotes->notes; l; l = l->next)
                {
@@ -525,8 +494,8 @@ void preferences_apply_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry,
                }
        }
 
-       else if (!strcmp (entry->key, GCONF_PATH "/settings/use_system_font") ||
-                !strcmp (entry->key, GCONF_PATH "/defaults/font"))
+       else if (!strcmp (key, KEY_USE_SYSTEM_FONT) ||
+                !strcmp (key, KEY_DEFAULT_FONT))
        {
                for (l = stickynotes->notes; l; l = l->next)
                {
@@ -535,7 +504,7 @@ void preferences_apply_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry,
                }
        }
 
-       else if (!strcmp (entry->key, GCONF_PATH "/settings/force_default"))
+       else if (!strcmp (key, KEY_FORCE_DEFAULT))
        {
                for (l = stickynotes->notes; l; l = l->next)
                {
diff --git a/stickynotes/stickynotes_applet_callbacks.h b/stickynotes/stickynotes_applet_callbacks.h
index 95b66a4..4f5eb48 100644
--- a/stickynotes/stickynotes_applet_callbacks.h
+++ b/stickynotes/stickynotes_applet_callbacks.h
@@ -45,7 +45,7 @@ void menu_about_cb(GtkAction *action, StickyNotesApplet *applet);
 void preferences_save_cb(gpointer data);
 void preferences_color_cb (GtkWidget *button, gpointer data);
 void preferences_font_cb (GtkWidget *button, gpointer data);
-void preferences_apply_cb(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data);
+void preferences_apply_cb(GSettings *settings, const gchar *key, gpointer user_data);
 void preferences_response_cb(GtkWidget *dialog, gint response, gpointer data);
 gboolean preferences_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]