Warning, /plasma/plasma-systemmonitor/src/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> 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.12 0008 import QtQuick.Controls 2.12 0009 import QtQuick.Dialogs 1.3 0010 import QtQuick.Layouts 1.12 0011 import QtQuick.Window 2.12 0012 0013 import org.kde.kirigami 2.11 as Kirigami 0014 import org.kde.newstuff 1.81 as NewStuff 0015 0016 import org.kde.systemmonitor 1.0 0017 import org.kde.ksysguard.page 1.0 as Page 0018 0019 Kirigami.ApplicationWindow { 0020 id: app 0021 0022 minimumWidth: Kirigami.Units.gridUnit * 34 0023 minimumHeight: Kirigami.Units.gridUnit* 27 0024 0025 title: pageStack.currentItem.title 0026 0027 header: contentItem.GraphicsInfo.api === GraphicsInfo.Software ? degradedWarning.createObject(app) : null 0028 0029 Loader { 0030 active: !Kirigami.Settings.isMobile 0031 source: Qt.resolvedUrl("qrc:/GlobalMenu.qml") 0032 } 0033 0034 Kirigami.PagePool { 0035 id: pagePoolObject 0036 } 0037 0038 globalDrawer: Kirigami.GlobalDrawer { 0039 id: globalDrawer 0040 0041 handleVisible: false 0042 modal: false 0043 width: collapsed ? globalToolBar.Layout.minimumWidth + Kirigami.Units.smallSpacing : Kirigami.Units.gridUnit * 10 0044 Behavior on width { NumberAnimation { duration: Kirigami.Units.longDuration; easing.type: Easing.InOutQuad } } 0045 showHeaderWhenCollapsed: true 0046 0047 Kirigami.Theme.colorSet: Kirigami.Theme.View 0048 0049 header: ToolBar { 0050 Layout.fillWidth: true 0051 Layout.preferredHeight: app.pageStack.globalToolBar.preferredHeight 0052 0053 leftPadding: globalDrawer.collapsed ? 0 : Kirigami.Units.smallSpacing 0054 rightPadding: globalDrawer.collapsed ? Kirigami.Units.smallSpacing / 2 : Kirigami.Units.smallSpacing 0055 topPadding: 0 0056 bottomPadding: 0 0057 0058 Kirigami.ActionToolBar { 0059 id: globalToolBar 0060 0061 anchors.fill: parent 0062 0063 overflowIconName: "application-menu" 0064 0065 actions: [ 0066 Kirigami.Action { 0067 id: toolsAction 0068 text: i18nc("@action", "Tools") 0069 icon.name: "tools-symbolic" 0070 }, 0071 Kirigami.Action { 0072 id: editPagesAction 0073 icon.name: "handle-sort" 0074 text: i18nc("@action", "Edit or Remove pages…") 0075 onTriggered: pageSortDialog.open() 0076 }, 0077 Kirigami.Action { 0078 id: exportAction 0079 text: i18nc("@action", "Export Current Page…") 0080 icon.name: "document-export" 0081 enabled: !app.pageStack.currentItem.edit 0082 onTriggered: exportDialog.open() 0083 }, 0084 Kirigami.Action { 0085 icon.name: "document-import" 0086 text: i18nc("@action", "Import Page…") 0087 onTriggered: importDialog.open() 0088 }, 0089 NewStuff.Action { 0090 id: ghnsAction 0091 text: i18nc("@action:inmenu", "Get New Pages…") 0092 configFile: "plasma-systemmonitor.knsrc" 0093 pageStack: app.pageStack.layers 0094 onEntryEvent: { 0095 if (event === NewStuff.Engine.StatusChangedEvent) { 0096 pagesModel.ghnsEntryStatusChanged(entry) 0097 } 0098 } 0099 }, 0100 Kirigami.Action { 0101 id: collapseAction 0102 icon.name: app.globalDrawer.collapsed ? "view-split-left-right" : "view-left-close" 0103 text: app.globalDrawer.collapsed ? i18nc("@action", "Expand Sidebar") : i18nc("@action", "Collapse Sidebar") 0104 onTriggered: app.globalDrawer.collapsed = !app.globalDrawer.collapsed 0105 }, 0106 Kirigami.Action { 0107 separator: true 0108 }, 0109 Kirigami.Action { 0110 icon.name: "tools-report-bug"; 0111 text: i18nc("@action", "Report Bug…"); 0112 onTriggered: Qt.openUrlExternally(CommandLineArguments.aboutData.bugAddress); 0113 }, 0114 Kirigami.Action { 0115 icon.name: "help-about-symbolic"; 0116 text: i18nc("@action", "About System Monitor"); 0117 onTriggered: app.pageStack.layers.push("AboutPage.qml") 0118 enabled: app.pageStack.layers.depth <= 1 0119 } 0120 ] 0121 Component.onCompleted: actions.push(app.quitAction) 0122 } 0123 0124 Instantiator { 0125 model: ToolsModel { id: toolsModel } 0126 0127 Kirigami.Action { 0128 text: model.name 0129 icon.name: model.icon 0130 shortcut: model.shortcut 0131 onTriggered: toolsModel.trigger(model.id) 0132 } 0133 0134 onObjectAdded: { toolsAction.children.push(object) } 0135 onObjectRemoved: { } 0136 } 0137 } 0138 0139 actions: [ 0140 Kirigami.Action { 0141 text: i18nc("@action", "Add New Page…") 0142 icon.name: "list-add" 0143 onTriggered: pageDialog.open() 0144 } 0145 ] 0146 0147 Instantiator { 0148 model: Page.PagesModel { id: pagesModel } 0149 0150 Page.EditablePageAction { 0151 text: model.title 0152 icon.name: model.icon 0153 pagePool: pagePoolObject 0154 pageData: model.data 0155 visible: !model.hidden 0156 onTriggered: { 0157 config.lastVisitedPage = model.fileName 0158 0159 if (app.pageStack.layers.depth > 0) { 0160 app.pageStack.layers.clear() 0161 } 0162 } 0163 0164 Component.onCompleted: { 0165 if (CommandLineArguments.pageId && model.fileName == CommandLineArguments.pageId) { 0166 trigger() 0167 } else if (CommandLineArguments.pageName && model.title == CommandLineArguments.pageName) { 0168 trigger() 0169 } else if (config.startPage == model.fileName) { 0170 trigger() 0171 } else if (config.startPage == "" && config.lastVisitedPage == model.fileName) { 0172 trigger() 0173 } 0174 } 0175 } 0176 0177 onObjectAdded: { 0178 var actions = Array.prototype.map.call(globalDrawer.actions, i => i) 0179 actions.splice(index, 0, object) 0180 globalDrawer.actions = actions 0181 } 0182 0183 onObjectRemoved: { 0184 var actions = Array.prototype.map.call(globalDrawer.actions, i => i) 0185 var actionIndex = actions.indexOf(object) 0186 actions.splice(actionIndex, 1) 0187 globalDrawer.actions = actions 0188 } 0189 } 0190 0191 contentData: [ 0192 TapHandler { 0193 acceptedButtons: Qt.RightButton 0194 onTapped: globalContextMenu.popup(eventPoint.scenePosition.x, eventPoint.scenePosition.y, globalDrawer) 0195 }, 0196 Menu { 0197 id: globalContextMenu 0198 0199 MenuItem { action: editPagesAction } 0200 MenuItem { action: ghnsAction } 0201 MenuItem { action: collapseAction } 0202 } 0203 ] 0204 } 0205 0206 Page.DialogLoader { 0207 id: pageDialog 0208 0209 sourceComponent: Page.PageDialog { 0210 title: i18nc("@window:title", "Add New Page") 0211 0212 onAccepted: { 0213 var fileName = name.toLowerCase().replace(" ", "_"); 0214 var newPage = pagesModel.addPage(fileName, {title: name, icon: iconName, margin: margin}) 0215 var row = newPage.insertChild(0, {name: "row-0", isTitle: false, title: "", heightMode: "balanced"}) 0216 var column = row.insertChild(0, {name: "column-0", showBackground: true}) 0217 column.insertChild(0, {name: "section-0", isSeparator: false}) 0218 newPage.savePage() 0219 0220 const pageAction = Array.from(globalDrawer.actions).find(action => action.pageData.fileName == newPage.fileName) 0221 pageAction.trigger() 0222 app.pageStack.currentItem.edit = true 0223 } 0224 } 0225 } 0226 0227 Page.DialogLoader { 0228 id: pageSortDialog 0229 0230 sourceComponent: Page.PageSortDialog { 0231 title: i18nc("@window:title", "Edit Pages") 0232 model: pagesModel 0233 startPage: config.startPage 0234 onAccepted: { 0235 config.startPage = startPage 0236 const currentPage = pageStack.currentItem.pageData.fileName 0237 const indices = pagesModel.match(pagesModel.index(0, 0), Page.PagesModel.FileNameRole, currentPage, 1, Qt.MatchExactly) 0238 if (indices.length == 0 || pagesModel.data(indices[0], Page.PagesModel.HiddenRole)) { 0239 if (config.lastVisitedPage == currentPage) { 0240 config.lastVisitedPage = "overview.page" 0241 } 0242 const startPage = config.startPage || config.lastVisitedPage 0243 Array.prototype.find.call(globalDrawer.actions, action => action.pageData.fileName == startPage).trigger() 0244 } 0245 } 0246 } 0247 } 0248 0249 Page.DialogLoader { 0250 id: exportDialog 0251 sourceComponent: FileDialog { 0252 selectExisting: false 0253 folder: shortcuts.home 0254 title: i18nc("@title:window %1 is the name of the page that is being exported", "Export %1", app.pageStack.currentItem.title) 0255 defaultSuffix: "page" 0256 nameFilters: [i18nc("Name filter in file dialog", "System Monitor page (*.page)")] 0257 onAccepted: app.pageStack.currentItem.pageData.saveAs(fileUrl) 0258 } 0259 } 0260 Page.DialogLoader { 0261 id: importDialog 0262 sourceComponent: FileDialog { 0263 selectExisting: true 0264 folder: shortcuts.home 0265 title: i18nc("@title:window", "Import Page") 0266 defaultSuffix: "page" 0267 nameFilters: [i18nc("Name filter in file dialog", "System Monitor page (*.page)")] 0268 onAccepted: { 0269 const newPage = pagesModel.importPage(fileUrl) 0270 if (!newPage) { 0271 return; 0272 } 0273 const pageAction = Array.from(globalDrawer.actions).find(action => action.pageData.fileName == newPage.fileName) 0274 pageAction.trigger() 0275 } 0276 } 0277 } 0278 0279 Configuration { 0280 id: config 0281 property alias width: app.width 0282 property alias height: app.height 0283 property alias sidebarCollapsed: globalDrawer.collapsed 0284 property alias pageOrder: pagesModel.pageOrder 0285 property alias hiddenPages: pagesModel.hiddenPages 0286 property string startPage 0287 property string lastVisitedPage 0288 } 0289 0290 Component { 0291 id: degradedWarning 0292 0293 ToolBar { 0294 Kirigami.InlineMessage { 0295 anchors.fill: parent 0296 visible: true 0297 type: Kirigami.MessageType.Warning 0298 text: i18n("System Monitor has fallen back to software rendering because hardware acceleration is not available, and visual glitches may appear. Please check your graphics drivers.") 0299 } 0300 } 0301 } 0302 0303 pageStack.columnView.columnWidth: Kirigami.Units.gridUnit * 19 0304 }