improve update events

This commit is contained in:
arcan1s 2015-07-20 00:21:39 +03:00
parent c7d998eb12
commit 1110929b14
13 changed files with 96 additions and 65 deletions

View File

@ -1,6 +1,9 @@
ver.2.3.4: Ver.2.3.4:
+ add support of load average (la1, la5, la15 tags)
- fix bug with invalid network data calculation - fix bug with invalid network data calculation
* update pattern parsing to recent plasma changes * improve work with data updating (#57)
* move plugin part back to private
* cast plugin as type, not signleton (#57)
Ver.2.3.3: Ver.2.3.3:
* change text rendering from Qt to native * change text rendering from Qt to native

View File

@ -1,3 +1,10 @@
Вер.2.3.4:
+ добавлена поддержа LA (теги la1, la5, la15)
- исправлен баг с неправильным расчетам скорости сети
* улучшена работа с обновлениями виджета (#57)
* плагин опять стал приватным
* исправлен каст плагина с синглтона (#57)
Вер.2.3.3: Вер.2.3.3:
* изменен рендеринг с Qt на нативный * изменен рендеринг с Qt на нативный

View File

@ -2,7 +2,7 @@
pkgname=plasma5-applet-awesome-widgets pkgname=plasma5-applet-awesome-widgets
_pkgname=awesome-widgets _pkgname=awesome-widgets
pkgver=2.3.3 pkgver=2.3.4
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')
@ -17,7 +17,7 @@ optdepends=("catalyst: for GPU monitor"
makedepends=('cmake' 'extra-cmake-modules') makedepends=('cmake' 'extra-cmake-modules')
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=('a40592d66d9b5149fc7d470dc3e355cb') md5sums=('74e5b45df042e81c20f5e8bf421451f8')
backup=('etc/xdg/plasma-dataengine-extsysmon.conf') backup=('etc/xdg/plasma-dataengine-extsysmon.conf')
prepare() { prepare() {

View File

@ -66,7 +66,8 @@ Item {
} }
signal dropSource(string sourceName) signal dropSource(string sourceName)
signal needUpdate signal needTextUpdate(string newText)
signal needToolTipUpdate(string newText)
signal sizeUpdate signal sizeUpdate
@ -91,7 +92,7 @@ Item {
onNewData: { onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName) if (debug) console.log("[main::onNewData] : Update source " + sourceName)
// FIXME: ugly workaround to make some sources working // FIXME: ugly workaround to make some sources working
systemmonitorDE.interval = plasmoid.configuration.interval // systemmonitorDE.interval = plasmoid.configuration.interval
awKeys.setDataBySource(sourceName, data, settings) awKeys.setDataBySource(sourceName, data, settings)
} }
@ -112,7 +113,7 @@ Item {
onNewData: { onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName) if (debug) console.log("[main::onNewData] : Update source " + sourceName)
// FIXME: ugly workaround to make some sources working // FIXME: ugly workaround to make some sources working
extsysmonDE.interval = plasmoid.configuration.interval // extsysmonDE.interval = plasmoid.configuration.interval
awKeys.setDataBySource(sourceName, data, settings) awKeys.setDataBySource(sourceName, data, settings)
} }
@ -175,7 +176,8 @@ Item {
Plasmoid.userConfiguringChanged(false) Plasmoid.userConfiguringChanged(false)
// connect data // connect data
awKeys.dropSourceFromDataengine.connect(dropSource) awKeys.dropSourceFromDataengine.connect(dropSource)
awKeys.needToBeUpdated.connect(needUpdate) awKeys.needTextToBeUpdated.connect(needTextUpdate)
awKeys.needToolTipToBeUpdated.connect(needToolTipUpdate)
} }
onDropSource: { onDropSource: {
@ -185,15 +187,19 @@ Item {
systemmonitorDE.disconnectSource(sourceName) systemmonitorDE.disconnectSource(sourceName)
} }
onNeedUpdate: { onNeedTextUpdate: {
if (debug) console.log("[main::onNeedUpdate]") if (debug) console.log("[main::onNeedTextUpdate]")
text.text = awKeys.parsePattern()
tooltip.text = awKeys.toolTipImage()
text.text = newText
sizeUpdate() sizeUpdate()
} }
onNeedToolTipUpdate: {
if (debug) console.log("[main::onNeedToolTipUpdate]")
tooltip.text = newText
}
onSizeUpdate: { onSizeUpdate: {
if (debug) console.log("[main::onSizeUpdate]") if (debug) console.log("[main::onSizeUpdate]")
@ -223,7 +229,7 @@ Item {
awKeys.setPopupEnabled(plasmoid.configuration.notify) awKeys.setPopupEnabled(plasmoid.configuration.notify)
awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines) awKeys.setWrapNewLines(plasmoid.configuration.wrapNewLines)
needUpdate() needTextUpdate(plasmoid.configuration.text)
} }
function action_checkUpdates() { function action_checkUpdates() {

View File

@ -215,7 +215,8 @@ void AWActions::showUpdates(QString version)
text += i18n("New version : %1", version) + QString("\n\n"); text += i18n("New version : %1", version) + QString("\n\n");
text += i18n("Click \"Ok\" to download"); text += i18n("Click \"Ok\" to download");
int select = QMessageBox::information(0, i18n("There are updates"), text, QMessageBox::Ok | QMessageBox::Cancel); int select = QMessageBox::information(nullptr, i18n("There are updates"), text,
QMessageBox::Ok | QMessageBox::Cancel);
switch (select) { switch (select) {
case QMessageBox::Ok: case QMessageBox::Ok:
QDesktopServices::openUrl(QString(RELEASES) + version); QDesktopServices::openUrl(QString(RELEASES) + version);

View File

@ -51,6 +51,9 @@ AWKeys::AWKeys(QObject *parent)
QString debugEnv = environment.value(QString("DEBUG"), QString("no")); QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes")); debug = (debugEnv == QString("yes"));
// backend
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate()));
// init dialog // init dialog
dialog = new QDialog(nullptr); dialog = new QDialog(nullptr);
widgetDialog = new QListWidget(dialog); widgetDialog = new QListWidget(dialog);
@ -73,11 +76,6 @@ AWKeys::~AWKeys()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
delete toolTip; delete toolTip;
delete createButton;
delete copyButton;
delete deleteButton;
delete dialogButtons;
delete widgetDialog;
delete dialog; delete dialog;
graphicalItems.clear(); graphicalItems.clear();
@ -165,22 +163,6 @@ QString AWKeys::parsePattern()
} }
QString AWKeys::toolTipImage()
{
if(debug) qDebug() << PDEBUG;
if (toolTip == nullptr) return QString("");
if (keys.isEmpty()) return QString();
QPixmap tooltip = toolTip->image();
QByteArray byteArray;
QBuffer buffer(&byteArray);
tooltip.save(&buffer, "PNG");
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
}
QSize AWKeys::toolTipSize() QSize AWKeys::toolTipSize()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -327,6 +309,10 @@ QStringList AWKeys::dictKeys(const bool sorted)
allKeys.append(QString("desktop")); allKeys.append(QString("desktop"));
allKeys.append(QString("ndesktop")); allKeys.append(QString("ndesktop"));
allKeys.append(QString("tdesktops")); allKeys.append(QString("tdesktops"));
// load average
allKeys.append(QString("la15"));
allKeys.append(QString("la5"));
allKeys.append(QString("la1"));
// bars // bars
QStringList graphicalItemsKeys; QStringList graphicalItemsKeys;
for (int i=0; i<graphicalItems.count(); i++) for (int i=0; i<graphicalItems.count(); i++)
@ -362,13 +348,10 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Source" << sourceName; if (debug) qDebug() << PDEBUG << ":" << "Source" << sourceName;
if (sourceName == QString("update")) { if (sourceName == QString("update")) return emit(needToBeUpdated());
emit(needToBeUpdated());
return;
}
// checking // checking
if (!checkKeys(data)) return; // if (!checkKeys(data)) return;
if (keys.isEmpty()) return; if (keys.isEmpty()) return;
// regular expressions // regular expressions
@ -517,6 +500,11 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
temperature(data[data.keys()[i]].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1); temperature(data[data.keys()[i]].toFloat(), params[QString("tempUnits")].toString()), 4, 'f', 1);
break; break;
} }
} else if (sourceName.startsWith(QString("cpu/system/loadavg"))) {
// load average
QString time = sourceName;
time.remove(QString("cpu/system/loadavg"));
values[QString("la%1").arg(time)] = QString("%1").arg(data[QString("value")].toFloat(), 5, 'f', 2);
} else if (sourceName == QString("mem/physical/application")) { } else if (sourceName == QString("mem/physical/application")) {
// app memory // app memory
values[QString("memmb")] = QString("%1").arg(data[QString("value")].toFloat() / 1024.0, 5, 'f', 0); values[QString("memmb")] = QString("%1").arg(data[QString("value")].toFloat() / 1024.0, 5, 'f', 0);
@ -639,8 +627,8 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data,
for (int i=0; i<tempDevices.count(); i++) for (int i=0; i<tempDevices.count(); i++)
if (sourceName == tempDevices[i]) { if (sourceName == tempDevices[i]) {
float temp = data[QString("units")].toString() == QString("°C") ? float temp = data[QString("units")].toString() == QString("°C") ?
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()) temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()) :
: data[QString("value")].toFloat(); data[QString("value")].toFloat();
values[QString("temp%1").arg(i)] = QString("%1").arg(temp, 4, 'f', 1); values[QString("temp%1").arg(i)] = QString("%1").arg(temp, 4, 'f', 1);
break; break;
} }
@ -797,6 +785,15 @@ void AWKeys::editItem(const QString type)
} }
void AWKeys::dataUpdate()
{
if (debug) qDebug() << PDEBUG;
emit(needTextToBeUpdated(parsePattern()));
emit(needToolTipToBeUpdated(toolTipImage()));
}
void AWKeys::loadKeysFromCache() void AWKeys::loadKeysFromCache()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -1325,6 +1322,22 @@ float AWKeys::temperature(const float temp, const QString units)
} }
QString AWKeys::toolTipImage()
{
if(debug) qDebug() << PDEBUG;
if (toolTip == nullptr) return QString("");
if (keys.isEmpty()) return QString();
QPixmap tooltip = toolTip->image();
QByteArray byteArray;
QBuffer buffer(&byteArray);
tooltip.save(&buffer, "PNG");
return QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
}
QStringList AWKeys::findGraphicalItems() QStringList AWKeys::findGraphicalItems()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;

View File

@ -57,7 +57,6 @@ public:
Q_INVOKABLE void setWrapNewLines(const bool wrap = false); Q_INVOKABLE void setWrapNewLines(const bool wrap = false);
Q_INVOKABLE bool isDebugEnabled(); Q_INVOKABLE bool isDebugEnabled();
Q_INVOKABLE QString parsePattern(); Q_INVOKABLE QString parsePattern();
Q_INVOKABLE QString toolTipImage();
Q_INVOKABLE QSize toolTipSize(); Q_INVOKABLE QSize toolTipSize();
// keys // keys
Q_INVOKABLE void addDevice(const QString source); Q_INVOKABLE void addDevice(const QString source);
@ -74,9 +73,12 @@ public:
signals: signals:
void dropSourceFromDataengine(const QString source); void dropSourceFromDataengine(const QString source);
void needTextToBeUpdated(const QString newText);
void needToolTipToBeUpdated(const QString newText);
void needToBeUpdated(); void needToBeUpdated();
private slots: private slots:
void dataUpdate();
void loadKeysFromCache(); void loadKeysFromCache();
void reinitKeys(); void reinitKeys();
// editor // editor
@ -93,11 +95,11 @@ private:
QString htmlValue(QString key); QString htmlValue(QString key);
int numberCpus(); int numberCpus();
float temperature(const float temp, const QString units); float temperature(const float temp, const QString units);
QString toolTipImage();
// find methods // find methods
QStringList findGraphicalItems(); QStringList findGraphicalItems();
QStringList findKeys(); QStringList findKeys();
// get methods // get methods
// get methods
QList<ExtQuotes *> getExtQuotes(); QList<ExtQuotes *> getExtQuotes();
QList<ExtScript *> getExtScripts(); QList<ExtScript *> getExtScripts();
QList<ExtUpgrade *> getExtUpgrade(); QList<ExtUpgrade *> getExtUpgrade();

