ElisaMainWindow.qml 10.6 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 audioPlayerState
96

97
        property double playControlItemVolume : 100.0
98
        property bool playControlItemMuted : false
99

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

103
        property bool expandedFilterView: false
104 105

   }
106

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

116
            persistentSettings.playListState = 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
Diego Gangl's avatar
Diego Gangl committed
121 122 123

            persistentSettings.playControlItemRepeat = headerBar.playerControl.repeat
            persistentSettings.playControlItemShuffle = headerBar.playerControl.shuffle
124 125 126
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
127 128 129
    Loader {
        id: mprisloader
        active: false
130

Alexander Stippich's avatar
Alexander Stippich committed
131 132
        sourceComponent:  PlatformIntegration {
            id: platformInterface
133

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

Alexander Stippich's avatar
Alexander Stippich committed
148 149
    Connections {
        target: elisa.audioPlayer
150

151 152
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
153

154 155 156 157 158 159 160
        onPlaying: {
            myPlayControlManager.playerPlaying()
        }

        onPaused: {
            myPlayControlManager.playerPaused()
        }
161

162 163 164
        onStopped: {
            myPlayControlManager.playerStopped()
        }
165 166
    }

Alexander Stippich's avatar
Alexander Stippich committed
167
    Connections {
168
        target: elisa.mediaPlayList
169

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

175 176 177
    ManageHeaderBar {
        id: myHeaderBarManager

178 179
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
180

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

    ManageMediaPlayerControl {
        id: myPlayControlManager

191 192
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
193 194
    }

195 196 197 198
    PassiveNotification {
        id: messageNotification
    }

199
    Rectangle {
200
        color: myPalette.base
201 202
        anchors.fill: parent

203 204 205
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
206

207 208 209 210
            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
211
                Layout.fillWidth: true
212

213 214
                HeaderBar {
                    id: headerBar
215

216 217
                    focus: true

218
                    anchors.fill: parent
219

220 221 222 223 224
                    tracksCount: myHeaderBarManager.remainingTracks
                    album: myHeaderBarManager.album
                    title: myHeaderBarManager.title
                    artist: myHeaderBarManager.artist
                    image: myHeaderBarManager.image
225

226
                    ratingVisible: false
227

Alexander Stippich's avatar
Alexander Stippich committed
228 229
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
230

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

Diego Gangl's avatar
Diego Gangl committed
239 240 241
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

Alexander Stippich's avatar
Alexander Stippich committed
244 245
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
246 247
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
248

249
                    TrackImportNotification {
250 251 252 253
                        id: importedTracksCountNotification

                        anchors
                        {
Diego Gangl's avatar
Diego Gangl committed
254 255 256 257
                            right: headerBar.right
                            top: headerBar.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 1.75
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
258
                        }
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                    }

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

285
                        active: elisa.musicManager !== undefined
286
                    }
287
                }
288
            }
289

290 291
            ContentView {
                id: contentView
292
                Layout.fillHeight: true
293
                Layout.fillWidth: true
294
            }
295 296
        }
    }
297 298 299 300 301

    Component.onCompleted:
    {
        elisa.initialize()

Diego Gangl's avatar
Diego Gangl committed
302 303 304
        elisa.mediaPlayList.randomPlay = Qt.binding(function() { return headerBar.playerControl.shuffle })
        elisa.mediaPlayList.repeatPlay = Qt.binding(function() { return headerBar.playerControl.repeat })
        myPlayControlManager.randomOrContinuePlay = Qt.binding(function() { return headerBar.playerControl.shuffle || headerBar.playerControl.repeat })
Alexander Stippich's avatar
Alexander Stippich committed
305 306
        myPlayControlManager.playListModel = Qt.binding(function() { return elisa.mediaPlayList })
        myPlayControlManager.currentTrack = Qt.binding(function() { return elisa.mediaPlayList.currentTrack })
307

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

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

        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
320 321

        mprisloader.active = true
322
    }
323
}