add notifications

edit widget.qml
fix bug in monitor
This commit is contained in:
arcan1s 2015-02-04 05:20:00 +03:00
parent f01fd96cf6
commit bb88892125
6 changed files with 52 additions and 9 deletions

View File

@ -205,8 +205,6 @@ Item {
function action_requestKey() { function action_requestKey() {
if (debug) console.log("[main::action_requestKey]") if (debug) console.log("[main::action_requestKey]")
var message = AWKeys.graphicalValueByKey(); AWKeys.graphicalValueByKey()
if (message.length == 0) return
AWActions.sendNotification("tag", message)
} }
} }

View File

@ -240,6 +240,8 @@ Item {
var message = i18n("Tag: %1", tags.currentText) var message = i18n("Tag: %1", tags.currentText)
message += "<br>" message += "<br>"
message += i18n("Value: %1", AWKeys.valueByKey(tags.currentText)) message += i18n("Value: %1", AWKeys.valueByKey(tags.currentText))
message += "<br>"
message += i18n("Info: %1", AWKeys.infoByKey(tags.currentText))
AWActions.sendNotification("tag", message) AWActions.sendNotification("tag", message)
} }
} }

View File

@ -33,6 +33,7 @@
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include "awactions.h"
#include "awtooltip.h" #include "awtooltip.h"
#include "extscript.h" #include "extscript.h"
#include "extupgrade.h" #include "extupgrade.h"
@ -569,6 +570,9 @@ bool AWKeys::setDataBySource(const QString sourceName,
toolTip->setData(QString("memTooltip"), values[QString("mem")].toFloat()); toolTip->setData(QString("memTooltip"), values[QString("mem")].toFloat());
} else if (sourceName == QString("netdev")) { } else if (sourceName == QString("netdev")) {
// network device // network device
if (values[QString("netdev")] != data[QString("value")].toString())
AWActions::sendNotification(QString("event"), i18n("Network device has been changed to %1",
data[QString("value")].toString()));
values[QString("netdev")] = data[QString("value")].toString(); values[QString("netdev")] = data[QString("value")].toString();
} else if (sourceName.contains(netRecRegExp)) { } else if (sourceName.contains(netRecRegExp)) {
// download speed // download speed
@ -682,7 +686,7 @@ bool AWKeys::setDataBySource(const QString sourceName,
} }
QString AWKeys::graphicalValueByKey() void AWKeys::graphicalValueByKey()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -690,12 +694,39 @@ QString AWKeys::graphicalValueByKey()
QString tag = QInputDialog::getItem(0, i18n("Select tag"), QString tag = QInputDialog::getItem(0, i18n("Select tag"),
i18n("Tag"), keys, 0, false, &ok); i18n("Tag"), keys, 0, false, &ok);
if ((!ok) || (tag.isEmpty())) return QString(""); if ((!ok) || (tag.isEmpty())) return;
QString message = i18n("Tag: %1", tag); QString message = i18n("Tag: %1", tag);
message += QString("<br>"); message += QString("<br>");
message += i18n("Value: %1", valueByKey(tag)); message += i18n("Value: %1", valueByKey(tag));
return message; 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("temp")))
return QString("%1").arg(tempDevices[key.remove(QString("temp")).toInt()]);
return QString("(none)");
} }

View File

@ -68,7 +68,8 @@ public:
const QMap<QString, QVariant> data, const QMap<QString, QVariant> data,
const QMap<QString, QVariant> params); const QMap<QString, QVariant> params);
// values // values
Q_INVOKABLE QString graphicalValueByKey(); Q_INVOKABLE void graphicalValueByKey();
Q_INVOKABLE QString infoByKey(QString key);
Q_INVOKABLE QString valueByKey(QString key); Q_INVOKABLE QString valueByKey(QString key);
// configuration // configuration
Q_INVOKABLE void editItem(const QString type); Q_INVOKABLE void editItem(const QString type);

View File

@ -17,12 +17,16 @@
#include "awtooltip.h" #include "awtooltip.h"
#include <KI18n/KLocalizedString>
#include <QDebug> #include <QDebug>
#include <QProcessEnvironment> #include <QProcessEnvironment>
#include <math.h> #include <math.h>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include "awactions.h"
AWToolTip::AWToolTip(QObject *parent, AWToolTip::AWToolTip(QObject *parent,
QMap<QString, QVariant> settings) QMap<QString, QVariant> settings)
@ -139,7 +143,7 @@ void AWToolTip::setData(const QString source, float value, const bool ac)
data[source].append(0.0); data[source].append(0.0);
else if (data[source].count() > configuration[QString("tooltipNumber")].toInt()) else if (data[source].count() > configuration[QString("tooltipNumber")].toInt())
data[source].takeFirst(); data[source].takeFirst();
if (isnan(value)) value = 100.0; if (isnan(value)) value = 0.0;
if (ac) if (ac)
data[source].append(value); data[source].append(value);
@ -155,5 +159,12 @@ void AWToolTip::setData(const QString source, float value, const bool ac)
boundaries[QString("downTooltip")] = data[QString("upTooltip")][i]; boundaries[QString("downTooltip")] = data[QString("upTooltip")][i];
boundaries[QString("downTooltip")] *= 1.2; boundaries[QString("downTooltip")] *= 1.2;
boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")]; boundaries[QString("upTooltip")] = boundaries[QString("downTooltip")];
} else if (source == QString("batTooltip")) {
int size = data[source].count();
if (data[source][size-1] * data[source][size-2] >= 0) return;
if (data[source].last() > 0.0)
AWActions::sendNotification(QString("event"), i18n("AC online"));
else
AWActions::sendNotification(QString("event"), i18n("AC offline"));
} }
} }

View File

@ -461,7 +461,7 @@ float ExtendedSysMon::getHddTemp(const QString cmd, const QString device)
break; break;
} }
} else { } else {
if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() < 3) { if (qoutput.split(QChar(':'), QString::SkipEmptyParts).count() >= 3) {
QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2]; QString temp = qoutput.split(QChar(':'), QString::SkipEmptyParts)[2];
temp.remove(QChar(0260)).remove(QChar('C')); temp.remove(QChar(0260)).remove(QChar('C'));
value = temp.toFloat(); value = temp.toFloat();