ElisaMainWindow.qml 9.59 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
            playListModel: elisa.mediaPlayList
            audioPlayerManager: elisa.audioControl
            player: elisa.audioPlayer
137 138 139
            headerBarManager: elisa.manageHeaderBar
            manageMediaPlayerControl: elisa.playerControl
            onRaisePlayer: {
Alexander Stippich's avatar
Alexander Stippich committed
140 141 142 143
                mainWindow.show()
                mainWindow.raise()
                mainWindow.requestActivate()
            }
144

145
        }
146 147
    }

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

Alexander Stippich's avatar
Alexander Stippich committed
154
    Connections {
155
        target: elisa.mediaPlayList
156

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

162 163 164 165
    PassiveNotification {
        id: messageNotification
    }

166
    Rectangle {
167
        color: myPalette.base
168 169
        anchors.fill: parent

170 171 172
        ColumnLayout {
            anchors.fill: parent
            spacing: 0
173

174 175 176 177
            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
178
                Layout.fillWidth: true
179

180 181
                HeaderBar {
                    id: headerBar
182

183 184
                    focus: true

185
                    anchors.fill: parent
186

187 188 189 190 191
                    tracksCount: elisa.manageHeaderBar.remainingTracks
                    album: elisa.manageHeaderBar.album
                    title: elisa.manageHeaderBar.title
                    artist: elisa.manageHeaderBar.artist
                    image: elisa.manageHeaderBar.image
192

193
                    ratingVisible: false
194

Alexander Stippich's avatar
Alexander Stippich committed
195 196
                    playerControl.duration: elisa.audioPlayer.duration
                    playerControl.seekable: elisa.audioPlayer.seekable
197

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

Diego Gangl's avatar
Diego Gangl committed
206 207 208
                    playerControl.repeat: persistentSettings.playControlItemRepeat
                    playerControl.shuffle: persistentSettings.playControlItemShuffle

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

Alexander Stippich's avatar
Alexander Stippich committed
211 212
                    playerControl.onPlay: elisa.audioControl.playPause()
                    playerControl.onPause: elisa.audioControl.playPause()
213 214
                    playerControl.onPlayPrevious: elisa.mediaPlayList.skipPreviousTrack()
                    playerControl.onPlayNext: elisa.mediaPlayList.skipNextTrack()
215

216
                    TrackImportNotification {
217 218 219 220
                        id: importedTracksCountNotification

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

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

252
                        active: elisa.musicManager !== undefined
253
                    }
254
                }
255
            }
256

257 258
            ContentView {
                id: contentView
259
                Layout.fillHeight: true
260
                Layout.fillWidth: true
261
            }
262 263
        }
    }
264 265 266 267 268

    Component.onCompleted:
    {
        elisa.initialize()

Alexander Stippich's avatar
Alexander Stippich committed
269 270 271
        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})
272

273 274 275
        if (persistentSettings.playListState) {
            elisa.mediaPlayList.persistentState = persistentSettings.playListState
        }
Diego Gangl's avatar
Diego Gangl committed
276

Alexander Stippich's avatar
Alexander Stippich committed
277 278 279
        if (persistentSettings.audioPlayerState) {
            elisa.audioControl.persistentState = persistentSettings.audioPlayerState
        }
Alexander Stippich's avatar
Alexander Stippich committed
280 281 282 283

        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
284
        mprisloader.active = true
285
    }
286
}