Addl fix #1706: command line duplicate search
authorColin Clark <[email protected]>
Sat, 12 Apr 2025 12:12:07 +0000 (13:12 +0100)
committerColin Clark <[email protected]>
Sat, 12 Apr 2025 12:12:07 +0000 (13:12 +0100)
https://github.com/BestImageViewer/geeqie/issues/1706#issuecomment-2796909310

Additional command line option:
--dupes-export

Uses the last-created duplicates window
Selects all files in that window
Exports the data in tab-separated format
If the comparison is not yet completed, the word "Incomplete" is output

The data format is the same as for the menu item dupes/export menu item

auto-complete/geeqie
src/command-line-handling.cc
src/dupe.cc
src/dupe.h
src/main.cc

index d6ea1ca53356e650f7695ae6d2c4632e6ed80526..14b75f4251eb07d56a75c0c7affde113154eb0ee 100644 (file)
@@ -4,7 +4,7 @@ file_types='@(3fr|ani|arw|avif|bmp|cr2|cr3|crw|cur|dds|djvu|dng|erf|exr|.fits|fi
 
 actions='About AddMark0 AddMark1 AddMark2 AddMark3 AddMark4 AddMark5 AddMark6 AddMark7 AddMark8 AddMark9 AlterNone Animate Back ClearMarks CloseWindow ColorProfile0 ColorProfile1 ColorProfile2 ColorProfile3 ColorProfile4 ColorProfile5 ConnectZoom100 ConnectZoom200 ConnectZoom25 ConnectZoom300 ConnectZoom33 ConnectZoom400 ConnectZoom50 ConnectZoomFillHor ConnectZoomFillVert ConnectZoomFit ConnectZoomIn ConnectZoomOut Copy CopyImage CopyPath CopyPathUnquoted CropFourThree CropNone CropOneOne CropRectangle CropSixteenNine CropThreeTwo CutPath Delete DeleteWindow DrawRectangle Escape ExifRotate ExifWin FilterMark0 FilterMark1 FilterMark2 FilterMark3 FilterMark4 FilterMark5 FilterMark6 FilterMark7 FilterMark8 FilterMark9 FindDupes FirstImage FirstPage Flip FloatTools FolderTree Forward FullScreen Grayscale HelpChangeLog HelpContents HelpKbd HelpNotes HelpPdf HelpSearch HelpShortcuts HideBars HideSelectableToolbars HideTools HistogramChanB HistogramChanCycle HistogramChanG HistogramChanR HistogramChanRGB HistogramChanV HistogramModeCycle HistogramModeLin HistogramModeLog Home IgnoreAlpha ImageBack ImageForward ImageHistogram ImageOverlay ImageOverlayCycle IntMark0 IntMark1 IntMark2 IntMark3 IntMark4 IntMark5 IntMark6 IntMark7 IntMark8 IntMark9 KeywordAutocomplete LastImage LastPage LayoutConfig LogWindow Maintenance Mark0 Mark1 Mark2 Mark3 Mark4 Mark5 Mark6 Mark7 Mark8 Mark9 Mirror Move NewCollection NewFolder NewWindow NewWindowDefault NewWindowFromCurrent NextImage NextPage OpenArchive OpenCollection OpenFile OpenRecentFile OpenWith OverUnderExposed PanView PermanentDelete Plugins Preferences PrevImage PrevPage Print Quit Rating0 Rating1 Rating2 Rating3 Rating4 Rating5 RatingM1 RectangularSelection Refresh Rename RenameWindow ResetMark0 ResetMark1 ResetMark2 ResetMark3 ResetMark4 ResetMark5 ResetMark6 ResetMark7 ResetMark8 ResetMark9 Rotate180 RotateCCW RotateCW SBar SBarSort SaveMetadata Search SearchAndRunCommand SelectAll SelectInvert SelectMark0 SelectMark1 SelectMark2 SelectMark3 SelectMark4 SelectMark5 SelectMark6 SelectMark7 SelectMark8 SelectMark9 SelectNone SetMark0 SetMark1 SetMark2 SetMark3 SetMark4 SetMark5 SetMark6 SetMark7 SetMark8 SetMark9 ShowFileFilter ShowInfoPixel ShowMarks SlideShow SlideShowFaster SlideShowPause SlideShowSlower SplitDownPane SplitHorizontal SplitNextPane SplitPaneSync SplitPreviousPane SplitQuad SplitSingle SplitTriple SplitUpPane SplitVertical StereoAuto StereoCross StereoCycle StereoOff StereoSBS Thumbnails ToggleMark0 ToggleMark1 ToggleMark2 ToggleMark3 ToggleMark4 ToggleMark5 ToggleMark6 ToggleMark7 ToggleMark8 ToggleMark9 UnselMark0 UnselMark1 UnselMark2 UnselMark3 UnselMark4 UnselMark5 UnselMark6 UnselMark7 UnselMark8 UnselMark9 Up UseColorProfiles UseImageProfile ViewIcons ViewInNewWindow ViewList WriteRotation WriteRotationKeepDate Zoom100 Zoom200 Zoom25 Zoom300 Zoom33 Zoom400 Zoom50 ZoomFillHor ZoomFillVert ZoomFit ZoomIn ZoomOut ZoomToRectangle'
 
