ElisaMainWindow.qml 11.1 KB
Newer Older
1
/*
2
 * Copyright 2016-2018 Matthieu Gallien <matthieu_gallien@yahoo.fr>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

20
import QtQuick 2.7
Alexander Stippich's avatar
Alexander Stippich committed
21 22
import QtQuick.Controls 2.2
import QtQuick.Controls 1.4 as Controls1
23 24
import QtQuick.Layouts 1.1
import QtQuick.Window 2.2
25
import org.kde.elisa 1.0
26
import Qt.labs.settings 1.0
27 28

ApplicationWindow {
29 30
    id: mainWindow

31
    visible: true
32

33
    minimumWidth: 1100
34
    minimumHeight: 600
35

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

39 40 41 42 43
    x: persistentSettings.x
    y: persistentSettings.y
    width: persistentSettings.width
    height: persistentSettings.height

Safa AlFulaij's avatar
Safa AlFulaij committed
44
    title: i18n("Elisa")
45

46
    property var goBackAction: elisa.action("go_back")
47
    property var findAction: elisa.action("edit_find")
48

49 50 51 52 53 54 55 56 57 58 59
    Controls1.Action  {
        shortcut: findAction.shortcut
        onTriggered: {
            if ( persistentSettings.expandedFilterView == true)
            {
                persistentSettings.expandedFilterView = false
            } else {
                persistentSettings.expandedFilterView = true
            }
        }
    }
60
    Controls1.Action  {
61
        shortcut: goBackAction.shortcut
62
        onTriggered: contentView.goBack()
63 64
    }

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

    ApplicationMenu {
        id: applicationMenu
    }

76 77 78 79 80
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

81 82 83 84
    Theme {
        id: elisaTheme
    }

85
    Settings {
86 87 88 89
        id: persistentSettings

        property int x
        property int y
90
        property int width : 1100
91
        property int height : 600
92

93
        property var playListState
94 95

        property var playListControlerState
96 97

        property var audioPlayerState
98

99
        property double playControlItemVolume : 100.0
100
        property bool playControlItemMuted : false
101

102
        property bool expandedFilterView: false
103 104

   }
105

106 107 108 109 110 111 112 113 114
    Connections {
        target: Qt.application
        onAboutToQuit:
        {
            persistentSettings.x = mainWindow.x;
            persistentSettings.y = mainWindow.y;
            persistentSettings.width = mainWindow.width;
            persistentSettings.height = mainWindow.height;

115 116
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
            persistentSettings.playListControlerState = elisa.mediaPlayList.persistentState;
Alexander Stippich's avatar
Alexander Stippich committed
117
            persistentSettings.audioPlayerState = elisa.audioControl.persistentState
118

119 120
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
121 122 123
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
124 125 126
    Loader {
        id: mprisloader
        active: false
127

Alexander Stippich's avatar
Alexander Stippich committed
128 129
        sourceComponent:  PlatformIntegration {
            id: platformInterface
130

Alexander Stippich's avatar
Alexander Stippich committed
131 132 133 134 135 136 137 138 139 140 141 142
            playListModel: elisa.mediaPlayList
            playListControler: elisa.mediaPlayList
            audioPlayerManager: elisa.audioControl
            player: elisa.audioPlayer
            headerBarManager: myHeaderBarManager
            manageMediaPlayerControl: myPlayControlManager
            onRaisePlayer:
            {
                mainWindow.show()
                mainWindow.raise()
                mainWindow.requestActivate()
            }
143
        }
144 145
    }

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

149 150
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
151

152 153 154 155 156 157 158
        onPlaying: {
            myPlayControlManager.playerPlaying()
        }

        onPaused: {
            myPlayControlManager.playerPaused()
        }
159

160 161 162
        onStopped: {
            myPlayControlManager.playerStopped()
        }
163 164
    }

Alexander Stippich's avatar
Alexander Stippich committed
165
    Connections {
166
        target: elisa.mediaPlayList
167

Alexander Stippich's avatar
Alexander Stippich committed
168
        onPlayListLoadFailed: {
169 170
            messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000)
        }
171 172
    }

173 174 175
    ManageHeaderBar {
        id: myHeaderBarManager

176 177
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
178

179 180 181 182
        artistRole: MediaPlayList.ArtistRole
        titleRole: MediaPlayList.TitleRole
        albumRole: MediaPlayList.AlbumRole
        imageRole: MediaPlayList.ImageRole
183
        isValidRole: MediaPlayList.IsValidRole
184 185 186 187 188
    }

    ManageMediaPlayerControl {
        id: myPlayControlManager

189 190
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
191 192
    }

193 194 195 196
    PassiveNotification {
        id: messageNotification
    }

197
    Rectangle {
198
        color: myPalette.base
199 200
        anchors.fill: parent

201 202 203
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
204

205 206 207 208
            Item {
                Layout.preferredHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.minimumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
                Layout.maximumHeight: mainWindow.height * 0.2 + elisaTheme.mediaPlayerControlHeight
209
                Layout.fillWidth: true
210

211 212
                HeaderBar {
                    id: headerBar
213

214 215
                    focus: true

216
                    anchors.fill: parent
217

218 219 220 221 222
                    tracksCount: myHeaderBarManager.remainingTracks
                    album: myHeaderBarManager.album
                    title: myHeaderBarManager.title
                    artist: myHeaderBarManager.artist
                    image: myHeaderBarManager.image
223

224
                    ratingVisible: false
225

Alexander Stippich's avatar
Alexander Stippich committed
226 227
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
228

229 230
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
231
                    playerControl.position: elisa.audioPlayer.position
232 233 234 235
                    playerControl.skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled
                    playerControl.playEnabled: myPlayControlManager.playControlEnabled
                    playerControl.isPlaying: myPlayControlManager.musicPlaying
236

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

Alexander Stippich's avatar
Alexander Stippich committed
239 240
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
241 242
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
243

Alexander Stippich's avatar
Alexander Stippich committed
244
                    Controls1.ToolButton {
245
                        id: menuButton
246

247
                        action: applicationMenuAction
248

249
                        z: 2
250

251 252 253 254 255 256 257 258
                        anchors
                        {
                            right: parent.right
                            top: parent.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
                    }
Alexander Stippich's avatar
Alexander Stippich committed
259

260 261
                    Rectangle {
                        anchors.fill: menuButton
262

263
                        z: 1
264

265
                        radius: width / 2
266

267 268
                        color: myPalette.window
                    }
269

270
                    TrackImportNotification {
271 272 273 274 275 276 277 278 279
                        id: importedTracksCountNotification

                        anchors
                        {
                            right: menuButton.left
                            top: menuButton.top
                            bottom: menuButton.bottom
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
                    }

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

306
                        active: elisa.musicManager !== undefined
307
                    }
308
                }
309
            }
310

311 312
            ContentView {
                id: contentView
313
                Layout.fillHeight: true
314
                Layout.fillWidth: true
315
            }
316 317
        }
    }
318 319 320 321 322

    Component.onCompleted:
    {
        elisa.initialize()

323 324 325
        elisa.mediaPlayList.randomPlay = Qt.binding(function() { return contentView.playList.randomPlayChecked })
        elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return contentView.playList.repeatPlayChecked })
        myPlayControlManager.randomOrContinuePlay = Qt.binding(function() { return contentView.playList.randomPlayChecked || contentView.playList.repeatPlayChecked })
Alexander Stippich's avatar
Alexander Stippich committed
326 327
        myPlayControlManager.playListModel = Qt.binding(function() { return elisa.mediaPlayList })
        myPlayControlManager.currentTrack = Qt.binding(function() { return elisa.mediaPlayList.currentTrack })
328

329 330 331
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Alexander Stippich's avatar
Alexander Stippich committed
332 333 334
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
335 336 337 338 339

        elisa.audioPlayer.muted = Qt.binding(function() { return headerBar.playerControl.muted })
        elisa.audioPlayer.volume = Qt.binding(function() { return headerBar.playerControl.volume })

        volume: headerBar.playerControl.volume
Alexander Stippich's avatar
Alexander Stippich committed
340 341

        mprisloader.active = true
342
    }
343
}