ElisaMainWindow.qml 10.2 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")
Diego Gangl's avatar
Diego Gangl committed
44

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

    ApplicationMenu {
        id: applicationMenu
    }

54 55 56 57 58
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

59 60 61 62
    Theme {
        id: elisaTheme
    }

63
    Settings {
64 65 66 67
        id: persistentSettings

        property int x
        property int y
68
        property int width : 1100
69
        property int height : 600
70

71
        property var playListState
72

73
        property var audioPlayerState
74

75
        property double playControlItemVolume : 100.0
76
        property bool playControlItemMuted : false
77

Diego Gangl's avatar
Diego Gangl committed
78 79 80
        property bool playControlItemRepeat : false
        property bool playControlItemShuffle : false

81
        property bool expandedFilterView: false
82

Diego Gangl's avatar
Diego Gangl committed
83
        property bool showPlaylist: true
84 85

        property bool headerBarIsMaximized: false
86 87 88 89 90 91
    }

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

93 94 95 96 97 98 99 100 101
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

102
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
103
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
104

105 106
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
107 108 109

            persistentSettings.playControlItemRepeat = headerBar.playerControl.repeat
            persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle
Diego Gangl's avatar
Diego Gangl committed
110
            persistentSettings.showPlaylist = contentView.showPlaylist
111 112

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
113 114 115
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
116 117 118
    Loader {
        id: mprisloader
        active: false
119

Alexander Stippich's avatar
Alexander Stippich committed
120 121
        sourceComponent:  PlatformIntegration {
            id: platformInterface
122

Alexander Stippich's avatar
Alexander Stippich committed
123 124 125
            playListModel: elisa.mediaPlayList
            audioPlayerManager: elisa.audioControl
            player: elisa.audioPlayer
126 127 128
            headerBarManager: elisa.manageHeaderBar
            manageMediaPlayerControl: elisa.playerControl
            onRaisePlayer: {
Alexander Stippich's avatar
Alexander Stippich committed
129 130 131 132
                mainWindow.show()
                mainWindow.raise()
                mainWindow.requestActivate()
            }
133

134
        }
135 136
    }

Alexander Stippich's avatar
Alexander Stippich committed
137 138
    Connections {
        target: elisa.audioPlayer
139 140
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
141 142
    }

Alexander Stippich's avatar
Alexander Stippich committed
143
    Connections {
144
        target: elisa.mediaPlayList
145

Alexander Stippich's avatar
Alexander Stippich committed
146
        onPlayListLoadFailed: {
147 148
            messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000)
        }
149 150
    }

151 152 153 154
    PassiveNotification {
        id: messageNotification
    }

155
    Rectangle {
156
        color: myPalette.base
157 158
        anchors.fill: parent

159 160 161
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
162

163
            Item {
164
                id: headerBarParent
165 166
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
167
                Layout.fillWidth: true
Matthieu Gallien's avatar
Matthieu Gallien committed
168

169

170 171
                HeaderBar {
                    id: headerBar
172

173 174
                    focus: true

175
                    anchors.fill: parent
176

177 178 179 180 181
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
182

183
                    ratingVisible: false
184

Alexander Stippich's avatar
Alexander Stippich committed
185 186
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
187

188 189
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
190
                    playerControl.position: elisa.audioPlayer.position
191 192 193 194
                    playerControl.skipBackwardEnabled: elisa.playerControl.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: elisa.playerControl.skipForwardControlEnabled
                    playerControl.playEnabled: elisa.playerControl.playControlEnabled
                    playerControl.isPlaying: elisa.playerControl.musicPlaying
195

Diego Gangl's avatar
Diego Gangl committed
196 197 198
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

Alexander Stippich's avatar
Alexander Stippich committed
201 202
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
203 204
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
205

206 207
                    playerControl.isMaximized: persistentSettings.headerBarIsMaximized

208
                    TrackImportNotification {
209 210 211 212
                        id: importedTracksCountNotification

                        anchors
                        {
Diego Gangl's avatar
Diego Gangl committed
213 214 215 216
                            right: headerBar.right
                            top: headerBar.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 1.75
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
217
                        }
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
                    }

                    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
                        }
243

244
                        active: elisa.musicManager !== undefined
245
                    }
246
                }
247
            }
248

249 250
            ContentView {
                id: contentView
251
                Layout.fillHeight: true
252
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
253
                showPlaylist: persistentSettings.showPlaylist
254
            }
255 256
        }
    }
257

258 259 260 261 262
    StateGroup {
        id: mainWindowState
        states: [
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
263
                when: headerBar.isMaximized
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
                changes: [
                    PropertyChanges {
                        target: mainWindow
                        minimumHeight: 120 + elisaTheme.mediaPlayerControlHeight
                        explicit: true
                    },
                    PropertyChanges {
                        target: headerBarParent
                        Layout.minimumHeight: mainWindow.height
                        Layout.maximumHeight: mainWindow.height
                    },
                    PropertyChanges {
                        target: contentView
                        height: 0
                        visible: false
                    }
                ]
            }
        ]
    }

285 286 287 288
    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
289 290 291
        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})
292

293 294 295
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
296

Alexander Stippich's avatar
Alexander Stippich committed
297 298 299
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
300 301 302 303

        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
304
        mprisloader.active = true
305
    }
306
}