ApplicationPage.qml 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *   Copyright (C) 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library/Lesser General Public License
 *   version 2, or (at your option) any later version, as published by the
 *   Free Software Foundation
 *
 *   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 General Public License for more details
 *
 *   You should have received a copy of the GNU Library/Lesser General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

20
import QtQuick 2.5
21
import QtQuick.Controls 1.1
22
import QtQuick.Controls 2.1 as QQC2
23 24
import QtQuick.Window 2.1
import QtQuick.Layouts 1.1
25
import org.kde.kquickcontrolsaddons 2.0
26
import org.kde.discover 2.0
27
import org.kde.discover.app 1.0
28
import org.kde.kirigami 2.1 as Kirigami
29
import "navigation.js" as Navigation
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
30

31
DiscoverPage {
32 33 34
    id: appInfo
    property QtObject application: null
    clip: true
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
35

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
36 37
    title: application.name

38 39
    background: Rectangle { color: Kirigami.Theme.viewBackgroundColor }

40 41
    ReviewsPage {
        id: reviewsSheet
42 43 44
        model: ReviewsModel {
            id: reviewsModel
            resource: appInfo.application
45 46 47
        }
    }

48 49 50 51
    Kirigami.OverlaySheet {
        id: originsOverlay
        bottomPadding: Kirigami.Units.largeSpacing
        topPadding: Kirigami.Units.largeSpacing
52
        readonly property alias model: alternativeResourcesView.model
53 54 55
        function listBackends() {
            var first = true;
            var ret = "";
56
            var m = alternativeResourcesView.model;
57 58 59 60 61 62 63
            for(var i=0, count=m.rowCount(); i<count; ++i) {
                var res = m.resourceAt(i)
                if (res != appInfo.application) {
                    if (!first) {
                        ret += ", "
                    }
                    ret += "<a href='" + i + "'>" + res.displayOrigin + "</a>"
64
                    first = false
65 66 67 68
                }
            }
            return ret
        }
69
        readonly property string sentence: alternativeResourcesView.count <= 1 ? "" : i18n("\nAlso available in %1", listBackends())
70
        ListView {
71
            id: alternativeResourcesView
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            model: ResourcesProxyModel {
                allBackends: true
                resourcesUrl: appInfo.application.url
            }
            delegate: Kirigami.BasicListItem {
                label: displayOrigin
                checked: appInfo.application == model.application
                onClicked: if(index>=0) {
                    var res = model.application
                    console.assert(res)
                    window.stack.pop()
                    Navigation.openApplication(res)
                }
            }
        }
    }

89 90 91 92 93
    header: QQC2.ToolBar {
        anchors {
            right: parent.right
            left: parent.left
        }
94

95 96
        contentItem: RowLayout {
            spacing: Kirigami.Units.smallSpacing
97

98
            ToolButton {
99
                Layout.leftMargin: Kirigami.Units.smallSpacing
100 101 102 103 104 105 106 107 108
                iconName: "draw-arrow-back"
                tooltip: i18n("Back")
                enabled: appInfo.sClose.enabled
                onClicked: appInfo.sClose.activated()
            }
            Item {
                Layout.fillWidth: true
            }
            Kirigami.Icon {
109 110
                Layout.preferredHeight: parent.implicitHeight
                Layout.preferredWidth: Layout.preferredHeight
111

112 113 114 115 116 117 118 119 120 121 122 123 124 125
                source: appInfo.application.icon
                Layout.alignment: Qt.AlignVCenter
            }
            Kirigami.Heading {
                level: 3
                Layout.maximumWidth: parent.width/2
                text: appInfo.application.name
                maximumLineCount: 1
                elide: Text.ElideRight
                horizontalAlignment: Text.AlignHCenter
            }
            Item {
                Layout.fillWidth: true
            }
126

127 128 129 130 131
            Binding {
                target: appInfo.actions
                property: "main"
                value: appbutton.action
            }
132

133 134
            InstallApplicationButton {
                id: appbutton
135
                Layout.rightMargin: Kirigami.Units.smallSpacing
136 137 138
                application: appInfo.application
                visible: applicationWindow().wideScreen
            }
139

140
            Button {
141
                Layout.rightMargin: Kirigami.Units.smallSpacing
142 143 144
                visible: application.isInstalled && application.canExecute
                text: i18n("Launch")
                onClicked: application.invokeApplication()
145
            }
146
        }
147
    }
148

149 150
    ColumnLayout {
        spacing: 0
151
        Kirigami.Heading {
152
            text: appInfo.application.comment
153
            level: 4
154 155
            Layout.fillWidth: true
            elide: Text.ElideRight
156
            bottomPadding: Kirigami.Units.largeSpacing
157
        }
158

159 160 161 162 163
        GridLayout {
            rowSpacing: 0
            columns: 2

            // Category row
164
            QQC2.Label {
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
                Layout.alignment: Qt.AlignRight
                text: i18n("Category:")
            }
            QQC2.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                text: appInfo.application.categoryDisplay
            }

            // Version row
            QQC2.Label {
                readonly property string version: appInfo.application.isInstalled ? appInfo.application.installedVersion : appInfo.application.availableVersion
                visible: version.length > 0
                Layout.alignment: Qt.AlignRight
                text: i18n("Version:")
            }
            QQC2.Label {
                readonly property string version: appInfo.application.isInstalled ? appInfo.application.installedVersion : appInfo.application.availableVersion
                visible: version.length > 0
                Layout.fillWidth: true
                elide: Text.ElideRight
                text: version ? version : ""
            }

            // Size row
            QQC2.Label {
                Layout.alignment: Qt.AlignRight
                text: i18n("Size:")
            }
            QQC2.Label {
                Layout.fillWidth: true
                elide: Text.ElideRight
                text: i18n("%1", appInfo.application.sizeDescription)
            }

            // Source row
            QQC2.Label {
                Layout.alignment: Qt.AlignRight
203
                text: i18n("Source:")
204
            }
205
            LinkButton {
206
                Layout.fillWidth: true
207
                horizontalAlignment: Text.AlignLeft
208 209
                enabled: alternativeResourcesView.count > 1
                text: appInfo.application.displayOrigin
210
                elide: Text.ElideRight
211
                onClicked: originsOverlay.open()
212
            }
213 214

            // License row
215
            QQC2.Label {
216
                Layout.alignment: Qt.AlignRight
217
                text: i18n("License:")
218
            }
219
            LinkButton {
220
                elide: Text.ElideRight
221 222
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignLeft
223
                text: appInfo.application.license
224
//                         tooltip: i18n("See full license terms")
225
                onClicked: Qt.openUrlExternally("https://spdx.org/licenses/" + appInfo.application.license + ".html#licenseText")
226
            }
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

            // Homepage row
            QQC2.Label {
                readonly property string homepage: application.homepage
                visible: homepage.length > 0
                Layout.alignment: Qt.AlignRight
                text: i18n("Homepage:")
            }
            LinkButton {
                readonly property string homepage: application.homepage
                visible: homepage.length > 0
                text: homepage
                onClicked: Qt.openUrlExternally(application.homepage)
                elide: Text.ElideRight
                Layout.fillWidth: true
                horizontalAlignment: Text.AlignLeft
            }
244
        }
245

246 247 248 249 250 251
        ApplicationScreenshots {
            Layout.topMargin: Kirigami.Units.largeSpacing
            Layout.fillWidth: true
            resource: appInfo.application
            page: appInfo
        }
252

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
        Kirigami.Heading {
            level: 3
            Layout.topMargin: Kirigami.Units.largeSpacing
            text: i18n("Description")
            Layout.fillWidth: true
            visible: appInfo.application.longDescription.length > 0
        }
        QQC2.Label {
            Layout.fillWidth: true
            horizontalAlignment: Text.AlignJustify
            wrapMode: Text.WordWrap
            text: appInfo.application.longDescription + originsOverlay.sentence
            onLinkActivated: {
                var idx = parseInt(link, 10)
                var res = originsOverlay.model.resourceAt(idx)
                window.stack.pop()
                Navigation.openApplication(res)
270
            }
271
        }
272

273 274 275 276 277 278
        LinkButton {
            id: addonsButton
            text: i18n("Addons")
            visible: addonsView.containsAddons
            onClicked: addonsView.sheetOpen = true
        }
279

280 281 282
        LinkButton {
            text: i18n("Review")
            onClicked: reviewsSheet.openReviewDialog()
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
283
            visible: !commentsButton.visible && reviewsModel.backend && reviewsModel.backend.isResourceSupported(appInfo.application)
284 285 286 287 288 289
        }
        LinkButton {
            id: commentsButton
            readonly property QtObject rating: appInfo.application.rating
            visible: rating && rating.ratingCount>0 && reviewsModel.count
            text: i18n("Show reviews (%1)...", rating ? reviewsModel.count : 0)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
290

291 292
            onClicked: {
                reviewsSheet.open()
293
            }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
294
        }
295 296 297 298 299

        Item {
            height: addonsButton.height
            width: 5
        }
300
    }
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
301

302 303 304 305 306
    readonly property var addons: AddonsView {
        id: addonsView
        application: appInfo.application
        parent: overlay
    }
Jonathan Thomas's avatar
Jonathan Thomas committed
307
}