lms: add dtime=0 condition to all queries involving files table
[profile/ivi/rygel.git] / src / plugins / lms / rygel-lms-image-year.vala
1 /*
2  * Copyright (C) 2013 Intel Corporation.
3  *
4  * Author: Jussi Kukkonen <jussi.kukkonen@intel.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 Rygel;
24 using Sqlite;
25
26 public class Rygel.LMS.ImageYear : Rygel.LMS.CategoryContainer {
27     private static const string SQL_ALL_TEMPLATE =
28         "SELECT images.id, title, artist, date, width, height, path, size, dlna_profile, dlna_mime, strftime('%Y', date, 'unixepoch') as year " +
29         "FROM images, files " +
30         "WHERE dtime = 0 AND images.id = files.id AND year = '%s' " +
31         "LIMIT ? OFFSET ?;";
32
33     private static const string SQL_COUNT_TEMPLATE =
34         "SELECT count(images.id), strftime('%Y', date, 'unixepoch') as year " +
35         "FROM images, files " +
36         "WHERE dtime = 0 AND images.id = files.id AND year = '%s';";
37
38     private static const string SQL_FIND_OBJECT_TEMPLATE =
39         "SELECT images.id, title, artist, date, width, height, path, size, dlna_profile, dlna_mime, strftime('%Y', date, 'unixepoch') as year " +
40         "FROM images, files " +
41         "WHERE dtime = 0 AND files.id = ? AND images.id = files.id AND year = '%s';";
42
43     protected override MediaObject? object_from_statement (Statement statement) {
44         var id = statement.column_int(0);
45         var path = statement.column_text(6);
46         var mime_type = statement.column_text(9);
47
48         if (mime_type == null || mime_type.length == 0){
49             /* TODO is this correct? */
50             debug ("Image item %d (%s) has no MIME type",
51                    id,
52                    path);
53         }
54
55         var title = statement.column_text(1);
56         var image = new ImageItem(this.build_child_id (id), this, title);
57         image.ref_id = this.build_reference_id (id);
58         image.creator = statement.column_text(2);
59         TimeVal tv = { (long) statement.column_int(3), (long) 0 };
60         image.date = tv.to_iso8601 ();
61         image.width = statement.column_int(4);
62         image.height = statement.column_int(5);
63         image.size = statement.column_int(7);
64         image.mime_type = mime_type;
65         image.dlna_profile = statement.column_text(8);
66         File file = File.new_for_path(path);
67         image.add_uri (file.get_uri ());
68
69         return image;
70     }
71
72     private static string get_sql_all (string year) {
73         return (SQL_ALL_TEMPLATE.printf (year));
74     }
75     private static string get_sql_find_object (string year) {
76         return (SQL_FIND_OBJECT_TEMPLATE.printf (year));
77     }
78     private static string get_sql_count (string year) {
79         return (SQL_COUNT_TEMPLATE.printf (year));
80     }
81
82     public ImageYear (MediaContainer parent,
83                       string         year,
84                       LMS.Database   lms_db) {
85         base ("%s".printf (year),
86               parent,
87               year,
88               lms_db,
89               get_sql_all (year),
90               get_sql_find_object (year),
91               get_sql_count (year));
92     }
93 }