summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Evins <evins@snaught.com>2010-07-25 23:55:40 -0400
committerJim Evins <evins@snaught.com>2010-07-25 23:55:40 -0400
commit618369ea3dd7525782ed580c1d065340ef5d041f (patch)
tree52de249b49f3711e1c5567cca77905d92b2e56e5
parent0427d07a57226b17b17f6b400dc5d12d0db8acac (diff)
Fixed several bugs with use of GSettings.gsettings
Fixed crash in recent-colors. Prune duplicates in recent-templates and recent-fonts. Fixed cut&paste problem with recent-fonts.
-rw-r--r--src/color-history-model.c10
-rw-r--r--src/font-history-model.c17
-rw-r--r--src/template-history-model.c13
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",