[Xfce4-commits] <xfce4-clipman-plugin:master> Properly remove cache files on history clear (bug 6324)
Mike Massonnet
noreply at xfce.org
Sat May 7 22:50:02 CEST 2011
Updating branch refs/heads/master
to ed1930a4838b44876596fd773d55728c7289c7a7 (commit)
from 93f8273f5dc8e51a37b9545ca4d0e0d1ccf33152 (commit)
commit ed1930a4838b44876596fd773d55728c7289c7a7
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Sat May 7 22:53:32 2011 +0200
Properly remove cache files on history clear (bug 6324)
panel-plugin/history.c | 10 ++++++++++
panel-plugin/history.h | 2 ++
panel-plugin/plugin.c | 23 +++++++++++++++++++----
3 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/panel-plugin/history.c b/panel-plugin/history.c
index 5829e02..b6c1e58 100644
--- a/panel-plugin/history.c
+++ b/panel-plugin/history.c
@@ -58,6 +58,7 @@ enum
enum
{
ITEM_ADDED,
+ CLEAR,
LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL];
@@ -359,6 +360,8 @@ clipman_history_clear (ClipmanHistory *history)
history->priv->images = NULL;
history->priv->item_to_restore = NULL;
+
+ g_signal_emit (history, signals[CLEAR], 0);
}
ClipmanHistory *
@@ -402,6 +405,13 @@ clipman_history_class_init (ClipmanHistoryClass *klass)
0, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ signals[CLEAR] =
+ g_signal_new ("clear", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST|G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (ClipmanHistoryClass, clear),
+ 0, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
g_object_class_install_property (object_class,
MAX_TEXTS_IN_HISTORY,
g_param_spec_uint ("max-texts-in-history",
diff --git a/panel-plugin/history.h b/panel-plugin/history.h
index 1b205dc..b0df827 100644
--- a/panel-plugin/history.h
+++ b/panel-plugin/history.h
@@ -72,6 +72,8 @@ struct _ClipmanHistoryClass
void
(*item_added) (ClipmanHistory *history);
+ void
+ (*clear) (ClipmanHistory *history);
};
struct _ClipmanHistory
diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c
index 39a3988..47cb088 100644
--- a/panel-plugin/plugin.c
+++ b/panel-plugin/plugin.c
@@ -120,6 +120,8 @@ plugin_register (void)
/* Connect signal to save content */
g_signal_connect_swapped (plugin->history, "item-added",
G_CALLBACK (plugin_save), plugin);
+ g_signal_connect_swapped (plugin->history, "clear",
+ G_CALLBACK (plugin_save), plugin);
/* Set the selection for the popup command */
my_plugin_set_popup_selection (plugin);
@@ -186,18 +188,31 @@ plugin_save (MyPlugin *plugin)
const gchar **texts;
gchar *data;
gchar *filename;
+ gchar *dirname;
+ const gchar *name;
gint n_texts, n_images;
gboolean save_on_quit;
+ GDir *dir;
+
+ /* Create initial directory and remove cache files */
+ dirname = xfce_resource_save_location (XFCE_RESOURCE_CACHE, "xfce4/clipman/", TRUE);
+
+ dir = g_dir_open (dirname, 0, NULL);
+ while ((name = g_dir_read_name (dir)) != NULL)
+ {
+ filename = g_build_filename (dirname, name, NULL);
+ g_unlink (filename);
+ g_free (filename);
+ }
+ g_dir_close (dir);
+
+ g_free (dirname);
/* Return if the history must not be saved */
g_object_get (plugin->history, "save-on-quit", &save_on_quit, NULL);
if (save_on_quit == FALSE)
return;
- /* Create initial directory */
- filename = xfce_resource_save_location (XFCE_RESOURCE_CACHE, "xfce4/clipman/", TRUE);
- g_free (filename);
-
/* Save the history */
list = clipman_history_get_list (plugin->history);
list = g_slist_reverse (list);
More information about the Xfce4-commits
mailing list