From 4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 09:06:59 +0200 Subject: Imported Upstream version 0.18.1 --- plugins/shotwell-data-imports/FSpotTagsTable.vala | 129 ++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 plugins/shotwell-data-imports/FSpotTagsTable.vala (limited to 'plugins/shotwell-data-imports/FSpotTagsTable.vala') diff --git a/plugins/shotwell-data-imports/FSpotTagsTable.vala b/plugins/shotwell-data-imports/FSpotTagsTable.vala new file mode 100644 index 0000000..07045cf --- /dev/null +++ b/plugins/shotwell-data-imports/FSpotTagsTable.vala @@ -0,0 +1,129 @@ +/* Copyright 2011-2014 Yorba Foundation + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +namespace DataImports.FSpot.Db { + +/** + * The value object for the "tags" table, representing a single database row. + */ +public class FSpotTagRow : Object { + public int64 tag_id; + public string name; + public int64 category_id; + public bool is_category; + public int sort_priority; + public string stock_icon; // only store stock icons +} + +/** + * This class represents the F-Spot tags table. + */ +public class FSpotTagsTable : FSpotDatabaseTable { + public static const string TABLE_NAME = "Tags"; + + public static const string PREFIX_STOCK_ICON = "stock_icon:"; + public static const string STOCK_ICON_FAV = "stock_icon:emblem-favorite"; + public static const string STOCK_ICON_PEOPLE = "stock_icon:emblem-people"; + public static const string STOCK_ICON_PLACES = "stock_icon:emblem-places"; + public static const string STOCK_ICON_EVENTS = "stock_icon:emblem-event"; + + private FSpotTableBehavior photo_tags_behavior; + + public FSpotTagsTable(Sqlite.Database db, FSpotDatabaseBehavior db_behavior) { + base(db); + set_behavior(db_behavior.get_tags_behavior()); + photo_tags_behavior = db_behavior.get_photo_tags_behavior(); + } + + public FSpotTagRow? get_by_id(int64 tag_id) throws DatabaseError { + Sqlite.Statement stmt; + FSpotTagRow? row = null; + string column_list = get_joined_column_list(); + string sql = "SELECT %s FROM %s WHERE id=?".printf(column_list, table_name); + + int res = fspot_db.prepare_v2(sql, -1, out stmt); + if (res != Sqlite.OK) + throw_error("Statement failed: %s".printf(sql), res); + + res = stmt.bind_int64(1, tag_id); + assert(res == Sqlite.OK); + + res = stmt.step(); + if (res == Sqlite.ROW) + behavior.build_row(stmt, out row); + else if (res == Sqlite.DONE) + message("Could not find tag row with ID %d", (int)tag_id); + + return row; + } + + public Gee.ArrayList get_by_photo_id(int64 photo_id) throws DatabaseError { + Gee.ArrayList rows = new Gee.ArrayList(); + + Sqlite.Statement stmt; + + string column_list = get_joined_column_list(true); + string sql = "SELECT %1$s FROM %2$s, %3$s WHERE %3$s.photo_id=? AND %3$s.tag_id = %2$s.id".printf( + column_list, table_name, photo_tags_behavior.get_table_name() + ); + + int res = fspot_db.prepare_v2(sql, -1, out stmt); + if (res != Sqlite.OK) + throw_error("Statement failed: %s".printf(sql), res); + + res = stmt.bind_int64(1, photo_id); + if (res != Sqlite.OK) + throw_error("Bind failed for photo_id", res); + + res = stmt.step(); + while (res == Sqlite.ROW) { + FSpotTagRow row; + behavior.build_row(stmt, out row); + rows.add(row); + res = stmt.step(); + } + + return rows; + } +} + +public class FSpotTagsV0Behavior : FSpotTableBehavior, Object { + private static FSpotTagsV0Behavior instance; + + private FSpotTagsV0Behavior() { + } + + public static FSpotTagsV0Behavior get_instance() { + if (instance == null) + instance = new FSpotTagsV0Behavior(); + return instance; + } + + public string get_table_name() { + return FSpotTagsTable.TABLE_NAME; + } + + public string[] list_columns() { + return { "id", "name", "category_id", "is_category", "sort_priority", "icon" }; + } + + public void build_row(Sqlite.Statement stmt, out FSpotTagRow row, int offset = 0) { + row = new FSpotTagRow(); + row.tag_id = stmt.column_int64(offset + 0); + row.name = stmt.column_text(offset + 1); + row.category_id = stmt.column_int64(offset + 2); + row.is_category = (stmt.column_int(offset + 3) > 0); + row.sort_priority = stmt.column_int(offset + 4); + string icon_str = stmt.column_text(offset + 5); + if (icon_str != null && icon_str.has_prefix(FSpotTagsTable.PREFIX_STOCK_ICON)) + row.stock_icon = icon_str; + else + row.stock_icon = ""; + } +} + +} + -- cgit v1.2.3