summaryrefslogtreecommitdiff
path: root/src/Exporter.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-06-14 20:36:17 +0200
committerJörg Frings-Fürst <debian@jff.email>2023-06-14 20:36:17 +0200
commit31804433d72460cbe0a39f9f8ea5e76058d84cda (patch)
tree2084a84c39f159c6aea254775dc0880d52579d45 /src/Exporter.vala
parenta9898fb3f39c44a85876930ef6b2558052569ae6 (diff)
parentd443a3c2509889533ca812c163056bace396b586 (diff)
Update upstream source from tag 'upstream/0.32.1'
Update to upstream version '0.32.1' with Debian dir c460ad6e13d3c39eaa2d5399059385e64e6fba4c
Diffstat (limited to 'src/Exporter.vala')
-rw-r--r--src/Exporter.vala75
1 files changed, 55 insertions, 20 deletions
diff --git a/src/Exporter.vala b/src/Exporter.vala
index b9596f5..a7f7b6b 100644
--- a/src/Exporter.vala
+++ b/src/Exporter.vala
@@ -55,7 +55,9 @@ public class Exporter : Object {
YES,
NO,
CANCEL,
- REPLACE_ALL
+ REPLACE_ALL,
+ RENAME,
+ RENAME_ALL,
}
public delegate void CompletionCallback(Exporter exporter, bool is_cancelled);
@@ -116,8 +118,10 @@ public class Exporter : Object {
private unowned ProgressMonitor? monitor = null;
private Cancellable cancellable;
private bool replace_all = false;
+ private bool rename_all = false;
private bool aborted = false;
private ExportFormatParameters export_params;
+ private static File? USE_TEMPORARY_EXPORT_FOLDER = null;
public Exporter(Gee.Collection<MediaSource> to_export, File? dir, Scaling scaling,
ExportFormatParameters export_params, bool auto_replace_all = false) {
@@ -131,7 +135,7 @@ public class Exporter : Object {
public Exporter.for_temp_file(Gee.Collection<MediaSource> to_export, Scaling scaling,
ExportFormatParameters export_params) {
this.to_export.add_all(to_export);
- this.dir = null;
+ this.dir = USE_TEMPORARY_EXPORT_FOLDER;
this.scaling = scaling;
this.export_params = export_params;
}
@@ -193,6 +197,7 @@ public class Exporter : Object {
private bool process_queue() {
int submitted = 0;
+ Gee.HashSet<string> used = new Gee.HashSet<string>();
foreach (MediaSource source in to_export) {
File? use_source_file = null;
PhotoFileFormat real_export_format = PhotoFileFormat.get_system_default_format();
@@ -227,7 +232,7 @@ public class Exporter : Object {
if (export_dir == null) {
try {
bool collision;
- dest = generate_unique_file(AppDirs.get_temp_dir(), basename, out collision);
+ dest = generate_unique_file(AppDirs.get_temp_dir(), basename, out collision, used);
} catch (Error err) {
AppWindow.error_message(_("Unable to generate a temporary file for %s: %s").printf(
source.get_file().get_basename(), err.message));
@@ -236,17 +241,30 @@ public class Exporter : Object {
}
} else {
dest = dir.get_child(basename);
+ bool rename = false;
- if (!replace_all && dest.query_exists(null)) {
- switch (overwrite_callback(this, dest)) {
+ if (!replace_all && (dest.query_exists(null) || used.contains(basename))) {
+ if (rename_all) {
+ rename = true;
+ } else {
+ switch (overwrite_callback(this, dest)) {
case Overwrite.YES:
// continue
- break;
+ break;
case Overwrite.REPLACE_ALL:
replace_all = true;
- break;
-
+ break;
+
+ case Overwrite.RENAME:
+ rename = true;
+ break;
+
+ case Overwrite.RENAME_ALL:
+ rename = true;
+ rename_all = true;
+ break;
+
case Overwrite.CANCEL:
cancellable.cancel();
@@ -264,10 +282,22 @@ public class Exporter : Object {
}
continue;
+ }
+ }
+ if (rename) {
+ try {
+ bool collision;
+ dest = generate_unique_file(dir, basename, out collision, used);
+ } catch (Error err) {
+ AppWindow.error_message(_("Unable to generate a temporary file for %s: %s").printf(
+ source.get_file().get_basename(), err.message));
+ break;
+ }
}
}
}
+ used.add(dest.get_basename());
workers.enqueue(new ExportJob(this, source, dest, scaling, export_params.quality,
real_export_format, cancellable, export_params.mode == ExportFormatMode.UNMODIFIED, export_params.export_metadata));
submitted++;
@@ -315,24 +345,30 @@ public class ExporterUI {
private Exporter.Overwrite on_export_overwrite(Exporter exporter, File file) {
progress_dialog.set_modal(false);
string question = _("File %s already exists. Replace?").printf(file.get_basename());
- Gtk.ResponseType response = AppWindow.negate_affirm_all_cancel_question(question,
- _("_Skip"), _("_Replace"), _("Replace _All"), _("Export"));
+ int response = AppWindow.export_overwrite_or_replace_question(question,
+ _("_Skip"), _("Rename"), _("Rename All"),_("_Replace"), _("Replace _All"), _("_Cancel"), _("Export"));
progress_dialog.set_modal(true);
switch (response) {
- case Gtk.ResponseType.APPLY:
- return Exporter.Overwrite.REPLACE_ALL;
+ case 2:
+ return Exporter.Overwrite.RENAME;
+
+ case 3:
+ return Exporter.Overwrite.RENAME_ALL;
- case Gtk.ResponseType.YES:
- return Exporter.Overwrite.YES;
+ case 4:
+ return Exporter.Overwrite.YES;
- case Gtk.ResponseType.CANCEL:
- return Exporter.Overwrite.CANCEL;
+ case 5:
+ return Exporter.Overwrite.REPLACE_ALL;
- case Gtk.ResponseType.NO:
- default:
- return Exporter.Overwrite.NO;
+ case 6:
+ return Exporter.Overwrite.CANCEL;
+
+ case 1:
+ default:
+ return Exporter.Overwrite.NO;
}
}
@@ -340,4 +376,3 @@ public class ExporterUI {
return export_error_dialog(file, remaining > 0) != Gtk.ResponseType.CANCEL;
}
}
-