Compare commits

..

19 Commits

Author SHA1 Message Date
14cee9dbc7 release 2.0.5 2014-10-05 00:20:09 +04:00
5759273e4c add workaroud for resizing 2014-10-04 01:17:34 +04:00
4387bb1e76 some fixes which was introduced with the latest patches 2014-10-02 06:13:10 +04:00
03af5f0e49 upd task, add ability to use $ symbol over $$ 2014-10-02 05:10:02 +04:00
7f6afbcb4d add resizing 2014-10-01 03:15:28 +04:00
4a320bc5d6 more correct destuction 2014-10-01 02:59:47 +04:00
29d34525a3 fix plasma crash caused by label destruction 2014-10-01 02:57:06 +04:00
0ab74b493c fix #31, update submodules 2014-10-01 02:33:10 +04:00
952fa97fcc Merge branch 'master' of github.com:arcan1s/awesome-widgets 2014-10-01 02:02:13 +04:00
677ed1ab5e fix update netdev 2014-10-01 02:01:18 +04:00
deb0b3bdbb chenge forceupdate logic 2014-09-29 00:59:19 +04:00
20c85f0d42 fix number of issue 2014-09-28 23:12:33 +04:00
f9a37f0cb2 edit echange log, fix #20 2014-09-26 01:43:22 +04:00
0c8013c26b add tooltip bottom 2014-09-26 01:41:27 +04:00
6b9e19ed58 Merge branch 'master' of github.com:arcan1s/awesome-widgets 2014-09-25 23:25:08 +04:00
432ab694fd update changelog 2014-09-25 23:24:33 +04:00
c506183247 fix battery tooltip 2014-09-24 09:51:46 +04:00
fe822518d5 release 2014-09-21 21:50:03 +04:00
1f9e8221f0 release 2.0.4
battery fixes
2014-09-21 21:49:02 +04:00
15 changed files with 104 additions and 56 deletions

View File

