Merge lp:~jamesh/mediascanner2/media-filter into lp:mediascanner2
- media-filter
- Merge into trunk
Proposed by
James Henstridge
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 232 | ||||||||
Proposed branch: | lp:~jamesh/mediascanner2/media-filter | ||||||||
Merge into: | lp:mediascanner2 | ||||||||
Prerequisite: | lp:~jamesh/mediascanner2/dbus-apparmor | ||||||||
Diff against target: |
2163 lines (+1313/-184) 33 files modified
src/mediascanner/CMakeLists.txt (+1/-0) src/mediascanner/Filter.cc (+154/-0) src/mediascanner/Filter.hh (+66/-0) src/mediascanner/MediaStore.cc (+93/-34) src/mediascanner/MediaStore.hh (+6/-3) src/ms-dbus/dbus-codec.cc (+45/-0) src/ms-dbus/dbus-codec.hh (+24/-0) src/ms-dbus/dbus-interface.hh (+26/-0) src/ms-dbus/service-skeleton.cc (+64/-14) src/ms-dbus/service-stub.cc (+30/-15) src/ms-dbus/service-stub.hh (+6/-3) src/qml/Ubuntu/MediaScanner/AlbumModelBase.cc (+1/-0) src/qml/Ubuntu/MediaScanner/AlbumModelBase.hh (+3/-1) src/qml/Ubuntu/MediaScanner/AlbumsModel.cc (+61/-22) src/qml/Ubuntu/MediaScanner/AlbumsModel.hh (+11/-7) src/qml/Ubuntu/MediaScanner/ArtistsModel.cc (+27/-2) src/qml/Ubuntu/MediaScanner/ArtistsModel.hh (+8/-1) src/qml/Ubuntu/MediaScanner/CMakeLists.txt (+1/-0) src/qml/Ubuntu/MediaScanner/GenresModel.cc (+86/-0) src/qml/Ubuntu/MediaScanner/GenresModel.hh (+71/-0) src/qml/Ubuntu/MediaScanner/MediaFileModelBase.cc (+1/-0) src/qml/Ubuntu/MediaScanner/MediaFileModelBase.hh (+3/-1) src/qml/Ubuntu/MediaScanner/SongsModel.cc (+82/-34) src/qml/Ubuntu/MediaScanner/SongsModel.hh (+14/-10) src/qml/Ubuntu/MediaScanner/plugin.cc (+2/-0) src/qml/Ubuntu/MediaScanner/plugin.qmltypes (+29/-5) src/qml/Ubuntu/MediaScanner/qmldir (+1/-0) test/qml/tst_albumsmodel.qml (+91/-0) test/qml/tst_artistsmodel.qml (+68/-0) test/qml/tst_genresmodel.qml (+44/-0) test/qml/tst_songsmodel.qml (+104/-0) test/test_dbus.cc (+39/-12) test/test_mediastore.cc (+51/-20) |
||||||||
To merge this branch: | bzr merge lp:~jamesh/mediascanner2/media-filter | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Mediascanner Team | Pending | ||
Review via email: mp+221335@code.launchpad.net |
Commit message
Introduce a mediascanner:
Description of the change
Introduce a mediascanner:
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/mediascanner/CMakeLists.txt' | |||
2 | --- src/mediascanner/CMakeLists.txt 2014-05-29 09:17:39 +0000 | |||
3 | +++ src/mediascanner/CMakeLists.txt 2014-05-29 09:17:39 +0000 | |||
4 | @@ -2,6 +2,7 @@ | |||
5 | 2 | MediaFile.cc | 2 | MediaFile.cc |
6 | 3 | MediaFileBuilder.cc | 3 | MediaFileBuilder.cc |
7 | 4 | MediaFilePrivate.cc | 4 | MediaFilePrivate.cc |
8 | 5 | Filter.cc | ||
9 | 5 | Album.cc | 6 | Album.cc |
10 | 6 | MediaStore.cc | 7 | MediaStore.cc |
11 | 7 | utils.cc | 8 | utils.cc |
12 | 8 | 9 | ||
13 | === added file 'src/mediascanner/Filter.cc' | |||
14 | --- src/mediascanner/Filter.cc 1970-01-01 00:00:00 +0000 | |||
15 | +++ src/mediascanner/Filter.cc 2014-05-29 09:17:39 +0000 | |||
16 | @@ -0,0 +1,154 @@ | |||
17 | 1 | /* | ||
18 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
19 | 3 | * | ||
20 | 4 | * Authors: | ||
21 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
22 | 6 | * | ||
23 | 7 | * This program is free software: you can redistribute it and/or modify | ||
24 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
25 | 9 | * published by the Free Software Foundation. | ||
26 | 10 | * | ||
27 | 11 | * This program is distributed in the hope that it will be useful, | ||
28 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | 14 | * GNU Lesser General Public License for more details. | ||
31 | 15 | * | ||
32 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
33 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | 18 | */ | ||
35 | 19 | |||
36 | 20 | #include "Filter.hh" | ||
37 | 21 | |||
38 | 22 | using std::string; | ||
39 | 23 | |||
40 | 24 | namespace mediascanner { | ||
41 | 25 | |||
42 | 26 | struct Filter::Private { | ||
43 | 27 | string artist; | ||
44 | 28 | string album; | ||
45 | 29 | string album_artist; | ||
46 | 30 | string genre; | ||
47 | 31 | |||
48 | 32 | bool have_artist; | ||
49 | 33 | bool have_album; | ||
50 | 34 | bool have_album_artist; | ||
51 | 35 | bool have_genre; | ||
52 | 36 | |||
53 | 37 | Private() : | ||
54 | 38 | have_artist(false), have_album(false), have_album_artist(false), | ||
55 | 39 | have_genre(false) { | ||
56 | 40 | } | ||
57 | 41 | }; | ||
58 | 42 | |||
59 | 43 | Filter::Filter() : p(new Private) { | ||
60 | 44 | } | ||
61 | 45 | |||
62 | 46 | Filter::Filter(const Filter &other) : Filter() { | ||
63 | 47 | *p = *other.p; | ||
64 | 48 | } | ||
65 | 49 | |||
66 | 50 | Filter::~Filter() { | ||
67 | 51 | delete p; | ||
68 | 52 | } | ||
69 | 53 | |||
70 | 54 | bool Filter::operator==(const Filter &other) const { | ||
71 | 55 | return | ||
72 | 56 | p->have_artist == other.p->have_artist && | ||
73 | 57 | p->have_album == other.p->have_album && | ||
74 | 58 | p->have_album_artist == other.p->have_album_artist && | ||
75 | 59 | p->have_genre == other.p->have_genre && | ||
76 | 60 | p->artist == other.p->artist && | ||
77 | 61 | p->album == other.p->album && | ||
78 | 62 | p->album_artist == other.p->album_artist && | ||
79 | 63 | p->genre == other.p->genre; | ||
80 | 64 | } | ||
81 | 65 | |||
82 | 66 | bool Filter::operator!=(const Filter &other) const { | ||
83 | 67 | return !(*this == other); | ||
84 | 68 | } | ||
85 | 69 | |||
86 | 70 | Filter &Filter::operator=(const Filter &other) { | ||
87 | 71 | *p = *other.p; | ||
88 | 72 | return *this; | ||
89 | 73 | } | ||
90 | 74 | |||
91 | 75 | void Filter::clear() { | ||
92 | 76 | unsetArtist(); | ||
93 | 77 | unsetAlbum(); | ||
94 | 78 | unsetAlbumArtist(); | ||
95 | 79 | unsetGenre(); | ||
96 | 80 | } | ||
97 | 81 | |||
98 | 82 | void Filter::setArtist(const std::string &artist) { | ||
99 | 83 | p->artist = artist; | ||
100 | 84 | p->have_artist = true; | ||
101 | 85 | } | ||
102 | 86 | |||
103 | 87 | void Filter::unsetArtist() { | ||
104 | 88 | p->artist = ""; | ||
105 | 89 | p->have_artist = false; | ||
106 | 90 | } | ||
107 | 91 | |||
108 | 92 | bool Filter::hasArtist() const { | ||
109 | 93 | return p->have_artist; | ||
110 | 94 | } | ||
111 | 95 | |||
112 | 96 | const std::string &Filter::getArtist() const { | ||
113 | 97 | return p->artist; | ||
114 | 98 | } | ||
115 | 99 | |||
116 | 100 | void Filter::setAlbum(const std::string &album) { | ||
117 | 101 | p->album = album; | ||
118 | 102 | p->have_album = true; | ||
119 | 103 | } | ||
120 | 104 | |||
121 | 105 | void Filter::unsetAlbum() { | ||
122 | 106 | p->album = ""; | ||
123 | 107 | p->have_album = false; | ||
124 | 108 | } | ||
125 | 109 | |||
126 | 110 | bool Filter::hasAlbum() const { | ||
127 | 111 | return p->have_album; | ||
128 | 112 | } | ||
129 | 113 | |||
130 | 114 | const std::string &Filter::getAlbum() const { | ||
131 | 115 | return p->album; | ||
132 | 116 | } | ||
133 | 117 | |||
134 | 118 | void Filter::setAlbumArtist(const std::string &album_artist) { | ||
135 | 119 | p->album_artist = album_artist; | ||
136 | 120 | p->have_album_artist = true; | ||
137 | 121 | } | ||
138 | 122 | |||
139 | 123 | void Filter::unsetAlbumArtist() { | ||
140 | 124 | p->album_artist = ""; | ||
141 | 125 | p->have_album_artist = false; | ||
142 | 126 | } | ||
143 | 127 | |||
144 | 128 | bool Filter::hasAlbumArtist() const { | ||
145 | 129 | return p->have_album_artist; | ||
146 | 130 | } | ||
147 | 131 | |||
148 | 132 | const std::string &Filter::getAlbumArtist() const { | ||
149 | 133 | return p->album_artist; | ||
150 | 134 | } | ||
151 | 135 | |||
152 | 136 | void Filter::setGenre(const std::string &genre) { | ||
153 | 137 | p->genre = genre; | ||
154 | 138 | p->have_genre = true; | ||
155 | 139 | } | ||
156 | 140 | |||
157 | 141 | void Filter::unsetGenre() { | ||
158 | 142 | p->genre = ""; | ||
159 | 143 | p->have_genre = false; | ||
160 | 144 | } | ||
161 | 145 | |||
162 | 146 | bool Filter::hasGenre() const { | ||
163 | 147 | return p->have_genre; | ||
164 | 148 | } | ||
165 | 149 | |||
166 | 150 | const std::string &Filter::getGenre() const { | ||
167 | 151 | return p->genre; | ||
168 | 152 | } | ||
169 | 153 | |||
170 | 154 | } | ||
171 | 0 | 155 | ||
172 | === added file 'src/mediascanner/Filter.hh' | |||
173 | --- src/mediascanner/Filter.hh 1970-01-01 00:00:00 +0000 | |||
174 | +++ src/mediascanner/Filter.hh 2014-05-29 09:17:39 +0000 | |||
175 | @@ -0,0 +1,66 @@ | |||
176 | 1 | /* | ||
177 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
178 | 3 | * | ||
179 | 4 | * Authors: | ||
180 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
181 | 6 | * | ||
182 | 7 | * This program is free software: you can redistribute it and/or modify | ||
183 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
184 | 9 | * published by the Free Software Foundation. | ||
185 | 10 | * | ||
186 | 11 | * This program is distributed in the hope that it will be useful, | ||
187 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
188 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
189 | 14 | * GNU Lesser General Public License for more details. | ||
190 | 15 | * | ||
191 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
192 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
193 | 18 | */ | ||
194 | 19 | |||
195 | 20 | #ifndef MEDIAFILTER_H_ | ||
196 | 21 | #define MEDIAFILTER_H_ | ||
197 | 22 | |||
198 | 23 | #include <string> | ||
199 | 24 | |||
200 | 25 | namespace mediascanner { | ||
201 | 26 | |||
202 | 27 | class Filter final { | ||
203 | 28 | public: | ||
204 | 29 | Filter(); | ||
205 | 30 | Filter(const Filter &other); | ||
206 | 31 | ~Filter(); | ||
207 | 32 | |||
208 | 33 | Filter &operator=(const Filter &other); | ||
209 | 34 | bool operator==(const Filter &other) const; | ||
210 | 35 | bool operator!=(const Filter &other) const; | ||
211 | 36 | |||
212 | 37 | void clear(); | ||
213 | 38 | |||
214 | 39 | void setArtist(const std::string &artist); | ||
215 | 40 | void unsetArtist(); | ||
216 | 41 | bool hasArtist() const; | ||
217 | 42 | const std::string &getArtist() const; | ||
218 | 43 | |||
219 | 44 | void setAlbum(const std::string &album); | ||
220 | 45 | void unsetAlbum(); | ||
221 | 46 | bool hasAlbum() const; | ||
222 | 47 | const std::string &getAlbum() const; | ||
223 | 48 | |||
224 | 49 | void setAlbumArtist(const std::string &album_artist); | ||
225 | 50 | void unsetAlbumArtist(); | ||
226 | 51 | bool hasAlbumArtist() const; | ||
227 | 52 | const std::string &getAlbumArtist() const; | ||
228 | 53 | |||
229 | 54 | void setGenre(const std::string &genre); | ||
230 | 55 | void unsetGenre(); | ||
231 | 56 | bool hasGenre() const; | ||
232 | 57 | const std::string &getGenre() const; | ||
233 | 58 | |||
234 | 59 | private: | ||
235 | 60 | struct Private; | ||
236 | 61 | Private *p; | ||
237 | 62 | }; | ||
238 | 63 | |||
239 | 64 | } | ||
240 | 65 | |||
241 | 66 | #endif | ||
242 | 0 | 67 | ||
243 | === modified file 'src/mediascanner/MediaStore.cc' | |||
244 | --- src/mediascanner/MediaStore.cc 2014-05-29 09:17:39 +0000 | |||
245 | +++ src/mediascanner/MediaStore.cc 2014-05-29 09:17:39 +0000 | |||
246 | @@ -33,6 +33,7 @@ | |||
247 | 33 | #include "MediaFile.hh" | 33 | #include "MediaFile.hh" |
248 | 34 | #include "MediaFileBuilder.hh" | 34 | #include "MediaFileBuilder.hh" |
249 | 35 | #include "Album.hh" | 35 | #include "Album.hh" |
250 | 36 | #include "Filter.hh" | ||
251 | 36 | #include "internal/sqliteutils.hh" | 37 | #include "internal/sqliteutils.hh" |
252 | 37 | #include "internal/utils.hh" | 38 | #include "internal/utils.hh" |
253 | 38 | 39 | ||
254 | @@ -448,21 +449,24 @@ | |||
255 | 448 | } | 449 | } |
256 | 449 | } | 450 | } |
257 | 450 | 451 | ||
259 | 451 | std::vector<MediaFile> MediaStore::listSongs(const std::string& artist, const std::string& album, const std::string& album_artist, int limit) const { | 452 | std::vector<MediaFile> MediaStore::listSongs(const Filter &filter, int limit) const { |
260 | 452 | std::string qs(R"( | 453 | std::string qs(R"( |
261 | 453 | SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, type | 454 | SELECT filename, content_type, etag, title, date, artist, album, album_artist, genre, disc_number, track_number, duration, type |
262 | 454 | FROM media | 455 | FROM media |
263 | 455 | WHERE type = ? | 456 | WHERE type = ? |
264 | 456 | )"); | 457 | )"); |
266 | 457 | if (!artist.empty()) { | 458 | if (filter.hasArtist()) { |
267 | 458 | qs += " AND artist = ?"; | 459 | qs += " AND artist = ?"; |
268 | 459 | } | 460 | } |
270 | 460 | if (!album.empty()) { | 461 | if (filter.hasAlbum()) { |
271 | 461 | qs += " AND album = ?"; | 462 | qs += " AND album = ?"; |
272 | 462 | } | 463 | } |
274 | 463 | if (!album_artist.empty()) { | 464 | if (filter.hasAlbumArtist()) { |
275 | 464 | qs += " AND album_artist = ?"; | 465 | qs += " AND album_artist = ?"; |
276 | 465 | } | 466 | } |
277 | 467 | if (filter.hasGenre()) { | ||
278 | 468 | qs += " AND genre = ?"; | ||
279 | 469 | } | ||
280 | 466 | qs += R"( | 470 | qs += R"( |
281 | 467 | ORDER BY album_artist, album, disc_number, track_number, title | 471 | ORDER BY album_artist, album, disc_number, track_number, title |
282 | 468 | LIMIT ? | 472 | LIMIT ? |
283 | @@ -470,31 +474,37 @@ | |||
284 | 470 | Statement query(p->db, qs.c_str()); | 474 | Statement query(p->db, qs.c_str()); |
285 | 471 | int param = 1; | 475 | int param = 1; |
286 | 472 | query.bind(param++, (int)AudioMedia); | 476 | query.bind(param++, (int)AudioMedia); |
295 | 473 | if (!artist.empty()) { | 477 | if (filter.hasArtist()) { |
296 | 474 | query.bind(param++, artist); | 478 | query.bind(param++, filter.getArtist()); |
297 | 475 | } | 479 | } |
298 | 476 | if (!album.empty()) { | 480 | if (filter.hasAlbum()) { |
299 | 477 | query.bind(param++, album); | 481 | query.bind(param++, filter.getAlbum()); |
300 | 478 | } | 482 | } |
301 | 479 | if (!album_artist.empty()) { | 483 | if (filter.hasAlbumArtist()) { |
302 | 480 | query.bind(param++, album_artist); | 484 | query.bind(param++, filter.getAlbumArtist()); |
303 | 485 | } | ||
304 | 486 | if (filter.hasGenre()) { | ||
305 | 487 | query.bind(param++, filter.getGenre()); | ||
306 | 481 | } | 488 | } |
307 | 482 | query.bind(param++, limit); | 489 | query.bind(param++, limit); |
308 | 483 | 490 | ||
309 | 484 | return collect_media(query); | 491 | return collect_media(query); |
310 | 485 | } | 492 | } |
311 | 486 | 493 | ||
313 | 487 | std::vector<Album> MediaStore::listAlbums(const std::string& artist, const std::string& album_artist, int limit) const { | 494 | std::vector<Album> MediaStore::listAlbums(const Filter &filter, int limit) const { |
314 | 488 | std::string qs(R"( | 495 | std::string qs(R"( |
315 | 489 | SELECT album, album_artist FROM media | 496 | SELECT album, album_artist FROM media |
316 | 490 | WHERE type = ? | 497 | WHERE type = ? |
317 | 491 | )"); | 498 | )"); |
319 | 492 | if (!artist.empty()) { | 499 | if (filter.hasArtist()) { |
320 | 493 | qs += " AND artist = ?"; | 500 | qs += " AND artist = ?"; |
321 | 494 | } | 501 | } |
323 | 495 | if (!album_artist.empty()) { | 502 | if (filter.hasAlbumArtist()) { |
324 | 496 | qs += " AND album_artist = ?"; | 503 | qs += " AND album_artist = ?"; |
325 | 497 | } | 504 | } |
326 | 505 | if (filter.hasGenre()) { | ||
327 | 506 | qs += "AND genre = ?"; | ||
328 | 507 | } | ||
329 | 498 | qs += R"( | 508 | qs += R"( |
330 | 499 | GROUP BY album, album_artist | 509 | GROUP BY album, album_artist |
331 | 500 | ORDER BY album_artist, album | 510 | ORDER BY album_artist, album |
332 | @@ -503,37 +513,68 @@ | |||
333 | 503 | Statement query(p->db, qs.c_str()); | 513 | Statement query(p->db, qs.c_str()); |
334 | 504 | int param = 1; | 514 | int param = 1; |
335 | 505 | query.bind(param++, (int)AudioMedia); | 515 | query.bind(param++, (int)AudioMedia); |
341 | 506 | if (!artist.empty()) { | 516 | if (filter.hasArtist()) { |
342 | 507 | query.bind(param++, artist); | 517 | query.bind(param++, filter.getArtist()); |
343 | 508 | } | 518 | } |
344 | 509 | if (!album_artist.empty()) { | 519 | if (filter.hasAlbumArtist()) { |
345 | 510 | query.bind(param++, album_artist); | 520 | query.bind(param++, filter.getAlbumArtist()); |
346 | 521 | } | ||
347 | 522 | if (filter.hasGenre()) { | ||
348 | 523 | query.bind(param++, filter.getGenre()); | ||
349 | 511 | } | 524 | } |
350 | 512 | query.bind(param++, limit); | 525 | query.bind(param++, limit); |
351 | 513 | 526 | ||
352 | 514 | return collect_albums(query); | 527 | return collect_albums(query); |
353 | 515 | } | 528 | } |
354 | 516 | 529 | ||
360 | 517 | vector<std::string> MediaStore::listArtists(bool album_artists, int limit) const { | 530 | vector<std::string> MediaStore::listArtists(const Filter &filter, int limit) const { |
361 | 518 | const char *qs; | 531 | string qs(R"( |
362 | 519 | 532 | SELECT artist FROM media | |
363 | 520 | if (album_artists) { | 533 | WHERE type = ? |
364 | 521 | qs = R"( | 534 | )"); |
365 | 535 | if (filter.hasGenre()) { | ||
366 | 536 | qs += " AND genre = ?"; | ||
367 | 537 | } | ||
368 | 538 | qs += R"( | ||
369 | 539 | GROUP BY artist | ||
370 | 540 | ORDER BY artist | ||
371 | 541 | LIMIT ? | ||
372 | 542 | )"; | ||
373 | 543 | Statement query(p->db, qs.c_str()); | ||
374 | 544 | int param = 1; | ||
375 | 545 | query.bind(param++, (int)AudioMedia); | ||
376 | 546 | if (filter.hasGenre()) { | ||
377 | 547 | query.bind(param++, filter.getGenre()); | ||
378 | 548 | } | ||
379 | 549 | query.bind(param++, limit); | ||
380 | 550 | |||
381 | 551 | vector<string> artists; | ||
382 | 552 | while (query.step()) { | ||
383 | 553 | artists.push_back(query.getText(0)); | ||
384 | 554 | } | ||
385 | 555 | return artists; | ||
386 | 556 | } | ||
387 | 557 | |||
388 | 558 | vector<std::string> MediaStore::listAlbumArtists(const Filter &filter, int limit) const { | ||
389 | 559 | string qs(R"( | ||
390 | 522 | SELECT album_artist FROM media | 560 | SELECT album_artist FROM media |
391 | 561 | WHERE type = ? | ||
392 | 562 | )"); | ||
393 | 563 | if (filter.hasGenre()) { | ||
394 | 564 | qs += " AND genre = ?"; | ||
395 | 565 | } | ||
396 | 566 | qs += R"( | ||
397 | 523 | GROUP BY album_artist | 567 | GROUP BY album_artist |
398 | 524 | ORDER BY album_artist | 568 | ORDER BY album_artist |
399 | 525 | LIMIT ? | 569 | LIMIT ? |
400 | 526 | )"; | 570 | )"; |
408 | 527 | } else { | 571 | Statement query(p->db, qs.c_str()); |
409 | 528 | qs = R"( | 572 | int param = 1; |
410 | 529 | SELECT artist FROM media | 573 | query.bind(param++, (int)AudioMedia); |
411 | 530 | GROUP BY artist | 574 | if (filter.hasGenre()) { |
412 | 531 | ORDER BY artist | 575 | query.bind(param++, filter.getGenre()); |
406 | 532 | LIMIT ? | ||
407 | 533 | )"; | ||
413 | 534 | } | 576 | } |
416 | 535 | Statement query(p->db, qs); | 577 | query.bind(param++, limit); |
415 | 536 | query.bind(1, limit); | ||
417 | 537 | 578 | ||
418 | 538 | vector<string> artists; | 579 | vector<string> artists; |
419 | 539 | while (query.step()) { | 580 | while (query.step()) { |
420 | @@ -542,6 +583,24 @@ | |||
421 | 542 | return artists; | 583 | return artists; |
422 | 543 | } | 584 | } |
423 | 544 | 585 | ||
424 | 586 | vector<std::string> MediaStore::listGenres(int limit) const { | ||
425 | 587 | Statement query(p->db, R"( | ||
426 | 588 | SELECT genre FROM media | ||
427 | 589 | WHERE type = ? | ||
428 | 590 | GROUP BY genre | ||
429 | 591 | ORDER BY genre | ||
430 | 592 | LIMIT ? | ||
431 | 593 | )"); | ||
432 | 594 | query.bind(1, (int)AudioMedia); | ||
433 | 595 | query.bind(2, limit); | ||
434 | 596 | |||
435 | 597 | vector<string> genres; | ||
436 | 598 | while (query.step()) { | ||
437 | 599 | genres.push_back(query.getText(0)); | ||
438 | 600 | } | ||
439 | 601 | return genres; | ||
440 | 602 | } | ||
441 | 603 | |||
442 | 545 | void MediaStorePrivate::pruneDeleted() { | 604 | void MediaStorePrivate::pruneDeleted() { |
443 | 546 | vector<string> deleted; | 605 | vector<string> deleted; |
444 | 547 | Statement query(db, "SELECT filename FROM media"); | 606 | Statement query(db, "SELECT filename FROM media"); |
445 | 548 | 607 | ||
446 | === modified file 'src/mediascanner/MediaStore.hh' | |||
447 | --- src/mediascanner/MediaStore.hh 2014-05-29 09:17:39 +0000 | |||
448 | +++ src/mediascanner/MediaStore.hh 2014-05-29 09:17:39 +0000 | |||
449 | @@ -29,6 +29,7 @@ | |||
450 | 29 | struct MediaStorePrivate; | 29 | struct MediaStorePrivate; |
451 | 30 | class MediaFile; | 30 | class MediaFile; |
452 | 31 | class Album; | 31 | class Album; |
453 | 32 | class Filter; | ||
454 | 32 | 33 | ||
455 | 33 | enum OpenType { | 34 | enum OpenType { |
456 | 34 | MS_READ_ONLY, | 35 | MS_READ_ONLY, |
457 | @@ -53,9 +54,11 @@ | |||
458 | 53 | std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const; | 54 | std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const; |
459 | 54 | std::vector<MediaFile> getAlbumSongs(const Album& album) const; | 55 | std::vector<MediaFile> getAlbumSongs(const Album& album) const; |
460 | 55 | std::string getETag(const std::string &filename) const; | 56 | std::string getETag(const std::string &filename) const; |
464 | 56 | std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const; | 57 | std::vector<MediaFile> listSongs(const Filter &filter, int limit=-1) const; |
465 | 57 | std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const; | 58 | std::vector<Album> listAlbums(const Filter &filter, int limit=-1) const; |
466 | 58 | std::vector<std::string> listArtists(bool album_artists, int limit=-1) const; | 59 | std::vector<std::string> listArtists(const Filter &filter, int limit=-1) const; |
467 | 60 | std::vector<std::string>listAlbumArtists(const Filter &filter, int limit=-1) const; | ||
468 | 61 | std::vector<std::string>listGenres(int limit=-1) const; | ||
469 | 59 | 62 | ||
470 | 60 | size_t size() const; | 63 | size_t size() const; |
471 | 61 | void pruneDeleted(); | 64 | void pruneDeleted(); |
472 | 62 | 65 | ||
473 | === modified file 'src/ms-dbus/dbus-codec.cc' | |||
474 | --- src/ms-dbus/dbus-codec.cc 2014-05-29 09:17:39 +0000 | |||
475 | +++ src/ms-dbus/dbus-codec.cc 2014-05-29 09:17:39 +0000 | |||
476 | @@ -24,6 +24,7 @@ | |||
477 | 24 | #include <mediascanner/MediaFile.hh> | 24 | #include <mediascanner/MediaFile.hh> |
478 | 25 | #include <mediascanner/MediaFileBuilder.hh> | 25 | #include <mediascanner/MediaFileBuilder.hh> |
479 | 26 | #include <mediascanner/Album.hh> | 26 | #include <mediascanner/Album.hh> |
480 | 27 | #include <mediascanner/Filter.hh> | ||
481 | 27 | #include "dbus-codec.hh" | 28 | #include "dbus-codec.hh" |
482 | 28 | 29 | ||
483 | 29 | using core::dbus::Message; | 30 | using core::dbus::Message; |
484 | @@ -32,6 +33,7 @@ | |||
485 | 32 | using mediascanner::MediaFileBuilder; | 33 | using mediascanner::MediaFileBuilder; |
486 | 33 | using mediascanner::MediaType; | 34 | using mediascanner::MediaType; |
487 | 34 | using mediascanner::Album; | 35 | using mediascanner::Album; |
488 | 36 | using mediascanner::Filter; | ||
489 | 35 | using std::string; | 37 | using std::string; |
490 | 36 | 38 | ||
491 | 37 | void Codec<MediaFile>::encode_argument(Message::Writer &out, const MediaFile &file) { | 39 | void Codec<MediaFile>::encode_argument(Message::Writer &out, const MediaFile &file) { |
492 | @@ -88,3 +90,46 @@ | |||
493 | 88 | r >> title >> artist; | 90 | r >> title >> artist; |
494 | 89 | album = Album(title, artist); | 91 | album = Album(title, artist); |
495 | 90 | } | 92 | } |
496 | 93 | |||
497 | 94 | void Codec<Filter>::encode_argument(Message::Writer &out, const Filter &filter) { | ||
498 | 95 | auto w = out.open_array(core::dbus::types::Signature("{ss}")); | ||
499 | 96 | |||
500 | 97 | if (filter.hasArtist()) { | ||
501 | 98 | w.close_dict_entry( | ||
502 | 99 | w.open_dict_entry() << string("artist") << filter.getArtist()); | ||
503 | 100 | } | ||
504 | 101 | if (filter.hasAlbum()) { | ||
505 | 102 | w.close_dict_entry( | ||
506 | 103 | w.open_dict_entry() << string("album") << filter.getAlbum()); | ||
507 | 104 | } | ||
508 | 105 | if (filter.hasAlbumArtist()) { | ||
509 | 106 | w.close_dict_entry( | ||
510 | 107 | w.open_dict_entry() << string("album_artist") << filter.getAlbumArtist()); | ||
511 | 108 | } | ||
512 | 109 | if (filter.hasGenre()) { | ||
513 | 110 | w.close_dict_entry( | ||
514 | 111 | w.open_dict_entry() << string("genre") << filter.getGenre()); | ||
515 | 112 | } | ||
516 | 113 | |||
517 | 114 | out.close_array(std::move(w)); | ||
518 | 115 | } | ||
519 | 116 | |||
520 | 117 | void Codec<Filter>::decode_argument(Message::Reader &in, Filter &filter) { | ||
521 | 118 | auto r = in.pop_array(); | ||
522 | 119 | |||
523 | 120 | filter.clear(); | ||
524 | 121 | while (r.type() != ArgumentType::invalid) { | ||
525 | 122 | string key, value; | ||
526 | 123 | r.pop_dict_entry() >> key >> value; | ||
527 | 124 | |||
528 | 125 | if (key == "artist") { | ||
529 | 126 | filter.setArtist(value); | ||
530 | 127 | } else if (key == "album") { | ||
531 | 128 | filter.setAlbum(value); | ||
532 | 129 | } else if (key == "album_artist") { | ||
533 | 130 | filter.setAlbumArtist(value); | ||
534 | 131 | } else if (key == "genre") { | ||
535 | 132 | filter.setGenre(value); | ||
536 | 133 | } | ||
537 | 134 | } | ||
538 | 135 | } | ||
539 | 91 | 136 | ||
540 | === modified file 'src/ms-dbus/dbus-codec.hh' | |||
541 | --- src/ms-dbus/dbus-codec.hh 2014-05-29 09:17:39 +0000 | |||
542 | +++ src/ms-dbus/dbus-codec.hh 2014-05-29 09:17:39 +0000 | |||
543 | @@ -27,6 +27,7 @@ | |||
544 | 27 | namespace mediascanner { | 27 | namespace mediascanner { |
545 | 28 | class MediaFile; | 28 | class MediaFile; |
546 | 29 | class Album; | 29 | class Album; |
547 | 30 | class Filter; | ||
548 | 30 | } | 31 | } |
549 | 31 | 32 | ||
550 | 32 | namespace core { | 33 | namespace core { |
551 | @@ -44,6 +45,12 @@ | |||
552 | 44 | static void decode_argument(Message::Reader &in, mediascanner::Album &album); | 45 | static void decode_argument(Message::Reader &in, mediascanner::Album &album); |
553 | 45 | }; | 46 | }; |
554 | 46 | 47 | ||
555 | 48 | template <> | ||
556 | 49 | struct Codec<mediascanner::Filter> { | ||
557 | 50 | static void encode_argument(Message::Writer &out, const mediascanner::Filter &filter); | ||
558 | 51 | static void decode_argument(Message::Reader &in, mediascanner::Filter &filter); | ||
559 | 52 | }; | ||
560 | 53 | |||
561 | 47 | namespace helper { | 54 | namespace helper { |
562 | 48 | 55 | ||
563 | 49 | template<> | 56 | template<> |
564 | @@ -80,6 +87,23 @@ | |||
565 | 80 | } | 87 | } |
566 | 81 | }; | 88 | }; |
567 | 82 | 89 | ||
568 | 90 | template<> | ||
569 | 91 | struct TypeMapper<mediascanner::Filter> { | ||
570 | 92 | constexpr static ArgumentType type_value() { | ||
571 | 93 | return ArgumentType::array; | ||
572 | 94 | } | ||
573 | 95 | constexpr static bool is_basic_type() { | ||
574 | 96 | return false; | ||
575 | 97 | } | ||
576 | 98 | constexpr static bool requires_signature() { | ||
577 | 99 | return true; | ||
578 | 100 | } | ||
579 | 101 | static const std::string &signature() { | ||
580 | 102 | static const std::string s = "a{ss}"; | ||
581 | 103 | return s; | ||
582 | 104 | } | ||
583 | 105 | }; | ||
584 | 106 | |||
585 | 83 | } | 107 | } |
586 | 84 | 108 | ||
587 | 85 | } | 109 | } |
588 | 86 | 110 | ||
589 | === modified file 'src/ms-dbus/dbus-interface.hh' | |||
590 | --- src/ms-dbus/dbus-interface.hh 2014-05-29 09:17:39 +0000 | |||
591 | +++ src/ms-dbus/dbus-interface.hh 2014-05-29 09:17:39 +0000 | |||
592 | @@ -153,6 +153,32 @@ | |||
593 | 153 | return std::chrono::seconds{1}; | 153 | return std::chrono::seconds{1}; |
594 | 154 | } | 154 | } |
595 | 155 | }; | 155 | }; |
596 | 156 | |||
597 | 157 | struct ListAlbumArtists { | ||
598 | 158 | typedef MediaStoreInterface Interface; | ||
599 | 159 | |||
600 | 160 | inline static const std::string& name() { | ||
601 | 161 | static std::string s = "ListAlbumArtists"; | ||
602 | 162 | return s; | ||
603 | 163 | } | ||
604 | 164 | |||
605 | 165 | inline static const std::chrono::milliseconds default_timeout() { | ||
606 | 166 | return std::chrono::seconds{1}; | ||
607 | 167 | } | ||
608 | 168 | }; | ||
609 | 169 | |||
610 | 170 | struct ListGenres { | ||
611 | 171 | typedef MediaStoreInterface Interface; | ||
612 | 172 | |||
613 | 173 | inline static const std::string& name() { | ||
614 | 174 | static std::string s = "ListGenres"; | ||
615 | 175 | return s; | ||
616 | 176 | } | ||
617 | 177 | |||
618 | 178 | inline static const std::chrono::milliseconds default_timeout() { | ||
619 | 179 | return std::chrono::seconds{1}; | ||
620 | 180 | } | ||
621 | 181 | }; | ||
622 | 156 | }; | 182 | }; |
623 | 157 | 183 | ||
624 | 158 | } | 184 | } |
625 | 159 | 185 | ||
626 | === modified file 'src/ms-dbus/service-skeleton.cc' | |||
627 | --- src/ms-dbus/service-skeleton.cc 2014-05-29 09:17:39 +0000 | |||
628 | +++ src/ms-dbus/service-skeleton.cc 2014-05-29 09:17:39 +0000 | |||
629 | @@ -6,6 +6,7 @@ | |||
630 | 6 | #include <sys/apparmor.h> | 6 | #include <sys/apparmor.h> |
631 | 7 | 7 | ||
632 | 8 | #include <mediascanner/Album.hh> | 8 | #include <mediascanner/Album.hh> |
633 | 9 | #include <mediascanner/Filter.hh> | ||
634 | 9 | #include <mediascanner/MediaFile.hh> | 10 | #include <mediascanner/MediaFile.hh> |
635 | 10 | #include <mediascanner/MediaStore.hh> | 11 | #include <mediascanner/MediaStore.hh> |
636 | 11 | 12 | ||
637 | @@ -88,6 +89,16 @@ | |||
638 | 88 | &Private::handle_list_artists, | 89 | &Private::handle_list_artists, |
639 | 89 | this, | 90 | this, |
640 | 90 | std::placeholders::_1)); | 91 | std::placeholders::_1)); |
641 | 92 | object->install_method_handler<MediaStoreInterface::ListAlbumArtists>( | ||
642 | 93 | std::bind( | ||
643 | 94 | &Private::handle_list_album_artists, | ||
644 | 95 | this, | ||
645 | 96 | std::placeholders::_1)); | ||
646 | 97 | object->install_method_handler<MediaStoreInterface::ListGenres>( | ||
647 | 98 | std::bind( | ||
648 | 99 | &Private::handle_list_genres, | ||
649 | 100 | this, | ||
650 | 101 | std::placeholders::_1)); | ||
651 | 91 | } | 102 | } |
652 | 92 | 103 | ||
653 | 93 | std::string get_client_apparmor_context(const Message::Ptr &message) { | 104 | std::string get_client_apparmor_context(const Message::Ptr &message) { |
654 | @@ -253,12 +264,12 @@ | |||
655 | 253 | if (!check_access(message, AudioMedia)) | 264 | if (!check_access(message, AudioMedia)) |
656 | 254 | return; | 265 | return; |
657 | 255 | 266 | ||
659 | 256 | std::string artist, album, album_artist; | 267 | Filter filter; |
660 | 257 | int32_t limit; | 268 | int32_t limit; |
662 | 258 | message->reader() >> artist >> album >> album_artist >> limit; | 269 | message->reader() >> filter >> limit; |
663 | 259 | Message::Ptr reply; | 270 | Message::Ptr reply; |
664 | 260 | try { | 271 | try { |
666 | 261 | auto results = store->listSongs(artist, album, album_artist, limit); | 272 | auto results = store->listSongs(filter, limit); |
667 | 262 | reply = Message::make_method_return(message); | 273 | reply = Message::make_method_return(message); |
668 | 263 | reply->writer() << results; | 274 | reply->writer() << results; |
669 | 264 | } catch (const std::exception &e) { | 275 | } catch (const std::exception &e) { |
670 | @@ -273,12 +284,12 @@ | |||
671 | 273 | if (!check_access(message, AudioMedia)) | 284 | if (!check_access(message, AudioMedia)) |
672 | 274 | return; | 285 | return; |
673 | 275 | 286 | ||
675 | 276 | std::string artist, album_artist; | 287 | Filter filter; |
676 | 277 | int32_t limit; | 288 | int32_t limit; |
678 | 278 | message->reader() >> artist >> album_artist >> limit; | 289 | message->reader() >> filter >> limit; |
679 | 279 | Message::Ptr reply; | 290 | Message::Ptr reply; |
680 | 280 | try { | 291 | try { |
682 | 281 | auto albums = store->listAlbums(artist, album_artist, limit); | 292 | auto albums = store->listAlbums(filter, limit); |
683 | 282 | reply = Message::make_method_return(message); | 293 | reply = Message::make_method_return(message); |
684 | 283 | reply->writer() << albums; | 294 | reply->writer() << albums; |
685 | 284 | } catch (const std::exception &e) { | 295 | } catch (const std::exception &e) { |
686 | @@ -293,14 +304,53 @@ | |||
687 | 293 | if (!check_access(message, AudioMedia)) | 304 | if (!check_access(message, AudioMedia)) |
688 | 294 | return; | 305 | return; |
689 | 295 | 306 | ||
698 | 296 | bool album_artists; | 307 | Filter filter; |
699 | 297 | int32_t limit; | 308 | int32_t limit; |
700 | 298 | message->reader() >> album_artists >> limit; | 309 | message->reader() >> filter >> limit; |
701 | 299 | Message::Ptr reply; | 310 | Message::Ptr reply; |
702 | 300 | try { | 311 | try { |
703 | 301 | auto artists = store->listArtists(album_artists, limit); | 312 | auto artists = store->listArtists(filter, limit); |
704 | 302 | reply = Message::make_method_return(message); | 313 | reply = Message::make_method_return(message); |
705 | 303 | reply->writer() << artists; | 314 | reply->writer() << artists; |
706 | 315 | } catch (const std::exception &e) { | ||
707 | 316 | reply = Message::make_error( | ||
708 | 317 | message, MediaStoreInterface::Errors::Error::name(), | ||
709 | 318 | e.what()); | ||
710 | 319 | } | ||
711 | 320 | impl->access_bus()->send(reply); | ||
712 | 321 | } | ||
713 | 322 | |||
714 | 323 | void handle_list_album_artists(const Message::Ptr &message) { | ||
715 | 324 | if (!check_access(message, AudioMedia)) | ||
716 | 325 | return; | ||
717 | 326 | |||
718 | 327 | Filter filter; | ||
719 | 328 | int32_t limit; | ||
720 | 329 | message->reader() >> filter >> limit; | ||
721 | 330 | Message::Ptr reply; | ||
722 | 331 | try { | ||
723 | 332 | auto artists = store->listAlbumArtists(filter, limit); | ||
724 | 333 | reply = Message::make_method_return(message); | ||
725 | 334 | reply->writer() << artists; | ||
726 | 335 | } catch (const std::exception &e) { | ||
727 | 336 | reply = Message::make_error( | ||
728 | 337 | message, MediaStoreInterface::Errors::Error::name(), | ||
729 | 338 | e.what()); | ||
730 | 339 | } | ||
731 | 340 | impl->access_bus()->send(reply); | ||
732 | 341 | } | ||
733 | 342 | |||
734 | 343 | void handle_list_genres(const Message::Ptr &message) { | ||
735 | 344 | if (!check_access(message, AudioMedia)) | ||
736 | 345 | return; | ||
737 | 346 | |||
738 | 347 | int32_t limit; | ||
739 | 348 | message->reader() >> limit; | ||
740 | 349 | Message::Ptr reply; | ||
741 | 350 | try { | ||
742 | 351 | auto genres = store->listGenres(limit); | ||
743 | 352 | reply = Message::make_method_return(message); | ||
744 | 353 | reply->writer() << genres; | ||
745 | 304 | } catch (const std::exception &e) { | 354 | } catch (const std::exception &e) { |
746 | 305 | reply = Message::make_error( | 355 | reply = Message::make_error( |
747 | 306 | message, MediaStoreInterface::Errors::Error::name(), | 356 | message, MediaStoreInterface::Errors::Error::name(), |
748 | 307 | 357 | ||
749 | === modified file 'src/ms-dbus/service-stub.cc' | |||
750 | --- src/ms-dbus/service-stub.cc 2014-05-29 09:17:39 +0000 | |||
751 | +++ src/ms-dbus/service-stub.cc 2014-05-29 09:17:39 +0000 | |||
752 | @@ -20,6 +20,7 @@ | |||
753 | 20 | #include <stdexcept> | 20 | #include <stdexcept> |
754 | 21 | 21 | ||
755 | 22 | #include <mediascanner/Album.hh> | 22 | #include <mediascanner/Album.hh> |
756 | 23 | #include <mediascanner/Filter.hh> | ||
757 | 23 | #include <mediascanner/MediaFile.hh> | 24 | #include <mediascanner/MediaFile.hh> |
758 | 24 | #include "service-stub.hh" | 25 | #include "service-stub.hh" |
759 | 25 | #include "dbus-interface.hh" | 26 | #include "dbus-interface.hh" |
760 | @@ -79,21 +80,35 @@ | |||
761 | 79 | return result.value(); | 80 | return result.value(); |
762 | 80 | } | 81 | } |
763 | 81 | 82 | ||
779 | 82 | std::vector<MediaFile> ServiceStub::listSongs(const string &artist, const string &album, const string &album_artist, int limit) const { | 83 | std::vector<MediaFile> ServiceStub::listSongs(const Filter &filter, int limit) const { |
780 | 83 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListSongs, std::vector<MediaFile>>(artist, album, album_artist, (int32_t)limit); | 84 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListSongs, std::vector<MediaFile>>(filter, (int32_t)limit); |
781 | 84 | if (result.is_error()) | 85 | if (result.is_error()) |
782 | 85 | throw std::runtime_error(result.error().print()); | 86 | throw std::runtime_error(result.error().print()); |
783 | 86 | return result.value(); | 87 | return result.value(); |
784 | 87 | } | 88 | } |
785 | 88 | 89 | ||
786 | 89 | std::vector<Album> ServiceStub::listAlbums(const string &artist, const string &album_artist, int limit) const { | 90 | std::vector<Album> ServiceStub::listAlbums(const Filter &filter, int limit) const { |
787 | 90 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListAlbums, std::vector<Album>>(artist, album_artist, (int32_t)limit); | 91 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListAlbums, std::vector<Album>>(filter, (int32_t)limit); |
788 | 91 | if (result.is_error()) | 92 | if (result.is_error()) |
789 | 92 | throw std::runtime_error(result.error().print()); | 93 | throw std::runtime_error(result.error().print()); |
790 | 93 | return result.value(); | 94 | return result.value(); |
791 | 94 | } | 95 | } |
792 | 95 | std::vector<string> ServiceStub::listArtists(bool album_artists, int limit) const { | 96 | std::vector<string> ServiceStub::listArtists(const Filter &filter, int limit) const { |
793 | 96 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListArtists, std::vector<string>>(album_artists, (int32_t)limit); | 97 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListArtists, std::vector<string>>(filter, (int32_t)limit); |
794 | 98 | if (result.is_error()) | ||
795 | 99 | throw std::runtime_error(result.error().print()); | ||
796 | 100 | return result.value(); | ||
797 | 101 | } | ||
798 | 102 | |||
799 | 103 | std::vector<string> ServiceStub::listAlbumArtists(const Filter &filter, int limit) const { | ||
800 | 104 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListAlbumArtists, std::vector<string>>(filter, (int32_t)limit); | ||
801 | 105 | if (result.is_error()) | ||
802 | 106 | throw std::runtime_error(result.error().print()); | ||
803 | 107 | return result.value(); | ||
804 | 108 | } | ||
805 | 109 | |||
806 | 110 | std::vector<string> ServiceStub::listGenres(int limit) const { | ||
807 | 111 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListGenres, std::vector<string>>((int32_t)limit); | ||
808 | 97 | if (result.is_error()) | 112 | if (result.is_error()) |
809 | 98 | throw std::runtime_error(result.error().print()); | 113 | throw std::runtime_error(result.error().print()); |
810 | 99 | return result.value(); | 114 | return result.value(); |
811 | 100 | 115 | ||
812 | === modified file 'src/ms-dbus/service-stub.hh' | |||
813 | --- src/ms-dbus/service-stub.hh 2014-05-29 09:17:39 +0000 | |||
814 | +++ src/ms-dbus/service-stub.hh 2014-05-29 09:17:39 +0000 | |||
815 | @@ -32,6 +32,7 @@ | |||
816 | 32 | namespace mediascanner { | 32 | namespace mediascanner { |
817 | 33 | 33 | ||
818 | 34 | class Album; | 34 | class Album; |
819 | 35 | class Filter; | ||
820 | 35 | class MediaFile; | 36 | class MediaFile; |
821 | 36 | 37 | ||
822 | 37 | namespace dbus { | 38 | namespace dbus { |
823 | @@ -46,9 +47,11 @@ | |||
824 | 46 | std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const; | 47 | std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const; |
825 | 47 | std::vector<MediaFile> getAlbumSongs(const Album& album) const; | 48 | std::vector<MediaFile> getAlbumSongs(const Album& album) const; |
826 | 48 | std::string getETag(const std::string &filename) const; | 49 | std::string getETag(const std::string &filename) const; |
830 | 49 | std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const; | 50 | std::vector<MediaFile> listSongs(const Filter &filter, int limit=-1) const; |
831 | 50 | std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const; | 51 | std::vector<Album> listAlbums(const Filter &filter, int limit=-1) const; |
832 | 51 | std::vector<std::string> listArtists(bool album_artists, int limit=-1) const; | 52 | std::vector<std::string> listArtists(const Filter &filter, int limit=-1) const; |
833 | 53 | std::vector<std::string> listAlbumArtists(const Filter &filter, int limit=-1) const; | ||
834 | 54 | std::vector<std::string> listGenres(int limit=-1) const; | ||
835 | 52 | 55 | ||
836 | 53 | private: | 56 | private: |
837 | 54 | struct Private; | 57 | struct Private; |
838 | 55 | 58 | ||
839 | === modified file 'src/qml/Ubuntu/MediaScanner/AlbumModelBase.cc' | |||
840 | --- src/qml/Ubuntu/MediaScanner/AlbumModelBase.cc 2014-05-06 09:09:49 +0000 | |||
841 | +++ src/qml/Ubuntu/MediaScanner/AlbumModelBase.cc 2014-05-29 09:17:39 +0000 | |||
842 | @@ -62,4 +62,5 @@ | |||
843 | 62 | beginResetModel(); | 62 | beginResetModel(); |
844 | 63 | this->results = results; | 63 | this->results = results; |
845 | 64 | endResetModel(); | 64 | endResetModel(); |
846 | 65 | Q_EMIT rowCountChanged(); | ||
847 | 65 | } | 66 | } |
848 | 66 | 67 | ||
849 | === modified file 'src/qml/Ubuntu/MediaScanner/AlbumModelBase.hh' | |||
850 | --- src/qml/Ubuntu/MediaScanner/AlbumModelBase.hh 2014-05-06 09:09:49 +0000 | |||
851 | +++ src/qml/Ubuntu/MediaScanner/AlbumModelBase.hh 2014-05-29 09:17:39 +0000 | |||
852 | @@ -31,7 +31,7 @@ | |||
853 | 31 | class AlbumModelBase : public QAbstractListModel { | 31 | class AlbumModelBase : public QAbstractListModel { |
854 | 32 | Q_OBJECT | 32 | Q_OBJECT |
855 | 33 | Q_ENUMS(Roles) | 33 | Q_ENUMS(Roles) |
857 | 34 | Q_PROPERTY(int rowCount READ rowCount) // NOTIFY modelReset | 34 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
858 | 35 | public: | 35 | public: |
859 | 36 | enum Roles { | 36 | enum Roles { |
860 | 37 | RoleTitle, | 37 | RoleTitle, |
861 | @@ -44,6 +44,8 @@ | |||
862 | 44 | QVariant data(const QModelIndex &index, int role) const override; | 44 | QVariant data(const QModelIndex &index, int role) const override; |
863 | 45 | 45 | ||
864 | 46 | Q_INVOKABLE QVariant get(int row, Roles role) const; | 46 | Q_INVOKABLE QVariant get(int row, Roles role) const; |
865 | 47 | Q_SIGNALS: | ||
866 | 48 | void rowCountChanged(); | ||
867 | 47 | protected: | 49 | protected: |
868 | 48 | QHash<int, QByteArray> roleNames() const override; | 50 | QHash<int, QByteArray> roleNames() const override; |
869 | 49 | void updateResults(const std::vector<mediascanner::Album> &results); | 51 | void updateResults(const std::vector<mediascanner::Album> &results); |
870 | 50 | 52 | ||
871 | === modified file 'src/qml/Ubuntu/MediaScanner/AlbumsModel.cc' | |||
872 | --- src/qml/Ubuntu/MediaScanner/AlbumsModel.cc 2014-02-27 07:02:21 +0000 | |||
873 | +++ src/qml/Ubuntu/MediaScanner/AlbumsModel.cc 2014-05-29 09:17:39 +0000 | |||
874 | @@ -24,8 +24,6 @@ | |||
875 | 24 | AlbumsModel::AlbumsModel(QObject *parent) | 24 | AlbumsModel::AlbumsModel(QObject *parent) |
876 | 25 | : AlbumModelBase(parent), | 25 | : AlbumModelBase(parent), |
877 | 26 | store(nullptr), | 26 | store(nullptr), |
878 | 27 | artist(""), | ||
879 | 28 | album_artist(""), | ||
880 | 29 | limit(-1) { | 27 | limit(-1) { |
881 | 30 | } | 28 | } |
882 | 31 | 29 | ||
883 | @@ -40,25 +38,66 @@ | |||
884 | 40 | } | 38 | } |
885 | 41 | } | 39 | } |
886 | 42 | 40 | ||
906 | 43 | QString AlbumsModel::getArtist() { | 41 | QVariant AlbumsModel::getArtist() { |
907 | 44 | return artist; | 42 | if (!filter.hasArtist()) |
908 | 45 | } | 43 | return QVariant(); |
909 | 46 | 44 | return QString::fromStdString(filter.getArtist()); | |
910 | 47 | void AlbumsModel::setArtist(const QString artist) { | 45 | } |
911 | 48 | if (this->artist != artist) { | 46 | |
912 | 49 | this->artist = artist; | 47 | void AlbumsModel::setArtist(const QVariant artist) { |
913 | 50 | update(); | 48 | if (artist.isNull()) { |
914 | 51 | } | 49 | if (filter.hasArtist()) { |
915 | 52 | } | 50 | filter.unsetArtist(); |
916 | 53 | 51 | update(); | |
917 | 54 | QString AlbumsModel::getAlbumArtist() { | 52 | } |
918 | 55 | return album_artist; | 53 | } else { |
919 | 56 | } | 54 | const std::string std_artist = artist.value<QString>().toStdString(); |
920 | 57 | 55 | if (!filter.hasArtist() || filter.getArtist() != std_artist) { | |
921 | 58 | void AlbumsModel::setAlbumArtist(const QString album_artist) { | 56 | filter.setArtist(std_artist); |
922 | 59 | if (this->album_artist != album_artist) { | 57 | update(); |
923 | 60 | this->album_artist = album_artist; | 58 | } |
924 | 61 | update(); | 59 | } |
925 | 60 | } | ||
926 | 61 | |||
927 | 62 | QVariant AlbumsModel::getAlbumArtist() { | ||
928 | 63 | if (!filter.hasAlbumArtist()) | ||
929 | 64 | return QVariant(); | ||
930 | 65 | return QString::fromStdString(filter.getAlbumArtist()); | ||
931 | 66 | } | ||
932 | 67 | |||
933 | 68 | void AlbumsModel::setAlbumArtist(const QVariant album_artist) { | ||
934 | 69 | if (album_artist.isNull()) { | ||
935 | 70 | if (filter.hasAlbumArtist()) { | ||
936 | 71 | filter.unsetAlbumArtist(); | ||
937 | 72 | update(); | ||
938 | 73 | } | ||
939 | 74 | } else { | ||
940 | 75 | const std::string std_album_artist = album_artist.value<QString>().toStdString(); | ||
941 | 76 | if (!filter.hasAlbumArtist() || filter.getAlbumArtist() != std_album_artist) { | ||
942 | 77 | filter.setAlbumArtist(std_album_artist); | ||
943 | 78 | update(); | ||
944 | 79 | } | ||
945 | 80 | } | ||
946 | 81 | } | ||
947 | 82 | |||
948 | 83 | QVariant AlbumsModel::getGenre() { | ||
949 | 84 | if (!filter.hasGenre()) | ||
950 | 85 | return QVariant(); | ||
951 | 86 | return QString::fromStdString(filter.getGenre()); | ||
952 | 87 | } | ||
953 | 88 | |||
954 | 89 | void AlbumsModel::setGenre(const QVariant genre) { | ||
955 | 90 | if (genre.isNull()) { | ||
956 | 91 | if (filter.hasGenre()) { | ||
957 | 92 | filter.unsetGenre(); | ||
958 | 93 | update(); | ||
959 | 94 | } | ||
960 | 95 | } else { | ||
961 | 96 | const std::string std_genre = genre.value<QString>().toStdString(); | ||
962 | 97 | if (!filter.hasGenre() || filter.getGenre() != std_genre) { | ||
963 | 98 | filter.setGenre(std_genre); | ||
964 | 99 | update(); | ||
965 | 100 | } | ||
966 | 62 | } | 101 | } |
967 | 63 | } | 102 | } |
968 | 64 | 103 | ||
969 | @@ -77,6 +116,6 @@ | |||
970 | 77 | if (store == nullptr) { | 116 | if (store == nullptr) { |
971 | 78 | updateResults(std::vector<mediascanner::Album>()); | 117 | updateResults(std::vector<mediascanner::Album>()); |
972 | 79 | } else { | 118 | } else { |
974 | 80 | updateResults(store->store.listAlbums(artist.toStdString(), album_artist.toStdString(), limit)); | 119 | updateResults(store->store.listAlbums(filter, limit)); |
975 | 81 | } | 120 | } |
976 | 82 | } | 121 | } |
977 | 83 | 122 | ||
978 | === modified file 'src/qml/Ubuntu/MediaScanner/AlbumsModel.hh' | |||
979 | --- src/qml/Ubuntu/MediaScanner/AlbumsModel.hh 2014-02-27 07:02:21 +0000 | |||
980 | +++ src/qml/Ubuntu/MediaScanner/AlbumsModel.hh 2014-05-29 09:17:39 +0000 | |||
981 | @@ -22,6 +22,7 @@ | |||
982 | 22 | 22 | ||
983 | 23 | #include <QString> | 23 | #include <QString> |
984 | 24 | 24 | ||
985 | 25 | #include <mediascanner/Filter.hh> | ||
986 | 25 | #include "MediaStoreWrapper.hh" | 26 | #include "MediaStoreWrapper.hh" |
987 | 26 | #include "AlbumModelBase.hh" | 27 | #include "AlbumModelBase.hh" |
988 | 27 | 28 | ||
989 | @@ -31,8 +32,9 @@ | |||
990 | 31 | class AlbumsModel : public AlbumModelBase { | 32 | class AlbumsModel : public AlbumModelBase { |
991 | 32 | Q_OBJECT | 33 | Q_OBJECT |
992 | 33 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) | 34 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) |
995 | 34 | Q_PROPERTY(QString artist READ getArtist WRITE setArtist) | 35 | Q_PROPERTY(QVariant artist READ getArtist WRITE setArtist) |
996 | 35 | Q_PROPERTY(QString albumArtist READ getAlbumArtist WRITE setAlbumArtist) | 36 | Q_PROPERTY(QVariant albumArtist READ getAlbumArtist WRITE setAlbumArtist) |
997 | 37 | Q_PROPERTY(QVariant genre READ getGenre WRITE setGenre) | ||
998 | 36 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) | 38 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) |
999 | 37 | public: | 39 | public: |
1000 | 38 | explicit AlbumsModel(QObject *parent=0); | 40 | explicit AlbumsModel(QObject *parent=0); |
1001 | @@ -40,17 +42,19 @@ | |||
1002 | 40 | MediaStoreWrapper *getStore(); | 42 | MediaStoreWrapper *getStore(); |
1003 | 41 | void setStore(MediaStoreWrapper *store); | 43 | void setStore(MediaStoreWrapper *store); |
1004 | 42 | 44 | ||
1009 | 43 | QString getArtist(); | 45 | QVariant getArtist(); |
1010 | 44 | void setArtist(const QString artist); | 46 | void setArtist(const QVariant artist); |
1011 | 45 | QString getAlbumArtist(); | 47 | QVariant getAlbumArtist(); |
1012 | 46 | void setAlbumArtist(const QString album_artist); | 48 | void setAlbumArtist(const QVariant album_artist); |
1013 | 49 | QVariant getGenre(); | ||
1014 | 50 | void setGenre(const QVariant genre); | ||
1015 | 47 | int getLimit(); | 51 | int getLimit(); |
1016 | 48 | void setLimit(int limit); | 52 | void setLimit(int limit); |
1017 | 49 | private: | 53 | private: |
1018 | 50 | void update(); | 54 | void update(); |
1019 | 51 | 55 | ||
1020 | 52 | MediaStoreWrapper *store; | 56 | MediaStoreWrapper *store; |
1022 | 53 | QString artist, album_artist; | 57 | Filter filter; |
1023 | 54 | int limit; | 58 | int limit; |
1024 | 55 | }; | 59 | }; |
1025 | 56 | 60 | ||
1026 | 57 | 61 | ||
1027 | === modified file 'src/qml/Ubuntu/MediaScanner/ArtistsModel.cc' | |||
1028 | --- src/qml/Ubuntu/MediaScanner/ArtistsModel.cc 2014-05-06 09:09:49 +0000 | |||
1029 | +++ src/qml/Ubuntu/MediaScanner/ArtistsModel.cc 2014-05-29 09:17:39 +0000 | |||
1030 | @@ -75,6 +75,27 @@ | |||
1031 | 75 | } | 75 | } |
1032 | 76 | } | 76 | } |
1033 | 77 | 77 | ||
1034 | 78 | QVariant ArtistsModel::getGenre() { | ||
1035 | 79 | if (!filter.hasGenre()) | ||
1036 | 80 | return QVariant(); | ||
1037 | 81 | return QString::fromStdString(filter.getGenre()); | ||
1038 | 82 | } | ||
1039 | 83 | |||
1040 | 84 | void ArtistsModel::setGenre(const QVariant genre) { | ||
1041 | 85 | if (genre.isNull()) { | ||
1042 | 86 | if (filter.hasGenre()) { | ||
1043 | 87 | filter.unsetGenre(); | ||
1044 | 88 | update(); | ||
1045 | 89 | } | ||
1046 | 90 | } else { | ||
1047 | 91 | const std::string std_genre = genre.value<QString>().toStdString(); | ||
1048 | 92 | if (!filter.hasGenre() || filter.getGenre() != std_genre) { | ||
1049 | 93 | filter.setGenre(std_genre); | ||
1050 | 94 | update(); | ||
1051 | 95 | } | ||
1052 | 96 | } | ||
1053 | 97 | } | ||
1054 | 98 | |||
1055 | 78 | int ArtistsModel::getLimit() { | 99 | int ArtistsModel::getLimit() { |
1056 | 79 | return limit; | 100 | return limit; |
1057 | 80 | } | 101 | } |
1058 | @@ -91,8 +112,12 @@ | |||
1059 | 91 | if (store == nullptr) { | 112 | if (store == nullptr) { |
1060 | 92 | this->results.clear(); | 113 | this->results.clear(); |
1061 | 93 | } else { | 114 | } else { |
1063 | 94 | this->results = store->store.listArtists(album_artists, limit); | 115 | if (album_artists) { |
1064 | 116 | this->results = store->store.listAlbumArtists(filter, limit); | ||
1065 | 117 | } else { | ||
1066 | 118 | this->results = store->store.listArtists(filter, limit); | ||
1067 | 119 | } | ||
1068 | 95 | } | 120 | } |
1069 | 96 | this->results = results; | ||
1070 | 97 | endResetModel(); | 121 | endResetModel(); |
1071 | 122 | Q_EMIT rowCountChanged(); | ||
1072 | 98 | } | 123 | } |
1073 | 99 | 124 | ||
1074 | === modified file 'src/qml/Ubuntu/MediaScanner/ArtistsModel.hh' | |||
1075 | --- src/qml/Ubuntu/MediaScanner/ArtistsModel.hh 2014-05-06 09:09:49 +0000 | |||
1076 | +++ src/qml/Ubuntu/MediaScanner/ArtistsModel.hh 2014-05-29 09:17:39 +0000 | |||
1077 | @@ -24,6 +24,7 @@ | |||
1078 | 24 | #include <QAbstractListModel> | 24 | #include <QAbstractListModel> |
1079 | 25 | #include <QString> | 25 | #include <QString> |
1080 | 26 | 26 | ||
1081 | 27 | #include <mediascanner/Filter.hh> | ||
1082 | 27 | #include "MediaStoreWrapper.hh" | 28 | #include "MediaStoreWrapper.hh" |
1083 | 28 | 29 | ||
1084 | 29 | namespace mediascanner { | 30 | namespace mediascanner { |
1085 | @@ -34,8 +35,9 @@ | |||
1086 | 34 | Q_ENUMS(Roles) | 35 | Q_ENUMS(Roles) |
1087 | 35 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) | 36 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) |
1088 | 36 | Q_PROPERTY(bool albumArtists READ getAlbumArtists WRITE setAlbumArtists) | 37 | Q_PROPERTY(bool albumArtists READ getAlbumArtists WRITE setAlbumArtists) |
1089 | 38 | Q_PROPERTY(QVariant genre READ getGenre WRITE setGenre) | ||
1090 | 37 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) | 39 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) |
1092 | 38 | Q_PROPERTY(int rowCount READ rowCount) // NOTIFY modelReset | 40 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
1093 | 39 | public: | 41 | public: |
1094 | 40 | enum Roles { | 42 | enum Roles { |
1095 | 41 | RoleArtist, | 43 | RoleArtist, |
1096 | @@ -46,6 +48,8 @@ | |||
1097 | 46 | QVariant data(const QModelIndex &index, int role) const override; | 48 | QVariant data(const QModelIndex &index, int role) const override; |
1098 | 47 | 49 | ||
1099 | 48 | Q_INVOKABLE QVariant get(int row, Roles role) const; | 50 | Q_INVOKABLE QVariant get(int row, Roles role) const; |
1100 | 51 | Q_SIGNALS: | ||
1101 | 52 | void rowCountChanged(); | ||
1102 | 49 | protected: | 53 | protected: |
1103 | 50 | QHash<int, QByteArray> roleNames() const override; | 54 | QHash<int, QByteArray> roleNames() const override; |
1104 | 51 | 55 | ||
1105 | @@ -53,6 +57,8 @@ | |||
1106 | 53 | void setStore(MediaStoreWrapper *store); | 57 | void setStore(MediaStoreWrapper *store); |
1107 | 54 | bool getAlbumArtists(); | 58 | bool getAlbumArtists(); |
1108 | 55 | void setAlbumArtists(bool album_artists); | 59 | void setAlbumArtists(bool album_artists); |
1109 | 60 | QVariant getGenre(); | ||
1110 | 61 | void setGenre(QVariant genre); | ||
1111 | 56 | int getLimit(); | 62 | int getLimit(); |
1112 | 57 | void setLimit(int limit); | 63 | void setLimit(int limit); |
1113 | 58 | 64 | ||
1114 | @@ -62,6 +68,7 @@ | |||
1115 | 62 | QHash<int, QByteArray> roles; | 68 | QHash<int, QByteArray> roles; |
1116 | 63 | std::vector<std::string> results; | 69 | std::vector<std::string> results; |
1117 | 64 | MediaStoreWrapper *store; | 70 | MediaStoreWrapper *store; |
1118 | 71 | Filter filter; | ||
1119 | 65 | bool album_artists; | 72 | bool album_artists; |
1120 | 66 | int limit; | 73 | int limit; |
1121 | 67 | }; | 74 | }; |
1122 | 68 | 75 | ||
1123 | === modified file 'src/qml/Ubuntu/MediaScanner/CMakeLists.txt' | |||
1124 | --- src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-05-29 09:17:39 +0000 | |||
1125 | +++ src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-05-29 09:17:39 +0000 | |||
1126 | @@ -12,6 +12,7 @@ | |||
1127 | 12 | AlbumModelBase.cc | 12 | AlbumModelBase.cc |
1128 | 13 | AlbumsModel.cc | 13 | AlbumsModel.cc |
1129 | 14 | ArtistsModel.cc | 14 | ArtistsModel.cc |
1130 | 15 | GenresModel.cc | ||
1131 | 15 | SongsModel.cc | 16 | SongsModel.cc |
1132 | 16 | SongsSearchModel.cc | 17 | SongsSearchModel.cc |
1133 | 17 | ) | 18 | ) |
1134 | 18 | 19 | ||
1135 | === added file 'src/qml/Ubuntu/MediaScanner/GenresModel.cc' | |||
1136 | --- src/qml/Ubuntu/MediaScanner/GenresModel.cc 1970-01-01 00:00:00 +0000 | |||
1137 | +++ src/qml/Ubuntu/MediaScanner/GenresModel.cc 2014-05-29 09:17:39 +0000 | |||
1138 | @@ -0,0 +1,86 @@ | |||
1139 | 1 | /* | ||
1140 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
1141 | 3 | * | ||
1142 | 4 | * Authors: | ||
1143 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
1144 | 6 | * | ||
1145 | 7 | * This program is free software: you can redistribute it and/or modify | ||
1146 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1147 | 9 | * published by the Free Software Foundation. | ||
1148 | 10 | * | ||
1149 | 11 | * This program is distributed in the hope that it will be useful, | ||
1150 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1151 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1152 | 14 | * GNU Lesser General Public License for more details. | ||
1153 | 15 | * | ||
1154 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
1155 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1156 | 18 | */ | ||
1157 | 19 | |||
1158 | 20 | #include "GenresModel.hh" | ||
1159 | 21 | |||
1160 | 22 | using namespace mediascanner::qml; | ||
1161 | 23 | |||
1162 | 24 | GenresModel::GenresModel(QObject *parent) | ||
1163 | 25 | : QAbstractListModel(parent), | ||
1164 | 26 | store(nullptr), | ||
1165 | 27 | limit(-1) { | ||
1166 | 28 | roles[Roles::RoleGenre] = "genre"; | ||
1167 | 29 | } | ||
1168 | 30 | |||
1169 | 31 | int GenresModel::rowCount(const QModelIndex &) const { | ||
1170 | 32 | return results.size(); | ||
1171 | 33 | } | ||
1172 | 34 | |||
1173 | 35 | QVariant GenresModel::data(const QModelIndex &index, int role) const { | ||
1174 | 36 | if (index.row() < 0 || index.row() >= (ptrdiff_t)results.size()) { | ||
1175 | 37 | return QVariant(); | ||
1176 | 38 | } | ||
1177 | 39 | switch (role) { | ||
1178 | 40 | case RoleGenre: | ||
1179 | 41 | return QString::fromStdString(results[index.row()]); | ||
1180 | 42 | default: | ||
1181 | 43 | return QVariant(); | ||
1182 | 44 | } | ||
1183 | 45 | } | ||
1184 | 46 | |||
1185 | 47 | QVariant GenresModel::get(int row, GenresModel::Roles role) const { | ||
1186 | 48 | return data(index(row, 0), role); | ||
1187 | 49 | } | ||
1188 | 50 | |||
1189 | 51 | QHash<int, QByteArray> GenresModel::roleNames() const { | ||
1190 | 52 | return roles; | ||
1191 | 53 | } | ||
1192 | 54 | |||
1193 | 55 | MediaStoreWrapper *GenresModel::getStore() { | ||
1194 | 56 | return store; | ||
1195 | 57 | } | ||
1196 | 58 | |||
1197 | 59 | void GenresModel::setStore(MediaStoreWrapper *store) { | ||
1198 | 60 | if (this->store != store) { | ||
1199 | 61 | this->store = store; | ||
1200 | 62 | update(); | ||
1201 | 63 | } | ||
1202 | 64 | } | ||
1203 | 65 | |||
1204 | 66 | int GenresModel::getLimit() { | ||
1205 | 67 | return limit; | ||
1206 | 68 | } | ||
1207 | 69 | |||
1208 | 70 | void GenresModel::setLimit(int limit) { | ||
1209 | 71 | if (this->limit != limit) { | ||
1210 | 72 | this->limit = limit; | ||
1211 | 73 | update(); | ||
1212 | 74 | } | ||
1213 | 75 | } | ||
1214 | 76 | |||
1215 | 77 | void GenresModel::update() { | ||
1216 | 78 | beginResetModel(); | ||
1217 | 79 | if (store == nullptr) { | ||
1218 | 80 | this->results.clear(); | ||
1219 | 81 | } else { | ||
1220 | 82 | this->results = store->store.listGenres(limit); | ||
1221 | 83 | } | ||
1222 | 84 | endResetModel(); | ||
1223 | 85 | Q_EMIT rowCountChanged(); | ||
1224 | 86 | } | ||
1225 | 0 | 87 | ||
1226 | === added file 'src/qml/Ubuntu/MediaScanner/GenresModel.hh' | |||
1227 | --- src/qml/Ubuntu/MediaScanner/GenresModel.hh 1970-01-01 00:00:00 +0000 | |||
1228 | +++ src/qml/Ubuntu/MediaScanner/GenresModel.hh 2014-05-29 09:17:39 +0000 | |||
1229 | @@ -0,0 +1,71 @@ | |||
1230 | 1 | /* | ||
1231 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
1232 | 3 | * | ||
1233 | 4 | * Authors: | ||
1234 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
1235 | 6 | * | ||
1236 | 7 | * This program is free software: you can redistribute it and/or modify | ||
1237 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1238 | 9 | * published by the Free Software Foundation. | ||
1239 | 10 | * | ||
1240 | 11 | * This program is distributed in the hope that it will be useful, | ||
1241 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1242 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1243 | 14 | * GNU Lesser General Public License for more details. | ||
1244 | 15 | * | ||
1245 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
1246 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1247 | 18 | */ | ||
1248 | 19 | |||
1249 | 20 | #ifndef MEDIASCANNER_QML_GENRESMODEL_H | ||
1250 | 21 | #define MEDIASCANNER_QML_GENRESMODEL_H | ||
1251 | 22 | |||
1252 | 23 | #include <string> | ||
1253 | 24 | #include <QAbstractListModel> | ||
1254 | 25 | #include <QString> | ||
1255 | 26 | |||
1256 | 27 | #include <mediascanner/Filter.hh> | ||
1257 | 28 | #include "MediaStoreWrapper.hh" | ||
1258 | 29 | |||
1259 | 30 | namespace mediascanner { | ||
1260 | 31 | namespace qml { | ||
1261 | 32 | |||
1262 | 33 | class GenresModel : public QAbstractListModel { | ||
1263 | 34 | Q_OBJECT | ||
1264 | 35 | Q_ENUMS(Roles) | ||
1265 | 36 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) | ||
1266 | 37 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) | ||
1267 | 38 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) | ||
1268 | 39 | public: | ||
1269 | 40 | enum Roles { | ||
1270 | 41 | RoleGenre, | ||
1271 | 42 | }; | ||
1272 | 43 | |||
1273 | 44 | explicit GenresModel(QObject *parent = 0); | ||
1274 | 45 | int rowCount(const QModelIndex &parent=QModelIndex()) const override; | ||
1275 | 46 | QVariant data(const QModelIndex &index, int role) const override; | ||
1276 | 47 | |||
1277 | 48 | Q_INVOKABLE QVariant get(int row, Roles role) const; | ||
1278 | 49 | Q_SIGNALS: | ||
1279 | 50 | void rowCountChanged(); | ||
1280 | 51 | protected: | ||
1281 | 52 | QHash<int, QByteArray> roleNames() const override; | ||
1282 | 53 | |||
1283 | 54 | MediaStoreWrapper *getStore(); | ||
1284 | 55 | void setStore(MediaStoreWrapper *store); | ||
1285 | 56 | int getLimit(); | ||
1286 | 57 | void setLimit(int limit); | ||
1287 | 58 | |||
1288 | 59 | private: | ||
1289 | 60 | void update(); | ||
1290 | 61 | |||
1291 | 62 | QHash<int, QByteArray> roles; | ||
1292 | 63 | std::vector<std::string> results; | ||
1293 | 64 | MediaStoreWrapper *store; | ||
1294 | 65 | int limit; | ||
1295 | 66 | }; | ||
1296 | 67 | |||
1297 | 68 | } | ||
1298 | 69 | } | ||
1299 | 70 | |||
1300 | 71 | #endif | ||
1301 | 0 | 72 | ||
1302 | === modified file 'src/qml/Ubuntu/MediaScanner/MediaFileModelBase.cc' | |||
1303 | --- src/qml/Ubuntu/MediaScanner/MediaFileModelBase.cc 2014-05-06 09:09:49 +0000 | |||
1304 | +++ src/qml/Ubuntu/MediaScanner/MediaFileModelBase.cc 2014-05-29 09:17:39 +0000 | |||
1305 | @@ -99,4 +99,5 @@ | |||
1306 | 99 | beginResetModel(); | 99 | beginResetModel(); |
1307 | 100 | this->results = results; | 100 | this->results = results; |
1308 | 101 | endResetModel(); | 101 | endResetModel(); |
1309 | 102 | Q_EMIT rowCountChanged(); | ||
1310 | 102 | } | 103 | } |
1311 | 103 | 104 | ||
1312 | === modified file 'src/qml/Ubuntu/MediaScanner/MediaFileModelBase.hh' | |||
1313 | --- src/qml/Ubuntu/MediaScanner/MediaFileModelBase.hh 2014-05-06 09:09:49 +0000 | |||
1314 | +++ src/qml/Ubuntu/MediaScanner/MediaFileModelBase.hh 2014-05-29 09:17:39 +0000 | |||
1315 | @@ -31,7 +31,7 @@ | |||
1316 | 31 | class MediaFileModelBase : public QAbstractListModel { | 31 | class MediaFileModelBase : public QAbstractListModel { |
1317 | 32 | Q_OBJECT | 32 | Q_OBJECT |
1318 | 33 | Q_ENUMS(Roles) | 33 | Q_ENUMS(Roles) |
1320 | 34 | Q_PROPERTY(int rowCount READ rowCount) // NOTIFY modelReset | 34 | Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) |
1321 | 35 | public: | 35 | public: |
1322 | 36 | enum Roles { | 36 | enum Roles { |
1323 | 37 | RoleModelData, | 37 | RoleModelData, |
1324 | @@ -56,6 +56,8 @@ | |||
1325 | 56 | QVariant data(const QModelIndex &index, int role) const override; | 56 | QVariant data(const QModelIndex &index, int role) const override; |
1326 | 57 | 57 | ||
1327 | 58 | Q_INVOKABLE QVariant get(int row, Roles role) const; | 58 | Q_INVOKABLE QVariant get(int row, Roles role) const; |
1328 | 59 | Q_SIGNALS: | ||
1329 | 60 | void rowCountChanged(); | ||
1330 | 59 | protected: | 61 | protected: |
1331 | 60 | QHash<int, QByteArray> roleNames() const override; | 62 | QHash<int, QByteArray> roleNames() const override; |
1332 | 61 | void updateResults(const std::vector<mediascanner::MediaFile> &results); | 63 | void updateResults(const std::vector<mediascanner::MediaFile> &results); |
1333 | 62 | 64 | ||
1334 | === modified file 'src/qml/Ubuntu/MediaScanner/SongsModel.cc' | |||
1335 | --- src/qml/Ubuntu/MediaScanner/SongsModel.cc 2014-02-27 05:37:36 +0000 | |||
1336 | +++ src/qml/Ubuntu/MediaScanner/SongsModel.cc 2014-05-29 09:17:39 +0000 | |||
1337 | @@ -24,9 +24,6 @@ | |||
1338 | 24 | SongsModel::SongsModel(QObject *parent) | 24 | SongsModel::SongsModel(QObject *parent) |
1339 | 25 | : MediaFileModelBase(parent), | 25 | : MediaFileModelBase(parent), |
1340 | 26 | store(nullptr), | 26 | store(nullptr), |
1341 | 27 | artist(""), | ||
1342 | 28 | album(""), | ||
1343 | 29 | album_artist(""), | ||
1344 | 30 | limit(-1) { | 27 | limit(-1) { |
1345 | 31 | } | 28 | } |
1346 | 32 | 29 | ||
1347 | @@ -41,36 +38,87 @@ | |||
1348 | 41 | } | 38 | } |
1349 | 42 | } | 39 | } |
1350 | 43 | 40 | ||
1381 | 44 | QString SongsModel::getArtist() { | 41 | QVariant SongsModel::getArtist() { |
1382 | 45 | return artist; | 42 | if (!filter.hasArtist()) |
1383 | 46 | } | 43 | return QVariant(); |
1384 | 47 | 44 | return QString::fromStdString(filter.getArtist()); | |
1385 | 48 | void SongsModel::setArtist(const QString artist) { | 45 | } |
1386 | 49 | if (this->artist != artist) { | 46 | |
1387 | 50 | this->artist = artist; | 47 | void SongsModel::setArtist(const QVariant artist) { |
1388 | 51 | update(); | 48 | if (artist.isNull()) { |
1389 | 52 | } | 49 | if (filter.hasArtist()) { |
1390 | 53 | } | 50 | filter.unsetArtist(); |
1391 | 54 | 51 | update(); | |
1392 | 55 | QString SongsModel::getAlbum() { | 52 | } |
1393 | 56 | return album; | 53 | } else { |
1394 | 57 | } | 54 | const std::string std_artist = artist.value<QString>().toStdString(); |
1395 | 58 | 55 | if (!filter.hasArtist() || filter.getArtist() != std_artist) { | |
1396 | 59 | void SongsModel::setAlbum(const QString album) { | 56 | filter.setArtist(std_artist); |
1397 | 60 | if (this->album != album) { | 57 | update(); |
1398 | 61 | this->album = album; | 58 | } |
1399 | 62 | update(); | 59 | } |
1400 | 63 | } | 60 | } |
1401 | 64 | } | 61 | |
1402 | 65 | 62 | QVariant SongsModel::getAlbum() { | |
1403 | 66 | QString SongsModel::getAlbumArtist() { | 63 | if (!filter.hasAlbum()) |
1404 | 67 | return album_artist; | 64 | return QVariant(); |
1405 | 68 | } | 65 | return QString::fromStdString(filter.getAlbum()); |
1406 | 69 | 66 | } | |
1407 | 70 | void SongsModel::setAlbumArtist(const QString album_artist) { | 67 | |
1408 | 71 | if (this->album_artist != album_artist) { | 68 | void SongsModel::setAlbum(const QVariant album) { |
1409 | 72 | this->album_artist = album_artist; | 69 | if (album.isNull()) { |
1410 | 73 | update(); | 70 | if (filter.hasAlbum()) { |
1411 | 71 | filter.unsetAlbum(); | ||
1412 | 72 | update(); | ||
1413 | 73 | } | ||
1414 | 74 | } else { | ||
1415 | 75 | const std::string std_album = album.value<QString>().toStdString(); | ||
1416 | 76 | if (!filter.hasAlbum() || filter.getAlbum() != std_album) { | ||
1417 | 77 | filter.setAlbum(std_album); | ||
1418 | 78 | update(); | ||
1419 | 79 | } | ||
1420 | 80 | } | ||
1421 | 81 | } | ||
1422 | 82 | |||
1423 | 83 | QVariant SongsModel::getAlbumArtist() { | ||
1424 | 84 | if (!filter.hasAlbumArtist()) | ||
1425 | 85 | return QVariant(); | ||
1426 | 86 | return QString::fromStdString(filter.getAlbumArtist()); | ||
1427 | 87 | } | ||
1428 | 88 | |||
1429 | 89 | void SongsModel::setAlbumArtist(const QVariant album_artist) { | ||
1430 | 90 | if (album_artist.isNull()) { | ||
1431 | 91 | if (filter.hasAlbumArtist()) { | ||
1432 | 92 | filter.unsetAlbumArtist(); | ||
1433 | 93 | update(); | ||
1434 | 94 | } | ||
1435 | 95 | } else { | ||
1436 | 96 | const std::string std_album_artist = album_artist.value<QString>().toStdString(); | ||
1437 | 97 | if (!filter.hasAlbumArtist() || filter.getAlbumArtist() != std_album_artist) { | ||
1438 | 98 | filter.setAlbumArtist(std_album_artist); | ||
1439 | 99 | update(); | ||
1440 | 100 | } | ||
1441 | 101 | } | ||
1442 | 102 | } | ||
1443 | 103 | |||
1444 | 104 | QVariant SongsModel::getGenre() { | ||
1445 | 105 | if (!filter.hasGenre()) | ||
1446 | 106 | return QVariant(); | ||
1447 | 107 | return QString::fromStdString(filter.getGenre()); | ||
1448 | 108 | } | ||
1449 | 109 | |||
1450 | 110 | void SongsModel::setGenre(const QVariant genre) { | ||
1451 | 111 | if (genre.isNull()) { | ||
1452 | 112 | if (filter.hasGenre()) { | ||
1453 | 113 | filter.unsetGenre(); | ||
1454 | 114 | update(); | ||
1455 | 115 | } | ||
1456 | 116 | } else { | ||
1457 | 117 | const std::string std_genre = genre.value<QString>().toStdString(); | ||
1458 | 118 | if (!filter.hasGenre() || filter.getGenre() != std_genre) { | ||
1459 | 119 | filter.setGenre(std_genre); | ||
1460 | 120 | update(); | ||
1461 | 121 | } | ||
1462 | 74 | } | 122 | } |
1463 | 75 | } | 123 | } |
1464 | 76 | 124 | ||
1465 | @@ -89,6 +137,6 @@ | |||
1466 | 89 | if (store == nullptr) { | 137 | if (store == nullptr) { |
1467 | 90 | updateResults(std::vector<mediascanner::MediaFile>()); | 138 | updateResults(std::vector<mediascanner::MediaFile>()); |
1468 | 91 | } else { | 139 | } else { |
1470 | 92 | updateResults(store->store.listSongs(artist.toStdString(), album.toStdString(), album_artist.toStdString(), limit)); | 140 | updateResults(store->store.listSongs(filter, limit)); |
1471 | 93 | } | 141 | } |
1472 | 94 | } | 142 | } |
1473 | 95 | 143 | ||
1474 | === modified file 'src/qml/Ubuntu/MediaScanner/SongsModel.hh' | |||
1475 | --- src/qml/Ubuntu/MediaScanner/SongsModel.hh 2014-02-27 05:37:36 +0000 | |||
1476 | +++ src/qml/Ubuntu/MediaScanner/SongsModel.hh 2014-05-29 09:17:39 +0000 | |||
1477 | @@ -22,6 +22,7 @@ | |||
1478 | 22 | 22 | ||
1479 | 23 | #include <QString> | 23 | #include <QString> |
1480 | 24 | 24 | ||
1481 | 25 | #include <mediascanner/Filter.hh> | ||
1482 | 25 | #include "MediaStoreWrapper.hh" | 26 | #include "MediaStoreWrapper.hh" |
1483 | 26 | #include "MediaFileModelBase.hh" | 27 | #include "MediaFileModelBase.hh" |
1484 | 27 | 28 | ||
1485 | @@ -31,9 +32,10 @@ | |||
1486 | 31 | class SongsModel : public MediaFileModelBase { | 32 | class SongsModel : public MediaFileModelBase { |
1487 | 32 | Q_OBJECT | 33 | Q_OBJECT |
1488 | 33 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) | 34 | Q_PROPERTY(mediascanner::qml::MediaStoreWrapper* store READ getStore WRITE setStore) |
1492 | 34 | Q_PROPERTY(QString artist READ getArtist WRITE setArtist) | 35 | Q_PROPERTY(QVariant artist READ getArtist WRITE setArtist) |
1493 | 35 | Q_PROPERTY(QString album READ getAlbum WRITE setAlbum) | 36 | Q_PROPERTY(QVariant album READ getAlbum WRITE setAlbum) |
1494 | 36 | Q_PROPERTY(QString albumArtist READ getAlbumArtist WRITE setAlbumArtist) | 37 | Q_PROPERTY(QVariant albumArtist READ getAlbumArtist WRITE setAlbumArtist) |
1495 | 38 | Q_PROPERTY(QVariant genre READ getGenre WRITE setGenre) | ||
1496 | 37 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) | 39 | Q_PROPERTY(int limit READ getLimit WRITE setLimit) |
1497 | 38 | public: | 40 | public: |
1498 | 39 | explicit SongsModel(QObject *parent=0); | 41 | explicit SongsModel(QObject *parent=0); |
1499 | @@ -41,19 +43,21 @@ | |||
1500 | 41 | MediaStoreWrapper *getStore(); | 43 | MediaStoreWrapper *getStore(); |
1501 | 42 | void setStore(MediaStoreWrapper *store); | 44 | void setStore(MediaStoreWrapper *store); |
1502 | 43 | 45 | ||
1509 | 44 | QString getArtist(); | 46 | QVariant getArtist(); |
1510 | 45 | void setArtist(const QString artist); | 47 | void setArtist(const QVariant artist); |
1511 | 46 | QString getAlbum(); | 48 | QVariant getAlbum(); |
1512 | 47 | void setAlbum(const QString album); | 49 | void setAlbum(const QVariant album); |
1513 | 48 | QString getAlbumArtist(); | 50 | QVariant getAlbumArtist(); |
1514 | 49 | void setAlbumArtist(const QString album_artist); | 51 | void setAlbumArtist(const QVariant album_artist); |
1515 | 52 | QVariant getGenre(); | ||
1516 | 53 | void setGenre(const QVariant genre); | ||
1517 | 50 | int getLimit(); | 54 | int getLimit(); |
1518 | 51 | void setLimit(int limit); | 55 | void setLimit(int limit); |
1519 | 52 | private: | 56 | private: |
1520 | 53 | void update(); | 57 | void update(); |
1521 | 54 | 58 | ||
1522 | 55 | MediaStoreWrapper *store; | 59 | MediaStoreWrapper *store; |
1524 | 56 | QString artist, album, album_artist; | 60 | Filter filter; |
1525 | 57 | int limit; | 61 | int limit; |
1526 | 58 | }; | 62 | }; |
1527 | 59 | 63 | ||
1528 | 60 | 64 | ||
1529 | === modified file 'src/qml/Ubuntu/MediaScanner/plugin.cc' | |||
1530 | --- src/qml/Ubuntu/MediaScanner/plugin.cc 2014-02-28 07:01:44 +0000 | |||
1531 | +++ src/qml/Ubuntu/MediaScanner/plugin.cc 2014-05-29 09:17:39 +0000 | |||
1532 | @@ -22,6 +22,7 @@ | |||
1533 | 22 | #include "MediaStoreWrapper.hh" | 22 | #include "MediaStoreWrapper.hh" |
1534 | 23 | #include "AlbumsModel.hh" | 23 | #include "AlbumsModel.hh" |
1535 | 24 | #include "ArtistsModel.hh" | 24 | #include "ArtistsModel.hh" |
1536 | 25 | #include "GenresModel.hh" | ||
1537 | 25 | #include "SongsModel.hh" | 26 | #include "SongsModel.hh" |
1538 | 26 | #include "SongsSearchModel.hh" | 27 | #include "SongsSearchModel.hh" |
1539 | 27 | 28 | ||
1540 | @@ -33,6 +34,7 @@ | |||
1541 | 33 | "Use a MediaStore to retrieve MediaFiles"); | 34 | "Use a MediaStore to retrieve MediaFiles"); |
1542 | 34 | qmlRegisterType<AlbumsModel>(uri, 0, 1, "AlbumsModel"); | 35 | qmlRegisterType<AlbumsModel>(uri, 0, 1, "AlbumsModel"); |
1543 | 35 | qmlRegisterType<ArtistsModel>(uri, 0, 1, "ArtistsModel"); | 36 | qmlRegisterType<ArtistsModel>(uri, 0, 1, "ArtistsModel"); |
1544 | 37 | qmlRegisterType<GenresModel>(uri, 0, 1, "GenresModel"); | ||
1545 | 36 | qmlRegisterType<SongsModel>(uri, 0, 1, "SongsModel"); | 38 | qmlRegisterType<SongsModel>(uri, 0, 1, "SongsModel"); |
1546 | 37 | qmlRegisterType<SongsSearchModel>(uri, 0, 1, "SongsSearchModel"); | 39 | qmlRegisterType<SongsSearchModel>(uri, 0, 1, "SongsSearchModel"); |
1547 | 38 | } | 40 | } |
1548 | 39 | 41 | ||
1549 | === modified file 'src/qml/Ubuntu/MediaScanner/plugin.qmltypes' | |||
1550 | --- src/qml/Ubuntu/MediaScanner/plugin.qmltypes 2014-05-08 07:17:11 +0000 | |||
1551 | +++ src/qml/Ubuntu/MediaScanner/plugin.qmltypes 2014-05-29 09:17:39 +0000 | |||
1552 | @@ -32,8 +32,9 @@ | |||
1553 | 32 | exports: ["Ubuntu.MediaScanner/AlbumsModel 0.1"] | 32 | exports: ["Ubuntu.MediaScanner/AlbumsModel 0.1"] |
1554 | 33 | exportMetaObjectRevisions: [0] | 33 | exportMetaObjectRevisions: [0] |
1555 | 34 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } | 34 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } |
1558 | 35 | Property { name: "artist"; type: "string" } | 35 | Property { name: "artist"; type: "QVariant" } |
1559 | 36 | Property { name: "albumArtist"; type: "string" } | 36 | Property { name: "albumArtist"; type: "QVariant" } |
1560 | 37 | Property { name: "genre"; type: "QVariant" } | ||
1561 | 37 | Property { name: "limit"; type: "int" } | 38 | Property { name: "limit"; type: "int" } |
1562 | 38 | } | 39 | } |
1563 | 39 | Component { | 40 | Component { |
1564 | @@ -49,6 +50,28 @@ | |||
1565 | 49 | } | 50 | } |
1566 | 50 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } | 51 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } |
1567 | 51 | Property { name: "albumArtists"; type: "bool" } | 52 | Property { name: "albumArtists"; type: "bool" } |
1568 | 53 | Property { name: "genre"; type: "QVariant" } | ||
1569 | 54 | Property { name: "limit"; type: "int" } | ||
1570 | 55 | Property { name: "rowCount"; type: "int"; isReadonly: true } | ||
1571 | 56 | Method { | ||
1572 | 57 | name: "get" | ||
1573 | 58 | type: "QVariant" | ||
1574 | 59 | Parameter { name: "row"; type: "int" } | ||
1575 | 60 | Parameter { name: "role"; type: "Roles" } | ||
1576 | 61 | } | ||
1577 | 62 | } | ||
1578 | 63 | Component { | ||
1579 | 64 | name: "mediascanner::qml::GenresModel" | ||
1580 | 65 | prototype: "QAbstractListModel" | ||
1581 | 66 | exports: ["Ubuntu.MediaScanner/GenresModel 0.1"] | ||
1582 | 67 | exportMetaObjectRevisions: [0] | ||
1583 | 68 | Enum { | ||
1584 | 69 | name: "Roles" | ||
1585 | 70 | values: { | ||
1586 | 71 | "RoleGenre": 0 | ||
1587 | 72 | } | ||
1588 | 73 | } | ||
1589 | 74 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } | ||
1590 | 52 | Property { name: "limit"; type: "int" } | 75 | Property { name: "limit"; type: "int" } |
1591 | 53 | Property { name: "rowCount"; type: "int"; isReadonly: true } | 76 | Property { name: "rowCount"; type: "int"; isReadonly: true } |
1592 | 54 | Method { | 77 | Method { |
1593 | @@ -140,9 +163,10 @@ | |||
1594 | 140 | exports: ["Ubuntu.MediaScanner/SongsModel 0.1"] | 163 | exports: ["Ubuntu.MediaScanner/SongsModel 0.1"] |
1595 | 141 | exportMetaObjectRevisions: [0] | 164 | exportMetaObjectRevisions: [0] |
1596 | 142 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } | 165 | Property { name: "store"; type: "mediascanner::qml::MediaStoreWrapper"; isPointer: true } |
1600 | 143 | Property { name: "artist"; type: "string" } | 166 | Property { name: "artist"; type: "QVariant" } |
1601 | 144 | Property { name: "album"; type: "string" } | 167 | Property { name: "album"; type: "QVariant" } |
1602 | 145 | Property { name: "albumArtist"; type: "string" } | 168 | Property { name: "albumArtist"; type: "QVariant" } |
1603 | 169 | Property { name: "genre"; type: "QVariant" } | ||
1604 | 146 | Property { name: "limit"; type: "int" } | 170 | Property { name: "limit"; type: "int" } |
1605 | 147 | } | 171 | } |
1606 | 148 | Component { | 172 | Component { |
1607 | 149 | 173 | ||
1608 | === modified file 'src/qml/Ubuntu/MediaScanner/qmldir' | |||
1609 | --- src/qml/Ubuntu/MediaScanner/qmldir 2014-01-02 07:48:47 +0000 | |||
1610 | +++ src/qml/Ubuntu/MediaScanner/qmldir 2014-05-29 09:17:39 +0000 | |||
1611 | @@ -1,2 +1,3 @@ | |||
1612 | 1 | module Ubuntu.MediaScanner | 1 | module Ubuntu.MediaScanner |
1613 | 2 | plugin mediascanner-qml | 2 | plugin mediascanner-qml |
1614 | 3 | typeinfo plugin.qmltypes | ||
1615 | 3 | 4 | ||
1616 | === added file 'test/qml/tst_albumsmodel.qml' | |||
1617 | --- test/qml/tst_albumsmodel.qml 1970-01-01 00:00:00 +0000 | |||
1618 | +++ test/qml/tst_albumsmodel.qml 2014-05-29 09:17:39 +0000 | |||
1619 | @@ -0,0 +1,91 @@ | |||
1620 | 1 | import QtQuick 2.0 | ||
1621 | 2 | import QtTest 1.0 | ||
1622 | 3 | import Ubuntu.MediaScanner 0.1 | ||
1623 | 4 | |||
1624 | 5 | Item { | ||
1625 | 6 | id: root | ||
1626 | 7 | |||
1627 | 8 | MediaStore { | ||
1628 | 9 | id: store | ||
1629 | 10 | } | ||
1630 | 11 | |||
1631 | 12 | AlbumsModel { | ||
1632 | 13 | id: model | ||
1633 | 14 | store: store | ||
1634 | 15 | } | ||
1635 | 16 | |||
1636 | 17 | TestCase { | ||
1637 | 18 | name: "AlbumsModelTests" | ||
1638 | 19 | |||
1639 | 20 | function cleanup() { | ||
1640 | 21 | model.artist = undefined; | ||
1641 | 22 | model.albumArtist = undefined; | ||
1642 | 23 | model.genre = undefined; | ||
1643 | 24 | model.limit = -1; | ||
1644 | 25 | } | ||
1645 | 26 | |||
1646 | 27 | function test_initial_state() { | ||
1647 | 28 | compare(model.artist, undefined); | ||
1648 | 29 | compare(model.albumArtist, undefined); | ||
1649 | 30 | compare(model.genre, undefined); | ||
1650 | 31 | compare(model.limit, -1); | ||
1651 | 32 | |||
1652 | 33 | compare(model.rowCount, 4); | ||
1653 | 34 | compare(model.get(0, AlbumsModel.RoleTitle), "Ivy and the Big Apples"); | ||
1654 | 35 | compare(model.get(0, AlbumsModel.RoleArtist), "Spiderbait"); | ||
1655 | 36 | |||
1656 | 37 | compare(model.get(1, AlbumsModel.RoleTitle), "Spiderbait"); | ||
1657 | 38 | compare(model.get(1, AlbumsModel.RoleArtist), "Spiderbait"); | ||
1658 | 39 | |||
1659 | 40 | compare(model.get(2, AlbumsModel.RoleTitle), "April Uprising"); | ||
1660 | 41 | compare(model.get(2, AlbumsModel.RoleArtist), "The John Butler Trio"); | ||
1661 | 42 | |||
1662 | 43 | compare(model.get(3, AlbumsModel.RoleTitle), "Sunrise Over Sea"); | ||
1663 | 44 | compare(model.get(3, AlbumsModel.RoleArtist), "The John Butler Trio"); | ||
1664 | 45 | } | ||
1665 | 46 | |||
1666 | 47 | function test_limit() { | ||
1667 | 48 | model.limit = 2; | ||
1668 | 49 | compare(model.rowCount, 2); | ||
1669 | 50 | |||
1670 | 51 | model.limit = 42; | ||
1671 | 52 | compare(model.rowCount, 4); | ||
1672 | 53 | |||
1673 | 54 | model.limit = -1; | ||
1674 | 55 | compare(model.rowCount, 4); | ||
1675 | 56 | } | ||
1676 | 57 | |||
1677 | 58 | function test_artist() { | ||
1678 | 59 | model.artist = "The John Butler Trio"; | ||
1679 | 60 | compare(model.rowCount, 2); | ||
1680 | 61 | |||
1681 | 62 | compare(model.get(0, AlbumsModel.RoleTitle), "April Uprising"); | ||
1682 | 63 | compare(model.get(0, AlbumsModel.RoleArtist), "The John Butler Trio"); | ||
1683 | 64 | |||
1684 | 65 | model.artist = "unknown"; | ||
1685 | 66 | compare(model.rowCount, 0); | ||
1686 | 67 | } | ||
1687 | 68 | |||
1688 | 69 | function test_album_artist() { | ||
1689 | 70 | model.albumArtist = "The John Butler Trio"; | ||
1690 | 71 | compare(model.rowCount, 2); | ||
1691 | 72 | |||
1692 | 73 | compare(model.get(0, AlbumsModel.RoleTitle), "April Uprising"); | ||
1693 | 74 | compare(model.get(0, AlbumsModel.RoleArtist), "The John Butler Trio"); | ||
1694 | 75 | |||
1695 | 76 | model.albumArtist = "unknown"; | ||
1696 | 77 | compare(model.rowCount, 0); | ||
1697 | 78 | } | ||
1698 | 79 | |||
1699 | 80 | function test_genre() { | ||
1700 | 81 | model.genre = "rock"; | ||
1701 | 82 | compare(model.rowCount, 2); | ||
1702 | 83 | compare(model.get(0, AlbumsModel.RoleTitle), "Ivy and the Big Apples"); | ||
1703 | 84 | compare(model.get(1, AlbumsModel.RoleTitle), "Spiderbait"); | ||
1704 | 85 | |||
1705 | 86 | model.genre = "unknown"; | ||
1706 | 87 | compare(model.rowCount, 0); | ||
1707 | 88 | } | ||
1708 | 89 | |||
1709 | 90 | } | ||
1710 | 91 | } | ||
1711 | 0 | 92 | ||
1712 | === added file 'test/qml/tst_artistsmodel.qml' | |||
1713 | --- test/qml/tst_artistsmodel.qml 1970-01-01 00:00:00 +0000 | |||
1714 | +++ test/qml/tst_artistsmodel.qml 2014-05-29 09:17:39 +0000 | |||
1715 | @@ -0,0 +1,68 @@ | |||
1716 | 1 | import QtQuick 2.0 | ||
1717 | 2 | import QtTest 1.0 | ||
1718 | 3 | import Ubuntu.MediaScanner 0.1 | ||
1719 | 4 | |||
1720 | 5 | Item { | ||
1721 | 6 | id: root | ||
1722 | 7 | |||
1723 | 8 | MediaStore { | ||
1724 | 9 | id: store | ||
1725 | 10 | } | ||
1726 | 11 | |||
1727 | 12 | ArtistsModel { | ||
1728 | 13 | id: model | ||
1729 | 14 | store: store | ||
1730 | 15 | } | ||
1731 | 16 | |||
1732 | 17 | TestCase { | ||
1733 | 18 | name: "ArtistsModelTests" | ||
1734 | 19 | |||
1735 | 20 | function cleanup() { | ||
1736 | 21 | model.albumArtists = false; | ||
1737 | 22 | model.genre = undefined; | ||
1738 | 23 | model.limit = -1; | ||
1739 | 24 | } | ||
1740 | 25 | |||
1741 | 26 | function test_initial_state() { | ||
1742 | 27 | compare(model.albumArtists, false); | ||
1743 | 28 | compare(model.limit, -1); | ||
1744 | 29 | |||
1745 | 30 | compare(model.rowCount, 2); | ||
1746 | 31 | compare(model.get(0, ArtistsModel.RoleArtist), "Spiderbait"); | ||
1747 | 32 | compare(model.get(1, ArtistsModel.RoleArtist), "The John Butler Trio"); | ||
1748 | 33 | } | ||
1749 | 34 | |||
1750 | 35 | function test_limit() { | ||
1751 | 36 | model.limit = 1; | ||
1752 | 37 | compare(model.rowCount, 1); | ||
1753 | 38 | |||
1754 | 39 | model.limit = 42; | ||
1755 | 40 | compare(model.rowCount, 2); | ||
1756 | 41 | |||
1757 | 42 | model.limit = -1; | ||
1758 | 43 | compare(model.rowCount, 2); | ||
1759 | 44 | } | ||
1760 | 45 | |||
1761 | 46 | function test_album_artists() { | ||
1762 | 47 | model.albumArtists = true; | ||
1763 | 48 | compare(model.rowCount, 2); | ||
1764 | 49 | |||
1765 | 50 | compare(model.get(0, ArtistsModel.RoleArtist), "Spiderbait"); | ||
1766 | 51 | compare(model.get(1, ArtistsModel.RoleArtist), "The John Butler Trio"); | ||
1767 | 52 | } | ||
1768 | 53 | |||
1769 | 54 | function test_genre() { | ||
1770 | 55 | model.genre = "rock"; | ||
1771 | 56 | compare(model.rowCount, 1); | ||
1772 | 57 | compare(model.get(0, ArtistsModel.RoleArtist), "Spiderbait"); | ||
1773 | 58 | |||
1774 | 59 | model.genre = "roots"; | ||
1775 | 60 | compare(model.rowCount, 1); | ||
1776 | 61 | compare(model.get(0, ArtistsModel.RoleArtist), "The John Butler Trio"); | ||
1777 | 62 | |||
1778 | 63 | model.genre = "unknown"; | ||
1779 | 64 | compare(model.rowCount, 0); | ||
1780 | 65 | } | ||
1781 | 66 | |||
1782 | 67 | } | ||
1783 | 68 | } | ||
1784 | 0 | 69 | ||
1785 | === added file 'test/qml/tst_genresmodel.qml' | |||
1786 | --- test/qml/tst_genresmodel.qml 1970-01-01 00:00:00 +0000 | |||
1787 | +++ test/qml/tst_genresmodel.qml 2014-05-29 09:17:39 +0000 | |||
1788 | @@ -0,0 +1,44 @@ | |||
1789 | 1 | import QtQuick 2.0 | ||
1790 | 2 | import QtTest 1.0 | ||
1791 | 3 | import Ubuntu.MediaScanner 0.1 | ||
1792 | 4 | |||
1793 | 5 | Item { | ||
1794 | 6 | id: root | ||
1795 | 7 | |||
1796 | 8 | MediaStore { | ||
1797 | 9 | id: store | ||
1798 | 10 | } | ||
1799 | 11 | |||
1800 | 12 | GenresModel { | ||
1801 | 13 | id: model | ||
1802 | 14 | store: store | ||
1803 | 15 | } | ||
1804 | 16 | |||
1805 | 17 | TestCase { | ||
1806 | 18 | name: "GenresModelTests" | ||
1807 | 19 | |||
1808 | 20 | function cleanup() { | ||
1809 | 21 | model.limit = -1; | ||
1810 | 22 | } | ||
1811 | 23 | |||
1812 | 24 | function test_initial_state() { | ||
1813 | 25 | compare(model.limit, -1); | ||
1814 | 26 | |||
1815 | 27 | compare(model.rowCount, 2); | ||
1816 | 28 | compare(model.get(0, ArtistsModel.RoleGenre), "rock"); | ||
1817 | 29 | compare(model.get(1, ArtistsModel.RoleGenre), "roots"); | ||
1818 | 30 | } | ||
1819 | 31 | |||
1820 | 32 | function test_limit() { | ||
1821 | 33 | model.limit = 1; | ||
1822 | 34 | compare(model.rowCount, 1); | ||
1823 | 35 | |||
1824 | 36 | model.limit = 42; | ||
1825 | 37 | compare(model.rowCount, 2); | ||
1826 | 38 | |||
1827 | 39 | model.limit = -1; | ||
1828 | 40 | compare(model.rowCount, 2); | ||
1829 | 41 | } | ||
1830 | 42 | |||
1831 | 43 | } | ||
1832 | 44 | } | ||
1833 | 0 | 45 | ||
1834 | === added file 'test/qml/tst_songsmodel.qml' | |||
1835 | --- test/qml/tst_songsmodel.qml 1970-01-01 00:00:00 +0000 | |||
1836 | +++ test/qml/tst_songsmodel.qml 2014-05-29 09:17:39 +0000 | |||
1837 | @@ -0,0 +1,104 @@ | |||
1838 | 1 | import QtQuick 2.0 | ||
1839 | 2 | import QtTest 1.0 | ||
1840 | 3 | import Ubuntu.MediaScanner 0.1 | ||
1841 | 4 | |||
1842 | 5 | Item { | ||
1843 | 6 | id: root | ||
1844 | 7 | |||
1845 | 8 | MediaStore { | ||
1846 | 9 | id: store | ||
1847 | 10 | } | ||
1848 | 11 | |||
1849 | 12 | SongsModel { | ||
1850 | 13 | id: model | ||
1851 | 14 | store: store | ||
1852 | 15 | } | ||
1853 | 16 | |||
1854 | 17 | TestCase { | ||
1855 | 18 | name: "SongsModelTests" | ||
1856 | 19 | |||
1857 | 20 | function cleanup() { | ||
1858 | 21 | model.artist = undefined; | ||
1859 | 22 | model.albumArtist = undefined; | ||
1860 | 23 | model.album = undefined; | ||
1861 | 24 | model.genre = undefined; | ||
1862 | 25 | model.limit = -1; | ||
1863 | 26 | } | ||
1864 | 27 | |||
1865 | 28 | function test_initial_state() { | ||
1866 | 29 | compare(model.artist, undefined); | ||
1867 | 30 | compare(model.albumArtist, undefined); | ||
1868 | 31 | compare(model.album, undefined); | ||
1869 | 32 | compare(model.limit, -1); | ||
1870 | 33 | |||
1871 | 34 | compare(model.rowCount, 7); | ||
1872 | 35 | compare(model.get(0, SongsModel.RoleTitle), "Buy Me a Pony") | ||
1873 | 36 | compare(model.get(0, SongsModel.RoleAlbum), "Ivy and the Big Apples"); | ||
1874 | 37 | compare(model.get(0, SongsModel.RoleAuthor), "Spiderbait"); | ||
1875 | 38 | |||
1876 | 39 | compare(model.get(1, SongsModel.RoleTitle), "Straight Through The Sun"); | ||
1877 | 40 | compare(model.get(2, SongsModel.RoleTitle), "It's Beautiful"); | ||
1878 | 41 | compare(model.get(3, SongsModel.RoleTitle), "Revolution"); | ||
1879 | 42 | compare(model.get(4, SongsModel.RoleTitle), "One Way Road"); | ||
1880 | 43 | compare(model.get(5, SongsModel.RoleTitle), "Peaches & Cream"); | ||
1881 | 44 | compare(model.get(6, SongsModel.RoleTitle), "Zebra"); | ||
1882 | 45 | } | ||
1883 | 46 | |||
1884 | 47 | function test_limit() { | ||
1885 | 48 | model.limit = 2; | ||
1886 | 49 | compare(model.rowCount, 2); | ||
1887 | 50 | |||
1888 | 51 | model.limit = 42; | ||
1889 | 52 | compare(model.rowCount, 7); | ||
1890 | 53 | |||
1891 | 54 | model.limit = -1; | ||
1892 | 55 | compare(model.rowCount, 7); | ||
1893 | 56 | } | ||
1894 | 57 | |||
1895 | 58 | function test_artist() { | ||
1896 | 59 | model.artist = "The John Butler Trio"; | ||
1897 | 60 | compare(model.rowCount, 4); | ||
1898 | 61 | |||
1899 | 62 | compare(model.get(0, SongsModel.RoleTitle), "Revolution"); | ||
1900 | 63 | compare(model.get(0, SongsModel.RoleAuthor), "The John Butler Trio"); | ||
1901 | 64 | |||
1902 | 65 | model.artist = "unknown"; | ||
1903 | 66 | compare(model.rowCount, 0); | ||
1904 | 67 | } | ||
1905 | 68 | |||
1906 | 69 | function test_album_artist() { | ||
1907 | 70 | model.albumArtist = "The John Butler Trio"; | ||
1908 | 71 | compare(model.rowCount, 4); | ||
1909 | 72 | |||
1910 | 73 | compare(model.get(0, SongsModel.RoleTitle), "Revolution"); | ||
1911 | 74 | compare(model.get(0, SongsModel.RoleAuthor), "The John Butler Trio"); | ||
1912 | 75 | |||
1913 | 76 | model.albumArtist = "unknown"; | ||
1914 | 77 | compare(model.rowCount, 0); | ||
1915 | 78 | } | ||
1916 | 79 | |||
1917 | 80 | function test_album() { | ||
1918 | 81 | model.album = "Sunrise Over Sea"; | ||
1919 | 82 | compare(model.rowCount, 2); | ||
1920 | 83 | |||
1921 | 84 | compare(model.get(0, SongsModel.RoleTitle), "Peaches & Cream"); | ||
1922 | 85 | compare(model.get(0, SongsModel.RoleAuthor), "The John Butler Trio"); | ||
1923 | 86 | |||
1924 | 87 | model.albumArtist = "unknown"; | ||
1925 | 88 | compare(model.rowCount, 0); | ||
1926 | 89 | } | ||
1927 | 90 | |||
1928 | 91 | function test_genre() { | ||
1929 | 92 | model.genre = "rock"; | ||
1930 | 93 | compare(model.rowCount, 3); | ||
1931 | 94 | |||
1932 | 95 | compare(model.get(0, SongsModel.RoleTitle), "Buy Me a Pony"); | ||
1933 | 96 | compare(model.get(1, SongsModel.RoleTitle), "Straight Through The Sun"); | ||
1934 | 97 | compare(model.get(2, SongsModel.RoleTitle), "It's Beautiful"); | ||
1935 | 98 | |||
1936 | 99 | model.albumArtist = "unknown"; | ||
1937 | 100 | compare(model.rowCount, 0); | ||
1938 | 101 | } | ||
1939 | 102 | |||
1940 | 103 | } | ||
1941 | 104 | } | ||
1942 | 0 | 105 | ||
1943 | === modified file 'test/test_dbus.cc' | |||
1944 | --- test/test_dbus.cc 2014-05-29 09:17:39 +0000 | |||
1945 | +++ test/test_dbus.cc 2014-05-29 09:17:39 +0000 | |||
1946 | @@ -6,18 +6,24 @@ | |||
1947 | 6 | #include <mediascanner/Album.hh> | 6 | #include <mediascanner/Album.hh> |
1948 | 7 | #include <mediascanner/MediaFile.hh> | 7 | #include <mediascanner/MediaFile.hh> |
1949 | 8 | #include <mediascanner/MediaFileBuilder.hh> | 8 | #include <mediascanner/MediaFileBuilder.hh> |
1950 | 9 | #include <mediascanner/Filter.hh> | ||
1951 | 9 | #include <ms-dbus/dbus-codec.hh> | 10 | #include <ms-dbus/dbus-codec.hh> |
1952 | 10 | 11 | ||
1953 | 11 | class MediaStoreDBusTests : public ::testing::Test { | 12 | class MediaStoreDBusTests : public ::testing::Test { |
1954 | 13 | protected: | ||
1955 | 14 | virtual void SetUp() override { | ||
1956 | 15 | ::testing::Test::SetUp(); | ||
1957 | 16 | message = core::dbus::Message::make_method_call( | ||
1958 | 17 | "org.example.Name", | ||
1959 | 18 | core::dbus::types::ObjectPath("/org/example/Path"), | ||
1960 | 19 | "org.example.Interface", | ||
1961 | 20 | "Method"); | ||
1962 | 21 | } | ||
1963 | 22 | |||
1964 | 23 | core::dbus::Message::Ptr message; | ||
1965 | 12 | }; | 24 | }; |
1966 | 13 | 25 | ||
1967 | 14 | TEST_F(MediaStoreDBusTests, mediafile_codec) { | 26 | TEST_F(MediaStoreDBusTests, mediafile_codec) { |
1968 | 15 | auto message = core::dbus::Message::make_method_call( | ||
1969 | 16 | "org.example.Name", | ||
1970 | 17 | core::dbus::types::ObjectPath("/org/example/Path"), | ||
1971 | 18 | "org.example.Interface", | ||
1972 | 19 | "Method"); | ||
1973 | 20 | |||
1974 | 21 | mediascanner::MediaFile media = mediascanner::MediaFileBuilder("a") | 27 | mediascanner::MediaFile media = mediascanner::MediaFileBuilder("a") |
1975 | 22 | .setContentType("type") | 28 | .setContentType("type") |
1976 | 23 | .setETag("etag") | 29 | .setETag("etag") |
1977 | @@ -42,12 +48,6 @@ | |||
1978 | 42 | } | 48 | } |
1979 | 43 | 49 | ||
1980 | 44 | TEST_F(MediaStoreDBusTests, album_codec) { | 50 | TEST_F(MediaStoreDBusTests, album_codec) { |
1981 | 45 | auto message = core::dbus::Message::make_method_call( | ||
1982 | 46 | "org.example.Name", | ||
1983 | 47 | core::dbus::types::ObjectPath("/org/example/Path"), | ||
1984 | 48 | "org.example.Interface", | ||
1985 | 49 | "Method"); | ||
1986 | 50 | |||
1987 | 51 | mediascanner::Album album("title", "artist"); | 51 | mediascanner::Album album("title", "artist"); |
1988 | 52 | message->writer() << album; | 52 | message->writer() << album; |
1989 | 53 | 53 | ||
1990 | @@ -61,6 +61,33 @@ | |||
1991 | 61 | EXPECT_EQ(album, album2); | 61 | EXPECT_EQ(album, album2); |
1992 | 62 | } | 62 | } |
1993 | 63 | 63 | ||
1994 | 64 | TEST_F(MediaStoreDBusTests, filter_codec) { | ||
1995 | 65 | mediascanner::Filter filter; | ||
1996 | 66 | filter.setArtist("Artist1"); | ||
1997 | 67 | filter.setAlbum("Album1"); | ||
1998 | 68 | filter.setAlbumArtist("AlbumArtist1"); | ||
1999 | 69 | filter.setGenre("Genre"); | ||
2000 | 70 | message->writer() << filter; | ||
2001 | 71 | |||
2002 | 72 | EXPECT_EQ("a{ss}", message->signature()); | ||
2003 | 73 | EXPECT_EQ(core::dbus::helper::TypeMapper<mediascanner::Filter>::signature(), message->signature()); | ||
2004 | 74 | |||
2005 | 75 | mediascanner::Filter other; | ||
2006 | 76 | message->reader() >> other; | ||
2007 | 77 | EXPECT_EQ(filter, other); | ||
2008 | 78 | } | ||
2009 | 79 | |||
2010 | 80 | TEST_F(MediaStoreDBusTests, filter_codec_empty) { | ||
2011 | 81 | mediascanner::Filter empty; | ||
2012 | 82 | message->writer() << empty; | ||
2013 | 83 | |||
2014 | 84 | EXPECT_EQ("a{ss}", message->signature()); | ||
2015 | 85 | |||
2016 | 86 | mediascanner::Filter other; | ||
2017 | 87 | message->reader() >> other; | ||
2018 | 88 | EXPECT_EQ(empty, other); | ||
2019 | 89 | } | ||
2020 | 90 | |||
2021 | 64 | int main(int argc, char **argv) { | 91 | int main(int argc, char **argv) { |
2022 | 65 | ::testing::InitGoogleTest(&argc, argv); | 92 | ::testing::InitGoogleTest(&argc, argv); |
2023 | 66 | return RUN_ALL_TESTS(); | 93 | return RUN_ALL_TESTS(); |
2024 | 67 | 94 | ||
2025 | === modified file 'test/test_mediastore.cc' | |||
2026 | --- test/test_mediastore.cc 2014-05-29 09:17:39 +0000 | |||
2027 | +++ test/test_mediastore.cc 2014-05-29 09:17:39 +0000 | |||
2028 | @@ -20,6 +20,7 @@ | |||
2029 | 20 | #include <mediascanner/MediaFile.hh> | 20 | #include <mediascanner/MediaFile.hh> |
2030 | 21 | #include <mediascanner/MediaFileBuilder.hh> | 21 | #include <mediascanner/MediaFileBuilder.hh> |
2031 | 22 | #include <mediascanner/Album.hh> | 22 | #include <mediascanner/Album.hh> |
2032 | 23 | #include <mediascanner/Filter.hh> | ||
2033 | 23 | #include <mediascanner/MediaStore.hh> | 24 | #include <mediascanner/MediaStore.hh> |
2034 | 24 | #include <mediascanner/internal/utils.hh> | 25 | #include <mediascanner/internal/utils.hh> |
2035 | 25 | 26 | ||
2036 | @@ -617,34 +618,56 @@ | |||
2037 | 617 | store.insert(audio5); | 618 | store.insert(audio5); |
2038 | 618 | store.insert(audio6); | 619 | store.insert(audio6); |
2039 | 619 | 620 | ||
2041 | 620 | vector<MediaFile> tracks = store.listSongs(); | 621 | Filter filter; |
2042 | 622 | vector<MediaFile> tracks = store.listSongs(filter); | ||
2043 | 621 | ASSERT_EQ(6, tracks.size()); | 623 | ASSERT_EQ(6, tracks.size()); |
2044 | 622 | EXPECT_EQ("TitleOne", tracks[0].getTitle()); | 624 | EXPECT_EQ("TitleOne", tracks[0].getTitle()); |
2045 | 623 | 625 | ||
2046 | 624 | // Apply a limit | 626 | // Apply a limit |
2048 | 625 | tracks = store.listSongs("", "", "", 4); | 627 | tracks = store.listSongs(filter, 4); |
2049 | 626 | EXPECT_EQ(4, tracks.size()); | 628 | EXPECT_EQ(4, tracks.size()); |
2050 | 627 | 629 | ||
2051 | 628 | // List songs by artist | 630 | // List songs by artist |
2053 | 629 | tracks = store.listSongs("ArtistOne"); | 631 | filter.setArtist("ArtistOne"); |
2054 | 632 | tracks = store.listSongs(filter); | ||
2055 | 630 | EXPECT_EQ(4, tracks.size()); | 633 | EXPECT_EQ(4, tracks.size()); |
2056 | 631 | 634 | ||
2057 | 632 | // List songs by album | 635 | // List songs by album |
2059 | 633 | tracks = store.listSongs("", "AlbumOne"); | 636 | filter.clear(); |
2060 | 637 | filter.setAlbum("AlbumOne"); | ||
2061 | 638 | tracks = store.listSongs(filter); | ||
2062 | 634 | EXPECT_EQ(2, tracks.size()); | 639 | EXPECT_EQ(2, tracks.size()); |
2063 | 635 | 640 | ||
2064 | 636 | // List songs by album artist | 641 | // List songs by album artist |
2066 | 637 | tracks = store.listSongs("", "", "Various Artists"); | 642 | filter.clear(); |
2067 | 643 | filter.setAlbumArtist("Various Artists"); | ||
2068 | 644 | tracks = store.listSongs(filter); | ||
2069 | 638 | EXPECT_EQ(2, tracks.size()); | 645 | EXPECT_EQ(2, tracks.size()); |
2070 | 639 | 646 | ||
2071 | 640 | // Combinations | 647 | // Combinations |
2079 | 641 | tracks = store.listSongs("ArtistOne", "AlbumOne", ""); | 648 | filter.clear(); |
2080 | 642 | EXPECT_EQ(2, tracks.size()); | 649 | filter.setArtist("ArtistOne"); |
2081 | 643 | tracks = store.listSongs("", "AlbumOne", "ArtistOne"); | 650 | filter.setAlbum("AlbumOne"); |
2082 | 644 | EXPECT_EQ(2, tracks.size()); | 651 | tracks = store.listSongs(filter); |
2083 | 645 | tracks = store.listSongs("ArtistOne", "AlbumOne", "ArtistOne"); | 652 | EXPECT_EQ(2, tracks.size()); |
2084 | 646 | EXPECT_EQ(2, tracks.size()); | 653 | |
2085 | 647 | tracks = store.listSongs("ArtistOne", "", "ArtistOne"); | 654 | filter.clear(); |
2086 | 655 | filter.setAlbum("AlbumOne"); | ||
2087 | 656 | filter.setAlbumArtist("ArtistOne"); | ||
2088 | 657 | tracks = store.listSongs(filter); | ||
2089 | 658 | EXPECT_EQ(2, tracks.size()); | ||
2090 | 659 | |||
2091 | 660 | filter.clear(); | ||
2092 | 661 | filter.setArtist("ArtistOne"); | ||
2093 | 662 | filter.setAlbum("AlbumOne"); | ||
2094 | 663 | filter.setAlbumArtist("ArtistOne"); | ||
2095 | 664 | tracks = store.listSongs(filter); | ||
2096 | 665 | EXPECT_EQ(2, tracks.size()); | ||
2097 | 666 | |||
2098 | 667 | filter.clear(); | ||
2099 | 668 | filter.setArtist("ArtistOne"); | ||
2100 | 669 | filter.setAlbumArtist("ArtistOne"); | ||
2101 | 670 | tracks = store.listSongs(filter); | ||
2102 | 648 | EXPECT_EQ(3, tracks.size()); | 671 | EXPECT_EQ(3, tracks.size()); |
2103 | 649 | } | 672 | } |
2104 | 650 | 673 | ||
2105 | @@ -687,24 +710,31 @@ | |||
2106 | 687 | store.insert(audio4); | 710 | store.insert(audio4); |
2107 | 688 | store.insert(audio5); | 711 | store.insert(audio5); |
2108 | 689 | 712 | ||
2110 | 690 | vector<Album> albums = store.listAlbums(); | 713 | Filter filter; |
2111 | 714 | vector<Album> albums = store.listAlbums(filter); | ||
2112 | 691 | ASSERT_EQ(4, albums.size()); | 715 | ASSERT_EQ(4, albums.size()); |
2113 | 692 | EXPECT_EQ("AlbumOne", albums[0].getTitle()); | 716 | EXPECT_EQ("AlbumOne", albums[0].getTitle()); |
2114 | 693 | 717 | ||
2115 | 694 | // test limit | 718 | // test limit |
2117 | 695 | albums = store.listAlbums("", "", 2); | 719 | albums = store.listAlbums(filter, 2); |
2118 | 696 | EXPECT_EQ(2, albums.size()); | 720 | EXPECT_EQ(2, albums.size()); |
2119 | 697 | 721 | ||
2120 | 698 | // Songs by artist | 722 | // Songs by artist |
2122 | 699 | albums = store.listAlbums("ArtistOne"); | 723 | filter.setArtist("ArtistOne"); |
2123 | 724 | albums = store.listAlbums(filter); | ||
2124 | 700 | EXPECT_EQ(3, albums.size()); | 725 | EXPECT_EQ(3, albums.size()); |
2125 | 701 | 726 | ||
2126 | 702 | // Songs by album artist | 727 | // Songs by album artist |
2128 | 703 | albums = store.listAlbums("", "ArtistOne"); | 728 | filter.clear(); |
2129 | 729 | filter.setAlbumArtist("ArtistOne"); | ||
2130 | 730 | albums = store.listAlbums(filter); | ||
2131 | 704 | EXPECT_EQ(2, albums.size()); | 731 | EXPECT_EQ(2, albums.size()); |
2132 | 705 | 732 | ||
2133 | 706 | // Combination | 733 | // Combination |
2135 | 707 | albums = store.listAlbums("ArtistOne", "Various Artists"); | 734 | filter.clear(); |
2136 | 735 | filter.setArtist("ArtistOne"); | ||
2137 | 736 | filter.setAlbumArtist("Various Artists"); | ||
2138 | 737 | albums = store.listAlbums(filter); | ||
2139 | 708 | EXPECT_EQ(1, albums.size()); | 738 | EXPECT_EQ(1, albums.size()); |
2140 | 709 | } | 739 | } |
2141 | 710 | 740 | ||
2142 | @@ -747,17 +777,18 @@ | |||
2143 | 747 | store.insert(audio4); | 777 | store.insert(audio4); |
2144 | 748 | store.insert(audio5); | 778 | store.insert(audio5); |
2145 | 749 | 779 | ||
2147 | 750 | vector<string> artists = store.listArtists(false); | 780 | Filter filter; |
2148 | 781 | vector<string> artists = store.listArtists(filter); | ||
2149 | 751 | ASSERT_EQ(2, artists.size()); | 782 | ASSERT_EQ(2, artists.size()); |
2150 | 752 | EXPECT_EQ("ArtistOne", artists[0]); | 783 | EXPECT_EQ("ArtistOne", artists[0]); |
2151 | 753 | EXPECT_EQ("ArtistTwo", artists[1]); | 784 | EXPECT_EQ("ArtistTwo", artists[1]); |
2152 | 754 | 785 | ||
2153 | 755 | // Test limit clause | 786 | // Test limit clause |
2155 | 756 | artists = store.listArtists(false, 1); | 787 | artists = store.listArtists(filter, 1); |
2156 | 757 | EXPECT_EQ(1, artists.size()); | 788 | EXPECT_EQ(1, artists.size()); |
2157 | 758 | 789 | ||
2158 | 759 | // List "album artists" | 790 | // List "album artists" |
2160 | 760 | artists = store.listArtists(true); | 791 | artists = store.listAlbumArtists(filter); |
2161 | 761 | ASSERT_EQ(3, artists.size()); | 792 | ASSERT_EQ(3, artists.size()); |
2162 | 762 | EXPECT_EQ("ArtistOne", artists[0]); | 793 | EXPECT_EQ("ArtistOne", artists[0]); |
2163 | 763 | EXPECT_EQ("ArtistTwo", artists[1]); | 794 | EXPECT_EQ("ArtistTwo", artists[1]); |
PASSED: Continuous integration, rev:267 jenkins. qa.ubuntu. com/job/ mediascanner2- ci/81/ jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- amd64-ci/ 22 jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- armhf-ci/ 22 jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- armhf-ci/ 22/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- i386-ci/ 22
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/mediascanne r2-ci/81/ rebuild
http://