diff --git a/sources/.kdev4/sources.kdev4 b/sources/.kdev4/sources.kdev4 index b97529b..ea73c1d 100644 --- a/sources/.kdev4/sources.kdev4 +++ b/sources/.kdev4/sources.kdev4 @@ -8,7 +8,7 @@ ProjectRootRelative=./ [CMake][CMake Build Directory 0] Build Directory Path=file:///home/arcanis/Documents/github/awesome-widgets/build -Build Type=Debug +Build Type=Release CMake Binary=file:///usr/bin/cmake Environment Profile= Extra Arguments= diff --git a/sources/awesome-widget-kf5/package/contents/ui/dataengine.qml b/sources/awesome-widget-kf5/package/contents/ui/dataengine.qml index bb39b9f..c03bd29 100644 --- a/sources/awesome-widget-kf5/package/contents/ui/dataengine.qml +++ b/sources/awesome-widget-kf5/package/contents/ui/dataengine.qml @@ -105,7 +105,7 @@ Item { id: gpuDev width: parent.width * 3 / 5 model: ["auto", "disable", "ati", "nvidia"] - onCurrentIndexChanged: cfg_dataengine["GPUDEV"] = gpuDev.currentText + onCurrentIndexChanged: cfg_dataengine["GPUDEV"] = model[currentIndex] Component.onCompleted: { for (var i=0; i + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "awactions.h" +#include "extquotes.h" +#include "extscript.h" +#include "extupgrade.h" +#include "graphicalitem.h" +#include "version.h" + + +AWKeysOperations::AWKeysOperations(QObject *parent) + : QObject(parent) +{ + // debug + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString debugEnv = environment.value(QString("DEBUG"), QString("no")); + debug = (debugEnv == QString("yes")); + + // signals + connect(this, SIGNAL(sourceAdded(QString)), this, SLOT(addSource(QString))); + + // init dialog + dialog = new QDialog(nullptr); + widgetDialog = new QListWidget(dialog); + dialogButtons = new QDialogButtonBox(QDialogButtonBox::Open | QDialogButtonBox::Close, + Qt::Vertical, dialog); + copyButton = dialogButtons->addButton(i18n("Copy"), QDialogButtonBox::ActionRole); + createButton = dialogButtons->addButton(i18n("Create"), QDialogButtonBox::ActionRole); + deleteButton = dialogButtons->addButton(i18n("Remove"), QDialogButtonBox::ActionRole); + QHBoxLayout *layout = new QHBoxLayout(dialog); + layout->addWidget(widgetDialog); + layout->addWidget(dialogButtons); + dialog->setLayout(layout); + connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)), this, SLOT(editItemButtonPressed(QAbstractButton *))); + connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject())); +} + + +AWKeysOperations::~AWKeysOperations() +{ + if (debug) qDebug() << PDEBUG; + + delete createButton; + delete copyButton; + delete deleteButton; + delete dialogButtons; + delete widgetDialog; + delete dialog; + + graphicalItems.clear(); + extScripts.clear(); + extUpgrade.clear(); +} + + +AWKeysOperations::AWStruct AWKeysOperations::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.*/.*")); + + AWKeysOperations::AWStruct str; + 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); + } else { + if (debug) qDebug() << PDEBUG << ":" << "Source" << source << "not found"; + } + + return str; +} + + +QStringList AWKeys::dictKeys() +{ + if (debug) qDebug() << PDEBUG; + + QStringList allKeys; + // time + allKeys.append(QString("time")); + allKeys.append(QString("isotime")); + allKeys.append(QString("shorttime")); + allKeys.append(QString("longtime")); + allKeys.append(QString("ctime")); + // uptime + allKeys.append(QString("uptime")); + allKeys.append(QString("cuptime")); + // cpuclock + for (int i=numberCpus()-1; i>=0; i--) + allKeys.append(QString("cpucl%1").arg(i)); + allKeys.append(QString("cpucl")); + // cpu + for (int i=numberCpus()-1; i>=0; i--) + allKeys.append(QString("cpu%1").arg(i)); + allKeys.append(QString("cpu")); + // temperature + for (int i=tempDevices.count()-1; i>=0; i--) + allKeys.append(QString("temp%1").arg(i)); + for (int i=fanDevices.count()-1; i>=0; i--) + allKeys.append(QString("fan%1").arg(i)); + // gputemp + allKeys.append(QString("gputemp")); + // gpu + allKeys.append(QString("gpu")); + // memory + allKeys.append(QString("memmb")); + allKeys.append(QString("memgb")); + allKeys.append(QString("memfreemb")); + allKeys.append(QString("memfreegb")); + allKeys.append(QString("memtotmb")); + allKeys.append(QString("memtotgb")); + allKeys.append(QString("memusedmb")); + allKeys.append(QString("memusedgb")); + allKeys.append(QString("mem")); + // swap + allKeys.append(QString("swapmb")); + allKeys.append(QString("swapgb")); + allKeys.append(QString("swapfreemb")); + allKeys.append(QString("swapfreegb")); + allKeys.append(QString("swaptotmb")); + allKeys.append(QString("swaptotgb")); + allKeys.append(QString("swap")); + // hdd + for (int i=mountDevices.count()-1; i>=0; i--) { + allKeys.append(QString("hddmb%1").arg(i)); + allKeys.append(QString("hddgb%1").arg(i)); + allKeys.append(QString("hddfreemb%1").arg(i)); + allKeys.append(QString("hddfreegb%1").arg(i)); + allKeys.append(QString("hddtotmb%1").arg(i)); + allKeys.append(QString("hddtotgb%1").arg(i)); + allKeys.append(QString("hdd%1").arg(i)); + } + // hdd speed + for (int i=diskDevices.count()-1; i>=0; i--) { + allKeys.append(QString("hddr%1").arg(i)); + allKeys.append(QString("hddw%1").arg(i)); + } + // hdd temp + for (int i=getHddDevices().count()-1; i>=0; i--) { + allKeys.append(QString("hddtemp%1").arg(i)); + allKeys.append(QString("hddtemp%1").arg(i)); + } + // network + for (int i=getNetworkDevices().count()-1; i>=0; i--) { + allKeys.append(QString("down%1").arg(i)); + allKeys.append(QString("up%1").arg(i)); + } + allKeys.append(QString("down")); + allKeys.append(QString("up")); + allKeys.append(QString("netdev")); + // battery + allKeys.append(QString("ac")); + 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%1").arg(i)); + allKeys.append(QString("bat")); + // player + allKeys.append(QString("album")); + allKeys.append(QString("artist")); + allKeys.append(QString("duration")); + allKeys.append(QString("progress")); + allKeys.append(QString("title")); + // ps + allKeys.append(QString("pscount")); + allKeys.append(QString("pstotal")); + allKeys.append(QString("ps")); + // package manager + for (int i=extUpgrade.count()-1; i>=0; i--) + allKeys.append(QString("pkgcount%1").arg(i)); + // quotes + for (int i=extQuotes.count()-1; i>=0; i--) { + allKeys.append(QString("ask%1").arg(i)); + allKeys.append(QString("bid%1").arg(i)); + allKeys.append(QString("price%1").arg(i)); + } + // custom + for (int i=extScripts.count()-1; i>=0; i--) + allKeys.append(QString("custom%1").arg(i)); + // desktop + allKeys.append(QString("desktop")); + allKeys.append(QString("ndesktop")); + allKeys.append(QString("tdesktops")); + // bars + QStringList graphicalItemsKeys; + for (int i=0; iname() + graphicalItems[i]->bar()); + graphicalItemsKeys.sort(); + for (int i=graphicalItemsKeys.count()-1; i>=0; i--) + allKeys.append(graphicalItemsKeys[i]); + + return allKeys; +} + + +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(const bool needAbstract) +{ + 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 rawInterfaceList = QNetworkInterface::allInterfaces(); + for (int i=0; i data, + const QMap params) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Source" << sourceName; + + if (sourceName == QString("update")) return true; + + // checking + if (!checkKeys(data)) return false; + if (!ready) return false; + + // regular expressions + QRegExp cpuRegExp = QRegExp(QString("cpu/cpu.*/TotalLoad")); + QRegExp cpuclRegExp = QRegExp(QString("cpu/cpu.*/clock")); + QRegExp hddrRegExp = QRegExp(QString("disk/.*/Rate/rblk")); + QRegExp hddwRegExp = QRegExp(QString("disk/.*/Rate/wblk")); + QRegExp mountFillRegExp = QRegExp(QString("partitions/.*/filllevel")); + QRegExp mountFreeRegExp = QRegExp(QString("partitions/.*/freespace")); + QRegExp mountUsedRegExp = QRegExp(QString("partitions/.*/usedspace")); + QRegExp netRecRegExp = QRegExp(QString("network/interfaces/.*/receiver/data")); + QRegExp netTransRegExp = QRegExp(QString("network/interfaces/.*/transmitter/data")); + QRegExp tempRegExp = QRegExp(QString("lmsensors/.*")); + + if (sourceName == QString("battery")) { + // battery + for (int i=0; isetData(QString("batTooltip"), data[data.keys()[i]].toFloat(), data[QString("ac")].toBool()); + } + } + } else if (sourceName == QString("cpu/system/TotalLoad")) { + // cpu + // notification + if ((data[QString("value")].toFloat() >= 90.0) && (values[QString("cpu")].toFloat() < 90.0)) + AWActions::sendNotification(QString("event"), i18n("High CPU load"), enablePopup); + // value + values[QString("cpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1); + toolTip->setData(QString("cpuTooltip"), data[QString("value")].toFloat()); + } else if (sourceName.contains(cpuRegExp)) { + // cpus + QString number = sourceName; + number.remove(QString("cpu/cpu")).remove(QString("/TotalLoad")); + values[QString("cpu") + number] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1); + } else if (sourceName == QString("cpu/system/AverageClock")) { + // cpucl + values[QString("cpucl")] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0); + toolTip->setData(QString("cpuclTooltip"), data[QString("value")].toFloat()); + } else if (sourceName.contains(cpuclRegExp)) { + // cpucls + QString number = sourceName; + number.remove(QString("cpu/cpu")).remove(QString("/clock")); + values[QString("cpucl") + number] = QString("%1").arg(data[QString("value")].toFloat(), 4, 'f', 0); + } else if (sourceName == QString("custom")) { + // custom + for (int i=0; i= 90.0) && (values[QString("gpu")].toFloat() < 90.0)) + AWActions::sendNotification(QString("event"), i18n("High GPU load"), enablePopup); + // value + values[QString("gpu")] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1); + } else if (sourceName == QString("gputemp")) { + // gpu temperature + values[QString("gputemp")] = QString("%1").arg( + temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1); + } else if (sourceName.contains(mountFillRegExp)) { + // fill level + QString mount = sourceName; + mount.remove(QString("partitions")).remove(QString("/filllevel")); + for (int i=0; i= 90.0) && (values[QString("hdd%1").arg(i)].toFloat() < 90.0)) + AWActions::sendNotification(QString("event"), i18n("Free space on %1 less than 10%", mount), enablePopup); + values[QString("hdd%1").arg(i)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 1); + break; + } + } else if (sourceName.contains(mountFreeRegExp)) { + // free space + QString mount = sourceName; + mount.remove(QString("partitions")).remove(QString("/freespace")); + for (int i=0; i= 90.0) && (values[QString("mem")].toFloat() < 90.0)) + AWActions::sendNotification(QString("event"), i18n("High memory usage"), enablePopup); + // value + values[QString("mem")] = QString("%1").arg(value, 5, 'f', 1); + toolTip->setData(QString("memTooltip"), values[QString("mem")].toFloat()); + } else if (sourceName == QString("netdev")) { + // network device + // notification + if (values[QString("netdev")] != data[QString("value")].toString()) + AWActions::sendNotification(QString("event"), i18n("Network device has been changed to %1", + data[QString("value")].toString()), + enablePopup); + // value + values[QString("netdev")] = data[QString("value")].toString(); + } else if (sourceName.contains(netRecRegExp)) { + // download speed + QString device = sourceName; + device.remove(QString("network/interfaces/")).remove(QString("/receiver/data")); + QStringList allNetworkDevices = getNetworkDevices(); + for (int i=0; isetData(QString("downTooltip"), data[QString("value")].toFloat()); + } + } else if (sourceName.contains(netTransRegExp)) { + // upload speed + QString device = sourceName; + device.remove(QString("network/interfaces/")).remove(QString("/transmitter/data")); + QStringList allNetworkDevices = getNetworkDevices(); + for (int i=0; isetData(QString("upTooltip"), data[QString("value")].toFloat()); + } + } else if (sourceName == QString("pkg")) { + // package manager + for (int i=0; i 0.0) && (values[QString("swap")].toFloat() == 0.0)) + AWActions::sendNotification(QString("event"), i18n("Swap is used"), enablePopup); + // value + values[QString("swap")] = QString("%1").arg(value, 5, 'f', 1); + toolTip->setData(QString("swapTooltip"), values[QString("swap")].toFloat()); + } else if (sourceName.contains(tempRegExp)) { + // temperature devices + if (data[QString("units")].toString() == QString("rpm")) { + for (int i=0; i"); + message += i18n("Value: %1", valueByKey(tag)); + + return AWActions::sendNotification(QString("tag"), message); +} + + +QString AWKeys::infoByKey(QString key) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Requested key" << key; + + key.remove(QRegExp(QString("^bar[0-9]{1,}"))); + if (key.startsWith(QString("custom"))) + return QString("%1").arg(extScripts[key.remove(QString("custom")).toInt()]->executable()); + else if (key.contains(QRegExp(QString("^hdd[rw]")))) + return QString("%1").arg(diskDevices[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]); + else if (key.startsWith(QString("fan"))) + return QString("%1").arg(fanDevices[key.remove(QString("fan")).toInt()]); + else if (key.contains(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))) + return QString("%1").arg(mountDevices[key.remove(QRegExp(QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))).toInt()]); + else if (key.startsWith(QString("hddtemp"))) + return QString("%1").arg(getHddDevices()[key.remove(QString("hddtemp")).toInt()]); + else if (key.contains(QRegExp(QString("^(down|up)[0-9]")))) + return QString("%1").arg(getNetworkDevices()[key.remove(QRegExp(QString("^(down|up)"))).toInt()]); + else if (key.startsWith(QString("pkgcount"))) + return QString("%1").arg(extUpgrade[key.remove(QString("pkgcount")).toInt()]->executable()); + else if ((key.startsWith(QString("ask"))) || + (key.startsWith(QString("bid"))) || + (key.startsWith(QString("price")))) + return QString("%1").arg(extQuotes[key.remove(QRegExp(QString("^(ask|bid|price)"))).toInt()]->ticker()); + else if (key.startsWith(QString("temp"))) + return QString("%1").arg(tempDevices[key.remove(QString("temp")).toInt()]); + + return QString("(none)"); +} + + +QString AWKeys::valueByKey(QString key) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Requested key" << key; + + key.remove(QRegExp(QString("^bar[0-9]{1,}"))); + + return values[key]; +} + + +void AWKeys::editItem(const QString type) +{ + if (debug) qDebug() << PDEBUG; + + widgetDialog->clear(); + if (type == QString("graphicalitem")) { + requestedItem = RequestedGraphicalItem; + for (int i=0; ifileName()); + QStringList tooltip; + tooltip.append(i18n("Tag: %1", graphicalItems[i]->name() + graphicalItems[i]->bar())); + tooltip.append(i18n("Comment: %1", graphicalItems[i]->comment())); + item->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(item); + } + } else if (type == QString("extquotes")) { + requestedItem = RequestedExtQuotes; + for (int i=0; ifileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", extQuotes[i]->name())); + tooltip.append(i18n("Comment: %1", extQuotes[i]->comment())); + tooltip.append(i18n("Ticker: %1", extQuotes[i]->ticker())); + item->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(item); + } + } else if (type == QString("extscript")) { + requestedItem = RequestedExtScript; + for (int i=0; ifileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", extScripts[i]->name())); + tooltip.append(i18n("Comment: %1", extScripts[i]->comment())); + tooltip.append(i18n("Exec: %1", extScripts[i]->executable())); + item->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(item); + } + } else if (type == QString("extupgrade")) { + requestedItem = RequestedExtUpgrade; + for (int i=0; ifileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", extUpgrade[i]->name())); + tooltip.append(i18n("Comment: %1", extUpgrade[i]->comment())); + tooltip.append(i18n("Exec: %1", extUpgrade[i]->executable())); + item->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(item); + } + } + + int ret = dialog->exec(); + if (debug) qDebug() << PDEBUG << ":" << "Dialog returns" << ret; + requestedItem = Nothing; +} + + +void AWKeys::addSource(const QString source) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Source" << source; +} + + +void AWKeys::editItemButtonPressed(QAbstractButton *button) +{ + if (debug) qDebug() << PDEBUG; + + QListWidgetItem *item = widgetDialog->currentItem(); + if (dynamic_cast(button) == copyButton) { + if (item == nullptr) return; + QString current = item->text(); + switch (requestedItem) { + case RequestedExtQuotes: + copyQuotes(current); + break; + case RequestedExtScript: + copyScript(current); + break; + case RequestedExtUpgrade: + copyUpgrade(current); + break; + case RequestedGraphicalItem: + copyBar(current); + break; + case Nothing: + default: + break; + } + } else if (dynamic_cast(button) == createButton) { + switch (requestedItem) { + case RequestedExtQuotes: + copyQuotes(QString("")); + break; + case RequestedExtScript: + copyScript(QString("")); + break; + case RequestedExtUpgrade: + copyUpgrade(QString("")); + break; + case RequestedGraphicalItem: + copyBar(QString("")); + break; + case Nothing: + default: + break; + } + } else if (dynamic_cast(button) == deleteButton) { + if (item == nullptr) return; + QString current = item->text(); + switch (requestedItem) { + case RequestedExtQuotes: + for (int i=0; ifileName() != current) continue; + if (extQuotes[i]->tryDelete() == 1) { + widgetDialog->takeItem(widgetDialog->row(item)); + extQuotes.clear(); + extQuotes = getExtQuotes(); + } + break; + } + break; + case RequestedExtScript: + for (int i=0; ifileName() != current) continue; + if (extScripts[i]->tryDelete() == 1) { + widgetDialog->takeItem(widgetDialog->row(item)); + extScripts.clear(); + extScripts = getExtScripts(); + } + break; + } + break; + case RequestedExtUpgrade: + for (int i=0; ifileName() != current) continue; + if (extUpgrade[i]->tryDelete() == 1) { + widgetDialog->takeItem(widgetDialog->row(item)); + extUpgrade.clear(); + extUpgrade = getExtUpgrade(); + } + break; + } + break; + case RequestedGraphicalItem: + for (int i=0; ifileName() != current) continue; + if (graphicalItems[i]->tryDelete() == 1) { + widgetDialog->takeItem(widgetDialog->row(item)); + graphicalItems.clear(); + graphicalItems = getGraphicalItems(); + } + break; + } + break; + case Nothing: + default: + break; + } + } else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole) { + if (item == nullptr) return; + QString current = item->text(); + switch (requestedItem) { + case RequestedExtQuotes: + for (int i=0; ifileName() != current) continue; + extQuotes[i]->showConfiguration(); + break; + } + break; + case RequestedExtScript: + for (int i=0; ifileName() != current) continue; + extScripts[i]->showConfiguration(); + break; + } + break; + case RequestedExtUpgrade: + for (int i=0; ifileName() != current) continue; + extUpgrade[i]->showConfiguration(); + break; + } + break; + case RequestedGraphicalItem: + for (int i=0; ifileName() != current) continue; + graphicalItems[i]->showConfiguration(); + break; + } + break; + case Nothing: + default: + break; + } + } +} + + +void AWKeys::copyBar(const QString original) +{ + if (debug) qDebug() << PDEBUG; + + int number = 0; + while (true) { + bool exit = true; + for (int i=0; iname() == QString("bar%1").arg(number)) { + number++; + exit = false; + break; + } + if (exit) break; + } + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/desktops"), + QStandardPaths::LocateDirectory); + bool ok; + QString name = QInputDialog::getText(0, i18n("Enter file name"), + i18n("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return; + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + QStringList bars; + bars.append(keys.filter((QRegExp(QString("cpu(?!cl).*"))))); + bars.append(keys.filter((QRegExp(QString("^gpu$"))))); + bars.append(keys.filter((QRegExp(QString("^mem$"))))); + bars.append(keys.filter((QRegExp(QString("^swap$"))))); + bars.append(keys.filter((QRegExp(QString("^hdd[0-9].*"))))); + bars.append(keys.filter((QRegExp(QString("^bat.*"))))); + + int originalItem = -1; + for (int i=0; ifileName() != original) || + (graphicalItems[i]->fileName() != name)) + continue; + originalItem = i; + break; + } + GraphicalItem *item = new GraphicalItem(0, name, dirs, debug); + item->setName(QString("bar%1").arg(number)); + if (originalItem != -1) { + item->setComment(graphicalItems[originalItem]->comment()); + item->setBar(graphicalItems[originalItem]->bar()); + item->setActiveColor(graphicalItems[originalItem]->activeColor()); + item->setInactiveColor(graphicalItems[originalItem]->inactiveColor()); + item->setType(graphicalItems[originalItem]->type()); + item->setDirection(graphicalItems[originalItem]->direction()); + item->setHeight(graphicalItems[originalItem]->height()); + item->setWidth(graphicalItems[originalItem]->width()); + } + + if (item->showConfiguration(bars) == 1) { + graphicalItems.clear(); + graphicalItems = getGraphicalItems(); + QListWidgetItem *widgetItem = new QListWidgetItem(item->fileName()); + QStringList tooltip; + tooltip.append(i18n("Tag: %1", item->name() + item->bar())); + tooltip.append(i18n("Comment: %1", item->comment())); + widgetItem->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(widgetItem); + widgetDialog->sortItems(); + } + delete item; +} + + +void AWKeys::copyQuotes(const QString original) +{ + if (debug) qDebug() << PDEBUG; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/quotes"), + QStandardPaths::LocateDirectory); + bool ok; + QString name = QInputDialog::getText(0, i18n("Enter file name"), + i18n("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return; + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + + int originalItem = -1; + for (int i=0; ifileName() != original) || + (extQuotes[i]->fileName() != name)) + continue; + originalItem = i; + break; + } + ExtQuotes *quotes = new ExtQuotes(0, name, dirs, debug); + if (originalItem != -1) { + quotes->setActive(extQuotes[originalItem]->isActive()); + quotes->setComment(extQuotes[originalItem]->comment()); + quotes->setInterval(extQuotes[originalItem]->interval()); + quotes->setName(extQuotes[originalItem]->name()); + quotes->setTicker(extQuotes[originalItem]->ticker()); + } + + if (quotes->showConfiguration() == 1) { + extQuotes.clear(); + extQuotes = getExtQuotes(); + QListWidgetItem *widgetItem = new QListWidgetItem(quotes->fileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", quotes->name())); + tooltip.append(i18n("Comment: %1", quotes->comment())); + tooltip.append(i18n("Ticker: %1", quotes->ticker())); + widgetItem->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(widgetItem); + widgetDialog->sortItems(); + } + delete quotes; +} + + + +void AWKeys::copyScript(const QString original) +{ + if (debug) qDebug() << PDEBUG; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/scripts"), + QStandardPaths::LocateDirectory); + bool ok; + QString name = QInputDialog::getText(0, i18n("Enter file name"), + i18n("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return; + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + + int originalItem = -1; + for (int i=0; ifileName() != original) || + (extScripts[i]->fileName() != name)) + continue; + originalItem = i; + break; + } + ExtScript *script = new ExtScript(0, name, dirs, debug); + if (originalItem != -1) { + script->setActive(extScripts[originalItem]->isActive()); + script->setComment(extScripts[originalItem]->comment()); + script->setExecutable(extScripts[originalItem]->executable()); + script->setHasOutput(extScripts[originalItem]->hasOutput()); + script->setInterval(extScripts[originalItem]->interval()); + script->setName(extScripts[originalItem]->name()); + script->setPrefix(extScripts[originalItem]->prefix()); + script->setRedirect(extScripts[originalItem]->redirect()); + } + + if (script->showConfiguration() == 1) { + extScripts.clear(); + extScripts = getExtScripts(); + QListWidgetItem *widgetItem = new QListWidgetItem(script->fileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", script->name())); + tooltip.append(i18n("Comment: %1", script->comment())); + tooltip.append(i18n("Exec: %1", script->executable())); + widgetItem->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(widgetItem); + widgetDialog->sortItems(); + } + delete script; +} + + +void AWKeys::copyUpgrade(const QString original) +{ + if (debug) qDebug() << PDEBUG; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/upgrade"), + QStandardPaths::LocateDirectory); + bool ok; + QString name = QInputDialog::getText(0, i18n("Enter file name"), + i18n("File name"), QLineEdit::Normal, + QString(""), &ok); + if ((!ok) || (name.isEmpty())) return; + if (!name.endsWith(QString(".desktop"))) name += QString(".desktop"); + + int originalItem = -1; + for (int i=0; ifileName() != original) || + (extUpgrade[i]->fileName() != name)) + continue; + originalItem = i; + break; + } + ExtUpgrade *upgrade = new ExtUpgrade(0, name, dirs, debug); + if (originalItem != -1) { + upgrade->setActive(extUpgrade[originalItem]->isActive()); + upgrade->setComment(extUpgrade[originalItem]->comment()); + upgrade->setExecutable(extUpgrade[originalItem]->executable()); + upgrade->setName(extUpgrade[originalItem]->name()); + upgrade->setNull(extUpgrade[originalItem]->null()); + upgrade->setInterval(extUpgrade[originalItem]->interval()); + } + + if (upgrade->showConfiguration() == 1) { + extUpgrade.clear(); + extUpgrade = getExtUpgrade(); + QListWidgetItem *widgetItem = new QListWidgetItem(upgrade->fileName()); + QStringList tooltip; + tooltip.append(i18n("Name: %1", upgrade->name())); + tooltip.append(i18n("Comment: %1", upgrade->comment())); + tooltip.append(i18n("Exec: %1", upgrade->executable())); + widgetItem->setToolTip(tooltip.join(QChar('\n'))); + widgetDialog->addItem(widgetItem); + widgetDialog->sortItems(); + } + delete upgrade; +} + + +bool AWKeys::checkKeys(const QMap data) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Data" << data; + + return (data.count() != 0); +} + + +QString AWKeys::networkDevice() +{ + if (debug) qDebug() << PDEBUG; + + QString device = QString("lo"); + QList rawInterfaceList = QNetworkInterface::allInterfaces(); + for (int i=0; iname() + graphicalItems[i]->bar()); + orderedKeys.sort(); + + QStringList selectedKeys; + for (int i=orderedKeys.count()-1; i>=0; i--) + if (pattern.contains(QString("$") + orderedKeys[i])) { + if (debug) qDebug() << PDEBUG << ":" << "Found key" << orderedKeys[i]; + selectedKeys.append(orderedKeys[i]); + } + + return selectedKeys; +} + + +QStringList AWKeys::findKeys(const QString pattern) +{ + QStringList selectedKeys; + for (int i=0; i AWKeys::getExtQuotes() +{ + if (debug) qDebug() << PDEBUG; + + QList externalQuotes; + // create directory at $HOME + QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + QString("/awesomewidgets/quotes"); + QDir localDirectory; + if ((!localDirectory.exists(localDir)) && (localDirectory.mkpath(localDir))) + if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/quotes"), + QStandardPaths::LocateDirectory); + QStringList names; + for (int i=0; i AWKeys::getExtScripts() +{ + if (debug) qDebug() << PDEBUG; + + QList externalScripts; + // create directory at $HOME + QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + 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("awesomewidgets/scripts"), + QStandardPaths::LocateDirectory); + QStringList names; + for (int i=0; i AWKeys::getExtUpgrade() +{ + if (debug) qDebug() << PDEBUG; + + QList externalUpgrade; + // create directory at $HOME + QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + 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("awesomewidgets/upgrade"), + QStandardPaths::LocateDirectory); + QStringList names; + for (int i=0; i AWKeys::getGraphicalItems() +{ + if (debug) qDebug() << PDEBUG; + + QList items; + // create directory at $HOME + QString localDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + + QString("/awesomewidgets/desktops"); + QDir localDirectory; + if (localDirectory.mkpath(localDir)) + if (debug) qDebug() << PDEBUG << ":" << "Created directory" << localDir; + + QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, + QString("awesomewidgets/desktops"), + QStandardPaths::LocateDirectory); + QStringList names; + for (int i=0; iname() + graphicalItems[i]->bar()) != tag) continue; + item = graphicalItems[i]; + break; + } + + return item; +} + + +QStringList AWKeys::getTimeKeys() +{ + if (debug) qDebug() << PDEBUG; + + QStringList keys; + keys.append(QString("dddd")); + keys.append(QString("ddd")); + keys.append(QString("dd")); + keys.append(QString("d")); + keys.append(QString("MMMM")); + keys.append(QString("MMM")); + keys.append(QString("MM")); + keys.append(QString("M")); + keys.append(QString("yyyy")); + keys.append(QString("yy")); + keys.append(QString("hh")); + keys.append(QString("h")); + keys.append(QString("mm")); + keys.append(QString("m")); + keys.append(QString("ss")); + keys.append(QString("s")); + + return keys; +} diff --git a/sources/awesome-widget-kf5/plugin/awkeysop.h b/sources/awesome-widget-kf5/plugin/awkeysop.h new file mode 100644 index 0000000..0a35e1f --- /dev/null +++ b/sources/awesome-widget-kf5/plugin/awkeysop.h @@ -0,0 +1,126 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#ifndef AWKEYS_H +#define AWKEYS_H + +#include +#include +#include +#include +#include +#include +#include +#include + + +class ExtQuotes; +class ExtScript; +class ExtUpgrade; +class GraphicalItem; + +class AWKeysOperations : public QObject +{ + Q_OBJECT + + enum RequestedItem { + Nothing, + RequestedGraphicalItem, + RequestedExtQuotes, + RequestedExtScript, + RequestedExtUpgrade + }; + typedef struct { + QString key = QString(); + QString value = QString(); + } AWStruct; + +public: + AWKeysOperations(QObject *parent = 0); + ~AWKeysOperations(); + + // keys + AWStruct addDevice(const QString source); + Q_INVOKABLE QStringList dictKeys(); + Q_INVOKABLE QStringList getDiskDevices(); + Q_INVOKABLE QStringList getFanDevices(); + Q_INVOKABLE QStringList getHddDevices(const bool needAbstract = false); + Q_INVOKABLE QStringList getMountDevices(); + Q_INVOKABLE QStringList getNetworkDevices(); + Q_INVOKABLE QStringList getTempDevices(); + Q_INVOKABLE bool setDataBySource(const QString sourceName, + const QMap data, + const QMap params); + // values + Q_INVOKABLE void graphicalValueByKey(); + Q_INVOKABLE QString infoByKey(QString key); + Q_INVOKABLE QString valueByKey(QString key); + // configuration + Q_INVOKABLE void editItem(const QString type); + +signals: + void sourceAdded(const QString source); + +private slots: + void addSource(const QString source); + // editor + void editItemButtonPressed(QAbstractButton *button); + void copyBar(const QString original); + void copyQuotes(const QString original); + void copyScript(const QString original); + void copyUpgrade(const QString original); + +private: + // methods + bool checkKeys(const QMap data); + 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 + QList getExtQuotes(); + QList getExtScripts(); + QList getExtUpgrade(); + QList getGraphicalItems(); + GraphicalItem *getItemByTag(const QString tag); + QStringList getTimeKeys(); + // graphical elements + QDialog *dialog = nullptr; + QListWidget *widgetDialog = nullptr; + QDialogButtonBox *dialogButtons = nullptr; + QPushButton *copyButton = nullptr; + QPushButton *createButton = nullptr; + QPushButton *deleteButton = nullptr; + RequestedItem requestedItem = Nothing; + // variables + bool debug = false; + bool enablePopup = false; + bool ready = false; + QList graphicalItems; + QList extQuotes; + QList extScripts; + QList extUpgrade; + QStringList foundBars, foundKeys, keys; + QMap values; + QStringList diskDevices, fanDevices, mountDevices, tempDevices; +}; + + +#endif /* AWKEYS_H */