mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-11-04 06:43:41 +00:00 
			
		
		
		
	add battery dataengine
This commit is contained in:
		@ -173,4 +173,101 @@ void AwesomeWidget::dataUpdated(const QString &sourceName, const Plasma::DataEng
 | 
			
		||||
void AwesomeWidget::disconnectFromEngine()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    QRegExp regExp;
 | 
			
		||||
 | 
			
		||||
    // cpu
 | 
			
		||||
    regExp = QRegExp(QString("cpu.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1) {
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("cpu/system/TotalLoad"), this);
 | 
			
		||||
        int numCpus = getNumberCpus();
 | 
			
		||||
        for (int i=0; i<numCpus; i++)
 | 
			
		||||
            sysmonEngine->disconnectSource(QString("cpu/cpu") + QString::number(i) + QString("/TotalLoad"), this);
 | 
			
		||||
    }
 | 
			
		||||
    // cpuclock
 | 
			
		||||
    regExp = QRegExp(QString("cpucl.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1) {
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("cpu/system/AverageClock"), this);
 | 
			
		||||
        int numCpus = getNumberCpus();
 | 
			
		||||
        for (int i=0; i<numCpus; i++)
 | 
			
		||||
            sysmonEngine->disconnectSource(QString("cpu/cpu") + QString::number(i) + QString("/clock"), this);
 | 
			
		||||
    }
 | 
			
		||||
    // custom command
 | 
			
		||||
    regExp = QRegExp(QString("custom.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("custom"), this);
 | 
			
		||||
    // desktop
 | 
			
		||||
    regExp = QRegExp(QString(".*desktop.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("desktop"), this);
 | 
			
		||||
    // disk speed
 | 
			
		||||
    regExp = QRegExp(QString("hdd[rw].*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        for (int i=0; i<configuration[QString("disk")].split(QString("@@")).count(); i++) {
 | 
			
		||||
            sysmonEngine->disconnectSource(configuration[QString("disk")].split(QString("@@"))[i] + QString("/Rate/rblk"), this);
 | 
			
		||||
            sysmonEngine->disconnectSource(configuration[QString("disk")].split(QString("@@"))[i] + QString("/Rate/wblk"), this);
 | 
			
		||||
        }
 | 
			
		||||
    // gpu
 | 
			
		||||
    regExp = QRegExp(QString("gpu"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("gpu"), this);
 | 
			
		||||
    // gputemp
 | 
			
		||||
    regExp = QRegExp(QString("gputemp"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("gputemp"), this);
 | 
			
		||||
    // mount
 | 
			
		||||
    regExp = QRegExp(QString("hdd([0-9]|mb|gb|totmb|totgb).*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        for (int i=0; i<configuration[QString("mount")].split(QString("@@")).count(); i++) {
 | 
			
		||||
            sysmonEngine->disconnectSource(QString("partitions") + configuration[QString("mount")].split(QString("@@"))[i] + QString("/filllevel"), this);
 | 
			
		||||
            sysmonEngine->disconnectSource(QString("partitions") + configuration[QString("mount")].split(QString("@@"))[i] + QString("/freespace"), this);
 | 
			
		||||
            sysmonEngine->disconnectSource(QString("partitions") + configuration[QString("mount")].split(QString("@@"))[i] + QString("/usedspace"), this);
 | 
			
		||||
        }
 | 
			
		||||
    // hddtemp
 | 
			
		||||
    regExp = QRegExp(QString("hddtemp.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("hddtemp"), this);
 | 
			
		||||
    // memory
 | 
			
		||||
    regExp = QRegExp(QString("mem.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1) {
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("mem/physical/free"), this);
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("mem/physical/used"), this);
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("mem/physical/application"), this);
 | 
			
		||||
    }
 | 
			
		||||
    // network
 | 
			
		||||
    regExp = QRegExp(QString("(down|up|netdev)"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1) {
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/transmitter/data"), this);
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("network/interfaces/") + values[QString("netdev")] + QString("/receiver/data"), this);
 | 
			
		||||
    }
 | 
			
		||||
    // package manager
 | 
			
		||||
    regExp = QRegExp(QString("pkgcount.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("pkg"), this);
 | 
			
		||||
    // player
 | 
			
		||||
    regExp = QRegExp(QString("(album|artist|duration|progress|title)"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("player"), this);
 | 
			
		||||
    // ps
 | 
			
		||||
    regExp = QRegExp(QString("ps.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        extsysmonEngine->disconnectSource(QString("ps"), this);
 | 
			
		||||
    // swap
 | 
			
		||||
    regExp = QRegExp(QString("swap.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1) {
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("mem/swap/free"), this);
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("mem/swap/used"), this);
 | 
			
		||||
    }
 | 
			
		||||
    // temp
 | 
			
		||||
    regExp = QRegExp(QString("temp.*"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        for (int i=0; i<configuration[QString("tempDevice")].split(QString("@@")).count(); i++)
 | 
			
		||||
            sysmonEngine->disconnectSource(configuration[QString("tempDevice")].split(QString("@@"))[i], this);
 | 
			
		||||
    // time
 | 
			
		||||
    regExp = QRegExp(QString("(^|iso|short|long|c)time"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        timeEngine->disconnectSource(QString("Local"), this);
 | 
			
		||||
    // uptime
 | 
			
		||||
    regExp = QRegExp(QString("(^|c)uptime"));
 | 
			
		||||
    if (foundKeys.indexOf(regExp) > -1)
 | 
			
		||||
        sysmonEngine->disconnectSource(QString("system/uptime"), this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,10 @@
 | 
			
		||||
# Configuration file for Extended Systemmonitor DataEngine
 | 
			
		||||
# $kdehome/share/config/extsysmon.conf
 | 
			
		||||
 | 
			
		||||
# ACPI devices
 | 
			
		||||
#AC=/sys/class/power_supply/AC/online
 | 
			
		||||
#BATTERY=/sys/class/power_supply/BAT0/capacity
 | 
			
		||||
 | 
			
		||||
# Custom command, separator is '@@'
 | 
			
		||||
#CUSTOM=curl ip4.telize.com
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -150,6 +150,7 @@ QStringList ExtendedSysMon::sources() const
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    QStringList source;
 | 
			
		||||
    source.append(QString("battery"));
 | 
			
		||||
    source.append(QString("custom"));
 | 
			
		||||
    source.append(QString("desktop"));
 | 
			
		||||
    source.append(QString("gpu"));
 | 
			
		||||
@ -170,6 +171,8 @@ void ExtendedSysMon::readConfiguration()
 | 
			
		||||
 | 
			
		||||
    // pre-setup
 | 
			
		||||
    QMap<QString, QString> rawConfig;
 | 
			
		||||
    rawConfig[QString("AC")] = QString("/sys/class/power_supply/AC/online");
 | 
			
		||||
    rawConfig[QString("BATTERY")] = QString("/sys/class/power_supply/BAT0/capacity");
 | 
			
		||||
    rawConfig[QString("CUSTOM")] = QString("curl ip4.telize.com");
 | 
			
		||||
    rawConfig[QString("DESKTOP")] = QString("");
 | 
			
		||||
    rawConfig[QString("DESKTOPCMD")] = QString("qdbus org.kde.kwin /KWin currentDesktop");
 | 
			
		||||
@ -275,6 +278,28 @@ QMap<QString, QString> ExtendedSysMon::updateConfiguration(const QMap<QString, Q
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QMap<QString, int> ExtendedSysMon::getBattery(const QString acPath, const QString batPath)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "AC path" << acPath;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Battery path" << batPath;
 | 
			
		||||
 | 
			
		||||
    QMap<QString, int> battery;
 | 
			
		||||
    battery[QString("ac")] = 0;
 | 
			
		||||
    battery[QString("battery")] = 0;
 | 
			
		||||
    QFile acFile(acPath);
 | 
			
		||||
    if (acFile.open(QIODevice::ReadOnly))
 | 
			
		||||
        battery[QString("ac")] = QString(acFile.readLine()).trimmed().toInt();
 | 
			
		||||
    acFile.close();
 | 
			
		||||
    QFile batFile(batPath);
 | 
			
		||||
    if (batFile.open(QIODevice::ReadOnly))
 | 
			
		||||
        battery[QString("battery")] = QString(batFile.readLine()).trimmed().toInt();
 | 
			
		||||
    batFile.close();
 | 
			
		||||
 | 
			
		||||
    return battery;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QMap<QString, QVariant> ExtendedSysMon::getCurrentDesktop(const QString cmd)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
@ -543,7 +568,12 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Source" << source;
 | 
			
		||||
 | 
			
		||||
    if (source == QString("custom")) {
 | 
			
		||||
    if (source == QString("battery")) {
 | 
			
		||||
        QMap<QString, int> battery = getBattery(configuration[QString("AC")],
 | 
			
		||||
                configuration[QString("BATTERY")]);
 | 
			
		||||
        setData(source, QString("ac"), QString::number(battery[QString("ac")]));
 | 
			
		||||
        setData(source, QString("bat"), QString::number(battery[QString("battery")]));
 | 
			
		||||
    } else if (source == QString("custom")) {
 | 
			
		||||
        for (int i=0; i<configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts).count(); i++) {
 | 
			
		||||
            setData(source, QString("custom") + QString::number(i),
 | 
			
		||||
                    getCustomCmd(configuration[QString("CUSTOM")].split(QString("@@"), QString::SkipEmptyParts)[i]));
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,7 @@ class ExtendedSysMon : public Plasma::DataEngine
 | 
			
		||||
public:
 | 
			
		||||
    ExtendedSysMon(QObject *parent, const QVariantList &args);
 | 
			
		||||
    // update functions
 | 
			
		||||
    QMap<QString, int> getBattery(const QString acPath, const QString batPath);
 | 
			
		||||
    QMap<QString, QVariant> getCurrentDesktop(const QString cmd);
 | 
			
		||||
    QString getCustomCmd(const QString cmd);
 | 
			
		||||
    float getGpu(const QString device);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user