mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-15 06:45:48 +00:00
some updates
This commit is contained in:
@ -41,4 +41,4 @@ target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
|
||||
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesomewidget)
|
||||
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})
|
||||
install (DIRECTORY ${SUBPROJECT_DESKTOPS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})
|
||||
install (DIRECTORY ${SUBPROJECT_DESKTOPS} DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME})
|
||||
|
@ -23,16 +23,12 @@
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QHBoxLayout>
|
||||
#include <QListWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkInterface>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QProcess>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QRegExp>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
@ -60,15 +56,6 @@ AWActions::~AWActions()
|
||||
}
|
||||
|
||||
|
||||
bool AWActions::checkKeys(const QMap<QString, QVariant> data)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Data" << data;
|
||||
|
||||
return (data.count() != 0);
|
||||
}
|
||||
|
||||
|
||||
void AWActions::checkUpdates()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -111,31 +98,6 @@ void AWActions::showReadme()
|
||||
}
|
||||
|
||||
|
||||
void AWActions::addDevice(const QString source)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source" << source;
|
||||
|
||||
QRegExp diskRegexp = QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp fanRegexp = QRegExp(QString("lmsensors/.*/fan.*"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
QRegExp tempRegexp = QRegExp(QString("lmsensors/.*temp.*/.*"));
|
||||
|
||||
if (diskRegexp.indexIn(source) > -1) {
|
||||
QStringList splitSource = source.split(QChar('/'));
|
||||
QString device = splitSource[0] + QString("/") + splitSource[1];
|
||||
diskDevices.append(device);
|
||||
} else if (fanRegexp.indexIn(source) > -1)
|
||||
fanDevices.append(source);
|
||||
else if (mountRegexp.indexIn(source) > -1) {
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
mountDevices.append(device);
|
||||
} else if (tempRegexp.indexIn(source) > -1)
|
||||
tempDevices.append(source);
|
||||
}
|
||||
|
||||
|
||||
QString AWActions::getAboutText(const QString type)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -173,74 +135,6 @@ QString AWActions::getAboutText(const QString type)
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getDiskDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
diskDevices.sort();
|
||||
|
||||
return diskDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getFanDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
fanDevices.sort();
|
||||
|
||||
return fanDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getHddDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList allDevices = QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
for (int i=0; i<devices.count(); i++)
|
||||
devices[i] = QString("/dev/") + devices[i];
|
||||
devices.sort();
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getMountDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mountDevices.sort();
|
||||
|
||||
return mountDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getNetworkDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList interfaceList;
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||
interfaceList.append(rawInterfaceList[i].name());
|
||||
interfaceList.sort();
|
||||
|
||||
return interfaceList;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWActions::getTempDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
tempDevices.sort();
|
||||
|
||||
return tempDevices;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::getFont(const QMap<QString, QVariant> defaultFont)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -308,38 +202,20 @@ QMap<QString, QVariant> AWActions::readDataEngineConfiguration()
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString("plasma-dataengine-extsysmon.conf"));
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << fileName;
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
QMap<QString, QVariant> rawConfig;
|
||||
QMap<QString, QVariant> configuration;
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
rawConfig[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto"));
|
||||
rawConfig[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all"));
|
||||
rawConfig[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo hddtemp"));
|
||||
rawConfig[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
rawConfig[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600"));
|
||||
rawConfig[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto"));
|
||||
rawConfig[QString("PKGCMD")] = settings.value(QString("PKGCMD"), QString("pacman -Qu"));
|
||||
rawConfig[QString("PKGNULL")] = settings.value(QString("PKGNULL"), QString("0"));
|
||||
rawConfig[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris"));
|
||||
configuration[QString("ACPIPATH")] = settings.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"));
|
||||
configuration[QString("GPUDEV")] = settings.value(QString("GPUDEV"), QString("auto"));
|
||||
configuration[QString("HDDDEV")] = settings.value(QString("HDDDEV"), QString("all"));
|
||||
configuration[QString("HDDTEMPCMD")] = settings.value(QString("HDDTEMPCMD"), QString("sudo hddtemp"));
|
||||
configuration[QString("MPDADDRESS")] = settings.value(QString("MPDADDRESS"), QString("localhost"));
|
||||
configuration[QString("MPDPORT")] = settings.value(QString("MPDPORT"), QString("6600"));
|
||||
configuration[QString("MPRIS")] = settings.value(QString("MPRIS"), QString("auto"));
|
||||
configuration[QString("PLAYER")] = settings.value(QString("PLAYER"), QString("mpris"));
|
||||
settings.endGroup();
|
||||
|
||||
return updateDataEngineConfiguration(rawConfig);
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWActions::updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=rawConfig[QString("PKGNULL")].toString().split(QString(","), QString::SkipEmptyParts).count();
|
||||
i<rawConfig[QString("PKGCMD")].toString().split(QString(","), QString::SkipEmptyParts).count();
|
||||
i++)
|
||||
rawConfig[QString("PKGNULL")].toString() += QString(",0");
|
||||
|
||||
for (int i=0; i<rawConfig.keys().count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" <<
|
||||
rawConfig.keys()[i] << QString("=") << rawConfig[rawConfig.keys()[i]];
|
||||
return rawConfig;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
||||
@ -358,8 +234,6 @@ void AWActions::writeDataEngineConfiguration(const QMap<QString, QVariant> confi
|
||||
settings.setValue(QString("MPDADDRESS"), configuration[QString("MPDADDRESS")]);
|
||||
settings.setValue(QString("MPDPORT"), configuration[QString("MPDPORT")]);
|
||||
settings.setValue(QString("MPRIS"), configuration[QString("MPRIS")]);
|
||||
settings.setValue(QString("PKGCMD"), configuration[QString("PKGCMD")]);
|
||||
settings.setValue(QString("PKGNULL"), configuration[QString("PKGNULL")]);
|
||||
settings.setValue(QString("PLAYER"), configuration[QString("PLAYER")]);
|
||||
settings.endGroup();
|
||||
|
||||
|
@ -34,22 +34,13 @@ public:
|
||||
AWActions(QObject *parent = 0);
|
||||
~AWActions();
|
||||
|
||||
Q_INVOKABLE bool checkKeys(const QMap<QString, QVariant> data);
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void runCmd(const QString cmd = QString("/usr/bin/true"));
|
||||
Q_INVOKABLE void sendNotification(const QString eventId, const QString message);
|
||||
Q_INVOKABLE void showReadme();
|
||||
// configuration slots
|
||||
Q_INVOKABLE void addDevice(const QString source);
|
||||
Q_INVOKABLE QString getAboutText(const QString type = "header");
|
||||
Q_INVOKABLE QStringList getDiskDevices();
|
||||
Q_INVOKABLE QStringList getFanDevices();
|
||||
Q_INVOKABLE QStringList getHddDevices();
|
||||
Q_INVOKABLE QStringList getMountDevices();
|
||||
Q_INVOKABLE QStringList getNetworkDevices();
|
||||
Q_INVOKABLE QStringList getTempDevices();
|
||||
Q_INVOKABLE QMap<QString, QVariant> getFont(const QMap<QString, QVariant> defaultFont);
|
||||
Q_INVOKABLE QString selectDevices(const QStringList source, const QStringList current);
|
||||
// dataengine
|
||||
Q_INVOKABLE QMap<QString, QVariant> readDataEngineConfiguration();
|
||||
Q_INVOKABLE void writeDataEngineConfiguration(const QMap<QString, QVariant> configuration);
|
||||
@ -59,10 +50,8 @@ private slots:
|
||||
void versionReplyRecieved(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QMap<QString, QVariant> updateDataEngineConfiguration(QMap<QString, QVariant> rawConfig);
|
||||
// variables
|
||||
bool debug = false;
|
||||
QStringList diskDevices, fanDevices, mountDevices, tempDevices;
|
||||
};
|
||||
|
||||
|
||||
|
@ -66,12 +66,29 @@ AWKeys::~AWKeys()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
delete toolTip;
|
||||
delete createButton;
|
||||
delete copyButton;
|
||||
delete dialogButtons;
|
||||
delete widgetDialog;
|
||||
delete dialog;
|
||||
|
||||
graphicalItems.clear();
|
||||
extScripts.clear();
|
||||
extUpgrade.clear();
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::checkKeys(const QMap<QString, QVariant> data)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Data" << data;
|
||||
|
||||
return (data.count() != 0);
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::initKeys(const QString pattern,
|
||||
const QMap<QString, QVariant> params,
|
||||
const QMap<QString, QVariant> tooltipParams)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -80,7 +97,6 @@ void AWKeys::initKeys(const QString pattern,
|
||||
extScripts.clear();
|
||||
extUpgrade.clear();
|
||||
graphicalItems.clear();
|
||||
counts.clear();
|
||||
keys.clear();
|
||||
foundBars.clear();
|
||||
foundKeys.clear();
|
||||
@ -90,7 +106,6 @@ void AWKeys::initKeys(const QString pattern,
|
||||
extScripts = getExtScripts();
|
||||
extUpgrade = getExtUpgrade();
|
||||
graphicalItems = getGraphicalItems();
|
||||
counts = getCounts(params);
|
||||
keys = dictKeys();
|
||||
foundBars = findGraphicalItems(pattern);
|
||||
foundKeys = findKeys(pattern);
|
||||
@ -108,17 +123,10 @@ bool AWKeys::isDebugEnabled()
|
||||
}
|
||||
|
||||
|
||||
bool AWKeys::isReady()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return ready;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::parsePattern(const QString pattern)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!ready) return pattern;
|
||||
|
||||
QString parsed = pattern;
|
||||
parsed.replace(QString("$$"), QString("$\\$\\"));
|
||||
@ -140,6 +148,31 @@ QPixmap AWKeys::toolTipImage()
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::addDevice(const QString source)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source" << source;
|
||||
|
||||
QRegExp diskRegexp = QRegExp(QString("disk/(?:md|sd|hd)[a-z|0-9]_.*/Rate/(?:rblk)"));
|
||||
QRegExp fanRegexp = QRegExp(QString("lmsensors/.*/fan.*"));
|
||||
QRegExp mountRegexp = QRegExp(QString("partitions/.*/filllevel"));
|
||||
QRegExp tempRegexp = QRegExp(QString("lmsensors/.*temp.*/.*"));
|
||||
|
||||
if (diskRegexp.indexIn(source) > -1) {
|
||||
QString device = source;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
diskDevices.append(device);
|
||||
} else if (fanRegexp.indexIn(source) > -1)
|
||||
fanDevices.append(source);
|
||||
else if (mountRegexp.indexIn(source) > -1) {
|
||||
QString device = source;
|
||||
device.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
mountDevices.append(device);
|
||||
} else if (tempRegexp.indexIn(source) > -1)
|
||||
tempDevices.append(source);
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::dictKeys()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -155,17 +188,17 @@ QStringList AWKeys::dictKeys()
|
||||
allKeys.append(QString("uptime"));
|
||||
allKeys.append(QString("cuptime"));
|
||||
// cpuclock
|
||||
for (int i=counts[QString("cpu")].toInt()-1; i>=0; i--)
|
||||
for (int i=numberCpus()-1; i>=0; i--)
|
||||
allKeys.append(QString("cpucl") + QString::number(i));
|
||||
allKeys.append(QString("cpucl"));
|
||||
// cpu
|
||||
for (int i=counts[QString("cpu")].toInt()-1; i>=0; i--)
|
||||
for (int i=numberCpus()-1; i>=0; i--)
|
||||
allKeys.append(QString("cpu") + QString::number(i));
|
||||
allKeys.append(QString("cpu"));
|
||||
// temperature
|
||||
for (int i=counts[QString("temp")].toInt()-1; i>=0; i--)
|
||||
for (int i=tempDevices.count()-1; i>=0; i--)
|
||||
allKeys.append(QString("temp") + QString::number(i));
|
||||
for (int i=counts[QString("fan")].toInt()-1; i>=0; i--)
|
||||
for (int i=fanDevices.count()-1; i>=0; i--)
|
||||
allKeys.append(QString("fan") + QString::number(i));
|
||||
// gputemp
|
||||
allKeys.append(QString("gputemp"));
|
||||
@ -190,7 +223,7 @@ QStringList AWKeys::dictKeys()
|
||||
allKeys.append(QString("swaptotgb"));
|
||||
allKeys.append(QString("swap"));
|
||||
// hdd
|
||||
for (int i=counts[QString("mount")].toInt()-1; i>=0; i--) {
|
||||
for (int i=mountDevices.count()-1; i>=0; i--) {
|
||||
allKeys.append(QString("hddmb") + QString::number(i));
|
||||
allKeys.append(QString("hddgb") + QString::number(i));
|
||||
allKeys.append(QString("hddfreemb") + QString::number(i));
|
||||
@ -200,12 +233,12 @@ QStringList AWKeys::dictKeys()
|
||||
allKeys.append(QString("hdd") + QString::number(i));
|
||||
}
|
||||
// hdd speed
|
||||
for (int i=counts[QString("disk")].toInt()-1; i>=0; i--) {
|
||||
for (int i=diskDevices.count()-1; i>=0; i--) {
|
||||
allKeys.append(QString("hddr") + QString::number(i));
|
||||
allKeys.append(QString("hddw") + QString::number(i));
|
||||
}
|
||||
// hdd temp
|
||||
for (int i=counts[QString("hddtemp")].toInt()-1; i>=0; i--) {
|
||||
for (int i=getHddDevices.count()-1; i>=0; i--) {
|
||||
allKeys.append(QString("hddtemp") + QString::number(i));
|
||||
allKeys.append(QString("hddtemp") + QString::number(i));
|
||||
}
|
||||
@ -215,7 +248,10 @@ QStringList AWKeys::dictKeys()
|
||||
allKeys.append(QString("netdev"));
|
||||
// battery
|
||||
allKeys.append(QString("ac"));
|
||||
for (int i=counts[QString("bat")].toInt()-1; i>=0; i--)
|
||||
QStringList allBatteryDevices = QDir(QString("/sys/class/power_supply"))
|
||||
.entryList(QDir::Dirs | QDir::NoDotAndDotDot,
|
||||
QDir::Name);
|
||||
for (int i=allBatteryDevices.filter(QRegExp(QString("BAT.*"))).count()-1; i>=0; i--)
|
||||
allKeys.append(QString("bat") + QString::number(i));
|
||||
allKeys.append(QString("bat"));
|
||||
// player
|
||||
@ -229,10 +265,10 @@ QStringList AWKeys::dictKeys()
|
||||
allKeys.append(QString("pstotal"));
|
||||
allKeys.append(QString("ps"));
|
||||
// package manager
|
||||
for (int i=counts[QString("pkg")].toInt()-1; i>=0; i--)
|
||||
for (int i=extUpgrade.count()-1; i>=0; i--)
|
||||
allKeys.append(QString("pkgcount") + QString::number(i));
|
||||
// custom
|
||||
for (int i=counts[QString("custom")].toInt()-1; i>=0; i--)
|
||||
for (int i=extScripts.count()-1; i>=0; i--)
|
||||
allKeys.append(QString("custom") + QString::number(i));
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
@ -243,6 +279,74 @@ QStringList AWKeys::dictKeys()
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getDiskDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
diskDevices.sort();
|
||||
|
||||
return diskDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getFanDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
fanDevices.sort();
|
||||
|
||||
return fanDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getHddDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList allDevices = QDir(QString("/dev")).entryList(QDir::System, QDir::Name);
|
||||
QStringList devices = allDevices.filter(QRegExp(QString("^[hms]d[a-z]$")));
|
||||
for (int i=0; i<devices.count(); i++)
|
||||
devices[i] = QString("/dev/") + devices[i];
|
||||
devices.sort();
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getMountDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mountDevices.sort();
|
||||
|
||||
return mountDevices;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getNetworkDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList interfaceList;
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||
interfaceList.append(rawInterfaceList[i].name());
|
||||
interfaceList.sort();
|
||||
|
||||
return interfaceList;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWKeys::getTempDevices()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
tempDevices.sort();
|
||||
|
||||
return tempDevices;
|
||||
}
|
||||
|
||||
|
||||
void AWKeys::setDataBySource(const QString sourceName,
|
||||
const QMap<QString, QVariant> data,
|
||||
const QMap<QString, QVariant> params)
|
||||
@ -250,6 +354,10 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Source" << sourceName;
|
||||
|
||||
// checking
|
||||
if (!checkKeys(data)) return;
|
||||
if (!ready) return;
|
||||
|
||||
// regular expressions
|
||||
QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad"));
|
||||
QRegExp cpuclRegExp = QRegExp(QString("cpu/cpu.*/clock"));
|
||||
@ -307,7 +415,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// read speed
|
||||
QString device = sourceName;
|
||||
device.remove(QString("/Rate/rblk"));
|
||||
for (int i=0; i<counts[QString("disk")].toInt(); i++)
|
||||
for (int i=0; i<diskDevices.count(); i++)
|
||||
if (params[QString("disk")].toString().split(QString("@@"))[i] == device) {
|
||||
values[QString("hddr") + QString::number(i)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 0);
|
||||
break;
|
||||
@ -316,7 +424,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// write speed
|
||||
QString device = sourceName;
|
||||
device.remove(QString("/Rate/wblk"));
|
||||
for (int i=0; i<counts[QString("disk")].toInt(); i++)
|
||||
for (int i=0; i<diskDevices.count(); i++)
|
||||
if (params[QString("disk")].toString().split(QString("@@"))[i] == device) {
|
||||
values[QString("hddw") + QString::number(i)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 0);
|
||||
break;
|
||||
@ -332,7 +440,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// fill level
|
||||
QString mount = sourceName;
|
||||
mount.remove(QString("partitions")).remove(QString("/filllevel"));
|
||||
for (int i=0; i<counts[QString("mount")].toInt(); i++)
|
||||
for (int i=0; i<mountDevices.count(); i++)
|
||||
if (params[QString("mount")].toString().split(QString("@@"))[i] == mount) {
|
||||
values[QString("hdd") + QString::number(i)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1);
|
||||
break;
|
||||
@ -341,7 +449,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// free space
|
||||
QString mount = sourceName;
|
||||
mount.remove(QString("partitions")).remove(QString("/freespace"));
|
||||
for (int i=0; i<counts[QString("mount")].toInt(); i++)
|
||||
for (int i=0; i<mountDevices.count(); i++)
|
||||
if (params[QString("mount")].toString().split(QString("@@"))[i] == mount) {
|
||||
values[QString("hddfreemb") + QString::number(i)] = QString("%1").arg(
|
||||
data[QString("value")].toFloat() / 1024.0, 5, 'f', 0);
|
||||
@ -353,7 +461,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// used
|
||||
QString mount = sourceName;
|
||||
mount.remove(QString("partitions")).remove(QString("/usedspace"));
|
||||
for (int i=0; i<counts[QString("mount")].toInt(); i++)
|
||||
for (int i=0; i<mountDevices.count(); i++)
|
||||
if (params[QString("mount")].toString().split(QString("@@"))[i] == mount) {
|
||||
values[QString("hddmb") + QString::number(i)] = QString("%1").arg(
|
||||
data[QString("value")].toFloat() / 1024.0, 5, 'f', 0);
|
||||
@ -371,7 +479,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
} else if (sourceName == QString("hddtemp")) {
|
||||
// hdd temperature
|
||||
for (int i=0; i<data.keys().count(); i++)
|
||||
for (int j=0; j<counts[QString("hddtemp")].toInt(); j++)
|
||||
for (int j=0; j<getHddDevices().count(); j++)
|
||||
if (data.keys()[i] == params[QString("hdd")].toString().split(QString("@@"))[j]) {
|
||||
values[QString("hddtemp") + QString::number(j)] = QString("%1").arg(
|
||||
temperature(data[data.keys()[i]].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
|
||||
@ -405,7 +513,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// download speed
|
||||
QString device = sourceName;
|
||||
device.remove(QString("network/interfaces/")).remove(QString("/receiver/data"));
|
||||
if (device == networkDevice(params[QString("customNetdev")].toString())) {
|
||||
if (device == networkDevice()) {
|
||||
values[QString("down")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
|
||||
toolTip->setData(QString("down"), data[QString("value")].toFloat());
|
||||
}
|
||||
@ -413,7 +521,7 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
// upload speed
|
||||
QString device = sourceName;
|
||||
device.remove(QString("network/interfaces/")).remove(QString("/transmitter/data"));
|
||||
if (device == networkDevice(params[QString("customNetdev")].toString())) {
|
||||
if (device == networkDevice()) {
|
||||
values[QString("up")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0);
|
||||
toolTip->setData(QString("up"), data[QString("value")].toFloat());
|
||||
}
|
||||
@ -453,13 +561,13 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
} else if (sourceName.contains(tempRegExp)) {
|
||||
// temperature devices
|
||||
if (data[QString("units")].toString() == QString("rpm")) {
|
||||
for (int i=0; i<counts[QString("fan")].toInt(); i++)
|
||||
for (int i=0; i<fanDevices.count(); i++)
|
||||
if (sourceName == params[QString("fanDevice")].toString().split(QString("@@"))[i]) {
|
||||
values[QString("fan") + QString::number(i)] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (int i=0; i<counts[QString("temp")].toInt(); i++)
|
||||
for (int i=0; i<tempDevices.count(); i++)
|
||||
if (sourceName == params[QString("tempDevice")].toString().split(QString("@@"))[i]) {
|
||||
values[QString("temp") + QString::number(i)] = QString("%1").arg(
|
||||
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
|
||||
@ -496,6 +604,23 @@ void AWKeys::setDataBySource(const QString sourceName,
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::graphicalValueByKey()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
bool ok;
|
||||
QString tag = QInputDialog::getItem(0, i18n("Select tag"),
|
||||
i18n("Tag"), keys, 0, false, &ok);
|
||||
|
||||
if ((!ok) || (tag.isEmpty())) return QString("");
|
||||
QString message = i18n("Tag: %1", tag);
|
||||
message += QString("<br>");
|
||||
message += i18n("Value: %1", valueByKey(tag));
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::valueByKey(QString key)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -638,7 +763,7 @@ void AWKeys::copyBar(const QString original)
|
||||
if (exit) break;
|
||||
}
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_applet_awesome-widget/desktops"),
|
||||
QString("awesomewidgets/desktops"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(0, i18n("Enter file name"),
|
||||
@ -685,7 +810,7 @@ void AWKeys::copyScript(const QString original)
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_dataengine_extsysmon/scripts"),
|
||||
QString("awesomewidgets/scripts"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(0, i18n("Enter file name"),
|
||||
@ -724,7 +849,7 @@ void AWKeys::copyUpgrade(const QString original)
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_dataengine_extsysmon/upgrade"),
|
||||
QString("awesomewidgets/upgrade"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(0, i18n("Enter file name"),
|
||||
@ -755,23 +880,20 @@ void AWKeys::copyUpgrade(const QString original)
|
||||
}
|
||||
|
||||
|
||||
QString AWKeys::networkDevice(const QString custom)
|
||||
QString AWKeys::networkDevice()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Custom device" << custom;
|
||||
|
||||
QString device = QString("lo");
|
||||
if (custom.isEmpty()) {
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
|
||||
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)) &&
|
||||
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsPointToPoint))) {
|
||||
device = rawInterfaceList[i].name();
|
||||
break;
|
||||
}
|
||||
} else
|
||||
device = custom;
|
||||
QList<QNetworkInterface> rawInterfaceList = QNetworkInterface::allInterfaces();
|
||||
for (int i=0; i<rawInterfaceList.count(); i++)
|
||||
if ((rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsUp)) &&
|
||||
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsLoopBack)) &&
|
||||
(!rawInterfaceList[i].flags().testFlag(QNetworkInterface::IsPointToPoint))) {
|
||||
device = rawInterfaceList[i].name();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
@ -842,24 +964,6 @@ QStringList AWKeys::findKeys(const QString pattern)
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> AWKeys::getCounts(const QMap<QString, QVariant> params)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QMap<QString, QVariant> awCounts;
|
||||
awCounts[QString("cpu")] = numberCpus();
|
||||
awCounts[QString("custom")] = extScripts.count();
|
||||
awCounts[QString("disk")] = params[QString("disk")].toString().split(QString("@@")).count();
|
||||
awCounts[QString("fan")] = params[QString("fanDevice")].toString().split(QString("@@")).count();
|
||||
awCounts[QString("hddtemp")] = params[QString("hdd")].toString().split(QString("@@")).count();
|
||||
awCounts[QString("mount")] = params[QString("mount")].toString().split(QString("@@")).count();
|
||||
awCounts[QString("pkg")] = extUpgrade.count();
|
||||
awCounts[QString("temp")] = params[QString("tempDevice")].toString().split(QString("@@")).count();
|
||||
|
||||
return awCounts;
|
||||
}
|
||||
|
||||
|
||||
QList<ExtScript *> AWKeys::getExtScripts()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -867,13 +971,13 @@ QList<ExtScript *> AWKeys::getExtScripts()
|
||||
QList<ExtScript *> externalScripts;
|
||||
// create directory at $HOME
|
||||
QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||
QString("/plasma_dataengine_extsysmon/scripts");
|
||||
QString("/awesomewidgets/scripts");
|
||||
QDir localDirectory;
|
||||
if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir)))
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_dataengine_extsysmon/scripts"),
|
||||
QString("awesomewidgets/scripts"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
for (int i=0; i<dirs.count(); i++) {
|
||||
@ -898,13 +1002,13 @@ QList<ExtUpgrade *> AWKeys::getExtUpgrade()
|
||||
QList<ExtUpgrade *> externalUpgrade;
|
||||
// create directory at $HOME
|
||||
QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||
QString("/plasma_dataengine_extsysmon/upgrade");
|
||||
QString("/awesomewidgets/upgrade");
|
||||
QDir localDirectory;
|
||||
if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir)))
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_dataengine_extsysmon/upgrade"),
|
||||
QString("awesomewidgets/upgrade"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
for (int i=0; i<dirs.count(); i++) {
|
||||
@ -929,13 +1033,13 @@ QList<GraphicalItem *> AWKeys::getGraphicalItems()
|
||||
QList<GraphicalItem *> items;
|
||||
// create directory at $HOME
|
||||
QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
|
||||
QString("/plasma_applet_awesome-widget/desktops");
|
||||
QString("/awesomewidgets/desktops");
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("plasma_applet_awesome-widget/desktops"),
|
||||
QString("awesomewidgets/desktops"),
|
||||
QStandardPaths::LocateDirectory);
|
||||
QStringList names;
|
||||
for (int i=0; i<dirs.count(); i++) {
|
||||
|
@ -50,19 +50,26 @@ public:
|
||||
AWKeys(QObject *parent = 0);
|
||||
~AWKeys();
|
||||
|
||||
Q_INVOKABLE bool checkKeys(const QMap<QString, QVariant> data);
|
||||
Q_INVOKABLE void initKeys(const QString pattern,
|
||||
const QMap<QString, QVariant> params,
|
||||
const QMap<QString, QVariant> tooltipParams);
|
||||
Q_INVOKABLE bool isDebugEnabled();
|
||||
Q_INVOKABLE bool isReady();
|
||||
Q_INVOKABLE QString parsePattern(const QString pattern);
|
||||
Q_INVOKABLE QPixmap toolTipImage();
|
||||
// keys
|
||||
Q_INVOKABLE void addDevice(const QString source);
|
||||
Q_INVOKABLE QStringList dictKeys();
|
||||
Q_INVOKABLE QStringList getDiskDevices();
|
||||
Q_INVOKABLE QStringList getFanDevices();
|
||||
Q_INVOKABLE QStringList getHddDevices();
|
||||
Q_INVOKABLE QStringList getMountDevices();
|
||||
Q_INVOKABLE QStringList getNetworkDevices();
|
||||
Q_INVOKABLE QStringList getTempDevices();
|
||||
Q_INVOKABLE void setDataBySource(const QString sourceName,
|
||||
const QMap<QString, QVariant> data,
|
||||
const QMap<QString, QVariant> params);
|
||||
// values
|
||||
Q_INVOKABLE QString graphicalValueByKey();
|
||||
Q_INVOKABLE QString valueByKey(QString key);
|
||||
// configuration
|
||||
Q_INVOKABLE void editItem(const QString type);
|
||||
@ -75,14 +82,13 @@ private slots:
|
||||
|
||||
private:
|
||||
// methods
|
||||
QString networkDevice(const QString custom = QString(""));
|
||||
QString networkDevice();
|
||||
int numberCpus();
|
||||
float temperature(const float temp, const QString units = QString("Celsius"));
|
||||
// find methods
|
||||
QStringList findGraphicalItems(const QString pattern);
|
||||
QStringList findKeys(const QString pattern);
|
||||
// get methods
|
||||
QMap<QString, QVariant> getCounts(const QMap<QString, QVariant> params);
|
||||
QList<ExtScript *> getExtScripts();
|
||||
QList<ExtUpgrade *> getExtUpgrade();
|
||||
QList<GraphicalItem *> getGraphicalItems();
|
||||
@ -103,8 +109,8 @@ private:
|
||||
QList<ExtScript *> extScripts;
|
||||
QList<ExtUpgrade *> extUpgrade;
|
||||
QStringList foundBars, foundKeys, keys;
|
||||
QMap<QString, QVariant> counts;
|
||||
QMap<QString, QString> values;
|
||||
QStringList diskDevices, fanDevices, mountDevices, tempDevices;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user