Remove commented out code.
[geeqie.git] / src / collect-dlg.c
index 009e4db..2194d77 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -10,7 +11,7 @@
  */
 
 
-#include "gqview.h"
+#include "main.h"
 #include "collect.h"
 #include "collect-dlg.h"
 
@@ -29,7 +30,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)
@@ -49,7 +50,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;
 
@@ -65,7 +66,7 @@ static gint collection_save_confirmed(FileDialog *fd, gint overwrite, Collection
                {
                GenericDialog *gd;
 
-               gd = file_util_gen_dlg(_("Overwrite File"), "Geeqie", "dlg_confirm",
+               gd = file_util_gen_dlg(_("Overwrite File"), "dlg_confirm",
                                        GENERIC_DIALOG(fd)->dialog, TRUE,
                                        collection_confirm_cancel_cb, fd);
 
@@ -101,11 +102,12 @@ static void collection_save_cb(FileDialog *fd, gpointer data)
        const gchar *path;
 
        path = fd->dest_path;
-       
-       if (!(strlen(path) > 7 && strncasecmp(path + (strlen(path) - 4), ".gqv", 4) == 0))
+
+       /* FIXME: utf8 */
+       if (!file_extension_match(path, GQ_COLLECTION_EXT))
                {
                gchar *buf;
-               buf = g_strconcat(path, ".gqv", NULL);
+               buf = g_strconcat(path, GQ_COLLECTION_EXT, NULL);
                gtk_entry_set_text(GTK_ENTRY(fd->entry), buf);
                g_free(buf);
                }
@@ -116,8 +118,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 (!fd->dest_path || isdir(fd->dest_path)) return;
+       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 (err) {
+               if  (text)
+                       {
+                       file_util_warning_dialog(_("Can not open collection file"), text, GTK_STOCK_DIALOG_ERROR, NULL);
+                       g_free(text);
+               }
+               return;
+       }
 
        if (append)
                {
@@ -159,8 +186,7 @@ static void collection_save_or_load_dialog(const gchar *path,
        CollectWindow *cw;
        const gchar *title;
        const gchar *btntext;
-       void *btnfunc;
-       gchar *base;
+       gpointer btnfunc;
        const gchar *stock_id;
 
        if (type == DIALOG_SAVE || type == DIALOG_SAVE_CLOSE)
@@ -192,16 +218,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, "Geeqie", "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_strconcat(homedir(), "/", GQVIEW_RC_DIR_COLLECTIONS, NULL);
-       file_dialog_add_path_widgets(fd, base, path,
-                                    "collection_load_save", ".gqv", _("Collection Files"));
-       g_free(base);
+       file_dialog_add_path_widgets(fd, get_collections_dir(), path,
+                                    "collection_load_save", GQ_COLLECTION_EXT, _("Collection Files"));
 
        fd->type = type;
 
@@ -210,21 +234,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;
 
@@ -248,4 +257,4 @@ void collection_dialog_append(gchar *path, CollectionData *cd)
 {
        collection_save_or_load_dialog(path, DIALOG_APPEND, cd);
 }
-
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */