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
|
/*
* 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.3
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Popups 1.0
import Ubuntu.MediaScanner 0.1
import Ubuntu.Thumbnailer 0.1
import QtQuick.LocalStorage 2.0
import "../meta-database.js" as Library
import "../playlists.js" as Playlists
import "ListItemActions"
MusicPage {
id: songStackPage
objectName: "songsPage"
visible: false
property string line1: ""
property string line2: ""
property string songtitle: ""
property var covers: []
property bool isAlbum: false
property string file: ""
property string year: ""
property alias album: songsModel.album
property alias genre: songsModel.genre
state: songStackPage.line1 === i18n.tr("Playlist") ? "playlist" : "album"
states: [
PageHeadState {
id: albumState
name: "album"
PropertyChanges {
target: songStackPage.head
backAction: albumState.backAction
actions: albumState.actions
}
},
PageHeadState {
id: playlistState
name: "playlist"
actions: [
Action {
objectName: "editPlaylist"
iconName: "edit"
onTriggered: {
var dialog = PopupUtils.open(editPlaylistDialog, mainView)
dialog.oldPlaylistName = line2
}
},
Action {
objectName: "deletePlaylist"
iconName: "delete"
onTriggered: {
var dialog = PopupUtils.open(removePlaylistDialog, mainView)
dialog.oldPlaylistName = line2
}
}
]
PropertyChanges {
target: songStackPage.head
backAction: playlistState.backAction
actions: playlistState.actions
}
}
]
SongsModel {
id: songsModel
store: musicStore
}
ListView {
id: albumtrackslist
anchors {
fill: parent
}
delegate: albumTracksDelegate
model: isAlbum ? songsModel : albumTracksModel.model
objectName: "songspage-listview"
width: parent.width
header: BlurredHeader {
rightColumn: Column {
spacing: units.gu(2)
Button {
id: shuffleRow
height: units.gu(4)
strokeColor: UbuntuColors.green
width: units.gu(15)
Text {
anchors {
centerIn: parent
}
color: "white"
text: i18n.tr("Shuffle")
}
MouseArea {
anchors.fill: parent
onClicked: {
shuffleModel(albumtrackslist.model) // play track
if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
Library.addRecent(songStackPage.line2, songStackPage.line1, songStackPage.covers[0], songStackPage.line2, "album")
mainView.hasRecent = true
recentModel.filterRecent()
} else if (songStackPage.line1 === i18n.tr("Playlist")) {
Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
mainView.hasRecent = true
recentModel.filterRecent()
}
}
}
}
Button {
id: queueAllRow
height: units.gu(4)
strokeColor: UbuntuColors.green
width: units.gu(15)
Text {
anchors {
centerIn: parent
}
color: "white"
text: i18n.tr("Queue all")
}
MouseArea {
anchors.fill: parent
onClicked: addQueueFromModel(albumtrackslist.model)
}
}
Button {
id: playRow
color: UbuntuColors.green
height: units.gu(4)
text: i18n.tr("Play all")
width: units.gu(15)
MouseArea {
anchors.fill: parent
onClicked: {
trackClicked(albumtrackslist.model, 0) // play track
if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
Library.addRecent(songStackPage.line2, songStackPage.line1, songStackPage.covers[0], songStackPage.line2, "album")
mainView.hasRecent = true
recentModel.filterRecent()
} else if (songStackPage.line1 === i18n.tr("Playlist")) {
Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
mainView.hasRecent = true
recentModel.filterRecent()
}
}
}
}
}
coverSources: songStackPage.covers
height: songStackPage.line1 !== i18n.tr("Playlist") &&
songStackPage.line1 !== i18n.tr("Genre") ?
units.gu(33) : units.gu(30)
bottomColumn: Column {
Label {
id: albumLabel
anchors {
left: parent.left
right: parent.right
}
color: styleMusic.common.music
elide: Text.ElideRight
fontSize: "x-large"
maximumLineCount: 1
text: line2
wrapMode: Text.NoWrap
}
Item {
height: units.gu(0.75)
width: parent.width
visible: albumArtist.visible
}
Label {
id: albumArtist
anchors {
left: parent.left
right: parent.right
}
color: styleMusic.common.subtitle
elide: Text.ElideRight
fontSize: "small"
maximumLineCount: 1
objectName: "songsPageHeaderAlbumArtist"
text: line1
visible: text !== i18n.tr("Playlist") &&
text !== i18n.tr("Genre")
wrapMode: Text.NoWrap
}
Item {
height: units.gu(1)
width: parent.width
}
Label {
id: albumYear
anchors {
left: parent.left
right: parent.right
}
color: styleMusic.common.subtitle
elide: Text.ElideRight
fontSize: "small"
maximumLineCount: 1
text: isAlbum && line1 !== i18n.tr("Genre") ? year + " | " + i18n.tr("%1 song", "%1 songs", albumtrackslist.count).arg(albumtrackslist.count)
: i18n.tr("%1 song", "%1 songs", albumtrackslist.count).arg(albumtrackslist.count)
wrapMode: Text.NoWrap
}
}
}
Component {
id: albumTracksDelegate
ListItemWithActions {
id: track
color: "transparent"
objectName: "songsPageListItem" + index
iconFrame: false
progression: false
showDivider: false
height: units.gu(6)
leftSideAction: songStackPage.line1 === i18n.tr("Playlist")
? playlistRemoveAction.item : null
reorderable: songStackPage.line1 === i18n.tr("Playlist")
rightSideActions: [
AddToQueue {
},
AddToPlaylist {
}
]
triggerActionOnMouseRelease: true
onItemClicked: {
trackClicked(albumtrackslist.model, index) // play track
if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
Library.addRecent(songStackPage.line2, songStackPage.line1, model.art, songStackPage.line2, "album")
mainView.hasRecent = true
recentModel.filterRecent()
} else if (songStackPage.line1 === i18n.tr("Playlist")) {
Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
mainView.hasRecent = true
recentModel.filterRecent()
}
}
onReorder: {
console.debug("Move: ", from, to);
Playlists.move(songStackPage.line2, from, to)
albumTracksModel.filterPlaylistTracks(songStackPage.line2)
}
Loader {
id: playlistRemoveAction
sourceComponent: Remove {
onTriggered: {
Playlists.removeFromPlaylist(songStackPage.line2, model.i)
albumTracksModel.filterPlaylistTracks(songStackPage.line2)
playlistModel.filterPlaylists()
}
}
}
// TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
onPressedChanged: musicRow.pressed = pressed
MusicRow {
id: musicRow
covers: []
showCovers: false
column: Column {
Label {
id: trackTitle
color: styleMusic.common.music
fontSize: "small"
objectName: "songspage-tracktitle"
text: model.title
}
Label {
id: trackArtist
color: styleMusic.common.subtitle
fontSize: "x-small"
text: model.author
}
}
}
Component.onCompleted: {
if (model.date !== undefined)
{
songStackPage.file = model.filename;
songStackPage.year = new Date(model.date).toLocaleString(Qt.locale(),'yyyy');
}
}
}
}
}
// Edit name of playlist dialog
Component {
id: editPlaylistDialog
Dialog {
id: dialogEditPlaylist
// TRANSLATORS: this is a title of a dialog with a prompt to rename a playlist
title: i18n.tr("Change name")
text: i18n.tr("Enter the new name of the playlist.")
property alias oldPlaylistName: playlistName.placeholderText
TextField {
id: playlistName
inputMethodHints: Qt.ImhNoPredictiveText
onPlaceholderTextChanged: text = placeholderText
}
Label {
id: editplaylistoutput
color: "red"
visible: false
}
Button {
text: i18n.tr("Change")
color: styleMusic.dialog.confirmButtonColor
onClicked: {
editplaylistoutput.visible = true
if (playlistName.text.length > 0) { // make sure something is acually inputed
console.debug("Debug: User changed name from "+playlistName.placeholderText+" to "+playlistName.text)
if (Playlists.renamePlaylist(playlistName.placeholderText, playlistName.text) === true) {
playlistModel.filterPlaylists()
PopupUtils.close(dialogEditPlaylist)
line2 = playlistName.text
}
else {
editplaylistoutput.text = i18n.tr("Playlist already exists")
}
}
else {
editplaylistoutput.text = i18n.tr("Please type in a name.")
}
}
}
Button {
text: i18n.tr("Cancel")
color: styleMusic.dialog.cancelButtonColor
onClicked: PopupUtils.close(dialogEditPlaylist)
}
}
}
// Remove playlist dialog
Component {
id: removePlaylistDialog
Dialog {
id: dialogRemovePlaylist
// TRANSLATORS: this is a title of a dialog with a prompt to delete a playlist
title: i18n.tr("Are you sure?")
text: i18n.tr("This will delete your playlist.")
property string oldPlaylistName
Button {
text: i18n.tr("Remove")
color: styleMusic.dialog.confirmButtonColor
onClicked: {
// removing playlist
Playlists.removePlaylist(dialogRemovePlaylist.oldPlaylistName)
playlistModel.filterPlaylists();
PopupUtils.close(dialogRemovePlaylist)
musicToolbar.goBack()
}
}
Button {
text: i18n.tr("Cancel")
color: styleMusic.dialog.cancelButtonColor
onClicked: PopupUtils.close(dialogRemovePlaylist)
}
}
}
}
|