DataListView.qml 8.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright 2018 Matthieu Gallien <matthieu_gallien@yahoo.fr>
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.10
import QtQuick.Controls 2.3
20
import org.kde.kirigami 2.5 as Kirigami
21
22
import org.kde.elisa 1.0

23
FocusScope {
24
    id: viewHeader
25

26
    property var viewType
27
28
    property var filterType
    property alias isSubPage: listView.isSubPage
29
    property alias mainTitle: listView.mainTitle
30
31
    property alias secondaryTitle: listView.secondaryTitle
    property int databaseId
32
    property alias showSection: listView.showSection
33
    property alias expandedFilterView: listView.expandedFilterView
34
    property alias image: listView.image
35
    property var modelType
36
    property alias sortRole: proxyModel.sortRole
37
    property var sortAscending
38
    property bool displaySingleAlbum: false
Jerome Guidon's avatar
Jerome Guidon committed
39
40
    property alias radioCase: listView.showCreateRadioButton

Matthieu Gallien's avatar
Matthieu Gallien committed
41
    function openMetaDataView(databaseId, url) {
42
43
44
45
        if (viewHeader.radioCase) {
            metadataLoader.setSource("MediaTrackMetadataView.qml",
                                     {
                                         "initialDatabaseId": databaseId,
Matthieu Gallien's avatar
Matthieu Gallien committed
46
47
                                         "fileName": url,
                                         "modelType": viewHeader.modelType,
48
49
50
51
52
53
54
55
56
57
                                         "showImage": false,
                                         "showTrackFileName": false,
                                         "showDeleteButton": databaseId !== -1,
                                         "showApplyButton": true,
                                         "editableMetadata": true,
                                     });
        } else {
            metadataLoader.setSource("MediaTrackMetadataView.qml",
                                     {
                                         "initialDatabaseId": databaseId,
Matthieu Gallien's avatar
Matthieu Gallien committed
58
59
                                         "fileName": url,
                                         "modelType": viewHeader.modelType,
60
61
62
63
64
65
66
                                         "showImage": true,
                                         "showTrackFileName": true,
                                         "showDeleteButton": false,
                                         "showApplyButton": false,
                                         "editableMetadata": false,
                                     });
        }
Jerome Guidon's avatar
Jerome Guidon committed
67
68
        metadataLoader.active = true
    }
69

70
    DataModel {
71
72
73
74
75
76
77
        id: realModel
    }

    AllTracksProxyModel {
        id: proxyModel

        sourceModel: realModel
78
        playList: elisa.mediaPlayList
79
80
    }

Jerome Guidon's avatar
Jerome Guidon committed
81
82
83
84
85
86
    Loader {
        id: metadataLoader
        active: false
        onLoaded: item.show()
    }

87
    Component {
88
        id: albumDelegate
89

Alexander Stippich's avatar
Alexander Stippich committed
90
        ListBrowserDelegate {
91
            id: entry
92

93
            width: listView.delegateWidth
94
            height: elisaTheme.delegateHeight
95

96
97
98
            focus: true

            databaseId: model.databaseId
99
100
101
102
            title: model.title ? model.title : ''
            artist: model.artist ? model.artist : ''
            album: model.album ? model.album : ''
            albumArtist: model.albumArtist ? model.albumArtist : ''
Jerome Guidon's avatar
Jerome Guidon committed
103
            duration: model.duration ? model.duration : ''
104
105
106
            imageUrl: model.imageUrl ? model.imageUrl : ''
            trackNumber: model.trackNumber ? model.trackNumber : -1
            discNumber: model.discNumber ? model.discNumber : -1
107
108
109
            rating: model.rating
            isSelected: listView.currentIndex === index
            isAlternateColor: (index % 2) === 1
Alexander Stippich's avatar
Alexander Stippich committed
110
            detailedView: false
111

Alexander Stippich's avatar
Alexander Stippich committed
112
            onEnqueue: elisa.mediaPlayList.enqueue(databaseId, name, ElisaUtils.Track,
113
114
                                                              ElisaUtils.AppendPlayList,
                                                              ElisaUtils.DoNotTriggerPlay)
115

Alexander Stippich's avatar
Alexander Stippich committed
116
            onReplaceAndPlay: elisa.mediaPlayList.enqueue(databaseId, name, ElisaUtils.Track,
117
118
119
120
                                                                     ElisaUtils.ReplacePlayList,
                                                                     ElisaUtils.TriggerPlay)


Alexander Stippich's avatar
Alexander Stippich committed
121
            onClicked: listView.currentIndex = index
122
123
124
125
126
127

            onActiveFocusChanged: {
                if (activeFocus && listView.currentIndex !== index) {
                    listView.currentIndex = index
                }
            }
Jerome Guidon's avatar
Jerome Guidon committed
128
129

            onCallOpenMetaDataView: {
Matthieu Gallien's avatar
Matthieu Gallien committed
130
                openMetaDataView(databaseId, model.url)
Jerome Guidon's avatar
Jerome Guidon committed
131
            }
132
133
134
135
        }
    }

    Component {
136
        id: detailedTrackDelegate
137

Alexander Stippich's avatar
Alexander Stippich committed
138
        ListBrowserDelegate {
139
140
            id: entry

141
            width: listView.delegateWidth
142
143
144
145
146
            height: elisaTheme.trackDelegateHeight

            focus: true

            databaseId: model.databaseId
147
148
149
150
            title: model.title ? model.title : ''
            artist: model.artist ? model.artist : ''
            album: model.album ? model.album : ''
            albumArtist: model.albumArtist ? model.albumArtist : ''
Jerome Guidon's avatar
Jerome Guidon committed
151
            duration: model.duration ? model.duration : ''
152
153
154
            imageUrl: model.imageUrl ? model.imageUrl : ''
            trackNumber: model.trackNumber ? model.trackNumber : -1
            discNumber: model.discNumber ? model.discNumber : -1
155
            rating: model.rating
156
            hideDiscNumber: model.isSingleDiscAlbum
157
158
            isSelected: listView.currentIndex === index
            isAlternateColor: (index % 2) === 1
159

160
            onEnqueue: elisa.mediaPlayList.enqueue(databaseId, name, modelType,
161
162
                                                   ElisaUtils.AppendPlayList,
                                                   ElisaUtils.DoNotTriggerPlay)
163

164
            onReplaceAndPlay: elisa.mediaPlayList.enqueue(databaseId, name, modelType,
165
166
                                                          ElisaUtils.ReplacePlayList,
                                                          ElisaUtils.TriggerPlay)
167

168
169
170
171
            onClicked: {
                listView.currentIndex = index
                entry.forceActiveFocus()
            }
Jerome Guidon's avatar
Jerome Guidon committed
172
173

            onCallOpenMetaDataView: {
Matthieu Gallien's avatar
Matthieu Gallien committed
174
                openMetaDataView(databaseId, model.url)
Jerome Guidon's avatar
Jerome Guidon committed
175
            }
176
        }
177
178
179
180
181
182
183
184
185
186
187
    }

    ListBrowserView {
        id: listView

        focus: true

        anchors.fill: parent

        contentModel: proxyModel

188
        delegate: (displaySingleAlbum ? albumDelegate : detailedTrackDelegate)
189

190
191
        enableSorting: !displaySingleAlbum

192
193
194
        allowArtistNavigation: isSubPage

        onShowArtist: {
195
            viewManager.openChildView(secondaryTitle, '', elisaTheme.artistIcon, 0, ElisaUtils.Artist, ViewManager.NoDiscHeaders)
196
197
198
199
        }

        onGoBack: viewManager.goBack()

200
        Loader {
201
202
203
            anchors.centerIn: parent
            height: Kirigami.Units.gridUnit * 5
            width: height
204
205
206
207
208

            visible: realModel.isBusy
            active: realModel.isBusy

            sourceComponent: BusyIndicator {
209
                anchors.centerIn: parent
210
211
            }
        }
212
    }
213
214
215
216

    Connections {
        target: elisa

217
218
219
        onMusicManagerChanged: realModel.initialize(elisa.musicManager,
                                                    elisa.musicManager.viewDatabase,
                                                    modelType)
220
221
    }

Jerome Guidon's avatar
Jerome Guidon committed
222
223
224
225
    Connections {
        target: listView.navigationBar

        onCreateRadio: {
Matthieu Gallien's avatar
Matthieu Gallien committed
226
            openMetaDataView(-1, '')
Jerome Guidon's avatar
Jerome Guidon committed
227
228
229
        }
    }

230
231
    Component.onCompleted: {
        if (elisa.musicManager) {
232
            realModel.initialize(elisa.musicManager, elisa.musicManager.viewDatabase, modelType, filterType, mainTitle, secondaryTitle, databaseId)
233
        }
234

235
        if (sortAscending === ViewManager.SortAscending) {
236
            proxyModel.sortModel(Qt.AscendingOrder)
237
        } else if (sortAscending === ViewManager.SortDescending) {
238
239
            proxyModel.sortModel(Qt.DescendingOrder)
        }
240
    }
241
}