ElisaMainWindow.qml 11.7 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

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

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

    ApplicationMenu {
        id: applicationMenu
    }

64 65 66 67 68
    SystemPalette {
        id: myPalette
        colorGroup: SystemPalette.Active
    }

69 70 71 72
    Theme {
        id: elisaTheme
    }

73
    Settings {
74 75 76 77
        id: persistentSettings

        property int x
        property int y
78
        property int width : 1100
79
        property int height : 600
80

81
        property var playListState
82 83

        property var playListControlerState
84 85

        property var audioPlayerState
86

87
        property double playControlItemVolume : 100.0
88
        property bool playControlItemMuted : false
89 90 91 92

        property string filterState

   }
93

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

103 104
            persistentSettings.playListState = elisa.mediaPlayList.persistentState;
            persistentSettings.playListControlerState = elisa.mediaPlayList.persistentState;
105
            persistentSettings.audioPlayerState = manageAudioPlayer.persistentState
106

107 108
            persistentSettings.playControlItemVolume = headerBar.playerControl.volume
            persistentSettings.playControlItemMuted = headerBar.playerControl.muted
109 110 111
        }
    }

112 113
    PlatformIntegration {
        id: platformInterface
114

115 116
        playListModel: elisa.mediaPlayList
        playListControler: elisa.mediaPlayList
117 118 119
        audioPlayerManager: manageAudioPlayer
        headerBarManager: myHeaderBarManager
        manageMediaPlayerControl: myPlayControlManager
Alexander Stippich's avatar
Alexander Stippich committed
120
        player: elisa.audioPlayer
121 122 123

        onRaisePlayer:
        {
124
            mainWindow.show()
125 126 127
            mainWindow.raise()
            mainWindow.requestActivate()
        }
128 129
    }

Alexander Stippich's avatar
Alexander Stippich committed
130 131
    Connections {
        target: elisa.audioPlayer
132

133 134
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
135

136 137 138 139 140 141 142
        onPlaying: {
            myPlayControlManager.playerPlaying()
        }

        onPaused: {
            myPlayControlManager.playerPaused()
        }
143

144 145 146
        onStopped: {
            myPlayControlManager.playerStopped()
        }
147 148
    }

Alexander Stippich's avatar
Alexander Stippich committed
149
    Connections {
150
        target: elisa.mediaPlayList
151

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

Alexander Stippich's avatar
Alexander Stippich committed
156
        onEnsurePlay: manageAudioPlayer.ensurePlay()
157

Alexander Stippich's avatar
Alexander Stippich committed
158
        onPlayListFinished: manageAudioPlayer.playListFinished()
159 160
    }

161 162 163
    ManageHeaderBar {
        id: myHeaderBarManager

164 165
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
166

167 168 169 170
        artistRole: MediaPlayList.ArtistRole
        titleRole: MediaPlayList.TitleRole
        albumRole: MediaPlayList.AlbumRole
        imageRole: MediaPlayList.ImageRole
171
        isValidRole: MediaPlayList.IsValidRole
172 173 174 175 176
    }

    ManageAudioPlayer {
        id: manageAudioPlayer

177 178
        currentTrack: elisa.mediaPlayList.currentTrack
        playListModel: elisa.mediaPlayList
179
        urlRole: MediaPlayList.ResourceRole
180
        isPlayingRole: MediaPlayList.IsPlayingRole
181 182 183
        titleRole: MediaPlayList.TitleRole
        artistNameRole: MediaPlayList.ArtistRole
        albumNameRole: MediaPlayList.AlbumRole
184

Alexander Stippich's avatar
Alexander Stippich committed
185 186 187 188 189 190
        playerStatus: elisa.audioPlayer.status
        playerPlaybackState: elisa.audioPlayer.playbackState
        playerError: elisa.audioPlayer.error
        audioDuration: elisa.audioPlayer.duration
        playerIsSeekable: elisa.audioPlayer.seekable
        playerPosition: elisa.audioPlayer.position
191

192
        persistentState: persistentSettings.audioPlayerState
193

Alexander Stippich's avatar
Alexander Stippich committed
194 195 196
        onPlayerPlay: elisa.audioPlayer.play()
        onPlayerPause: elisa.audioPlayer.pause()
        onPlayerStop: elisa.audioPlayer.stop()
197
        onSkipNextTrack: elisa.mediaPlayList.skipNextTrack()
Alexander Stippich's avatar
Alexander Stippich committed
198
        onSeek: elisa.audioPlayer.seek(position)
199 200
        onSourceInError:
        {
201
            elisa.mediaPlayList.trackInError(source, playerError)
202
            elisa.musicManager.playBackError(source, playerError)
203 204 205
        }

        onDisplayTrackError: messageNotification.showNotification(i18n("Error when playing %1", "" + fileName), 3000)
206 207 208 209 210
    }

    ManageMediaPlayerControl {
        id: myPlayControlManager

211 212
        playListModel: elisa.mediaPlayList
        currentTrack: elisa.mediaPlayList.currentTrack
213 214
    }

