Refactor: move view_file implementations to their own subdirectory.
[geeqie.git] / src / view_file.c
index e0c2419..d537e8a 100644 (file)
@@ -1,17 +1,29 @@
 /*
- * Geeqie
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: Laurent Monin
  *
- * 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 "view_file.h"
 
+#include "dupe.h"
+#include "collect.h"
+#include "collect-table.h"
 #include "editors.h"
 #include "layout.h"
 #include "menu.h"
@@ -19,8 +31,8 @@
 #include "ui_menu.h"
 #include "ui_fileops.h"
 #include "utilops.h"
-#include "view_file_list.h"
-#include "view_file_icon.h"
+#include "view_file/view_file_list.h"
+#include "view_file/view_file_icon.h"
 
 /*
  *-----------------------------------------------------------------------------
@@ -392,6 +404,24 @@ static void vf_pop_menu_enable_grouping_cb(GtkWidget *widget, gpointer data)
        file_data_disable_grouping_list(vf_pop_menu_file_list(vf), FALSE);
 }
 
+static void vf_pop_menu_duplicates_cb(GtkWidget *widget, gpointer data)
+{
+       ViewFile *vf = data;
+       DupeWindow *dw;
+
+       dw = dupe_window_new();
+       dupe_window_add_files(dw, vf_pop_menu_file_list(vf), FALSE);
+}
+
+static void vf_pop_menu_add_collection_cb(GtkWidget *widget, gpointer data)
+{
+       ViewFile *vf = data;
+       CollectWindow *w;
+
+       w = collection_window_new(NULL);
+       collection_table_add_filelist(w->table, vf_pop_menu_file_list(vf));
+}
+
 static void vf_pop_menu_disable_grouping_cb(GtkWidget *widget, gpointer data)
 {
        ViewFile *vf = data;
@@ -606,6 +636,12 @@ GtkWidget *vf_pop_menu(ViewFile *vf)
                                G_CALLBACK(vf_pop_menu_disable_grouping_cb), vf);
 
        menu_item_add_divider(menu);
+       menu_item_add_stock_sensitive(menu, _("_Find duplicates..."), GTK_STOCK_FIND, active,
+                               G_CALLBACK(vf_pop_menu_duplicates_cb), vf);
+       menu_item_add_divider(menu);
+       menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, active,
+                               G_CALLBACK(vf_pop_menu_add_collection_cb), vf);
+       menu_item_add_divider(menu);
 
        submenu = submenu_add_sort(NULL, G_CALLBACK(vf_pop_menu_sort_cb), vf,
                                   FALSE, FALSE, TRUE, vf->sort_method);
@@ -633,7 +669,7 @@ GtkWidget *vf_pop_menu(ViewFile *vf)
                                    G_CALLBACK(vficon_pop_menu_show_names_cb), vf);
                break;
        }
-       
+
        menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vf_pop_menu_refresh_cb), vf);
 
        return menu;
@@ -661,7 +697,7 @@ gboolean vf_set_fd(ViewFile *vf, FileData *dir_fd)
        case FILEVIEW_LIST: ret = vflist_set_fd(vf, dir_fd); break;
        case FILEVIEW_ICON: ret = vficon_set_fd(vf, dir_fd); break;
        }
-       
+
        return ret;
 }
 
@@ -698,9 +734,9 @@ static GtkWidget *vf_marks_filter_init(ViewFile *vf)
 {
        GtkWidget *frame = gtk_frame_new(NULL);
        GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
-       
+
        gint i;
-       
+
        for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
                {
                GtkWidget *check = gtk_check_button_new();
@@ -728,7 +764,7 @@ ViewFile *vf_new(FileViewType type, FileData *dir_fd)
        ViewFile *vf;
 
        vf = g_new0(ViewFile, 1);
-       
+
        vf->type = type;
        vf->sort_method = SORT_NAME;
        vf->sort_ascend = TRUE;
@@ -737,14 +773,14 @@ ViewFile *vf_new(FileViewType type, FileData *dir_fd)
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-       
+
        vf->filter = vf_marks_filter_init(vf);
 
        vf->widget = gtk_vbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
        gtk_widget_show(vf->scrolled);
-       
+
        g_signal_connect(G_OBJECT(vf->widget), "destroy",
                         G_CALLBACK(vf_destroy_cb), vf);
 
@@ -799,19 +835,19 @@ static gdouble vf_thumb_progress(ViewFile *vf)
 {
        gint count = 0;
        gint done = 0;
-       
+
        switch (vf->type)
        {
        case FILEVIEW_LIST: vflist_thumb_progress_count(vf->list, &count, &done); break;
        case FILEVIEW_ICON: vficon_thumb_progress_count(vf->list, &count, &done); break;
        }
-       
+
        DEBUG_1("thumb progress: %d of %d", done, count);
        return (gdouble)done / count;
 }
 
 static void vf_set_thumb_fd(ViewFile *vf, FileData *fd)
-{      
+{
        switch (vf->type)
        {
        case FILEVIEW_LIST: vflist_set_thumb_fd(vf, fd); break;
@@ -878,11 +914,7 @@ static gboolean vf_thumb_next(ViewFile *vf)
 {
        FileData *fd = NULL;
 
-#if GTK_CHECK_VERSION(2,20,0)
        if (!gtk_widget_get_realized(vf->listview))
-#else
-       if (!GTK_WIDGET_REALIZED(vf->listview))
-#endif
                {
                vf_thumb_status(vf, 0.0, NULL);
                return FALSE;
@@ -936,7 +968,7 @@ static void vf_thumb_reset_all(ViewFile *vf)
 void vf_thumb_update(ViewFile *vf)
 {
        vf_thumb_stop(vf);
-       
+
        if (vf->type == FILEVIEW_LIST && !VFLIST(vf)->thumbs_enabled) return;
 
        vf_thumb_status(vf, 0.0, _("Loading thumbs..."));
@@ -976,7 +1008,7 @@ guint vf_marks_get_filter(ViewFile *vf)
        guint ret = 0;
        gint i;
        if (!vf->marks_enabled) return 0;
-       
+
        for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
                {
                if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
@@ -1045,13 +1077,13 @@ void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
        /* FIXME: NOTIFY_METADATA should be checked by the keyword-to-mark functions and converted to NOTIFY_MARKS only if there was a change */
 
        if (!(type & interested) || vf->refresh_idle_id || !vf->dir_fd) return;
-       
+
        refresh = (fd == vf->dir_fd);
 
        if (!refresh)
                {
                gchar *base = remove_level_from_path(fd->path);
-               refresh = (strcmp(base, vf->dir_fd->path) == 0);
+               refresh = (g_strcmp0(base, vf->dir_fd->path) == 0);
                g_free(base);
                }
 
@@ -1060,18 +1092,18 @@ void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
                if (!refresh && fd->change->dest)
                        {
                        gchar *dest_base = remove_level_from_path(fd->change->dest);
-                       refresh = (strcmp(dest_base, vf->dir_fd->path) == 0);
+                       refresh = (g_strcmp0(dest_base, vf->dir_fd->path) == 0);
                        g_free(dest_base);
                        }
 
                if (!refresh && fd->change->source)
                        {
                        gchar *source_base = remove_level_from_path(fd->change->source);
-                       refresh = (strcmp(source_base, vf->dir_fd->path) == 0);
+                       refresh = (g_strcmp0(source_base, vf->dir_fd->path) == 0);
                        g_free(source_base);
                        }
                }
-       
+
        if (refresh)
                {
                DEBUG_1("Notify vf: %s %04x", fd->path, type);