[gnome-boxes/gnome-3-12] media-manager: Use correct tracker language property
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/gnome-3-12] media-manager: Use correct tracker language property
- Date: Tue, 20 May 2014 15:30:58 +0000 (UTC)
commit bf8addb0bbc4ce449efe0a350e4848993ef3a131
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu May 8 14:27:26 2014 +0100
media-manager: Use correct tracker language property
In the end, it was decided not to make the existing 'nie:language'
property multi-valued but rather introduce a new custom property for
this case, 'osinfo:language'.
This patch also:
* moves the handling of Tracker SPARQL query into a seperate
module/class, TrackerISOQuery.
* ensures compatibility with older Tracker (that doesn't extract and
expose the new 'osinfo:language' property) by using different queries,
depending on whether or not 'osinfo:language' property is known to
Tracker.
* ensures language info is extracted from media if its available in case
of older Tracker and therefore ensures that we don't end up using a
locale that media doesn't support and break express installation.
https://bugzilla.gnome.org/show_bug.cgi?id=729122
src/Makefile.am | 1 +
src/media-manager.vala | 29 ++++++++-------------
src/tracker-iso-query.vala | 59 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 18 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0af0520..4b3d6f4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -138,6 +138,7 @@ gnome_boxes_SOURCES = \
wizard.vala \
downloader.vala \
empty-boxes.vala \
+ tracker-iso-query.vala \
$(NULL)
gnome_boxes_LDADD = \
diff --git a/src/media-manager.vala b/src/media-manager.vala
index 04a830b..2fade9c 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -6,9 +6,6 @@ using Tracker;
private class Boxes.MediaManager : Object {
private static MediaManager media_manager;
- private const string SPARQL_QUERY = "SELECT nie:url(?iso) nie:title(?iso) nie:language(?iso)" +
- " osinfo:id(?iso) osinfo:mediaId(?iso)" +
- " { ?iso nfo:isBootable true }";
public OSDatabase os_db { get; private set; }
public Client client { get; private set; }
@@ -125,19 +122,15 @@ private class Boxes.MediaManager : Object {
// Now ISO files
try {
- var cursor = yield connection.query_async (SPARQL_QUERY);
- while (yield cursor.next_async ()) {
- var file = File.new_for_uri (cursor.get_string (0));
- var path = file.get_path ();
- if (path == null)
- continue; // FIXME: Support non-local files as well
- var title = cursor.get_string (1);
- var languages = cursor.get_string (2);
- var os_id = cursor.get_string (3);
- var media_id = cursor.get_string (4);
-
- var lang_list = (languages != null)? languages.split (",") : new string[]{};
-
+ var query = yield new TrackerISOQuery (connection);
+ string path, title, os_id, media_id;
+ string[] lang_list;
+
+ while (yield query.fetch_next_iso_data (out path,
+ out title,
+ out os_id,
+ out media_id,
+ out lang_list)) {
try {
var media = yield create_installer_media_from_iso_info (path, title, os_id, media_id,
lang_list);
unowned GLib.List<InstallerMedia> dup_node = list.find_custom (media,
compare_media_by_label);
@@ -226,12 +219,12 @@ private class Boxes.MediaManager : Object {
string? label,
string? os_id,
string? media_id,
- string[] lang_list = new string[]{})
+ string[] lang_list)
throws GLib.Error {
if (!FileUtils.test (path, FileTest.EXISTS))
throw new Boxes.Error.INVALID (_("No such file %s").printf (path));
- if (label == null || os_id == null || media_id == null)
+ if (label == null || os_id == null || media_id == null || lang_list == null)
return yield create_installer_media_for_path (path);
var os = yield os_db.get_os_by_id (os_id);
diff --git a/src/tracker-iso-query.vala b/src/tracker-iso-query.vala
new file mode 100644
index 0000000..ba92064
--- /dev/null
+++ b/src/tracker-iso-query.vala
@@ -0,0 +1,59 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+using Tracker;
+
+private class Boxes.TrackerISOQuery {
+ private const string LANG_QUERY = "ASK { osinfo:language a
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> }";
+ private const string ISO_QUERY = "SELECT nie:url(?iso) nie:title(?iso)\n" +
+ " osinfo:id(?iso) osinfo:mediaId(?iso)\n" +
+ "{ ?iso nfo:isBootable true }";
+ private const string ISO_QUERY_LANG = "SELECT nie:url(?iso) nie:title(?iso)\n" +
+ " osinfo:id(?iso) osinfo:mediaId(?iso)
osinfo:language(?iso)\n" +
+ "{ ?iso nfo:isBootable true }";
+
+ private Sparql.Cursor cursor;
+
+ public async TrackerISOQuery (Sparql.Connection connection) throws GLib.Error {
+ var iso_query = ISO_QUERY;
+ var cursor = yield connection.query_async (LANG_QUERY);
+ if ((yield cursor.next_async ()) && cursor.get_boolean (0))
+ iso_query = ISO_QUERY_LANG;
+ debug ("Tracker SPARQL query: %s", iso_query);
+
+ this.cursor = yield connection.query_async (iso_query);
+ }
+
+ public async bool fetch_next_iso_data (out string path,
+ out string title,
+ out string os_id,
+ out string media_id,
+ out string[] lang_list) throws GLib.Error {
+ path = title = os_id = media_id = null;
+ lang_list = null;
+
+ if (!(yield cursor.next_async ()))
+ return false;
+
+ var file = File.new_for_uri (cursor.get_string (0));
+ path = file.get_path ();
+ if (path == null) {
+ // FIXME: Support non-local files as well
+ return yield fetch_next_iso_data (out path,
+ out title,
+ out os_id,
+ out media_id,
+ out lang_list);
+ }
+
+ title = cursor.get_string (1);
+ os_id = cursor.get_string (2);
+ media_id = cursor.get_string (3);
+ if (cursor.n_columns > 4) {
+ var languages = cursor.get_string (4);
+
+ lang_list = (languages != null)? languages.split (",") : new string[]{};
+ }
+
+ return true;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]