From: Jim Evins Date: Sat, 2 Oct 2010 18:01:15 +0000 (-0400) Subject: Merge changes from gsettings branch. X-Git-Tag: glabels-2_3_1~141^2~10 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a0e160ca8b5dd417430b42f1984ed3ceafbca6bd;p=glabels Merge changes from gsettings branch. --- diff --git a/configure.ac b/configure.ac index 836e342f..645fd2f6 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,8 @@ LT_INIT GNOME_DOC_INIT GTK_DOC_CHECK(1.0) +GLIB_GSETTINGS + AC_SEARCH_LIBS([strerror],[cposix]) AC_PROG_CC AC_PROG_INSTALL @@ -70,9 +72,8 @@ dnl --------------------------------------------------------------------------- dnl - Library dependencies dnl --------------------------------------------------------------------------- dnl Required dependencies -GLIB_REQUIRED=2.24.0 +GLIB_REQUIRED=2.25.11 GTK_REQUIRED=2.20.0 -GCONF_REQUIRED=2.28.0 LIBXML_REQUIRED=2.7.0 LIBRSVG_REQUIRED=2.26.0 @@ -86,7 +87,6 @@ LIBZINT_REQUIRED=2.4.0 dnl Make above strings available for packaging files (e.g. rpm spec files) AC_SUBST(GLIB_REQUIRED) AC_SUBST(GTK_REQUIRED) -AC_SUBST(GCONF_REQUIRED) AC_SUBST(LIBXML_REQUIRED) AC_SUBST(LIBEBOOK_REQUIRED) AC_SUBST(LIBBARCODE_REQUIRED) @@ -101,7 +101,6 @@ dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(GLABELS, [\ glib-2.0 >= $GLIB_REQUIRED \ gtk+-2.0 >= $GTK_REQUIRED \ - gconf-2.0 >= $GCONF_REQUIRED \ libxml-2.0 >= $LIBXML_REQUIRED \ librsvg-2.0 > $LIBRSVG_REQUIRED \ ]) @@ -115,7 +114,6 @@ dnl - LIBGLABELS more modest prerequisites dnl --------------------------------------------------------------------------- PKG_CHECK_MODULES(LIBGLABELS, [\ glib-2.0 >= $GLIB_REQUIRED \ - gconf-2.0 >= $GCONF_REQUIRED \ libxml-2.0 >= $LIBXML_REQUIRED \ ]) @@ -284,6 +282,8 @@ data/icons/48x48/Makefile data/man/Makefile data/mime/Makefile data/pixmaps/Makefile +data/schemas/Makefile +data/schemas/org.gnome.glabels-3.gschema.xml.in data/ui/Makefile templates/Makefile po/Makefile.in diff --git a/data/Makefile.am b/data/Makefile.am index ed0a3699..bc73c756 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,5 +1,12 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = desktop icons man mime pixmaps ui +SUBDIRS = \ + desktop \ + icons \ + man \ + mime \ + pixmaps \ + schemas \ + ui diff --git a/data/schemas/Makefile.am b/data/schemas/Makefile.am new file mode 100644 index 00000000..b971934c --- /dev/null +++ b/data/schemas/Makefile.am @@ -0,0 +1,23 @@ + +gsettings_files = \ + org.gnome.glabels-3.gschema.xml.in + +gsettings_SCHEMAS = $(gsettings_files:.xml.in=.xml) + +@INTLTOOL_XML_NOMERGE_RULE@ +@GSETTINGS_RULES@ + + +EXTRA_DIST = \ + $(gsettings_files) + +CLEANFILES = \ + $(gsettings_SCHEMAS) + +DISTCLEANFILES = \ + $(gsettings_files) \ + $(gsettings_SCHEMAS) + +MAINTAINERCLEANFILES = \ + $(DISTCLEANFILES) \ + $(gsettings_SCHEMAS:.xml=.valid) diff --git a/data/schemas/org.gnome.glabels-3.gschema.xml.in.in b/data/schemas/org.gnome.glabels-3.gschema.xml.in.in new file mode 100644 index 00000000..415cf020 --- /dev/null +++ b/data/schemas/org.gnome.glabels-3.gschema.xml.in.in @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + true + <_summary>Show/hide main toolbar. + <_description>Controls visibility of main toolbar. + + + + true + <_summary>Show/hide drawing toolbar. + <_description>Controls visibility of drawing toolbar. + + + + true + <_summary>Show/hide property toolbar. + <_description>Controls visibility of property toolbar. + + + + false + <_summary>Show/hide grid. + <_description>Controls visibility of grid. + + + + true + <_summary>Show/hide markup. + <_description>Controls visibility of markup lines. + + + + -1 + <_summary>Maximum recent files. + <_description>Controls maximum number of recent files tracked. + + + + + + + + + + + + + + + '' + <_summary>Units. + <_description>The default unit of measurement. + + + + + + + + + '' + <_summary>Default page size. + <_description>The prefered page size when searching templates. + + + + + + + + 'Sans' + <_summary>Default font family. + <_description>The default font family for new text objects. + + + + + 12 + <_summary>Default font size. + <_description>The default font size for new text objects. + + + + + + + + 'Regular' + <_summary>Default font weight. + <_description>The default font weight for new text objects. + + + + false + <_summary>Default font italic flag. + <_description>The default font italic state for new text objects. + + + + 0x000000ff + <_summary>Default text color. + <_description>The default color of text for new text objects (0xRRGGBBAA). + + + + + + + + + 'Left' + <_summary>Default text alignment. + <_description>The default text alignment for new text objects. + + + + + 1.0 + <_summary>Default text line spacing. + <_description>The default line spacing for new text objects. + + + + + 1.0 + <_summary>Default line width. + <_description>The default line width for new objects. + + + + 0x000000ff + <_summary>Default line color. + <_description>The default line color new objects (0xRRGGBBAA). + + + + 0x00ff00ff + <_summary>Default fill color. + <_description>The default fill color new objects (0xRRGGBBAA). + + + + + + + + + [] + <_summary>Recent templates. + <_description>Recently used templates. + + + + [] + <_summary>Recent fonts. + <_description>Recently used font families. + + + + [] + <_summary>Recent colors. + <_description>Recently created custom colors. + + + + + + diff --git a/src/color-history-model.c b/src/color-history-model.c index cf11a805..8069fa3d 100644 --- a/src/color-history-model.c +++ b/src/color-history-model.c @@ -22,30 +22,25 @@ #include "color-history-model.h" -#include +#include #include "marshal.h" -#define BASE_KEY "/apps/glabels" -#define RECENT_COLORS_KEY BASE_KEY "/recent-colors" - - /*========================================================*/ /* Private types. */ /*========================================================*/ -/** GL_COLOR_HISTORY_MODEL Private fields */ struct _glColorHistoryModelPrivate { - GConfClient *gconf_client; + GSettings *history; guint max_n; }; enum { - CHANGED, - LAST_SIGNAL + CHANGED, + LAST_SIGNAL }; @@ -60,14 +55,15 @@ static guint signals[LAST_SIGNAL] = {0}; /* Private function prototypes. */ /*========================================================*/ -static void gl_color_history_model_finalize (GObject *object); +static void gl_color_history_model_finalize (GObject *object); -static void conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glColorHistoryModel *this); +static void history_changed_cb (glColorHistoryModel *this); -static GSList *get_color_list (glColorHistoryModel *this); +static guint *get_color_array (glColorHistoryModel *this, + guint *n_elements); +static void set_color_array (glColorHistoryModel *this, + guint *array, + guint n_elements); /*****************************************************************************/ @@ -88,15 +84,15 @@ gl_color_history_model_class_init (glColorHistoryModelClass *class) gobject_class->finalize = gl_color_history_model_finalize; - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glColorHistoryModelClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, - 0); + signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glColorHistoryModelClass, changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } @@ -108,19 +104,13 @@ gl_color_history_model_init (glColorHistoryModel *this) { this->priv = g_new0 (glColorHistoryModelPrivate, 1); - this->priv->gconf_client = gconf_client_get_default (); + this->priv->history = g_settings_new ("org.gnome.glabels-3.history"); - g_return_if_fail (this->priv->gconf_client != NULL); + g_return_if_fail (this->priv->history != NULL); - gconf_client_add_dir (this->priv->gconf_client, - BASE_KEY, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - - gconf_client_notify_add (this->priv->gconf_client, - RECENT_COLORS_KEY, - (GConfClientNotifyFunc)conf_notify_cb, this, - NULL, NULL); + g_signal_connect_swapped (G_OBJECT (this->priv->history), + "changed::recent-colors", + G_CALLBACK (history_changed_cb), this); } @@ -135,7 +125,7 @@ gl_color_history_model_finalize (GObject *object) g_return_if_fail (object && IS_GL_COLOR_HISTORY_MODEL (object)); this = GL_COLOR_HISTORY_MODEL (object); - g_object_unref (G_OBJECT(this->priv->gconf_client)); + g_object_unref (G_OBJECT(this->priv->history)); g_free (this->priv); G_OBJECT_CLASS (gl_color_history_model_parent_class)->finalize (object); @@ -165,57 +155,33 @@ void gl_color_history_model_add_color (glColorHistoryModel *this, guint color) { - GSList *list = NULL; - GSList *old_list; - GSList *p; - - /* - * Start new list with this color. - */ - list = g_slist_append (list, GINT_TO_POINTER (color)); - - /* - * Transfer old list to new list, ignoring any duplicate of this color - */ - old_list = get_color_list (this); - for ( p = old_list; p; p=p->next ) - { - if ( color != (guint)GPOINTER_TO_INT (p->data) ) - { - list = g_slist_append (list, p->data); - } - } - g_slist_free (old_list); + guint *old; + guint *new; + guint i, n; + + old = get_color_array (this, &n); + + new = g_new0 (guint, this->priv->max_n); - /* - * Truncate list to maximum size - */ - while (g_slist_length (list) > this->priv->max_n) + new[0] = color; + + for ( i = 0; (i < (this->priv->max_n-1)) && (i < n); i++ ) { - p = g_slist_last (list); - list = g_slist_remove_link (list, p); - g_slist_free_1 (p); + new[i+1] = old[i]; } - /* - * Update conf - */ - gconf_client_set_list (this->priv->gconf_client, - RECENT_COLORS_KEY, - GCONF_VALUE_INT, - list, - NULL); + set_color_array (this, new, i+1); + + g_free (old); + g_free (new); } /*****************************************************************************/ -/* GConf notify callback. */ +/* History changed callback. */ /*****************************************************************************/ static void -conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glColorHistoryModel *this) +history_changed_cb (glColorHistoryModel *this) { g_signal_emit (G_OBJECT(this), signals[CHANGED], 0); } @@ -224,19 +190,57 @@ conf_notify_cb (GConfClient *client, /*****************************************************************************/ /* Get list of colors. */ /*****************************************************************************/ -static GSList * -get_color_list (glColorHistoryModel *this) +static guint * +get_color_array (glColorHistoryModel *this, + guint *n_elements) { - GSList *list; - - /* - * Get color list. - */ - list = gconf_client_get_list (this->priv->gconf_client, - RECENT_COLORS_KEY, - GCONF_VALUE_INT, - NULL); - return list; + GVariant *value; + GVariant *child_value; + gsize i; + guint *array; + + value = g_settings_get_value (this->priv->history, "recent-colors"); + *n_elements = g_variant_n_children (value); + + array = g_new0 (guint, *n_elements); + + for ( i = 0; i < *n_elements; i++ ) + { + child_value = g_variant_get_child_value (value, i); + array[i] = g_variant_get_uint32 (child_value); + g_variant_unref (child_value); + } + + g_variant_unref (value); + + return array; +} + + +/*****************************************************************************/ +/* Set list of colors. */ +/*****************************************************************************/ +static void +set_color_array (glColorHistoryModel *this, + guint *array, + guint n_elements) +{ + GVariant *value; + GVariant **child_values; + gsize i; + + child_values = g_new (GVariant *, n_elements); + + for ( i = 0; i < n_elements; i++ ) + { + child_values[i] = g_variant_new_uint32 (array[i]); + } + + value = g_variant_new_array (G_VARIANT_TYPE_UINT32, child_values, n_elements); + + g_settings_set_value (this->priv->history, "recent-colors", value); + + g_free (child_values); } @@ -247,17 +251,16 @@ guint gl_color_history_model_get_color (glColorHistoryModel *this, guint i) { + guint *array; guint color = 0; - GSList *list; - GSList *p; + guint n; - list = get_color_list (this); - p = g_slist_nth (list, i); - if (p) + array = get_color_array (this, &n); + if ( array && (i < n) ) { - color = GPOINTER_TO_INT (p->data); + color = array[i]; } - g_slist_free (list); + g_free (array); return color; } diff --git a/src/font-history-model.c b/src/font-history-model.c index 0b25f05a..9710f292 100644 --- a/src/font-history-model.c +++ b/src/font-history-model.c @@ -22,32 +22,27 @@ #include "font-history-model.h" -#include +#include #include #include "font-util.h" #include "marshal.h" -#define BASE_KEY "/apps/glabels" -#define RECENT_FONTS_KEY BASE_KEY "/recent-fonts" - - /*========================================================*/ /* Private types. */ /*========================================================*/ -/** GL_FONT_HISTORY_MODEL Private fields */ struct _glFontHistoryModelPrivate { - GConfClient *gconf_client; + GSettings *history; guint max_n; }; enum { - CHANGED, - LAST_SIGNAL + CHANGED, + LAST_SIGNAL }; @@ -64,10 +59,7 @@ static guint signals[LAST_SIGNAL] = {0}; static void gl_font_history_model_finalize (GObject *object); -static void conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glFontHistoryModel *this); +static void history_changed_cb (glFontHistoryModel *this); /*****************************************************************************/ @@ -88,15 +80,15 @@ gl_font_history_model_class_init (glFontHistoryModelClass *class) gobject_class->finalize = gl_font_history_model_finalize; - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glFontHistoryModelClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, - 0); + signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glFontHistoryModelClass, changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); } @@ -108,19 +100,13 @@ gl_font_history_model_init (glFontHistoryModel *this) { this->priv = g_new0 (glFontHistoryModelPrivate, 1); - this->priv->gconf_client = gconf_client_get_default (); - - g_return_if_fail (this->priv->gconf_client != NULL); + this->priv->history = g_settings_new ("org.gnome.glabels-3.history"); - gconf_client_add_dir (this->priv->gconf_client, - BASE_KEY, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); + g_return_if_fail (this->priv->history != NULL); - gconf_client_notify_add (this->priv->gconf_client, - RECENT_FONTS_KEY, - (GConfClientNotifyFunc)conf_notify_cb, this, - NULL, NULL); + g_signal_connect_swapped (G_OBJECT (this->priv->history), + "changed::recent-fonts", + G_CALLBACK (history_changed_cb), this); } @@ -135,7 +121,7 @@ gl_font_history_model_finalize (GObject *object) g_return_if_fail (object && IS_GL_FONT_HISTORY_MODEL (object)); this = GL_FONT_HISTORY_MODEL (object); - g_object_unref (G_OBJECT(this->priv->gconf_client)); + g_object_unref (G_OBJECT(this->priv->history)); g_free (this->priv); G_OBJECT_CLASS (gl_font_history_model_parent_class)->finalize (object); @@ -165,62 +151,39 @@ void gl_font_history_model_add_family (glFontHistoryModel *this, const gchar *family) { - GSList *list = NULL; - GList *old_list; - GList *p; - GSList *ps; + gchar **old; + gchar **new; + gint i, j; - /* - * Start new list with this family. - */ - list = g_slist_append (list, (gchar *)family); + old = g_settings_get_strv (this->priv->history, "recent-fonts"); + + new = g_new0 (gchar *, this->priv->max_n+1); - /* - * Transfer old list to new list, ignoring any duplicate of this family - */ - old_list = gl_font_history_model_get_family_list (this); - for ( p = old_list; p; p=p->next ) + /* Put in first slot. */ + new[0] = g_strdup (family); + + /* Push everthing else down, pruning any duplicate found. */ + for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ ) { - if ( lgl_str_utf8_casecmp (family, p->data) ) - { - list = g_slist_append (list, p->data); - } - else + if ( lgl_str_utf8_casecmp (family, old[i]) != 0 ) { - g_free (p->data); + new[j++] = g_strdup (old[i]); } } - g_list_free (old_list); - /* - * Truncate list to maximum size - */ - while (g_slist_length (list) > this->priv->max_n) - { - ps = g_slist_last (list); - list = g_slist_remove_link (list, ps); - g_slist_free_1 (ps); - } + g_settings_set_strv (this->priv->history, "recent-fonts", + (const gchar * const *)new); - /* - * Update conf - */ - gconf_client_set_list (this->priv->gconf_client, - RECENT_FONTS_KEY, - GCONF_VALUE_STRING, - list, - NULL); + g_strfreev (old); + g_strfreev (new); } /*****************************************************************************/ -/* GConf notify callback. */ +/* History changed callback. */ /*****************************************************************************/ static void -conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glFontHistoryModel *this) +history_changed_cb (glFontHistoryModel *this) { g_signal_emit (G_OBJECT(this), signals[CHANGED], 0); } @@ -232,33 +195,23 @@ conf_notify_cb (GConfClient *client, GList * gl_font_history_model_get_family_list (glFontHistoryModel *this) { + gchar **strv; GList *list = NULL; - GSList *tmp_list; - GSList *p; + gint i; - /* - * Get family list. - */ - tmp_list = gconf_client_get_list (this->priv->gconf_client, - RECENT_FONTS_KEY, - GCONF_VALUE_STRING, - NULL); + strv = g_settings_get_strv (this->priv->history, "recent-fonts"); /* - * Proof read family list; transfer storage to new list. + * Proof read name list; transfer storage to new list. */ - for (p=tmp_list; p != NULL; p=p->next) + for ( i = 0; strv[i]; i++ ) { - if ( gl_font_util_is_family_installed (p->data) ) - { - list = g_list_append (list, p->data); - } - else + if ( gl_font_util_is_family_installed (strv[i]) ) { - g_free (p->data); + list = g_list_append (list, g_strdup (strv[i])); } } - g_slist_free (tmp_list); + g_strfreev (strv); return list; } diff --git a/src/prefs-model.c b/src/prefs-model.c index ca4537ff..167d3271 100644 --- a/src/prefs-model.c +++ b/src/prefs-model.c @@ -22,10 +22,9 @@ #include "prefs-model.h" -#include +#include #include #include -#include #include #include "marshal.h" @@ -39,37 +38,6 @@ /* Private macros and constants. */ /*========================================================*/ -/* GConf keys */ -#define BASE_KEY "/apps/glabels" - -#define PREF_UNITS "/units" -#define PREF_DEFAULT_PAGE_SIZE "/default-page-size" - -#define PREF_DEFAULT_FONT_FAMILY "/default-font-family" -#define PREF_DEFAULT_FONT_SIZE "/default-font-size" -#define PREF_DEFAULT_FONT_WEIGHT "/default-font-weight" -#define PREF_DEFAULT_FONT_ITALIC_FLAG "/default-font-italic-flag" -#define PREF_DEFAULT_TEXT_COLOR "/default-text-color" -#define PREF_DEFAULT_TEXT_ALIGNMENT "/default-text-alignment" -#define PREF_DEFAULT_TEXT_LINE_SPACING "/default-text-line-spacing" - -#define PREF_DEFAULT_LINE_WIDTH "/default-line-width" -#define PREF_DEFAULT_LINE_COLOR "/default-line-color" - -#define PREF_DEFAULT_FILL_COLOR "/default-fill-color" - -#define PREF_MAIN_TOOLBAR_VISIBLE "/main-toolbar-visible" - -#define PREF_DRAWING_TOOLBAR_VISIBLE "/drawing-toolbar-visible" - -#define PREF_PROPERTY_TOOLBAR_VISIBLE "/property-toolbar-visible" - -#define PREF_GRID_VISIBLE "/grid-visible" -#define PREF_MARKUP_VISIBLE "/markup-visible" - -#define PREF_MAX_RECENTS "/max-recents" - - /* Default values */ #define DEFAULT_UNITS_STRING_US lgl_units_get_id (LGL_UNITS_INCH) #define DEFAULT_PAGE_SIZE_US "US-Letter" @@ -77,19 +45,6 @@ #define DEFAULT_UNITS_STRING_METRIC lgl_units_get_id (LGL_UNITS_MM) #define DEFAULT_PAGE_SIZE_METRIC "A4" -#define DEFAULT_FONT_FAMILY "Sans" -#define DEFAULT_FONT_SIZE 14.0 -#define DEFAULT_FONT_WEIGHT_STRING gl_str_util_weight_to_string (PANGO_WEIGHT_NORMAL) -#define DEFAULT_FONT_ITALIC_FLAG FALSE -#define DEFAULT_TEXT_ALIGN_STRING gl_str_util_align_to_string (PANGO_ALIGN_LEFT) -#define DEFAULT_TEXT_COLOR GL_COLOR (0,0,0) -#define DEFAULT_TEXT_LINE_SPACING 1.0 - -#define DEFAULT_LINE_WIDTH 1.0 -#define DEFAULT_LINE_COLOR GL_COLOR_A (0, 0, 0, 255) - -#define DEFAULT_FILL_COLOR GL_COLOR_A (0, 255, 0, 255) - /*========================================================*/ /* Private types. */ @@ -97,13 +52,15 @@ struct _glPrefsModelPrivate { - GConfClient *gconf_client; + GSettings *locale; + GSettings *objects; + GSettings *ui; }; enum { - CHANGED, - LAST_SIGNAL + CHANGED, + LAST_SIGNAL }; @@ -120,26 +77,7 @@ static guint signals[LAST_SIGNAL] = {0}; static void gl_prefs_model_finalize (GObject *object); -static void notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glPrefsModel *prefs_model); - -static gchar *get_string (GConfClient *client, - const gchar *key, - const gchar *def); - -static gboolean get_bool (GConfClient *client, - const gchar *key, - gboolean def); - -static gint get_int (GConfClient *client, - const gchar *key, - gint def); - -static gdouble get_float (GConfClient *client, - const gchar *key, - gdouble def); +static void gsettings_changed_cb (glPrefsModel *prefs_model); /*****************************************************************************/ @@ -151,68 +89,71 @@ G_DEFINE_TYPE (glPrefsModel, gl_prefs_model, G_TYPE_OBJECT); static void gl_prefs_model_class_init (glPrefsModelClass *class) { - GObjectClass *object_class = G_OBJECT_CLASS (class); + GObjectClass *object_class = G_OBJECT_CLASS (class); - gl_debug (DEBUG_PREFS, "START"); + gl_debug (DEBUG_PREFS, "START"); - gl_prefs_model_parent_class = g_type_class_peek_parent (class); + gl_prefs_model_parent_class = g_type_class_peek_parent (class); - object_class->finalize = gl_prefs_model_finalize; + object_class->finalize = gl_prefs_model_finalize; - signals[CHANGED] = - g_signal_new ("changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (glPrefsModelClass, changed), - NULL, NULL, - gl_marshal_VOID__VOID, - G_TYPE_NONE, - 0); + signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glPrefsModelClass, changed), + NULL, NULL, + gl_marshal_VOID__VOID, + G_TYPE_NONE, + 0); - gl_debug (DEBUG_PREFS, "END"); + gl_debug (DEBUG_PREFS, "END"); } static void gl_prefs_model_init (glPrefsModel *this) { - gl_debug (DEBUG_PREFS, "START"); + gl_debug (DEBUG_PREFS, "START"); this->priv = g_new0 (glPrefsModelPrivate, 1); - this->priv->gconf_client = gconf_client_get_default (); + this->priv->locale = g_settings_new ("org.gnome.glabels-3.locale"); + this->priv->objects = g_settings_new ("org.gnome.glabels-3.objects"); + this->priv->ui = g_settings_new ("org.gnome.glabels-3.ui"); - g_return_if_fail (this->priv->gconf_client != NULL); + g_return_if_fail (this->priv->locale != NULL); + g_return_if_fail (this->priv->objects != NULL); + g_return_if_fail (this->priv->ui != NULL); - gconf_client_add_dir (this->priv->gconf_client, - BASE_KEY, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - - gconf_client_notify_add (this->priv->gconf_client, - BASE_KEY, - (GConfClientNotifyFunc)notify_cb, this, - NULL, NULL); + g_signal_connect_swapped (G_OBJECT (this->priv->locale), "changed", + G_CALLBACK (gsettings_changed_cb), this); + g_signal_connect_swapped (G_OBJECT (this->priv->objects), "changed", + G_CALLBACK (gsettings_changed_cb), this); + g_signal_connect_swapped (G_OBJECT (this->priv->ui), "changed", + G_CALLBACK (gsettings_changed_cb), this); - gl_debug (DEBUG_PREFS, "END"); + gl_debug (DEBUG_PREFS, "END"); } static void gl_prefs_model_finalize (GObject *object) { - glPrefsModel *this = GL_PREFS_MODEL (object); + glPrefsModel *this = GL_PREFS_MODEL (object); - gl_debug (DEBUG_PREFS, "START"); + gl_debug (DEBUG_PREFS, "START"); - g_return_if_fail (object && GL_IS_PREFS_MODEL (object)); + g_return_if_fail (object && GL_IS_PREFS_MODEL (object)); - g_object_unref (G_OBJECT(this->priv->gconf_client)); + g_object_unref (G_OBJECT(this->priv->locale)); + g_object_unref (G_OBJECT(this->priv->objects)); + g_object_unref (G_OBJECT(this->priv->ui)); g_free (this->priv); - G_OBJECT_CLASS (gl_prefs_model_parent_class)->finalize (object); + G_OBJECT_CLASS (gl_prefs_model_parent_class)->finalize (object); - gl_debug (DEBUG_PREFS, "END"); + gl_debug (DEBUG_PREFS, "END"); } @@ -222,15 +163,15 @@ gl_prefs_model_finalize (GObject *object) glPrefsModel * gl_prefs_model_new (void) { - glPrefsModel *this; + glPrefsModel *this; - gl_debug (DEBUG_PREFS, "START"); + gl_debug (DEBUG_PREFS, "START"); - this = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL)); + this = GL_PREFS_MODEL (g_object_new (gl_prefs_model_get_type(), NULL)); - gl_debug (DEBUG_PREFS, "END"); + gl_debug (DEBUG_PREFS, "END"); - return this; + return this; } @@ -241,10 +182,9 @@ void gl_prefs_model_set_units (glPrefsModel *this, lglUnits units) { - gconf_client_set_string (this->priv->gconf_client, - BASE_KEY PREF_UNITS, - lgl_units_get_id (units), - NULL); + g_settings_set_string (this->priv->locale, + "units", + lgl_units_get_id (units)); } @@ -255,30 +195,32 @@ lglUnits gl_prefs_model_get_units (glPrefsModel *this) { const gchar *pgsize; - const gchar *default_units_string; gchar *string; lglUnits units; - /* Make educated guess about locale default. */ - pgsize = gtk_paper_size_get_default (); - if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 ) - { - default_units_string = DEFAULT_UNITS_STRING_US; - } - else + string = g_settings_get_string (this->priv->locale, "units"); + + /* If not set, make educated guess about locale default. */ + if ( !string || !strlen(string) ) { - default_units_string = DEFAULT_UNITS_STRING_METRIC; + pgsize = gtk_paper_size_get_default (); + if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 ) + { + string = g_strdup (DEFAULT_UNITS_STRING_US); + } + else + { + string = g_strdup (DEFAULT_UNITS_STRING_METRIC); + } } - string = get_string (this->priv->gconf_client, - BASE_KEY PREF_UNITS, - default_units_string); - units = lgl_units_from_id (string); - g_free (string); + units = lgl_units_from_id (string); + g_free (string); /* If invalid, make an educated guess from locale. */ if (units == LGL_UNITS_INVALID) { + pgsize = gtk_paper_size_get_default (); if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 ) { units = LGL_UNITS_INCH; @@ -300,10 +242,9 @@ void gl_prefs_model_set_default_page_size (glPrefsModel *this, const gchar *page_size) { - gconf_client_set_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_PAGE_SIZE, - page_size, - NULL); + g_settings_set_string (this->priv->locale, + "default-page-size", + page_size); } @@ -314,34 +255,34 @@ gchar * gl_prefs_model_get_default_page_size (glPrefsModel *this) { const gchar *pgsize; - const gchar *default_page_size; gchar *page_size; - lglPaper *paper; + lglPaper *paper; - /* Make educated guess about locale default. */ - pgsize = gtk_paper_size_get_default (); - if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 ) - { - default_page_size = DEFAULT_PAGE_SIZE_US; - } - else + page_size = g_settings_get_string (this->priv->locale, "default-page-size"); + + /* If not set, make educated guess about locale default. */ + if ( !page_size || !strlen(page_size) ) { - default_page_size = DEFAULT_PAGE_SIZE_METRIC; + pgsize = gtk_paper_size_get_default (); + if ( strcmp (pgsize, GTK_PAPER_NAME_LETTER) == 0 ) + { + page_size = g_strdup (DEFAULT_PAGE_SIZE_US); + } + else + { + page_size = g_strdup (DEFAULT_PAGE_SIZE_METRIC); + } } - page_size = get_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_PAGE_SIZE, - default_page_size); - - /* Proof read the default page size -- it must be a valid id. */ - /* (For compatability with older versions.) */ - paper = lgl_db_lookup_paper_from_id (page_size); - if ( paper == NULL ) { + /* Proof read the default page size -- it must be a valid id. */ + /* (For compatability with older versions.) */ + paper = lgl_db_lookup_paper_from_id (page_size); + if ( paper == NULL ) { g_free (page_size); - page_size = g_strdup (DEFAULT_PAGE_SIZE_US); - } else { - lgl_paper_free (paper); - } + page_size = g_strdup (DEFAULT_PAGE_SIZE_US); + } else { + lgl_paper_free (paper); + } return page_size; } @@ -354,10 +295,9 @@ void gl_prefs_model_set_default_font_family (glPrefsModel *this, const gchar *family) { - gconf_client_set_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_FAMILY, - family, - NULL); + g_settings_set_string (this->priv->objects, + "default-font-family", + family); } @@ -369,9 +309,8 @@ gl_prefs_model_get_default_font_family (glPrefsModel *this) { gchar *family; - family = get_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_FAMILY, - DEFAULT_FONT_FAMILY); + family = g_settings_get_string (this->priv->objects, + "default-font-family"); return family; } @@ -384,10 +323,9 @@ void gl_prefs_model_set_default_font_size (glPrefsModel *this, gdouble size) { - gconf_client_set_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_SIZE, - size, - NULL); + g_settings_set_double (this->priv->objects, + "default-font-size", + size); } @@ -399,9 +337,8 @@ gl_prefs_model_get_default_font_size (glPrefsModel *this) { gdouble size; - size = get_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_SIZE, - DEFAULT_FONT_SIZE); + size = g_settings_get_double (this->priv->objects, + "default-font-size"); return size; } @@ -414,10 +351,9 @@ void gl_prefs_model_set_default_font_weight (glPrefsModel *this, PangoWeight weight) { - gconf_client_set_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_WEIGHT, - gl_str_util_weight_to_string(weight), - NULL); + g_settings_set_string (this->priv->objects, + "default-font-weight", + gl_str_util_weight_to_string(weight)); } @@ -430,11 +366,10 @@ gl_prefs_model_get_default_font_weight (glPrefsModel *this) gchar *string; PangoWeight weight; - string = get_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_WEIGHT, - DEFAULT_FONT_WEIGHT_STRING); - weight = gl_str_util_string_to_weight (string); - g_free (string); + string = g_settings_get_string (this->priv->objects, + "default-font-weight"); + weight = gl_str_util_string_to_weight (string); + g_free (string); return weight; } @@ -447,10 +382,9 @@ void gl_prefs_model_set_default_font_italic_flag (glPrefsModel *this, gboolean italic_flag) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_ITALIC_FLAG, - italic_flag, - NULL); + g_settings_set_boolean (this->priv->objects, + "default-font-italic-flag", + italic_flag); } @@ -462,9 +396,8 @@ gl_prefs_model_get_default_font_italic_flag (glPrefsModel *this) { gboolean italic_flag; - italic_flag = get_bool (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FONT_ITALIC_FLAG, - DEFAULT_FONT_ITALIC_FLAG); + italic_flag = g_settings_get_boolean (this->priv->objects, + "default-font-italic-flag"); return italic_flag; } @@ -477,10 +410,9 @@ void gl_prefs_model_set_default_text_color (glPrefsModel *this, guint color) { - gconf_client_set_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_COLOR, - color, - NULL); + g_settings_set_value (this->priv->objects, + "default-text-color", + g_variant_new_uint32 (color)); } @@ -490,11 +422,12 @@ gl_prefs_model_set_default_text_color (glPrefsModel *this, guint gl_prefs_model_get_default_text_color (glPrefsModel *this) { - guint color; + GVariant *value; + guint color; - color = get_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_COLOR, - DEFAULT_TEXT_COLOR); + value = g_settings_get_value (this->priv->objects, "default-text-color"); + color = g_variant_get_uint32 (value); + g_variant_unref (value); return color; } @@ -507,10 +440,9 @@ void gl_prefs_model_set_default_text_alignment (glPrefsModel *this, PangoAlignment alignment) { - gconf_client_set_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT, - gl_str_util_align_to_string(alignment), - NULL); + g_settings_set_string (this->priv->objects, + "default-text-alignment", + gl_str_util_align_to_string(alignment)); } @@ -523,11 +455,10 @@ gl_prefs_model_get_default_text_alignment (glPrefsModel *this) gchar *string; PangoAlignment alignment; - string = get_string (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_ALIGNMENT, - DEFAULT_TEXT_ALIGN_STRING); - alignment = gl_str_util_string_to_align (string); - g_free (string); + string = g_settings_get_string (this->priv->objects, + "default-text-alignment"); + alignment = gl_str_util_string_to_align (string); + g_free (string); return alignment; } @@ -540,10 +471,9 @@ void gl_prefs_model_set_default_text_line_spacing (glPrefsModel *this, gdouble spacing) { - gconf_client_set_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_LINE_SPACING, - spacing, - NULL); + g_settings_set_double (this->priv->objects, + "default-text-line-spacing", + spacing); } @@ -555,9 +485,8 @@ gl_prefs_model_get_default_text_line_spacing (glPrefsModel *this) { gdouble spacing; - spacing = get_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_TEXT_LINE_SPACING, - DEFAULT_TEXT_LINE_SPACING); + spacing = g_settings_get_double (this->priv->objects, + "default-text-line-spacing"); return spacing; } @@ -570,10 +499,9 @@ void gl_prefs_model_set_default_line_width (glPrefsModel *this, gdouble width) { - gconf_client_set_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_LINE_WIDTH, - width, - NULL); + g_settings_set_double (this->priv->objects, + "default-line-width", + width); } @@ -585,9 +513,8 @@ gl_prefs_model_get_default_line_width (glPrefsModel *this) { gdouble width; - width = get_float (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_LINE_WIDTH, - DEFAULT_LINE_WIDTH); + width = g_settings_get_double (this->priv->objects, + "default-line-width"); return width; } @@ -600,10 +527,9 @@ void gl_prefs_model_set_default_line_color (glPrefsModel *this, guint color) { - gconf_client_set_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_LINE_COLOR, - color, - NULL); + g_settings_set_value (this->priv->objects, + "default-line-color", + g_variant_new_uint32 (color)); } @@ -613,11 +539,12 @@ gl_prefs_model_set_default_line_color (glPrefsModel *this, guint gl_prefs_model_get_default_line_color (glPrefsModel *this) { - guint color; + GVariant *value; + guint color; - color = get_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_LINE_COLOR, - DEFAULT_LINE_COLOR); + value = g_settings_get_value (this->priv->objects, "default-line-color"); + color = g_variant_get_uint32 (value); + g_variant_unref (value); return color; } @@ -630,10 +557,9 @@ void gl_prefs_model_set_default_fill_color (glPrefsModel *this, guint color) { - gconf_client_set_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FILL_COLOR, - color, - NULL); + g_settings_set_value (this->priv->objects, + "default-fill-color", + g_variant_new_uint32 (color)); } @@ -643,11 +569,12 @@ gl_prefs_model_set_default_fill_color (glPrefsModel *this, guint gl_prefs_model_get_default_fill_color (glPrefsModel *this) { - guint color; + GVariant *value; + guint color; - color = get_int (this->priv->gconf_client, - BASE_KEY PREF_DEFAULT_FILL_COLOR, - DEFAULT_FILL_COLOR); + value = g_settings_get_value (this->priv->objects, "default-fill-color"); + color = g_variant_get_uint32 (value); + g_variant_unref (value); return color; } @@ -660,10 +587,9 @@ void gl_prefs_model_set_main_toolbar_visible (glPrefsModel *this, gboolean visible) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE, - visible, - NULL); + g_settings_set_boolean (this->priv->ui, + "main-toolbar-visible", + visible); } @@ -675,9 +601,8 @@ gl_prefs_model_get_main_toolbar_visible (glPrefsModel *this) { gboolean visible; - visible = get_bool (this->priv->gconf_client, - BASE_KEY PREF_MAIN_TOOLBAR_VISIBLE, - TRUE); + visible = g_settings_get_boolean (this->priv->ui, + "main-toolbar-visible"); return visible; } @@ -690,10 +615,9 @@ void gl_prefs_model_set_drawing_toolbar_visible (glPrefsModel *this, gboolean visible) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE, - visible, - NULL); + g_settings_set_boolean (this->priv->ui, + "drawing-toolbar-visible", + visible); } @@ -705,9 +629,8 @@ gl_prefs_model_get_drawing_toolbar_visible (glPrefsModel *this) { gboolean visible; - visible = get_bool (this->priv->gconf_client, - BASE_KEY PREF_DRAWING_TOOLBAR_VISIBLE, - TRUE); + visible = g_settings_get_boolean (this->priv->ui, + "drawing-toolbar-visible"); return visible; } @@ -720,10 +643,9 @@ void gl_prefs_model_set_property_toolbar_visible (glPrefsModel *this, gboolean visible) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE, - visible, - NULL); + g_settings_set_boolean (this->priv->ui, + "property-toolbar-visible", + visible); } @@ -735,9 +657,8 @@ gl_prefs_model_get_property_toolbar_visible (glPrefsModel *this) { gboolean visible; - visible = get_bool (this->priv->gconf_client, - BASE_KEY PREF_PROPERTY_TOOLBAR_VISIBLE, - TRUE); + visible = g_settings_get_boolean (this->priv->ui, + "property-toolbar-visible"); return visible; } @@ -750,10 +671,9 @@ void gl_prefs_model_set_grid_visible (glPrefsModel *this, gboolean visible) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_GRID_VISIBLE, - visible, - NULL); + g_settings_set_boolean (this->priv->ui, + "grid-visible", + visible); } @@ -765,9 +685,8 @@ gl_prefs_model_get_grid_visible (glPrefsModel *this) { gboolean visible; - visible = get_bool (this->priv->gconf_client, - BASE_KEY PREF_GRID_VISIBLE, - TRUE); + visible = g_settings_get_boolean (this->priv->ui, + "grid-visible"); return visible; } @@ -780,10 +699,9 @@ void gl_prefs_model_set_markup_visible (glPrefsModel *this, gboolean visible) { - gconf_client_set_bool (this->priv->gconf_client, - BASE_KEY PREF_MARKUP_VISIBLE, - visible, - NULL); + g_settings_set_boolean (this->priv->ui, + "markup-visible", + visible); } @@ -795,9 +713,8 @@ gl_prefs_model_get_markup_visible (glPrefsModel *this) { gboolean visible; - visible = get_bool (this->priv->gconf_client, - BASE_KEY PREF_MARKUP_VISIBLE, - TRUE); + visible = g_settings_get_boolean (this->priv->ui, + "markup-visible"); return visible; } @@ -810,10 +727,9 @@ void gl_prefs_model_set_max_recents (glPrefsModel *this, gint max_recents) { - gconf_client_set_int (this->priv->gconf_client, - BASE_KEY PREF_MAX_RECENTS, - max_recents, - NULL); + g_settings_set_int (this->priv->ui, + "max-recents", + max_recents); } @@ -825,9 +741,8 @@ gl_prefs_model_get_max_recents (glPrefsModel *this) { gint max_recents; - max_recents = get_int (this->priv->gconf_client, - BASE_KEY PREF_MAX_RECENTS, - -1); + max_recents = g_settings_get_int (this->priv->ui, + "max-recents"); return max_recents; } @@ -837,131 +752,12 @@ gl_prefs_model_get_max_recents (glPrefsModel *this) /* PRIVATE. Key changed callback. */ /*---------------------------------------------------------------------------*/ static void -notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glPrefsModel *this) -{ - gl_debug (DEBUG_PREFS, "Key was changed: %s", entry->key); - - g_signal_emit (G_OBJECT(this), signals[CHANGED], 0); -} - - -/*---------------------------------------------------------------------------*/ -/* PRIVATE. Utilities to get values with defaults. */ -/*---------------------------------------------------------------------------*/ -static gchar* -get_string (GConfClient *client, - const gchar *key, - const gchar *def) -{ - gchar* val; - - val = gconf_client_get_string (client, key, NULL); - - if (val != NULL) { - - return val; - - } else { - - return def ? g_strdup (def) : NULL; - - } -} - - -static gboolean -get_bool (GConfClient *client, - const gchar *key, - gboolean def) +gsettings_changed_cb (glPrefsModel *this) { - GConfValue* val; - gboolean retval; - - val = gconf_client_get (client, key, NULL); - - if (val != NULL) { - - if ( val->type == GCONF_VALUE_BOOL ) { - retval = gconf_value_get_bool (val); - } else { - retval = def; - } - - gconf_value_free (val); - - return retval; - - } else { - - return def; - - } + g_signal_emit (G_OBJECT(this), signals[CHANGED], 0); } -static gint -get_int (GConfClient *client, - const gchar *key, - gint def) -{ - GConfValue* val; - gint retval; - - val = gconf_client_get (client, key, NULL); - - if (val != NULL) { - - if ( val->type == GCONF_VALUE_INT) { - retval = gconf_value_get_int(val); - } else { - retval = def; - } - - gconf_value_free (val); - - return retval; - - } else { - - return def; - - } -} - - -static gdouble -get_float (GConfClient *client, - const gchar *key, - gdouble def) -{ - GConfValue* val; - gdouble retval; - - val = gconf_client_get (client, key, NULL); - - if (val != NULL) { - - if ( val->type == GCONF_VALUE_FLOAT ) { - retval = gconf_value_get_float(val); - } else { - retval = def; - } - - gconf_value_free (val); - - return retval; - - } else { - return def; - - } -} - - - /* diff --git a/src/template-history-model.c b/src/template-history-model.c index e00579ec..7c1cc473 100644 --- a/src/template-history-model.c +++ b/src/template-history-model.c @@ -22,24 +22,19 @@ #include "template-history-model.h" -#include +#include #include #include "marshal.h" -#define BASE_KEY "/apps/glabels" -#define RECENT_TEMPLATES_KEY BASE_KEY "/recent-templates" - - /*========================================================*/ /* Private types. */ /*========================================================*/ -/** GL_TEMPLATE_HISTORY_MODEL Private fields */ struct _glTemplateHistoryModelPrivate { - GConfClient *gconf_client; + GSettings *history; guint max_n; }; @@ -63,10 +58,7 @@ static guint signals[LAST_SIGNAL] = {0}; static void gl_template_history_model_finalize (GObject *object); -static void conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glTemplateHistoryModel *this); +static void history_changed_cb (glTemplateHistoryModel *this); /*****************************************************************************/ @@ -107,19 +99,13 @@ gl_template_history_model_init (glTemplateHistoryModel *this) { this->priv = g_new0 (glTemplateHistoryModelPrivate, 1); - this->priv->gconf_client = gconf_client_get_default (); - - g_return_if_fail (this->priv->gconf_client != NULL); + this->priv->history = g_settings_new ("org.gnome.glabels-3.history"); - gconf_client_add_dir (this->priv->gconf_client, - BASE_KEY, - GCONF_CLIENT_PRELOAD_ONELEVEL, - NULL); + g_return_if_fail (this->priv->history != NULL); - gconf_client_notify_add (this->priv->gconf_client, - RECENT_TEMPLATES_KEY, - (GConfClientNotifyFunc)conf_notify_cb, this, - NULL, NULL); + g_signal_connect_swapped (G_OBJECT (this->priv->history), + "changed::recent-templates", + G_CALLBACK (history_changed_cb), this); } @@ -134,7 +120,7 @@ gl_template_history_model_finalize (GObject *object) g_return_if_fail (object && IS_GL_TEMPLATE_HISTORY_MODEL (object)); this = GL_TEMPLATE_HISTORY_MODEL (object); - g_object_unref (G_OBJECT(this->priv->gconf_client)); + g_object_unref (G_OBJECT(this->priv->history)); g_free (this->priv); G_OBJECT_CLASS (gl_template_history_model_parent_class)->finalize (object); @@ -158,68 +144,45 @@ gl_template_history_model_new (guint n) /*****************************************************************************/ -/* Add template to history. */ +/* Add template to history. */ /*****************************************************************************/ void gl_template_history_model_add_name (glTemplateHistoryModel *this, const gchar *name) { - GSList *list = NULL; - GList *old_list; - GList *p; - GSList *ps; + gchar **old; + gchar **new; + gint i, j; - /* - * Start new list with this name. - */ - list = g_slist_append (list, (gchar *)name); + old = g_settings_get_strv (this->priv->history, "recent-templates"); + + new = g_new0 (gchar *, this->priv->max_n+1); - /* - * Transfer old list to new list, ignoring any duplicate of this name - */ - old_list = gl_template_history_model_get_name_list (this); - for ( p = old_list; p; p=p->next ) + /* Put in first slot. */ + new[0] = g_strdup (name); + + /* Push everthing else down, pruning any duplicate found. */ + for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ ) { - if ( lgl_str_utf8_casecmp (name, p->data) ) - { - list = g_slist_append (list, p->data); - } - else + if ( lgl_str_utf8_casecmp (name, old[i]) != 0 ) { - g_free (p->data); + new[j++] = g_strdup (old[i]); } } - g_list_free (old_list); - /* - * Truncate list to maximum size - */ - while (g_slist_length (list) > this->priv->max_n) - { - ps = g_slist_last (list); - list = g_slist_remove_link (list, ps); - g_slist_free_1 (ps); - } + g_settings_set_strv (this->priv->history, "recent-templates", + (const gchar * const *)new); - /* - * Update conf - */ - gconf_client_set_list (this->priv->gconf_client, - RECENT_TEMPLATES_KEY, - GCONF_VALUE_STRING, - list, - NULL); + g_strfreev (old); + g_strfreev (new); } /*****************************************************************************/ -/* GConf notify callback. */ +/* History changed callback. */ /*****************************************************************************/ static void -conf_notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - glTemplateHistoryModel *this) +history_changed_cb (glTemplateHistoryModel *this) { g_signal_emit (G_OBJECT(this), signals[CHANGED], 0); } @@ -231,33 +194,23 @@ conf_notify_cb (GConfClient *client, GList * gl_template_history_model_get_name_list (glTemplateHistoryModel *this) { + gchar **strv; GList *list = NULL; - GSList *tmp_list; - GSList *p; + gint i; - /* - * Get name list. - */ - tmp_list = gconf_client_get_list (this->priv->gconf_client, - RECENT_TEMPLATES_KEY, - GCONF_VALUE_STRING, - NULL); + strv = g_settings_get_strv (this->priv->history, "recent-templates"); /* * Proof read name list; transfer storage to new list. */ - for (p=tmp_list; p != NULL; p=p->next) + for ( i = 0; strv[i]; i++ ) { - if ( lgl_db_does_template_name_exist (p->data) ) - { - list = g_list_append (list, p->data); - } - else + if ( lgl_db_does_template_name_exist (strv[i]) ) { - g_free (p->data); + list = g_list_append (list, g_strdup (strv[i])); } } - g_slist_free (tmp_list); + g_strfreev (strv); return list; } diff --git a/src/ui.c b/src/ui.c index b9dacd9f..93390bae 100644 --- a/src/ui.c +++ b/src/ui.c @@ -23,7 +23,6 @@ #include "ui.h" #include -#include #include #include