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