build,core,plugins: Port to GDBus and GVariant
[profile/ivi/rygel.git] / src / plugins / tracker / rygel-tracker-insertion-query.vala
1 /*
2  * Copyright (C) 20010 Nokia Corporation.
3  *
4  * Author: Zeeshan Ali <zeenix@gmail.com>
5  *
6  * This file is part of Rygel.
7  *
8  * Rygel is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Rygel is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22
23 using Gee;
24
25 /**
26  * Represents Tracker SPARQL Insertion query
27  */
28 public class Rygel.Tracker.InsertionQuery : Query {
29     private const string TEMP_ID = "x";
30     private const string QUERY_ID = "_:" + TEMP_ID;
31
32     public string id;
33
34     public InsertionQuery (MediaItem item, string category) {
35         var triplets = new QueryTriplets ();
36         triplets.add (new QueryTriplet (QUERY_ID, "a", category));
37         triplets.add (new QueryTriplet (QUERY_ID, "a", "nie:DataObject"));
38         triplets.add (new QueryTriplet (QUERY_ID, "a", "nfo:FileDataObject"));
39         triplets.add (new QueryTriplet (QUERY_ID,
40                                         "nie:mimeType",
41                                         "\"" + item.mime_type + "\""));
42         if (item.dlna_profile != null) {
43             triplets.add (new QueryTriplet (QUERY_ID,
44                                             "nmm:dlnaProfile",
45                                             "\"" + item.dlna_profile + "\""));
46         }
47         triplets.add (new QueryTriplet (QUERY_ID,
48                                         "nie:url",
49                                         "\"" + item.uris[0] + "\""));
50         triplets.add (new QueryTriplet (QUERY_ID,
51                                         "nfo:fileSize",
52                                         "\"" + item.size.to_string () + "\""));
53
54         var now = TimeVal ();
55         triplets.add (new QueryTriplet (QUERY_ID,
56                                         "nfo:fileLastModified",
57                                         "\"" + now.to_iso8601 () + "\""));
58
59         base (triplets);
60     }
61
62     public override async void execute (ResourcesIface resources)
63                                         throws IOError {
64         var str = this.to_string ();
65
66         debug ("Executing SPARQL query: %s", str);
67
68         var result = yield resources.sparql_update_blank (str);
69
70         this.id = result[0,0].lookup (TEMP_ID);
71
72         debug ("Created item in Tracker store with ID '%s'", this.id);
73     }
74
75     public override string to_string () {
76         return "INSERT { " + base.to_string () + " }";
77     }
78 }