Fix #130: Doubled path in thumbnail preferences
[geeqie.git] / src / cache_maint.c
index c85c083..2e5a7bb 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "main.h"
@@ -23,6 +32,7 @@
 #include "ui_spinner.h"
 #include "ui_tabcomp.h"
 #include "ui_utildlg.h"
+#include "window.h"
 
 
 typedef struct _CMData CMData;
@@ -49,25 +59,6 @@ struct _CMData
  *-------------------------------------------------------------------
  */
 
-#if 0
-static gint extension_truncate(gchar *path, const gchar *ext)
-{
-       gint l;
-       gint el;
-
-       if (!path || !ext) return FALSE;
-
-       l = strlen(path);
-       el = strlen(ext);
-
-       if (l < el || strcmp(path + (l - el), ext) != 0) return FALSE;
-
-       path[l - el] = '\0';
-
-       return TRUE;
-}
-#endif
-
 static gchar *extension_find_dot(gchar *path)
 {
        gchar *dot = NULL;
@@ -256,7 +247,7 @@ static void cache_maintain_home_close_cb(GenericDialog *gd, gpointer data)
 {
        CMData *cm = data;
 
-       if (!GTK_WIDGET_SENSITIVE(cm->button_close)) return;
+       if (!gtk_widget_get_sensitive(cm->button_close)) return;
 
        cache_maintain_home_close(cm);
 }
@@ -287,7 +278,7 @@ void cache_maintain_home(gboolean metadata, gboolean clear, GtkWidget *parent)
                cache_folder = get_thumbnails_cache_dir();
                }
 
-       dir_fd = file_data_new_simple(cache_folder);
+       dir_fd = file_data_new_dir(cache_folder);
        if (!filelist_read(dir_fd, NULL, &dlist))
                {
                file_data_unref(dir_fd);
@@ -334,7 +325,7 @@ void cache_maintain_home(gboolean metadata, gboolean clear, GtkWidget *parent)
        gtk_widget_show(hbox);
 
        cm->entry = gtk_entry_new();
-       GTK_WIDGET_UNSET_FLAGS(cm->entry, GTK_CAN_FOCUS);
+       gtk_widget_set_can_focus(cm->entry, FALSE);
        gtk_editable_set_editable(GTK_EDITABLE(cm->entry), FALSE);
        gtk_box_pack_start(GTK_BOX(hbox), cm->entry, TRUE, TRUE, 0);
        gtk_widget_show(cm->entry);
@@ -348,160 +339,6 @@ void cache_maintain_home(gboolean metadata, gboolean clear, GtkWidget *parent)
        cm->idle_id = g_idle_add(cache_maintain_home_cb, cm);
 }
 