View File

@ -33,7 +33,7 @@ AWToolTip::AWToolTip(QObject *parent, QVariantMap settings)
QString debugEnv = environment.value(QString("DEBUG"), QString("no")); QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes")); debug = (debugEnv == QString("yes"));
toolTipScene = new QGraphicsScene(); toolTipScene = new QGraphicsScene(nullptr);
toolTipView = new QGraphicsView(toolTipScene); toolTipView = new QGraphicsView(toolTipScene);
toolTipView->setStyleSheet(QString("background: transparent")); toolTipView->setStyleSheet(QString("background: transparent"));
toolTipView->setContentsMargins(0, 0, 0, 0); toolTipView->setContentsMargins(0, 0, 0, 0);
@ -72,7 +72,6 @@ AWToolTip::~AWToolTip()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
delete toolTipView;
delete toolTipScene; delete toolTipScene;
} }
@ -94,10 +93,9 @@ QPixmap AWToolTip::image()
toolTipScene->clear(); toolTipScene->clear();
QPen pen = QPen(); QPen pen = QPen();
// background // background
if (configuration[QString("useTooltipBackground")].toBool()) toolTipScene->setBackgroundBrush(configuration[QString("useTooltipBackground")].toBool() ?
toolTipScene->setBackgroundBrush(QBrush(QColor(configuration[QString("tooltipBackground")].toString()))); QBrush(QColor(configuration[QString("tooltipBackground")].toString())) :
else QBrush(Qt::NoBrush));
toolTipScene->setBackgroundBrush(QBrush(Qt::NoBrush));
bool down = false; bool down = false;
for (int i=0; i<requiredKeys.count(); i++) { for (int i=0; i<requiredKeys.count(); i++) {
float normX = 100.0 / static_cast<float>(data[requiredKeys[i]].count()); float normX = 100.0 / static_cast<float>(data[requiredKeys[i]].count());

View File

@ -52,7 +52,8 @@ public:
}; };
explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(), explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(),
const QStringList directories = QStringList(), const bool debugCmd = false); const QStringList directories = QStringList(),
const bool debugCmd = false);
~GraphicalItem(); ~GraphicalItem();
QString fileName(); QString fileName();
QString image(const float value); QString image(const float value);

