Skip to content

Commit

Permalink
add executable source, add new monitor types, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
burlog committed Nov 30, 2017
1 parent 438af5c commit e1a38e1
Show file tree
Hide file tree
Showing 14 changed files with 1,066 additions and 76 deletions.
67 changes: 67 additions & 0 deletions plasmoid/contents/code/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2017 Michal Bukovský <[email protected]>
*
* 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) version 3 or 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, see <http://www.gnu.org/licenses/>
*/

function to_string(value) {
return Number(value).toLocaleString(Qt.locale(), "f")
}

function format_number(conf, value) {
var value_units = [
{"unit": "Y", "exp": Math.pow(10, 24)},
{"unit": "Z", "exp": Math.pow(10, 21)},
{"unit": "E", "exp": Math.pow(10, 18)},
{"unit": "P", "exp": Math.pow(10, 15)},
{"unit": "T", "exp": Math.pow(10, 12)},
{"unit": "G", "exp": Math.pow(10, 9)},
{"unit": "M", "exp": Math.pow(10, 6)},
{"unit": "k", "exp": Math.pow(10, 3)},
{"unit": "", "exp": Math.pow(10, 0)},
{"unit": "m", "exp": Math.pow(10, -3)},
{"unit": "u", "exp": Math.pow(10, -6)},
{"unit": "n", "exp": Math.pow(10, -9)},
{"unit": "p", "exp": Math.pow(10, -12)},
{"unit": "f", "exp": Math.pow(10, -15)},
{"unit": "a", "exp": Math.pow(10, -18)},
]

for (var i = 0; i < value_units.length; ++i) {
var value_unit = value_units[i]
var fixed_value = value * conf.multiplier
if (fixed_value > value_unit.exp)
return to_string(fixed_value / value_unit.exp) + value_unit.unit
}
return "0"
}

function get_label(conf, orig_values) {
if (!conf.use_value_as_label)
return conf.label
var label = 0.0
for (var i = 0; i < orig_values.length; ++i)
label += orig_values[i]
return format_number(conf, label)
}

function is_label_visible(conf) {
return conf.use_value_as_label
|| (conf.label && conf.label.length)
}

function get_height(conf, base) {
return base.height - theme.mSize(theme.defaultFont).height * (is_label_visible(conf)? 1: 0)
}

14 changes: 12 additions & 2 deletions plasmoid/contents/config/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ ConfigModel {
source: "Config.qml"
}
ConfigCategory {
name: i18n("Data Sources")
name: i18n("System Monitor Data Source")
icon: "utilities-system-monitor"
source: "DataSourcesConfig.qml"
source: "SystemMonitorDataSourceConfig.qml"
}
ConfigCategory {
name: i18n("Executabale Data Source")
icon: "application-x-executable"
source: "ExecutableDataSourceConfig.qml"
}
ConfigCategory {
name: i18n("Examples")
icon: "user-desktop"
source: "ExampleConfig.qml"
}
}

14 changes: 13 additions & 1 deletion plasmoid/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
<entry name="label" type="String">
<default></default>
</entry>
<entry name="use_value_as_label" type="Bool">
<default>false</default>
</entry>
<entry name="monitor_type" type="Int">
<default>0</default>
</entry>
<entry name="max_value" type="Double">
<default>0.0</default>
</entry>
<entry name="multiplier" type="Double">
<default>1.0</default>
</entry>
<entry name="update_interval" type="Double">
<default>1.0</default>
</entry>
Expand All @@ -30,9 +39,12 @@
<entry name="colors" type="StringList">
<default></default>
</entry>
<entry name="guessed_max_values" type="StringList">
<entry name="labels" type="StringList">
<default></default>
</entry>
<entry name="guessed_max_value" type="Double">
<default>0.0</default>
</entry>
</group>
</kcfg>

103 changes: 103 additions & 0 deletions plasmoid/contents/ui/BarMonitor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2014 Martin Yrjölä <[email protected]>
* Copyright (C) 2017 Michal Bukovský <[email protected]>
*
* 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) version 3 or 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, see <http://www.gnu.org/licenses/>
*/

import QtQuick 2.2
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents

import "../code/utils.js" as Utils

