ElisaMainWindow.qml 12.5 KB
Newer Older
1
/*
Matthieu Gallien's avatar
Matthieu Gallien committed
2 3 4
   SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>

   SPDX-License-Identifier: LGPL-3.0-or-later
5 6
 */

7
import QtQuick 2.7
8
import QtQuick.Controls 2.3
9 10
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
11
import org.kde.kirigami 2.5 as Kirigami
12
import org.kde.elisa 1.0
13
import org.kde.elisa.host 1.0
14
import Qt.labs.settings 1.0
15
import Qt.labs.platform 1.1
16

17
Kirigami.ApplicationWindow {
18
    id: mainWindow
19
    
20
    visible: true
21 22 23 24 25 26 27 28 29 30 31 32 33 34

    contextDrawer: Kirigami.ContextDrawer {
        id: playlistDrawer
        handleClosedIcon.source: "view-media-playlist"
        handleOpenIcon.source: "view-right-close"
        // without this drawer button is never shown
        enabled: true
        MediaPlayListView {
            id: playList
            anchors.fill: parent
            onStartPlayback: ElisaApplication.audioControl.ensurePlay()
            onPausePlayback: ElisaApplication.audioControl.playPause()
        }
    }
35 36 37
    
    minimumWidth: 590
    property int minHeight: 320
38

Safa AlFulaij's avatar
Safa AlFulaij committed
39 40 41
    LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
    LayoutMirroring.childrenInherit: true

42 43 44 45 46
    x: persistentSettings.x
    y: persistentSettings.y
    width: persistentSettings.width
    height: persistentSettings.height

Safa AlFulaij's avatar
Safa AlFulaij committed
47
    title: i18n("Elisa")
48

49 50 51
    Accessible.role: Accessible.Application
    Accessible.name: title

52 53 54 55 56
    property var goBackAction: ElisaApplication.action("go_back")
    property var seekAction: ElisaApplication.action("Seek")
    property var scrubAction: ElisaApplication.action("Scrub")
    property var playPauseAction: ElisaApplication.action("Play-Pause")
    property var findAction: ElisaApplication.action("edit_find")
Diego Gangl's avatar
Diego Gangl committed
57

58
    Action {
59
        shortcut: goBackAction.shortcut
60
        onTriggered: contentView.goBack()
61 62
    }

63
    Action {
64
        shortcut: seekAction.shortcut
65
        onTriggered: ElisaApplication.audioControl.seek(headerBar.playerControl.position + 10000)
66 67 68
    }

    Action {
69
        shortcut: scrubAction.shortcut
70
        onTriggered: ElisaApplication.audioControl.seek(headerBar.playerControl.position - 10000)
71 72
    }

73
    Action {
74
        shortcut: playPauseAction.shortcut
75
        onTriggered: ElisaApplication.audioControl.playPause()
76 77 78 79 80
    }

    Action {
        shortcut: findAction.shortcut
        onTriggered: persistentSettings.expandedFilterView = !persistentSettings.expandedFilterView
81 82
    }

83 84 85 86
    ApplicationMenu {
        id: applicationMenu
    }

87 88 89 90 91
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

92 93 94 95
    Theme {
        id: elisaTheme
    }

96
    Settings {
97 98 99 100
        id: persistentSettings

        property int x
        property int y
101 102
        property int width : 900
        property int height : 650
103

104
        property var playListState
105

106
        property var audioPlayerState
107

108
        property double playControlItemVolume : 100.0
109
        property bool playControlItemMuted : false
110

111
        property bool expandedFilterView: false
112

Diego Gangl's avatar
Diego Gangl committed
113
        property bool showPlaylist: true
114 115

        property bool headerBarIsMaximized: false
116 117 118 119
    }

    Connections {
        target: headerBar.playerControl
120
        function onOpenMenu() {
121 122 123 124 125 126
            if (applicationMenu.visible) {
                applicationMenu.close()
            } else {
                applicationMenu.popup(mainWindow.width - applicationMenu.width, headerBar.height)
            }
        }
127
    }
128

129 130
    Connections {
        target: Qt.application
131
        function onAboutToQuit() {
132 133 134 135 136
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

137 138
            persistentSettings.playListState = ElisaApplication.mediaPlayListProxyModel.persistentState;
            persistentSettings.audioPlayerState = ElisaApplication.audioControl.persistentState
139

140 141
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
142

Diego Gangl's avatar
Diego Gangl committed
143
            persistentSettings.showPlaylist = contentView.showPlaylist
144 145

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
146 147 148
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
149 150 151
    Loader {
        id: mprisloader
        active: false
152

Alexander Stippich's avatar
Alexander Stippich committed
153 154
        sourceComponent:  PlatformIntegration {
            id: platformInterface
155

156 157 158 159 160 161 162
            playListModel: ElisaApplication.mediaPlayListProxyModel
            audioPlayerManager: ElisaApplication.audioControl
            player: ElisaApplication.audioPlayer
            headerBarManager: ElisaApplication.manageHeaderBar
            manageMediaPlayerControl: ElisaApplication.playerControl
            showProgressOnTaskBar: ElisaApplication.showProgressOnTaskBar
            showSystemTrayIcon: ElisaApplication.showSystemTrayIcon
163
            elisaMainWindow: mainWindow
164

165
            function onRaisePlayer() {
166
                mainWindow.visible = true
Alexander Stippich's avatar
Alexander Stippich committed
167 168 169
                mainWindow.raise()
                mainWindow.requestActivate()
            }
170

171
        }
172 173
    }

Alexander Stippich's avatar
Alexander Stippich committed
174
    Connections {
175
        target: ElisaApplication.audioPlayer
176 177 178 179 180 181
        function onVolumeChanged() {
            headerBar.playerControl.volume = ElisaApplication.audioPlayer.volume
        }
        function onMutedChanged() {
            headerBar.playerControl.muted = ElisaApplication.audioPlayer.muted
        }
182 183
    }

184
    Rectangle {
185
        color: myPalette.base
186 187
        anchors.fill: parent

188 189 190
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
191

192 193 194 195 196
            HeaderBar {
                id: headerBar

                focus: true

197 198
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
199
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
200

201 202 203 204 205 206 207
                tracksCount: ElisaApplication.mediaPlayListProxyModel.remainingTracks
                album: (ElisaApplication.manageHeaderBar.album !== undefined ? ElisaApplication.manageHeaderBar.album : '')
                title: ElisaApplication.manageHeaderBar.title
                artist: (ElisaApplication.manageHeaderBar.artist !== undefined ? ElisaApplication.manageHeaderBar.artist : '')
                albumArtist: (ElisaApplication.manageHeaderBar.albumArtist !== undefined ? ElisaApplication.manageHeaderBar.albumArtist : '')
                image: ElisaApplication.manageHeaderBar.image
                albumID: ElisaApplication.manageHeaderBar.albumId
208 209 210

                ratingVisible: false

stef lep's avatar
stef lep committed
211
                playerControl.duration: ElisaApplication.audioControl.audioDuration
212
                playerControl.seekable: ElisaApplication.audioPlayer.seekable
213 214 215

                playerControl.volume: persistentSettings.playControlItemVolume
                playerControl.muted: persistentSettings.playControlItemMuted
stef lep's avatar
stef lep committed
216
                playerControl.position: ElisaApplication.audioControl.playerPosition
217 218 219 220
                playerControl.skipBackwardEnabled: ElisaApplication.playerControl.skipBackwardControlEnabled
                playerControl.skipForwardEnabled: ElisaApplication.playerControl.skipForwardControlEnabled
                playerControl.playEnabled: ElisaApplication.playerControl.playControlEnabled
                playerControl.isPlaying: ElisaApplication.playerControl.musicPlaying
221

222 223
                playerControl.repeat: ElisaApplication.mediaPlayListProxyModel.repeatPlay
                playerControl.shuffle: ElisaApplication.mediaPlayListProxyModel.shufflePlayList
224

225
                playerControl.onSeek: ElisaApplication.audioPlayer.seek(position)
226

227 228
                playerControl.onPlay: ElisaApplication.audioControl.playPause()
                playerControl.onPause: ElisaApplication.audioControl.playPause()
229
                playerControl.onPlayPrevious: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
230
                playerControl.onPlayNext: ElisaApplication.mediaPlayListProxyModel.skipNextTrack()
231 232 233 234 235 236 237 238 239 240 241 242 243

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

                TrackImportNotification {
                    id: importedTracksCountNotification

                    anchors
                    {
                        right: headerBar.right
                        top: headerBar.top
244 245
                        rightMargin: Kirigami.Units.largeSpacing * 2
                        topMargin: Kirigami.Units.largeSpacing * 3
246
                    }
247
                }
248

249 250
                Binding {
                    id: indexerBusyBinding
251

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

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

266
            Kirigami.Separator {
267 268 269
                Layout.fillWidth: true
            }

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

281 282 283
    StateGroup {
        id: mainWindowState
        states: [
284 285 286 287 288 289
            State {
                name: "headerBarIsNormal"
                when: !headerBar.isMaximized
                changes: [
                    PropertyChanges {
                        target: mainWindow
290
                        minimumHeight: mainWindow.minHeight * 1.5
291 292 293
                        explicit: true
                    },
                    PropertyChanges {
294
                        target: headerBar
295 296 297 298 299
                        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
                changes: [
                    PropertyChanges {
                        target: mainWindow
306
                        minimumHeight: mainWindow.minHeight
307 308 309
                        explicit: true
                    },
                    PropertyChanges {
310
                        target: headerBar
311 312
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
313 314 315 316 317 318 319
                    },
                    PropertyChanges {
                        target: playlistDrawer
                        collapsed: true
                        visible: false
                        drawerOpen: false
                        handleVisible: false
320 321 322 323
                    }
                ]
            }
        ]
324 325 326 327
        transitions: Transition {
            NumberAnimation {
                properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight"
                easing.type: Easing.InOutQuad
328
                duration: Kirigami.Units.longDuration
329 330
            }
        }
331 332
    }

333 334
    Component.onCompleted:
    {
335
        ElisaApplication.initialize()
336

337
        if (persistentSettings.playListState) {
338
            ElisaApplication.mediaPlayListProxyModel.persistentState = persistentSettings.playListState
339
        }
Diego Gangl's avatar
Diego Gangl committed
340

Alexander Stippich's avatar
Alexander Stippich committed
341
        if (persistentSettings.audioPlayerState) {
342
            ElisaApplication.audioControl.persistentState = persistentSettings.audioPlayerState
Alexander Stippich's avatar
Alexander Stippich committed
343
        }
Alexander Stippich's avatar
Alexander Stippich committed
344

345 346 347 348
        ElisaApplication.mediaPlayListProxyModel.shufflePlayList = Qt.binding(function() { return headerBar.playerControl.shuffle })
        ElisaApplication.mediaPlayListProxyModel.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
        ElisaApplication.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
        ElisaApplication.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })
Alexander Stippich's avatar
Alexander Stippich committed
349

Alexander Stippich's avatar
Alexander Stippich committed
350
        mprisloader.active = true
351 352

        ElisaApplication.arguments = ElisaArguments.arguments
353
    }
354
}