ElisaMainWindow.qml 12.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;
117
            persistentSettings.audioPlayerState = manageAudioPlayer.persistentState
118

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

124 125
    PlatformIntegration {
        id: platformInterface
126

127 128
        playListModel: elisa.mediaPlayList
        playListControler: elisa.mediaPlayList
129 130 131
        audioPlayerManager: manageAudioPlayer
        headerBarManager: myHeaderBarManager
        manageMediaPlayerControl: myPlayControlManager
Alexander Stippich's avatar
Alexander Stippich committed
132
        player: elisa.audioPlayer
133 134 135

        onRaisePlayer:
        {
136
            mainWindow.show()
137 138 139
            mainWindow.raise()
            mainWindow.requestActivate()
        }
140 141
    }

Alexander Stippich's avatar
Alexander Stippich committed
142 143
    Connections {
        target: elisa.audioPlayer
144

145 146
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
147

148 149 150 151 152 153 154
        onPlaying: {
            myPlayControlManager.playerPlaying()
        }

        onPaused: {
            myPlayControlManager.playerPaused()
        }
155

156 157 158
        onStopped: {
            myPlayControlManager.playerStopped()
        }
159 160
    }

Alexander Stippich's avatar
Alexander Stippich committed
161
    Connections {
162
        target: elisa.mediaPlayList
163

Alexander Stippich's avatar
Alexander Stippich committed
164
        onPlayListLoadFailed: {
165 166
            messageNotification.showNotification(i18nc("message of passive notification when playlist load failed", "Load of playlist failed"), 3000)
        }
167

Alexander Stippich's avatar
Alexander Stippich committed
168
        onEnsurePlay: manageAudioPlayer.ensurePlay()
169

Alexander Stippich's avatar
Alexander Stippich committed
170
        onPlayListFinished: manageAudioPlayer.playListFinished()
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
    }

    ManageAudioPlayer {
        id: manageAudioPlayer

189 190
        currentTrack: elisa.mediaPlayList.currentTrack
        playListModel: elisa.mediaPlayList
191
        urlRole: MediaPlayList.ResourceRole
192
        isPlayingRole: MediaPlayList.IsPlayingRole
193 194 195
        titleRole: MediaPlayList.TitleRole
        artistNameRole: MediaPlayList.ArtistRole
        albumNameRole: MediaPlayList.AlbumRole
196

Alexander Stippich's avatar
Alexander Stippich committed
197 198 199 200 201 202
        playerStatus: elisa.audioPlayer.status
        playerPlaybackState: elisa.audioPlayer.playbackState
        playerError: elisa.audioPlayer.error
        audioDuration: elisa.audioPlayer.duration
        playerIsSeekable: elisa.audioPlayer.seekable
        playerPosition: elisa.audioPlayer.position
203

204
        persistentState: persistentSettings.audioPlayerState
205

Alexander Stippich's avatar
Alexander Stippich committed
206 207 208
        onPlayerPlay: elisa.audioPlayer.play()
        onPlayerPause: elisa.audioPlayer.pause()
        onPlayerStop: elisa.audioPlayer.stop()
209
        onSkipNextTrack: elisa.mediaPlayList.skipNextTrack()
Alexander Stippich's avatar
Alexander Stippich committed
210
        onSeek: elisa.audioPlayer.seek(position)
211 212
        onSourceInError:
        {
213
            elisa.mediaPlayList.trackInError(source, playerError)
214
            elisa.musicManager.playBackError(source, playerError)
215 216 217
        }

        onDisplayTrackError: messageNotification.showNotification(i18n("Error when playing %1", "" + fileName), 3000)
218 219 220 221 222
    }

    ManageMediaPlayerControl {
        id: myPlayControlManager

223 224
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
225 226
    }

227 228 229 230
    PassiveNotification {
        id: messageNotification
    }

231
    Rectangle {
232
        color: myPalette.base
233 234
        anchors.fill: parent

235 236 237
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
238

239 240 241 242
            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
243
                Layout.fillWidth: true
244

245 246
                HeaderBar {
                    id: headerBar
247

248 249
                    focus: true

250
                    anchors.fill: parent
251

252 253 254 255 256
                    tracksCount: myHeaderBarManager.remainingTracks
                    album: myHeaderBarManager.album
                    title: myHeaderBarManager.title
                    artist: myHeaderBarManager.artist
                    image: myHeaderBarManager.image
257

258
                    ratingVisible: false
259

Alexander Stippich's avatar
Alexander Stippich committed
260 261
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
262

263 264
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
265
                    playerControl.position: elisa.audioPlayer.position
266 267 268 269
                    playerControl.skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled
                    playerControl.playEnabled: myPlayControlManager.playControlEnabled
                    playerControl.isPlaying: myPlayControlManager.musicPlaying
270

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

273 274
                    playerControl.onPlay: manageAudioPlayer.playPause()
                    playerControl.onPause: manageAudioPlayer.playPause()
275

276 277
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
278

Alexander Stippich's avatar
Alexander Stippich committed
279
                    Controls1.ToolButton {
280
                        id: menuButton
281

282
                        action: applicationMenuAction
283

284
                        z: 2
285

286 287 288 289 290 291 292 293 294 295
                        anchors
                        {
                            right: parent.right
                            top: parent.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
                    }
                    Rectangle {
                        anchors.fill: menuButton
296

297
                        z: 1
298

299
                        radius: width / 2
300

301 302
                        color: myPalette.window
                    }
303

304
                    TrackImportNotification {
305 306 307 308 309 310 311 312 313
                        id: importedTracksCountNotification

                        anchors
                        {
                            right: menuButton.left
                            top: menuButton.top
                            bottom: menuButton.bottom
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
                    }

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

340
                        active: elisa.musicManager !== undefined
341
                    }
342
                }
343
            }
344

345 346
            ContentView {
                id: contentView
347
                Layout.fillHeight: true
348
                Layout.fillWidth: true
349
            }
350 351
        }
    }
352 353 354 355 356

    Component.onCompleted:
    {
        elisa.initialize()

357 358 359
        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 })
360

361 362 363 364
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }

Alexander Stippich's avatar
Alexander Stippich committed
365 366 367 368 369 370

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

        volume: headerBar.playerControl.volume
371
    }
372
}