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

Diego Gangl's avatar
Diego Gangl committed
33
    minimumWidth: contentView.showPlaylist ? 1100 : 700
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
            }
        }
    }
Diego Gangl's avatar
Diego Gangl committed
60 61

   Controls1.Action  {
62
        shortcut: goBackAction.shortcut
63
        onTriggered: contentView.goBack()
64 65
    }

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

    ApplicationMenu {
        id: applicationMenu
    }

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

82 83 84 85
    Theme {
        id: elisaTheme
    }

86
    Settings {
87 88 89 90
        id: persistentSettings

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

94
        property var playListState
95

96
        property var audioPlayerState
97

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

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

104
        property bool expandedFilterView: false
105

Diego Gangl's avatar
Diego Gangl committed
106
        property bool showPlaylist: true
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 129
        }
    }

Alexander Stippich's avatar
Alexander Stippich committed
130 131 132
    Loader {
        id: mprisloader
        active: false
133

Alexander Stippich's avatar
Alexander Stippich committed
134 135
        sourceComponent:  PlatformIntegration {
            id: platformInterface
136

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

148
        }
149 150
    }

Alexander Stippich's avatar
Alexander Stippich committed
151 152
    Connections {
        target: elisa.audioPlayer
153 154
        onVolumeChanged: headerBar.playerControl.volume = elisa.audioPlayer.volume
        onMutedChanged: headerBar.playerControl.muted = elisa.audioPlayer.muted
155 156
    }

Alexander Stippich's avatar
Alexander Stippich committed
157
    Connections {
158
        target: elisa.mediaPlayList
159

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

165 166 167 168
    PassiveNotification {
        id: messageNotification
    }

169
    Rectangle {
170
        color: myPalette.base
171 172
        anchors.fill: parent

173 174 175
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
176

177 178 179 180
            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
181
                Layout.fillWidth: true
182

183 184
                HeaderBar {
                    id: headerBar
185

186 187
                    focus: true

188
                    anchors.fill: parent
189

190 191 192 193 194
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
195

196
                    ratingVisible: false
197

Alexander Stippich's avatar
Alexander Stippich committed
198 199
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
200

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

Diego Gangl's avatar
Diego Gangl committed
209 210 211
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

Alexander Stippich's avatar
Alexander Stippich committed
214 215
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
216 217
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
218

219
                    TrackImportNotification {
220 221 222 223
                        id: importedTracksCountNotification

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

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

255
                        active: elisa.musicManager !== undefined
256
                    }
257
                }
258
            }
259

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

    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
273 274 275
        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})
276

277 278 279
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
280

Alexander Stippich's avatar
Alexander Stippich committed
281 282 283
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
284 285 286 287

        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
288
        mprisloader.active = true
289
    }
290
}