[glabels/gsettings] Fixed several bugs with use of GSettings.
- From: Jim Evins <jimevins src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glabels/gsettings] Fixed several bugs with use of GSettings.
- Date: Mon, 26 Jul 2010 03:58:12 +0000 (UTC)
commit 618369ea3dd7525782ed580c1d065340ef5d041f
Author: Jim Evins <evins snaught com>
Date: Sun Jul 25 23:55:40 2010 -0400
Fixed several bugs with use of GSettings.
Fixed crash in recent-colors. Prune duplicates in recent-templates and
recent-fonts. Fixed cut&paste problem with recent-fonts.
src/color-history-model.c | 10 +++++-----
src/font-history-model.c | 17 +++++++++++------
src/template-history-model.c | 13 +++++++++----
3 files changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/src/color-history-model.c b/src/color-history-model.c
index 78bc6a0..8069fa3 100644
--- a/src/color-history-model.c
+++ b/src/color-history-model.c
@@ -165,12 +165,12 @@ gl_color_history_model_add_color (glColorHistoryModel *this,
new[0] = color;
- for ( i = 0; (i < this->priv->max_n) && (i < n); i++ )
+ for ( i = 0; (i < (this->priv->max_n-1)) && (i < n); i++ )
{
new[i+1] = old[i];
}
- set_color_array (this, new, i);
+ set_color_array (this, new, i+1);
g_free (old);
g_free (new);
@@ -233,14 +233,14 @@ set_color_array (glColorHistoryModel *this,
for ( i = 0; i < n_elements; i++ )
{
- child_values[i] = g_variant_ref_sink (g_variant_new_uint32 (array[i]));
+ child_values[i] = g_variant_new_uint32 (array[i]);
}
- g_variant_new_array (G_VARIANT_TYPE ("u"), child_values, n_elements);
+ value = g_variant_new_array (G_VARIANT_TYPE_UINT32, child_values, n_elements);
g_settings_set_value (this->priv->history, "recent-colors", value);
- g_variant_unref (value);
+ g_free (child_values);
}
diff --git a/src/font-history-model.c b/src/font-history-model.c
index ef7b142..9710f29 100644
--- a/src/font-history-model.c
+++ b/src/font-history-model.c
@@ -153,20 +153,25 @@ gl_font_history_model_add_family (glFontHistoryModel *this,
{
gchar **old;
gchar **new;
- gint i;
+ gint i, j;
- old = g_settings_get_strv (this->priv->history, "recent-templates");
+ old = g_settings_get_strv (this->priv->history, "recent-fonts");
new = g_new0 (gchar *, this->priv->max_n+1);
+ /* Put in first slot. */
new[0] = g_strdup (family);
- for ( i = 0; (i < (this->priv->max_n-1)) && old[i]; i++ )
+ /* Push everthing else down, pruning any duplicate found. */
+ for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
{
- new[i+1] = g_strdup (old[i]);
+ if ( lgl_str_utf8_casecmp (family, old[i]) != 0 )
+ {
+ new[j++] = g_strdup (old[i]);
+ }
}
- g_settings_set_strv (this->priv->history, "recent-templates",
+ g_settings_set_strv (this->priv->history, "recent-fonts",
(const gchar * const *)new);
g_strfreev (old);
@@ -194,7 +199,7 @@ gl_font_history_model_get_family_list (glFontHistoryModel *this)
GList *list = NULL;
gint i;
- strv = g_settings_get_strv (this->priv->history, "recent-templates");
+ strv = g_settings_get_strv (this->priv->history, "recent-fonts");
/*
* Proof read name list; transfer storage to new list.
diff --git a/src/template-history-model.c b/src/template-history-model.c
index 1e53862..7c1cc47 100644
--- a/src/template-history-model.c
+++ b/src/template-history-model.c
@@ -144,7 +144,7 @@ gl_template_history_model_new (guint n)
/*****************************************************************************/
-/* Add template to history. */
+/* Add template to history. */
/*****************************************************************************/
void
gl_template_history_model_add_name (glTemplateHistoryModel *this,
@@ -152,17 +152,22 @@ gl_template_history_model_add_name (glTemplateHistoryModel *this,
{
gchar **old;
gchar **new;
- gint i;
+ gint i, j;
old = g_settings_get_strv (this->priv->history, "recent-templates");
new = g_new0 (gchar *, this->priv->max_n+1);
+ /* Put in first slot. */
new[0] = g_strdup (name);
- for ( i = 0; (i < (this->priv->max_n-1)) && old[i]; i++ )
+ /* Push everthing else down, pruning any duplicate found. */
+ for ( i = 0, j = 1; (j < (this->priv->max_n-1)) && old[i]; i++ )
{
- new[i+1] = g_strdup (old[i]);
+ if ( lgl_str_utf8_casecmp (name, old[i]) != 0 )
+ {
+ new[j++] = g_strdup (old[i]);
+ }
}
g_settings_set_strv (this->priv->history, "recent-templates",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]