2 * Copyright (C) 2013 Intel Corporation.
4 * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
6 * This file is part of Rygel.
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.
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.
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.
26 public class Rygel.LMS.Albums : Rygel.LMS.CategoryContainer {
27 private static const string SQL_ALL =
28 "SELECT audio_albums.id, audio_albums.name as title, " +
29 "audio_artists.name as artist " +
30 "FROM audio_albums " +
31 "LEFT JOIN audio_artists " +
32 "ON audio_albums.artist_id = audio_artists.id " +
35 private static const string SQL_ALL_WITH_FILTER_TEMPLATE =
36 "SELECT audio_albums.id, audio_albums.name as title, " +
37 "audio_artists.name as artist " +
38 "FROM audio_albums " +
39 "LEFT JOIN audio_artists " +
40 "ON audio_albums.artist_id = audio_artists.id " +
44 private static const string SQL_COUNT =
45 "SELECT COUNT(audio_albums.id) " +
48 private static const string SQL_COUNT_WITH_FILTER_TEMPLATE =
49 "SELECT COUNT(audio_albums.id), audio_albums.name as title, " +
50 "audio_artists.name as artist " +
51 "FROM audio_albums " +
52 "LEFT JOIN audio_artists " +
53 "ON audio_albums.artist_id = audio_artists.id " +
56 /* count songs inside albums */
57 private static const string SQL_CHILD_COUNT_WITH_FILTER_TEMPLATE =
58 "SELECT COUNT(audios.id), audios.title as title, " +
59 "audio_artists.name as artist " +
60 "FROM audios, files, audio_albums " +
61 "LEFT JOIN audio_artists " +
62 "ON audios.artist_id = audio_artists.id " +
63 "WHERE dtime = 0 AND audios.id = files.id AND audios.album_id = audio_albums.id %s;";
65 /* select songs inside albums */
66 private static const string SQL_CHILD_ALL_WITH_FILTER_TEMPLATE =
67 "SELECT files.id, files.path, files.size, " +
68 "audios.title as title, audios.trackno, audios.length, audios.channels, audios.sampling_rate, audios.bitrate, audios.dlna_profile, audios.dlna_mime, " +
69 "audio_artists.name as artist, " +
70 "audio_albums.name, audio_albums.id " +
71 "FROM audios, files, audio_albums " +
72 "LEFT JOIN audio_artists " +
73 "ON audios.artist_id = audio_artists.id " +
74 "WHERE dtime = 0 AND audios.id = files.id AND audios.album_id = audio_albums.id %s " +
78 private static const string SQL_FIND_OBJECT =
79 "SELECT audio_albums.id, audio_albums.name " +
80 "FROM audio_albums " +
81 "WHERE audio_albums.id = ?;";
83 protected override string get_sql_all_with_filter (string filter) {
84 if (filter.length == 0) {
85 return Albums.SQL_ALL;
87 return (Albums.SQL_ALL_WITH_FILTER_TEMPLATE.printf (filter));
90 protected override string get_sql_count_with_filter (string filter) {
91 if (filter.length == 0) {
92 return Albums.SQL_COUNT;
94 return (Albums.SQL_COUNT_WITH_FILTER_TEMPLATE.printf (filter));
97 protected override uint get_child_count_with_filter (string where_filter,
101 /* search the children (albums) as usual */
102 var count = base.get_child_count_with_filter (where_filter, args);
104 /* now search the album contents */
106 if (where_filter.length > 0) {
107 filter = "AND %s".printf (where_filter);
109 var query = Albums.SQL_CHILD_COUNT_WITH_FILTER_TEMPLATE.printf (filter);
111 var stmt = this.lms_db.prepare_and_init (query, args.values);
112 if (stmt.step () == Sqlite.ROW) {
113 count += stmt.column_int (0);
115 } catch (DatabaseError e) {
116 warning ("Query failed: %s", e.message);
122 protected override MediaObjects? get_children_with_filter (string where_filter,
124 string sort_criteria,
127 var children = base. get_children_with_filter (where_filter,
133 if (where_filter.length > 0) {
134 filter = "AND %s".printf (where_filter);
136 var query = Albums.SQL_CHILD_ALL_WITH_FILTER_TEMPLATE.printf (filter);
138 var stmt = this.lms_db.prepare_and_init (query, args.values);
139 while (Database.get_children_step (stmt)) {
140 var album_id = stmt.column_text (13);
141 var album = new Album (album_id, this, "", this.lms_db);
143 var song = album.object_from_statement (stmt);
144 song.parent_ref = song.parent;
148 } catch (DatabaseError e) {
149 warning ("Query failed: %s", e.message);
155 protected override MediaObject? object_from_statement (Statement statement) {
156 var id = "%d".printf (statement.column_int (0));
157 LMS.Album album = new LMS.Album (id,
159 statement.column_text (1),
164 public Albums (MediaContainer parent,
165 LMS.Database lms_db) {
171 Albums.SQL_FIND_OBJECT,