diff options
author | Ken Moore <ken@pcbsd.org> | 2015-05-22 12:11:01 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-05-22 12:11:01 -0400 |
commit | 766980aeaba64e23001c7437220dd67afd70c052 (patch) | |
tree | dad60ac664a3598aee13d0801b3334aeea0d1220 | |
parent | Add a few new functions to LuminaOS: (diff) | |
download | lumina-766980aeaba64e23001c7437220dd67afd70c052.tar.gz lumina-766980aeaba64e23001c7437220dd67afd70c052.tar.bz2 lumina-766980aeaba64e23001c7437220dd67afd70c052.zip |
Finish cleaning up the new CPU/Memory desction routines in libLumina, and add a new desktop plugin for monitoring system statistics (CPU/Mem usage, CPU temps).
-rw-r--r-- | libLumina/LuminaOS-FreeBSD.cpp | 31 | ||||
-rw-r--r-- | libLumina/LuminaUtils.cpp | 28 | ||||
-rw-r--r-- | lumina-config/LPlugins.cpp | 7 | ||||
-rw-r--r-- | lumina-config/PanelWidget.ui | 276 | ||||
-rw-r--r-- | lumina-desktop/LSession.cpp | 1 | ||||
-rw-r--r-- | lumina-desktop/desktop-plugins/NewDP.h | 3 | ||||
-rw-r--r-- | lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.cpp | 61 | ||||
-rw-r--r-- | lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.h | 57 | ||||
-rw-r--r-- | lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.ui | 99 | ||||
-rw-r--r-- | lumina-desktop/lumina-desktop.pro | 9 |
10 files changed, 546 insertions, 26 deletions
diff --git a/libLumina/LuminaOS-FreeBSD.cpp b/libLumina/LuminaOS-FreeBSD.cpp index 0843b1ce..3bf857d9 100644 --- a/libLumina/LuminaOS-FreeBSD.cpp +++ b/libLumina/LuminaOS-FreeBSD.cpp @@ -257,25 +257,38 @@ QString LOS::FileSystemCapacity(QString dir) { //Return: percentage capacity as QStringList LOS::CPUTemperatures(){ //Returns: List containing the temperature of any CPU's ("50C" for example) QStringList temps = LUtils::getCmdOutput("sysctl -ai").filter(".temperature:"); + temps.sort(); for(int i=0; i<temps.length(); i++){ - temps[i] = temps[i].section(":",1,5).simplified(); //only pull out the value, not the variable + if(temps[i].contains(".acpi.") || temps[i].contains(".cpu")){ + temps[i] = temps[i].section(":",1,5).simplified(); //only pull out the value, not the variable + }else{ + //non CPU temperature - skip it + temps.removeAt(i); i--; + } } return temps; } int LOS::CPUUsagePercent(){ //Returns: Overall percentage of the amount of CPU cycles in use (-1 for errors) - QStringList info = LUtils::getCmdOutput("iostat -t proc -Cd"); - //Output: [cpu header, column headers, values(us ni sy in id)] - if(info.length()==3){ - //idle value is the last one, use 100% minus that (don't worry about usage breakdown) - return (100 - info[2].section(" ",4,4,QString::SectionSkipEmpty).toInt()); - }else{ - return -1; //error + //qDebug() << "Get CPU usage"; + QStringList info = LUtils::getCmdOutput("iostat",QStringList() <<"-c"<<"2"<<"-t"<<"proc"<<"-w"<<"0.2"); + if(info.length()<4){return -1;} + //Only need the idle percentage (last number on the 4th line) + info = info[3].split(" ",QString::SkipEmptyParts); + //qDebug() << "CPU Info:" << info; + if(info.isEmpty()){ return -1; } + QString idle = info.last(); + if(idle.isEmpty()){ return -1; } + else{ + return (100 - idle.toInt() ); } } int LOS::MemoryUsagePercent(){ - QStringList mem = LUtils::getCmdOutput("top -n 0").filter("Mem: ").first().section(":",1,50).split(", "); + //qDebug() << "Get Mem Usage"; + QStringList mem = LUtils::getCmdOutput("top -n 0").filter("Mem: ", Qt::CaseInsensitive); + if(mem.isEmpty()){ return -1; } + mem = mem.first().section(":",1,50).split(", "); //Memory Labels: "Active", "Inact", "Wired", "Cache", "Buf", "Free" (usually in that order) // Format of each entry: "<number><Unit> <Label>" double fB = 0; //Free Bytes diff --git a/libLumina/LuminaUtils.cpp b/libLumina/LuminaUtils.cpp index f1c007f0..8eee76ca 100644 --- a/libLumina/LuminaUtils.cpp +++ b/libLumina/LuminaUtils.cpp @@ -26,35 +26,33 @@ QString LUtils::LuminaDesktopVersion(){ } int LUtils::runCmd(QString cmd, QStringList args){ - QProcess *proc = new QProcess; - proc->setProcessChannelMode(QProcess::MergedChannels); + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); if(args.isEmpty()){ - proc->start(cmd); + proc.start(cmd); }else{ - proc->start(cmd, args); + proc.start(cmd, args); } - while(!proc->waitForFinished(300)){ + while(!proc.waitForFinished(300)){ QCoreApplication::processEvents(); } - int ret = proc->exitCode(); - delete proc; + int ret = proc.exitCode(); return ret; } QStringList LUtils::getCmdOutput(QString cmd, QStringList args){ - QProcess *proc = new QProcess; - proc->setProcessChannelMode(QProcess::MergedChannels); + QProcess proc; + proc.setProcessChannelMode(QProcess::MergedChannels); if(args.isEmpty()){ - proc->start(cmd); + proc.start(cmd); }else{ - proc->start(cmd,args); + proc.start(cmd,args); } - while(!proc->waitForFinished(300)){ + while(!proc.waitForFinished(500)){ QCoreApplication::processEvents(); } - QStringList out = QString(proc->readAllStandardOutput()).split("\n"); - delete proc; + QStringList out = QString(proc.readAllStandardOutput()).split("\n"); return out; } @@ -148,6 +146,8 @@ void LUtils::LoadTranslation(QApplication *app, QString appname){ double LUtils::DisplaySizeToBytes(QString num){ num = num.toLower().simplified(); + num = num.remove(" "); + if(num.isEmpty()){ return 0.0; } if(num.endsWith("b")){ num.chop(1); } //remove the "bytes" marker (if there is one) QString lab = "b"; if(!num[num.size()-1].isNumber()){ diff --git a/lumina-config/LPlugins.cpp b/lumina-config/LPlugins.cpp index 94b61f34..31b189bb 100644 --- a/lumina-config/LPlugins.cpp +++ b/lumina-config/LPlugins.cpp @@ -188,6 +188,13 @@ void LPlugins::LoadDesktopPlugins(){ info.ID = "audioplayer"; info.icon = "media-playback-start"; DESKTOP.insert(info.ID, info); + //System Monitor Plugin + info = LPI(); //clear it + info.name = QObject::tr("System Monitor"); + info.description = QObject::tr("Keep track of system statistics such as CPU/Memory usage and CPU temperatures."); + info.ID = "systemmonitor"; + info.icon = "cpu"; + DESKTOP.insert(info.ID, info); } void LPlugins::LoadMenuPlugins(){ diff --git a/lumina-config/PanelWidget.ui b/lumina-config/PanelWidget.ui new file mode 100644 index 00000000..a2452d17 --- /dev/null +++ b/lumina-config/PanelWidget.ui @@ -0,0 +1,276 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PanelWidget</class> + <widget class="QWidget" name="PanelWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>264</width> + <height>280</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>2</number> + </property> + <property name="leftMargin"> + <number>1</number> + </property> + <property name="topMargin"> + <number>1</number> + </property> + <property name="rightMargin"> + <number>1</number> + </property> + <property name="bottomMargin"> + <number>1</number> + </property> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QToolButton" name="tool_rm"> + <property name="text"> + <string notr="true">rem</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string notr="true">TextLabel</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QToolBox" name="toolBox"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="page"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>262</width> + <height>169</height> + </rect> + </property> + <attribute name="label"> + <string>Geometry</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Screen Edge:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="comboBox"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Size:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QSpinBox" name="spinBox"> + <property name="suffix"> + <string> pixels thick</string> + </property> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>30000</number> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QSpinBox" name="spinBox_2"> + <property name="suffix"> + <string>% length</string> + </property> + </widget> + </item> + <item row="5" column="0"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Alignment:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="comboBox_2"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="page_3"> + <attribute name="label"> + <string>Appearance</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QCheckBox" name="check_autohide"> + <property name="text"> + <string>Auto-hide Panel</string> + </property> + </widget> + </item> + <item> + <widget class="QGroupBox" name="group_customcolor"> + <property name="title"> + <string>Use Custom Color</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <property name="leftMargin"> + <number>2</number> + </property> + <property name="topMargin"> + <number>2</number> + </property> + <property name="rightMargin"> + <number>2</number> + </property> + <property name="bottomMargin"> + <number>2</number> + </property> + <item> + <widget class="QToolButton" name="tool_selectcolor"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_color_sample"> + <property name="text"> + <string>Sample</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <widget class="QWidget" name="page_2"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>262</width> + <height>169</height> + </rect> + </property> + <attribute name="label"> + <string>Plugins</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QListWidget" name="listWidget"/> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QToolButton" name="toolButton_2"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="toolButton_4"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="toolButton_3"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="toolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/lumina-desktop/LSession.cpp b/lumina-desktop/LSession.cpp index a3b301b3..1fe20376 100644 --- a/lumina-desktop/LSession.cpp +++ b/lumina-desktop/LSession.cpp @@ -296,6 +296,7 @@ void LSession::launchStartupApps(){ if(vol>=0){ LOS::setAudioVolume(vol); } LSession::playAudioFile(LOS::LuminaShare()+"Login.ogg"); } + qDebug() << " - Finished with startup routines"; } void LSession::StartLogout(){ diff --git a/lumina-desktop/desktop-plugins/NewDP.h b/lumina-desktop/desktop-plugins/NewDP.h index d06b2e60..3e7c5eec 100644 --- a/lumina-desktop/desktop-plugins/NewDP.h +++ b/lumina-desktop/desktop-plugins/NewDP.h @@ -19,6 +19,7 @@ #include "desktopview/DesktopViewPlugin.h" #include "notepad/NotepadPlugin.h" #include "audioplayer/PlayerWidget.h" +#include "systemmonitor/MonitorWidget.h" //#include "messagecenter/MessageCenter.h" class NewDP{ @@ -38,6 +39,8 @@ public: plug = new NotePadPlugin(parent, plugin); }else if(plugin.section("---",0,0)=="audioplayer"){ plug = new AudioPlayerPlugin(parent, plugin); + }else if(plugin.section("---",0,0)=="systemmonitor"){ + plug = new SysMonitorPlugin(parent, plugin); //}else if(plugin.section("---",0,0)=="messagecenter"){ //plug = new MessageCenterPlugin(parent, plugin); }else{ diff --git a/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.cpp b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.cpp new file mode 100644 index 00000000..419b33cb --- /dev/null +++ b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.cpp @@ -0,0 +1,61 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "MonitorWidget.h" +#include "ui_MonitorWidget.h" + + +#include <LuminaXDG.h> +#include <LuminaOS.h> + +MonitorWidget::MonitorWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MonitorWidget()){ + ui->setupUi(this); //load the designer form + upTimer = new QTimer(this); + upTimer->setInterval(2000); //update every 2 seconds + connect(upTimer, SIGNAL(timeout()), this, SLOT(UpdateStats()) ); + LoadIcons(); + upTimer->start(); +} + +MonitorWidget::~MonitorWidget(){ + //qDebug() << "Removing MonitorWidget"; +} + +void MonitorWidget::LoadIcons(){ + ui->tabWidget->setTabIcon(0,LXDG::findIcon("appointment-recurring","") ); //Summary + ui->tabWidget->setTabIcon(1,LXDG::findIcon("cpu","") ); //CPU Log + ui->tabWidget->setTabIcon(2,LXDG::findIcon("media-flash-memory","") ); //Mem Log +} + +void MonitorWidget::UpdateStats(){ + //qDebug() << "Updating System statistics..."; + ui->label_temps->setText( LOS::CPUTemperatures().join(", ") ); + if(ui->progress_cpu->isEnabled()){ + int perc = LOS::CPUUsagePercent(); + ui->progress_cpu->setValue(perc); + if(perc<0){ ui->progress_cpu->setEnabled(false); } //disable this for future checks + } + if(ui->progress_mem->isEnabled()){ + int perc = LOS::MemoryUsagePercent(); + ui->progress_mem->setValue(perc); + if(perc<0){ ui->progress_mem->setEnabled(false); } //disable this for future checks + } + //Also perform/update the logs as necessary + // -- TO DO -- +} + +SysMonitorPlugin::SysMonitorPlugin(QWidget *parent, QString ID) : LDPlugin(parent, ID, true){ + monitor = new MonitorWidget(this); + this->setLayout( new QVBoxLayout() ); + this->layout()->setContentsMargins(0,0,0,0); + this->layout()->addWidget(monitor); + + this->setInitialSize(300,75); +} + +SysMonitorPlugin::~SysMonitorPlugin(){ + //qDebug() << "Remove SysMonitorPlugin"; +}
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.h b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.h new file mode 100644 index 00000000..08e8c09c --- /dev/null +++ b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.h @@ -0,0 +1,57 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This plugin is a simple hardware status monitor on the desktop +//=========================================== +#ifndef _LUMINA_DESKTOP_PLUGIN_HW_MONITOR_WIDGET_H +#define _LUMINA_DESKTOP_PLUGIN_HW_MONITOR_WIDGET_H + +#include <QTimer> +#include <QWidget> + +#include "../LDPlugin.h" + +namespace Ui{ + class MonitorWidget; +}; + +class MonitorWidget : public QWidget{ + Q_OBJECT +public: + MonitorWidget(QWidget *parent = 0); + ~MonitorWidget(); + +public slots: + void LoadIcons(); + +private: + Ui::MonitorWidget *ui; + QTimer *upTimer; + +private slots: + void UpdateStats(); +}; + +// Wrapper class to put this into a desktop plugin container +class SysMonitorPlugin : public LDPlugin{ + Q_OBJECT +public: + SysMonitorPlugin(QWidget* parent, QString ID); + ~SysMonitorPlugin(); + +private: + MonitorWidget *monitor; + +public slots: + void LocaleChange(){ + QTimer::singleShot(0,monitor, SLOT(LoadIcons())); + } + void ThemeChange(){ + QTimer::singleShot(0,monitor, SLOT(LoadIcons())); + } +}; + +#endif diff --git a/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.ui b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.ui new file mode 100644 index 00000000..c3a58017 --- /dev/null +++ b/lumina-desktop/desktop-plugins/systemmonitor/MonitorWidget.ui @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MonitorWidget</class> + <widget class="QWidget" name="MonitorWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>300</width> + <height>122</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="leftMargin"> + <number>2</number> + </property> + <property name="topMargin"> + <number>2</number> + </property> + <property name="rightMargin"> + <number>2</number> + </property> + <property name="bottomMargin"> + <number>2</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Summary</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>CPU Temp:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="label_temps"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>CPU Usage:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QProgressBar" name="progress_cpu"> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Mem Usage:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QProgressBar" name="progress_mem"> + <property name="value"> + <number>0</number> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>CPU Log</string> + </attribute> + </widget> + <widget class="QWidget" name="tab_3"> + <attribute name="title"> + <string>Memory Log</string> + </attribute> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/lumina-desktop/lumina-desktop.pro b/lumina-desktop/lumina-desktop.pro index d0f02b65..1964cafd 100644 --- a/lumina-desktop/lumina-desktop.pro +++ b/lumina-desktop/lumina-desktop.pro @@ -55,7 +55,8 @@ SOURCES += main.cpp \ desktop-plugins/applauncher/AppLauncherPlugin.cpp \ desktop-plugins/desktopview/DesktopViewPlugin.cpp \ desktop-plugins/notepad/NotepadPlugin.cpp \ - desktop-plugins/audioplayer/PlayerWidget.cpp + desktop-plugins/audioplayer/PlayerWidget.cpp \ + desktop-plugins/systemmonitor/MonitorWidget.cpp # desktop-plugins/messagecenter/MessageCenter.cpp @@ -98,14 +99,16 @@ HEADERS += Globals.h \ desktop-plugins/applauncher/AppLauncherPlugin.h \ desktop-plugins/desktopview/DesktopViewPlugin.h \ desktop-plugins/notepad/NotepadPlugin.h \ - desktop-plugins/audioplayer/PlayerWidget.h + desktop-plugins/audioplayer/PlayerWidget.h \ + desktop-plugins/systemmonitor/MonitorWidget.h # desktop-plugins/messagecenter/MessageCenter.h FORMS += SystemWindow.ui \ BootSplash.ui \ panel-plugins/userbutton/UserWidget.ui \ panel-plugins/systemdashboard/SysMenuQuick.ui \ - desktop-plugins/audioplayer/PlayerWidget.ui + desktop-plugins/audioplayer/PlayerWidget.ui \ + desktop-plugins/systemmonitor/MonitorWidget.ui RESOURCES+= Lumina-DE.qrc |