[ghex] Port to GSettings



commit efc36f4058609510074abf3c1d2b03f45957f07a
Author: Kalev Lember <kalevlember gmail com>
Date:   Mon Aug 8 19:13:56 2011 +0300

    Port to GSettings
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656080

 Makefile.am                     |    2 +-
 configure.ac                    |   16 +----
 data/Makefile.am                |   20 +++----
 data/ghex.convert               |    9 +++
 data/ghex2.schemas              |  129 ---------------------------------------
 data/org.gnome.GHex.gschema.xml |   28 +++++++++
 src/config.c                    |  100 +++++++++++-------------------
 src/configuration.h             |   26 +++-----
 src/ghex-window.h               |    2 -
 src/preferences.c               |   56 +++++++----------
 10 files changed, 122 insertions(+), 266 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index c2b0f2d..2a09ac2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
-DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper --disable-schemas-install
+DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper
 
 SUBDIRS = data po help src icons
 
diff --git a/configure.ac b/configure.ac
index 9a2739d..dcb15d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,8 @@ AC_CHECK_FUNCS([pow strstr strtoul])
 
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 
+GLIB_GSETTINGS
+
 LIBGTKHEX_RELEASE=3.0
 AC_SUBST(LIBGTKHEX_RELEASE)
 LIBGTKHEX_RELEASE_STRING=gtkhex-${LIBGTKHEX_RELEASE}
@@ -41,9 +43,8 @@ AC_SUBST(LIBGTKHEX_LIBS)
 AC_SUBST(LIBGTKHEX_CFLAGS)
 
 PKG_CHECK_MODULES(GHEX,
-		  gio-2.0                       \
-		  gtk+-3.0 >= 3.0 		\
-		  gconf-2.0)
+		  gio-2.0 >= 2.26	\
+		  gtk+-3.0 >= 3.0)
 AC_SUBST(GHEX_CFLAGS)
 AC_SUBST(GHEX_LIBS)
 
@@ -71,15 +72,6 @@ GNOME_COMPILE_WARNINGS([maximum])
 AC_ARG_ENABLE(debug,
               [  --enable-debug      Enables extra debugging output], AC_DEFINE(ENABLE_DEBUG, 1, [Should verbose debugging output be enabled.]))
 
-dnl Checking for gconftool-2
-AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
-
-if test "x$GCONFTOOL" = xno; then
-	AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
-fi
-
-AM_GCONF_SOURCE_2
-
 GNOME_DOC_INIT([0.9.0],,
   [AC_MSG_WARN([[gnome-doc-utils not found: documentation will not be built.]])])
 
diff --git a/data/Makefile.am b/data/Makefile.am
index cc619f8..bcdc8b0 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,12 +1,16 @@
-schemadir = $(GCONF_SCHEMA_FILE_DIR)
-schema_DATA = ghex2.schemas
-
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gtkhex-3.pc
 
+ GSETTINGS_RULES@
+gsettings_SCHEMAS = org.gnome.GHex.gschema.xml
+
+convertdir = $(datadir)/GConf/gsettings
+convert_DATA = ghex.convert
+
 EXTRA_DIST =			\
 	ghex.desktop.in		\
-	$(schema_DATA)
+	$(gsettings_SCHEMAS)	\
+	$(convert_DATA)
 
 desktopdir = $(datadir)/applications
 desktop_in_files = ghex.desktop.in
@@ -14,13 +18,5 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 @INTLTOOL_DESKTOP_RULE@
 
-#Install the ghex2 schema file
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
-	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(srcdir)/$(schema_DATA)
-else
-install-data-local:
-endif
-
 CLEANFILES =			\
 	$(desktop_DATA)
