[almanah] core: Port to GSettings
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [almanah] core: Port to GSettings
- Date: Sat, 2 Apr 2011 15:29:41 +0000 (UTC)
commit fffad8ad73c17c035c1449654d9e2cc389daf248
Author: Philip Withnall <philip tecnocode co uk>
Date: Tue Jun 29 23:10:54 2010 +0100
core: Port to GSettings
Everything except the Evolution event factory has been ported. Evolution
itself hasn't yet ported to GSettings, so the Evolution event factory has
to remain using GConf for the time being.
configure.ac | 8 ++-
data/Makefile.am | 29 +++++-------
data/almanah.convert | 4 ++
data/almanah.schemas.in | 37 ---------------
data/org.gnome.almanah.gschema.xml.in.in | 20 ++++++++
po/POTFILES.in | 2 +-
src/main-window.c | 73 ++++++++++++++++++++++++++---
src/main-window.h | 4 --
src/main.c | 9 ++--
src/main.h | 8 +---
src/preferences-dialog.c | 60 ++----------------------
src/storage-manager.c | 3 +-
12 files changed, 119 insertions(+), 138 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 14b727a..5f5f583 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,7 @@ AC_PROG_CXX
AM_PROG_CC_C_O
LT_INIT([])
PKG_PROG_PKG_CONFIG
-AM_GCONF_SOURCE_2
+GLIB_GSETTINGS
AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
@@ -78,13 +78,14 @@ dnl Dependencies
dnl ***************************************************************************
dnl Required dependencies
-PKG_CHECK_MODULES(STANDARD, glib-2.0 gtk+-3.0 >= 2.14 gmodule-2.0 gthread-2.0 gio-2.0 sqlite3 cairo gconf-2.0 atk)
+PKG_CHECK_MODULES(STANDARD, glib-2.0 gtk+-3.0 >= 2.14 gmodule-2.0 gthread-2.0 gio-2.0 >= 2.25.0 sqlite3 cairo atk)
AC_SUBST(STANDARD_CFLAGS)
AC_SUBST(STANDARD_LIBS)
dnl Evolution
-PKG_CHECK_MODULES(EVO, libecal-1.2 libedataserver-1.2 libedataserverui-3.0, have_evo=yes, have_evo=no)
+PKG_CHECK_MODULES(EVO, libecal-1.2 libedataserver-1.2 libedataserverui-3.0 gconf-2.0, have_evo=yes, have_evo=no)
if test "x$have_evo" = "xyes"; then
+ AM_GCONF_SOURCE_2
AC_DEFINE(HAVE_EVO, 1, [Defined if libecal-1.2 is installed])
fi
AM_CONDITIONAL([HAVE_EVO], [test x$have_evo = xyes])
@@ -165,5 +166,6 @@ data/icons/16x16/Makefile
data/icons/22x22/Makefile
data/icons/32x32/Makefile
data/icons/48x48/Makefile
+data/org.gnome.almanah.gschema.xml.in
])
AC_OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
index baead9f..4acfc31 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -30,30 +30,22 @@ ui_DATA = almanah.ui
@INTLTOOL_DESKTOP_RULE@
-desktop_in_files = almanah.desktop.in
desktopdir = $(datadir)/applications
+desktop_in_files = almanah.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
###############################################################################
-# GConf schemas
+# GSettings schemas
###############################################################################
- INTLTOOL_SCHEMAS_RULE@
+gsettings_SCHEMAS = org.gnome.almanah.gschema.xml
-schemasdir = $(GCONF_SCHEMA_FILE_DIR)
-schemas_in_files = almanah.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
+ GSETTINGS_RULES@
+ INTLTOOL_XML_NOMERGE_RULE@
-install-data-local:
-if GCONF_SCHEMAS_INSTALL
- @GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) gconftool-2 \
- --makefile-install-rule $(schemas_DATA) || \
- (echo ;\
- echo "*****************************************************"; \
- echo "Installation of schemas failed: install them manually"; \
- echo "*****************************************************";)
- @true
-endif
+# Data migration tool
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = almanah.convert
###############################################################################
# General
@@ -62,9 +54,10 @@ endif
EXTRA_DIST = \
$(ui_DATA) \
$(desktop_in_files) \
- $(schemas_in_files)
+ $(schemas_in_files) \
+ $(convert_DATA)
CLEANFILES = \
$(desktop_DATA) \
- $(schemas_DATA)
+ $(gsettings_SCHEMAS)
-include $(top_srcdir)/git.mk
diff --git a/data/almanah.convert b/data/almanah.convert
new file mode 100644
index 0000000..4afd660
--- /dev/null
+++ b/data/almanah.convert
@@ -0,0 +1,4 @@
+[org.gnome.almanah]
+encryption-key = /apps/almanah/encryption_key
+spelling-language = /apps/almanah/spelling_language
+spell-checking-enabled = /apps/almanah/spell_checking_enabled
diff --git a/data/org.gnome.almanah.gschema.xml.in.in b/data/org.gnome.almanah.gschema.xml.in.in
new file mode 100644
index 0000000..241c279
--- /dev/null
+++ b/data/org.gnome.almanah.gschema.xml.in.in
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema id="org.gnome.almanah" path="/org/gnome/Almanah/" gettext-domain="@GETTEXT_PACKAGE@">
+ <key name="encryption-key" type="s">
+ <default>''</default>
+ <_summary>Database encryption key ID</_summary>
+ <_description>The ID of the key to use to encrypt and decrypt the database, if Almanah has been built with encryption support. Leave blank to disable database encryption.</_description>
+ </key>
+ <key name="spelling-language" type="s">
+ <default>''</default>
+ <_summary>Spell checking language</_summary>
+ <_description>The locale specifier of the language in which to check entry spellings.</_description>
+ </key>
+ <key name="spell-checking-enabled" type="b">
+ <default>true</default>
+ <_summary>Spell checking enabled?</_summary>
+ <_description>Whether spell checking of entries is enabled.</_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5e91fca..ef23b6c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,7 +1,7 @@
# List of source files containing translatable strings.
[encoding: UTF-8]
data/almanah.desktop.in
-data/almanah.schemas.in
+data/org.gnome.almanah.gschema.xml.in.in
[type: gettext/glade]data/almanah.ui
src/add-definition-dialog.c
src/date-entry-dialog.c
diff --git a/src/main-window.c b/src/main-window.c
index 98509d9..041c1d0 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -22,7 +22,7 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <gconf/gconf.h>
+#include <gio/gio.h>
#ifdef ENABLE_SPELL_CHECKING
#include <gtkspell/gtkspell.h>
#endif /* ENABLE_SPELL_CHECKING */
@@ -44,6 +44,9 @@
#include "widgets/calendar.h"
static void almanah_main_window_dispose (GObject *object);
+#ifdef ENABLE_SPELL_CHECKING
+static void almanah_main_window_finalize (GObject *object);
+#endif /* ENABLE_SPELL_CHECKING */
static void set_current_entry (AlmanahMainWindow *self, AlmanahEntry *entry);
static void save_window_state (AlmanahMainWindow *self);
static void restore_window_state (AlmanahMainWindow *self);
@@ -113,6 +116,10 @@ struct _AlmanahMainWindowPrivate {
AlmanahEntry *current_entry; /* whether it's been modified is stored as gtk_text_buffer_get_modified (priv->entry_buffer) */
gulong current_entry_notify_id; /* signal handler for current_entry::notify */
+
+#ifdef ENABLE_SPELL_CHECKING
+ gulong spell_checking_enabled_changed_id; /* signal handler for almanah->settings::changed::spell-checking-enabled */
+#endif /* ENABLE_SPELL_CHECKING */
};
G_DEFINE_TYPE (AlmanahMainWindow, almanah_main_window, GTK_TYPE_WINDOW)
@@ -124,6 +131,9 @@ almanah_main_window_class_init (AlmanahMainWindowClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (AlmanahMainWindowPrivate));
gobject_class->dispose = almanah_main_window_dispose;
+#ifdef ENABLE_SPELL_CHECKING
+ gobject_class->finalize = almanah_main_window_finalize;
+#endif /* ENABLE_SPELL_CHECKING */
}
static void
@@ -133,6 +143,12 @@ almanah_main_window_init (AlmanahMainWindow *self)
gtk_window_set_title (GTK_WINDOW (self), _("Almanah Diary"));
g_signal_connect (self, "delete-event", G_CALLBACK (mw_delete_event_cb), NULL);
+
+#ifdef ENABLE_SPELL_CHECKING
+ /* We don't use g_settings_bind() because enabling spell checking could fail, and we need to show an error dialogue */
+ self->priv->spell_checking_enabled_changed_id = g_signal_connect (almanah->settings, "changed::spell-checking-enabled",
+ (GCallback) spell_checking_enabled_changed_cb, self);
+#endif /* ENABLE_SPELL_CHECKING */
}
static void
@@ -144,6 +160,19 @@ almanah_main_window_dispose (GObject *object)
G_OBJECT_CLASS (almanah_main_window_parent_class)->dispose (object);
}
+#ifdef ENABLE_SPELL_CHECKING
+static void
+almanah_main_window_finalize (GObject *object)
+{
+ AlmanahMainWindowPrivate *priv = ALMANAH_MAIN_WINDOW (object)->priv;
+
+ g_signal_handler_disconnect (object, priv->spell_checking_enabled_changed_id);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (almanah_main_window_parent_class)->finalize (object);
+}
+#endif /* ENABLE_SPELL_CHECKING */
+
AlmanahMainWindow *
almanah_main_window_new (void)
{
@@ -212,8 +241,8 @@ almanah_main_window_new (void)
#ifdef ENABLE_SPELL_CHECKING
/* Set up spell checking, if it's enabled */
- if (gconf_client_get_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled", NULL) == TRUE)
- almanah_main_window_enable_spell_checking (main_window, NULL);
+ if (g_settings_get_boolean (almanah->settings, "spell-checking-enabled") == TRUE)
+ enable_spell_checking (main_window, NULL);
#endif /* ENABLE_SPELL_CHECKING */
/* Set up text formatting. It's important this is done after setting up GtkSpell, so that we know whether to
@@ -1324,8 +1353,36 @@ mw_definition_removed_cb (AlmanahStorageManager *storage_manager, const gchar *d
}
#ifdef ENABLE_SPELL_CHECKING
-gboolean
-almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **error)
+static void
+spell_checking_enabled_changed_cb (GSettings *settings, gchar *key, AlmanahMainWindow *self)
+{
+ gboolean enabled = g_settings_get_boolean (settings, "spell-checking-enabled");
+
+ if (almanah->debug)
+ g_debug ("spell_checking_enabled_changed_cb called with %u.", enabled);
+
+ if (enabled == TRUE) {
+ GError *error = NULL;
+
+ enable_spell_checking (self, &error);
+
+ if (error != NULL) {
+ GtkWidget *dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("Spelling checker could not be initialized"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ g_error_free (error);
+ }
+ } else {
+ disable_spell_checking (self);
+ }
+}
+
+static gboolean
+enable_spell_checking (AlmanahMainWindow *self, GError **error)
{
GtkSpell *gtkspell;
gchar *spelling_language;
@@ -1343,7 +1400,7 @@ almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **err
gtk_text_tag_table_remove (table, tag);
/* Get the spell checking language */
- spelling_language = gconf_client_get_string (almanah->gconf_client, "/apps/almanah/spelling_language", NULL);
+ spelling_language = g_settings_get_string (almanah->settings, "spelling-language");
/* Make sure it's either NULL or a proper locale specifier */
if (spelling_language != NULL && spelling_language[0] == '\0') {
@@ -1359,8 +1416,8 @@ almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **err
return TRUE;
}
-void
-almanah_main_window_disable_spell_checking (AlmanahMainWindow *self)
+static void
+disable_spell_checking (AlmanahMainWindow *self)
{
GtkSpell *gtkspell;
GtkTextTagTable *table;
diff --git a/src/main-window.h b/src/main-window.h
index 4067c03..71feafd 100644
--- a/src/main-window.h
+++ b/src/main-window.h
@@ -48,10 +48,6 @@ GType almanah_main_window_get_type (void);
AlmanahMainWindow *almanah_main_window_new (void);
void almanah_main_window_select_date (AlmanahMainWindow *self, GDate *date);
-#ifdef ENABLE_SPELL_CHECKING
-gboolean almanah_main_window_enable_spell_checking (AlmanahMainWindow *self, GError **error);
-void almanah_main_window_disable_spell_checking (AlmanahMainWindow *self);
-#endif /* ENABLE_SPELL_CHECKING */
G_END_DECLS
diff --git a/src/main.c b/src/main.c
index 64b3826..ec7ff7d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <gconf/gconf.h>
+#include <gio/gio.h>
#include "main.h"
#include "storage-manager.h"
@@ -49,7 +49,7 @@ storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme
}
g_object_unref (almanah->storage_manager);
- g_object_unref (almanah->gconf_client);
+ g_object_unref (almanah->settings);
g_object_unref (almanah->page_setup);
g_object_unref (almanah->print_settings);
@@ -163,9 +163,8 @@ main (int argc, char *argv[])
almanah = g_new0 (Almanah, 1);
almanah->debug = debug;
- /* Open GConf */
- almanah->gconf_client = gconf_client_get_default ();
- gconf_client_add_dir (almanah->gconf_client, "/apps/almanah", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ /* Open GSettings */
+ almanah->settings = g_settings_new ("org.gnome.almanah");
/* Ensure the DB directory exists */
if (g_file_test (g_get_user_data_dir (), G_FILE_TEST_IS_DIR) == FALSE)
diff --git a/src/main.h b/src/main.h
index ee9ab90..980e9e5 100644
--- a/src/main.h
+++ b/src/main.h
@@ -20,7 +20,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <glib.h>
-#include <gconf/gconf-client.h>
+#include <gio/gio.h>
#include "storage-manager.h"
#include "event-manager.h"
@@ -28,16 +28,12 @@
#ifndef ALMANAH_MAIN_H
#define ALMANAH_MAIN_H
-#ifdef ENABLE_ENCRYPTION
-#define ENCRYPTION_KEY_GCONF_PATH "/apps/almanah/encryption_key"
-#endif /* ENABLE_ENCRYPTION */
-
G_BEGIN_DECLS
typedef struct {
AlmanahStorageManager *storage_manager;
AlmanahEventManager *event_manager;
- GConfClient *gconf_client;
+ GSettings *settings;
GtkPrintSettings *print_settings;
GtkPageSetup *page_setup;
diff --git a/src/preferences-dialog.c b/src/preferences-dialog.c
index 6c4e1be..763b174 100644
--- a/src/preferences-dialog.c
+++ b/src/preferences-dialog.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#ifdef ENABLE_ENCRYPTION
#define LIBCRYPTUI_API_SUBJECT_TO_CHANGE
#include <cryptui-key-combo.h>
@@ -41,8 +42,6 @@ static void pd_new_key_button_clicked_cb (GtkButton *button, AlmanahPreferencesD
#endif /* ENABLE_ENCRYPTION */
#ifdef ENABLE_SPELL_CHECKING
static void pd_response_cb (GtkDialog *dialog, gint response_id, AlmanahPreferencesDialog *preferences_dialog);
-static void spell_checking_enabled_notify_cb (GConfClient *client, guint connection_id, GConfEntry *entry, AlmanahPreferencesDialog *self);
-static void pd_spell_checking_enabled_check_button_toggled_cb (GtkToggleButton *toggle_button, gpointer user_data);
#endif /* ENABLE_SPELL_CHECKING */
struct _AlmanahPreferencesDialogPrivate {
@@ -98,9 +97,6 @@ almanah_preferences_dialog_dispose (GObject *object)
priv->key_store = NULL;
}
#endif /* ENABLE_ENCRYPTION */
-#ifdef ENABLE_SPELL_CHECKING
- gconf_client_notify_remove (almanah->gconf_client, priv->spell_checking_enabled_id);
-#endif /* ENABLE_SPELL_CHECKING */
/* Chain up to the parent class */
G_OBJECT_CLASS (almanah_preferences_dialog_parent_class)->dispose (object);
@@ -184,7 +180,7 @@ almanah_preferences_dialog_new (void)
atk_object_add_relationship (a11y_key_combo, ATK_RELATION_LABELLED_BY, a11y_label);
/* Set the selected key combo value */
- key = gconf_client_get_string (almanah->gconf_client, ENCRYPTION_KEY_GCONF_PATH, NULL);
+ key = g_settings_get_string (almanah->settings, "encryption-key");
if (key != NULL && *key == '\0') {
g_free (key);
key = NULL;
@@ -205,11 +201,7 @@ almanah_preferences_dialog_new (void)
priv->spell_checking_enabled_check_button = GTK_CHECK_BUTTON (gtk_check_button_new_with_mnemonic (_("Enable _spell checking")));
gtk_table_attach_defaults (table, GTK_WIDGET (priv->spell_checking_enabled_check_button), 1, 4, 2, 3);
- spell_checking_enabled_notify_cb (NULL, 0, NULL, preferences_dialog);
- g_signal_connect (priv->spell_checking_enabled_check_button, "toggled", G_CALLBACK (pd_spell_checking_enabled_check_button_toggled_cb), preferences_dialog);
- priv->spell_checking_enabled_id = gconf_client_notify_add (almanah->gconf_client, "/apps/almanah/spell_checking_enabled",
- (GConfClientNotifyFunc) spell_checking_enabled_notify_cb, preferences_dialog,
- NULL, NULL);
+ g_settings_bind (almanah->settings, "spell-checking-enabled", priv->spell_checking_enabled_check_button, "active", G_SETTINGS_BIND_DEFAULT);
#endif /* ENABLE_SPELL_CHECKING */
g_object_unref (builder);
@@ -224,12 +216,12 @@ pd_key_combo_changed_cb (GtkComboBox *combo_box, AlmanahPreferencesDialog *prefe
const gchar *key;
GError *error = NULL;
- /* Save the new encryption key to GConf */
+ /* Save the new encryption key to GSettings */
key = cryptui_key_combo_get_key (preferences_dialog->priv->key_combo);
if (key == NULL)
key = "";
- if (gconf_client_set_string (almanah->gconf_client, ENCRYPTION_KEY_GCONF_PATH, key, &error) == FALSE) {
+ if (g_settings_set_string (almanah->settings, "encryption-key", key) == FALSE) {
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (almanah->preferences_dialog),
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
_("Error saving the encryption key"));
@@ -267,46 +259,4 @@ pd_response_cb (GtkDialog *dialog, gint response_id, AlmanahPreferencesDialog *p
{
gtk_widget_hide (GTK_WIDGET (dialog));
}
-
-static void
-spell_checking_enabled_notify_cb (GConfClient *client, guint connection_id, GConfEntry *entry, AlmanahPreferencesDialog *self)
-{
- gboolean enabled;
-
- enabled = gconf_client_get_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled", NULL);
-
- if (almanah->debug)
- g_debug ("spell_checking_enabled_notify_cb called with %u.", enabled);
-
- g_signal_handlers_block_by_func (self->priv->spell_checking_enabled_check_button, pd_spell_checking_enabled_check_button_toggled_cb, self);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->spell_checking_enabled_check_button), enabled);
- g_signal_handlers_unblock_by_func (self->priv->spell_checking_enabled_check_button, pd_spell_checking_enabled_check_button_toggled_cb, self);
-
- if (enabled == TRUE) {
- GError *error = NULL;
-
- almanah_main_window_enable_spell_checking (ALMANAH_MAIN_WINDOW (almanah->main_window), &error);
-
- if (error != NULL) {
- GtkWidget *dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- _("Spelling checker could not be initialized"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- g_error_free (error);
- }
- } else {
- almanah_main_window_disable_spell_checking (ALMANAH_MAIN_WINDOW (almanah->main_window));
- }
-}
-
-static void
-pd_spell_checking_enabled_check_button_toggled_cb (GtkToggleButton *toggle_button, gpointer user_data)
-{
- gconf_client_set_bool (almanah->gconf_client, "/apps/almanah/spell_checking_enabled",
- gtk_toggle_button_get_active (toggle_button), NULL);
-}
-
#endif /* ENABLE_SPELL_CHECKING */
diff --git a/src/storage-manager.c b/src/storage-manager.c
index 77188ac..28f6dce 100644
--- a/src/storage-manager.c
+++ b/src/storage-manager.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <sys/stat.h>
@@ -485,7 +486,7 @@ get_encryption_key (void)
guint i;
gchar *encryption_key;
- encryption_key = gconf_client_get_string (almanah->gconf_client, ENCRYPTION_KEY_GCONF_PATH, NULL);
+ encryption_key = g_settings_get_string (almanah->settings, "encryption-key");
if (encryption_key == NULL || encryption_key[0] == '\0') {
g_free (encryption_key);
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]