@ -1,3 +1,12 @@
Ver.2.0.5:
+ add tooltip bottom (#30)
* fix network interface update
* fix battery tooltip bug
* edit DP layout (#31)
Ver.2.0.4:
* more correct work with batteries
Ver.2.0.3: Ver.2.0.3:
+ add support of several $bat tags + add support of several $bat tags
* edit layout * edit layout

View File

@ -1,3 +1,12 @@
Вер.2.0.5:
+ добавлен нижний край к тултипу (#30)
* исправлен баг с обновлением сетевого интерфейса
* исправлен баг с тултипом батареи
* отредактирована разметка DP (#31)
Вер.2.0.4:
* более корректная работа с батареями
Вер.2.0.3: Вер.2.0.3:
+ добавлена поддержка нескольких тегов $bat + добавлена поддержка нескольких тегов $bat
* отредактирована разметка * отредактирована разметка

View File

@ -1,8 +1,8 @@
# Maintainer: Evgeniy "arcanis" Alexeev <arcanis.arch at gmail dot com> # Maintainer: Evgeniy Alekseev <arcanis at archlinux dot org>
pkgname=kdeplasma-applets-awesome-widgets pkgname=kdeplasma-applets-awesome-widgets
_pkgname=awesome-widgets _pkgname=awesome-widgets
pkgver=2.0.3 pkgver=2.0.5
pkgrel=1 pkgrel=1
pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)" pkgdesc="Collection of minimalistic Plasmoids which look like Awesome WM widgets (ex-PyTextMonitor)"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
@ -19,7 +19,7 @@ optdepends=("amarok: for music player monitor"
makedepends=('automoc4' 'cmake') makedepends=('automoc4' 'cmake')
source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz) source=(https://github.com/arcan1s/awesome-widgets/releases/download/V.${pkgver}/${_pkgname}-${pkgver}-src.tar.xz)
install=${pkgname}.install install=${pkgname}.install
md5sums=('238e8418672b92bca0ac8431c6f085fb') md5sums=('a86de1841491ea1fc1d8021c5b3d9d43')
backup=('usr/share/config/extsysmon.conf') backup=('usr/share/config/extsysmon.conf')
prepare() { prepare() {

View File

@ -57,7 +57,8 @@ For edited output you must open Settings window and setup output format in lines
* tag `$down` - download speed, *KB/s* * tag `$down` - download speed, *KB/s*
* tag `$up` - upload speed, *KB/s* * tag `$up` - upload speed, *KB/s*
* tag `$netdev` - current network device * tag `$netdev` - current network device
* tag `$batN` - battery N charge, *%*. `$bat0` is average value * tag `$bat` - average battery charge, *%*
* tag `$batN` - battery N charge, *%*
* tag `$ac` - status AC device. Return (\*) if AC device is online or *( )* if offline * tag `$ac` - status AC device. Return (\*) if AC device is online or *( )* if offline
* tag `$album` - current song album. One of supported music players must be installed * tag `$album` - current song album. One of supported music players must be installed
* tag `$artist` - current song artist. One of supported music players must be installed * tag `$artist` - current song artist. One of supported music players must be installed
@ -291,8 +292,7 @@ Additional information
TODO (wish list) TODO (wish list)
---------------- ----------------
* 3rdpatry modules support (C++, Python and Shell modules in the plan) See [milestones](https://github.com/arcan1s/awesome-widgets/milestones) for more details.
* graphical bars support
Links Links
----- -----

View File

@ -1,9 +1,5 @@
post_install() { post_install() {
kbuildsycoca4 > /dev/null 2>&1 kbuildsycoca4 > /dev/null 2>&1
cat << __EOF
To migrate to version 2.* and newer see this article:
http://arcanis.name/en/2014/09/04/migration-to-v2/
__EOF
} }
post_upgrade() { post_upgrade() {

View File

@ -8,7 +8,7 @@ cmake_policy (SET CMP0015 NEW)
project (awesome-widgets) project (awesome-widgets)
set (PROJECT_VERSION_MAJOR 2) set (PROJECT_VERSION_MAJOR 2)
set (PROJECT_VERSION_MINOR 0) set (PROJECT_VERSION_MINOR 0)
set (PROJECT_VERSION_PATCH 3) set (PROJECT_VERSION_PATCH 5)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
set (PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty) set (PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)

View File

@ -83,9 +83,9 @@ void AwesomeWidget::createActions()
connect(contextMenu[1], SIGNAL(triggered(bool)), this, SLOT(showReadme())); connect(contextMenu[1], SIGNAL(triggered(bool)), this, SLOT(showReadme()));
contextMenu.append(new QAction(QIcon::fromTheme(QString("stock-refresh")), contextMenu.append(new QAction(QIcon::fromTheme(QString("stock-refresh")),
i18n("Update text"), this)); i18n("Update text"), this));
connect(contextMenu[2], SIGNAL(triggered(bool)), this, SLOT(updateNetworkDevice()));
connect(contextMenu[2], SIGNAL(triggered(bool)), extsysmonEngine, SLOT(updateAllSources())); connect(contextMenu[2], SIGNAL(triggered(bool)), extsysmonEngine, SLOT(updateAllSources()));
connect(contextMenu[2], SIGNAL(triggered(bool)), sysmonEngine, SLOT(updateAllSources())); connect(contextMenu[2], SIGNAL(triggered(bool)), sysmonEngine, SLOT(updateAllSources()));
connect(contextMenu[2], SIGNAL(triggered(bool)), this, SLOT(updateNetworkDevice()));
} }
@ -202,10 +202,7 @@ void AwesomeWidget::init()
setLayout(mainLayout); setLayout(mainLayout);
textLabel = new CustomLabel(this, debug); textLabel = new CustomLabel(this, debug);
QGraphicsProxyWidget *pw = new QGraphicsProxyWidget(this); QGraphicsProxyWidget *pw = new QGraphicsProxyWidget(this);
pw->setAttribute(Qt::WA_TranslucentBackground, true);
pw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
textLabel->setAttribute(Qt::WA_TranslucentBackground, true); textLabel->setAttribute(Qt::WA_TranslucentBackground, true);
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pw->setWidget(textLabel); pw->setWidget(textLabel);
mainLayout->addItem(pw, 0, 0); mainLayout->addItem(pw, 0, 0);
@ -324,9 +321,9 @@ QStringList AwesomeWidget::getKeys()
allKeys.append(QString("netdev")); allKeys.append(QString("netdev"));
// battery // battery
allKeys.append(QString("ac")); allKeys.append(QString("ac"));
allKeys.append(QString("bat0")); for (int i=counts[QString("bat")]-1; i>=0; i--)
for (int i=0; i<counts[QString("bat")]; i++) allKeys.append(QString("bat") + QString::number(i));
allKeys.append(QString("bat") + QString::number(i+1)); allKeys.append(QString("bat"));
// player // player
allKeys.append(QString("album")); allKeys.append(QString("album"));
allKeys.append(QString("artist")); allKeys.append(QString("artist"));

View File

@ -65,7 +65,7 @@ public slots:
void configChanged(); void configChanged();
// update events // update events
void sendNotification(const QString eventId, const QString message); void sendNotification(const QString eventId, const QString message);
void updateNetworkDevice(); void updateNetworkDevice(const bool delay = true);
void updateText(const bool clear = false); void updateText(const bool clear = false);
void updateTooltip(); void updateTooltip();

View File

@ -641,7 +641,12 @@ void AwesomeWidget::configChanged()
// counts // counts
QMap<QString, QString> deSettings = readDataEngineConfiguration(); QMap<QString, QString> deSettings = readDataEngineConfiguration();
counts[QString("bat")] = QDir(deSettings[QString("ACPIPATH")]).entryList(QDir::Dirs | QDir::NoDotAndDotDot).count(); counts[QString("bat")] = 0;
QStringList acpiDevices = QDir(deSettings[QString("ACPIPATH")]).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
QRegExp batRegexp = QRegExp(QString("BAT.*"));
for (int i=0; i<acpiDevices.count(); i++)
if (acpiDevices[i].indexOf(batRegexp) > -1)
counts[QString("bat")]++;
counts[QString("cpu")] = getNumberCpus(); counts[QString("cpu")] = getNumberCpus();
counts[QString("custom")] = deSettings[QString("CUSTOM")].split(QString("@@")).count(); counts[QString("custom")] = deSettings[QString("CUSTOM")].split(QString("@@")).count();
counts[QString("disk")] = configuration[QString("disk")].split(QString("@@")).count(); counts[QString("disk")] = configuration[QString("disk")].split(QString("@@")).count();

View File

@ -198,13 +198,13 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
values[data.keys()[i]] = QString("%1").arg(data[data.keys()[i]].toFloat(), 3, 'f', 0); values[data.keys()[i]] = QString("%1").arg(data[data.keys()[i]].toFloat(), 3, 'f', 0);
} }
if ((configuration[QString("batteryTooltip")].toInt() == 2) && if ((configuration[QString("batteryTooltip")].toInt() == 2) &&
(!isnan(data[QString("bat0")].toFloat()))) { (!isnan(data[QString("bat")].toFloat()))) {
if (tooltipValues[QString("bat")].count() > configuration[QString("tooltipNumber")].toInt()) if (tooltipValues[QString("bat")].count() > configuration[QString("tooltipNumber")].toInt())
tooltipValues[QString("bat")].takeFirst(); tooltipValues[QString("bat")].takeFirst();
if (data[QString("ac")].toBool()) if (data[QString("ac")].toBool())
tooltipValues[QString("bat0")].append(data[QString("bat0")].toFloat()); tooltipValues[QString("bat")].append(data[QString("bat")].toFloat());
else else
tooltipValues[QString("bat0")].append(-data[QString("bat0")].toFloat()); tooltipValues[QString("bat")].append(-data[QString("bat")].toFloat());
} }
} else if (sourceName == QString("cpu/system/TotalLoad")) { } else if (sourceName == QString("cpu/system/TotalLoad")) {
values[QString("cpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1); values[QString("cpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1);
@ -340,12 +340,12 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
tooltipValues[QString("down")].append(data[QString("value")].toFloat()); tooltipValues[QString("down")].append(data[QString("value")].toFloat());
} }
networkDeviceUpdate++; networkDeviceUpdate++;
if (networkDeviceUpdate == 30) { if (networkDeviceUpdate >= 30) {
networkDeviceUpdate = 0; networkDeviceUpdate = 0;
if (configuration[QString("useCustomNetdev")].toInt() == 2) { if (configuration[QString("useCustomNetdev")].toInt() == 0) {
sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), this); sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), this);
sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), this); sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), this);
updateNetworkDevice(); updateNetworkDevice(false);
sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"),
this, configuration[QString("interval")].toInt()); this, configuration[QString("interval")].toInt());
sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), sysmonEngine->connectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"),