diff --git a/data/ghex.convert b/data/ghex.convert
new file mode 100644
index 0000000..ce0a4cc
--- /dev/null
+++ b/data/ghex.convert
@@ -0,0 +1,9 @@
+[org.gnome.GHex]
+font = /apps/ghex2/font
+group-data-by = /apps/ghex2/group
+max-undo-depth = /apps/ghex2/maxundodepth
+offset-format = /apps/ghex2/offsetformat
+print-font-data = /apps/ghex2/datafont
+print-font-header = /apps/ghex2/headerfont
+print-shaded-rows = /apps/ghex2/boxsize
+show-offsets = /apps/ghex2/offsetscolumn
diff --git a/data/org.gnome.GHex.gschema.xml b/data/org.gnome.GHex.gschema.xml
new file mode 100644
index 0000000..54d24c8
--- /dev/null
+++ b/data/org.gnome.GHex.gschema.xml
@@ -0,0 +1,28 @@
+<schemalist>
+  <schema id="org.gnome.GHex" path="/org/gnome/ghex/">
+    <key name="font" type="s">
+      <default>'Monospace 12'</default>
+    </key>
+    <key name="group-data-by" type="i">
+      <default>1</default>
+    </key>
+    <key name="max-undo-depth" type="i">
+      <default>100</default>
+    </key>
+    <key name="offset-format" type="s">
+      <default>'%X'</default>
+    </key>
+    <key name="print-font-data" type="s">
+      <default>'Courier 10'</default>
+    </key>
+    <key name="print-font-header" type="s">
+      <default>'Helvetica 12'</default>
+    </key>
+    <key name="print-shaded-rows" type="i">
+      <default>0</default>
+    </key>
+    <key name="show-offsets" type="b">
+      <default>true</default>
+    </key>
+  </schema>
+</schemalist>
diff --git a/src/config.c b/src/config.c
index 3a734b4..068e92c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -27,16 +27,13 @@
 
 #include <string.h>
 
-#include <gconf/gconf-client.h>
-#include <gconf/gconf-value.h>
-
 #include "configuration.h"
 #include "gtkhex.h"
 #include "ghex-window.h"
 
 #define DEFAULT_FONT "Monospace 12"
 
-GConfClient *gconf_client = NULL;
+GSettings *settings = NULL;
 
 gint def_group_type = GROUP_BYTE;
 guint max_undo_depth;
