ElisaMainWindow.qml 13 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
    readonly property int initialViewIndex: 3

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

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

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

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

74
75
76
77
78
79
80
81
82
83
    Action {
        shortcut: nextTrackAction.shortcut
        onTriggered: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
    }

    Action {
        shortcut: previousTrackAction.shortcut
        onTriggered: ElisaApplication.mediaPlayListProxyModel.skipNextTrack(ElisaApplication.audioPlayer.position)
    }

84
    Action {
85
        shortcut: playPauseAction.shortcut
86
        onTriggered: ElisaApplication.audioControl.playPause()
87
88
89
90
91
    }

    Action {
        shortcut: findAction.shortcut
        onTriggered: persistentSettings.expandedFilterView = !persistentSettings.expandedFilterView
92
93
    }

94
95
96
97
    ApplicationMenu {
        id: applicationMenu
    }

98
99
100
101
102
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

103
104
105
106
    Theme {
        id: elisaTheme
    }

107
    Settings {
108
109
110
111
        id: persistentSettings

        property int x
        property int y
112
113
        property int width : 900
        property int height : 650
114

115
        property var playListState
116

117
        property var audioPlayerState
118

119
        property double playControlItemVolume : 100.0
120
        property bool playControlItemMuted : false
121

122
        property bool expandedFilterView: false
123

Diego Gangl's avatar
Diego Gangl committed
124
        property bool showPlaylist: true
125
126

        property bool headerBarIsMaximized: false
127
128
129
130
    }

    Connections {
        target: headerBar.playerControl
131
        function onOpenMenu() {
132
133
134
135
136
137
            if (applicationMenu.visible) {
                applicationMenu.close()
            } else {
                applicationMenu.popup(mainWindow.width - applicationMenu.width, headerBar.height)
            }
        }
138
    }
139

140
141
    Connections {
        target: Qt.application
142
        function onAboutToQuit() {
143
144
145
146
147
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

148
149
            persistentSettings.playListState = ElisaApplication.mediaPlayListProxyModel.persistentState;
            persistentSettings.audioPlayerState = ElisaApplication.audioControl.persistentState
150

151
152
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
153

Diego Gangl's avatar
Diego Gangl committed
154
            persistentSettings.showPlaylist = contentView.showPlaylist
155
156

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
157
158
159
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
160
161
162
    Loader {
        id: mprisloader
        active: false
163

Alexander Stippich's avatar
Alexander Stippich committed
164
165
        sourceComponent:  PlatformIntegration {
            id: platformInterface
166

167
168
169
170
171
172
173
            playListModel: ElisaApplication.mediaPlayListProxyModel
            audioPlayerManager: ElisaApplication.audioControl
            player: ElisaApplication.audioPlayer
            headerBarManager: ElisaApplication.manageHeaderBar
            manageMediaPlayerControl: ElisaApplication.playerControl
            showProgressOnTaskBar: ElisaApplication.showProgressOnTaskBar
            showSystemTrayIcon: ElisaApplication.showSystemTrayIcon
174
            elisaMainWindow: mainWindow
175

176
            function onRaisePlayer() {
177
                mainWindow.visible = true
Alexander Stippich's avatar
Alexander Stippich committed
178
179
180
                mainWindow.raise()
                mainWindow.requestActivate()
            }
181

182
        }
183
184
    }

Alexander Stippich's avatar
Alexander Stippich committed
185
    Connections {
186
        target: ElisaApplication.audioPlayer
187
188
189
190
191
192
        function onVolumeChanged() {
            headerBar.playerControl.volume = ElisaApplication.audioPlayer.volume
        }
        function onMutedChanged() {
            headerBar.playerControl.muted = ElisaApplication.audioPlayer.muted
        }
193
194
    }

195
    Rectangle {
196
        color: myPalette.base
197
198
        anchors.fill: parent

199
200
201
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
202

203
204
205
206
207
            HeaderBar {
                id: headerBar

                focus: true

208
209
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
210
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
211

212
213
214
215
216
217
                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
218
219
220

                ratingVisible: false

stef lep's avatar
stef lep committed
221
                playerControl.duration: ElisaApplication.audioControl.audioDuration
222
                playerControl.seekable: ElisaApplication.audioPlayer.seekable
223
224
225

                playerControl.volume: persistentSettings.playControlItemVolume
                playerControl.muted: persistentSettings.playControlItemMuted
stef lep's avatar
stef lep committed
226
                playerControl.position: ElisaApplication.audioControl.playerPosition
227
228
229
230
                playerControl.skipBackwardEnabled: ElisaApplication.playerControl.skipBackwardControlEnabled
                playerControl.skipForwardEnabled: ElisaApplication.playerControl.skipForwardControlEnabled
                playerControl.playEnabled: ElisaApplication.playerControl.playControlEnabled
                playerControl.isPlaying: ElisaApplication.playerControl.musicPlaying
231

Jan Blackquill's avatar
Jan Blackquill committed
232
                playerControl.repeat: ElisaApplication.mediaPlayListProxyModel.repeatMode
233
                playerControl.shuffle: ElisaApplication.mediaPlayListProxyModel.shufflePlayList
234

235
                playerControl.onSeek: ElisaApplication.audioControl.playerSeek(position)
236

237
238
                playerControl.onPlay: ElisaApplication.audioControl.playPause()
                playerControl.onPause: ElisaApplication.audioControl.playPause()
239
                playerControl.onPlayPrevious: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
240
                playerControl.onPlayNext: ElisaApplication.mediaPlayListProxyModel.skipNextTrack()
241
242
243
244
245
246
247
248
249
250
251
252
253

                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
254
255
                        rightMargin: Kirigami.Units.largeSpacing * 2
                        topMargin: Kirigami.Units.largeSpacing * 3
256
                    }
257
                }
258

259
260
                Binding {
                    id: indexerBusyBinding
261

262
263
                    target: importedTracksCountNotification
                    property: 'indexingRunning'
264
265
                    value: ElisaApplication.musicManager.indexerBusy
                    when: ElisaApplication.musicManager !== undefined
266
                }
267

268
269
270
                Binding {
                    target: importedTracksCountNotification
                    property: 'importedTracksCount'
271
272
                    value: ElisaApplication.musicManager.importedTracksCount
                    when: ElisaApplication.musicManager !== undefined
273
                }
274
            }
275

276
            Kirigami.Separator {
277
278
279
                Layout.fillWidth: true
            }

280
281
            ContentView {
                id: contentView
282
                Layout.fillHeight: true
283
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
284
                showPlaylist: persistentSettings.showPlaylist
285
                showExpandedFilterView: persistentSettings.expandedFilterView
286
                playlistDrawer: playlistDrawer
287
                initialIndex: ElisaApplication.initialViewIndex
288
            }
289
290
        }
    }
291

292
293
294
    StateGroup {
        id: mainWindowState
        states: [
295
296
297
298
299
300
            State {
                name: "headerBarIsNormal"
                when: !headerBar.isMaximized
                changes: [
                    PropertyChanges {
                        target: mainWindow
301
                        minimumHeight: mainWindow.minHeight * 1.5
302
303
304
                        explicit: true
                    },
                    PropertyChanges {
305
                        target: headerBar
306
307
308
309
310
                        Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                        Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                    }
                ]
            },
311
312
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
313
                when: headerBar.isMaximized
314
315
316
                changes: [
                    PropertyChanges {
                        target: mainWindow
317
                        minimumHeight: mainWindow.minHeight
318
319
320
                        explicit: true
                    },
                    PropertyChanges {
321
                        target: headerBar
322
323
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
324
325
326
327
328
329
330
                    },
                    PropertyChanges {
                        target: playlistDrawer
                        collapsed: true
                        visible: false
                        drawerOpen: false
                        handleVisible: false
331
332
333
334
                    }
                ]
            }
        ]
335
336
337
338
        transitions: Transition {
            NumberAnimation {
                properties: "Layout.minimumHeight, Layout.maximumHeight, minimumHeight"
                easing.type: Easing.InOutQuad
339
                duration: Kirigami.Units.longDuration
340
341
            }
        }
342
343
    }

344
345
    Component.onCompleted:
    {
346
        ElisaApplication.initialize()
347
        ElisaApplication.activateColorScheme(ElisaConfigurationDialog.colorScheme)
348

349
        if (persistentSettings.playListState) {
350
            ElisaApplication.mediaPlayListProxyModel.persistentState = persistentSettings.playListState
351
        }
Diego Gangl's avatar
Diego Gangl committed
352

Alexander Stippich's avatar
Alexander Stippich committed
353
        if (persistentSettings.audioPlayerState) {
354
            ElisaApplication.audioControl.persistentState = persistentSettings.audioPlayerState
Alexander Stippich's avatar
Alexander Stippich committed
355
        }
Alexander Stippich's avatar
Alexander Stippich committed
356

357
        ElisaApplication.mediaPlayListProxyModel.shufflePlayList = Qt.binding(function() { return headerBar.playerControl.shuffle })
Jan Blackquill's avatar
Jan Blackquill committed
358
        ElisaApplication.mediaPlayListProxyModel.repeatMode = Qt.binding(function() { return headerBar.playerControl.repeat })
359
360
        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
361

Alexander Stippich's avatar
Alexander Stippich committed
362
        mprisloader.active = true
363
364

        ElisaApplication.arguments = ElisaArguments.arguments
365
    }
366
}