2
* Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
3
* Copyright (C) 2008 Nokia Corporation.
5
* Author: Zeeshan Ali <zeenix@gmail.com>
7
* This file is part of Rygel.
9
* Rygel is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* Rygel is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
* A container listing a Tracker search result.
31
public class Rygel.TrackerSearchContainer : Rygel.MediaContainer {
32
/* class-wide constants */
33
private const string TRACKER_SERVICE = "org.freedesktop.Tracker";
34
private const string TRACKER_PATH = "/org/freedesktop/Tracker";
35
private const string TRACKER_IFACE = "org.freedesktop.Tracker";
36
private const string SEARCH_PATH = "/org/freedesktop/Tracker/Search";
37
private const string SEARCH_IFACE = "org.freedesktop.Tracker.Search";
38
private const string METADATA_PATH = "/org/freedesktop/Tracker/Metadata";
39
private const string METADATA_IFACE = "org.freedesktop.Tracker.Metadata";
41
public dynamic DBus.Object metadata;
42
public dynamic DBus.Object search;
43
public dynamic DBus.Object tracker;
45
public string service;
47
public string query_condition;
49
public string[] keywords;
51
Gee.List<AsyncResult> results;
53
public TrackerSearchContainer (string id,
54
MediaContainer parent,
57
string query_condition = "",
58
string[] keywords = new string[0]) {
59
base (id, parent, title, 0);
61
this.service = service;
62
this.keywords = keywords;
63
this.query_condition = query_condition;
66
this.create_proxies ();
68
/* FIXME: We need to hook to some tracker signals to keep
69
* this field up2date at all times
71
this.get_children_count ();
73
this.results = new Gee.ArrayList<AsyncResult>();
74
} catch (DBus.Error error) {
75
critical ("Failed to connect to session bus: %s\n", error.message);
79
private void get_children_count () {
81
// We are performing actual search (though an optimized one) to get
82
// the hitcount rather than GetHitCount because GetHitCount only
83
// allows us to get hit count for Text searches.
96
} catch (GLib.Error error) {
97
critical ("error getting items under service '%s': %s",
105
private void on_search_query_cb (string[][] search_result,
108
critical ("error getting items under service '%s': %s",
115
this.child_count = search_result.length;
119
public override void get_children (uint offset,
121
Cancellable? cancellable,
122
AsyncReadyCallback callback) {
123
var res = new TrackerSearchResult (this, callback);
125
this.results.add (res);
128
this.search.Query (0,
130
TrackerItem.get_metadata_keys (),
133
this.query_condition,
140
} catch (GLib.Error error) {
143
res.complete_in_idle ();
147
public override Gee.List<MediaObject>? get_children_finish (
150
var search_res = (Rygel.TrackerSearchResult) res;
152
this.results.remove (search_res);
154
if (search_res.error != null) {
155
throw search_res.error;
157
return search_res.data;
161
public override void find_object (string id,
162
Cancellable? cancellable,
163
AsyncReadyCallback callback) {
164
var res = new TrackerGetMetadataResult (this, callback, id);
166
this.results.add (res);
171
res.item_path = this.get_item_info (id,
173
out res.item_service);
174
if (res.item_path == null) {
175
res.complete_in_idle ();
180
string[] keys = TrackerItem.get_metadata_keys ();
182
this.metadata.Get (res.item_service,
186
} catch (GLib.Error error) {
189
res.complete_in_idle ();
193
public override MediaObject? find_object_finish (AsyncResult res)
195
var metadata_res = (TrackerGetMetadataResult) res;
197
if (metadata_res.error != null) {
198
throw metadata_res.error;
200
return metadata_res.data;
204
public bool is_thy_child (string item_id) {
205
string parent_id = null;
206
this.get_item_info (id, out parent_id, out service);
208
if (parent_id != null && parent_id == this.id) {
215
public MediaItem? create_item (string service,
218
var id = service + ":" + this.id + ":" + path;
220
if (service == TrackerVideoItem.SERVICE) {
221
return new TrackerVideoItem (id,
225
} else if (service == TrackerImageItem.SERVICE) {
226
return new TrackerImageItem (id,
230
} else if (service == TrackerMusicItem.SERVICE) {
231
return new TrackerMusicItem (id,
240
// Returns the path, ID of the parent and service this item belongs to, or
241
// null item_id is invalid
242
public string? get_item_info (string item_id,
243
out string parent_id,
244
out string service) {
245
var tokens = item_id.split (":", 3);
247
if (tokens[0] != null && tokens[1] != null && tokens[2] != null) {
249
parent_id = tokens[1];
257
private void create_proxies () throws DBus.Error {
258
DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
260
this.metadata = connection.get_object (TRACKER_SERVICE,
263
this.search = connection.get_object (TRACKER_SERVICE,
266
this.tracker = connection.get_object (TRACKER_SERVICE,