215 216 217 218
    PassiveNotification {
        id: messageNotification
    }

219
    Rectangle {
220
        color: myPalette.base
221 222
        anchors.fill: parent

223 224 225
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
226

227 228 229 230
            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
231
                Layout.fillWidth: true
232

233 234
                HeaderBar {
                    id: headerBar
235

236 237
                    focus: true

238
                    anchors.fill: parent
239

240 241 242 243 244
                    tracksCount: myHeaderBarManager.remainingTracks
                    album: myHeaderBarManager.album
                    title: myHeaderBarManager.title
                    artist: myHeaderBarManager.artist
                    image: myHeaderBarManager.image
245

246
                    ratingVisible: false
247

Alexander Stippich's avatar
Alexander Stippich committed
248 249
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
250

251 252
                    playerControl.volume: persistentSettings.playControlItemVolume
                    playerControl.muted: persistentSettings.playControlItemMuted
Alexander Stippich's avatar
Alexander Stippich committed
253
                    playerControl.position: elisa.audioPlayer.position
254 255 256 257
                    playerControl.skipBackwardEnabled: myPlayControlManager.skipBackwardControlEnabled
                    playerControl.skipForwardEnabled: myPlayControlManager.skipForwardControlEnabled
                    playerControl.playEnabled: myPlayControlManager.playControlEnabled
                    playerControl.isPlaying: myPlayControlManager.musicPlaying
258

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

261 262
                    playerControl.onPlay: manageAudioPlayer.playPause()
                    playerControl.onPause: manageAudioPlayer.playPause()
263

264 265
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
266

Alexander Stippich's avatar
Alexander Stippich committed
267
                    Controls1.ToolButton {
268
                        id: menuButton
269

270
                        action: applicationMenuAction
271

272
                        z: 2
273

274 275 276 277 278 279 280 281 282 283
                        anchors
                        {
                            right: parent.right
                            top: parent.top
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                            topMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
                    }
                    Rectangle {
                        anchors.fill: menuButton
284

285
                        z: 1
286

287
                        radius: width / 2
288

289 290
                        color: myPalette.window
                    }
291

292
                    TrackImportNotification {
293 294 295 296 297 298 299 300 301
                        id: importedTracksCountNotification

                        anchors
                        {
                            right: menuButton.left
                            top: menuButton.top
                            bottom: menuButton.bottom
                            rightMargin: elisaTheme.layoutHorizontalMargin * 3
                        }
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
                    }

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

328
                        active: elisa.musicManager !== undefined
329
                    }
330
                }
331
            }
332

333 334
            ContentView {
                id: contentView
335
                Layout.fillHeight: true
336
                Layout.fillWidth: true
337
            }
338 339
        }
    }
340 341 342 343 344

    Component.onCompleted:
    {
        elisa.initialize()

345 346 347
        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 })
348

349 350 351 352
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }

Alexander Stippich's avatar
Alexander Stippich committed
353 354 355 356 357

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

358
        elisa.mediaPlayList.enqueue(elisa.arguments)
Alexander Stippich's avatar
Alexander Stippich committed
359
        volume: headerBar.playerControl.volume
360
    }
361
}