ElisaMainWindow.qml 11.3 KB
Newer Older
1
/*
2
 * Copyright 2016-2018 Matthieu Gallien <matthieu_gallien@yahoo.fr>
3
 *
4 5
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
6 7 8
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
9
 * This program is distributed in the hope that it will be useful,
10 11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14 15
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17
 */

18
import QtQuick 2.7
19
import QtQuick.Controls 2.3
20 21
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
22
import org.kde.elisa 1.0
23
import Qt.labs.settings 1.0
24 25

ApplicationWindow {
26 27
    id: mainWindow

28
    visible: true
29

Diego Gangl's avatar
Diego Gangl committed
30
    minimumWidth: contentView.showPlaylist ? 1100 : 700
31
    minimumHeight: 600
32

Safa AlFulaij's avatar
Safa AlFulaij committed
33 34 35
    LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
    LayoutMirroring.childrenInherit: true

36 37 38 39 40
    x: persistentSettings.x
    y: persistentSettings.y
    width: persistentSettings.width
    height: persistentSettings.height

Safa AlFulaij's avatar
Safa AlFulaij committed
41
    title: i18n("Elisa")
42

43
    property var goBackAction: elisa.action("go_back")
44 45
    property var seekAction: elisa.action("Seek")
    property var scrubAction: elisa.action("Scrub")
Diego Gangl's avatar
Diego Gangl committed
46

47
    Action {
48
        shortcut: goBackAction.shortcut
49
        onTriggered: contentView.goBack()
50 51
    }

52 53 54 55 56 57 58 59 60 61
    Action {
            shortcut: seekAction.shortcut
            onTriggered: elisa.audioControl.seek(headerBar.playerControl.position + 10000)
    }

    Action {
            shortcut: scrubAction.shortcut
            onTriggered: elisa.audioControl.seek(headerBar.playerControl.position - 10000)
    }

62 63 64 65
    ApplicationMenu {
        id: applicationMenu
    }

66 67 68 69 70
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

71 72 73 74
    Theme {
        id: elisaTheme
    }

75
    Settings {
76 77 78 79
        id: persistentSettings

        property int x
        property int y
80
        property int width : 1100
81
        property int height : 600
82

83
        property var playListState
84

85
        property var audioPlayerState
86

87
        property double playControlItemVolume : 100.0
88
        property bool playControlItemMuted : false
89

Diego Gangl's avatar
Diego Gangl committed
90 91 92
        property bool playControlItemRepeat : false
        property bool playControlItemShuffle : false

93
        property bool expandedFilterView: false
94

Diego Gangl's avatar
Diego Gangl committed
95
        property bool showPlaylist: true
96 97

        property bool headerBarIsMaximized: false
98 99 100 101 102 103
    }

    Connections {
        target: headerBar.playerControl
        onOpenMenu: applicationMenu.popup()
    }
104

105 106 107 108 109 110 111 112 113
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

114
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
115
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
116

117 118
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
119 120 121

            persistentSettings.playControlItemRepeat = headerBar.playerControl.repeat
            persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle
Diego Gangl's avatar
Diego Gangl committed
122
            persistentSettings.showPlaylist = contentView.showPlaylist
123 124

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
125 126 127
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
128 129 130
    Loader {
        id: mprisloader
        active: false
131

Alexander Stippich's avatar
Alexander Stippich committed
132 133
        sourceComponent:  PlatformIntegration {
            id: platformInterface
134

Alexander Stippich's avatar
Alexander Stippich committed
135 136 137
            playListModel: elisa.mediaPlayList
            audioPlayerManager: elisa.audioControl
            player: elisa.audioPlayer
138 139 140
            headerBarManager: elisa.manageHeaderBar
            manageMediaPlayerControl: elisa.playerControl
            onRaisePlayer: {
Alexander Stippich's avatar
Alexander Stippich committed
141 142 143 144
                mainWindow.show()
                mainWindow.raise()
                mainWindow.requestActivate()
            }
145

146
        }
147 148
    }

Alexander Stippich's avatar
Alexander Stippich committed
149 150
    Connections {
        target: elisa.audioPlayer
151 152
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
153 154
    }

Alexander Stippich's avatar
Alexander Stippich committed
155
    Connections {
156
        target: elisa.mediaPlayList
157

Alexander Stippich's avatar
Alexander Stippich committed
158
        onPlayListLoadFailed: {
159 160
            messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000)
        }
161 162
    }

