diff options
author | Jens Georg <mail@jensge.org> | 2020-05-24 17:37:46 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2020-07-05 15:31:52 +0200 |
commit | f0f22f58793786aee18dc116bb45d7916320d0bc (patch) | |
tree | ff9c60ef19e1966ef9c8c3b1b59ff545fd48cbae /src/plugins | |
parent | 234603ff447de98bd8e640b984db877535af399e (diff) | |
download | rygel-f0f22f58793786aee18dc116bb45d7916320d0bc.tar.gz |
tracker3: Port to new API
Diffstat (limited to 'src/plugins')
12 files changed, 131 insertions, 77 deletions
diff --git a/src/plugins/tracker3/rygel-tracker-category-all-container.vala b/src/plugins/tracker3/rygel-tracker-category-all-container.vala index 64ab3aa7..5a2695b8 100644 --- a/src/plugins/tracker3/rygel-tracker-category-all-container.vala +++ b/src/plugins/tracker3/rygel-tracker-category-all-container.vala @@ -33,14 +33,13 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, WritableContainer, SearchableContainer { /* class-wide constants */ - private const string TRACKER_SERVICE = "org.freedesktop.Tracker1"; - private const string RESOURCES_PATH = "/org/freedesktop/Tracker1/Resources"; + private const string TRACKER_SERVICE = "org.freedesktop.Tracker3.Miner.Files"; + private const string RESOURCES_PATH = "/org/freedesktop/Tracker3/Endpoint"; + private const string TRACKER_INTERFACE = "org.freedesktop.Tracker3.Endpoint"; public ArrayList<string> create_classes { get; set; } public ArrayList<string> search_classes { get; set; } - private Sparql.Connection resources; - public CategoryAllContainer (CategoryContainer parent) { base ("All" + parent.id, parent, "All", parent.item_factory); @@ -48,13 +47,6 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, this.create_classes.add (item_factory.upnp_class); this.search_classes = new ArrayList<string> (); - try { - this.resources = Sparql.Connection.bus_new ("org.freedesktop.Tracker3.Miner.Files", null); - } catch (Error io_error) { - critical (_("Failed to create a Tracker connection: %s"), - io_error.message); - } - if (item_factory.upload_dir != null) { try { var uri = Filename.to_uri (item_factory.upload_dir, null); @@ -69,7 +61,7 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, try { var connection = Bus.get_sync (BusType.SESSION); connection.signal_subscribe (TRACKER_SERVICE, - TRACKER_SERVICE + ".Resources", + TRACKER_INTERFACE, "GraphUpdated", RESOURCES_PATH, this.item_factory.category_iri, @@ -80,8 +72,9 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, error.message); } + message("RUnnin cleanup query for %s", this.item_factory.category); var cleanup_query = new CleanupQuery (this.item_factory.category); - cleanup_query.execute.begin (this.resources); + cleanup_query.execute.begin (RootContainer.connection, () => { query.result.close (); } ); } public async void add_item (MediaFileItem item, Cancellable? cancellable) @@ -140,7 +133,7 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, var category = this.item_factory.category; var query = new InsertionQuery (item, category); - yield query.execute (this.resources); + yield query.execute (RootContainer.connection); return query.id; } @@ -148,6 +141,6 @@ public class Rygel.Tracker.CategoryAllContainer : SearchContainer, private async void remove_entry_from_store (string id) throws Error { var query = new DeletionQuery (id); - yield query.execute (this.resources); + yield query.execute (RootContainer.connection); } } diff --git a/src/plugins/tracker3/rygel-tracker-insertion-query.vala b/src/plugins/tracker3/rygel-tracker-insertion-query.vala index e062d058..4d5323a6 100644 --- a/src/plugins/tracker3/rygel-tracker-insertion-query.vala +++ b/src/plugins/tracker3/rygel-tracker-insertion-query.vala @@ -152,6 +152,7 @@ public class Rygel.Tracker.InsertionQuery : Query { } } catch (Error error) { } + cursor.close (); } else { var file = File.new_for_uri (this.uri); if (file.is_native () && diff --git a/src/plugins/tracker3/rygel-tracker-metadata-container.vala b/src/plugins/tracker3/rygel-tracker-metadata-container.vala index 1637fef3..72180386 100644 --- a/src/plugins/tracker3/rygel-tracker-metadata-container.vala +++ b/src/plugins/tracker3/rygel-tracker-metadata-container.vala @@ -39,7 +39,6 @@ public abstract class Rygel.Tracker.MetadataContainer : Rygel.SimpleContainer { private string child_class; - private Sparql.Connection resources; protected QueryTriplets triplets; protected MetadataContainer (string id, @@ -51,15 +50,6 @@ public abstract class Rygel.Tracker.MetadataContainer : Rygel.SimpleContainer { this.item_factory = item_factory; this.child_class = child_class; - - try { - this.resources = Sparql.Connection.bus_new ("org.freedesktop.Tracker3.Miner.Files", null); - } catch (Error error) { - critical (_("Failed to create Tracker connection: %s"), - error.message); - - return; - } } internal async void fetch_metadata_values () { @@ -74,7 +64,7 @@ public abstract class Rygel.Tracker.MetadataContainer : Rygel.SimpleContainer { var query = this.create_query (); try { - yield query.execute (this.resources); + yield query.execute (RootContainer.connection); /* Iterate through all the values */ while (query.result.next ()) { @@ -106,6 +96,8 @@ public abstract class Rygel.Tracker.MetadataContainer : Rygel.SimpleContainer { this.add_child_container (container); } + + query.result.close (); } catch (Error error) { critical (_("Error getting all values for ā%sā: %s"), this.id, diff --git a/src/plugins/tracker3/rygel-tracker-metadata-values.vala b/src/plugins/tracker3/rygel-tracker-metadata-values.vala index e9fd1606..1c443df7 100644 --- a/src/plugins/tracker3/rygel-tracker-metadata-values.vala +++ b/src/plugins/tracker3/rygel-tracker-metadata-values.vala @@ -48,6 +48,9 @@ public abstract class Rygel.Tracker.MetadataValues : MetadataContainer { this.triplets.add (new QueryTriplet (SelectionQuery.ITEM_VARIABLE, "a", this.item_factory.category)); + this.triplets.add (new QueryTriplet (SelectionQuery.ITEM_VARIABLE, + "nie:isStoredAs", + SelectionQuery.STORAGE_VARIABLE)); this.fetch_metadata_values.begin (); } @@ -58,7 +61,9 @@ public abstract class Rygel.Tracker.MetadataValues : MetadataContainer { property_map[this.property] + " AS ?x"); - return new SelectionQuery (selected, triplets, null, "?x"); + var q = new SelectionQuery (selected, triplets, null, "?x"); + critical(q.to_string()); + return q; } protected override SearchContainer create_container (string id, diff --git a/src/plugins/tracker3/rygel-tracker-music.vala b/src/plugins/tracker3/rygel-tracker-music.vala index dc81cf00..f0f9abb9 100644 --- a/src/plugins/tracker3/rygel-tracker-music.vala +++ b/src/plugins/tracker3/rygel-tracker-music.vala @@ -31,8 +31,8 @@ public class Rygel.Tracker.Music : CategoryContainer { base (id, parent, title, new MusicItemFactory ()); this.add_child_container (new Artists (this)); - this.add_child_container (new Albums (this)); - this.add_child_container (new Genre (this)); + //this.add_child_container (new Albums (this)); + //this.add_child_container (new Genre (this)); this.search_classes.add (AudioItem.UPNP_CLASS); this.search_classes.add (MusicItem.UPNP_CLASS); this.add_create_class (AudioItem.UPNP_CLASS); diff --git a/src/plugins/tracker3/rygel-tracker-new.vala b/src/plugins/tracker3/rygel-tracker-new.vala index efabcc86..f2055b97 100644 --- a/src/plugins/tracker3/rygel-tracker-new.vala +++ b/src/plugins/tracker3/rygel-tracker-new.vala @@ -29,7 +29,6 @@ using Gee; public class Rygel.Tracker.New : Rygel.Tracker.SearchContainer { private const string ADDED_PREDICATE = "tracker:added"; private const string ADDED_VARIABLE = "?added"; - private const long THREE_DAYS_AS_SEC = 259200; public New (MediaContainer parent, ItemFactory item_factory) { var triplets = new QueryTriplets (); @@ -42,11 +41,11 @@ public class Rygel.Tracker.New : Rygel.Tracker.SearchContainer { ADDED_VARIABLE)); var now = new DateTime.now_utc (); - now.add_days (-3); + now = now.add_days (-3); var three_days_ago = "%sZ".printf (now.format ("%Y-%m-%dT%H:%M:%S")); var filters = new ArrayList<string> (); - filters.add (ADDED_VARIABLE + " > \"" + three_days_ago + "\""); + filters.add (ADDED_VARIABLE + " > \"" + three_days_ago + "\"^^xsd:dateTime"); base (parent.id + "New", parent, diff --git a/src/plugins/tracker3/rygel-tracker-plugin-factory.vala b/src/plugins/tracker3/rygel-tracker-plugin-factory.vala index e7c74c92..06f8149b 100644 --- a/src/plugins/tracker3/rygel-tracker-plugin-factory.vala +++ b/src/plugins/tracker3/rygel-tracker-plugin-factory.vala @@ -38,22 +38,11 @@ public void module_init (PluginLoader loader) { } public class Rygel.Tracker.PluginFactory { - private const string TRACKER_SERVICE = "org.freedesktop.Tracker1"; - private const string STATISTICS_OBJECT = - "/org/freedesktop/Tracker1/Statistics"; - - StatsIface stats; PluginLoader loader; public PluginFactory (PluginLoader loader) throws IOError, DBusError { - this.stats = Bus.get_proxy_sync (BusType.SESSION, - TRACKER_SERVICE, - STATISTICS_OBJECT, - DBusProxyFlags.DO_NOT_LOAD_PROPERTIES); this.loader = loader; - this.stats.get (); - this.loader.add_plugin (new Tracker.Plugin ()); } } diff --git a/src/plugins/tracker3/rygel-tracker-plugin.vala b/src/plugins/tracker3/rygel-tracker-plugin.vala index d01cb528..84a29369 100644 --- a/src/plugins/tracker3/rygel-tracker-plugin.vala +++ b/src/plugins/tracker3/rygel-tracker-plugin.vala @@ -21,9 +21,10 @@ */ using Gee; +using Tracker; public class Rygel.Tracker.Plugin : Rygel.MediaServerPlugin { - public const string NAME = "Tracker"; + public const string NAME = "Tracker3"; private static RootContainer root; diff --git a/src/plugins/tracker3/rygel-tracker-root-container.vala b/src/plugins/tracker3/rygel-tracker-root-container.vala index 88a7d3af..c5d3b25a 100644 --- a/src/plugins/tracker3/rygel-tracker-root-container.vala +++ b/src/plugins/tracker3/rygel-tracker-root-container.vala @@ -24,11 +24,24 @@ using GUPnP; using Gee; +using Tracker; /** * Represents the root container for Tracker media content hierarchy. */ public class Rygel.Tracker.RootContainer : Rygel.SimpleContainer { + private const string TRACKER_SERVICE = "org.freedesktop.Tracker3.Miner.Files"; + + public static Sparql.Connection connection; + + static construct { + try { + RootContainer.connection = Sparql.Connection.bus_new (TRACKER_SERVICE, null); + } catch (Error err) { + error ("Failed to connect to tracker: %s", err.message); + } + } + public RootContainer (string title) { base.root (title); @@ -52,7 +65,7 @@ public class Rygel.Tracker.RootContainer : Rygel.SimpleContainer { var config = MetaConfig.get_default (); try { - value = config.get_bool ("Tracker", key); + value = config.get_bool ("Tracker3", key); } catch (GLib.Error error) {} return value; diff --git a/src/plugins/tracker3/rygel-tracker-search-container.vala b/src/plugins/tracker3/rygel-tracker-search-container.vala index 4310e090..965d8294 100644 --- a/src/plugins/tracker3/rygel-tracker-search-container.vala +++ b/src/plugins/tracker3/rygel-tracker-search-container.vala @@ -38,7 +38,9 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { public SelectionQuery query; public ItemFactory item_factory; - private Sparql.Connection resources; + static construct { + update_id_hash = new HashMap<string, uint> (); + } private static HashMap<string, uint> update_id_hash; @@ -50,10 +52,6 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { ArrayList<string>? filters = null) { base (id, parent, title); - if (unlikely (update_id_hash == null)) { - update_id_hash = new HashMap<string, uint> (); - } - if (update_id_hash.has_key (this.id)) { this.update_id = update_id_hash[this.id]; } @@ -80,6 +78,10 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { (SelectionQuery.ITEM_VARIABLE, "a", item_factory.category)); + our_triplets.add (new QueryTriplet + (SelectionQuery.ITEM_VARIABLE, + "nie:isStoredAs", + SelectionQuery.STORAGE_VARIABLE)); var property_map = UPnPPropertyMap.get_property_map (); foreach (var property in this.item_factory.properties) { @@ -88,7 +90,7 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { var order_by = MODIFIED_PROPERTY + "(" + - SelectionQuery.ITEM_VARIABLE + + SelectionQuery.STORAGE_VARIABLE + ")"; this.query = new SelectionQuery (variables, @@ -96,13 +98,7 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { filters, order_by); - try { - this.resources = Sparql.Connection.bus_new ("org.freedesktop.Tracker3.Miner.Files", null); - - this.get_children_count.begin (); - } catch (Error error) { - critical (_("Failed to get Tracker connection: %s"), error.message); - } + this.get_children_count.begin (); } public override async MediaObjects? get_children (uint offset, @@ -140,7 +136,7 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { sort_criteria); if (query != null) { - yield query.execute (this.resources); + yield query.execute (RootContainer.connection); /* Iterate through all items */ while (yield query.result.next_async ()) { @@ -154,6 +150,8 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { query.result); results.add (item); } + + query.result.close (); } total_matches = results.size; @@ -217,13 +215,14 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { SelectionQuery.ITEM_VARIABLE + ") AS ?x"); - yield query.execute (this.resources); + yield query.execute (RootContainer.connection); if (query.result.next ()) { this.child_count = int.parse (query.result.get_string (0)); this.updated (); } + query.result.close (); } catch (GLib.Error error) { critical (_("Error getting item count under category ā%sā: %s"), this.item_factory.category, @@ -284,10 +283,12 @@ public class Rygel.Tracker.SearchContainer : SimpleContainer { foreach (string s in sort_props) { var key = key_chain_map[s.substring(1)]; - if (key.index_of (SelectionQuery.ITEM_VARIABLE) == 0) { + if (key.index_of (SelectionQuery.ITEM_VARIABLE) == 0 || + key.index_of (SelectionQuery.STORAGE_VARIABLE) == 0) { continue; } + if (s.has_prefix("-")) { order += "DESC (" + key + ") "; diff --git a/src/plugins/tracker3/rygel-tracker-selection-query.vala b/src/plugins/tracker3/rygel-tracker-selection-query.vala index 9a0f8282..7fd9c580 100644 --- a/src/plugins/tracker3/rygel-tracker-selection-query.vala +++ b/src/plugins/tracker3/rygel-tracker-selection-query.vala @@ -29,17 +29,19 @@ using Tracker; */ public class Rygel.Tracker.SelectionQuery : Query { public const string ITEM_VARIABLE = "?item"; - private const string SHARED_FILTER = "(!BOUND(nmm:uPnPShared(" + + public const string STORAGE_VARIABLE = "?storage"; + + private const string SHARED_FILTER = ""; /*"(!BOUND(nmm:uPnPShared(" + ITEM_VARIABLE + ")) ||" + " nmm:uPnPShared(" + ITEM_VARIABLE + ") = true) && " + - "(BOUND(nie:url(" + - ITEM_VARIABLE + ")))"; + "(BOUND(nie:isStoredAs(" + + ITEM_VARIABLE + ")))";*/ private const string STRICT_SHARED_FILTER = "(BOUND(nmm:dlnaProfile(" + ITEM_VARIABLE + ")))"; - private const string AVAILABLE_FILTER = "(tracker:available(" + - ITEM_VARIABLE + ") = true)"; + private const string AVAILABLE_FILTER = "(tracker:available(nie:isStoredAs(" + + ITEM_VARIABLE + ")) = true)"; private string uri_filter; @@ -77,7 +79,7 @@ public class Rygel.Tracker.SelectionQuery : Query { var config = MetaConfig.get_default (); try { - uris = config.get_string_list ("Tracker", "only-export-from"); + uris = config.get_string_list ("Tracker3", "only-export-from"); } catch (Error error) { uris = new ArrayList<string> (); } @@ -162,17 +164,17 @@ public class Rygel.Tracker.SelectionQuery : Query { var filters = new ArrayList<string> (); filters.add_all (this.filters); // Make sure we don't expose items that are marked not to be shared - filters.add (SHARED_FILTER); + // filters.add (SHARED_FILTER); // Make sure we don't expose items on removable media that isn't // mounted - filters.add (AVAILABLE_FILTER); + //filters.add (AVAILABLE_FILTER); // If strict sharing is enabled, only expose files that have a DLNA // profile set try { var config = MetaConfig.get_default (); - if (config.get_bool ("Tracker", "strict-sharing")) { + if (config.get_bool ("Tracker3", "strict-sharing")) { filters.add (STRICT_SHARED_FILTER); } } catch (Error error) {}; diff --git a/src/plugins/tracker3/rygel-tracker-upnp-property-map.vala b/src/plugins/tracker3/rygel-tracker-upnp-property-map.vala index 7670b57c..298d0eea 100644 --- a/src/plugins/tracker3/rygel-tracker-upnp-property-map.vala +++ b/src/plugins/tracker3/rygel-tracker-upnp-property-map.vala @@ -23,6 +23,16 @@ using Gee; +internal class Rygel.Tracker.QueryVariable { + public string base_variable; + public string alias; + + public QueryVariable(string base_variable, string alias) { + this.base_variable = base_variable; + this.alias = alias; + } +} + /** * A map of UPnP properties to tracker property functions, coalesces, * subqueries or other custom functions @@ -30,6 +40,7 @@ using Gee; public class Rygel.Tracker.UPnPPropertyMap : Object { HashMap<string, ArrayList<string>> property_map; HashMap<string, string> functions; + HashMap<string, QueryVariable> variables; private static UPnPPropertyMap instance; public static UPnPPropertyMap get_property_map () { @@ -43,45 +54,84 @@ public class Rygel.Tracker.UPnPPropertyMap : Object { private UPnPPropertyMap () { this.property_map = new HashMap<string, ArrayList<string>> (); this.functions = new HashMap<string, string> (); + this.variables = new HashMap<string, QueryVariable> (); + + this.add_variable ("upnp:class", SelectionQuery.ITEM_VARIABLE, "?_cls"); // Item this.add_key_chain ("res", "nie:url"); + this.add_variable ("res", SelectionQuery.STORAGE_VARIABLE, "?_url"); this.add_function ("place_holder", "tracker:coalesce((SELECT false WHERE { { %s a ?o } " + "FILTER (?o IN (nfo:FileDataObject, " + "nfo:RemoteDataObject)) }), true)"); + this.add_variable ("place_holder", SelectionQuery.STORAGE_VARIABLE, "?_ph"); this.add_key_chain ("fileName", "nfo:fileName"); - this.add_alternative ("dc:title", "nie:title", "nfo:fileName"); + this.add_variable ("fileName", SelectionQuery.STORAGE_VARIABLE, "?_fn"); + + this.add_alternative ("dc:title", "nie:title", "?_fn"); + this.add_function ("dc:title", "tracker:coalesce(nie:title(%s), nfo:fileName(?storage))"); + this.add_variable ("dc:title", SelectionQuery.ITEM_VARIABLE, "?_title"); + this.add_key_chain ("dlnaProfile", "nmm:dlnaProfile"); + this.add_variable ("dlnaProfile", SelectionQuery.ITEM_VARIABLE, "?_profile"); + this.add_alternative ("mimeType", "nmm:dlnaMime", "nie:mimeType"); + this.add_variable ("mimeType", SelectionQuery.ITEM_VARIABLE, "?_mime"); + this.add_alternative ("res@size", "nfo:fileSize", "nie:byteSize"); - this.add_alternative ("date", - "nie:contentCreated", - "nfo:fileLastModified"); + this.add_variable ("res@size", SelectionQuery.STORAGE_VARIABLE, "?_mime"); + + this.add_function ("date", "tracker:coalesce(nie:contentCreated(%s), nfo:fileLastModified(?storage))"); + this.add_variable ("date", SelectionQuery.ITEM_VARIABLE, "?_date"); // Music Item this.add_key_chain ("res@duration", "nfo:duration"); + this.add_variable ("res@duration", SelectionQuery.ITEM_VARIABLE, "?_duration"); + this.add_key_chain ("upnp:artist", "nmm:performer", "nmm:artistName"); + this.add_variable ("upnp:artist", SelectionQuery.ITEM_VARIABLE, "?_artist"); + this.add_key_chain ("dc:creator", "nmm:performer", "nmm:artistName"); + this.add_variable ("dc:creator", SelectionQuery.ITEM_VARIABLE, "?_artist"); + this.add_key_chain ("upnp:album", "nmm:musicAlbum", "nie:title"); + this.add_variable ("upnp:album", SelectionQuery.ITEM_VARIABLE, "?_album"); + this.add_key_chain ("upnp:originalTrackNumber", "nmm:trackNumber"); + this.add_variable ("upnp:originalTrackNumber", SelectionQuery.ITEM_VARIABLE, "?_track"); + this.add_key_chain ("upnp:genre", "nfo:genre"); + this.add_variable ("upnp:genre", SelectionQuery.ITEM_VARIABLE, "?_genre"); + this.add_key_chain ("sampleRate", "nfo:sampleRate"); + this.add_variable ("sampleRate", SelectionQuery.ITEM_VARIABLE, "?_rate"); + this.add_key_chain ("upnp:nrAudioChannels", "nfo:channels"); + this.add_variable ("upnp:nrAudioChannels", SelectionQuery.ITEM_VARIABLE, "?_channels"); + this.add_key_chain ("upnp:bitsPerSample", "nfo:bitsPerSample"); + this.add_variable ("upnp:bitsPerSample", SelectionQuery.ITEM_VARIABLE, "?_bps"); + this.add_key_chain ("upnp:bitrate", "nfo:averageBitrate"); + this.add_variable ("upnp:bitrate", SelectionQuery.ITEM_VARIABLE, "?_rate"); // Picture & Video Items this.add_key_chain ("width", "nfo:width"); + this.add_variable ("width", SelectionQuery.ITEM_VARIABLE, "?_w"); + this.add_key_chain ("height", "nfo:height"); + this.add_variable ("height", SelectionQuery.ITEM_VARIABLE, "?_h"); this.add_key_chain ("rygel:originalVolumeNumber", "nmm:musicAlbumDisc", "nmm:setNumber"); + this.add_variable ("rygel:originalVolumeNumber", SelectionQuery.ITEM_VARIABLE, "?_vol"); } public new string @get (string property) { - var str = SelectionQuery.ITEM_VARIABLE; + var variable = this.variables[property]; + var str = variable.base_variable; if (this.property_map.has_key (property)) { foreach (var key in this.property_map[property]) { @@ -91,7 +141,11 @@ public class Rygel.Tracker.UPnPPropertyMap : Object { str = this.functions[property].printf (str); } - return str; + return str; // + " AS " + variable.alias; + } + + private void add_variable (string property, string base_item, string alias) { + this.variables[property] = new QueryVariable(base_item, alias); } private void add_key_chain (string property, ...) { @@ -120,7 +174,11 @@ public class Rygel.Tracker.UPnPPropertyMap : Object { string alternative = list.arg (); while (alternative != null) { - str.append_printf ("%s(%%1$s),", alternative); + if (alternative.has_prefix ("?")) { + str.append (alternative); + } else { + str.append_printf ("%s(%%1$s),", alternative); + } alternative = list.arg (); } |