~vthompson/music-app/use-media-keys

133.1.1 by Andrew Hayzen
* Custom toolbar created
1
/*
766.2.12 by Andrew Hayzen
* Add searching to MusicaddtoPlaylist.qml
2
 * Copyright (C) 2013, 2014, 2015
409.3.70 by Victor Thompson
Update copyright
3
 *      Andrew Hayzen <ahayzen@gmail.com>
4
 *      Daniel Holm <d.holmen@gmail.com>
5
 *      Victor Thompson <victor.thompson@gmail.com>
133.1.1 by Andrew Hayzen
* Custom toolbar created
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; version 3.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
628.1.1 by Akiva Avraham
Updated library imports to qtquick-2.3
20
import QtQuick 2.3
133.1.1 by Andrew Hayzen
* Custom toolbar created
21
import QtQuick.LocalStorage 2.0
22
import QtMultimedia 5.0
586.2.1 by Andrew Hayzen
* Bump Ubuntu.Components to 1.1
23
import Ubuntu.Components 1.1
586.2.3 by Andrew Hayzen
* Bump Ubuntu.Components.Popups and Ubuntu.Components.ListItems to 1.0
24
import Ubuntu.Components.Popups 1.0
675.1.3 by Andrew Hayzen
* Remove smooth = true
25
import "common"
133.1.1 by Andrew Hayzen
* Custom toolbar created
26
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
27
Item {
28
    anchors {
29
        bottom: parent.bottom
30
        left: parent.left
31
        right: parent.right
32
    }
133.1.1 by Andrew Hayzen
* Custom toolbar created
33
34
    // Properties storing the current page info
35
    property var currentPage: null
36
    property var currentTab: null
37
38
    // Properties and signals for the toolbar
466.2.1 by Andrew Hayzen
* Migrate the following sheets to page/pagestacks, SongsSheet.qml, AlbumsSheet.qml and MusicaddtoPlaylist.qml
39
    property alias currentHeight: musicToolbarPanel.height
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
40
    property alias opened: musicToolbarPanel.opened
133.1.1 by Andrew Hayzen
* Custom toolbar created
41
785.1.2 by Andrew Hayzen
* Pop songsPage if there are not tracks
42
    property bool popping: false
43
133.1.1 by Andrew Hayzen
* Custom toolbar created
44
    /* Helper functions */
45
287.2.6 by Victor Thompson
Add goBack function back in
46
    // Back button has been pressed, jump up pageStack or back to parent page
47
    function goBack()
48
    {
766.2.3 by Andrew Hayzen
* Tidy comments
49
        if (mainPageStack !== null && mainPageStack.depth > 1) {
466.2.12 by Andrew Hayzen
* Abstract Page to MusicPage to make bottom edge implementation easier
50
            mainPageStack.pop(currentPage)
287.2.6 by Victor Thompson
Add goBack function back in
51
        }
133.1.1 by Andrew Hayzen
* Custom toolbar created
52
    }
53
785.1.2 by Andrew Hayzen
* Pop songsPage if there are not tracks
54
    // Pop a specific page in the stack
55
    function popPage(page)
56
    {
57
        var tmpPages = []
58
59
        popping = true
60
785.1.4 by Andrew Hayzen
* Remove recent entries
61
        while (mainPageStack.currentPage !== page && mainPageStack.depth > 0) {
785.1.2 by Andrew Hayzen
* Pop songsPage if there are not tracks
62
            tmpPages.push(mainPageStack.currentPage)
63
            mainPageStack.pop()
64
        }
65
785.1.4 by Andrew Hayzen
* Remove recent entries
66
        if (mainPageStack.depth > 0) {
67
            mainPageStack.pop()
68
        }
785.1.2 by Andrew Hayzen
* Pop songsPage if there are not tracks
69
70
        for (var i=tmpPages.length - 1; i > -1; i--) {
71
            mainPageStack.push(tmpPages[i])
72
        }
73
74
        popping = false
75
    }
76
133.1.1 by Andrew Hayzen
* Custom toolbar created
77
    // Set the current page, and any parent/stacks
