From 8cca8454eaaddb82174ebad9d02fa5b3094c89dd Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 17 May 2010 22:42:43 -0700 Subject: [PATCH] Add "Clean Cache" feature This deletes any cached files that are more than a day old, based on their mtime. It might be useful to touch files when they are used in order to keep them from being deleted. --- data/Makefile.am | 3 +++ data/main.ui.in | 48 ++++++++++++++++++++++++++++++---------------- src/aweather-gui.c | 32 ++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 17 deletions(-) diff --git a/data/Makefile.am b/data/Makefile.am index 29dadf2..bec25f6 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -14,6 +14,9 @@ pixmapdir = $(datadir)/pixmaps dist_pixmap_DATA = aweather.png endif +glade: + GLADE_CATALOG_PATH=. glade-3 main.ui.in + .svg.png: rsvg -w 48 -h 48 $< $@ .png.ico: diff --git a/data/main.ui.in b/data/main.ui.in index 8f178b9..0067664 100644 --- a/data/main.ui.in +++ b/data/main.ui.in @@ -50,15 +50,24 @@ True Work offline - True offline + True True - True prefs + True + True + True + + + + + True + cleancache + True True True @@ -71,8 +80,8 @@ True - True quit + True True True @@ -92,8 +101,8 @@ True - True zoomin + True True True @@ -101,8 +110,8 @@ True - True zoomout + True True True @@ -115,8 +124,8 @@ True - True refresh + True True True @@ -136,11 +145,10 @@ True - True contents + True True True - @@ -151,8 +159,8 @@ True - True about + True True True @@ -174,8 +182,8 @@ True - True zoomin + True False @@ -185,8 +193,8 @@ True - True zoomout + True False @@ -205,8 +213,8 @@ True - True offline + True toolbutton3 True @@ -218,8 +226,8 @@ True - True refresh + True True @@ -239,8 +247,8 @@ True - True prefs + True toolbutton1 True @@ -926,9 +934,9 @@ The hypothetical commands `show w' and `show c' should show the appropriate part - - + + @@ -940,5 +948,13 @@ The hypothetical commands `show w' and `show c' should show the appropriate part Contents AWeather Reference Manual gtk-help + + + + Clean cache + Clean cache + Clean out old cached files + gtk-clear + diff --git a/src/aweather-gui.c b/src/aweather-gui.c index 41069b0..59dbfaa 100644 --- a/src/aweather-gui.c +++ b/src/aweather-gui.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,36 @@ G_MODULE_EXPORT gboolean on_gui_key_press(GtkWidget *widget, GdkEventKey *event, return FALSE; } -G_MODULE_EXPORT void on_help_contents(GtkMenuItem *menu, AWeatherGui *self) +static void cleancache_r(gchar *path) +{ + GDir *dir = g_dir_open(path, 0, NULL); + if (!dir) + return; + const gchar *child; + while ((child = g_dir_read_name(dir))) { + gchar *child_path = g_build_filename(path, child, NULL); + if (g_file_test(child_path, G_FILE_TEST_IS_DIR)) { + cleancache_r(child_path); + } else { + struct stat st; + g_stat(child_path, &st); + if (st.st_atime < time(NULL)-60*60*24) + g_remove(child_path); + } + g_free(child_path); + } + g_dir_close(dir); + g_rmdir(path); +} +G_MODULE_EXPORT void on_cleancache(GtkMenuItem *menu, AWeatherGui *self) +{ + g_debug("AWeatherGui: on_cleancache"); + /* Todo: move this to libgis */ + gchar *cache = g_build_filename(g_get_user_cache_dir(), "libgis", NULL); + cleancache_r(cache); +} + +G_MODULE_EXPORT void on_contents(GtkMenuItem *menu, AWeatherGui *self) { GError *err = NULL; gchar *path = g_strdup(HTMLDIR "/aweather.html"); -- 2.43.2