[shotwell/wip/phako/128: 2/4] video-support: Create meta-data sublibrary




commit 2f0a6ddfb285eeba0edbe4b6b1c02de569f1af89
Author: Jens Georg <mail jensge org>
Date:   Tue May 7 22:19:22 2019 +0200

    video-support: Create meta-data sublibrary

 src/meson.build                                    |  3 +-
 src/metadata/MediaMetadata.vala                    | 15 ++++
 .../MetadataDateTime.vala}                         | 85 ++++++----------------
 src/metadata/MetadataRational.vala                 | 21 ++++++
 src/metadata/meson.build                           | 16 ++++
 src/util/file.vala                                 | 14 ----
 6 files changed, 77 insertions(+), 77 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 285124b9..b92d25c0 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -40,6 +40,7 @@ shotwell_deps = [gio, gee, sqlite, gtk, sqlite, posix, gphoto2,
                  libraw, libexif, sw_plugin, webpdemux, webp, version,
                  clutter, clutter_gtk, champlain, champlain_gtk]
 
+subdir('metadata')
 subdir('publishing')
 
 executable(
@@ -220,7 +221,6 @@ executable(
         'MediaDataRepresentation.vala',
         'DesktopIntegration.vala',
         'MediaInterfaces.vala',
-        'MediaMetadata.vala',
         'VideoMetadata.vala',
         'MediaMonitor.vala',
         'PhotoMonitor.vala',
@@ -271,6 +271,7 @@ executable(
     dependencies : [
         shotwell_deps,
         sw_publishing_gui
+        metadata
     ],
     vala_args : [
         '--pkg', 'libgphoto2',
diff --git a/src/metadata/MediaMetadata.vala b/src/metadata/MediaMetadata.vala
new file mode 100644
index 00000000..a329cb13
--- /dev/null
+++ b/src/metadata/MediaMetadata.vala
@@ -0,0 +1,15 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+public abstract class MediaMetadata {
+    public abstract void read_from_file(File file) throws Error;
+
+    public abstract MetadataDateTime? get_creation_date_time();
+
+    public abstract string? get_title();
+
+    public abstract string? get_comment();
+}
diff --git a/src/MediaMetadata.vala b/src/metadata/MetadataDateTime.vala
similarity index 64%
rename from src/MediaMetadata.vala
rename to src/metadata/MetadataDateTime.vala
index b2ba1b77..789e2622 100644
--- a/src/MediaMetadata.vala
+++ b/src/metadata/MetadataDateTime.vala
@@ -1,125 +1,86 @@
-/* Copyright 2016 Software Freedom Conservancy Inc.
- *
- * This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later).  See the COPYING file in this distribution.
- */
-
-public abstract class MediaMetadata {
-    public abstract void read_from_file(File file) throws Error;
-    
-    public abstract MetadataDateTime? get_creation_date_time();
-    
-    public abstract string? get_title();
-
-    public abstract string? get_comment();
-}
-
-public struct MetadataRational {
-    public int numerator;
-    public int denominator;
-    
-    public MetadataRational(int numerator, int denominator) {
-        this.numerator = numerator;
-        this.denominator = denominator;
-    }
-    
-    private bool is_component_valid(int component) {
-        return (component >= 0) && (component <= 1000000);
-    }
-    
-    public bool is_valid() {
-        return (is_component_valid(numerator) && is_component_valid(denominator));
-    }
-    
-    public string to_string() {
-        return (is_valid()) ? ("%d/%d".printf(numerator, denominator)) : "";
-    }
-}
-
 public errordomain MetadataDateTimeError {
     INVALID_FORMAT,
     UNSUPPORTED_FORMAT
 }
 
 public class MetadataDateTime {
-    
+
     private time_t timestamp;
-    
+
     public MetadataDateTime(time_t timestamp) {
         this.timestamp = timestamp;
     }
-    
+
     public MetadataDateTime.from_exif(string label) throws MetadataDateTimeError {
         if (!from_exif_date_time(label, out timestamp))
             throw new MetadataDateTimeError.INVALID_FORMAT("%s is not EXIF format date/time", label);
     }
-    
+
     public MetadataDateTime.from_iptc(string date, string time) throws MetadataDateTimeError {
         // TODO: Support IPTC date/time format
         throw new MetadataDateTimeError.UNSUPPORTED_FORMAT("IPTC date/time format not currently supported");
     }
-    
+
     public MetadataDateTime.from_xmp(string label) throws MetadataDateTimeError {
         TimeVal time_val = TimeVal();
         if (!time_val.from_iso8601(label))
             throw new MetadataDateTimeError.INVALID_FORMAT("%s is not XMP format date/time", label);
-        
+
         timestamp = time_val.tv_sec;
     }
-    
+
     public time_t get_timestamp() {
         return timestamp;
     }
-    
+
     public string get_exif_label() {
         return to_exif_date_time(timestamp);
     }
-    
+
     // TODO: get_iptc_date() and get_iptc_time()
-    
+
     public string get_xmp_label() {
         TimeVal time_val = TimeVal();
         time_val.tv_sec = timestamp;
         time_val.tv_usec = 0;
-        
+
         return time_val.to_iso8601();
     }
-    
+
     public static bool from_exif_date_time(string date_time, out time_t timestamp) {
         timestamp = 0;
-        
+
         Time tm = Time();
-        
-        // Check standard EXIF format 
-        if (date_time.scanf("%d:%d:%d %d:%d:%d", 
+
+        // Check standard EXIF format
+        if (date_time.scanf("%d:%d:%d %d:%d:%d",
                             &tm.year, &tm.month, &tm.day, &tm.hour, &tm.minute, &tm.second) != 6) {
             // Fallback in a more generic format
             string tmp = date_time.dup();
             tmp.canon("0123456789", ' ');
-            if (tmp.scanf("%4d%2d%2d%2d%2d%2d", 
+            if (tmp.scanf("%4d%2d%2d%2d%2d%2d",
                           &tm.year, &tm.month, &tm.day, &tm.hour, &tm.minute,&tm.second) != 6)
                 return false;
         }
-        
+
         // watch for bogosity
         if (tm.year <= 1900 || tm.month <= 0 || tm.day < 0 || tm.hour < 0 || tm.minute < 0 || tm.second < 0)
             return false;
-        
+
         tm.year -= 1900;
         tm.month--;
         tm.isdst = -1;
-        
+
         timestamp = tm.mktime();
-        
+
         return true;
     }
-    
+
     public static string to_exif_date_time(time_t timestamp) {
         return Time.local(timestamp).format("%Y:%m:%d %H:%M:%S");
     }
-    
+
     public string to_string() {
         return to_exif_date_time(timestamp);
     }
 }
-
diff --git a/src/metadata/MetadataRational.vala b/src/metadata/MetadataRational.vala
new file mode 100644
index 00000000..a4ed62a0
--- /dev/null
+++ b/src/metadata/MetadataRational.vala
@@ -0,0 +1,21 @@
+public struct MetadataRational {
+    public int numerator;
+    public int denominator;
+
+    public MetadataRational(int numerator, int denominator) {
+        this.numerator = numerator;
+        this.denominator = denominator;
+    }
+
+    private bool is_component_valid(int component) {
+        return (component >= 0) && (component <= 1000000);
+    }
+
+    public bool is_valid() {
+        return (is_component_valid(numerator) && is_component_valid(denominator));
+    }
+
+    public string to_string() {
+        return (is_valid()) ? ("%d/%d".printf(numerator, denominator)) : "";
+    }
+}
diff --git a/src/metadata/meson.build b/src/metadata/meson.build
new file mode 100644
index 00000000..7f322caa
--- /dev/null
+++ b/src/metadata/meson.build
@@ -0,0 +1,16 @@
+libmetadata = static_library(
+    'metadata',
+    [
+        'MediaMetadata.vala',
+        'MetadataDateTime.vala',
+        'MetadataRational.vala'
+    ],
+    dependencies : [
+        gio
+    ]
+)
+
+metadata = declare_dependency(
+    include_directories : include_directories('.'),
+    link_with : libmetadata
+)
diff --git a/src/util/file.vala b/src/util/file.vala
index 32b77620..c6609d4c 100644
--- a/src/util/file.vala
+++ b/src/util/file.vala
@@ -199,20 +199,6 @@ public string? get_file_info_id(FileInfo info) {
     return info.get_attribute_string(FileAttribute.ID_FILE);
 }
 
-// Breaks a uint64 skip amount into several smaller skips.
-public void skip_uint64(InputStream input, uint64 skip_amount) throws GLib.Error {
-    while (skip_amount > 0) {
-        // skip() throws an error if the amount is too large, so check against ssize_t.MAX
-        if (skip_amount >= ssize_t.MAX) {
-            input.skip(ssize_t.MAX);
-            skip_amount -= ssize_t.MAX;
-        } else {
-            input.skip((size_t) skip_amount);
-            skip_amount = 0;
-        }
-    }
-}
-
 // Returns the number of files (and/or directories) within a directory.
 public uint64 count_files_in_directory(File dir) throws GLib.Error {
     if (!query_is_directory(dir))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]