@@ -51,9 +48,7 @@ void ghex_load_configuration () {
 	PangoFontMetrics *new_metrics;
 
 	/* Get the default font metrics */
-	font_name = gconf_client_get_string (gconf_client,
-										 GHEX_BASE_KEY GHEX_PREF_FONT,
-										 NULL);
+	font_name = g_settings_get_string (settings, GHEX_PREF_FONT);
 
 	if (NULL == font_name)
 		font_name = g_strdup (DEFAULT_FONT);
@@ -80,18 +75,14 @@ void ghex_load_configuration () {
 	g_free (font_name);
 
 	/* Get the default group type -- SnM */
-	def_group_type = gconf_client_get_int (gconf_client,
-										   GHEX_BASE_KEY GHEX_PREF_GROUP,
-										   NULL);
+	def_group_type = g_settings_get_int (settings, GHEX_PREF_GROUP);
 
 	/* Sanity check for group type */
 	if (def_group_type <= 0 )
 		def_group_type = GROUP_BYTE;
 
 	/* Get the max undo depth -- SnM */
-	max_undo_depth = gconf_client_get_int (gconf_client,
-										   GHEX_BASE_KEY GHEX_PREF_MAX_UNDO_DEPTH,
-										   NULL);
+	max_undo_depth = g_settings_get_int (settings, GHEX_PREF_MAX_UNDO_DEPTH);
 
 
 	/* Get the offset format -- SnM */ 
@@ -99,9 +90,7 @@ void ghex_load_configuration () {
 	if (offset_fmt)
 		g_free (offset_fmt);
 
-	offset_fmt = gconf_client_get_string (gconf_client,
-										  GHEX_BASE_KEY GHEX_PREF_OFFSET_FORMAT,
-										  NULL);
+	offset_fmt = g_settings_get_string (settings, GHEX_PREF_OFFSET_FORMAT);
 
 	/* Check if offset_fmt is NULL. Shouldnt happen if we get the default
 	 * value from the gconf client -- SnM
@@ -112,19 +101,13 @@ void ghex_load_configuration () {
 	}
 
 	/* Get the show offsets column value -- SnM */
-	show_offsets_column = gconf_client_get_bool (gconf_client,
-												 GHEX_BASE_KEY GHEX_PREF_OFFSETS_COLUMN,
-												 NULL);
+	show_offsets_column = g_settings_get_boolean (settings, GHEX_PREF_OFFSETS_COLUMN);
 
 	/* Get the shaded box size -- SnM */
-	shaded_box_size = gconf_client_get_int (gconf_client,
-											GHEX_BASE_KEY GHEX_PREF_BOX_SIZE,
-											NULL);
+	shaded_box_size = g_settings_get_int (settings, GHEX_PREF_BOX_SIZE);
 
 	/* Get the data font name -- SnM */
-	data_font_name = gconf_client_get_string (gconf_client,
-											  GHEX_BASE_KEY GHEX_PREF_DATA_FONT,
-											  NULL);
+	data_font_name = g_settings_get_string (settings, GHEX_PREF_DATA_FONT);
 	
 	/* Check if data_font_name is NULL. Should not happen if we get the
 	 * default value from the gconf client -- SnM
@@ -134,9 +117,7 @@ void ghex_load_configuration () {
 	}
 
 	/* Get the header font name -- SnM */
-	header_font_name = gconf_client_get_string (gconf_client,
-												GHEX_BASE_KEY GHEX_PREF_HEADER_FONT,
-												NULL);
+	header_font_name = g_settings_get_string (settings, GHEX_PREF_HEADER_FONT);
 
 	/* Check if the header_font_name is NULL. Should not happen if we get
 	 * the default value from the gconf client -- SnM
@@ -147,15 +128,15 @@ void ghex_load_configuration () {
 	}
 }
 
-static void ghex_prefs_notify_cb (GConfClient *gconf_client,
-								  guint cnxn_id,
-								  GConfEntry *entry,
-								  gpointer user_data)
+static void
+ghex_prefs_changed_cb (GSettings   *settings,
+                       const gchar *key,
+                       gpointer     user_data)
 {
 	const GList *winn, *docn;
 
-	if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_OFFSETS_COLUMN)) {
-		gboolean show_off = gconf_value_get_bool(entry->value);
+	if (!strcmp (key, GHEX_PREF_OFFSETS_COLUMN)) {
+		gboolean show_off = g_settings_get_boolean (settings, key);
 		show_offsets_column = show_off;
 		winn = ghex_window_get_list();
 		while(winn) {
@@ -164,11 +145,11 @@ static void ghex_prefs_notify_cb (GConfClient *gconf_client,
 			winn = g_list_next(winn);
 		}
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_GROUP)) {
-		def_group_type = gconf_value_get_int(entry->value);
+	else if (!strcmp (key, GHEX_PREF_GROUP)) {
+		def_group_type = g_settings_get_int (settings, key);
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_MAX_UNDO_DEPTH)) {
-		gint new_undo_max = gconf_value_get_int(entry->value);
+	else if (!strcmp (key, GHEX_PREF_MAX_UNDO_DEPTH)) {
+		gint new_undo_max = g_settings_get_int (settings, key);
 		max_undo_depth = new_undo_max;
 		docn = hex_document_get_list();
 		while(docn) {
@@ -176,16 +157,16 @@ static void ghex_prefs_notify_cb (GConfClient *gconf_client,
 			docn = g_list_next(docn);
 		}
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_BOX_SIZE)) {
-		shaded_box_size = gconf_value_get_int(entry->value);
+	else if (!strcmp (key, GHEX_PREF_BOX_SIZE)) {
+		shaded_box_size = g_settings_get_int (settings, key);
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_OFFSET_FORMAT) &&
-			strcmp(gconf_value_get_string(entry->value), offset_fmt)) {
+	else if (!strcmp (key, GHEX_PREF_OFFSET_FORMAT) &&
+			strcmp (g_settings_get_string (settings, key), offset_fmt)) {
 		gchar *old_offset_fmt = offset_fmt;
 		gint len, i;
 		gboolean expect_spec;
 
-		offset_fmt = g_strdup(gconf_value_get_string(entry->value));
+		offset_fmt = g_strdup (g_settings_get_string (settings, key));
 
 		/* check for a valid format string */
 		len = strlen(offset_fmt);
@@ -202,17 +183,16 @@ static void ghex_prefs_notify_cb (GConfClient *gconf_client,
 				   offset_fmt[i] != 'P' && offset_fmt[i] != 'p') {
 					g_free(offset_fmt);
 					offset_fmt = old_offset_fmt;
-					gconf_client_set_string(gconf_client, GHEX_BASE_KEY GHEX_PREF_OFFSET_FORMAT,
-											"%X", NULL);
+					g_settings_set_string (settings, GHEX_PREF_OFFSET_FORMAT, "%X");
 				}
 			}
 		}
 		if(offset_fmt != old_offset_fmt)
 			g_free(old_offset_fmt);
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_FONT)) {
-		if(gconf_value_get_string(entry->value) != NULL) {
-			const gchar *font_name = gconf_value_get_string(entry->value);
+	else if (!strcmp (key, GHEX_PREF_FONT)) {
+		if (g_settings_get_string (settings, key) != NULL) {
+			const gchar *font_name = g_settings_get_string (settings, key);
 			PangoFontMetrics *new_metrics;
 			PangoFontDescription *new_desc;
 
@@ -240,31 +220,25 @@ static void ghex_prefs_notify_cb (GConfClient *gconf_client,
 			}
 		}
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_DATA_FONT)) {
+	else if (!strcmp (key, GHEX_PREF_DATA_FONT)) {
 		if(data_font_name)
 			g_free(data_font_name);
-		data_font_name = g_strdup (gconf_value_get_string(entry->value));
+		data_font_name = g_strdup (g_settings_get_string (settings, key));
 	}
-	else if(!strcmp(entry->key, GHEX_BASE_KEY GHEX_PREF_HEADER_FONT)) {
+	else if (!strcmp (key, GHEX_PREF_HEADER_FONT)) {
 		if(header_font_name)
 			g_free(header_font_name);
-		header_font_name = g_strdup (gconf_value_get_string(entry->value));
+		header_font_name = g_strdup (g_settings_get_string (settings, key));
 	}
 }
 
 void ghex_init_configuration ()
 {
-	gconf_client = gconf_client_get_default ();
-
-	g_return_if_fail (gconf_client != NULL);
+    settings = g_settings_new ("org.gnome.GHex");
 
-	gconf_client_add_dir (gconf_client,
-						  GHEX_BASE_KEY,
-						  GCONF_CLIENT_PRELOAD_RECURSIVE,
-						  NULL);
+    g_return_if_fail (settings != NULL);
 
-	gconf_client_notify_add (gconf_client,
-							 GHEX_BASE_KEY,
-							 ghex_prefs_notify_cb,
-							 NULL, NULL, NULL);
+    g_signal_connect (settings, "changed",
+                      G_CALLBACK (ghex_prefs_changed_cb),
+                      NULL);
 }
diff --git a/src/configuration.h b/src/configuration.h
index 691a5fc..ebcffe6 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -24,8 +24,6 @@
 #ifndef __GHEX_CONFIGURATION_H__
 #define __GHEX_CONFIGURATION_H__
 
-#include <gconf/gconf-client.h>
-
 #include <gtk/gtk.h>
 
 #include "preferences.h"
@@ -33,17 +31,15 @@
 
 G_BEGIN_DECLS
 
-/* GConf keys */
-#define GHEX_BASE_KEY                "/apps/ghex2"
-#define GHEX_PREF_FONT               "/font"
-#define GHEX_PREF_GROUP              "/group"
-#define GHEX_PREF_MAX_UNDO_DEPTH     "/maxundodepth"   
-#define GHEX_PREF_OFFSET_FORMAT      "/offsetformat"
-#define GHEX_PREF_OFFSETS_COLUMN     "/offsetscolumn"
-#define GHEX_PREF_PAPER              "/paper"
-#define GHEX_PREF_BOX_SIZE           "/boxsize"
-#define GHEX_PREF_DATA_FONT          "/datafont"
-#define GHEX_PREF_HEADER_FONT        "/headerfont"
+/* GSettings keys */
+#define GHEX_PREF_FONT               "font"
+#define GHEX_PREF_GROUP              "group-data-by"
+#define GHEX_PREF_MAX_UNDO_DEPTH     "max-undo-depth"
+#define GHEX_PREF_OFFSET_FORMAT      "offset-format"
+#define GHEX_PREF_DATA_FONT          "print-font-data"
+#define GHEX_PREF_HEADER_FONT        "print-font-header"
+#define GHEX_PREF_BOX_SIZE           "print-shaded-rows"
+#define GHEX_PREF_OFFSETS_COLUMN     "show-offsets"
 
 /* our preferred settings; as only one copy of them is required,
    we'll make them global vars, although this is a bit ugly */
@@ -60,9 +56,9 @@ extern gboolean   show_offsets_column;
 extern gint       shaded_box_size;
 extern gint       def_group_type;
 
-extern GConfClient *gconf_client;
+extern GSettings *settings;
 
-/* Initializes the gconf client */
+/* Initializes the gsettings client */
 void ghex_init_configuration (void);
 
 /* config stuff */
diff --git a/src/ghex-window.h b/src/ghex-window.h
index d76966e..631ea25 100644
--- a/src/ghex-window.h
+++ b/src/ghex-window.h
@@ -10,8 +10,6 @@
 #ifndef __GHEX_WINDOW_H__
 #define __GHEX_WINDOW_H__
 
-#include <gconf/gconf-client.h>
-
 #include <math.h>
 #include <ctype.h>
 
diff --git a/src/preferences.c b/src/preferences.c
index b6268ba..da5d861 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -391,10 +391,9 @@ max_undo_changed_cb(GtkAdjustment *adj, PropertyUI *pui)
 	if((guint)gtk_adjustment_get_value(adj) != max_undo_depth) {
 		max_undo_depth = gtk_spin_button_get_value_as_int
 			(GTK_SPIN_BUTTON(pui->undo_spin));
-		gconf_client_set_int (gconf_client,
-							  GHEX_BASE_KEY GHEX_PREF_MAX_UNDO_DEPTH,
-							  max_undo_depth,
-							  NULL);
+		g_settings_set_int (settings,
+		                    GHEX_PREF_MAX_UNDO_DEPTH,
+		                    max_undo_depth);
 	}
 }
 
@@ -404,10 +403,9 @@ box_size_changed_cb(GtkAdjustment *adj, PropertyUI *pui)
 	if((guint)gtk_adjustment_get_value(adj) != shaded_box_size) {
 		shaded_box_size = gtk_spin_button_get_value_as_int
 			(GTK_SPIN_BUTTON(pui->box_size_spin));
-		gconf_client_set_int (gconf_client,
-							  GHEX_BASE_KEY GHEX_PREF_BOX_SIZE,
-							  shaded_box_size,
-							  NULL);
+		g_settings_set_int (settings,
+		                    GHEX_PREF_BOX_SIZE,
+		                    shaded_box_size);
 	}
 }
 
