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 import QtQuick 2.15
0008 import QtQuick.Controls 2.1
0009 import QtQuick.Layouts 1.1
0010 import org.kde.discover 2.0
0011 import org.kde.discover.app 1.0
0012 import org.kde.kirigami 2.14 as Kirigami
0013 
0014 Kirigami.OverlaySheet {
0015     id: page
0016     parent: applicationWindow().overlay
0017 
0018     property alias model: reviewsView.model
0019     readonly property QtObject reviewsBackend: resource.backend.reviewsBackend
0020     readonly property var resource: model.resource
0021 
0022     readonly property var rd: ReviewDialog {
0023         id: reviewDialog
0024 
0025         application: page.resource
0026         backend: page.reviewsBackend
0027         onAccepted: backend.submitReview(resource, summary, review, rating, name)
0028     }
0029 
0030     function openReviewDialog() {
0031         page.sheetOpen = false
0032         reviewDialog.open()
0033     }
0034 
0035     header: ColumnLayout {
0036         width: parent.width
0037         spacing: Kirigami.Units.largeSpacing
0038 
0039         Kirigami.Heading {
0040             Layout.fillWidth: true
0041             wrapMode: Text.WordWrap
0042             text: i18n("Reviews for %1", page.resource.name)
0043         }
0044 
0045         RowLayout {
0046             Layout.bottomMargin: Kirigami.Units.largeSpacing
0047 
0048             Button {
0049                 id: reviewButton
0050 
0051                 visible: page.reviewsBackend != null
0052                 enabled: page.resource.isInstalled
0053                 text: i18n("Write a Review…")
0054                 onClicked: page.openReviewDialog()
0055             }
0056             Label {
0057                 Layout.fillWidth: true
0058                 text: i18n("Install this app to write a review")
0059                 wrapMode: Text.WordWrap
0060                 visible: !reviewButton.enabled
0061                 opacity: 0.6
0062             }
0063 
0064         }
0065     }
0066 
0067     ListView {
0068         id: reviewsView
0069 
0070         clip: true
0071         topMargin: Kirigami.Units.largeSpacing
0072         leftMargin: Kirigami.Units.largeSpacing
0073         rightMargin: Kirigami.Units.largeSpacing
0074         bottomMargin: Kirigami.Units.largeSpacing
0075         spacing: Kirigami.Units.smallSpacing
0076         implicitWidth: Kirigami.Units.gridUnit * 25
0077         // 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
0078         cacheBuffer: height * 2
0079         reuseItems: true
0080 
0081         delegate: ReviewDelegate {
0082             width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
0083             separator: index !== ListView.view.count - 1
0084             onMarkUseful: page.model.markUseful(index, useful)
0085         }
0086     }
0087 }