ElisaMainWindow.qml 11.6 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 44 45
    Accessible.role: Accessible.Application
    Accessible.name: title

46
    property var goBackAction: elisa.action("go_back")
47 48
    property var seekAction: elisa.action("Seek")
    property var scrubAction: elisa.action("Scrub")
49
    property var playPauseAction: elisa.action("Play-Pause")
Diego Gangl's avatar
Diego Gangl committed
50

51
    Action {
52
        shortcut: goBackAction.shortcut
53
        onTriggered: contentView.goBack()
54 55
    }

56 57 58 59 60 61 62 63 64 65
    Action {
            shortcut: seekAction.shortcut
            onTriggered: elisa.audioControl.seek(headerBar.playerControl.position + 10000)
    }

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

66 67 68 69 70
    Action {
            shortcut: playPauseAction.shortcut
            onTriggered: elisa.audioControl.playPause()
    }

71 72 73 74
    ApplicationMenu {
        id: applicationMenu
    }

75 76 77 78 79
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

80 81 82 83
    Theme {
        id: elisaTheme
    }

84
    Settings {
85 86 87 88
        id: persistentSettings

        property int x
        property int y
89
        property int width : 1100
90
        property int height : 600
91

92
        property var playListState
93

94
        property var audioPlayerState
95

96
        property double playControlItemVolume : 100.0
97
        property bool playControlItemMuted : false
98

99
        property bool expandedFilterView: false
100

Diego Gangl's avatar
Diego Gangl committed
101
        property bool showPlaylist: true
102 103

        property bool headerBarIsMaximized: false
104 105 106 107 108 109
    }

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

111 112 113 114 115 116 117 118 119
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

120
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
121
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
122

123 124
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
125

Diego Gangl's avatar
Diego Gangl committed
126
            persistentSettings.showPlaylist = contentView.showPlaylist
127 128

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
129 130 131
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
132 133 134
    Loader {
        id: mprisloader
        active: false
135

Alexander Stippich's avatar
Alexander Stippich committed
136 137
        sourceComponent:  PlatformIntegration {
            id: platformInterface
138

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

150
        }
151 152
    }

Alexander Stippich's avatar
Alexander Stippich committed
153 154
    Connections {
        target: elisa.audioPlayer
155 156
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
157 158
    }

Alexander Stippich's avatar
Alexander Stippich committed
159
    Connections {
160
        target: elisa.mediaPlayList
161

Alexander Stippich's avatar
Alexander Stippich committed
162
        onPlayListLoadFailed: {
163 164
            messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000)
        }
165 166
    }

167 168 169 170
    PassiveNotification {
        id: messageNotification
    }

171
    Rectangle {
172
        color: myPalette.base
173 174
        anchors.fill: parent

175 176 177
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
178

179
            Item {
180
                id: headerBarParent
181 182
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
183
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
184

185

186 187
                HeaderBar {
                    id: headerBar
188

189 190
                    focus: true

191
                    anchors.fill: parent
192

193 194 195 196
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
197
                    albumArtist: elisa.manageHeaderBar.albumArtist
198
                    image: elisa.manageHeaderBar.image
199
                    albumID: elisa.manageHeaderBar.albumId
200

201
                    ratingVisible: false
202

Alexander Stippich's avatar
Alexander Stippich committed
203 204
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
205

206 207
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
208
                    playerControl.position: elisa.audioPlayer.position
209 210 211 212
                    playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled
                    playerControl.playEnabled: elisa.playerControl.playControlEnabled
                    playerControl.isPlaying: elisa.playerControl.musicPlaying
213

214 215
                    playerControl.repeat: elisa.mediaPlayList.repeatPlay
                    playerControl.shuffle: elisa.mediaPlayList.randomPlay
Diego Gangl's avatar
Diego Gangl committed
216

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

Alexander Stippich's avatar
Alexander Stippich committed
219 220
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
221 222
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
223

224
                    playerControl.isMaximized: persistentSettings.headerBarIsMaximized
225 226
                    onOpenArtist: { contentView.openArtist(artist) }
                    onOpenNowPlaying: { contentView.openNowPlaying() }
227
                    onOpenAlbum: { contentView.openAlbum(album, albumArtist, image, albumID) }
228

229
                    TrackImportNotification {
230 231 232 233
                        id: importedTracksCountNotification

                        anchors
                        {
Diego Gangl's avatar
Diego Gangl committed
234 235 236 237
                            right: headerBar.right
                            top: headerBar.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 1.75
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
238
                        }
239 240 241 242 243 244 245 246 247
                    }

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

248 249
                    Binding {
                        id: indexerBusyBinding
250

251 252 253 254
                        target: importedTracksCountNotification
                        property: 'indexingRunning'
                        value: elisa.musicManager.indexerBusy
                        when: elisa.musicManager !== undefined
255 256
                    }

257 258 259 260 261
                    Binding {
                        target: importedTracksCountNotification
                        property: 'importedTracksCount'
                        value: elisa.musicManager.importedTracksCount
                        when: elisa.musicManager !== undefined
262
                    }
263
                }
264
            }
265

266 267 268 269 270 271
            Rectangle {
                Layout.fillWidth: true
                height: 1
                color: myPalette.mid
            }

272 273
            ContentView {
                id: contentView
274
                Layout.fillHeight: true
275
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
276
                showPlaylist: persistentSettings.showPlaylist
277
            }
278 279
        }
    }
280

281 282 283
    StateGroup {
        id: mainWindowState
        states: [
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
            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
                    }
                ]
            },
300 301
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
302
                when: headerBar.isMaximized
303 304 305 306 307 308 309 310 311 312 313 314 315 316
                changes: [
                    PropertyChanges {
                        target: mainWindow
                        minimumHeight: 120 + elisaTheme.mediaPlayerControlHeight
                        explicit: true
                    },
                    PropertyChanges {
                        target: headerBarParent
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
                    }
                ]
            }
        ]
317 318 319 320 321 322 323
        transitions: Transition {
            NumberAnimation {
                properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight"
                easing.type: Easing.InOutQuad
                duration: 300
            }
        }
324 325
    }

326 327 328 329
    Component.onCompleted:
    {
        elisa.initialize()

330 331 332
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
333

Alexander Stippich's avatar
Alexander Stippich committed
334 335 336
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
337

338 339 340
        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})
Alexander Stippich's avatar
Alexander Stippich committed
341 342 343
        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
344
        mprisloader.active = true
345
    }
346
}