@@ -416,10 +414,9 @@ offsets_col_cb(GtkToggleButton *tb, PropertyUI *pui)
 {
 	show_offsets_column = gtk_toggle_button_get_active
 		(GTK_TOGGLE_BUTTON(pui->offsets_col));
-	gconf_client_set_bool (gconf_client,
-						   GHEX_BASE_KEY GHEX_PREF_OFFSETS_COLUMN,
-						   show_offsets_column,
-						   NULL);	
+	g_settings_set_boolean (settings,
+	                        GHEX_PREF_OFFSETS_COLUMN,
+	                        show_offsets_column);
 }
 
 static void
@@ -432,10 +429,9 @@ group_type_cb(GtkRadioButton *rd, PropertyUI *pui)
 			def_group_type = group_type[i];
 			break;
 		}
-	gconf_client_set_int (gconf_client,
-						  GHEX_BASE_KEY GHEX_PREF_GROUP,
-						  def_group_type,
-						  NULL);
+	g_settings_set_int (settings,
+	                    GHEX_PREF_GROUP,
+	                    def_group_type);
 }
 
 static void
@@ -496,10 +492,9 @@ select_display_font_cb(GtkWidget *w, PropertyUI *pui)
 				(gtk_font_button_get_font_name
 				 (GTK_FONT_BUTTON(pui->font_button)));
 			def_font_desc = new_desc;