-#if 0
-/* This checks all files in ~/GQ_RC_DIR/thumbnails and
- * removes them if thay have no source counterpart.
- * (this assumes all cache files have an extension of 4 chars including '.')
- */
-gint cache_maintain_home_dir(const gchar *dir, gint recursive, gint clear)
-{
-       gchar *base;
-       gint base_length;
-       GList *dlist = NULL;
-       FileData *dir_fd;
-       GList *flist = NULL;
-       gboolean still_have_a_file = FALSE;
-
-       DEBUG_1("maintainance check: %s", dir);
-
-       base_length = strlen(homedir()) + strlen("/") + strlen(GQ_CACHE_RC_THUMB);
-       base = g_strconcat(homedir(), "/", GQ_CACHE_RC_THUMB, dir, NULL);
-       dir_fd = file_data_new_simple(base);
-       g_free(base);
-
-       if (filelist_read(dir_fd, &flist, &dlist))
-               {
-               GList *work;
-
-               work = dlist;
-               while (work)
-                       {
-                       FileData *fd = work->data;
-                       if (recursive && strlen(fd->path) > base_length &&
-                           !cache_maintain_home_dir(fd->path + base_length, recursive, clear))
-                               {
-                               DEBUG_1("Deleting thumb dir: %s", fd->path);
-                               if (!rmdir_utf8(fd->path))
-                                       {
-                                       log_printf("Unable to delete dir: %s\n", fd->path);
-                                       }
-                               }
-                       else
-                               {
-                               still_have_a_file = TRUE;
-                               }
-                       work = work->next;
-                       }
-
-               work = flist;
-               while (work)
-                       {
-                       FileData *fd = work->data;
-                       gchar *path = g_strdup(fd->path);
-                       gchar *dot;
-
-                       dot = extension_find_dot(path);
-
-                       if (dot) *dot = '\0';
-                       if (clear ||
-                           (strlen(path) > base_length && !isfile(path + base_length)) )
-                               {
-                               if (dot) *dot = '.';
-                               if (!unlink_file(path)) log_printf("failed to delete:%s\n", path);
-                               }
-                       else
-                               {
-                               still_have_a_file = TRUE;
-                               }
-                       g_free(path);
-
-                       work = work->next;
-                       }
-               }
-
-       filelist_free(dlist);
-       filelist_free(flist);
-       file_data_unref(dir_fd);
-
-       return still_have_a_file;
-}
-
-/* This checks relative caches in dir/.thumbnails and
- * removes them if they have no source counterpart.
- */
-gint cache_maintain_dir(FileData *dir_fd, gint recursive, gint clear)
-{
-       GList *list = NULL;
-       gchar *cachedir;
-       FileData *cachedir_fd;
-       gboolean still_have_a_file = FALSE;
-       GList *work;
-
-       cachedir = g_build_filename(dir, GQ_CACHE_LOCAL_THUMB, NULL);
-       cachedir_fd = file_data_new_simple(cachedir);
-       g_free(cachedir);
-
-       filelist_read(cachedir_fd, &list, NULL);
-       work = list;
-
-       while (work)
-               {
-               FileData *fd;
-               gchar *source;
-
-               fd = work->data;
-               work = work->next;
-
-               source = g_build_filename(dir->path, fd->name, NULL);
-
-               if (clear ||
-                   extension_truncate(source, GQ_CACHE_EXT_THUMB) ||
-                   extension_truncate(source, GQ_CACHE_EXT_SIM))
-                       {
-                       if (!clear && isfile(source))
-                               {
-                               still_have_a_file = TRUE;
-                               }
-                       else
-                               {
-                               if (!unlink_file(fd->path))
-                                       {
-                                       DEBUG_1("Failed to remove cache file %s", fd->path);
-                                       still_have_a_file = TRUE;
-                                       }
-                               }
-                       }
-               else
-                       {
-                       still_have_a_file = TRUE;
-                       }
-               g_free(source);
-               }
-
-       filelist_free(list);
-       file_data_unref(cachedir_fd);
-
-       if (recursive)
-               {
-               list = NULL;
-
-               filelist_read(dir_fd, NULL, &list);
-               work = list;
-               while (work)
-                       {
-                       FileData *fd = work->data;
-                       work = work->next;
-
-                       still_have_a_file |= cache_maintain_dir(fd->path, recursive, clear);
-                       }
-
-               filelist_free(list);
-               }
-
-       return still_have_a_file;
-}
-#endif
-
 static void cache_file_move(const gchar *src, const gchar *dest)
 {
        if (!dest || !src || !isfile(src)) return;
@@ -622,7 +459,7 @@ static void cache_maint_copied(FileData *fd)
 void cache_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
        if (!(type & NOTIFY_CHANGE) || !fd->change) return;
-       
+
        DEBUG_1("Notify cache_maint: %s %04x", fd->path, type);
        switch (fd->change->type)
                {
@@ -708,7 +545,7 @@ static void cache_manager_render_close_cb(GenericDialog *fd, gpointer data)
 {
        CleanData *cd = data;
 
-       if (!GTK_WIDGET_SENSITIVE(cd->button_close)) return;
+       if (!gtk_widget_get_sensitive(cd->button_close)) return;
 
        cache_manager_render_reset(cd);
        generic_dialog_close(cd->gd);
@@ -823,7 +660,7 @@ static void cache_manager_render_start_cb(GenericDialog *fd, gpointer data)
        CleanData *cd = data;
        gchar *path;
 
-       if (cd->list || !GTK_WIDGET_SENSITIVE(cd->button_start)) return;
+       if (cd->list || !gtk_widget_get_sensitive(cd->button_start)) return;
 
        path = remove_trailing_slash((gtk_entry_get_text(GTK_ENTRY(cd->entry))));
        parse_out_relatives(path);
@@ -844,7 +681,7 @@ static void cache_manager_render_start_cb(GenericDialog *fd, gpointer data)
 
                spinner_set_interval(cd->spinner, SPINNER_SPEED);
 
-               dir_fd = file_data_new_simple(path);
+               dir_fd = file_data_new_dir(path);
                cache_manager_render_folder(cd, dir_fd);
                file_data_unref(dir_fd);
                while (cache_manager_render_file(cd));
@@ -898,7 +735,7 @@ static void cache_manager_render_dialog(GtkWidget *widget, const gchar *path)
        hbox = pref_box_new(cd->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
 
        cd->progress = gtk_entry_new();
-       GTK_WIDGET_UNSET_FLAGS(cd->progress, GTK_CAN_FOCUS);
+       gtk_widget_set_can_focus(cd->progress, FALSE);
        gtk_editable_set_editable(GTK_EDITABLE(cd->progress), FALSE);
        gtk_entry_set_text(GTK_ENTRY(cd->progress), _("click start to begin"));
        gtk_box_pack_start(GTK_BOX(hbox), cd->progress, TRUE, TRUE, 0);
@@ -920,7 +757,7 @@ static void cache_manager_standard_clean_close_cb(GenericDialog *gd, gpointer da
 {
        CleanData *cd = data;
 
-       if (!GTK_WIDGET_SENSITIVE(cd->button_close)) return;
+       if (!gtk_widget_get_sensitive(cd->button_close)) return;
 
        generic_dialog_close(cd->gd);
 
@@ -1033,7 +870,7 @@ static void cache_manager_standard_clean_start_cb(GenericDialog *gd, gpointer da
        gchar *path;
        FileData *dir_fd;
 
-       if (cd->list || !GTK_WIDGET_SENSITIVE(cd->button_start)) return;
+       if (cd->list || !gtk_widget_get_sensitive(cd->button_start)) return;
 
        gtk_widget_set_sensitive(cd->button_start, FALSE);
        gtk_widget_set_sensitive(cd->button_stop, TRUE);
@@ -1042,21 +879,21 @@ static void cache_manager_standard_clean_start_cb(GenericDialog *gd, gpointer da
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(cd->progress), _("running..."));
 
        path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_NORMAL, NULL);
-       dir_fd = file_data_new_simple(path);
+       dir_fd = file_data_new_dir(path);
        filelist_read(dir_fd, &list, NULL);
        cd->list = list;
        file_data_unref(dir_fd);
        g_free(path);
 
        path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_LARGE, NULL);
-       dir_fd = file_data_new_simple(path);
+       dir_fd = file_data_new_dir(path);
        filelist_read(dir_fd, &list, NULL);
        cd->list = g_list_concat(cd->list, list);
        file_data_unref(dir_fd);
        g_free(path);
 
        path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, THUMB_FOLDER_FAIL, NULL);
-       dir_fd = file_data_new_simple(path);
+       dir_fd = file_data_new_dir(path);
        filelist_read(dir_fd, &list, NULL);
        cd->list = g_list_concat(cd->list, list);
        file_data_unref(dir_fd);
@@ -1113,6 +950,9 @@ static void cache_manager_standard_process(GtkWidget *widget, gboolean clear)
 
        cd->progress = gtk_progress_bar_new();
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(cd->progress), _("click start to begin"));
+#if GTK_CHECK_VERSION(3,0,0)
+       gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(cd->progress), TRUE);
+#endif
        gtk_box_pack_start(GTK_BOX(cd->gd->vbox), cd->progress, FALSE, FALSE, 0);
        gtk_widget_show(cd->progress);
 
@@ -1193,19 +1033,21 @@ static void cache_manager_close_cb(GenericDialog *gd, gpointer data)
        cache_manager = NULL;
 }
 
+static void cache_manager_help_cb(GenericDialog *gd, gpointer data)
+{
+       help_window_show("GuideReferenceManagement.html");
+}
+
 static GtkWidget *cache_manager_location_label(GtkWidget *group, const gchar *subdir)
 {
        GtkWidget *label;
        gchar *buf;
-       gchar *path;
 
-       path = g_build_filename(homedir(), subdir, NULL);
-       buf = g_strdup_printf(_("Location: %s"), path);
-       g_free(path);
+       buf = g_strdup_printf(_("Location: %s"), subdir);
        label = pref_label_new(group, buf);
        g_free(buf);
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
-       
+
        return label;
 }
 
@@ -1216,6 +1058,7 @@ void cache_manager_show(void)
        GtkWidget *button;
        GtkWidget *table;
        GtkSizeGroup *sizegroup;
+       gchar *path;
 
        if (cache_manager)
                {
@@ -1234,6 +1077,8 @@ void cache_manager_show(void)
        gd->cancel_cb = cache_manager_close_cb;
        generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL,
                                  cache_manager_close_cb, FALSE);
+       generic_dialog_add_button(gd, GTK_STOCK_HELP, NULL,
+                                 cache_manager_help_cb, FALSE);
 
        generic_dialog_add_message(gd, NULL, _("Cache and Data Maintenance"), NULL);
 
@@ -1258,7 +1103,9 @@ void cache_manager_show(void)
 
        group = pref_group_new(gd->vbox, FALSE, _("Shared thumbnail cache"), GTK_ORIENTATION_VERTICAL);
 
-       cache_manager_location_label(group, THUMB_FOLDER_GLOBAL);
+       path = g_build_filename(homedir(), THUMB_FOLDER_GLOBAL, NULL);
+       cache_manager_location_label(group, path);
+       g_free(path);
 
        table = pref_table_new(group, 2, 2, FALSE, FALSE);