163 164 165 166
    PassiveNotification {
        id: messageNotification
    }

167
    Rectangle {
168
        color: myPalette.base
169 170
        anchors.fill: parent

171 172 173
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
174

175
            Item {
176
                id: headerBarParent
177 178
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
179
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
180

181

182 183
                HeaderBar {
                    id: headerBar
184

185 186
                    focus: true

187
                    anchors.fill: parent
188

189 190 191 192 193
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
194

195
                    ratingVisible: false
196

Alexander Stippich's avatar
Alexander Stippich committed
197 198
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
199

200 201
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
202
                    playerControl.position: elisa.audioPlayer.position
203 204 205 206
                    playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled
                    playerControl.playEnabled: elisa.playerControl.playControlEnabled
                    playerControl.isPlaying: elisa.playerControl.musicPlaying
207

Diego Gangl's avatar
Diego Gangl committed
208 209 210
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

Alexander Stippich's avatar
Alexander Stippich committed
211
                    playerControl.onSeek: elisa.audioPlayer.seek(position)
212

Alexander Stippich's avatar
Alexander Stippich committed
213 214
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
215 216
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
217

218 219
                    playerControl.isMaximized: persistentSettings.headerBarIsMaximized

220
                    TrackImportNotification {
221 222 223 224
                        id: importedTracksCountNotification

                        anchors
                        {
Diego Gangl's avatar
Diego Gangl committed
225 226 227 228
                            right: headerBar.right
                            top: headerBar.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 1.75
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
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
                    }

                    Binding {
                        target: importedTracksCountNotification
                        property: 'musicManager'
                        value: elisa.musicManager
                        when: elisa.musicManager !== undefined
                    }

                    Loader {
                        sourceComponent: Binding {
                            target: importedTracksCountNotification
                            property: 'indexingRunning'
                            value: elisa.musicManager.indexingRunning
                        }

                        active: elisa.musicManager !== undefined
                    }

                    Loader {
                        sourceComponent: Binding {
                            target: importedTracksCountNotification
                            property: 'importedTracksCount'
                            value: elisa.musicManager.importedTracksCount
                        }
255

256
                        active: elisa.musicManager !== undefined
257
                    }
258
                }
259
            }
260

261 262
            ContentView {
                id: contentView
263
                Layout.fillHeight: true
264
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
265
                showPlaylist: persistentSettings.showPlaylist
266
            }
267 268
        }
    }
269

270 271 272
    StateGroup {
        id: mainWindowState
        states: [
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
            State {
                name: "headerBarIsNormal"
                when: !headerBar.isMaximized
                changes: [
                    PropertyChanges {
                        target: mainWindow
                        minimumHeight: 600
                        explicit: true
                    },
                    PropertyChanges {
                        target: headerBarParent
                        Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                        Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                    }
                ]
            },
289 290
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
291
                when: headerBar.isMaximized
292 293 294 295 296 297 298 299 300 301 302 303 304 305
                changes: [
                    PropertyChanges {
                        target: mainWindow
                        minimumHeight: 120 + elisaTheme.mediaPlayerControlHeight
                        explicit: true
                    },
                    PropertyChanges {
                        target: headerBarParent
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
                    }
                ]
            }
        ]
306 307 308 309 310 311 312
        transitions: Transition {
            NumberAnimation {
                properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight"
                easing.type: Easing.InOutQuad
                duration: 300
            }
        }
313 314
    }

315 316 317 318
    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
319 320 321
        elisa.mediaPlayList.randomPlay = Qt.binding(function() { return headerBar.playerControl.shuffle })
        elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
        elisa.playerControl.randomOrContinuePlay = Qt.binding(function() { return headerBar.playerControl.shuffle || headerBar.playerControl.repeat})
322

323 324 325
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
326

Alexander Stippich's avatar
Alexander Stippich committed
327 328 329
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
330 331 332 333

        elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
        elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })

Alexander Stippich's avatar
Alexander Stippich committed
334
        mprisloader.active = true
335
    }
336
}