Warning, /plasma/discover/discover/qml/ReviewsPage.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 pragma ComponentBehavior: Bound 0008 0009 import QtQuick 0010 import QtQuick.Controls as QQC2 0011 import QtQuick.Layouts 0012 import org.kde.discover as Discover 0013 import org.kde.discover.app as DiscoverApp 0014 import org.kde.kirigami as Kirigami 0015 import org.kde.kitemmodels as KItemModels 0016 0017 Kirigami.OverlaySheet { 0018 id: page 0019 0020 property Discover.ReviewsModel model 0021 property alias sortModel: sortModel 0022 property alias sortRole: sortModel.sortRoleName 0023 0024 readonly property Discover.AbstractReviewsBackend reviewsBackend: resource.backend.reviewsBackend 0025 readonly property Discover.AbstractResource resource: model.resource 0026 0027 readonly property ReviewDialog rd: ReviewDialog { 0028 id: reviewDialog 0029 0030 application: page.resource 0031 backend: page.reviewsBackend 0032 onAccepted: backend.submitReview(page.resource, summary, review, rating, name) 0033 } 0034 0035 function openReviewDialog() { 0036 visible = false 0037 reviewDialog.open() 0038 } 0039 0040 implicitWidth: Math.min(Kirigami.Units.gridUnit * 70, Math.max(Kirigami.Units.gridUnit * 30, parent.width * 0.8)) 0041 0042 header: GridLayout { 0043 id: headerLayout 0044 width: parent.width 0045 columnSpacing: Kirigami.Units.largeSpacing 0046 rowSpacing: columnSpacing 0047 rows: 2 0048 columns: 3 0049 0050 Kirigami.Heading { 0051 Layout.fillWidth: true 0052 Layout.columnSpan: 3 0053 wrapMode: Text.WordWrap 0054 text: i18n("Reviews for %1", page.resource.name) 0055 } 0056 0057 QQC2.Button { 0058 id: reviewButton 0059 0060 visible: page.reviewsBackend !== null 0061 enabled: page.resource.isInstalled 0062 text: i18n("Write a Review…") 0063 onClicked: page.openReviewDialog() 0064 } 0065 // This layout is intended as a mere container of messageLabel, don't put anything else in it 0066 RowLayout { 0067 id: inlineMessageParent 0068 spacing: Kirigami.Units.smallSpacing 0069 Layout.fillWidth: true 0070 QQC2.Label { 0071 id: messageLabel 0072 Layout.fillWidth: true 0073 parent: inlineMessageParent.width >= messageLabelMetrics.width ? inlineMessageParent : newlineMessageParent 0074 text: i18n("Install this app to write a review") 0075 wrapMode: Text.WordWrap 0076 visible: !reviewButton.enabled 0077 opacity: 0.6 0078 TextMetrics { 0079 id: messageLabelMetrics 0080 font: messageLabel.font 0081 text: messageLabel.text 0082 } 0083 } 0084 } 0085 0086 QQC2.ActionGroup { 0087 id: sortGroup 0088 exclusive: true 0089 } 0090 Kirigami.ActionToolBar { 0091 id: actionToolBar 0092 Layout.minimumWidth: implicitWidth + 1 0093 // This is to align it under the close button, some api for it could be good 0094 Layout.rightMargin: showCloseButton ? -Kirigami.Units.iconSizes.smallMedium : 0 0095 0096 alignment: Qt.AlignRight 0097 Layout.fillWidth: false 0098 actions: Kirigami.Action { 0099 text: i18n("Sort: %1", sortGroup.checkedAction.text) 0100 icon.name: "view-sort-symbolic" 0101 displayHint: Kirigami.DisplayHint.KeepVisible 0102 Kirigami.Action { 0103 text: i18nc("@label:listbox Most relevant reviews", "Most Relevant") 0104 QQC2.ActionGroup.group: sortGroup 0105 checkable: true 0106 checked: sortModel.sortRoleName === "wilsonScore" 0107 onTriggered: sortModel.sortRoleName = "wilsonScore" 0108 } 0109 Kirigami.Action { 0110 text: i18nc("@label:listbox Most recent reviews", "Most Recent") 0111 QQC2.ActionGroup.group: sortGroup 0112 checkable: true 0113 checked: sortModel.sortRoleName === "date" 0114 onTriggered: sortModel.sortRoleName = "date" 0115 } 0116 Kirigami.Action { 0117 text: i18nc("@label:listbox Reviews with the highest ratings", "Highest Ratings") 0118 QQC2.ActionGroup.group: sortGroup 0119 checkable: true 0120 checked: sortModel.sortRoleName === "rating" 0121 onTriggered: sortModel.sortRoleName = "rating" 0122 } 0123 } 0124 } 0125 // This layout is intended as a mere container of messageLabel, don't put anything else in it 0126 RowLayout { 0127 id: newlineMessageParent 0128 spacing: Kirigami.Units.smallSpacing 0129 Layout.fillWidth: true 0130 Layout.columnSpan: 3 0131 } 0132 } 0133 0134 ListView { 0135 id: reviewsView 0136 0137 model: KItemModels.KSortFilterProxyModel { 0138 id: sortModel 0139 sourceModel: page.model 0140 filterRoleName: "shouldShow" 0141 filterRowCallback: (sourceRow, sourceParent) => { 0142 return sourceModel.data(sourceModel.index(sourceRow, 0, sourceParent), filterRole) === true; 0143 } 0144 // need to do it afterwads as direct binding won't work, because at startup sortRoleName will be empty 0145 onSortRoleNameChanged: sortOrder = Qt.DescendingOrder 0146 } 0147 clip: true 0148 topMargin: Kirigami.Units.largeSpacing 0149 leftMargin: Kirigami.Units.largeSpacing 0150 rightMargin: Kirigami.Units.largeSpacing 0151 bottomMargin: Kirigami.Units.largeSpacing 0152 spacing: Kirigami.Units.smallSpacing 0153 implicitWidth: Math.max(Kirigami.Units.gridUnit * 25, Math.round(page.parent.width / 2)) 0154 // Still preload some items to make the scrollbar behave better, but can't preload all the comments as some apps like Firefox have thousands of them which will freeze Discover for minutes 0155 cacheBuffer: height * 2 0156 reuseItems: true 0157 contentWidth: width - leftMargin - rightMargin 0158 0159 delegate: ReviewDelegate { 0160 required property int index 0161 0162 width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin 0163 separator: index !== ListView.view.count - 1 0164 onMarkUseful: useful => { 0165 page.model.markUseful(index, useful); 0166 } 0167 } 0168 } 0169 }