466.2.12 by Andrew Hayzen
* Abstract Page to MusicPage to make bottom edge implementation easier
78
    function setPage(childPage)
133.1.1 by Andrew Hayzen
* Custom toolbar created
79
    {
785.1.2 by Andrew Hayzen
* Pop songsPage if there are not tracks
80
        if (!popping) {
81
            currentPage = childPage;
82
        }
133.1.1 by Andrew Hayzen
* Custom toolbar created
83
    }
84
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
85
    Panel {
86
        id: musicToolbarPanel
87
        anchors {
88
            left: parent.left
89
            right: parent.right
90
            bottom: parent.bottom
91
        }
651.1.1 by Andrew Hayzen
* Remove legacy toolbar code
92
        height: units.gu(7.25)
640.4.1 by Andrew Hayzen
* Fix the toolbar so it is always shown
93
        locked: true
94
        opened: true
384.2.3 by Andrew Hayzen
* Add temporary workaround for Panel
95
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
96
        /* Expanded toolbar */
687.1.1 by Andrew Hayzen
* Remove rectangles
97
        Item {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
98
            id: musicToolbarExpandedContainer
99
            anchors {
100
                fill: parent
133.1.1 by Andrew Hayzen
* Custom toolbar created
101
            }
102
103
            Rectangle {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
104
                id: musicToolbarPlayerControls
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
105
                anchors {
106
                    fill: parent
107
                }
108
                color: "#000"
301.1.8 by Andrew Hayzen
* Fixes for trackQueue empty
109
                state: trackQueue.model.count === 0 ? "disabled" : "enabled"
133.1.1 by Andrew Hayzen
* Custom toolbar created
110
                states: [
111
                    State {
112
                        name: "disabled"
113
                        PropertyChanges {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
114
                            target: disabledPlayerControlsGroup
115
                            visible: true
116
                        }
117
                        PropertyChanges {
118
                            target: enabledPlayerControlsGroup
133.1.1 by Andrew Hayzen
* Custom toolbar created
119
                            visible: false
120
                        }
121
                    },
122
                    State {
123
                        name: "enabled"
124
                        PropertyChanges {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
125
                            target: disabledPlayerControlsGroup
126
                            visible: false
127
                        }
128
                        PropertyChanges {
129
                            target: enabledPlayerControlsGroup
133.1.1 by Andrew Hayzen
* Custom toolbar created
130
                            visible: true
131
                        }
132
                    }
133
                ]
134
640.4.1 by Andrew Hayzen
* Fix the toolbar so it is always shown
135
                /* Disabled (empty state) controls */
687.1.1 by Andrew Hayzen
* Remove rectangles
136
                Item {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
137
                    id: disabledPlayerControlsGroup
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
138
                    anchors {
640.4.3 by Andrew Hayzen
* Switch progress bar position
139
                        bottom: playerControlsProgressBar.top
640.4.1 by Andrew Hayzen
* Fix the toolbar so it is always shown
140
                        left: parent.left
141
                        right: parent.right
640.4.3 by Andrew Hayzen
* Switch progress bar position
142
                        top: parent.top
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
143
                    }
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
144
145
                    Label {
146
                        id: noSongsInQueueLabel
574.1.1 by Victor Thompson
Fix empty queue message length
147
                        anchors {
148
                            left: parent.left
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
149
                            leftMargin: units.gu(2)
574.1.1 by Victor Thompson
Fix empty queue message length
150
                            right: disabledPlayerControlsPlayButton.left
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
151
                            rightMargin: units.gu(2)
152
                            verticalCenter: parent.verticalCenter
574.1.1 by Victor Thompson
Fix empty queue message length
153
                        }
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
154
                        color: styleMusic.playerControls.labelColor
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
155
                        text: i18n.tr("Tap to shuffle music")
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
156
                        fontSize: "large"
756.1.1 by Victor Thompson
Do not show 'Tap to shuffle music' page when there is no music.
157
                        visible: !emptyPage.noMusic
574.1.1 by Victor Thompson
Fix empty queue message length
158
                        wrapMode: Text.WordWrap
159
                        maximumLineCount: 2
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
160
                    }
398.1.1 by Andrew Hayzen
* Add ability to play random song when queue is empty
161
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
162
                    /* Play/Pause button */
163
                    Icon {
398.1.1 by Andrew Hayzen
* Add ability to play random song when queue is empty
164
                        id: disabledPlayerControlsPlayButton
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
165
                        anchors {
166
                            right: parent.right
167
                            rightMargin: units.gu(3)
168
                            verticalCenter: parent.verticalCenter
169
                        }
170
                        color: "#FFF"
171
                        height: units.gu(2.5)
172
                        name: player.playbackState === MediaPlayer.PlayingState ?
173
                                  "media-playback-pause" : "media-playback-start"
640.5.6 by Victor Thompson
update
174
                        objectName: "disabledSmallPlayShape"
398.1.1 by Andrew Hayzen
* Add ability to play random song when queue is empty
175
                        width: height
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
176
                    }
398.1.1 by Andrew Hayzen
* Add ability to play random song when queue is empty
177
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
178
                    /* Click to shuffle music */
179
                    MouseArea {
180
                        anchors {
181
                            fill: parent
182
                        }
183
                        onClicked: {
446.2.3 by Andrew Hayzen
* Add empty state to disabled small toolbar play button
184
                            if (emptyPage.noMusic) {
185
                                return;
186
                            }
187
398.1.1 by Andrew Hayzen
* Add ability to play random song when queue is empty
188
                            if (trackQueue.model.count === 0) {
189
                                playRandomSong();
190
                            }
191
                            else {
192
                                player.toggle();
193
                            }
194
                        }
195
                    }
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
196
                }
197
640.4.3 by Andrew Hayzen
* Switch progress bar position
198
                /* Enabled (queue > 0) controls */
687.1.1 by Andrew Hayzen
* Remove rectangles
199
                Item {
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
200
                    id: enabledPlayerControlsGroup
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
201
                    anchors {
640.4.3 by Andrew Hayzen
* Switch progress bar position
202
                        bottom: playerControlsProgressBar.top
640.4.1 by Andrew Hayzen
* Fix the toolbar so it is always shown
203
                        left: parent.left
204
                        right: parent.right
640.4.3 by Andrew Hayzen
* Switch progress bar position
205
                        top: parent.top
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
206
                    }
207
208
                    /* Album art in player controls */
675.1.3 by Andrew Hayzen
* Remove smooth = true
209
                    CoverGrid {
210
                         id:  playerControlsImage
211
                         anchors {
212
                             bottom: parent.bottom
213
                             left: parent.left
214
                             top: parent.top
215
                         }
216
                         covers: [{art: player.currentMetaArt, author: player.currentMetaArtist, album: player.currentMetaArt}]
217
                         size: parent.height
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
218
                    }
219
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
220
                    /* Column of meta labels */
221
                    Column {
222
                        id: playerControlsLabels
223
                        anchors {
224
                            left: playerControlsImage.right
225
                            leftMargin: units.gu(1.5)
640.1.2 by Andrew Hayzen
* Rework mouse areas with animated click region
226
                            right: playerControlsPlayButton.left
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
227
                            rightMargin: units.gu(1)
228
                            verticalCenter: parent.verticalCenter
229
                        }
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
230
231
                        /* Title of track */
232
                        Label {
233
                            id: playerControlsTitle
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
234
                            anchors {
235
                                left: parent.left
236
                                right: parent.right
237
                            }
238
                            color: "#FFF"
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
239
                            elide: Text.ElideRight
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
240
                            fontSize: "small"
640.1.2 by Andrew Hayzen
* Rework mouse areas with animated click region
241
                            font.weight: Font.DemiBold
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
242
                            text: player.currentMetaTitle === ""
243
                                  ? player.source : player.currentMetaTitle
244
                        }
245
246
                        /* Artist of track */
247
                        Label {
248
                            id: playerControlsArtist
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
249
                            anchors {
250
                                left: parent.left
251
                                right: parent.right
252
                            }
253
                            color: "#FFF"
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
254
                            elide: Text.ElideRight
255
                            fontSize: "small"
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
256
                            opacity: 0.4
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
257
                            text: player.currentMetaArtist
258
                        }
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
259
                    }
260
261
                    /* Play/Pause button */
262
                    Icon {
263
                        id: playerControlsPlayButton
264
                        anchors {
640.1.2 by Andrew Hayzen
* Rework mouse areas with animated click region
265
                            right: parent.right
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
266
                            rightMargin: units.gu(3)
267
                            verticalCenter: parent.verticalCenter
268
                        }
269
                        color: "#FFF"
270
                        height: units.gu(2.5)
271
                        name: player.playbackState === MediaPlayer.PlayingState ?
272
                                  "media-playback-pause" : "media-playback-start"
651.1.2 by Andrew Hayzen
* Various fixes for autopilot
273
                        objectName: "playShape"
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
274
                        width: height
275
                    }
276
277
                    MouseArea {
278
                        anchors {
279
                            bottom: parent.bottom
640.1.2 by Andrew Hayzen
* Rework mouse areas with animated click region
280
                            horizontalCenter: playerControlsPlayButton.horizontalCenter
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
281
                            top: parent.top
282
                        }
283
                        onClicked: player.toggle()
640.1.2 by Andrew Hayzen
* Rework mouse areas with animated click region
284
                        width: units.gu(8)
285
286
                        Rectangle {
287
                            anchors {
288
                                fill: parent
289
                            }
290
                            color: "#FFF"
291
                            opacity: parent.pressed ? 0.1 : 0
292
293
                            Behavior on opacity {
294
                                UbuntuNumberAnimation {
295
                                    duration: UbuntuAnimation.FastDuration
296
                                }
297
                            }
298
                        }
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
299
                    }
300
301
                    /* Mouse area to jump to now playing */
687.1.1 by Andrew Hayzen
* Remove rectangles
302
                    Item {
640.1.1 by Andrew Hayzen
* Implement new small toolbar design
303
                        anchors {
304
                            bottom: parent.bottom
305
                            left: parent.left
306
                            right: playerControlsLabels.right
307
                            top: parent.top
308
                        }
651.1.6 by Andrew Hayzen
* Further fixes for autopilot
309
                        objectName: "jumpNowPlaying"
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
310
                        function trigger() {
444.2.2 by Andrew Hayzen
* Change setNowPlaying(visible) to pushNowPlaying(void)
311
                            tabs.pushNowPlaying();
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
312
                        }
313
                    }
314
                }
640.4.3 by Andrew Hayzen
* Switch progress bar position
315
316
                /* Object which provides the progress bar when toolbar is minimized */
317
                Rectangle {
318
                    id: playerControlsProgressBar
319
                    anchors {
320
                        bottom: parent.bottom
321
                        left: parent.left
322
                        right: parent.right
323
                    }
324
                    color: styleMusic.common.black
325
                    height: units.gu(0.25)
326
327
                    Rectangle {
328
                        id: playerControlsProgressBarHint
329
                        anchors {
330
                            left: parent.left
331
                            top: parent.top
332
                        }
333
                        color: UbuntuColors.blue
334
                        height: parent.height
803.1.1 by Victor Thompson
* Fix Queue progress hint not being shown
335
                        width: player.duration > 0 ? (player.position / player.duration) * playerControlsProgressBar.width : 0
640.4.3 by Andrew Hayzen
* Switch progress bar position
336
337
                        Connections {
338
                            target: player
339
                            onPositionChanged: {
340
                                playerControlsProgressBarHint.width = (player.position / player.duration) * playerControlsProgressBar.width
341
                            }
342
                            onStopped: {
343
                                playerControlsProgressBarHint.width = 0;
344
                            }
345
                        }
346
                    }
347
                }
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
348
            }
349
        }
297.2.1 by Andrew Hayzen
* Allow toolbar to be shown when Alt key is pressed
350
    }
133.1.1 by Andrew Hayzen
* Custom toolbar created
351
}
384.2.1 by Andrew Hayzen
* Migrate musicToolbar to use Panel component
352