Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / collect-dlg.c
index 2c03ea3..6bbb0fb 100644 (file)
@@ -1,16 +1,24 @@
 /*
- * Geeqie
- * (C) 2004 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2004 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"
 #include "collect.h"
 #include "collect-dlg.h"
@@ -30,7 +38,7 @@ enum {
 };
 
 
-static gint collection_save_confirmed(FileDialog *fd, gint overwrite, CollectionData *cd);
+static gboolean collection_save_confirmed(FileDialog *fd, gboolean overwrite, CollectionData *cd);
 
 
 static void collection_confirm_ok_cb(GenericDialog *gd, gpointer data)
@@ -50,7 +58,7 @@ static void collection_confirm_cancel_cb(GenericDialog *gd, gpointer data)
        /* this is a no-op, so the cancel button is added */
 }
 
-static gint collection_save_confirmed(FileDialog *fd, gint overwrite, CollectionData *cd)
+static gboolean collection_save_confirmed(FileDialog *fd, gboolean overwrite, CollectionData *cd)
 {
        gchar *buf;
 
@@ -66,7 +74,7 @@ static gint collection_save_confirmed(FileDialog *fd, gint overwrite, Collection
                {
                GenericDialog *gd;
 
-               gd = file_util_gen_dlg(_("Overwrite File"), GQ_WMCLASS, "dlg_confirm",
+               gd = file_util_gen_dlg(_("Overwrite File"), "dlg_confirm",
                                        GENERIC_DIALOG(fd)->dialog, TRUE,
                                        collection_confirm_cancel_cb, fd);
 
@@ -118,8 +126,33 @@ static void collection_save_cb(FileDialog *fd, gpointer data)
 static void real_collection_button_pressed(FileDialog *fd, gpointer data, gint append)
 {
        CollectionData *cd = data;
+       gboolean err = FALSE;
+       gchar *text = NULL;
+
+       if (!isname(fd->dest_path))
+               {
+               err = TRUE;
+               text = g_strdup_printf(_("No such file '%s'."), fd->dest_path);
+               }
+       if (!err && isdir(fd->dest_path))
+               {
+               err = TRUE;
+               text = g_strdup_printf(_("'%s' is a directory, not a collection file."), fd->dest_path);
+               }
+       if (!err && !access_file(fd->dest_path, R_OK))
+               {
+               err = TRUE;
+               text = g_strdup_printf(_("You do not have read permissions on the file '%s'."), fd->dest_path);
+               }
 
-       if (!fd->dest_path || isdir(fd->dest_path)) return;
+       if (err) {
+               if  (text)
+                       {
+                       file_util_warning_dialog(_("Can not open collection file"), text, GTK_STOCK_DIALOG_ERROR, NULL);
+                       g_free(text);
+               }
+               return;
+       }
 
        if (append)
                {
@@ -162,7 +195,6 @@ static void collection_save_or_load_dialog(const gchar *path,
        const gchar *title;
        const gchar *btntext;
        gpointer btnfunc;
-       gchar *base;
        const gchar *stock_id;
 
        if (type == DIALOG_SAVE || type == DIALOG_SAVE_CLOSE)
@@ -194,16 +226,14 @@ static void collection_save_or_load_dialog(const gchar *path,
        cw = collection_window_find(cd);
        if (cw) parent = cw->window;
 
-       fd = file_util_file_dlg(title, GQ_WMCLASS, "dlg_collection", parent,
+       fd = file_util_file_dlg(title, "dlg_collection", parent,
                             collection_save_or_load_dialog_close_cb, cd);
 
        generic_dialog_add_message(GENERIC_DIALOG(fd), NULL, title, NULL);
        file_dialog_add_button(fd, stock_id, btntext, btnfunc, TRUE);
 
-       base = g_build_filename(homedir(), GQ_RC_DIR_COLLECTIONS, NULL);
-       file_dialog_add_path_widgets(fd, base, path,
+       file_dialog_add_path_widgets(fd, get_collections_dir(), path,
                                     "collection_load_save", GQ_COLLECTION_EXT, _("Collection Files"));
-       g_free(base);
 
        fd->type = type;
 
@@ -212,21 +242,6 @@ static void collection_save_or_load_dialog(const gchar *path,
 
 void collection_dialog_save_as(gchar *path, CollectionData *cd)
 {
-#if 0
-       if (!cd->list)
-               {
-               GtkWidget *parent = NULL;
-               CollectWindow *cw;
-
-               cw = collection_window_find(cd);
-               if (cw) parent = cw->window;
-               file_util_warning_dialog(_("Collection empty"),
-                                        _("The current collection is empty, save aborted."),
-                                        GTK_STOCK_DIALOG_INFO, parent);
-               return;
-               }
-#endif
-
        if (!path) path = cd->path;
        if (!path) path = cd->name;