]> Pileus Git - aweather/commitdiff
Add "Clean Cache" feature
authorAndy Spencer <andy753421@gmail.com>
Tue, 18 May 2010 05:42:43 +0000 (22:42 -0700)
committerAndy Spencer <andy753421@gmail.com>
Tue, 18 May 2010 05:42:43 +0000 (22:42 -0700)
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
data/main.ui.in
src/aweather-gui.c

index 29dadf21616785a734a12ef96f27901b9842dfd3..bec25f696586c6dddad81245b3c7635a1a436c0d 100644 (file)
@@ -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:
index 8f178b9c54918e3b8be81749e093e45c5f40aa74..00676645bccce028bec4f8750555f5cf6f68732c 100644 (file)
                       <object class="GtkCheckMenuItem" id="main_menu_file_offline">
                         <property name="visible">True</property>
                         <property name="tooltip_text" translatable="yes">Work offline</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">offline</property>
+                        <property name="use_action_appearance">True</property>
                       </object>
                     </child>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_file_prefs">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">prefs</property>
+                        <property name="use_action_appearance">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="main_menu_file_cleancache">
+                        <property name="visible">True</property>
+                        <property name="related_action">cleancache</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
@@ -71,8 +80,8 @@
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_file_quit">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">quit</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_view_zoomin">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">zoomin</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_view_zoomout">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">zoomout</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_view_refresh">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">refresh</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_help_contents">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">contents</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_help_contents"/>
                       </object>
                     </child>
                     <child>
                     <child>
                       <object class="GtkImageMenuItem" id="main_menu_help_about">
                         <property name="visible">True</property>
-                        <property name="use_action_appearance">True</property>
                         <property name="related_action">about</property>
+                        <property name="use_action_appearance">True</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                       </object>
             <child>
               <object class="GtkToolButton" id="main_tb_zoomin">
                 <property name="visible">True</property>
-                <property name="use_action_appearance">True</property>
                 <property name="related_action">zoomin</property>
+                <property name="use_action_appearance">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
             <child>
               <object class="GtkToolButton" id="main_tb_zoomout">
                 <property name="visible">True</property>
-                <property name="use_action_appearance">True</property>
                 <property name="related_action">zoomout</property>
+                <property name="use_action_appearance">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
             <child>
               <object class="GtkToggleToolButton" id="main_tb_offline">
                 <property name="visible">True</property>
-                <property name="use_action_appearance">True</property>
                 <property name="related_action">offline</property>
+                <property name="use_action_appearance">True</property>
                 <property name="label" translatable="yes">toolbutton3</property>
                 <property name="use_underline">True</property>
               </object>
             <child>
               <object class="GtkToolButton" id="main_tb_refresh">
                 <property name="visible">True</property>
-                <property name="use_action_appearance">True</property>
                 <property name="related_action">refresh</property>
+                <property name="use_action_appearance">True</property>
                 <property name="use_underline">True</property>
               </object>
               <packing>
             <child>
               <object class="GtkToolButton" id="main_tb_prefs">
                 <property name="visible">True</property>
-                <property name="use_action_appearance">True</property>
                 <property name="related_action">prefs</property>
+                <property name="use_action_appearance">True</property>
                 <property name="label" translatable="yes">toolbutton1</property>
                 <property name="use_underline">True</property>
               </object>
@@ -926,9 +934,9 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
   </object>
   <object class="GtkSizeGroup" id="prefs_general_size">
     <widgets>
-      <widget name="prefs_general_site_label"/>
-      <widget name="prefs_general_url_label"/>
       <widget name="prefs_general_log_label"/>
+      <widget name="prefs_general_url_label"/>
+      <widget name="prefs_general_site_label"/>
     </widgets>
   </object>
   <object class="GtkAdjustment" id="prefs_general_log_adj">
@@ -940,5 +948,13 @@ The hypothetical commands `show w' and `show c' should show the appropriate part
     <property name="short_label">Contents</property>
     <property name="tooltip">AWeather Reference Manual</property>
     <property name="stock_id">gtk-help</property>
+    <signal name="activate" handler="on_contents"/>
+  </object>
+  <object class="GtkAction" id="cleancache">
+    <property name="label">Clean cache</property>
+    <property name="short_label">Clean cache</property>
+    <property name="tooltip">Clean out old cached files</property>
+    <property name="stock_id">gtk-clear</property>
+    <signal name="activate" handler="on_cleancache"/>
   </object>
 </interface>
index 41069b0c2603360b4cc04f818116ee748bfeac78..59dbfaab6b9cb6aaa0c11c939d67c6a8d7e95662 100644 (file)
@@ -18,6 +18,7 @@
 #include <config.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
+#include <glib/gstdio.h>
 #include <math.h>
 
 #include <gis.h>
@@ -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");