Item {
id: bar_monitor

anchors.fill: parent
height: childrenRect.height

property var orig_values
property var values

ColumnLayout {
width: parent.width

Item {
id: bar_row

height: Utils.get_height(plasmoid.configuration, bar_monitor)

Rectangle {
id: bar_border

height: Utils.get_height(plasmoid.configuration, bar_monitor)
width: bar_monitor.width

color: "transparent"

radius: 3
opacity: .4

border {
color: theme.textColor
width: 1
}
}

Repeater {
id: bar_repeater
model: values.length

Rectangle {
color: plasmoid.configuration.colors[index]
height: (bar_border.height - (bar_border.border.width * 2)) * bar_monitor.values[index]
width: bar_border.width - (bar_border.border.width * 2)
z: -1
anchors {
bottom: index == 0
? bar_border.bottom
: bar_repeater.itemAt(index - 1).top
bottomMargin: index == 0
? bar_border.border.width
: 0
}
}
}
}

PlasmaComponents.Label {
id: bar_label

width: bar_border.width
Layout.maximumWidth: bar_border.width
visible: Utils.is_label_visible(plasmoid.configuration)
elide: Text.ElideRight
horizontalAlignment: Text.AlignHCenter

onVisibleChanged: {
bar_row.height = Utils.get_height(plasmoid.configuration, bar_monitor)
bar_monitor.height = Utils.get_height(plasmoid.configuration, bar_monitor)
}

anchors {
top: bar_row.bottom
horizontalCenter: parent.horizontalCenter
}

text: Utils.get_label(plasmoid.configuration, orig_values)
}
}
}

27 changes: 24 additions & 3 deletions plasmoid/contents/ui/CircularMonitor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@

import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents

import "../code/utils.js" as Utils

Item {
property alias colors: canvas.colors
id: circular_monitor

property var orig_values
property alias values: canvas.values

anchors {
Expand All @@ -43,7 +48,6 @@ Item {
property real alpha: 1.0

property var values
property var colors

// This fixes edge bleeding
readonly property double filler: 0.01
Expand All @@ -66,7 +70,7 @@ Item {
// draw the sectors
for (var i = 0; i < values.length; i++) {
var radians = values[i] * 2 * Math.PI
ctx.fillStyle = colors[i]
ctx.fillStyle = plasmoid.configuration.colors[i]
ctx.beginPath()
ctx.arc(width / 2, height / 2, min / 2.03, currentRadian, currentRadian + radians + filler, false)
ctx.arc(width / 2, height / 2, min / 3.5, currentRadian + radians + filler, currentRadian, true)
Expand All @@ -89,5 +93,22 @@ Item {
ctx.restore()
}
}

// the label if requested
PlasmaComponents.Label {
id: label
width: parent.width - (Math.min(canvas.height, canvas.width) / 2.03 - Math.min(canvas.height, canvas.width) / 3.5) * 2
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight

// tells the label to be centered in parent (in the centre of CircularMonitor)
anchors {
verticalCenter: parent.verticalCenter
horizontalCenter: parent.horizontalCenter
}

// the value
text: Utils.get_label(plasmoid.configuration, orig_values)
}
}

60 changes: 60 additions & 0 deletions plasmoid/contents/ui/CompactBarMonitor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2014 Martin Yrjölä <[email protected]>
* Copyright (C) 2015 Joshua Worth <[email protected]>
*
* 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) version 3 or 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, see <http://www.gnu.org/licenses/>
*/

import QtQuick 2.2
import QtQuick.Layouts 1.1
import QtGraphicalEffects 1.0

Item {
id: barMonitor

property var colors
property var proportions: []

Layout.fillHeight: true
Layout.fillWidth: true

Rectangle {
id: barBorder
anchors.fill: parent
opacity: 0
}

Repeater {
id: barRepeater
model: proportions.length
Rectangle {
color: barMonitor.colors[index]
height: barBorder.height * barMonitor.proportions[index]
width: barBorder.width
anchors {
bottom: index == 0 ? barBorder.bottom : barRepeater.itemAt(index-1).top
bottomMargin: index == 0 ? barBorder.border.width : 0
}

LinearGradient {
anchors.fill: parent
end: Qt.point(width, 0)
gradient: Gradient {
GradientStop { position: 0.0; color: "#60ffffff" }
GradientStop { position: 1.0; color: "transparent" }
}
}
}
}
}
Loading

0 comments on commit e1a38e1

Please sign in to comment.