[Xfce4-commits] <xfce-utils:completion> Fix history saving.
Jérôme Guelfucci
noreply at xfce.org
Wed Nov 3 21:04:06 CET 2010
Updating branch refs/heads/completion
to 675b3cdf30bd8bf5fe39bf5ac061a8e4b75907b7 (commit)
from 925dc51c71dfcbd1989a1e233eb4c611e7225758 (commit)
commit 675b3cdf30bd8bf5fe39bf5ac061a8e4b75907b7
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sun Oct 31 13:29:19 2010 +0100
Fix history saving.
xfrun/xfrun-history.c | 93 +++++++++++++++++++++++++++---------------------
xfrun/xfrun-history.h | 1 -
2 files changed, 52 insertions(+), 42 deletions(-)
diff --git a/xfrun/xfrun-history.c b/xfrun/xfrun-history.c
index 1bafdd7..8a29a60 100644
--- a/xfrun/xfrun-history.c
+++ b/xfrun/xfrun-history.c
@@ -43,6 +43,7 @@ static void xfrun_history_free_list (gpointer item,
gpointer user_data);
static gchar **xfrun_history_get_file_content (void);
static GList *xfrun_history_initialize_history (void);
+static void xfrun_history_save (GList *list);
static gchar *xfrun_history_completion_func (gpointer item);
static GCompletion *xfrun_history_initialize_completion (GList *history);
@@ -78,6 +79,9 @@ xfrun_history_finalize (GObject *gobject)
{
XfrunHistory *self = XFRUN_HISTORY (gobject);
+ /* Save history */
+ xfrun_history_save (self->priv->history);
+
/* Free the history list */
if (self->priv->history)
{
@@ -176,6 +180,53 @@ static GList
return list;
}
+static void
+xfrun_history_save (GList *list)
+{
+ GError *error;
+ gchar *history_file;
+ gchar *contents;
+ GList *l;
+
+ if (list == NULL)
+ return;
+
+ error = NULL;
+ contents = g_strdup ("");
+ history_file =
+ xfce_resource_lookup (XFCE_RESOURCE_CACHE, "xfce4/xfrun4/history");
+
+ for (l = list; l != NULL; l = g_list_next (l))
+ {
+ XfrunHistoryItem *item;
+ gchar *tmp;
+
+ item = (XfrunHistoryItem *) l->data;
+
+ tmp = g_strconcat (contents,
+ item->in_terminal ? "1" : "0",
+ ":",
+ item->command,
+ "\n", NULL);
+
+ g_free (contents);
+ contents = tmp;
+ }
+
+ g_printf ("%s", contents);
+
+ if (!g_file_set_contents (history_file, contents, strlen (contents), &error))
+ {
+ xfce_dialog_show_error (NULL, error,
+ _("Error when writing history"));
+
+ g_error_free (error);
+ }
+
+ g_free (contents);
+ g_free (history_file);
+}
+
static gchar
*xfrun_history_completion_func (gpointer item)
{
@@ -442,7 +493,7 @@ void xfrun_history_add (XfrunHistory *history,
g_return_if_fail (command != NULL);
item = g_slice_new (XfrunHistoryItem);
- item->command = command;
+ item->command = g_strdup (command);
item->in_terminal = in_terminal;
/* Add the command to the history list */
@@ -458,47 +509,7 @@ void xfrun_history_add (XfrunHistory *history,
g_list_free (add);
}
-/**
- * xfrun_history_save:
- * @history: a #XfrunHistory
- *
- * Save the history list in the user ressource directory.
- *
- **/
-void xfrun_history_save (XfrunHistory *history)
-{
- GError *error;
- gchar *history_file;
- gchar *contents;
- GList *l;
-
- g_return_if_fail (XFRUN_IS_HISTORY (history));
- error = NULL;
- contents = NULL;
- history_file =
- xfce_resource_lookup (XFCE_RESOURCE_CACHE, "xfce4/xfrun4/history");
-
- for (l = history->priv->history; l != NULL; l = g_list_next (l))
- {
- contents = g_strconcat (contents,
- ((XfrunHistoryItem *)l->data)->command ? "1" : "0",
- ":",
- ((XfrunHistoryItem *)l->data)->command,
- "\n", NULL);
- }
-
- if (!g_file_set_contents (history_file, contents, -1, &error))
- {
- xfce_dialog_show_error (NULL, error,
- _("Error when writing history"));
-
- g_error_free (error);
- }
-
- g_free (contents);
- g_free (history_file);
-}
/**
* xfrun_history_new
diff --git a/xfrun/xfrun-history.h b/xfrun/xfrun-history.h
index 64191fe..c4bbffb 100644
--- a/xfrun/xfrun-history.h
+++ b/xfrun/xfrun-history.h
@@ -72,7 +72,6 @@ void xfrun_history_completion_reset (XfrunHistory *history);
void xfrun_history_add (XfrunHistory *history,
gchar *command,
gboolean in_terminal);
-void xfrun_history_save (XfrunHistory *history);
XfrunHistory *xfrun_history_new (void);
More information about the Xfce4-commits
mailing list