diff --git a/applets/systemmonitor/common/contents/ui/Applet.qml b/applets/systemmonitor/common/contents/ui/Applet.qml index 9055a7a67..575f96dd7 100644 --- a/applets/systemmonitor/common/contents/ui/Applet.qml +++ b/applets/systemmonitor/common/contents/ui/Applet.qml @@ -1,157 +1,167 @@ /* * Copyright 2014 Marco Martin * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * 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 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. */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras Item { id: rootItem signal sourceAdded(string source) property Component delegate width: units.gridUnit * 10 height: units.gridUnit * 10 Plasmoid.preferredRepresentation: plasmoid.fullRepresentation Layout.minimumWidth: units.gridUnit * 12 * (plasmoid.formFactor === PlasmaCore.Types.Horizontal ? sourcesModel.count : 1) Layout.minimumHeight: units.gridUnit * 4 * (plasmoid.formFactor === PlasmaCore.Types.Vertical ? sourcesModel.count : 1) Layout.preferredHeight: Layout.minimumHeight function addSource(source1, friendlyName1, source2, friendlyName2) { var found = false; for (var i = 0; i < sourcesModel.count; ++i) { var obj = sourcesModel.get(i); if (obj.source1 === encodeURIComponent(source1) && obj.source2 === encodeURIComponent(source2)) { found = true; break; } } if (found) { return; } smSource.connectSource(source1); if (source2) { smSource.connectSource(source2); } sourcesModel.append( {"source1": encodeURIComponent(source1), "friendlyName1": friendlyName1, "source2": encodeURIComponent(source2), "friendlyName2": friendlyName2, "dataSource": smSource}); } + function showSource(source) { + if (plasmoid.configuration.sources && plasmoid.configuration.sources.length > 0) { + return plasmoid.configuration.sources.indexOf(encodeURIComponent(source)) !== -1; + } else { + return sourceDefaultEnable(source); + } + } + + function sourceDefaultEnable(source) { + return true; + } + ListModel { id: sourcesModel } Component.onCompleted: { for (var i in smSource.sources) { smSource.sourceAdded(smSource.sources[i]); } } PlasmaCore.DataSource { id: smSource engine: "systemmonitor" interval: plasmoid.configuration.updateInterval onSourceAdded: { - if (plasmoid.configuration.sources && plasmoid.configuration.sources.length > 0 && - plasmoid.configuration.sources.indexOf(encodeURIComponent(source)) === -1) { - return; + if (showSource(source)) { + rootItem.sourceAdded(source); } - rootItem.sourceAdded(source); } onSourceRemoved: { for (var i = sourcesModel.count - 1; i >= 0; --i) { var obj = sourcesModel.get(i); if (obj.source1 === source || obj.source2 === source) { sourcesModel.remove(i); } } smSource.disconnectSource(source); } } Connections { target: plasmoid.configuration onSourcesChanged: { if (plasmoid.configuration.sources.length === 0) { for (var i in smSource.sources) { var source = smSource.sources[i]; smSource.sourceAdded(source); } } else { var sourcesToRemove = []; for (var i = sourcesModel.count - 1; i >= 0; --i) { var obj = sourcesModel.get(i); if (plasmoid.configuration.sources.indexOf(encodeURIComponent(obj.source1)) === -1) { sourcesToRemove.push(obj.source1); } } for (i = 0; i < sourcesToRemove.length; ++i) { smSource.sourceRemoved(sourcesToRemove[i]); } for (var i in plasmoid.configuration.sources) { var source = decodeURIComponent(plasmoid.configuration.sources[i]); smSource.sourceAdded(source); } } } } PlasmaExtras.Heading { id: heading width: parent.width level: 2 text: plasmoid.title visible: plasmoid.formFactor !== PlasmaCore.Types.Horizontal && plasmoid.formFactor !== PlasmaCore.Types.Vertical } GridLayout { rows: 1 columns: 1 flow: plasmoid.formFactor !== PlasmaCore.Types.Horizontal ? GridLayout.LeftToRight : GridLayout.TopToBottom anchors { top: heading.visible ? heading.bottom : parent.top bottom: parent.bottom } width: parent.width Repeater { model: sourcesModel delegate: rootItem.delegate } } } diff --git a/applets/systemmonitor/common/contents/ui/ConfigGeneral.qml b/applets/systemmonitor/common/contents/ui/ConfigGeneral.qml index dafe0045c..3f025ffaf 100644 --- a/applets/systemmonitor/common/contents/ui/ConfigGeneral.qml +++ b/applets/systemmonitor/common/contents/ui/ConfigGeneral.qml @@ -1,169 +1,173 @@ /* * Copyright 2013 Bhushan Shah * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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 General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. */ import QtQuick 2.5 import QtQuick.Controls 1.4 as QQC1 import QtQuick.Controls 2.5 as QQC2 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.5 as Kirigami import org.kde.plasma.core 2.0 as PlasmaCore Item { id: iconsPage width: childrenRect.width height: childrenRect.height implicitWidth: formLayout.implicitWidth implicitHeight: formLayout.implicitHeight property var cfg_sources: [] function sourcesChanged() { if (! cfg_sources) { cfg_sources = [] } if (cfg_sources.length == 0) { for (var i in dataSourcesColumn.children) { var child = dataSourcesColumn.children[i]; if (child.checked !== undefined) { - child.checked = true; + child.checked = sourceDefaultEnable(child.source); } } } else { for (var i in dataSourcesColumn.children) { var child = dataSourcesColumn.children[i]; if (child.checked !== undefined) { child.checked = cfg_sources.indexOf(child.source) !== -1; } } } } + function sourceDefaultEnable(source) { + return true; + } + onCfg_sourcesChanged: { sourcesChanged(); } property int cfg_updateInterval signal sourceAdded(string source) function addSource(source, friendlyName) { var found = false; for (var i = 0; i < sourcesModel.count; ++i) { var obj = sourcesModel.get(i); if (obj.source === source) { found = true; break; } } if (found) { return; } sourcesModel.append( {"source": encodeURIComponent(source), "friendlyName": friendlyName}); } PlasmaCore.DataSource { id: smSource engine: "systemmonitor" onSourceAdded: { iconsPage.sourceAdded(source); } onSourceRemoved: { for (var i = sourcesModel.count - 1; i >= 0; --i) { var obj = sourcesModel.get(i); if (obj.source === source) { sourcesModel.remove(i); } } } } Component.onCompleted: { for (var i in smSource.sources) { var source = smSource.sources[i]; iconsPage.sourceAdded(source); } sourcesChanged(); } ListModel { id: sourcesModel } Kirigami.FormLayout { id: formLayout anchors.left: parent.left anchors.right: parent.right // QQC2 SpinBox doesn't cleanly support non-integer values, which can be // worked around, but the code is messy and the user experience is // somewhat poor. So for now, we stick with the QQC1 SpinBox QQC1.SpinBox { id: updateIntervalSpinBox Kirigami.FormData.label: i18n("Update interval:") decimals: 1 suffix: i18ncp("Suffix for spinbox (seconds)", " second", " seconds") maximumValue: 1000 stepSize: 0.1 onValueChanged: cfg_updateInterval = value * 1000 Component.onCompleted: value = cfg_updateInterval / 1000 } Item { Kirigami.FormData.isSection: true } ColumnLayout { id: dataSourcesColumn Kirigami.FormData.label: i18n("Show:") Kirigami.FormData.buddyFor: children[1] // 0 is the Repeater Repeater { id: repeater model: sourcesModel QQC2.CheckBox { id: checkBox text: model.friendlyName property string source: model.source onCheckedChanged: { if (checked) { if (cfg_sources.indexOf(model.source) == -1) { cfg_sources.push(model.source); } } else { var idx = cfg_sources.indexOf(model.source); if (idx !== -1) { cfg_sources.splice(idx, 1); } } cfg_sourcesChanged(); } } } } } } diff --git a/applets/systemmonitor/cpu/contents/ui/cpu.qml b/applets/systemmonitor/cpu/contents/ui/cpu.qml index e9751e37d..28bbda1ab 100644 --- a/applets/systemmonitor/cpu/contents/ui/cpu.qml +++ b/applets/systemmonitor/cpu/contents/ui/cpu.qml @@ -1,48 +1,52 @@ /* * Copyright 2015 Marco Martin * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * 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 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. */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons Applet { id: root onSourceAdded: { var match = source.match(/^cpu\/(\w+)\/TotalLoad/); if (match) { root.addSource(source, match[1]); } } + function sourceDefaultEnable(source) { + return source.match(/^cpu(\/|%2F)system(\/|%2F)TotalLoad/); + } + delegate: SinglePlotter { autoRange: false rangeMin: 0 rangeMax: 100 function formatData(data) { //i18nc("CPU usage: %1 is the value, %2 the unit datatype", "%1 %2") //return i18n("%1 %2", Math.round(data.value), data.units); return i18nc("CPU usage: %1 is the value, %2 the unit datatype", "%1 %2", Math.round(data.value), data.units); } } } diff --git a/applets/systemmonitor/cpu/contents/ui/cpuConfig.qml b/applets/systemmonitor/cpu/contents/ui/cpuConfig.qml index 906ddaef0..bc147f43c 100644 --- a/applets/systemmonitor/cpu/contents/ui/cpuConfig.qml +++ b/applets/systemmonitor/cpu/contents/ui/cpuConfig.qml @@ -1,37 +1,41 @@ /* * Copyright 2015 Marco Martin * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * 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 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. */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons ConfigGeneral { id: root onSourceAdded: { var match = source.match(/^cpu\/(\w+)\/TotalLoad/); if (match) { root.addSource(source, match[1]); } } + + function sourceDefaultEnable(source) { + return source.match(/^cpu(\/|%2F)system(\/|%2F)TotalLoad/); + } }