ElisaMainWindow.qml 10.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
Alexander Stippich's avatar
Alexander Stippich committed
19 20
import QtQuick.Controls 2.2
import QtQuick.Controls 1.4 as Controls1
21 22
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
23
import org.kde.elisa 1.0
24
import Qt.labs.settings 1.0
25 26

ApplicationWindow {
27 28
    id: mainWindow

29
    visible: true
30

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

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

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

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

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

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

Alexander Stippich's avatar
Alexander Stippich committed
51
    Controls1.Action {
52 53 54 55 56 57 58 59 60 61
        id: applicationMenuAction
        text: i18nc("open application menu", "Application Menu")
        iconName: "application-menu"
        onTriggered: applicationMenu.popup()
    }

    ApplicationMenu {
        id: applicationMenu
    }

62 63 64 65 66
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

67 68 69 70
    Theme {
        id: elisaTheme
    }

71
    Settings {
72 73 74 75
        id: persistentSettings

        property int x
        property int y
76
        property int width : 1100
77
        property int height : 600
78

79
        property var playListState
80

81
        property var audioPlayerState
82

83
        property double playControlItemVolume : 100.0
84
        property bool playControlItemMuted : false
85

Diego Gangl's avatar
Diego Gangl committed
86 87 88
        property bool playControlItemRepeat : false
        property bool playControlItemShuffle : false

89
        property bool expandedFilterView: false
90

Diego Gangl's avatar
Diego Gangl committed
91
        property bool showPlaylist: true
92 93

        property bool headerBarIsMaximized: false
94
   }
95

96 97 98 99 100 101 102 103 104
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

105
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
106
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
107

108 109
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
Diego Gangl's avatar
Diego Gangl committed
110 111 112

            persistentSettings.playControlItemRepeat = headerBar.playerControl.repeat
            persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle
Diego Gangl's avatar
Diego Gangl committed
113
            persistentSettings.showPlaylist = contentView.showPlaylist
114 115

            persistentSettings.headerBarIsMaximized = headerBar.isMaximized
116 117 118
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
119 120 121
    Loader {
        id: mprisloader
        active: false
122

Alexander Stippich's avatar
Alexander Stippich committed
123 124
        sourceComponent:  PlatformIntegration {
            id: platformInterface
125

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

137
        }
138 139
    }

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

Alexander Stippich's avatar
Alexander Stippich committed
146
    Connections {
147
        target: elisa.mediaPlayList
148

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

154 155 156 157
    PassiveNotification {
        id: messageNotification
    }

158
    Rectangle {
159
        color: myPalette.base
160 161
        anchors.fill: parent

162 163 164
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
165

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

172

173 174
                HeaderBar {
                    id: headerBar
175

176 177
                    focus: true

178
                    anchors.fill: parent
179

180 181 182 183 184
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
185

186
                    ratingVisible: false
187

Alexander Stippich's avatar
Alexander Stippich committed
188 189
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
190

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

Diego Gangl's avatar
Diego Gangl committed
199 200 201
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

Alexander Stippich's avatar
Alexander Stippich committed
204 205
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
206 207
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
208

209 210
                    playerControl.isMaximized: persistentSettings.headerBarIsMaximized

211
                    TrackImportNotification {
212 213 214 215
                        id: importedTracksCountNotification

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

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

247
                        active: elisa.musicManager !== undefined
248
                    }
249
                }
250
            }
251

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

261 262 263 264 265
    StateGroup {
        id: mainWindowState
        states: [
            State {
                name: "headerBarIsMaximized"
Matthieu Gallien's avatar
Matthieu Gallien committed
266
                when: headerBar.isMaximized
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
                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
                    }
                ]
            }
        ]
    }

288 289 290 291
    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
292 293 294
        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})
295

296 297 298
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
299

Alexander Stippich's avatar
Alexander Stippich committed
300 301 302
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
303 304 305 306

        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
307
        mprisloader.active = true
308
    }
309
}