summaryrefslogtreecommitdiff
path: root/src/camera/ImportPage.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera/ImportPage.vala')
-rw-r--r--src/camera/ImportPage.vala76
1 files changed, 48 insertions, 28 deletions
diff --git a/src/camera/ImportPage.vala b/src/camera/ImportPage.vala
index 4e055ec..f7698a6 100644
--- a/src/camera/ImportPage.vala
+++ b/src/camera/ImportPage.vala
@@ -615,20 +615,13 @@ public class ImportPage : CheckerboardPage {
return true;
}
-
- public override bool complete(MediaSource source, BatchImportRoll import_roll) throws Error {
- bool ret = false;
- if (source is Photo) {
- Photo photo = source as Photo;
-
- // Associate paired JPEG with RAW photo.
- if (associated_file != null) {
- photo.add_backing_photo_for_development(RawDeveloper.CAMERA, associated_file);
- ret = true;
- photo.set_raw_developer(Config.Facade.get_instance().get_default_raw_developer());
- }
+
+ public override File? get_associated_file() {
+ if (associated_file == null) {
+ return null;
}
- return ret;
+
+ return File.new_for_path(associated_file.filepath);
}
}
@@ -917,8 +910,8 @@ public class ImportPage : CheckerboardPage {
protected override void init_actions(int selected_count, int count) {
on_view_changed();
- set_action_important("ImportSelected", true);
- set_action_important("ImportAll", true);
+ set_action_sensitive("ImportSelected", true);
+ set_action_sensitive("ImportAll", true);
base.init_actions(selected_count, count);
}
@@ -1015,6 +1008,17 @@ public class ImportPage : CheckerboardPage {
} catch (Error err) {
// error means not mounted
}
+
+ // Could not find mount for gphoto2://, re-try with mtp://
+ // It seems some devices are mounted using MTP and not gphoto2 daemon
+ if (mount == null && this.uri.has_prefix("gphoto2")) {
+ uri = File.new_for_uri("mtp" + this.uri.substring(7));
+ try {
+ mount = uri.find_enclosing_mount(null);
+ } catch (Error err) {
+ // error means not mounted
+ }
+ }
if (mount != null) {
// it's mounted, offer to unmount for the user
@@ -1153,22 +1157,45 @@ public class ImportPage : CheckerboardPage {
return false;
}
+ private int claim_timeout = 500;
+
private RefreshResult refresh_camera() {
if (busy)
return RefreshResult.BUSY;
- this.set_page_message (_("Starting import, please wait…"));
-
+ this.set_page_message (_("Connecting to camera, please wait…"));
update_status(busy, false);
refresh_error = null;
refresh_result = camera.init(spin_idle_context.context);
+
+ // If we fail to claim the device, we might have run into a conflict
+ // with gvfs-gphoto2-volume-monitor. Back off, try again after
+ // claim_timeout ms.
+ // We will wait 3.5s in total (500 + 1000 + 2000) before giving
+ // up with the infamous -53 error dialog.
+ if (refresh_result == GPhoto.Result.IO_USB_CLAIM) {
+ if (claim_timeout < 4000) {
+ Timeout.add (claim_timeout, () => {
+ refresh_camera();
+ return false;
+ });
+ claim_timeout *= 2;
+
+ return RefreshResult.LOCKED;
+ }
+ }
+
+ // reset claim_timeout to initial value
+ claim_timeout = 500;
+
if (refresh_result != GPhoto.Result.OK) {
warning("Unable to initialize camera: %s", refresh_result.to_full_string());
return (refresh_result == GPhoto.Result.IO_LOCK) ? RefreshResult.LOCKED : RefreshResult.LIBRARY_ERROR;
}
+ this.set_page_message (_("Starting import, please wait…"));
update_status(true, refreshed);
on_view_changed();
@@ -1379,6 +1406,7 @@ public class ImportPage : CheckerboardPage {
return true;
}
+ files.sort();
for (int ctr = 0; ctr < files.count(); ctr++) {
string filename;
@@ -1553,9 +1581,7 @@ public class ImportPage : CheckerboardPage {
// calculate EXIF's fingerprint
string? exif_only_md5 = null;
if (metadata != null) {
- uint8[]? flattened_sans_thumbnail = metadata.flatten_exif(false);
- if (flattened_sans_thumbnail != null && flattened_sans_thumbnail.length > 0)
- exif_only_md5 = md5_binary(flattened_sans_thumbnail, flattened_sans_thumbnail.length);
+ exif_only_md5 = metadata.exif_hash();
}
// XXX: Cannot use the metadata for the thumbnail preview because libgphoto2
@@ -1564,9 +1590,8 @@ public class ImportPage : CheckerboardPage {
// this means the preview orientation will be wrong and the MD5 is not generated
// if the EXIF did not parse properly (see above)
- uint8[] preview_raw = null;
- size_t preview_raw_length = 0;
Gdk.Pixbuf preview = null;
+ string? preview_md5 = null;
try {
string preview_fulldir = fulldir;
string preview_filename = filename;
@@ -1575,7 +1600,7 @@ public class ImportPage : CheckerboardPage {
preview_filename = associated.get_filename();
}
preview = GPhoto.load_preview(spin_idle_context.context, camera, preview_fulldir,
- preview_filename, out preview_raw, out preview_raw_length);
+ preview_filename, out preview_md5);
} catch (Error err) {
// only issue the warning message if we're not reading a video. GPhoto is capable
// of reading video previews about 50% of the time, so we don't want to put a guard
@@ -1587,11 +1612,6 @@ public class ImportPage : CheckerboardPage {
}
}
- // calculate thumbnail fingerprint
- string? preview_md5 = null;
- if (preview != null && preview_raw != null && preview_raw_length > 0)
- preview_md5 = md5_binary(preview_raw, preview_raw_length);
-
#if TRACE_MD5
debug("camera MD5 %s: exif=%s preview=%s", filename, exif_only_md5, preview_md5);
#endif