~vthompson/music-app/remix-songs-page

91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
1
/*
91.2.2 by Victor Thompson
Update copyright to include Andrew.
2
 * Copyright (C) 2013 Andrew Hayzen <ahayzen@gmail.com>
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
3
 *                    Daniel Holm <d.holmen@gmail.com>
91.2.2 by Victor Thompson
Update copyright to include Andrew.
4
 *                    Victor Thompson <victor.thompson@gmail.com>
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; version 3.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
import QtQuick 2.0
20
import Ubuntu.Components 0.1
21
import Ubuntu.Components.ListItems 0.1
22
import Ubuntu.Components.Popups 0.1
23
import Ubuntu.Components.ListItems 0.1 as ListItem
24
import QtMultimedia 5.0
25
import QtQuick.LocalStorage 2.0
26
import "settings.js" as Settings
27
import "meta-database.js" as Library
28
import "playlists.js" as Playlists
29
30
Page {
31
    id: mainpage
32
    title: i18n.tr("Music")
33
133.1.1 by Andrew Hayzen
* Custom toolbar created
34
    onVisibleChanged: {
35
        if (visible === true)
36
        {
37
            musicToolbar.setPage(mainpage);
38
        }
39
    }
40
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
41
    ListItem.Standard {
42
        id: recentlyPlayed
184.3.1 by Victor Thompson
Adjust Recent and Genres item sizes and rename Recent list
43
        text: i18n.tr("Recent")
220.1.3 by Victor Thompson
Show recent list as empty instead of hiding it when it is empty
44
    }
220.1.4 by Victor Thompson
Add a button to clear history.
45
    Item {
220.1.3 by Victor Thompson
Show recent list as empty instead of hiding it when it is empty
46
        id: recentlistempty
47
        anchors.top: recentlyPlayed.bottom
48
        anchors.topMargin: units.gu(1)
49
        height: units.gu(22)
220.1.4 by Victor Thompson
Add a button to clear history.
50
        width: parent.width
220.1.3 by Victor Thompson
Show recent list as empty instead of hiding it when it is empty
51
        visible: !mainView.hasRecent
52
53
        Label {
54
            horizontalAlignment: Text.AlignHCenter
55
            verticalAlignment: Text.AlignVCenter
56
            color: styleMusic.nowPlaying.labelSecondaryColor
220.1.4 by Victor Thompson
Add a button to clear history.
57
            anchors.centerIn: parent
220.1.3 by Victor Thompson
Show recent list as empty instead of hiding it when it is empty
58
            elide: Text.ElideRight
59
            fontSize: "large"
60
            text: i18n.tr("No recent albums or playlists")
61
        }
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
62
    }
63
64
    ListView {
65
        id: recentlist
66
        width: parent.width
67
        anchors.top: recentlyPlayed.bottom
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
68
        anchors.topMargin: units.gu(1)
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
69
        spacing: units.gu(2)
184.3.1 by Victor Thompson
Adjust Recent and Genres item sizes and rename Recent list
70
        height: units.gu(22)
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
71
        // TODO: Update when view counts are collected
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
72
        model: recentModel.model
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
73
        delegate: recentDelegate
136.1.1 by Victor Thompson
Add a busy indicator while app is loading.
74
        header: Item {
127.2.1 by Victor Thompson
Resolve spacing issues
75
            id: spacer
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
76
            width: units.gu(1)
127.2.1 by Victor Thompson
Resolve spacing issues
77
        }
220.1.4 by Victor Thompson
Add a button to clear history.
78
        footer: Item {
79
            id: clearRecent
80
            width: units.gu(20)
81
            height: units.gu(20)
220.1.5 by Victor Thompson
Fix button visibility
82
            visible: mainView.hasRecent && !loading.visible
220.1.4 by Victor Thompson
Add a button to clear history.
83
            Button {
84
                id: clearRecentButton
85
                anchors.centerIn: parent
86
                text: "Clear History"
87
                onClicked: {
88
                    Library.clearRecentHistory()
89
                    mainView.hasRecent = false
90
                    recentModel.filterRecent()
91
                }
92
            }
93
        }
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
94
        orientation: ListView.Horizontal
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
95
        visible: mainView.hasRecent
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
96
97
        Component {
98
            id: recentDelegate
99
            Item {
100
                id: recentItem
184.3.1 by Victor Thompson
Adjust Recent and Genres item sizes and rename Recent list
101
                height: units.gu(20)
102
                width: units.gu(20)
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
103
                UbuntuShape {
104
                    id: recentShape
105
                    height: recentItem.width
106
                    width: recentItem.width
107
                    image: Image {
108
                        id: icon
109
                        fillMode: Image.Stretch
110
                        property string title: model.title
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
111
                        property string title2: model.title2
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
112
                        property string cover: model.cover
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
113
                        property string type: model.type
114
                        property string time: model.time
115
                        property string key: model.key
100.3.1 by Victor Thompson
Use Grilo to build the existing Metadata library.
116
                        source: cover !== "" ? cover : "images/cover_default.png"
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
117
                    }
118
                }
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
119
                Rectangle {  // Background so can see text in current state
127.3.1 by Victor Thompson
Show labels on recent items
120
                    id: albumBg
121
                    anchors.bottom: parent.bottom
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
122
                    anchors.bottomMargin: units.gu(2)
127.3.1 by Victor Thompson
Show labels on recent items
123
                    color: styleMusic.common.black
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
124
                    height: units.gu(4)
127.3.1 by Victor Thompson
Show labels on recent items
125
                    width: parent.width
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
126
                    Label {
127
                        id: albumArtist
128
                        anchors.top: albumBg.top
129
                        anchors.topMargin: units.gu(1)
130
                        anchors.left: parent.left
131
                        anchors.leftMargin: units.gu(1)
132
                        anchors.right: parent.right
133
                        anchors.rightMargin: units.gu(1)
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
134
                        color: styleMusic.common.white
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
135
                        elide: Text.ElideRight
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
136
                        text: title
137
                        fontSize: "small"
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
138
                    }
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
139
                }
140
                UbuntuShape {  // Background so can see text in current state
141
                    id: albumBg2
142
                    anchors.bottom: parent.bottom
143
                    color: styleMusic.common.black
144
                    height: units.gu(3)
145
                    width: parent.width
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
146
                    Label {
147
                        id: albumLabel
148
                        anchors.left: parent.left
149
                        anchors.leftMargin: units.gu(1)
150
                        anchors.bottom: parent.bottom
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
151
                        anchors.bottomMargin: units.gu(1)
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
152
                        anchors.right: parent.right
153
                        anchors.rightMargin: units.gu(1)
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
154
                        color: styleMusic.nowPlaying.labelSecondaryColor
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
155
                        elide: Text.ElideRight
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
156
                        text: title2
157
                        fontSize: "x-small"
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
158
                    }
127.3.1 by Victor Thompson
Show labels on recent items
159
                }
91.2.3 by Victor Thompson
Add recent album to queue, play first item, and go staight to Now Playing.
160
                MouseArea {
161
                    anchors.fill: parent
162
                    onClicked: {
220.1.2 by Victor Thompson
Intitial Recent list for playlists and albums
163
                        if (type === "album") {
164
                            recentAlbumTracksModel.filterAlbumTracks(key)
165
                            trackQueue.model.clear()
166
                            addQueueFromModel(recentAlbumTracksModel)
167
                            currentModel = recentAlbumTracksModel
168
                            currentQuery = recentAlbumTracksModel.query
169
                            currentParam = recentAlbumTracksModel.param
170
                        } else if (type === "playlist") {
171
                            recentPlaylistTracksModel.filterPlaylistTracks(key)
172
                            trackQueue.model.clear()
173
                            addQueueFromModel(recentPlaylistTracksModel)
174
                            currentModel = recentPlaylistTracksModel
175
                            currentQuery = recentPlaylistTracksModel.query
176
                            currentParam = recentPlaylistTracksModel.param
177
                        }
178
                        Library.addRecent(title, title2, cover, key, type)
179
                        mainView.hasRecent = true
180
                        recentModel.filterRecent()
91.2.3 by Victor Thompson
Add recent album to queue, play first item, and go staight to Now Playing.
181
                        var file = trackQueue.model.get(0).file
182
                        currentIndex = trackQueue.indexOf(file)
183
                        queueChanged = true
184
                        player.stop()
185
                        player.source = Qt.resolvedUrl(file)
186
                        player.play()
187
                        nowPlaying.visible = true
175.1.2 by Andrew Hayzen
* Fix for selecting Recently Played or Genre
188
                        musicToolbar.showToolbar()
91.2.3 by Victor Thompson
Add recent album to queue, play first item, and go staight to Now Playing.
189
                    }
190
                }
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
191
            }
192
        }
193
    }
194
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
195
    ListItem.ThinDivider {
196
        id: divider
220.1.3 by Victor Thompson
Show recent list as empty instead of hiding it when it is empty
197
        anchors.top: recentlist.visible ? recentlist.bottom : recentlistempty.bottom
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
198
    }
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
199
    ListItem.Standard {
200
        id: genres
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
201
        anchors.top: divider.bottom
202
        text: i18n.tr("Genres")
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
203
    }
204
    // TODO: add music genres. frequency of play? most tracks?
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
205
    ListView {
206
        id: genrelist
207
        width: parent.width
208
        anchors.top: genres.bottom
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
209
        anchors.topMargin: units.gu(1)
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
210
        spacing: units.gu(2)
184.3.1 by Victor Thompson
Adjust Recent and Genres item sizes and rename Recent list
211
        height: units.gu(22)
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
212
        model: genreModel.model
213
        delegate: genreDelegate
136.1.1 by Victor Thompson
Add a busy indicator while app is loading.
214
        header: Item {
127.2.1 by Victor Thompson
Resolve spacing issues
215
            id: spacer
159.2.10 by Daniel Holm
Bigger album on start tab and changes to labels; default art in playlist.
216
            width: units.gu(1)
127.2.1 by Victor Thompson
Resolve spacing issues
217
        }
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
218
        orientation: ListView.Horizontal
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
219
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
220
        Component {
221
            id: genreDelegate
222
            Item {
223
                id: genreItem
229.2.6 by Victor Thompson
resolve AP test failures
224
                objectName: "genreItemObject"
184.3.2 by Victor Thompson
Fix Genres
225
                height: units.gu(20)
226
                width: units.gu(20)
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
227
                UbuntuShape {
228
                    id: genreShape
229
                    height: genreItem.width
230
                    width: genreItem.width
231
                    image: Image {
232
                        id: icon
233
                        fillMode: Image.Stretch
234
                        property string artist: model.artist
235
                        property string album: model.album
236
                        property string title: model.title
237
                        property string cover: model.cover
238
                        property string length: model.length
239
                        property string file: model.file
240
                        property string year: model.year
241
                        property string genre: model.genre
242
                        source: cover !== "" ? cover : "images/cover_default.png"
243
                    }
244
                }
245
                MouseArea {
246
                    anchors.fill: parent
247
                    onClicked: {
248
                        genreTracksModel.filterGenreTracks(genre)
249
                        trackQueue.model.clear()
250
                        addQueueFromModel(genreTracksModel)
251
                        currentModel = genreTracksModel
252
                        currentQuery = genreTracksModel.query
253
                        currentParam = genreTracksModel.param
254
                        var file = trackQueue.model.get(0).file
255
                        currentIndex = trackQueue.indexOf(file)
256
                        queueChanged = true
257
                        player.stop()
258
                        player.source = Qt.resolvedUrl(file)
259
                        player.play()
260
                        nowPlaying.visible = true
175.1.2 by Andrew Hayzen
* Fix for selecting Recently Played or Genre
261
                        musicToolbar.showToolbar();
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
262
                    }
263
                }
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
264
                Rectangle {  // Background so can see text in current state
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
265
                    id: genreBg
266
                    anchors.bottom: parent.bottom
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
267
                    anchors.bottomMargin: units.gu(2)
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
268
                    color: styleMusic.common.black
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
269
                    height: units.gu(4)
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
270
                    width: parent.width
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
271
                    Label {
272
                        id: genreTotal
273
                        anchors.top: genreBg.top
274
                        anchors.topMargin: units.gu(1)
275
                        anchors.left: parent.left
276
                        anchors.leftMargin: units.gu(1)
277
                        anchors.right: parent.right
278
                        anchors.rightMargin: units.gu(1)
279
                        color: styleMusic.nowPlaying.labelSecondaryColor
280
                        elide: Text.ElideRight
127.7.15 by David Planella
Some i18n improvements on plurals
281
			text: i18n.tr("%1 song", "%1 songs", model.total).arg(model.total)
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
282
                        fontSize: "x-small"
283
                    }
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
284
                }
285
                UbuntuShape {  // Background so can see text in current state
286
                    id: genreBg2
287
                    anchors.bottom: parent.bottom
288
                    color: styleMusic.common.black
289
                    height: units.gu(3)
290
                    width: parent.width
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
291
                    Label {
292
                        id: genreLabel
293
                        anchors.bottom: parent.bottom
217.1.1 by Victor Thompson
Make transparent labels on cover art solid and overlap.
294
                        anchors.bottomMargin: units.gu(1)
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
295
                        anchors.left: parent.left
296
                        anchors.leftMargin: units.gu(1)
297
                        anchors.right: parent.right
298
                        anchors.rightMargin: units.gu(1)
195.2.1 by David Planella
Updated font colors in the Music view to match visual design spec
299
                        color: styleMusic.common.white
184.2.1 by Andrew Hayzen
* Fix for labels on the MusicStart.qml not using elide
300
                        elide: Text.ElideRight
301
                        text: genre === "" ? "None" : genre
302
                        fontSize: "small"
303
                    }
100.5.1 by Victor Thompson
Add genres to Library and Music Start page.
304
                }
305
            }
306
        }
307
    }
91.2.1 by Victor Thompson
Initial music tab. Nothing is functional yet.
308
}