ElisaMainWindow.qml 10.7 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")
45
    property var findAction: elisa.action("edit_find")
46

47 48 49 50 51 52 53 54 55 56 57
    Controls1.Action  {
        shortcut: findAction.shortcut
        onTriggered: {
            if ( persistentSettings.expandedFilterView == true)
            {
                persistentSettings.expandedFilterView = false
            } else {
                persistentSettings.expandedFilterView = true
            }
        }
    }
Diego Gangl's avatar
Diego Gangl committed
58 59

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

Alexander Stippich's avatar
Alexander Stippich committed
64
    Controls1.Action {
65 66 67 68 69 70 71 72 73 74
        id: applicationMenuAction
        text: i18nc("open application menu", "Application Menu")
        iconName: "application-menu"
        onTriggered: applicationMenu.popup()
    }

    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

Diego Gangl's avatar
Diego Gangl committed
99 100 101
        property bool playControlItemRepeat : false
        property bool playControlItemShuffle : false

102
        property bool expandedFilterView: false
103

Diego Gangl's avatar
Diego Gangl committed
104
        property bool showPlaylist: true
105 106

        property bool headerBarIsMaximized: false
107
   }
108

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

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

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

            persistentSettings.playControlItemRepeat = headerBar.playerControl.repeat
            persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle
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
184
                
185

186 187
                HeaderBar {
                    id: headerBar
188

189 190
                    focus: true

191
                    anchors.fill: parent
192

193 194 195 196 197
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
198

199
                    ratingVisible: false
200

Alexander Stippich's avatar
Alexander Stippich committed
201 202
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
203

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

Diego Gangl's avatar
Diego Gangl committed
212 213 214
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

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

222 223
                    playerControl.isMaximized: persistentSettings.headerBarIsMaximized

224
                    TrackImportNotification {
225 226 227 228
                        id: importedTracksCountNotification

                        anchors
                        {
Diego Gangl's avatar
Diego Gangl committed
229 230 231 232
                            right: headerBar.right
                            top: headerBar.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 1.75
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
233
                        }
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
                    }

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

260
                        active: elisa.musicManager !== undefined
261
                    }
262
                }
263
            }
264

265 266
            ContentView {
                id: contentView
267
                Layout.fillHeight: true
268
                Layout.fillWidth: true
Diego Gangl's avatar
Diego Gangl committed
269
                showPlaylist: persistentSettings.showPlaylist
270
            }
271 272
        }
    }
273

274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    StateGroup {
        id: mainWindowState
        states: [
            State {
                name: "headerBarIsMaximized"
                when: headerBar.isMaximized 
                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
                    }
                ]
            }
        ]
    }

301 302 303 304
    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
305 306 307
        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})
308

309 310 311
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
312

Alexander Stippich's avatar
Alexander Stippich committed
313 314 315
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
316 317 318 319

        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
320
        mprisloader.active = true
321
    }
322
}