1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
/*
* Copyright (C) 2013, 2014
* Andrew Hayzen <ahayzen@gmail.com>
* Daniel Holm <d.holmen@gmail.com>
* Victor Thompson <victor.thompson@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components 1.1 as Toolkit
import Ubuntu.Components.ListItems 0.1
import Ubuntu.Components.Popups 0.1
import Ubuntu.Components.ListItems 0.1 as ListItem
import Ubuntu.MediaScanner 0.1
import Ubuntu.Thumbnailer 0.1
import QtMultimedia 5.0
import QtQuick.LocalStorage 2.0
import "settings.js" as Settings
import "meta-database.js" as Library
import "playlists.js" as Playlists
import "common"
MusicPage {
id: mainpage
title: i18n.tr("Music")
/* Dev button for search.
Button {
id: searchButton
text: i18n.tr("Search")
anchors.top: parent.top
anchors.topMargin: units.gu(2)
anchors.bottom: recentlyPlayed.top
anchors.bottomMargin: units.gu(1)
height: units.gu(4)
onClicked: {
PopupUtils.open(Qt.resolvedUrl("MusicSearch.qml"), mainView,
{
title: i18n.tr("Search")
} )
}
}
*/
Flickable{
id: musicFlickable
anchors.fill: parent
width: mainpage.width
height: mainpage.height
contentHeight: mainView.hasRecent ? recentlyPlayed.height + recentlist.height + genres.height + genrelist.height + albums.height + albumlist.height + units.gu(4)
: genres.height + genrelist.height + albums.height + albumlist.height + units.gu(3)
contentWidth: width
focus: true
ListItem.Standard {
id: recentlyPlayed
Label {
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: units.gu(2)
}
text: i18n.tr("Recent")
color: styleMusic.common.music
}
visible: mainView.hasRecent
}
ListView {
id: recentlist
anchors.top: recentlyPlayed.bottom
anchors.topMargin: units.gu(1)
width: parent.width
spacing: units.gu(1)
height: units.gu(18)
// TODO: Update when view counts are collected
model: recentModel.model
delegate: recentDelegate
header: Item {
id: recentSpacer
width: units.gu(1)
}
footer: Item {
id: clearRecent
width: recentlist.height - units.gu(2)
height: width
visible: mainView.hasRecent && !loading.visible
Button {
id: clearRecentButton
anchors.centerIn: parent
text: i18n.tr("Clear History")
onClicked: {
Library.clearRecentHistory()
mainView.hasRecent = false
recentModel.filterRecent()
}
}
}
orientation: ListView.Horizontal
visible: mainView.hasRecent
Component {
id: recentDelegate
Item {
property string title: model.title
property string title2: model.title2 !== "Playlist" ? model.title2 : i18n.tr("Playlist")
property var covers: type === "playlist" ? Playlists.getPlaylistCovers(title) : [{author: model.title2, album: model.title}]
property string type: model.type
property string time: model.time
property string key: model.key
id: recentItem
height: recentlist.height - units.gu(1)
width: height
CoverRow {
id: recentShape
anchors {
top: parent.top
left: parent.left
verticalCenter: parent.verticalCenter
}
count: recentItem.covers.length
size: recentItem.width
covers: recentItem.covers
spacing: units.gu(2)
}
Item { // Background so can see text in current state
id: albumBg
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: units.gu(6)
clip: true
UbuntuShape{
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: recentShape.height
radius: "medium"
color: styleMusic.common.black
opacity: 0.6
}
}
Label {
id: albumArtist
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(3)
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: title
fontSize: "small"
font.weight: Font.DemiBold
}
Label {
id: albumLabel
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: title2
fontSize: "x-small"
}
MouseArea {
anchors.fill: parent
onClicked: {
if (type === "playlist") {
albumTracksModel.filterPlaylistTracks(key)
} else {
songsPage.album = title;
}
songsPage.genre = undefined;
songsPage.line1 = title2
songsPage.line2 = title
songsPage.covers = recentItem.covers
songsPage.isAlbum = (type === "album")
songsPage.title = songsPage.isAlbum ? i18n.tr("Album") : i18n.tr("Playlist")
mainPageStack.push(songsPage)
}
// TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
onPressedChanged: recentShape.pressed = pressed
}
}
}
}
ListItem.ThinDivider {
id: genreDivider
anchors.top: mainView.hasRecent ? recentlist.bottom : parent.top
}
ListItem.Standard {
id: genres
anchors.top: genreDivider.bottom
Label {
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: units.gu(2)
}
text: i18n.tr("Genres")
color: styleMusic.common.music
}
}
// TODO: add music genres. frequency of play? most tracks?
ListView {
id: genrelist
width: parent.width
anchors.top: genres.bottom
anchors.topMargin: units.gu(1)
spacing: units.gu(1)
height: units.gu(18)
model: GenresModel {
store: musicStore
}
delegate: genreDelegate
header: Item {
id: genreSpacer
width: units.gu(1)
}
orientation: ListView.Horizontal
Component {
id: genreDelegate
Item {
id: genreItem
objectName: "genreItemObject"
height: genrelist.height - units.gu(1)
width: height
Repeater {
id: albumGenreModelRepeater
model: AlbumsModel {
genre: model.genre
store: musicStore
}
delegate: Item {
property string author: model.artist
property string album: model.title
}
property var covers: []
signal finished()
onFinished: {
genreShape.count = count
genreShape.covers = covers
}
onItemAdded: {
covers.push({author: item.author, album: item.album});
if (index === count - 1) {
finished();
}
}
}
SongsModel {
id: songGenreModel
genre: model.genre
store: musicStore
}
CoverRow {
id: genreShape
anchors {
top: parent.top
left: parent.left
verticalCenter: parent.verticalCenter
}
count: 0
size: genreItem.width
covers: []
spacing: units.gu(2)
}
MouseArea {
anchors.fill: parent
onClicked: {
songsPage.album = undefined
songsPage.covers = genreShape.covers
songsPage.genre = model.genre
songsPage.isAlbum = true
songsPage.line1 = i18n.tr("Genre")
songsPage.line2 = model.genre
songsPage.title = i18n.tr("Genre")
mainPageStack.push(songsPage)
}
// TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
onPressedChanged: genreShape.pressed = pressed
}
Item { // Background so can see text in current state
id: genreBg
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: units.gu(5.5)
clip: true
UbuntuShape{
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: genreShape.height
radius: "medium"
color: styleMusic.common.black
opacity: 0.6
}
}
Label {
id: genreLabel
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: model.genre
fontSize: "small"
font.weight: Font.DemiBold
}
Label {
id: genreTotal
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(3)
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: i18n.tr("%1 song", "%1 songs", songGenreModel.rowCount).arg(songGenreModel.rowCount)
fontSize: "x-small"
}
}
}
}
ListItem.ThinDivider {
id: albumsDivider
anchors.top: genrelist.bottom
}
ListItem.Standard {
id: albums
Label {
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: units.gu(2)
}
text: i18n.tr("Albums")
color: styleMusic.common.music
}
anchors.top: albumsDivider.bottom
}
ListView {
id: albumlist
width: parent.width
anchors.top: albums.bottom
anchors.topMargin: units.gu(1)
spacing: units.gu(1)
height: units.gu(18)
model: Toolkit.SortFilterModel {
id: albumsModelFilter
property alias rowCount: albumsModel.rowCount
model: AlbumsModel {
id: albumsModel
store: musicStore
}
sort.property: "title"
sort.order: Qt.AscendingOrder
}
delegate: albumDelegate
header: Item {
id: albumSpacer
width: units.gu(1)
}
orientation: ListView.Horizontal
Component {
id: albumDelegate
Item {
property string artist: model.artist
property string album: model.title
property var covers: [{author: model.artist, album: model.title}]
id: albumItem
objectName: "albumItemObject"
height: albumlist.height - units.gu(1)
width: height
CoverRow {
id: albumShape
anchors {
top: parent.top
left: parent.left
verticalCenter: parent.verticalCenter
}
count: albumItem.covers.length
size: albumItem.width
covers: albumItem.covers
spacing: units.gu(2)
}
MouseArea {
anchors.fill: parent
onClicked: {
songsPage.album = album
songsPage.covers = covers
songsPage.genre = undefined
songsPage.isAlbum = true
songsPage.line1 = artist
songsPage.line2 = album
songsPage.title = i18n.tr("Album")
mainPageStack.push(songsPage)
}
// TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
onPressedChanged: albumShape.pressed = pressed
}
Item { // Background so can see text in current state
id: albumBg
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: units.gu(6)
clip: true
UbuntuShape{
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: albumShape.height
radius: "medium"
color: styleMusic.common.black
opacity: 0.6
}
}
Label {
id: albumLabel
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(1)
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: artist
fontSize: "x-small"
}
Label {
id: albumLabel2
anchors.bottom: parent.bottom
anchors.bottomMargin: units.gu(3)
anchors.left: parent.left
anchors.leftMargin: units.gu(1)
anchors.right: parent.right
anchors.rightMargin: units.gu(1)
color: styleMusic.common.white
elide: Text.ElideRight
text: album
fontSize: "small"
font.weight: Font.DemiBold
}
}
}
}
}
}
|