View File

@ -151,12 +151,12 @@ void ExtQuotes::setApiVersion(const int _apiVersion)
} }
void ExtQuotes::setActive(const bool state) void ExtQuotes::setActive(const bool _state)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state; if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_active = state; m_active = _state;
} }

View File

@ -196,12 +196,12 @@ void ExtScript::setApiVersion(const int _apiVersion)
} }
void ExtScript::setActive(const bool state) void ExtScript::setActive(const bool _state)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state; if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_active = state; m_active = _state;
} }
@ -519,7 +519,7 @@ void ExtScript::updateValue()
if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput; if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput;
break; break;
case stderr2stdout: case stderr2stdout:
value = QString("%1\t%2").arg(qdebug).arg(qoutput); value = QString("%1\n%2").arg(qdebug).arg(qoutput);
break; break;
case nothing: case nothing:
default: default:

View File

@ -333,14 +333,14 @@ QVariantMap ExtendedSysMon::getBattery(const QString acpiPath)
(fullLevelFile.open(QIODevice::ReadOnly))) { (fullLevelFile.open(QIODevice::ReadOnly))) {
float batCurrent = QString(currentLevelFile.readLine()).trimmed().toFloat(); float batCurrent = QString(currentLevelFile.readLine()).trimmed().toFloat();
float batFull = QString(fullLevelFile.readLine()).trimmed().toFloat(); float batFull = QString(fullLevelFile.readLine()).trimmed().toFloat();
battery[QString("bat%1").arg(i)] = 100 * batCurrent / batFull; battery[QString("bat%1").arg(i)] = static_cast<int>(100 * batCurrent / batFull);
currentLevel += batCurrent; currentLevel += batCurrent;
fullLevel += batFull; fullLevel += batFull;
} }
currentLevelFile.close(); currentLevelFile.close();
fullLevelFile.close(); fullLevelFile.close();
} }
battery[QString("bat")] = 100 * currentLevel / fullLevel; battery[QString("bat")] = static_cast<int>(100 * currentLevel / fullLevel);
return battery; return battery;
} }

View File

@ -146,12 +146,12 @@ void ExtUpgrade::setApiVersion(const int _apiVersion)
} }
void ExtUpgrade::setActive(const bool state) void ExtUpgrade::setActive(const bool _state)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state; if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
m_active = state; m_active = _state;
} }
@ -251,7 +251,7 @@ int ExtUpgrade::run()
if (!m_active) return value; if (!m_active) return value;
if ((times == 1) && (process->state() == QProcess::NotRunning)) if ((times == 1) && (process->state() == QProcess::NotRunning))
process->start(QString("bash -c \"%1\"").arg(m_executable)); process->start(QString("sh -c \"%1\"").arg(m_executable));
else if (times >= m_interval) else if (times >= m_interval)
times = 0; times = 0;
times++; times++;