From 9593095331a3dd581e654069bb452de3aabd1c44 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 19 Dec 2008 01:47:25 -0500 Subject: [PATCH] Finish implementing support for KDE 4.2's data engine. - Also removed warning when swaptotal and ramtotal are 0. --- applet/system_monitor.cpp | 90 ++++++++++++++++++++++++++++++++++++++--------- applet/system_monitor.h | 4 +-- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/applet/system_monitor.cpp b/applet/system_monitor.cpp index 8240538..c1a5ed6 100644 --- a/applet/system_monitor.cpp +++ b/applet/system_monitor.cpp @@ -36,7 +36,15 @@ systemMonitor::systemMonitor(QObject *parent, const QVariantList &args) m_sys(0), m_nice(0), m_idle(0), - m_disk(0){ + m_disk(0), + m_ramfree(0), + m_ramused(0), + m_rambuffers(0), + m_ramcached(0), + m_ramtotal(1), + m_swapfree(0), + m_swapused(0), + m_swaptotal(1){ setHasConfigurationInterface(true); resize(100, 100); @@ -244,27 +252,75 @@ void systemMonitor::dataUpdated(const QString& source, const Plasma::DataEngine: m_user = (data["value"].toString().toDouble()) / 100; - }else if( source.endsWith("/sys") || source.endsWith("/nice") || source.endsWith("/wait") || source.endsWith("/idle")){ + }else if(source.endsWith("/sys")){ - sys_mon->connectSource(source, this, 500); + m_sys = (data["value"].toString().toDouble()) / 100; + + }else if(source.endsWith("/nice")){ + + m_nice = (data["value"].toString().toDouble()) / 100; + + }else if(source.endsWith("/wait")){ + + m_disk = (data["value"].toString().toDouble()) / 100; + + }else if(source.endsWith("/idle")){ + + m_idle = (data["value"].toString().toDouble()) / 100; } }else if(source.startsWith("mem/swap")){ - sys_mon->connectSource(source, this, 500); + if(source.endsWith("/used")){ + + m_swapused = data["value"].toDouble() / 100; + + }else if(source.endsWith("/free")){ + + m_swapfree = data["value"].toDouble() / 100; + + } + + m_swaptotal = m_swapfree + m_swapused; + + if(m_swaptotal == 0){ + + m_swaptotal = 1; + + } + + update(); }else if(source.startsWith("mem/physical/")){ - if(source.endsWith("used")){ + if(source.endsWith("/used")){ + + m_ramused = data["value"].toDouble(); + + }else if(source.endsWith("/cached")){ + + m_ramcached = data["value"].toDouble(); + + }else if(source.endsWith("/buf")){ + + m_rambuffers = data["value"].toDouble(); - m_ramused = (data["value"].toDouble()); + }else if(source.endsWith("/free")){ + + m_ramfree = data["value"].toDouble(); } - } + m_ramtotal = m_ramused + m_ramcached + m_rambuffers + m_ramfree; - update(); + if(m_ramtotal == 0){ + + m_ramtotal = 1; + + } + + } } @@ -313,13 +369,13 @@ void systemMonitor::paintSwapUsage(QPainter *p, const QStyleOptionGraphicsItem * p->save(); - p->translate(0, contentsRect.height() * m_swapfree); + p->translate(0, contentsRect.height() * m_swapfree / m_swaptotal); p->setBrush(this->m_swapUsedColour); p->setPen(this->m_swapUsedColour); - p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_swapused)); + p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_swapused / m_swaptotal)); p->restore(); @@ -331,27 +387,27 @@ void systemMonitor::paintRAMUsage(QPainter *p, const QStyleOptionGraphicsItem *o p->save(); - p->translate(0, contentsRect.height() * m_ramfree); + p->translate(0, contentsRect.height() * m_ramfree / m_ramtotal); p->setBrush(this->m_ramCachedColour); p->setPen(this->m_ramCachedColour); - p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_ramcached)); - p->translate(0, contentsRect.height() * m_ramcached); + p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_ramcached / m_ramtotal)); + p->translate(0, contentsRect.height() * m_ramcached / m_ramtotal); p->setBrush(this->m_ramBuffersColour); p->setPen(this->m_ramBuffersColour); - p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_rambuffers)); - p->translate(0, contentsRect.height() * m_rambuffers); + p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_rambuffers / m_ramtotal)); + p->translate(0, contentsRect.height() * m_rambuffers / m_ramtotal); p->setBrush(this->m_ramUsedColour); p->setPen(this->m_ramUsedColour); - p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_ramused)); + p->drawRect(QRectF(contentsRect.left(), contentsRect.top(), contentsRect.width(), contentsRect.height() * m_ramused / m_ramtotal)); p->restore(); @@ -435,7 +491,7 @@ void systemMonitor::readConfig(){ void systemMonitor::toolTipAboutToShow(){ - Plasma::ToolTipManager::self()->setContent(this, Plasma::ToolTipContent("System Status:", QString("CPU usage: %1%
Ram Usage: %2%
Swap Usage: %3%").arg( round((1-m_idle) * 100)).arg( round((1 - m_ramfree) * 100)).arg( round((1-m_swapused) * 100 )))); + Plasma::ToolTipManager::self()->setContent(this, Plasma::ToolTipContent("System Status:", QString("CPU usage: %1%
Ram Usage: %2%
Swap Usage: %3%").arg( round((1 - m_idle) * 100)).arg( round((1 - m_ramfree / m_ramtotal) * 100)).arg( round((1 - m_swapused / m_swaptotal) * 100 )))); } diff --git a/applet/system_monitor.h b/applet/system_monitor.h index b95ec62..572a896 100644 --- a/applet/system_monitor.h +++ b/applet/system_monitor.h @@ -63,8 +63,8 @@ private: void reconnectSources(Plasma::DataEngine *sys_mon); double m_user, m_sys, m_nice, m_idle, m_disk; - double m_ramfree, m_ramused, m_rambuffers, m_ramcached; - double m_swapfree, m_swapused; + double m_ramfree, m_ramused, m_rambuffers, m_ramcached, m_ramtotal; + double m_swapfree, m_swapused, m_swaptotal; Ui::generalConfig uiGeneral; Ui::coloursConfig uiColours; -- 2.11.4.GIT