summaryrefslogtreecommitdiff
path: root/plugins/shotwell-data-imports
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:39:49 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2016-06-26 08:39:49 +0200
commit29a7aef998e975b42401cfa96d1b750d91eadf06 (patch)
treeeda2bdff398789ea2358cc39986dd1f7ee9d027a /plugins/shotwell-data-imports
parent4e10e30c2f99d552239871aa1b27a08a6c18f1a4 (diff)
Imported Upstream version 0.23.2upstream/0.23.2
Diffstat (limited to 'plugins/shotwell-data-imports')
-rw-r--r--plugins/shotwell-data-imports/Makefile8
-rw-r--r--plugins/shotwell-data-imports/SqliteSupport.vala75
-rw-r--r--plugins/shotwell-data-imports/VersionNumber.vala49
3 files changed, 129 insertions, 3 deletions
diff --git a/plugins/shotwell-data-imports/Makefile b/plugins/shotwell-data-imports/Makefile
index 52329e7..203aeed 100644
--- a/plugins/shotwell-data-imports/Makefile
+++ b/plugins/shotwell-data-imports/Makefile
@@ -5,12 +5,14 @@ PLUGIN_PKGS := \
gtk+-3.0 \
gexiv2 \
gee-0.8 \
- sqlite3
+ sqlite3 \
+ libxml-2.0 \
+ libsoup-2.4
SRC_FILES := \
shotwell-data-imports.vala \
- ../common/VersionNumber.vala \
- ../common/SqliteSupport.vala \
+ VersionNumber.vala \
+ SqliteSupport.vala \
FSpotImporter.vala \
FSpotDatabaseBehavior.vala \
FSpotDatabase.vala \
diff --git a/plugins/shotwell-data-imports/SqliteSupport.vala b/plugins/shotwell-data-imports/SqliteSupport.vala
new file mode 100644
index 0000000..859dc84
--- /dev/null
+++ b/plugins/shotwell-data-imports/SqliteSupport.vala
@@ -0,0 +1,75 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU LGPL (version 2.1 or later).
+ * See the COPYING file in this distribution.
+ */
+
+public errordomain DatabaseError {
+ ERROR,
+ BACKING,
+ MEMORY,
+ ABORT,
+ LIMITS,
+ TYPESPEC
+}
+
+public abstract class ImportableDatabaseTable {
+
+ protected static Sqlite.Database db;
+
+ public string table_name = null;
+
+ protected void set_table_name(string table_name) {
+ this.table_name = table_name;
+ }
+
+ // This method will throw an error on an SQLite return code unless it's OK, DONE, or ROW, which
+ // are considered normal results.
+ protected static void throw_error(string method, int res) throws DatabaseError {
+ string msg = "(%s) [%d] - %s".printf(method, res, db.errmsg());
+
+ switch (res) {
+ case Sqlite.OK:
+ case Sqlite.DONE:
+ case Sqlite.ROW:
+ return;
+
+ case Sqlite.PERM:
+ case Sqlite.BUSY:
+ case Sqlite.READONLY:
+ case Sqlite.IOERR:
+ case Sqlite.CORRUPT:
+ case Sqlite.CANTOPEN:
+ case Sqlite.NOLFS:
+ case Sqlite.AUTH:
+ case Sqlite.FORMAT:
+ case Sqlite.NOTADB:
+ throw new DatabaseError.BACKING(msg);
+
+ case Sqlite.NOMEM:
+ throw new DatabaseError.MEMORY(msg);
+
+ case Sqlite.ABORT:
+ case Sqlite.LOCKED:
+ case Sqlite.INTERRUPT:
+ throw new DatabaseError.ABORT(msg);
+
+ case Sqlite.FULL:
+ case Sqlite.EMPTY:
+ case Sqlite.TOOBIG:
+ case Sqlite.CONSTRAINT:
+ case Sqlite.RANGE:
+ throw new DatabaseError.LIMITS(msg);
+
+ case Sqlite.SCHEMA:
+ case Sqlite.MISMATCH:
+ throw new DatabaseError.TYPESPEC(msg);
+
+ case Sqlite.ERROR:
+ case Sqlite.INTERNAL:
+ case Sqlite.MISUSE:
+ default:
+ throw new DatabaseError.ERROR(msg);
+ }
+ }
+}
diff --git a/plugins/shotwell-data-imports/VersionNumber.vala b/plugins/shotwell-data-imports/VersionNumber.vala
new file mode 100644
index 0000000..7077597
--- /dev/null
+++ b/plugins/shotwell-data-imports/VersionNumber.vala
@@ -0,0 +1,49 @@
+/* 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.
+ */
+
+namespace Utils {
+
+/**
+ * A class that represents a version number in the form x.y.z and is able to compare
+ * different versions.
+ */
+public class VersionNumber : Object, Gee.Comparable<VersionNumber> {
+ private int[] version;
+
+ public VersionNumber(int[] version) {
+ this.version = version;
+ }
+
+ public VersionNumber.from_string(string str_version, string separator = ".") {
+ string[] version_items = str_version.split(separator);
+ this.version = new int[version_items.length];
+ for (int i = 0; i < version_items.length; i++)
+ this.version[i] = int.parse(version_items[i]);
+ }
+
+ public string to_string() {
+ string[] version_items = new string[this.version.length];
+ for (int i = 0; i < this.version.length; i++)
+ version_items[i] = this.version[i].to_string();
+ return string.joinv(".", version_items);
+ }
+
+ public int compare_to(VersionNumber other) {
+ int max_len = ((this.version.length > other.version.length) ?
+ this.version.length : other.version.length);
+ int res = 0;
+ for(int i = 0; i < max_len; i++) {
+ int this_v = (i < this.version.length ? this.version[i] : 0);
+ int other_v = (i < other.version.length ? other.version[i] : 0);
+ res = this_v - other_v;
+ if (res != 0)
+ break;
+ }
+ return res;
+ }
+}
+
+}