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

@ -215,7 +215,8 @@ void AWActions::showUpdates(QString version)
text += i18n("New version : %1", version) + QString("\n\n");
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) {
case QMessageBox::Ok:
QDesktopServices::openUrl(QString(RELEASES) + version);

View File

@ -51,6 +51,9 @@ AWKeys::AWKeys(QObject *parent)
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes"));
// backend
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(dataUpdate()));
// init dialog
dialog = new QDialog(nullptr);
widgetDialog = new QListWidget(dialog);
@ -73,11 +76,6 @@ AWKeys::~AWKeys()
if (debug) qDebug() << PDEBUG;
delete toolTip;
delete createButton;
delete copyButton;
delete deleteButton;
delete dialogButtons;
delete widgetDialog;
delete dialog;
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()
{
if (debug) qDebug() << PDEBUG;
@ -327,6 +309,10 @@ QStringList AWKeys::dictKeys(const bool sorted)
allKeys.append(QString("desktop"));
allKeys.append(QString("ndesktop"));
allKeys.append(QString("tdesktops"));
// load average
allKeys.append(QString("la15"));
allKeys.append(QString("la5"));
allKeys.append(QString("la1"));
// bars
QStringList graphicalItemsKeys;
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 << ":" << "Source" << sourceName;
if (sourceName == QString("update")) {
emit(needToBeUpdated());
return;
}
if (sourceName == QString("update")) return emit(needToBeUpdated());
// checking
if (!checkKeys(data)) return;
// if (!checkKeys(data)) return;
if (keys.isEmpty()) return;
// 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);
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")) {
// app memory
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++)
if (sourceName == tempDevices[i]) {
float temp = data[QString("units")].toString() == QString("°C") ?
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString())
: data[QString("value")].toFloat();
temperature(data[QString("value")].toFloat(), params[QString("tempUnits")].toString()) :
data[QString("value")].toFloat();
values[QString("temp%1").arg(i)] = QString("%1").arg(temp, 4, 'f', 1);
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()
{
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()
{
if (debug) qDebug() << PDEBUG;

View File

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

View File

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