-options='--action= --action-list --back --cache-metadata --cache-render= --cache-render-recurse= --cache-render-shared= --cache-render-shared-recurse= --cache-shared= --cache-thumbs= --close-window --config-load= --debug= --delay= --dupes= --dupes-recurse= --file= --File= --file-extensions --first --fullscreen --geometry= --get-collection= --get-collection-list --get-destination= --get-file-info --get-filelist= --get-filelist-recurse= --get-rectangle --get-render-intent --get-selection --get-sidecars= --get-window-list --grep= --id= --last --log-file= --lua= --new-window --next --pixel-info --print0 --quit --raise --selection-add= --selection-clear --selection-remove= --show-log-window --slideshow --slideshow-recurse= --tell --tools --view= --version'
+options='--action= --action-list --back --cache-metadata --cache-render= --cache-render-recurse= --cache-render-shared= --cache-render-shared-recurse= --cache-shared= --cache-thumbs= --close-window --config-load= --debug= --delay= --dupes= --dupes-export --dupes-recurse= --file= --File= --file-extensions --first --fullscreen --geometry= --get-collection= --get-collection-list --get-destination= --get-file-info --get-filelist= --get-filelist-recurse= --get-rectangle --get-render-intent --get-selection --get-sidecars= --get-window-list --grep= --id= --last --log-file= --lua= --new-window --next --pixel-info --print0 --quit --raise --selection-add= --selection-clear --selection-remove= --show-log-window --slideshow --slideshow-recurse= --tell --tools --view= --version'
 
 _geeqie()
 {
index 4c6ddf686016d879a7c342068b3e797b4b456f0b..f1e2674cbf801f841485d1206ec49a22848f3771 100644 (file)
@@ -455,6 +455,15 @@ void gq_dupes(GtkApplication *app, GApplicationCommandLine *app_command_line, GV
        dupe_window_add_folder(folder_path);
 }
 
+void gq_dupes_export(GtkApplication *, GApplicationCommandLine *app_command_line, GVariantDict *, GList *)
+{
+       g_autoptr(GString) output_string = g_string_new(nullptr);
+
+       export_duplicates_data_command_line(output_string);
+
+       g_application_command_line_print(app_command_line, "%s\n", output_string->str);
+}
+
 void gq_dupes_recurse(GtkApplication *app, GApplicationCommandLine *app_command_line, GVariantDict *command_line_options_dict, GList *)
 {
        const gchar *path;
@@ -1449,6 +1458,7 @@ CommandLineOptionEntry command_line_options[] =
        { "delay",                       gq_delay,                       PRIMARY_REMOTE, GUI  },
        { "file",                        gq_file,                        PRIMARY_REMOTE, GUI  },
        { "dupes",                       gq_dupes,                       PRIMARY_REMOTE, GUI  },
+       { "dupes-export",                gq_dupes_export,                PRIMARY_REMOTE, TEXT },
        { "dupes-recurse",               gq_dupes_recurse,               PRIMARY_REMOTE, GUI  },
        { "File",                        gq_File,                        PRIMARY_REMOTE, GUI  },
        { "file-extensions",             gq_file_extensions,             PRIMARY_REMOTE, TEXT },
index 76b9e550a2cf60fce2d3ab06349252cbcf63207c..da9a0eb416ea12f2198cf013456d846720fd7dbe 100644 (file)
@@ -5106,14 +5106,11 @@ static void export_duplicates_data_cancel_cb(FileDialog *, gpointer data)
        export_duplicates_close(edd);
 }
 
-static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
+static void export_duplicates_data(DupeWindow *dw, const gchar *sep, GString *output_string)
 {
-       auto edd = static_cast<ExportDupesData *>(data);
        GtkTreeModel *store;
        GtkTreeIter iter;
        DupeItem *di;
-       GFileOutputStream *gfstream;
-       GFile *out_file;
        GList *work;
        GtkTreeSelection *selection;
        GList *slist;
@@ -5122,25 +5119,13 @@ static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
        gboolean color_new = FALSE;
        gint match_count;
 
-       history_list_add_to_key("export_duplicates", fdlg->dest_path, -1);
-
-       out_file = g_file_new_for_path(fdlg->dest_path);
-
-       g_autoptr(GError) error = nullptr;
-       gfstream = g_file_replace(out_file, nullptr, TRUE, G_FILE_CREATE_NONE, nullptr, &error);
-       if (error)
-               {
-               log_printf(_("Error creating Export duplicates data file: Error: %s\n"), error->message);
-               return;
-               }
-
-       const gchar *sep = (edd->separator == EXPORT_CSV) ?  "," : "\t";
        g_autofree gchar *header = g_strjoin(sep, _("Match"), _("Group"), _("Similarity"), _("Set"), _("Thumbnail"), _("Name"), _("Size"), _("Date"), _("Width"), _("Height"), _("Path"), NULL);
 
-       g_autoptr(GString) output_string = g_string_new(header);
+       output_string = g_string_append(output_string, header);
        output_string = g_string_append_c(output_string, '\n');
 
-       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(edd->dupewindow->listview));
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
+       gtk_tree_selection_select_all(selection);
        slist = gtk_tree_selection_get_selected_rows(selection, &store);
        work = slist;
 
@@ -5166,7 +5151,7 @@ static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
                g_string_append_printf(output_string, "%d", match_count);
                output_string = g_string_append(output_string, sep);
 
-               if ((dupe_match_find_parent(edd->dupewindow, di) == di))
+               if ((dupe_match_find_parent(dw, di) == di))
                        {
                        output_string = g_string_append(output_string, "1");
                        }
@@ -5215,6 +5200,31 @@ static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
                work = work->next;
                }
        g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
