[shotwell/wip/remove-deprecated: 1/2] wip: Remove deprecated gexiv2 calls
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/remove-deprecated: 1/2] wip: Remove deprecated gexiv2 calls
- Date: Sat, 8 Oct 2022 08:56:44 +0000 (UTC)
commit e132b2aab887bf00f6295c62f755b986513a7c94
Author: Jens Georg <mail jensge org>
Date: Sat Oct 8 10:48:35 2022 +0200
wip: Remove deprecated gexiv2 calls
plugins/shotwell-publishing/FlickrPublishing.vala | 98 ++++++++-------
plugins/shotwell-publishing/YoutubeUploader.vala | 5 -
src/photos/PhotoMetadata.vala | 147 +++++++++++++++-------
3 files changed, 156 insertions(+), 94 deletions(-)
---
diff --git a/plugins/shotwell-publishing/FlickrPublishing.vala
b/plugins/shotwell-publishing/FlickrPublishing.vala
index 2e252aa3..252bd8bd 100644
--- a/plugins/shotwell-publishing/FlickrPublishing.vala
+++ b/plugins/shotwell-publishing/FlickrPublishing.vala
@@ -772,50 +772,62 @@ internal class Uploader : Publishing.RESTSupport.BatchUploader {
if (!publishable_metadata.has_iptc())
return;
- if (publishable_metadata.has_tag("Iptc.Application2.Caption"))
- publishable_metadata.set_tag_string("Iptc.Application2.Caption",
- Publishing.RESTSupport.asciify_string(publishable_metadata.get_tag_string(
- "Iptc.Application2.Caption")));
-
- if (publishable_metadata.has_tag("Iptc.Application2.Headline"))
- publishable_metadata.set_tag_string("Iptc.Application2.Headline",
- Publishing.RESTSupport.asciify_string(publishable_metadata.get_tag_string(
- "Iptc.Application2.Headline")));
-
- if (publishable_metadata.has_tag("Iptc.Application2.Keywords")) {
- Gee.Set<string> keyword_set = new Gee.HashSet<string>();
- string[] iptc_keywords = publishable_metadata.get_tag_multiple("Iptc.Application2.Keywords");
- if (iptc_keywords != null)
- foreach (string keyword in iptc_keywords)
- keyword_set.add(keyword);
-
- string[] xmp_keywords = publishable_metadata.get_tag_multiple("Xmp.dc.subject");
- if (xmp_keywords != null)
- foreach (string keyword in xmp_keywords)
- keyword_set.add(keyword);
-
- string[] all_keywords = keyword_set.to_array();
- // append a null pointer to the end of all_keywords -- this is a necessary workaround
- // https://bugzilla.gnome.org/show_bug.cgi?id=712479. See also
- // https://bugzilla.gnome.org/show_bug.cgi?id=717438 which describes the user-visible
- // behavior seen in the Flickr Connector as a result of the former bug.
- all_keywords += null;
-
- string[] no_keywords = new string[1];
- // append a null pointer to the end of no_keywords -- this is a necessary workaround
- // for similar reasons as above.
- no_keywords[0] = null;
-
- publishable_metadata.set_tag_multiple("Xmp.dc.subject", all_keywords);
- publishable_metadata.set_tag_multiple("Iptc.Application2.Keywords", no_keywords);
-
- try {
- publishable_metadata.save_file(publishable.get_serialized_file().get_path());
- } catch (GLib.Error err) {
- warning("couldn't write metadata to file '%s' for upload preprocessing.",
- publishable.get_serialized_file().get_path());
+ try {
+ if (publishable_metadata.try_has_tag("Iptc.Application2.Caption"))
+ publishable_metadata.try_set_tag_string("Iptc.Application2.Caption",
+ Publishing.RESTSupport.asciify_string(publishable_metadata.try_get_tag_string(
+ "Iptc.Application2.Caption")));
+ } catch (Error err) {}
+
+ try {
+ if (publishable_metadata.try_has_tag("Iptc.Application2.Headline"))
+ publishable_metadata.try_set_tag_string("Iptc.Application2.Headline",
+ Publishing.RESTSupport.asciify_string(publishable_metadata.try_get_tag_string(
+ "Iptc.Application2.Headline")));
+ } catch (Error error) {}
+
+ try {
+ if (publishable_metadata.try_has_tag("Iptc.Application2.Keywords")) {
+ Gee.Set<string> keyword_set = new Gee.HashSet<string>();
+ string[] iptc_keywords =
publishable_metadata.try_get_tag_multiple("Iptc.Application2.Keywords");
+ if (iptc_keywords != null)
+ foreach (string keyword in iptc_keywords)
+ keyword_set.add(keyword);
+
+ string[] xmp_keywords = publishable_metadata.try_get_tag_multiple("Xmp.dc.subject");
+ if (xmp_keywords != null)
+ foreach (string keyword in xmp_keywords)
+ keyword_set.add(keyword);
+
+ string[] all_keywords = keyword_set.to_array();
+ // append a null pointer to the end of all_keywords -- this is a necessary workaround
+ // https://bugzilla.gnome.org/show_bug.cgi?id=712479. See also
+ // https://bugzilla.gnome.org/show_bug.cgi?id=717438 which describes the user-visible
+ // behavior seen in the Flickr Connector as a result of the former bug.
+ all_keywords += null;
+
+ string[] no_keywords = new string[1];
+ // append a null pointer to the end of no_keywords -- this is a necessary workaround
+ // for similar reasons as above.
+ no_keywords[0] = null;
+
+ try {
+ publishable_metadata.try_set_tag_multiple("Xmp.dc.subject", all_keywords);
+ } catch (Error error) {
+ }
+ try {
+ publishable_metadata.try_set_tag_multiple("Iptc.Application2.Keywords", no_keywords);
+ } catch (Error error) {
+ }
+
+ try {
+ publishable_metadata.save_file(publishable.get_serialized_file().get_path());
+ } catch (GLib.Error err) {
+ warning("couldn't write metadata to file '%s' for upload preprocessing.",
+ publishable.get_serialized_file().get_path());
+ }
}
- }
+ } catch (Error error) {}
}
protected override Publishing.RESTSupport.Transaction create_transaction(
diff --git a/plugins/shotwell-publishing/YoutubeUploader.vala
b/plugins/shotwell-publishing/YoutubeUploader.vala
index f98bf15c..9f46c1cd 100644
--- a/plugins/shotwell-publishing/YoutubeUploader.vala
+++ b/plugins/shotwell-publishing/YoutubeUploader.vala
@@ -5,7 +5,6 @@ internal class UploadTransaction : Publishing.RESTSupport.GooglePublisher.Authen
private PublishingParameters parameters;
private Publishing.RESTSupport.GoogleSession session;
private Spit.Publishing.Publishable publishable;
- private MappedFile mapped_file;
public UploadTransaction(Publishing.RESTSupport.GoogleSession session,
PublishingParameters parameters, Spit.Publishing.Publishable publishable) {
@@ -18,10 +17,6 @@ internal class UploadTransaction : Publishing.RESTSupport.GooglePublisher.Authen
this.publishable = publishable;
}
- public Spit.Publishing.Publishable get_publishable() {
- return this.publishable;
- }
-
public override void execute() throws Spit.Publishing.PublishingError {
// Collect parameters
diff --git a/src/photos/PhotoMetadata.vala b/src/photos/PhotoMetadata.vala
index 27c14c80..cd37f8fa 100644
--- a/src/photos/PhotoMetadata.vala
+++ b/src/photos/PhotoMetadata.vala
@@ -241,9 +241,13 @@ public class PhotoMetadata : MediaMetadata {
public override Bytes flatten() throws Error {
unowned GExiv2.PreviewProperties?[] props = owner.exiv2.get_preview_properties();
assert(props != null && props.length > number);
-
- return new
- Bytes(owner.exiv2.get_preview_image(props[number]).get_data());
+
+ try {
+ return new
+ Bytes(owner.exiv2.try_get_preview_image(props[number]).get_data());
+ } catch (Error err) {
+ return new Bytes(null);
+ }
}
}
@@ -364,7 +368,11 @@ public class PhotoMetadata : MediaMetadata {
}
public bool has_tag(string tag) {
- return exiv2.has_tag(tag);
+ try {
+ return exiv2.try_has_tag(tag);
+ } catch (Error error) {
+ return false;
+ }
}
private Gee.Set<string> create_string_set(owned CompareDataFunc<string>? compare_func) {
@@ -425,19 +433,35 @@ public class PhotoMetadata : MediaMetadata {
}
public string? get_tag_label(string tag) {
- return GExiv2.Metadata.get_tag_label(tag);
+ try {
+ return GExiv2.Metadata.try_get_tag_label(tag);
+ } catch (Error error) {
+ return null;
+ }
}
public string? get_tag_description(string tag) {
- return GExiv2.Metadata.get_tag_description(tag);
+ try {
+ return GExiv2.Metadata.try_get_tag_description(tag);
+ } catch (Error error) {
+ return null;
+ }
}
public string? get_string(string tag, PrepareInputTextOptions options = PREPARE_STRING_OPTIONS) {
- return prepare_input_text(exiv2.get_tag_string(tag), options, DEFAULT_USER_TEXT_INPUT_LENGTH);
+ try {
+ return prepare_input_text(exiv2.try_get_tag_string(tag), options,
DEFAULT_USER_TEXT_INPUT_LENGTH);
+ } catch (Error error) {
+ return null;
+ }
}
public string? get_string_interpreted(string tag, PrepareInputTextOptions options =
PREPARE_STRING_OPTIONS) {
- return prepare_input_text(exiv2.get_tag_interpreted_string(tag), options,
DEFAULT_USER_TEXT_INPUT_LENGTH);
+ try {
+ return prepare_input_text(exiv2.try_get_tag_interpreted_string(tag), options,
DEFAULT_USER_TEXT_INPUT_LENGTH);
+ } catch (Error error) {
+ return null;
+ }
}
public string? get_first_string(string[] tags) {
@@ -467,24 +491,28 @@ public class PhotoMetadata : MediaMetadata {
// (there or here), don't use this function to access EXIF. See:
// https://gitlab.gnome.org/GNOME/gexiv2/issues/10
public Gee.List<string>? get_string_multiple(string tag) {
- string[] values = exiv2.get_tag_multiple(tag);
- if (values == null || values.length == 0)
- return null;
-
- Gee.List<string> list = new Gee.ArrayList<string>();
-
- Gee.HashSet<string> collection = new Gee.HashSet<string>();
- foreach (string value in values) {
- string? prepped = prepare_input_text(value, PREPARE_STRING_OPTIONS,
- DEFAULT_USER_TEXT_INPUT_LENGTH);
-
- if (prepped != null && !collection.contains(prepped)) {
- list.add(prepped);
- collection.add(prepped);
+ try {
+ string[] values = exiv2.try_get_tag_multiple(tag);
+ if (values == null || values.length == 0)
+ return null;
+
+ Gee.List<string> list = new Gee.ArrayList<string>();
+
+ Gee.HashSet<string> collection = new Gee.HashSet<string>();
+ foreach (string value in values) {
+ string? prepped = prepare_input_text(value, PREPARE_STRING_OPTIONS,
+ DEFAULT_USER_TEXT_INPUT_LENGTH);
+
+ if (prepped != null && !collection.contains(prepped)) {
+ list.add(prepped);
+ collection.add(prepped);
+ }
}
+
+ return list.size > 0 ? list : null;
+ } catch (Error error) {
+ return null;
}
-
- return list.size > 0 ? list : null;
}
// Returns a List that has been filtered through a Set, so no duplicates will be found.
@@ -512,8 +540,11 @@ public class PhotoMetadata : MediaMetadata {
return;
}
- if (!exiv2.set_tag_string(tag, prepped))
- warning("Unable to set tag %s to string %s from source %s", tag, value, source_name);
+ try {
+ exiv2.try_set_tag_string(tag, prepped);
+ } catch (Error error) {
+ warning("Unable to set tag %s to string %s from source %s: %s", tag, value, source_name,
error.message);
+ }
}
private delegate void SetGenericValue(string tag);
@@ -564,8 +595,11 @@ public class PhotoMetadata : MediaMetadata {
// user-visible behavior seen in the Flickr Connector as a result of the former bug.
values += null;
- if (!exiv2.set_tag_multiple(tag, values))
- warning("Unable to set %d strings to tag %s from source %s", values.length, tag, source_name);
+ try {
+ exiv2.try_set_tag_multiple(tag, values);
+ } catch (Error err) {
+ warning("Unable to set %d strings to tag %s from source %s: %s", values.length, tag,
source_name, err.message);
+ }
}
public void set_all_string_multiple(string[] tags, Gee.Collection<string> values, SetOption option) {
@@ -579,7 +613,11 @@ public class PhotoMetadata : MediaMetadata {
return false;
}
- value = exiv2.get_tag_long(tag);
+ try {
+ value = exiv2.try_get_tag_long(tag);
+ } catch (Error error) {
+ return false;
+ }
return true;
}
@@ -596,8 +634,11 @@ public class PhotoMetadata : MediaMetadata {
}
public void set_long(string tag, long value) {
- if (!exiv2.set_tag_long(tag, value))
- warning("Unable to set tag %s to long %ld from source %s", tag, value, source_name);
+ try {
+ exiv2.try_set_tag_long(tag, value);
+ } catch (Error err) {
+ warning("Unable to set tag %s to long %ld from source %s: %s", tag, value, source_name,
err.message);
+ }
}
public void set_all_long(string[] tags, long value, SetOption option) {
@@ -606,11 +647,14 @@ public class PhotoMetadata : MediaMetadata {
public bool get_rational(string tag, out MetadataRational rational) {
int numerator, denominator;
- bool result = exiv2.get_exif_tag_rational(tag, out numerator, out denominator);
-
- rational = MetadataRational(numerator, denominator);
-
- return result;
+ try {
+ exiv2.try_get_exif_tag_rational(tag, out numerator, out denominator);
+ rational = MetadataRational(numerator, denominator);
+ } catch (Error error) {
+ return false;
+ }
+
+ return true;
}
public bool get_first_rational(string[] tags, out MetadataRational rational) {
@@ -625,9 +669,11 @@ public class PhotoMetadata : MediaMetadata {
}
public void set_rational(string tag, MetadataRational rational) {
- if (!exiv2.set_exif_tag_rational(tag, rational.numerator, rational.denominator)) {
- warning("Unable to set tag %s to rational %s from source %s", tag, rational.to_string(),
- source_name);
+ try {
+ exiv2.try_set_exif_tag_rational(tag, rational.numerator, rational.denominator);
+ } catch (Error err) {
+ warning("Unable to set tag %s to rational %s from source %s: %s", tag, rational.to_string(),
+ source_name, err.message);
}
}
@@ -766,7 +812,10 @@ public class PhotoMetadata : MediaMetadata {
}
public void remove_exif_thumbnail() {
- exiv2.erase_exif_thumbnail();
+ try {
+ exiv2.try_erase_exif_thumbnail();
+ } catch (Error err) { }
+
if (exif != null) {
Exif.Mem.new_default().free(exif.data);
exif.data = null;
@@ -775,7 +824,9 @@ public class PhotoMetadata : MediaMetadata {
}
public void remove_tag(string tag) {
- exiv2.clear_tag(tag);
+ try {
+ exiv2.try_clear_tag(tag);
+ } catch (Error err){}
}
public void remove_tags(string[] tags) {
@@ -1147,12 +1198,16 @@ public class PhotoMetadata : MediaMetadata {
public Orientation get_orientation() {
// GExiv2.Orientation is the same value-wise as Orientation, with one exception:
// GExiv2.Orientation.UNSPECIFIED must be handled
- GExiv2.Orientation orientation = exiv2.get_orientation();
- if (orientation == GExiv2.Orientation.UNSPECIFIED || orientation < Orientation.MIN ||
- orientation > Orientation.MAX)
+ try {
+ GExiv2.Orientation orientation = exiv2.try_get_orientation();
+ if (orientation == GExiv2.Orientation.UNSPECIFIED || orientation < Orientation.MIN ||
+ orientation > Orientation.MAX)
+ return Orientation.TOP_LEFT;
+ else
+ return (Orientation) orientation;
+ } catch (Error error) {
return Orientation.TOP_LEFT;
- else
- return (Orientation) orientation;
+ }
}
public void set_orientation(Orientation orientation) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]