-			gconf_client_set_string (gconf_client,
-									 GHEX_BASE_KEY GHEX_PREF_FONT,
-									 def_font_name,
-									 NULL);
+			g_settings_set_string (settings,
+			                       GHEX_PREF_FONT,
+			                       def_font_name);
 		}
 		else
 			display_error_dialog (ghex_window_get_active(),
@@ -515,20 +510,18 @@ select_font_cb(GtkWidget *w, PropertyUI *pui)
 			g_free(data_font_name);
 		data_font_name = g_strdup(gtk_font_button_get_font_name
 								  (GTK_FONT_BUTTON (pui->df_button)));
-		gconf_client_set_string (gconf_client,
-								 GHEX_BASE_KEY GHEX_PREF_DATA_FONT,
-								 data_font_name,
-								 NULL);
+		g_settings_set_string (settings,
+		                       GHEX_PREF_DATA_FONT,
+		                       data_font_name);
 	}
 	else if(w == pui->hf_button) {
 		if(header_font_name)
 			g_free(header_font_name);
 		header_font_name = g_strdup(gtk_font_button_get_font_name
 									(GTK_FONT_BUTTON (pui->hf_button)));
-		gconf_client_set_string (gconf_client,
-								 GHEX_BASE_KEY GHEX_PREF_HEADER_FONT,
-								 header_font_name,
-								 NULL);
+		g_settings_set_string (settings,
+		                       GHEX_PREF_HEADER_FONT,
+		                       header_font_name);
 	}
 }
 
@@ -577,10 +570,9 @@ update_offset_fmt_from_entry(GtkEntry *entry, PropertyUI *pui)
 	}
 	if(offset_fmt != old_offset_fmt)
 		g_free(old_offset_fmt);
-	gconf_client_set_string (gconf_client,
-							 GHEX_BASE_KEY GHEX_PREF_OFFSET_FORMAT,
-							 offset_fmt,
-							 NULL);
+	g_settings_set_string (settings,
+	                       GHEX_PREF_OFFSET_FORMAT,
+	                       offset_fmt);
 	win_list = ghex_window_get_list();
 	while(NULL != win_list) {
 		ghex_window_update_status_message((GHexWindow *)win_list->data);



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