[gucharmap] port to GSettings
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] port to GSettings
- Date: Fri, 27 Jan 2012 14:23:46 +0000 (UTC)
commit 6eee95f6e150c4735790d3ec6aae50b805cd59fd
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jan 27 02:53:03 2012 -0500
port to GSettings
gucharmap-settings only exists now for the window geometry (until Gtk
grows support for this).
Translation of the schema is also currently disabled, pending proper
support in intltool.
https://bugzilla.gnome.org/show_bug.cgi?id=624892
Makefile.am | 20 +--
configure.ac | 27 +--
gucharmap.schemas.in | 100 ----------
gucharmap/Makefile.am | 8 +-
gucharmap/gucharmap-chapters-view.c | 7 -
gucharmap/gucharmap-chapters-view.h | 2 -
gucharmap/gucharmap-settings.c | 283 +----------------------------
gucharmap/gucharmap-settings.h | 10 -
gucharmap/gucharmap-unicode-info.c | 38 ----
gucharmap/gucharmap-unicode-info.h | 3 -
gucharmap/gucharmap-window.c | 65 +++++--
gucharmap/gucharmap-window.h | 1 +
gucharmap/main.c | 11 -
gucharmap/org.gnome.gucharmap.gschema.xml | 82 +++++++++
14 files changed, 154 insertions(+), 503 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index f51b000..d38c8e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,10 +19,6 @@ desktopdir = $(datadir)/applications
desktop_in_files = gucharmap.desktop.in.in
desktop_DATA = $(desktop_in_files:.desktop.in.in=.desktop)
-schemadir = $(GCONF_SCHEMA_FILE_DIR)
-schema_in_files = gucharmap.schemas.in
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
-
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gucharmap-$(GUCHARMAP_API_PC_VERSION).pc
@@ -32,7 +28,7 @@ EXTRA_DIST = \
autogen.sh \
gtkrc.win32 \
gnome-doc-utils.make \
- $(schema_in_files) \
+ org.gnome.gucharmap.schema.xml.in \
COPYING.UNICODE \
$(NULL)
@@ -46,7 +42,7 @@ DISTCHECK_CONFIGURE_FLAGS = \
CLEANFILES = \
$(desktop_DATA) \
- $(schema_DATA) \
+ $(gsettings_schema) \
$(NULL)
MAINTAINERCLEANFILES = \
@@ -69,17 +65,6 @@ MAINTAINERCLEANFILES = \
$(srcdir)/gnome-doc-utils.make \
`find "$(srcdir)" -type f -name Makefile.in -print`
-if ENABLE_CHARMAP
-install-data-local: $(schema_DATA)
-if GCONF_SCHEMAS_INSTALL
- if test -z "$(DESTDIR)" ; then \
- for p in $^ ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $$p 2>&1 > /dev/null; \
- done \
- fi
-endif # GCONF_SCHEMAS_INSTALL
-endif # ENABLE_CHARMAP
-
ChangeLog:
$(AM_V_GEN) if test -f $(top_srcdir)/.git/HEAD; then \
git log --stat > $@; \
@@ -90,6 +75,5 @@ dist: ChangeLog
.PHONY: ChangeLog
@INTLTOOL_DESKTOP_RULE@
- INTLTOOL_SCHEMAS_RULE@
-include $(top_srcdir)/git.mk
diff --git a/configure.ac b/configure.ac
index d856c55..c8acb39 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,6 +56,7 @@ AC_PROG_CC
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
IT_PROG_INTLTOOL([0.40.0])
+GLIB_SETTINGS
AM_PROG_CC_C_O
@@ -63,6 +64,9 @@ AM_PROG_CC_C_O
GNOME_COMMON_INIT
GNOME_DEBUG_CHECK
+GLIB_REQUIRED=2.16.3
+GIO_REQUIRED=2.25.5
+
# check for win32
case "$host" in
*-*-mingw*) os_win32="yes" ;;
@@ -110,10 +114,10 @@ AC_SUBST([GUCHARMAP_LIBRARY_SUFFIX_U],[AS_TR_SH([$GUCHARMAP_LIBRARY_SUFFIX])])
AM_CONDITIONAL([HAVE_GTK_2],[test "$with_gtk" = "2.0"])
AM_CONDITIONAL([HAVE_GTK_3],[test "$with_gtk" = "3.0"])
-GLIB_REQUIRED=2.16.3
PKG_CHECK_MODULES([GTK],[
glib-2.0 >= $GLIB_REQUIRED
+ gio-2.0 >= $GIO_REQUIRED
gtk+-$GTK_API_VERSION >= $GTK_REQUIRED
])
@@ -122,23 +126,7 @@ AC_SUBST([GLIB_GENMARSHAL])
GLIB_MKENUMS="$($PKG_CONFIG --variable=glib_mkenums glib-2.0)"
AC_SUBST([GLIB_MKENUMS])
-AC_ARG_ENABLE([gconf],
- [AS_HELP_STRING([--disable-gconf],[don't build with gconf support])],
- [],[enable_gconf=yes])
-
-if test "$enable_gconf" = "yes"; then
- GCONFPKGS="gconf-2.0 gthread-2.0"
- PKG_CHECK_MODULES([GCONF],[$GCONFPKGS])
-
- AC_DEFINE([HAVE_GCONF], [1], [Define if have gconf])
-else
- GCONFPKGS=
- AC_MSG_NOTICE([GCONF support disabled with --disable-gconf])
-fi
-AC_SUBST([GCONFPKGS])
-
-AM_GCONF_SOURCE_2
-AC_PATH_PROG([GCONFTOOL],[gconftool-2],[no])
+GLIB_GSETTINGS
AC_MSG_CHECKING([whether to build the charmap programme])
AC_ARG_ENABLE([charmap],
@@ -154,9 +142,6 @@ AC_CHECK_FUNCS([bind_textdomain_codeset])
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
-AC_SUBST(GCONF_CFLAGS)
-AC_SUBST(GCONF_LIBS)
-
AH_TEMPLATE([ENABLE_UNIHAN], [Define if you want CJK ideograph information])
AC_ARG_ENABLE(unihan,
AC_HELP_STRING([--disable-unihan],
diff --git a/gucharmap/Makefile.am b/gucharmap/Makefile.am
index c40f4b8..0acffcf 100644
--- a/gucharmap/Makefile.am
+++ b/gucharmap/Makefile.am
@@ -147,7 +147,6 @@ gucharmap_CPPFLAGS = \
gucharmap_CFLAGS = \
$(GTK_CFLAGS) \
- $(GCONF_CFLAGS) \
$(AM_CFLAGS)
gucharmap_LDFLAGS = \
@@ -156,7 +155,6 @@ gucharmap_LDFLAGS = \
gucharmap_LDADD = \
libgucharmap GUCHARMAP_LIBRARY_SUFFIX_U@.la \
$(GTK_LIBS) \
- $(GCONF_LIBS) \
$(INTL_LIBS)
if OS_WIN32
@@ -264,4 +262,10 @@ endif # !OS_WIN32
endif # ENABLE_CHARMAP
+gsettings_ENUM_NAMESPACE = org.gnome.gucharmap
+gsettings_ENUM_FILES = gucharmap-settings.h
+gsettings_SCHEMAS = org.gnome.gucharmap.gschema.xml
+
+ GSETTINGS_RULES@
+
-include $(top_srcdir)/git.mk
diff --git a/gucharmap/gucharmap-chapters-view.c b/gucharmap/gucharmap-chapters-view.c
index dfdd091..8fddcd1 100644
--- a/gucharmap/gucharmap-chapters-view.c
+++ b/gucharmap/gucharmap-chapters-view.c
@@ -297,10 +297,3 @@ gucharmap_chapters_view_get_book_codepoint_list (GucharmapChaptersView *view)
return gucharmap_chapters_model_get_book_codepoint_list (priv->model);
}
-
-gboolean
-gucharmap_chapters_view_select_locale (GucharmapChaptersView *view)
-{
- return gucharmap_chapters_view_select_character (view,
- gucharmap_unicode_get_locale_character ());
-}
diff --git a/gucharmap/gucharmap-chapters-view.h b/gucharmap/gucharmap-chapters-view.h
index b80b41a..7e8160c 100644
--- a/gucharmap/gucharmap-chapters-view.h
+++ b/gucharmap/gucharmap-chapters-view.h
@@ -75,8 +75,6 @@ gchar * gucharmap_chapters_view_get_selected (GucharmapChaptersView
gboolean gucharmap_chapters_view_set_selected (GucharmapChaptersView *view,
const gchar *name);
-gboolean gucharmap_chapters_view_select_locale (GucharmapChaptersView *view);
-
G_END_DECLS
#endif /* #ifndef GUCHARMAP_CHAPTERS_VIEW_H */
diff --git a/gucharmap/gucharmap-settings.c b/gucharmap/gucharmap-settings.c
index 0140501..2fef9cd 100644
--- a/gucharmap/gucharmap-settings.c
+++ b/gucharmap/gucharmap-settings.c
@@ -27,270 +27,10 @@
#include <gucharmap/gucharmap.h>
#include "gucharmap-settings.h"
-#ifdef HAVE_GCONF
-#include <gconf/gconf-client.h>
-static GConfClient *client;
-#endif
-
-/* The last unicode character we support */
-/* keep in sync with gucharmap-private.h! */
-#define UNICHAR_MAX (0x0010FFFFUL)
-
#define WINDOW_STATE_TIMEOUT 1 /* s */
-#define GCONF_PREFIX "/apps/gucharmap"
-
-static GucharmapChaptersMode
-get_default_chapters_mode (void)
-{
- /* XXX: In the future, do something based on chapters mode and locale
- * or something. */
- return GUCHARMAP_CHAPTERS_SCRIPT;
-}
-
-static gchar *
-get_default_font (void)
-{
- return NULL;
-}
-
-static gboolean
-get_default_snap_pow2 (void)
-{
- return FALSE;
-}
-
-#ifdef HAVE_GCONF
-
-void
-gucharmap_settings_initialize (void)
-{
- client = gconf_client_get_default ();
-
- if (client == NULL) {
- g_message(_("GConf could not be initialized."));
- return;
- }
-
- gconf_client_add_dir (client, GCONF_PREFIX,
- GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
-}
-
-void
-gucharmap_settings_shutdown (void)
-{
- gconf_client_remove_dir (client, GCONF_PREFIX, NULL);
- g_object_unref(client);
- client = NULL;
-}
-
-static gboolean
-gucharmap_settings_initialized (void)
-{
- return (client != NULL);
-}
-
-GucharmapChaptersMode
-gucharmap_settings_get_chapters_mode (void)
-{
- GucharmapChaptersMode ret;
- gchar *mode;
-
- mode = gconf_client_get_string (client, GCONF_PREFIX"/chapters_mode", NULL);
- if (mode == NULL)
- return get_default_chapters_mode ();
-
- if (strcmp (mode, "script") == 0)
- ret = GUCHARMAP_CHAPTERS_SCRIPT;
- else if (strcmp (mode, "block") == 0)
- ret = GUCHARMAP_CHAPTERS_BLOCK;
- else
- ret = get_default_chapters_mode ();
-
- g_free (mode);
- return ret;
-}
-
-void
-gucharmap_settings_set_chapters_mode (GucharmapChaptersMode mode)
-{
- switch (mode)
- {
- case GUCHARMAP_CHAPTERS_SCRIPT:
- gconf_client_set_string (client, GCONF_PREFIX"/chapters_mode", "script", NULL);
- break;
-
- case GUCHARMAP_CHAPTERS_BLOCK:
- gconf_client_set_string (client, GCONF_PREFIX"/chapters_mode", "block", NULL);
- break;
- }
-}
-
-gchar *
-gucharmap_settings_get_font (void)
-{
- char *font;
-
- if (!gucharmap_settings_initialized ()) {
- return get_default_font ();
- }
-
- font = gconf_client_get_string (client, GCONF_PREFIX"/font", NULL);
- if (!font || !font[0]) {
- g_free (font);
- return NULL;
- }
-
- return font;
-}
-
-void
-gucharmap_settings_set_font (gchar *fontname)
-{
- if (!gucharmap_settings_initialized ()) {
- return;
- }
-
- gconf_client_set_string (client, GCONF_PREFIX"/font", fontname, NULL);
-}
-
-gunichar
-gucharmap_settings_get_last_char (void)
-{
- /* See bug 469053 */
- gchar *str, *endptr;
- guint64 value;
-
- if (!gucharmap_settings_initialized ()) {
- return gucharmap_unicode_get_locale_character ();
- }
-
- str = gconf_client_get_string (client, GCONF_PREFIX"/last_char", NULL);
- if (!str || !g_str_has_prefix (str, "U+")) {
- g_free (str);
- return gucharmap_unicode_get_locale_character ();
- }
-
- endptr = NULL;
- errno = 0;
- value = g_ascii_strtoull (str + 2 /* skip the "U+" */, &endptr, 16);
- if (errno || endptr == str || value > UNICHAR_MAX) {
- g_free (str);
- return gucharmap_unicode_get_locale_character ();
- }
-
- g_free (str);
-
- return (gunichar) value;
-}
-
-void
-gucharmap_settings_set_last_char (gunichar wc)
-{
- char str[32];
-
- if (!gucharmap_settings_initialized ()) {
- return;
- }
-
- g_snprintf (str, sizeof (str), "U+%04X", wc);
- str[sizeof (str) - 1] = '\0';
- gconf_client_set_string (client, GCONF_PREFIX"/last_char", str, NULL);
-}
-
-gboolean
-gucharmap_settings_get_snap_pow2 (void)
-{
- if (!gucharmap_settings_initialized ()) {
- return get_default_snap_pow2 ();
- }
-
- return gconf_client_get_bool (client, GCONF_PREFIX"/snap_cols_pow2", NULL);
-}
-
-void
-gucharmap_settings_set_snap_pow2 (gboolean snap_pow2)
-{
- if (!gucharmap_settings_initialized ()) {
- return;
- }
-
- gconf_client_set_bool (client, GCONF_PREFIX"/snap_cols_pow2", snap_pow2, NULL);
-}
-
-#else /* HAVE_GCONF */
-
-void
-gucharmap_settings_initialize (void)
-{
- return;
-}
-
-void
-gucharmap_settings_shutdown (void)
-{
- return;
-}
-
-static gboolean
-gucharmap_settings_initialized (void)
-{
- return FALSE;
-}
-
-GucharmapChaptersMode
-gucharmap_settings_get_chapters_mode (void)
-{
- return get_default_chapters_mode();
-}
-
-void
-gucharmap_settings_set_chapters_mode (GucharmapChaptersMode mode)
-{
- return;
-}
-
-gchar *
-gucharmap_settings_get_font (void)
-{
- return get_default_font ();
-}
-
-void
-gucharmap_settings_set_font (gchar *fontname)
-{
- return;
-}
-
-gunichar
-gucharmap_settings_get_last_char (void)
-{
- return gucharmap_unicode_get_locale_character ();
-}
-
-void
-gucharmap_settings_set_last_char (gunichar wc)
-{
- return;
-}
-
-gboolean
-gucharmap_settings_get_snap_pow2 (void)
-{
- return get_default_snap_pow2 ();
-}
-
-void
-gucharmap_settings_set_snap_pow2 (gboolean snap_pow2)
-{
- return;
-}
-
-#endif /* HAVE_GCONF */
-
-#ifdef HAVE_GCONF
-
typedef struct {
+ GSettings *settings;
guint timeout_id;
int width;
int height;
@@ -301,8 +41,7 @@ typedef struct {
static gboolean
window_state_timeout_cb (WindowState *state)
{
- gconf_client_set_int (client, GCONF_PREFIX "/width", state->width, NULL);
- gconf_client_set_int (client, GCONF_PREFIX "/height", state->height, NULL);
+ g_settings_set (state->settings, "size", "(ii)", state->width, state->height);
state->timeout_id = 0;
return FALSE;
@@ -318,6 +57,8 @@ free_window_state (WindowState *state)
window_state_timeout_cb (state);
}
+ g_object_unref (state->settings);
+
g_slice_free (WindowState, state);
}
@@ -348,18 +89,16 @@ window_state_event_cb (GtkWidget *widget,
{
if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
state->is_maximised = (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) != 0;
- gconf_client_set_bool (client, GCONF_PREFIX "/maximized", state->is_maximised, NULL);
+ g_settings_set_boolean (state->settings, "maximized", state->is_maximised);
}
if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
state->is_fullscreen = (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) != 0;
- gconf_client_set_bool (client, GCONF_PREFIX "/fullscreen", state->is_fullscreen, NULL);
+ g_settings_set_boolean (state->settings, "fullscreen", state->is_fullscreen);
}
return FALSE;
}
-#endif /* HAVE_GCONF */
-
/**
* gucharma_settings_add_window:
* @window: a #GtkWindow
@@ -371,7 +110,6 @@ window_state_event_cb (GtkWidget *widget,
void
gucharmap_settings_add_window (GtkWindow *window)
{
-#ifdef HAVE_GCONF
WindowState *state;
int width, height;
gboolean maximised, fullscreen;
@@ -380,6 +118,7 @@ gucharmap_settings_add_window (GtkWindow *window)
g_return_if_fail (!gtk_widget_get_realized (GTK_WIDGET (window)));
state = g_slice_new0 (WindowState);
+ state->settings = g_settings_new ("org.gnome.gucharmap.WindowState");
g_object_set_data_full (G_OBJECT (window), "GamesConf::WindowState",
state, (GDestroyNotify) free_window_state);
@@ -388,10 +127,9 @@ gucharmap_settings_add_window (GtkWindow *window)
g_signal_connect (window, "window-state-event",
G_CALLBACK (window_state_event_cb), state);
- maximised = gconf_client_get_bool (client, GCONF_PREFIX "/maximized", NULL);
- fullscreen = gconf_client_get_bool (client, GCONF_PREFIX "/fullscreen", NULL);
- width = gconf_client_get_int (client, GCONF_PREFIX "/width", NULL);
- height = gconf_client_get_int (client, GCONF_PREFIX "/height", NULL);
+ maximised = g_settings_get_boolean (state->settings, "maximized");
+ fullscreen = g_settings_get_boolean (state->settings, "fullscreen");
+ g_settings_get (state->settings, "size", "(ii)", &width, &height);
if (width > 0 && height > 0) {
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
@@ -402,5 +140,4 @@ gucharmap_settings_add_window (GtkWindow *window)
if (fullscreen) {
gtk_window_fullscreen (GTK_WINDOW (window));
}
-#endif /* HAVE_GCONF */
}
diff --git a/gucharmap/gucharmap-settings.h b/gucharmap/gucharmap-settings.h
index 11352a9..9ac33d2 100644
--- a/gucharmap/gucharmap-settings.h
+++ b/gucharmap/gucharmap-settings.h
@@ -31,16 +31,6 @@ typedef enum
GUCHARMAP_CHAPTERS_BLOCK = 1
} GucharmapChaptersMode;
-void gucharmap_settings_initialize (void);
-void gucharmap_settings_shutdown (void);
-GucharmapChaptersMode gucharmap_settings_get_chapters_mode (void);
-void gucharmap_settings_set_chapters_mode (GucharmapChaptersMode mode);
-gchar * gucharmap_settings_get_font (void);
-void gucharmap_settings_set_font (gchar *font);
-gunichar gucharmap_settings_get_last_char (void);
-void gucharmap_settings_set_last_char (gunichar wc);
-gboolean gucharmap_settings_get_snap_pow2 (void);
-void gucharmap_settings_set_snap_pow2 (gboolean snap_pow2);
void gucharmap_settings_add_window (GtkWindow *window);
G_END_DECLS
diff --git a/gucharmap/gucharmap-unicode-info.c b/gucharmap/gucharmap-unicode-info.c
index edfeead..c633837 100644
--- a/gucharmap/gucharmap-unicode-info.c
+++ b/gucharmap/gucharmap-unicode-info.c
@@ -649,41 +649,3 @@ gucharmap_unichar_isgraph (gunichar uc)
&& t != G_UNICODE_SURROGATE
&& t != G_UNICODE_SPACE_SEPARATOR);
}
-
-static gunichar
-get_first_non_underscore_char (const char *str)
-{
- const char *p;
-
- if (!str)
- return 0;
-
- for (p = str; p && *p; p = g_utf8_find_next_char (p, NULL))
- {
- gunichar ch;
-
- ch = g_utf8_get_char (p);
- if (g_unichar_isalpha (ch))
- return ch;
- }
-
- return 0;
-}
-
-/**
- * gucharmap_unicode_get_locale_character:
- *
- * Determines a character that's commonly used in the current
- * locale's script.
- *
- * Returns: a unicode character
- */
-gunichar
-gucharmap_unicode_get_locale_character (void)
-{
- GtkStockItem item;
- if (!gtk_stock_lookup (GTK_STOCK_FIND, &item))
- return 0;
-
- return get_first_non_underscore_char (item.label);
-}
diff --git a/gucharmap/gucharmap-unicode-info.h b/gucharmap/gucharmap-unicode-info.h
index 1dbc818..a9e8644 100644
--- a/gucharmap/gucharmap-unicode-info.h
+++ b/gucharmap/gucharmap-unicode-info.h
@@ -79,9 +79,6 @@ G_CONST_RETURN gchar * gucharmap_unicode_get_script_for_char (gunichar wc);
G_CONST_RETURN gchar * gucharmap_unicode_version_to_string (GucharmapUnicodeVersion version);
-/* doesn't really belong here, but no better place was available */
-gunichar gucharmap_unicode_get_locale_character (void);
-
G_END_DECLS
#endif /* #ifndef GUCHARMAP_UNICODE_INFO_H */
diff --git a/gucharmap/gucharmap-window.c b/gucharmap/gucharmap-window.c
index 07743e6..cf52e12 100644
--- a/gucharmap/gucharmap-window.c
+++ b/gucharmap/gucharmap-window.c
@@ -331,7 +331,7 @@ snap_cols_pow2 (GtkAction *action,
{
gboolean is_active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
gucharmap_charmap_set_snap_pow2 (guw->charmap, is_active);
- gucharmap_settings_set_snap_pow2 (is_active);
+ g_settings_set_boolean (guw->settings, "snap-cols-pow2", is_active);
}
static void
@@ -572,7 +572,7 @@ view_by (GtkAction *action,
}
gucharmap_window_set_chapters_model (guw, mode);
- gucharmap_settings_set_chapters_mode (mode);
+ g_settings_set_enum (guw->settings, "group-by", mode);
}
#ifdef DEBUG_chpe
@@ -702,12 +702,17 @@ status_realize (GtkWidget *status,
static gboolean
save_last_char_idle_cb (GucharmapWindow *guw)
{
+ gchar outbuf[10];
gunichar wc;
+ gint len;
guw->save_last_char_idle_id = 0;
wc = gucharmap_charmap_get_active_character (guw->charmap);
- gucharmap_settings_set_last_char (wc);
+ len = g_unichar_to_utf8 (wc, outbuf);
+ outbuf[len] = '\0';
+
+ g_settings_set_string (guw->settings, "last-char", outbuf);
return FALSE;
}
@@ -730,7 +735,7 @@ fontsel_sync_font_desc (GucharmapMiniFontSelection *fontsel,
guw->in_notification = FALSE;
font = pango_font_description_to_string (font_desc);
- gucharmap_settings_set_font (font);
+ g_settings_set (guw->settings, "font", "ms", font);
g_free (font);
}
@@ -836,11 +841,14 @@ gucharmap_window_init (GucharmapWindow *guw)
NULL,
G_CALLBACK (no_font_fallback_toggled_cb), FALSE },
{ "SnapColumns", NULL, N_("Snap _Columns to Power of Two"), NULL,
- NULL,
- G_CALLBACK (snap_cols_pow2), FALSE },
+ NULL, NULL, FALSE },
};
GtkWidget *menubar;
GtkAction *action;
+ gchar *active;
+ gchar *font;
+
+ guw->settings = g_settings_new ("org.gnome.gucharmap");
gtk_window_set_title (GTK_WINDOW (guw), _("Character Map"));
gtk_window_set_icon_name (GTK_WINDOW (guw), GUCHARMAP_ICON_NAME);
@@ -861,7 +869,7 @@ gucharmap_window_init (GucharmapWindow *guw)
gtk_action_group_add_radio_actions (guw->action_group,
radio_menu_entries,
G_N_ELEMENTS (radio_menu_entries),
- gucharmap_settings_get_chapters_mode(),
+ g_settings_get_enum (guw->settings, "group-by"),
G_CALLBACK (view_by),
guw);
gtk_action_group_add_toggle_actions (guw->action_group,
@@ -884,15 +892,11 @@ gucharmap_window_init (GucharmapWindow *guw)
/* The font selector */
guw->fontsel = gucharmap_mini_font_selection_new ();
- g_signal_connect (guw->fontsel, "notify::font-desc",
- G_CALLBACK (fontsel_sync_font_desc), guw);
gtk_box_pack_start (GTK_BOX (big_vbox), guw->fontsel, FALSE, FALSE, 0);
gtk_widget_show (GTK_WIDGET (guw->fontsel));
/* The charmap */
guw->charmap = GUCHARMAP_CHARMAP (gucharmap_charmap_new ());
- g_signal_connect (guw->charmap, "notify::active-character",
- G_CALLBACK (charmap_sync_active_character), guw);
g_signal_connect (guw->charmap, "notify::font-desc",
G_CALLBACK (charmap_sync_font_desc), guw);
@@ -959,18 +963,43 @@ gucharmap_window_init (GucharmapWindow *guw)
gtk_widget_show (big_vbox);
+ gtk_widget_grab_focus (GTK_WIDGET (gucharmap_charmap_get_chartable (guw->charmap)));
+
+ gtk_window_set_has_resize_grip (GTK_WINDOW (guw), TRUE);
+
+ /* read initial settings */
+ /* font */
+ g_settings_get (guw->settings, "font", "ms", &font);
+ if (font != NULL)
+ {
+ gucharmap_window_set_font (guw, font);
+ g_free (font);
+ }
+
+ /* snap-to-power-of-two */
action = gtk_action_group_get_action (guw->action_group, "SnapColumns");
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- gucharmap_settings_get_snap_pow2 ());
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), g_settings_get_boolean (guw->settings, "snap-cols-pow2"));
- gucharmap_window_set_chapters_model (guw, gucharmap_settings_get_chapters_mode ());
+ /* group by */
+ gucharmap_window_set_chapters_model (guw, g_settings_get_enum (guw->settings, "group-by"));
- gucharmap_charmap_set_active_character (guw->charmap,
- gucharmap_settings_get_last_char ());
+ /* active character */
+ active = g_settings_get_string (guw->settings, "last-char");
+ gucharmap_charmap_set_active_character (guw->charmap, g_utf8_get_char (active));
+ g_free (active);
- gtk_widget_grab_focus (GTK_WIDGET (gucharmap_charmap_get_chartable (guw->charmap)));
+ /* window geometry */
+ gucharmap_settings_add_window (GTK_WINDOW (guw));
- gtk_window_set_has_resize_grip (GTK_WINDOW (guw), TRUE);
+ /* connect these only after applying the initial settings in order to
+ * avoid unnecessary writes to GSettings.
+ */
+ g_signal_connect (guw->charmap, "notify::active-character",
+ G_CALLBACK (charmap_sync_active_character), guw);
+ g_signal_connect (guw->fontsel, "notify::font-desc",
+ G_CALLBACK (fontsel_sync_font_desc), guw);
+ g_signal_connect (action, "activate",
+ G_CALLBACK (snap_cols_pow2), guw);
}
static void
diff --git a/gucharmap/gucharmap-window.h b/gucharmap/gucharmap-window.h
index 7c62da8..490a42b 100644
--- a/gucharmap/gucharmap-window.h
+++ b/gucharmap/gucharmap-window.h
@@ -40,6 +40,7 @@ struct _GucharmapWindow
{
GtkWindow parent;
+ GSettings *settings;
GucharmapCharmap *charmap;
GtkWidget *status;
diff --git a/gucharmap/main.c b/gucharmap/main.c
index a6e3c1b..71e5b91 100644
--- a/gucharmap/main.c
+++ b/gucharmap/main.c
@@ -25,7 +25,6 @@
#include <gtk/gtk.h>
#include <gucharmap/gucharmap.h>
-#include "gucharmap-settings.h"
#include "gucharmap-window.h"
static gboolean
@@ -78,8 +77,6 @@ main (int argc, char **argv)
exit (1);
}
- gucharmap_settings_initialize ();
-
g_set_application_name (_("Character Map"));
gtk_window_set_default_icon_name (GUCHARMAP_ICON_NAME);
@@ -96,23 +93,15 @@ main (int argc, char **argv)
#endif
gtk_window_set_default_size (GTK_WINDOW (window), rect.width * 9/16, rect.height * 9/16);
- /* No --font argument, use the stored font (if any) */
- if (!font)
- font = gucharmap_settings_get_font ();
-
if (font)
{
gucharmap_window_set_font (GUCHARMAP_WINDOW (window), font);
g_free (font);
}
- gucharmap_settings_add_window (GTK_WINDOW (window));
-
gtk_window_present (GTK_WINDOW (window));
gtk_main ();
- gucharmap_settings_shutdown ();
-
return 0;
}
diff --git a/gucharmap/org.gnome.gucharmap.gschema.xml b/gucharmap/org.gnome.gucharmap.gschema.xml
new file mode 100644
index 0000000..f85e2b3
--- /dev/null
+++ b/gucharmap/org.gnome.gucharmap.gschema.xml
@@ -0,0 +1,82 @@
+<?xml version='1.0' encoding='utf-8'?>
+
+<!--
+ Copyright  2012 Ryan Lortie
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the licence, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301
+ USA
+
+ Author: Ryan Lortie <desrt desrt ca>
+-->
+
+<schemalist gettext-domain='gucharmap'>
+ <schema id='org.gnome.gucharmap' path='/org/gnome/gucharmap/'>
+ <key name='group-by' enum='org.gnome.gucharmap.GucharmapChaptersMode'>
+ <summary>Character map grouping method</summary>
+ <description>
+ This is how the characters in the character map are grouped.
+ The characters can either be grouped by 'script' or 'block'.
+ </description>
+ <default>'script'</default>
+ </key>
+
+ <key name='font' type='ms'>
+ <summary>Character map font description</summary>
+ <description>
+ The font to use for the character map. If set to 'nothing' then
+ the default is the system font with the size doubled. Otherwise
+ it should be a font description string like 'Sans 24'.
+ </description>
+ <default>nothing</default>
+ </key>
+
+ <key name='snap-cols-pow2' type='b'>
+ <summary>Snap number of columns to a power of two</summary>
+ <description>
+ The number of columns in the character map grid is determined by
+ the width of the window. If this setting is 'true' then the
+ value will be forced to the nearest power of two.
+ </description>
+ <default>false</default>
+ </key>
+
+ <key name='last-char' type='s'>
+ <summary>Last selected character</summary>
+ <description>
+ This is the last character that was selected in the character
+ map (and will be selected again when the character map is next
+ started). If set, it should be a string with a single character.
+
+ By default, it is the first letter of the alphabet in the current
+ locale.
+ </description>
+ <default l10n='messages' context='First letter of alphabet'>'A'</default>
+ </key>
+ </schema>
+
+ <schema id='org.gnome.gucharmap.WindowState' path='/org/gnome/gucharmap/window-state/'>
+ <key name='maximized' type='b'>
+ <default>false</default>
+ </key>
+
+ <key name='fullscreen' type='b'>
+ <default>false</default>
+ </key>
+
+ <key name='size' type='(ii)'>
+ <default>(-1, -1)</default>
+ </key>
+ </schema>
+</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]