View File

@ -43,7 +43,7 @@ void AwesomeWidget::reinit()
keys = getKeys(); keys = getKeys();
foundKeys = findKeys(); foundKeys = findKeys();
updateNetworkDevice(); updateNetworkDevice(false);
connectToEngine(); connectToEngine();
} }
@ -63,11 +63,14 @@ void AwesomeWidget::sendNotification(const QString eventId, const QString messag
} }
void AwesomeWidget::updateNetworkDevice() void AwesomeWidget::updateNetworkDevice(const bool delay)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
values[QString("netdev")] = getNetworkDevice(); if (delay)
networkDeviceUpdate = 30;
else
values[QString("netdev")] = getNetworkDevice();
} }
@ -76,9 +79,12 @@ void AwesomeWidget::updateText(const bool clear)
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString text = configuration[QString("text")]; QString text = configuration[QString("text")];
if (!clear) if (!clear) {
text.replace(QString("$$"), QString("$\\$\\"));
for (int i=0; i<foundKeys.count(); i++) for (int i=0; i<foundKeys.count(); i++)
text.replace(QString("$") + foundKeys[i], values[foundKeys[i]]); text.replace(QString("$") + foundKeys[i], values[foundKeys[i]]);
text.replace(QString("$\\$\\"), QString("$$"));
}
textLabel->setText(formatLine[0] + text + formatLine[1]); textLabel->setText(formatLine[0] + text + formatLine[1]);
update(); update();
} }
@ -88,7 +94,7 @@ void AwesomeWidget::updateTooltip()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
toolTipView->resize(100.0 * counts[QString("tooltip")], 100.0); toolTipView->resize(100.0 * counts[QString("tooltip")], 105.0);
// boundaries // boundaries
QMap<QString, float> boundaries; QMap<QString, float> boundaries;
boundaries[QString("cpu")] = 100.0; boundaries[QString("cpu")] = 100.0;
@ -137,9 +143,9 @@ void AwesomeWidget::updateTooltip()
if (down) shift -= 100.0; if (down) shift -= 100.0;
for (int j=0; j<tooltipValues[trueKeys[i]].count()-1; j++) { for (int j=0; j<tooltipValues[trueKeys[i]].count()-1; j++) {
float x1 = j * normX + shift; float x1 = j * normX + shift;
float y1 = - fabs(tooltipValues[trueKeys[i]][j]) * normY; float y1 = - fabs(tooltipValues[trueKeys[i]][j]) * normY + 5.0;
float x2 = (j + 1) * normX + shift; float x2 = (j + 1) * normX + shift;
float y2 = - fabs(tooltipValues[trueKeys[i]][j+1]) * normY; float y2 = - fabs(tooltipValues[trueKeys[i]][j+1]) * normY + 5.0;
if (isBattery) { if (isBattery) {
if (tooltipValues[trueKeys[i]][j+1] > 0) if (tooltipValues[trueKeys[i]][j+1] > 0)
pen.setColor(QColor(configuration[QString("batteryColor")])); pen.setColor(QColor(configuration[QString("batteryColor")]));

View File

@ -27,8 +27,9 @@
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QGraphicsGridLayout> #include <QGraphicsGridLayout>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsProxyWidget>
#include <QGraphicsView> #include <QGraphicsView>
#include <QMouseEvent>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <QTextCodec> #include <QTextCodec>
@ -37,7 +38,7 @@
CustomPlasmaLabel::CustomPlasmaLabel(DesktopPanel *wid, const int num, const bool debugCmd) CustomPlasmaLabel::CustomPlasmaLabel(DesktopPanel *wid, const int num, const bool debugCmd)
: Plasma::Label(wid), : QLabel(0),
debug(debugCmd), debug(debugCmd),
number(num), number(num),
widget(wid) widget(wid)
@ -59,13 +60,14 @@ int CustomPlasmaLabel::getNumber()
} }
void CustomPlasmaLabel::mousePressEvent(QGraphicsSceneMouseEvent *event) void CustomPlasmaLabel::mousePressEvent(QMouseEvent *event)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button(); if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button();
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
widget->setCurrentDesktop(number); widget->setCurrentDesktop(number);
emit(QLabel::mousePressEvent(event));
} }
@ -183,15 +185,14 @@ void DesktopPanel::reinit()
// clear // clear
// labels // labels
for (int i=0; i<labels.count(); i++) { for (int i=0; i<proxyWidgets.count(); i++) {
layout->removeItem(labels[i]); layout->removeItem(proxyWidgets[i]);
proxyWidgets[i]->setWidget(0);
delete labels[i]; delete labels[i];
delete proxyWidgets[i];
} }
labels.clear(); labels.clear();
// layout proxyWidgets.clear();
layout = new QGraphicsGridLayout();
layout->setContentsMargins(1, 1, 1, 1);
setLayout(layout);
// add // add
// layout // layout
@ -199,16 +200,22 @@ void DesktopPanel::reinit()
setBackgroundHints(NoBackground); setBackgroundHints(NoBackground);
// labels // labels
for (int i=0; i<desktopNames.count(); i++) { for (int i=0; i<desktopNames.count(); i++) {
labels.append(new CustomPlasmaLabel(this, i)); proxyWidgets.append(new QGraphicsProxyWidget(this));
labels.append(new CustomPlasmaLabel(this, i, debug));
labels[i]->setWordWrap(false); labels[i]->setWordWrap(false);
labels[i]->setAttribute(Qt::WA_NoSystemBackground, true); labels[i]->setAttribute(Qt::WA_TranslucentBackground, true);
proxyWidgets[i]->setWidget(labels[i]);
if (configuration[QString("layout")].toInt() == 0) if (configuration[QString("layout")].toInt() == 0)
layout->addItem(labels[i], 0, i); layout->addItem(proxyWidgets[i], 0, i);
else else
layout->addItem(labels[i], i, 0); layout->addItem(proxyWidgets[i], i, 0);
} }
updateText(true); updateText(true);
for (int i=0; i<proxyWidgets.count(); i++) {
labels[i]->adjustSize();
proxyWidgets[i]->setGeometry(labels[i]->geometry());
}
} }
@ -271,6 +278,22 @@ void DesktopPanel::updateText(const bool first)
labels[i]->setText(text); labels[i]->setText(text);
} }
update(); update();
int height = 0;
int width = 0;
for (int i=0; i<proxyWidgets.count(); i++) {
labels[i]->adjustSize();
proxyWidgets[i]->setGeometry(labels[i]->geometry());
if (configuration[QString("layout")].toInt() == 0) {
width += proxyWidgets[i]->geometry().width();
if (height < proxyWidgets[i]->geometry().height())
height = proxyWidgets[i]->geometry().height();
} else {
height += proxyWidgets[i]->geometry().height();
if (width < proxyWidgets[i]->geometry().width())
width = proxyWidgets[i]->geometry().width();
}
}
layout->setMinimumSize(width, height);
} }

