/*************************************************************************** * This file is part of pytextmonitor * * * * pytextmonitor 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. * * * * pytextmonitor 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 pytextmonitor. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ #include "awesome-widget.h" #include #include #include #include #include #include #include #include #include "customlabel.h" #include #include AwesomeWidget::AwesomeWidget(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args) { // debug QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); QString debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); if (debugEnv == QString("yes")) debug = true; else debug = false; setHasConfigurationInterface(true); // text format init formatLine.append(QString("")); formatLine.append(QString("")); } AwesomeWidget::~AwesomeWidget() { } QString AwesomeWidget::getNetworkDevice() { if (debug) qDebug() << PDEBUG; QString device = QString("lo"); if (configuration[QString("useCustomNetdev")].toInt() == 2) device = configuration[QString("customNetdev")]; else { QList rawInterfaceList = QNetworkInterface::allInterfaces(); for (int i=0; itoUnicode(process.output).toInt(); } float AwesomeWidget::getTemp(const float temp) { if (debug) qDebug() << PDEBUG; float convertedTemp = temp; if (configuration[QString("tempUnits")] == QString("Celsius")) ; else if (configuration[QString("tempUnits")] == QString("Fahrenheit")) convertedTemp = temp * 9.0 / 5.0 + 32.0; else if (configuration[QString("tempUnits")] == QString("Kelvin")) convertedTemp = temp + 273.15; else if (configuration[QString("tempUnits")] == QString("Reaumur")) convertedTemp = temp * 0.8; else if (configuration[QString("tempUnits")] == QString("cm^-1")) convertedTemp = temp * 0.695; else if (configuration[QString("tempUnits")] == QString("kJ/mol")) convertedTemp = temp * 8.31; else if (configuration[QString("tempUnits")] == QString("kcal/mol")) convertedTemp = temp * 1.98; return convertedTemp; } QStringList AwesomeWidget::getTimeKeys() { if (debug) qDebug() << PDEBUG; QStringList timeKeys; timeKeys.append(QString("d")); timeKeys.append(QString("dd")); timeKeys.append(QString("ddd")); timeKeys.append(QString("dddd")); timeKeys.append(QString("M")); timeKeys.append(QString("MM")); timeKeys.append(QString("MMM")); timeKeys.append(QString("MMMM")); timeKeys.append(QString("yy")); timeKeys.append(QString("yyyy")); timeKeys.append(QString("h")); timeKeys.append(QString("hh")); timeKeys.append(QString("m")); timeKeys.append(QString("mm")); timeKeys.append(QString("s")); timeKeys.append(QString("ss")); return timeKeys; } void AwesomeWidget::init() { if (debug) qDebug() << PDEBUG; // dataengines extsysmonEngine = dataEngine(QString("ext-sysmon")); sysmonEngine = dataEngine(QString("systemmonitor")); timeEngine = dataEngine(QString("time")); // tooltip toolTip = Plasma::ToolTipContent(); toolTip.setMainText(QString("Awesome Widget")); toolTip.setSubText(QString("")); toolTipScene = new QGraphicsScene(); toolTipView = new QGraphicsView(toolTipScene); toolTipView->setStyleSheet(QString("background: transparent")); toolTipView->setContentsMargins(0, 0, 0, 0); toolTipView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); toolTipView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); Plasma::ToolTipManager::self()->setContent(this, toolTip); // body mainLayout = new QGraphicsLinearLayout(); mainLayout->setContentsMargins(1, 1, 1, 1); setLayout(mainLayout); textLabel = new CustomLabel(this, debug); // read variables configChanged(); timer = new QTimer(this); timer->setSingleShot(false); timer->setInterval(configuration[QString("interval")].toInt()); connect(timer, SIGNAL(timeout()), this, SLOT(updateText())); connect(timer, SIGNAL(timeout()), this, SLOT(updateTooltip())); timer->start(); } QStringList AwesomeWidget::findKeys() { if (debug) qDebug() << PDEBUG; QStringList selectedKeys; for (int i=0; i -1) { if (debug) qDebug() << PDEBUG << ":" << "Found key" << keys[i]; selectedKeys.append(keys[i]); } return selectedKeys; } QStringList AwesomeWidget::getKeys() { 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")); // cpu allKeys.append(QString("cpu")); for (int i=0; i