Commit 6eee95f6 authored by Ryan Lortie's avatar Ryan Lortie

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
parent 94230bc3
......@@ -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
......@@ -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],
......
<?xml version="1.0"?>
<gconfschemafile>
<schemalist>
<schema>
<key>/schemas/apps/gucharmap/chapters_mode</key>
<applyto>/apps/gucharmap/chapters_mode</applyto>
<owner>gucharmap</owner>
<type>string</type>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/last_char</key>
<applyto>/apps/gucharmap/last_char</applyto>
<owner>gucharmap</owner>
<type>string</type>
<default>0</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/font</key>
<applyto>/apps/gucharmap/font</applyto>
<owner>gucharmap</owner>
<type>string</type>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/height</key>
<applyto>/apps/gucharmap/height</applyto>
<owner>gucharmap</owner>
<type>int</type>
<default>0</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/snap_cols_pow2</key>
<applyto>/apps/gucharmap/snap_cols_pow2</applyto>
<owner>gucharmap</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/width</key>
<applyto>/apps/gucharmap/width</applyto>
<owner>gucharmap</owner>
<type>int</type>
<default>0</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/maximized</key>
<applyto>/apps/gucharmap/maximized</applyto>
<owner>gucharmap</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gucharmap/fullscreen</key>
<applyto>/apps/gucharmap/fullscreen</applyto>
<owner>gucharmap</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short></short>
<long></long>
</locale>
</schema>
</schemalist>
</gconfschemafile>
......@@ -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
......@@ -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 ());
}
......@@ -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 */
......@@ -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 */
}
......@@ -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
......
......@@ -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);
}
......@@ -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 */
......
......@@ -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 */