View File

@ -21,7 +21,7 @@
#include <Plasma/Applet> #include <Plasma/Applet>
#include <Plasma/DataEngine> #include <Plasma/DataEngine>
#include <Plasma/Label> #include <QLabel>
#include <ui_appearance.h> #include <ui_appearance.h>
#include <ui_toggle.h> #include <ui_toggle.h>
@ -29,21 +29,23 @@
class QGraphicsGridLayout; class QGraphicsGridLayout;
class QGraphicsProxyWidget;
class DesktopPanel; class DesktopPanel;
class CustomPlasmaLabel : public Plasma::Label class CustomPlasmaLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
CustomPlasmaLabel(DesktopPanel *wid, const int num, CustomPlasmaLabel(DesktopPanel *wid,
const int num,
const bool debugCmd = false); const bool debugCmd = false);
~CustomPlasmaLabel(); ~CustomPlasmaLabel();
int getNumber(); int getNumber();
protected: protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QMouseEvent *event);
private: private:
// debug // debug
@ -89,6 +91,7 @@ private:
void updateText(const bool first = false); void updateText(const bool first = false);
// ui // ui
QGraphicsGridLayout *layout; QGraphicsGridLayout *layout;
QList<QGraphicsProxyWidget *> proxyWidgets;
QList<CustomPlasmaLabel *> labels; QList<CustomPlasmaLabel *> labels;
// debug // debug
bool debug; bool debug;

