Warning, /multimedia/elisa/src/qml/AbstractDataView.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2018 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr> 0003 SPDX-FileCopyrightText: 2022 (c) Nate Graham <nate@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-3.0-or-later 0006 */ 0007 0008 import QtQuick 2.15 0009 import QtQuick.Controls 2.15 0010 import QtQml.Models 2.1 0011 import QtQuick.Layouts 1.2 0012 0013 import org.kde.kirigami 2.12 as Kirigami 0014 import org.kde.elisa 1.0 0015 0016 FocusScope { 0017 id: abstractView 0018 0019 // Subclasses must set these 0020 property alias delegate: delegateModel.delegate 0021 property alias contentView: scrollView.contentItem 0022 0023 // Instances should set these as needed 0024 property AbstractItemModel realModel 0025 property AbstractProxyModel proxyModel 0026 property var modelType 0027 property var filterType 0028 property var filter 0029 property string mainTitle 0030 property string secondaryTitle 0031 property url image 0032 property bool sortModel: true 0033 property bool isSubPage: false 0034 property bool modelIsInitialized: false 0035 property bool allowArtistNavigation: false 0036 property bool showCreateRadioButton: false 0037 property bool showEnqueueButton: false 0038 property bool displaySingleAlbum: false 0039 property alias showRating: navigationBar.showRating 0040 property alias sortRole: navigationBar.sortRole 0041 property alias sortRoles: navigationBar.sortRoles 0042 property alias sortRoleNames: navigationBar.sortRoleNames 0043 property alias sortOrderNames: navigationBar.sortOrderNames 0044 property alias sortOrder: navigationBar.sortOrder 0045 property alias viewManager: navigationBar.viewManager 0046 property alias expandedFilterView: navigationBar.expandedFilterView 0047 0048 // Inner items exposed to subclasses for various purposes 0049 readonly property alias delegateModel: delegateModel 0050 readonly property alias navigationBar: navigationBar 0051 readonly property int viewWidth: scrollView.width - scrollView.scrollBarWidth 0052 0053 // Other properties 0054 property AbstractProxyModel contentModel 0055 property int depth: 1 0056 0057 focus: true 0058 0059 Accessible.role: Accessible.Pane 0060 Accessible.name: mainTitle 0061 0062 function initializeModel() { 0063 if (!proxyModel) { 0064 return 0065 } 0066 0067 if (!realModel) { 0068 return 0069 } 0070 0071 if (!ElisaApplication.musicManager) { 0072 return 0073 } 0074 0075 if (modelIsInitialized) { 0076 return 0077 } 0078 0079 proxyModel.sourceModel = realModel 0080 proxyModel.dataType = modelType 0081 proxyModel.playList = Qt.binding(() => ElisaApplication.mediaPlayListProxyModel) 0082 abstractView.contentModel = proxyModel 0083 0084 if (sortModel) { 0085 proxyModel.sortModel(sortOrder) 0086 } 0087 0088 realModel.initializeByData(ElisaApplication.musicManager, ElisaApplication.musicManager.viewDatabase, 0089 modelType, filterType, filter) 0090 0091 modelIsInitialized = true 0092 } 0093 0094 // Model 0095 DelegateModel { 0096 id: delegateModel 0097 model: abstractView.contentModel 0098 } 0099 0100 // Main view components 0101 ColumnLayout { 0102 anchors.fill: parent 0103 spacing: 0 0104 0105 NavigationActionBar { 0106 id: navigationBar 0107 0108 z: 1 // on top of track list 0109 0110 mainTitle: abstractView.mainTitle 0111 secondaryTitle: abstractView.secondaryTitle 0112 image: abstractView.image 0113 enableSorting: abstractView.sortModel 0114 enableGoBack: abstractView.isSubPage || abstractView.depth > 1 0115 allowArtistNavigation: abstractView.isSubPage 0116 showCreateRadioButton: abstractView.modelType === ElisaUtils.Radio 0117 showEnqueueButton: abstractView.modelType !== ElisaUtils.Radio 0118 0119 Layout.fillWidth: true 0120 0121 Binding { 0122 target: abstractView.contentModel 0123 property: "filterText" 0124 when: abstractView.contentModel 0125 value: navigationBar.filterText 0126 } 0127 0128 Binding { 0129 target: abstractView.contentModel 0130 property: "filterRating" 0131 when: abstractView.contentModel 0132 value: navigationBar.filterRating 0133 } 0134 0135 Binding { 0136 target: abstractView.contentModel 0137 property: "sortRole" 0138 when: abstractView.contentModel && navigationBar.enableSorting 0139 value: navigationBar.sortRole 0140 } 0141 0142 onEnqueue: contentModel.enqueueToPlayList(delegateModel.rootIndex) 0143 0144 onReplaceAndPlay: contentModel.replaceAndPlayOfPlayList(delegateModel.rootIndex) 0145 0146 onGoBack: abstractView.viewManager.goBack() 0147 0148 onSortOrderChanged: { 0149 if (!contentModel || !navigationBar.enableSorting) { 0150 return 0151 } 0152 0153 if ((contentModel.sortedAscending && sortOrder !== Qt.AscendingOrder) || 0154 (!contentModel.sortedAscending && sortOrder !== Qt.DescendingOrder)) { 0155 contentModel.sortModel(sortOrder) 0156 } 0157 } 0158 } 0159 0160 ScrollView { 0161 id: scrollView 0162 0163 readonly property int scrollBarWidth: ScrollBar.vertical.visible ? ScrollBar.vertical.width : 0 0164 0165 Layout.fillHeight: true 0166 Layout.fillWidth: true 0167 0168 // HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890 0169 ScrollBar.horizontal.policy: ScrollBar.AlwaysOff 0170 0171 // Content view goes here, set as the contentItem: property 0172 } 0173 } 0174 0175 // Loading spinner 0176 Loader { 0177 id: busyIndicatorLoader 0178 anchors.centerIn: parent 0179 height: Kirigami.Units.gridUnit * 5 0180 width: height 0181 0182 active: realModel ? realModel.isBusy : true 0183 visible: active && status === Loader.Ready 0184 0185 sourceComponent: BusyIndicator { 0186 anchors.centerIn: parent 0187 } 0188 } 0189 0190 // "Nothing here" placeholder message 0191 Loader { 0192 anchors.centerIn: parent 0193 anchors.verticalCenterOffset: Math.round(navigationBar.height / 2) 0194 width: parent.width - (Kirigami.Units.largeSpacing * 4) 0195 active: contentDirectoryView.count === 0 && !busyIndicatorLoader.active 0196 visible: active && status === Loader.Ready 0197 0198 sourceComponent: Kirigami.PlaceholderMessage { 0199 anchors.centerIn: parent 0200 icon.name: "edit-none" 0201 text: navigationBar.filterText.length > 0 ? i18nc("@info:placeholder", "No matches") : i18nc("@info:placeholder", "Nothing to display") 0202 } 0203 } 0204 0205 Connections { 0206 target: ElisaApplication 0207 0208 function onMusicManagerChanged() { 0209 abstractView.initializeModel() 0210 } 0211 } 0212 0213 Component.onCompleted: { 0214 initializeModel() 0215 } 0216 }