lms plugin: add trackable container support (based on lms update id signal)
[profile/ivi/rygel.git] / src / plugins / lms / rygel-lms-artist.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.Artist : Rygel.LMS.CategoryContainer {
27     private static const string SQL_ALL_TEMPLATE =
28         "SELECT audio_albums.id, audio_albums.name " +
29         "FROM audio_albums " +
30         "WHERE audio_albums.artist_id = %s " +
31         "LIMIT ? OFFSET ?;";
32
33     private static const string SQL_COUNT_TEMPLATE =
34         "SELECT COUNT(audio_albums.id) " +
35         "FROM audio_albums " +
36         "WHERE audio_albums.artist_id = %s";
37
38     private static const string SQL_FIND_OBJECT_TEMPLATE =
39         "SELECT audio_albums.id, audio_albums.name " +
40         "FROM audio_albums " +
41         "WHERE audio_albums.id = ? AND audio_albums.artist_id = %s;";
42
43     private static string get_sql_all (string id) {
44         return (SQL_ALL_TEMPLATE.printf (id));
45     }
46     private static string get_sql_find_object (string id) {
47         return (SQL_FIND_OBJECT_TEMPLATE.printf (id));
48     }
49     private static string get_sql_count (string id) {
50         return (SQL_COUNT_TEMPLATE.printf (id));
51     }
52
53     protected override MediaObject? object_from_statement (Statement statement) {
54         var db_id = "%d".printf (statement.column_int (0));
55         var title = statement.column_text (1);
56         return new LMS.Album (db_id, this, title, this.lms_db);
57     }
58
59     public Artist (string         id,
60                    MediaContainer parent,
61                    string         title,
62                    LMS.Database   lms_db) {
63
64         base (id,
65               parent,
66               title,
67               lms_db,
68               get_sql_all (id),
69               get_sql_find_object (id),
70               get_sql_count (id),
71               null, // LMS does not track adding or removing albums
72               null
73              );
74     }
75 }