+}
+
+static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
+{
+       auto edd = static_cast<ExportDupesData *>(data);
+       GFileOutputStream *gfstream;
+       GFile *out_file;
+
+       history_list_add_to_key("export_duplicates", fdlg->dest_path, -1);
+
+       out_file = g_file_new_for_path(fdlg->dest_path);
+
+       g_autoptr(GError) error = nullptr;
+       gfstream = g_file_replace(out_file, nullptr, TRUE, G_FILE_CREATE_NONE, nullptr, &error);
+       if (error)
+               {
+               log_printf(_("Error creating Export duplicates data file: Error: %s\n"), error->message);
+               return;
+               }
+
+       const gchar *sep = (edd->separator == EXPORT_CSV) ?  "," : "\t";
+
+       g_autoptr(GString) output_string = g_string_new(nullptr);
+
+       export_duplicates_data((edd->dupewindow), sep, output_string);
 
        g_output_stream_write(G_OUTPUT_STREAM(gfstream), output_string->str, output_string->len, nullptr, &error);
 
@@ -5224,6 +5234,27 @@ static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
        export_duplicates_close(edd);
 }
 
+void export_duplicates_data_command_line(GString *output_string)
+{
+       if (dupe_window_list != nullptr)
+               {
+               auto dw = static_cast<DupeWindow *>(g_list_last(dupe_window_list)->data);
+
+               if (dw->idle_id != 0)
+                       {
+                       output_string = g_string_append(output_string, _("Incomplete"));
+                       }
+               else
+                       {
+                       export_duplicates_data(dw, "\t", output_string);
+                       }
+               }
+       else
+               {
+               output_string = g_string_append(output_string, _("No duplicates windows open"));
+               }
+}
+
 static void pop_menu_export(GList *, gpointer dupe_window, gpointer data)
 {
        const gint index = GPOINTER_TO_INT(data);
index 529c821c82e04cca98ac1b6184e1760dfc5ab7f0..66ba17838281ca39ce9c2cffe3741080ae6beed7 100644 (file)
@@ -166,5 +166,6 @@ void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection);
 void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse);
 void dupe_window_add_folder(const gchar *path);
 void dupe_window_add_folder_recurse(const gchar *path);
+void export_duplicates_data_command_line(GString *output_string);
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 160ca9d8492a618ef1b92f1ca7f1039eb5bc93e7..baaab2e3af30899a1fa386977871d40f1fbf09fa 100644 (file)
@@ -151,6 +151,7 @@ GOptionEntry command_line_options[] =
 #endif
        { "delay"                     , 'd', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, _("set slide show delay to Hrs Mins N.M seconds,")                               , "<[H:][M:][N][.M]>" },
        { "dupes"                     ,   0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, _("find duplicates in folder")                                                   , "<FOLDER>" },
+       { "dupes-export"              ,   0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE,   nullptr, _("export duplicates search result")                                             , nullptr },
        { "dupes-recurse"             ,   0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, _("find duplicates in folder recursively")                                       , "<FOLDER>" },
        { "file"                      ,   0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, _("open FILE or URL bring Geeqie window to the top")                             , "<FILE>|<URL>" },
        { "File"                      ,   0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, nullptr, _("open FILE or URL do not bring Geeqie window to the top")                      , "<FILE>|<URL>" },