View File

@ -285,7 +285,7 @@ QMap<QString, QVariant> ExtendedSysMon::getBattery(const QString acpiPath)
QMap<QString, QVariant> battery; QMap<QString, QVariant> battery;
battery[QString("ac")] = false; battery[QString("ac")] = false;
battery[QString("bat0")] = 0; battery[QString("bat")] = 0;
QFile acFile(acpiPath + QString("/AC/online")); QFile acFile(acpiPath + QString("/AC/online"));
if (acFile.open(QIODevice::ReadOnly)) { if (acFile.open(QIODevice::ReadOnly)) {
if (QString(acFile.readLine()).trimmed().toInt() == 1) if (QString(acFile.readLine()).trimmed().toInt() == 1)
@ -293,7 +293,7 @@ QMap<QString, QVariant> ExtendedSysMon::getBattery(const QString acpiPath)
} }
acFile.close(); acFile.close();
// batterites // batterites
QStringList allDevices = QDir(acpiPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot); QStringList allDevices = QDir(acpiPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
QStringList batDevices; QStringList batDevices;
QRegExp batRegexp = QRegExp(QString("BAT.*")); QRegExp batRegexp = QRegExp(QString("BAT.*"));
for (int i=0; i<allDevices.count(); i++) for (int i=0; i<allDevices.count(); i++)
@ -302,18 +302,18 @@ QMap<QString, QVariant> ExtendedSysMon::getBattery(const QString acpiPath)
for (int i=0; i<batDevices.count(); i++) { for (int i=0; i<batDevices.count(); i++) {
QFile batFile(acpiPath + QString("/") + batDevices[i] + QString("/capacity")); QFile batFile(acpiPath + QString("/") + batDevices[i] + QString("/capacity"));
if (batFile.open(QIODevice::ReadOnly)) if (batFile.open(QIODevice::ReadOnly))
battery[QString("bat") + QString::number(i+1)] = QString(batFile.readLine()).trimmed().toInt(); battery[QString("bat") + QString::number(i)] = QString(batFile.readLine()).trimmed().toInt();
batFile.close(); batFile.close();
} }
float number = 0.0; float number = 0.0;
float average = 0.0; float average = 0.0;
for (int i=0; i<battery.keys().count(); i++) { for (int i=0; i<battery.keys().count(); i++) {
if (battery.keys()[i] == QString("ac")) continue; if (battery.keys()[i] == QString("ac")) continue;
if (battery.keys()[i] == QString("bat0")) continue; if (battery.keys()[i] == QString("bat")) continue;
average += battery[battery.keys()[i]].toInt(); average += battery[battery.keys()[i]].toInt();
number++; number++;
} }
battery[QString("bat0")] = int(average / number); battery[QString("bat")] = int(average / number);
return battery; return battery;
} }