Warning, /plasma/discover/discover/qml/DiscoverDrawer.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2015 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.5
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Controls 2.1
0010 import org.kde.discover 2.0
0011 import org.kde.discover.app 1.0
0012 import org.kde.kirigami 2.19 as Kirigami
0013 import "navigation.js" as Navigation
0014 
0015 Kirigami.GlobalDrawer {
0016     id: drawer
0017 
0018     leftPadding: 0
0019     rightPadding: 0
0020     topPadding: 0
0021     bottomPadding: 0
0022 
0023     // FIXME: Dirty workaround for 385992
0024     width: Kirigami.Units.gridUnit * 14
0025 
0026     property bool wideScreen: false
0027     readonly property real minimumHeight: header.implicitHeight + content.height + footer.implicitHeight
0028 
0029     resetMenuOnTriggered: false
0030 
0031     property string currentSearchText
0032 
0033     onCurrentSubMenuChanged: {
0034         if (currentSubMenu)
0035             currentSubMenu.trigger()
0036         else if (currentSearchText.length > 0)
0037             window.leftPage.category = null
0038         else
0039             Navigation.openHome()
0040     }
0041 
0042     function suggestSearchText(text) {
0043         if (searchField.visible) {
0044             searchField.text = text
0045             forceSearchFieldFocus()
0046         }
0047     }
0048 
0049     function forceSearchFieldFocus() {
0050         if (searchField.visible && wideScreen) {
0051             searchField.forceActiveFocus();
0052         }
0053     }
0054 
0055     header: Kirigami.AbstractApplicationHeader {
0056         visible: drawer.wideScreen
0057 
0058         contentItem: SearchField {
0059             id: searchField
0060 
0061             anchors {
0062                 left: parent.left
0063                 leftMargin: Kirigami.Units.smallSpacing
0064                 right: parent.right
0065                 rightMargin: Kirigami.Units.smallSpacing
0066             }
0067 
0068             // Give the search field keyboard focus by default, unless it would
0069             // make the virtual keyboard appear, because we don't want that
0070             focus: !Kirigami.InputMethod.willShowOnActive
0071 
0072             visible: window.leftPage && (window.leftPage.searchFor !== null || window.leftPage.hasOwnProperty("search"))
0073 
0074             page: window.leftPage
0075 
0076             onCurrentSearchTextChanged: {
0077                 var curr = window.leftPage;
0078 
0079                 if (pageStack.depth>1)
0080                     pageStack.pop()
0081 
0082                 if (currentSearchText === "" && window.currentTopLevel === "" && !window.leftPage.category) {
0083                     Navigation.openHome()
0084                 } else if (!curr.hasOwnProperty("search")) {
0085                     if (currentSearchText) {
0086                         Navigation.clearStack()
0087                         Navigation.openApplicationList( { search: currentSearchText })
0088                     }
0089                 } else {
0090                     curr.search = currentSearchText;
0091                     curr.forceActiveFocus()
0092                 }
0093             }
0094         }
0095     }
0096 
0097     ColumnLayout {
0098         spacing: 0
0099         Layout.fillWidth: true
0100 
0101         Kirigami.Separator {
0102             Layout.fillWidth: true
0103         }
0104 
0105         ProgressView {
0106             separatorVisible: false
0107         }
0108 
0109         ActionListItem {
0110             action: featuredAction
0111         }
0112         ActionListItem {
0113             action: searchAction
0114         }
0115         ActionListItem {
0116             action: installedAction
0117             visible: drawer.wideScreen
0118         }
0119         ActionListItem {
0120             action: sourcesAction
0121         }
0122 
0123         ActionListItem {
0124             action: aboutAction
0125         }
0126 
0127         ActionListItem {
0128             objectName: "updateButton"
0129             action: updateAction
0130             visible: drawer.wideScreen
0131 
0132             trailing: Kirigami.Icon {
0133                 visible: ResourcesModel.updatesCount > 0
0134                 width: Kirigami.Units.iconSizes.sizeForLabels
0135                 height: Kirigami.Units.iconSizes.sizeForLabels
0136                 source: "emblem-important"
0137             }
0138 
0139             // Disable down navigation on the last item so we don't escape the
0140             // actual list.
0141             Keys.onDownPressed: event.accepted = true
0142         }
0143 
0144         states: [
0145             State {
0146                 name: "full"
0147                 when: drawer.wideScreen
0148                 PropertyChanges { target: drawer; drawerOpen: true }
0149             },
0150             State {
0151                 name: "compact"
0152                 when: !drawer.wideScreen
0153                 PropertyChanges { target: drawer; drawerOpen: false }
0154             }
0155         ]
0156     }
0157 
0158     Component {
0159         id: categoryActionComponent
0160         Kirigami.Action {
0161             property QtObject category
0162             readonly property bool itsMe: window.leftPage && window.leftPage.hasOwnProperty("category") && (window.leftPage.category === category)
0163             text: category ? category.name : ""
0164             iconName: category ? category.icon : ""
0165             checked: itsMe
0166             visible: (!window.leftPage
0167                    || !window.leftPage.subcategories
0168                    || window.leftPage.subcategories === undefined
0169                    || currentSearchText.length === 0
0170                    || (category && category.contains(window.leftPage.subcategories))
0171                      )
0172             onTriggered: {
0173                 if (!window.leftPage.canNavigate)
0174                     Navigation.openCategory(category, currentSearchText)
0175                 else {
0176                     if (pageStack.depth>1)
0177                         pageStack.pop()
0178                     pageStack.currentIndex = 0
0179                     window.leftPage.category = category
0180                 }
0181 
0182                 if (!drawer.wideScreen && category.subcategories.length === 0) {
0183                     drawer.close();
0184                 }
0185             }
0186         }
0187     }
0188 
0189     function createCategoryActions(categories) {
0190         return categories.map((cat) => {
0191             return categoryActionComponent.createObject(drawer, {
0192                 category: cat,
0193                 children: createCategoryActions(cat.subcategories)
0194             });
0195         });
0196     }
0197 
0198     actions: createCategoryActions(CategoryModel.rootCategories)
0199 
0200     modal: !drawer.wideScreen
0201 }