lms plugin: add trackable container support (based on lms update id signal)
[profile/ivi/rygel.git] / src / plugins / lms / rygel-lms-image-years.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.ImageYears : Rygel.LMS.CategoryContainer {
27     private static const string SQL_ALL =
28         "SELECT DISTINCT(strftime('%Y', images.date, 'unixepoch')) as year " +
29         "FROM images " + 
30         "LIMIT ? OFFSET ?;";
31
32     private static const string SQL_COUNT =
33         "SELECT COUNT(DISTINCT(strftime('%Y', images.date, 'unixepoch'))) " +
34         "FROM images;";
35
36     /* actually returns multiple times the same result (because no DISTINCT) */
37     /* Casting the year is a workaround so we can keep using
38      * Database.find_object() without making the argument a variant or something like it*/
39     private static const string SQL_FIND_OBJECT =
40         "SELECT strftime('%Y', images.date, 'unixepoch') as year " +
41         "FROM images " +
42         "WHERE year = CAST(? AS TEXT)";
43
44     protected override MediaObject? object_from_statement (Statement statement) {
45         return new LMS.ImageYear (this, statement.column_text (0), this.lms_db);
46     }
47
48     public ImageYears (MediaContainer parent, LMS.Database lms_db) {
49         base ("years",
50               parent,
51               _("Years"),
52               lms_db,
53               ImageYears.SQL_ALL,
54               ImageYears.SQL_FIND_OBJECT,
55               ImageYears.SQL_COUNT,
56               null, null
57              );
58     }
59 }