mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
add abstactextitem class (building is broken atm)
This commit is contained in:
parent
b699095f38
commit
880a986782
@ -2,7 +2,9 @@ Ver.2.3.4:
|
||||
+ add support of weather items
|
||||
+ add support of load average (la1, la5, la15 tags)
|
||||
+ add "drop key cache" button
|
||||
+ add support of clang building
|
||||
- fix bug with invalid network data calculation
|
||||
* rewrite ExtItems to use own abstract class
|
||||
* improve work with data updating (#57)
|
||||
* move plugin part back to private
|
||||
* cast plugin as type, not signleton (#57)
|
||||
|
@ -283,10 +283,13 @@ QStringList AWKeys::dictKeys(const bool sorted)
|
||||
allKeys.append(QString("pstotal"));
|
||||
allKeys.append(QString("ps"));
|
||||
// package manager
|
||||
for (int i=extUpgrade.count()-1; i>=0; i--)
|
||||
allKeys.append(extUpgrade[i]->tag());
|
||||
for (int i=extUpgrade.count()-1; i>=0; i--) {
|
||||
if (!extUpgrade[i]->isActive()) continue;
|
||||
allKeys.append(extUpgrade[i]->tag(QString("pkgcount")));
|
||||
}
|
||||
// quotes
|
||||
for (int i=extQuotes.count()-1; i>=0; i--) {
|
||||
if (!extQuotes[i]->isActive()) continue;
|
||||
allKeys.append(extQuotes[i]->tag(QString("ask")));
|
||||
allKeys.append(extQuotes[i]->tag(QString("askchg")));
|
||||
allKeys.append(extQuotes[i]->tag(QString("percaskchg")));
|
||||
@ -298,8 +301,10 @@ QStringList AWKeys::dictKeys(const bool sorted)
|
||||
allKeys.append(extQuotes[i]->tag(QString("percpricechg")));
|
||||
}
|
||||
// custom
|
||||
for (int i=extScripts.count()-1; i>=0; i--)
|
||||
allKeys.append(extScripts[i]->tag());
|
||||
for (int i=extScripts.count()-1; i>=0; i--) {
|
||||
if (!extScripts[i]->isActive()) continue;
|
||||
allKeys.append(extScripts[i]->tag(QString("custom")));
|
||||
}
|
||||
// desktop
|
||||
allKeys.append(QString("desktop"));
|
||||
allKeys.append(QString("ndesktop"));
|
||||
@ -310,6 +315,7 @@ QStringList AWKeys::dictKeys(const bool sorted)
|
||||
allKeys.append(QString("la1"));
|
||||
// weather
|
||||
for (int i=extWeather.count()-1; i>=0; i--) {
|
||||
if (!extWeather[i]->isActive()) continue;
|
||||
allKeys.append(extWeather[i]->tag(QString("weatherId")));
|
||||
allKeys.append(extWeather[i]->tag(QString("weather")));
|
||||
allKeys.append(extWeather[i]->tag(QString("humidity")));
|
||||
@ -708,7 +714,7 @@ QString AWKeys::infoByKey(QString key)
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (key.startsWith(QString("custom")))
|
||||
for (int i=0; i<extScripts.count(); i++) {
|
||||
if (extScripts[i]->tag() != key) continue;
|
||||
if (extScripts[i]->tag(QString("custom")) != key) continue;
|
||||
return extScripts[i]->executable();
|
||||
}
|
||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||
@ -721,7 +727,7 @@ QString AWKeys::infoByKey(QString key)
|
||||
return QString("%1").arg(networkDevices[key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
for (int i=0; i<extUpgrade.count(); i++) {
|
||||
if (extUpgrade[i]->tag() != key) continue;
|
||||
if (extUpgrade[i]->tag(QString("pkgcount")) != key) continue;
|
||||
return extUpgrade[i]->executable();
|
||||
}
|
||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||
|
235
sources/extsysmon/abstractextitem.cpp
Normal file
235
sources/extsysmon/abstractextitem.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
/***************************************************************************
|
||||
* 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/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
m_fileName(desktopName),
|
||||
m_dirs(directories),
|
||||
debug(debugCmd)
|
||||
{
|
||||
m_name = m_fileName;
|
||||
}
|
||||
|
||||
|
||||
AbstractExtItem::~AbstractExtItem()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
}
|
||||
|
||||
|
||||
int AbstractExtItem::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::comment()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
|
||||
QStringList AbstractExtItem::directories()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_dirs;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::fileName()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
|
||||
int AbstractExtItem::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
bool AbstractExtItem::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
int AbstractExtItem::number()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_number;
|
||||
}
|
||||
|
||||
|
||||
QString AbstractExtItem::tag(const QString _type)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Tag type" << _type;
|
||||
|
||||
return QString("%1%2").arg(_type).arg(m_number);
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setActive(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setComment(const QString _comment)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setInterval(const int _interval)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
|
||||
if (_interval <= 0) return;
|
||||
|
||||
m_interval = _interval;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::setNumber(int _number)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
|
||||
if (_number == -1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_number = qrand() % 1000;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool AbstractExtItem::tryDelete()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
|
||||
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
|
||||
|
||||
// check if exists
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::writeConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
81
sources/extsysmon/abstractextitem.h
Normal file
81
sources/extsysmon/abstractextitem.h
Normal file
@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
* 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 ABSTRACTEXTITEM_H
|
||||
#define ABSTRACTEXTITEM_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class AbstractExtItem : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QStringList directories READ directories)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
|
||||
public:
|
||||
explicit AbstractExtItem(QWidget *parent = nullptr,
|
||||
const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
virtual ~AbstractExtItem();
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString comment();
|
||||
QStringList directories();
|
||||
QString fileName();
|
||||
int interval();
|
||||
bool isActive();
|
||||
QString name();
|
||||
int number();
|
||||
QString tag(const QString _type);
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setInterval(const int _interval = 1);
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
|
||||
public slots:
|
||||
virtual void readConfiguration();
|
||||
virtual QVariantMap run() = 0;
|
||||
virtual int showConfiguration() = 0;
|
||||
bool tryDelete();
|
||||
virtual void writeConfiguration();
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
bool debug;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
int m_interval = 1;
|
||||
QString m_name = QString("none");
|
||||
int m_number = -1;
|
||||
};
|
||||
|
||||
|
||||
#endif /* ABSTRACTEXTITEM_H */
|
@ -25,7 +25,6 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QTime>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <qreplytimeout/qreplytimeout.h>
|
||||
@ -35,13 +34,10 @@
|
||||
|
||||
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
m_fileName(quotesName),
|
||||
m_dirs(directories),
|
||||
: AbstractExtItem(parent, quotesName, directories, debugCmd),
|
||||
debug(debugCmd),
|
||||
ui(new Ui::ExtQuotes)
|
||||
{
|
||||
m_name = m_fileName;
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -56,7 +52,8 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
||||
values[QString("percpricechg")] = 0.0;
|
||||
|
||||
manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)),
|
||||
this, SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
}
|
||||
|
||||
|
||||
@ -71,71 +68,6 @@ ExtQuotes::~ExtQuotes()
|
||||
}
|
||||
|
||||
|
||||
int ExtQuotes::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString ExtQuotes::comment()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
|
||||
QString ExtQuotes::fileName()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
|
||||
int ExtQuotes::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
bool ExtQuotes::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
QString ExtQuotes::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
int ExtQuotes::number()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_number;
|
||||
}
|
||||
|
||||
|
||||
QString ExtQuotes::tag(const QString _type)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Tag type" << _type;
|
||||
|
||||
return QString("%1%2").arg(_type).arg(m_number);
|
||||
}
|
||||
|
||||
|
||||
QString ExtQuotes::ticker()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -144,66 +76,6 @@ QString ExtQuotes::ticker()
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setActive(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setComment(const QString _comment)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setInterval(const int _interval)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
|
||||
|
||||
m_interval = _interval;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setNumber(int _number)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
|
||||
if (_number == -1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_number = qrand() % 1000;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::setTicker(const QString _ticker)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -217,33 +89,27 @@ void ExtQuotes::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
|
||||
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// update for current API
|
||||
if ((m_apiVersion > 0) && (m_apiVersion < AWEQAPI)) {
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
|
||||
setApiVersion(AWEQAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, float> ExtQuotes::run()
|
||||
QVariantMap ExtQuotes::run()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if ((!m_active) || (isRunning)) return values;
|
||||
if ((!isActive()) || (isRunning)) return values;
|
||||
|
||||
if (times == 1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Send request";
|
||||
@ -253,7 +119,7 @@ QMap<QString, float> ExtQuotes::run()
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= m_interval) times = 0;
|
||||
if (times >= interval()) times = 0;
|
||||
times++;
|
||||
|
||||
return values;
|
||||
@ -264,12 +130,12 @@ int ExtQuotes::showConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->lineEdit_name->setText(m_name);
|
||||
ui->lineEdit_comment->setText(m_comment);
|
||||
ui->label_numberValue->setText(QString("%1").arg(m_number));
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_ticker->setText(m_ticker);
|
||||
ui->checkBox_active->setCheckState(m_active ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(m_interval);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1) return ret;
|
||||
@ -286,37 +152,15 @@ int ExtQuotes::showConfiguration()
|
||||
}
|
||||
|
||||
|
||||
bool ExtQuotes::tryDelete()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
|
||||
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
|
||||
|
||||
// check if exists
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ExtQuotes::writeConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
|
||||
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("X-AW-Ticker"), m_ticker);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -343,20 +187,23 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
|
||||
// ask
|
||||
value = jsonQuotes[QString("Ask")].toString().toFloat();
|
||||
values[QString("askchg")] = values[QString("ask")] == 0 ? 0.0 : value - values[QString("ask")];
|
||||
values[QString("percaskchg")] = 100 * values[QString("askchg")] / values[QString("ask")];
|
||||
values[QString("askchg")] = values[QString("ask")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("ask")].toFloat();
|
||||
values[QString("percaskchg")] = 100.0 * values[QString("askchg")].toFloat() / values[QString("ask")].toFloat();
|
||||
values[QString("ask")] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes[QString("Bid")].toString().toFloat();
|
||||
values[QString("bidchg")] = values[QString("bid")] == 0 ? 0.0 : value - values[QString("bid")];
|
||||
values[QString("percbidchg")] = 100 * values[QString("bidchg")] / values[QString("bid")];
|
||||
values[QString("bidchg")] = values[QString("bid")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("bid")].toFloat();
|
||||
values[QString("percbidchg")] = 100.0 * values[QString("bidchg")].toFloat() / values[QString("bid")].toFloat();
|
||||
values[QString("bid")] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toFloat();
|
||||
values[QString("pricechg")] = values[QString("price")] == 0 ? 0.0 : value - values[QString("price")];
|
||||
values[QString("percpricechg")] = 100 * values[QString("pricechg")] / values[QString("price")];
|
||||
values[QString("pricechg")] = values[QString("price")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("price")].toFloat();
|
||||
values[QString("percpricechg")] = 100.0 * values[QString("pricechg")].toFloat() / values[QString("price")].toFloat();
|
||||
values[QString("price")] = value;
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,10 @@
|
||||
#ifndef EXTQUOTES_H
|
||||
#define EXTQUOTES_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define YAHOO_URL "https://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.quotes where symbol=\"$TICKER\"&env=store://datatables.org/alltableswithkeys&format=json"
|
||||
|
||||
@ -30,15 +30,9 @@ namespace Ui {
|
||||
class ExtQuotes;
|
||||
}
|
||||
|
||||
class ExtQuotes : public QDialog
|
||||
class ExtQuotes : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
Q_PROPERTY(QString ticker READ ticker WRITE setTicker)
|
||||
|
||||
public:
|
||||
@ -46,53 +40,30 @@ public:
|
||||
const QStringList directories = QStringList(), const bool debugCmd = false);
|
||||
~ExtQuotes();
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString comment();
|
||||
QString fileName();
|
||||
int interval();
|
||||
bool isActive();
|
||||
QString name();
|
||||
int number();
|
||||
QString tag(const QString _type = QString("price"));
|
||||
QString ticker();
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setInterval(const int _interval = 0);
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
void setTicker(const QString _ticker = QString("EURUSD=X"));
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QMap<QString, float> run();
|
||||
QVariantMap run();
|
||||
int showConfiguration();
|
||||
bool tryDelete();
|
||||
void writeConfiguration();
|
||||
|
||||
private slots:
|
||||
void quotesReplyReceived(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
bool debug;
|
||||
QNetworkAccessManager *manager;
|
||||
bool isRunning = false;
|
||||
Ui::ExtQuotes *ui;
|
||||
QString url();
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
int m_interval = 60;
|
||||
QString m_name = QString("none");
|
||||
int m_number = -1;
|
||||
QString m_ticker = QString("EURUSD=X");
|
||||
// values
|
||||
int times = 0;
|
||||
QMap<QString, float> values;
|
||||
QVariantMap values;
|
||||
};
|
||||
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QTextCodec>
|
||||
#include <QTime>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
@ -34,21 +33,19 @@
|
||||
|
||||
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
m_fileName(scriptName),
|
||||
m_dirs(directories),
|
||||
: AbstractExtItem(parent, scriptName, directories, debugCmd),
|
||||
debug(debugCmd),
|
||||
ui(new Ui::ExtScript)
|
||||
{
|
||||
m_name = m_fileName;
|
||||
readConfiguration();
|
||||
readJsonFilters();
|
||||
// init process
|
||||
ui->setupUi(this);
|
||||
|
||||
value[QString("value")] = QString();
|
||||
|
||||
process = new QProcess(this);
|
||||
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
// init ui
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
|
||||
@ -62,22 +59,6 @@ ExtScript::~ExtScript()
|
||||
}
|
||||
|
||||
|
||||
int ExtScript::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::comment()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::executable()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -86,14 +67,6 @@ QString ExtScript::executable()
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::fileName()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
|
||||
QStringList ExtScript::filters()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -110,38 +83,6 @@ bool ExtScript::hasOutput()
|
||||
}
|
||||
|
||||
|
||||
int ExtScript::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
int ExtScript::number()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_number;
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::prefix()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -180,41 +121,6 @@ QString ExtScript::strRedirect()
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::tag()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return QString("custom%1").arg(m_number);
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setActive(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setComment(const QString _comment)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setExecutable(const QString _executable)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -243,40 +149,6 @@ void ExtScript::setHasOutput(const bool _state)
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setInterval(const int _interval)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
|
||||
if (_interval <= 0) return;
|
||||
|
||||
m_interval = _interval;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setNumber(int _number)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
|
||||
if (_number == -1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_number = qrand() % 1000;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setPrefix(const QString _prefix)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -348,22 +220,15 @@ void ExtScript::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
|
||||
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
||||
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
|
||||
setHasOutput(settings.value(QString("X-AW-Output"), QVariant(m_output)).toString() == QString("true"));
|
||||
setStrRedirect(settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
// api == 2
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
// api == 3
|
||||
setFilters(settings.value(QString("X-AW-Filters"), m_filters).toString()
|
||||
.split(QChar(','), QString::SkipEmptyParts));
|
||||
@ -374,7 +239,7 @@ void ExtScript::readConfiguration()
|
||||
setRedirect(stdout2stderr);
|
||||
|
||||
// update for current API
|
||||
if ((m_apiVersion > 0) && (m_apiVersion < AWESAPI)) {
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
|
||||
setApiVersion(AWESAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -405,10 +270,10 @@ void ExtScript::readJsonFilters()
|
||||
}
|
||||
|
||||
|
||||
QString ExtScript::run()
|
||||
QVariantMap ExtScript::run()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!m_active) return value;
|
||||
if (!isActive()) return value;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
QStringList cmdList;
|
||||
@ -416,7 +281,7 @@ QString ExtScript::run()
|
||||
cmdList.append(m_executable);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmdList.join(QChar(' '));
|
||||
process->start(cmdList.join(QChar(' ')));
|
||||
} else if (times >= m_interval)
|
||||
} else if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
|
||||
@ -428,15 +293,15 @@ int ExtScript::showConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->lineEdit_name->setText(m_name);
|
||||
ui->lineEdit_comment->setText(m_comment);
|
||||
ui->label_numberValue->setText(QString("%1").arg(m_number));
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(m_executable);
|
||||
ui->lineEdit_prefix->setText(m_prefix);
|
||||
ui->checkBox_active->setCheckState(m_active ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_output->setCheckState(m_output ? Qt::Checked : Qt::Unchecked);
|
||||
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect));
|
||||
ui->spinBox_interval->setValue(m_interval);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
// filters
|
||||
ui->checkBox_colorFilter->setCheckState(m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_linesFilter->setCheckState(m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
|
||||
@ -464,40 +329,18 @@ int ExtScript::showConfiguration()
|
||||
}
|
||||
|
||||
|
||||
bool ExtScript::tryDelete()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
|
||||
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
|
||||
|
||||
// check if exists
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::writeConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
|
||||
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Prefix"), m_prefix);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Output"), QVariant(m_output).toString());
|
||||
settings.setValue(QString("X-AW-Redirect"), strRedirect());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(',')));
|
||||
settings.endGroup();
|
||||
|
||||
@ -520,15 +363,15 @@ void ExtScript::updateValue()
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Output" << qoutput;
|
||||
break;
|
||||
case stderr2stdout:
|
||||
value = QString("%1\n%2").arg(qdebug).arg(qoutput);
|
||||
value[QString("value")] = QString("%1\n%2").arg(qdebug).arg(qoutput);
|
||||
break;
|
||||
case nothing:
|
||||
default:
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Debug" << qdebug;
|
||||
value = qoutput;
|
||||
value[QString("value")] = qoutput;
|
||||
break;
|
||||
}
|
||||
|
||||
// filters
|
||||
value = applyFilters(value);
|
||||
value[QString("value")] = applyFilters(value[QString("value")].toString());
|
||||
}
|
||||
|
@ -18,26 +18,21 @@
|
||||
#ifndef EXTSCRIPT_H
|
||||
#define EXTSCRIPT_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QProcess>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ExtScript;
|
||||
}
|
||||
|
||||
class ExtScript : public QDialog
|
||||
class ExtScript : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
|
||||
Q_PROPERTY(QStringList filters READ filters WRITE setFilters)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
Q_PROPERTY(bool output READ hasOutput WRITE setHasOutput)
|
||||
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
|
||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||
@ -53,31 +48,17 @@ public:
|
||||
const QStringList directories = QStringList(), const bool debugCmd = false);
|
||||
~ExtScript();
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString comment();
|
||||
QString executable();
|
||||
QString fileName();
|
||||
QStringList filters();
|
||||
bool hasOutput();
|
||||
int interval();
|
||||
bool isActive();
|
||||
QString name();
|
||||
int number();
|
||||
QString prefix();
|
||||
Redirect redirect();
|
||||
// derivatives
|
||||
QString strRedirect();
|
||||
QString tag();
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setExecutable(const QString _executable = QString("/usr/bin/true"));
|
||||
void setFilters(const QStringList _filters = QStringList());
|
||||
void setHasOutput(const bool _state = true);
|
||||
void setInterval(const int _interval = 1);
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
void setPrefix(const QString _prefix = QString(""));
|
||||
void setRedirect(const Redirect _redirect = nothing);
|
||||
void setStrRedirect(const QString _redirect = QString("nothing"));
|
||||
@ -88,29 +69,20 @@ public:
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
void readJsonFilters();
|
||||
QString run();
|
||||
QVariantMap run();
|
||||
int showConfiguration();
|
||||
bool tryDelete();
|
||||
void writeConfiguration();
|
||||
|
||||
private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
bool debug;
|
||||
QProcess *process = nullptr;
|
||||
Ui::ExtScript *ui;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QStringList m_filters = QStringList();
|
||||
int m_interval = 1;
|
||||
QString m_name = QString("none");
|
||||
int m_number = -1;
|
||||
bool m_output = true;
|
||||
QString m_prefix = QString("");
|
||||
Redirect m_redirect = nothing;
|
||||
@ -118,7 +90,7 @@ private:
|
||||
Q_PID childProcess = 0;
|
||||
QVariantMap jsonFilters = QVariantMap();
|
||||
int times = 0;
|
||||
QString value = QString();
|
||||
QVariantMap value;
|
||||
};
|
||||
|
||||
|
||||
|
@ -701,10 +701,8 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
for (int i=0; i<battery.keys().count(); i++)
|
||||
setData(source, battery.keys()[i], battery[battery.keys()[i]]);
|
||||
} else if (source == QString("custom")) {
|
||||
for (int i=0; i<externalScripts.count(); i++) {
|
||||
if (!externalScripts[i]->isActive()) continue;
|
||||
setData(source, externalScripts[i]->tag(), externalScripts[i]->run());
|
||||
}
|
||||
for (int i=0; i<externalScripts.count(); i++)
|
||||
setData(source, externalScripts[i]->tag(QString("custom")), externalScripts[i]->run()[QString("value")]);
|
||||
} else if (source == QString("desktop")) {
|
||||
QVariantMap desktop = getCurrentDesktop();
|
||||
for (int i=0; i<desktop.keys().count(); i++)
|
||||
@ -725,10 +723,8 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
} else if (source == QString("netdev")) {
|
||||
setData(source, QString("value"), getNetworkDevice());
|
||||
} else if (source == QString("pkg")) {
|
||||
for (int i=0; i<externalUpgrade.count(); i++) {
|
||||
if (!externalUpgrade[i]->isActive()) continue;
|
||||
setData(source, externalUpgrade[i]->tag(), externalUpgrade[i]->run());
|
||||
}
|
||||
for (int i=0; i<externalUpgrade.count(); i++)
|
||||
setData(source, externalUpgrade[i]->tag(QString("pkgcount")), externalUpgrade[i]->run()[QString("value")]);
|
||||
} else if (source == QString("player")) {
|
||||
QVariantMap player = getPlayerInfo(configuration[QString("PLAYER")],
|
||||
configuration[QString("MPDADDRESS")],
|
||||
@ -742,8 +738,7 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
setData(source, ps.keys()[i], ps[ps.keys()[i]]);
|
||||
} else if (source == QString("quotes")) {
|
||||
for (int i=0; i<externalQuotes.count(); i++) {
|
||||
if (!externalQuotes[i]->isActive()) continue;
|
||||
QMap<QString, float> data = externalQuotes[i]->run();
|
||||
QVariantMap data = externalQuotes[i]->run();
|
||||
for (int j=0; j<data.keys().count(); j++)
|
||||
setData(source, externalQuotes[i]->tag(data.keys()[j]), data[data.keys()[j]]);
|
||||
}
|
||||
@ -751,7 +746,6 @@ bool ExtendedSysMon::updateSourceEvent(const QString &source)
|
||||
setData(source, QString("value"), true);
|
||||
} else if (source == QString("weather")) {
|
||||
for (int i=0; i<externalWeather.count(); i++) {
|
||||
if (!externalWeather[i]->isActive()) continue;
|
||||
QVariantMap data = externalWeather[i]->run();
|
||||
for (int j=0; j<data.keys().count(); j++)
|
||||
setData(source, externalWeather[i]->tag(data.keys()[j]), data[data.keys()[j]]);
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QTextCodec>
|
||||
#include <QTime>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
@ -31,20 +30,18 @@
|
||||
|
||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
m_fileName(upgradeName),
|
||||
m_dirs(directories),
|
||||
: AbstractExtItem(parent, upgradeName, directories, debugCmd),
|
||||
debug(debugCmd),
|
||||
ui(new Ui::ExtUpgrade)
|
||||
{
|
||||
m_name = m_fileName;
|
||||
readConfiguration();
|
||||
// init process
|
||||
ui->setupUi(this);
|
||||
|
||||
value[QString("value")] = 0;
|
||||
|
||||
process = new QProcess(this);
|
||||
connect(process, SIGNAL(finished(int)), this, SLOT(updateValue()));
|
||||
process->waitForFinished(0);
|
||||
// init ui
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
|
||||
@ -58,22 +55,6 @@ ExtUpgrade::~ExtUpgrade()
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString ExtUpgrade::comment()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
|
||||
QString ExtUpgrade::executable()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -82,30 +63,6 @@ QString ExtUpgrade::executable()
|
||||
}
|
||||
|
||||
|
||||
QString ExtUpgrade::fileName()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
QString ExtUpgrade::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::null()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -114,57 +71,6 @@ int ExtUpgrade::null()
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::number()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_number;
|
||||
}
|
||||
|
||||
|
||||
QString ExtUpgrade::tag()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return QString("pkgcount%1").arg(m_number);
|
||||
}
|
||||
|
||||
|
||||
bool ExtUpgrade::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setActive(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setComment(const QString _comment)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setExecutable(const QString _executable)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -174,24 +80,6 @@ void ExtUpgrade::setExecutable(const QString _executable)
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setInterval(const int _interval)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
|
||||
|
||||
m_interval = _interval;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setNull(const int _null)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -202,58 +90,36 @@ void ExtUpgrade::setNull(const int _null)
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::setNumber(int _number)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
|
||||
if (_number == -1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_number = qrand() % 1000;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
|
||||
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setExecutable(settings.value(QString("Exec"), m_executable).toString());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
|
||||
setNull(settings.value(QString("X-AW-Null"), m_null).toInt());
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
// api == 2
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// update for current API
|
||||
if ((m_apiVersion > 0) && (m_apiVersion < AWEUAPI)) {
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
|
||||
setApiVersion(AWEUAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ExtUpgrade::run()
|
||||
QVariantMap ExtUpgrade::run()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!m_active) return value;
|
||||
if (!isActive()) return value;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning))
|
||||
process->start(QString("sh -c \"%1\"").arg(m_executable));
|
||||
else if (times >= m_interval)
|
||||
else if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
|
||||
@ -265,13 +131,13 @@ int ExtUpgrade::showConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->lineEdit_name->setText(m_name);
|
||||
ui->lineEdit_comment->setText(m_comment);
|
||||
ui->label_numberValue->setText(QString("%1").arg(m_number));
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_command->setText(m_executable);
|
||||
ui->checkBox_active->setCheckState(m_active ? Qt::Checked : Qt::Unchecked);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_null->setValue(m_null);
|
||||
ui->spinBox_interval->setValue(m_interval);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1) return ret;
|
||||
@ -289,38 +155,16 @@ int ExtUpgrade::showConfiguration()
|
||||
}
|
||||
|
||||
|
||||
bool ExtUpgrade::tryDelete()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
|
||||
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
|
||||
|
||||
// check if exists
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ExtUpgrade::writeConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
|
||||
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Null"), m_null);
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
@ -335,5 +179,5 @@ void ExtUpgrade::updateValue()
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process->readAllStandardError();
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
|
||||
value = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null;
|
||||
value[QString("value")] = qoutput.split(QChar('\n'), QString::SkipEmptyParts).count() - m_null;
|
||||
}
|
||||
|
@ -18,78 +18,51 @@
|
||||
#ifndef EXTUPGRADE_H
|
||||
#define EXTUPGRADE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QProcess>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class ExtUpgrade;
|
||||
}
|
||||
|
||||
class ExtUpgrade : public QDialog
|
||||
class ExtUpgrade : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(QString executable READ executable WRITE setExecutable)
|
||||
Q_PROPERTY(int null READ null WRITE setNull)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
|
||||
public:
|
||||
explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(),
|
||||
const QStringList directories = QStringList(), const bool debugCmd = false);
|
||||
~ExtUpgrade();
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString comment();
|
||||
QString executable();
|
||||
QString fileName();
|
||||
int interval();
|
||||
QString name();
|
||||
int null();
|
||||
int number();
|
||||
QString tag();
|
||||
bool isActive();
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setExecutable(const QString _executable = QString("/usr/bin/true"));
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNull(const int _null = 0);
|
||||
void setNumber(int _number = -1);
|
||||
void setInterval(const int _interval = 0);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int run();
|
||||
QVariantMap run();
|
||||
int showConfiguration();
|
||||
bool tryDelete();
|
||||
void writeConfiguration();
|
||||
|
||||
private slots:
|
||||
void updateValue();
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
bool debug;
|
||||
QProcess *process = nullptr;
|
||||
Ui::ExtUpgrade *ui;
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QString m_name = QString("none");
|
||||
int m_null = 0;
|
||||
int m_number = -1;
|
||||
int m_interval = 3600;
|
||||
// internal properties
|
||||
int times = 0;
|
||||
int value = 0;
|
||||
QVariantMap value;
|
||||
};
|
||||
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QTime>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <qreplytimeout/qreplytimeout.h>
|
||||
@ -35,13 +34,10 @@
|
||||
|
||||
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: QDialog(parent),
|
||||
m_fileName(weatherName),
|
||||
m_dirs(directories),
|
||||
: AbstractExtItem(parent, weatherName, directories, debugCmd),
|
||||
debug(debugCmd),
|
||||
ui(new Ui::ExtWeather)
|
||||
{
|
||||
m_name = m_fileName;
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -169,71 +165,6 @@ QString ExtWeather::weatherFromInt(const int _id)
|
||||
}
|
||||
|
||||
|
||||
int ExtWeather::apiVersion()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::comment()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::fileName()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
|
||||
int ExtWeather::interval()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
|
||||
|
||||
bool ExtWeather::isActive()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_active;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::name()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
int ExtWeather::number()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return m_number;
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::tag(const QString _type)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Tag type" << _type;
|
||||
|
||||
return QString("%1%2").arg(_type).arg(m_number);
|
||||
}
|
||||
|
||||
|
||||
QString ExtWeather::city()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -258,66 +189,6 @@ int ExtWeather::ts()
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setActive(const bool _state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setComment(const QString _comment)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setInterval(const int _interval)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Interval" << _interval;
|
||||
|
||||
m_interval = _interval;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setName(const QString _name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setNumber(int _number)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number" << _number;
|
||||
if (_number == -1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
_number = qrand() % 1000;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Generated number is" << _number;
|
||||
}
|
||||
|
||||
m_number = _number;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::setCity(const QString _city)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -327,7 +198,6 @@ void ExtWeather::setCity(const QString _city)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExtWeather::setCountry(const QString _country)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -350,25 +220,19 @@ void ExtWeather::readConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs[i]).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName), QSettings::IniFormat);
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
if (!QDir(directories()[i]).entryList(QDir::Files).contains(fileName())) continue;
|
||||
QSettings settings(QString("%1/%2").arg(directories()[i]).arg(fileName()), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setName(settings.value(QString("Name"), m_name).toString());
|
||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
||||
setApiVersion(settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt());
|
||||
setCity(settings.value(QString("X-AW-City"), m_city).toString());
|
||||
setCountry(settings.value(QString("X-AW-Country"), m_country).toString());
|
||||
setTs(settings.value(QString("X-AW-TS"), m_ts).toInt());
|
||||
setActive(settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() == QString("true"));
|
||||
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt());
|
||||
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
// update for current API
|
||||
if ((m_apiVersion > 0) && (m_apiVersion < AWEWAPI)) {
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
|
||||
setApiVersion(AWEWAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -378,7 +242,7 @@ void ExtWeather::readConfiguration()
|
||||
QVariantMap ExtWeather::run()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if ((!m_active) || (isRunning)) return values;
|
||||
if ((!isActive()) || (isRunning)) return values;
|
||||
|
||||
if (times == 1) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Send request";
|
||||
@ -388,7 +252,7 @@ QVariantMap ExtWeather::run()
|
||||
}
|
||||
|
||||
// update value
|
||||
if (times >= m_interval) times = 0;
|
||||
if (times >= interval()) times = 0;
|
||||
times++;
|
||||
|
||||
return values;
|
||||
@ -399,14 +263,14 @@ int ExtWeather::showConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->lineEdit_name->setText(m_name);
|
||||
ui->lineEdit_comment->setText(m_comment);
|
||||
ui->label_numberValue->setText(QString("%1").arg(m_number));
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_numberValue->setText(QString("%1").arg(number()));
|
||||
ui->lineEdit_city->setText(m_city);
|
||||
ui->lineEdit_country->setText(m_country);
|
||||
ui->spinBox_timestamp->setValue(m_ts);
|
||||
ui->checkBox_active->setCheckState(m_active ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(m_interval);
|
||||
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked : Qt::Unchecked);
|
||||
ui->spinBox_interval->setValue(interval());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1) return ret;
|
||||
@ -425,39 +289,17 @@ int ExtWeather::showConfiguration()
|
||||
}
|
||||
|
||||
|
||||
bool ExtWeather::tryDelete()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << QString("%1/%2").arg(m_dirs[i]).arg(m_fileName) <<
|
||||
QFile::remove(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName));
|
||||
|
||||
// check if exists
|
||||
for (int i=0; i<m_dirs.count(); i++)
|
||||
if (QFile::exists(QString("%1/%2").arg(m_dirs[i]).arg(m_fileName))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ExtWeather::writeConfiguration()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs[0]).arg(m_fileName), QSettings::IniFormat);
|
||||
QSettings settings(QString("%1/%2").arg(directories()[0]).arg(fileName()), QSettings::IniFormat);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
settings.setValue(QString("Name"), m_name);
|
||||
settings.setValue(QString("Comment"), m_comment);
|
||||
settings.setValue(QString("X-AW-City"), m_city);
|
||||
settings.setValue(QString("X-AW-Country"), m_country);
|
||||
settings.setValue(QString("X-AW-TS"), m_ts);
|
||||
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
|
||||
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString());
|
||||
settings.setValue(QString("X-AW-Interval"), m_interval);
|
||||
settings.setValue(QString("X-AW-Number"), m_number);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -18,10 +18,11 @@
|
||||
#ifndef EXTWEATHER_H
|
||||
#define EXTWEATHER_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "abstractextitem.h"
|
||||
|
||||
#define OWM_URL "http://api.openweathermap.org/data/2.5/weather?q=$CITY,$COUNTRY&units=metric"
|
||||
#define OWM_FORECAST_URL "http://api.openweathermap.org/data/2.5/forecast?q=$CITY,$COUNTRY&units=metric"
|
||||
|
||||
@ -30,15 +31,9 @@ namespace Ui {
|
||||
class ExtWeather;
|
||||
}
|
||||
|
||||
class ExtWeather : public QDialog
|
||||
class ExtWeather : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int apiVersion READ apiVersion WRITE setApiVersion)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
||||
Q_PROPERTY(int interval READ interval WRITE setInterval)
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(int number READ number WRITE setNumber)
|
||||
Q_PROPERTY(QString city READ city WRITE setCity)
|
||||
Q_PROPERTY(QString country READ country WRITE setCountry)
|
||||
Q_PROPERTY(int ts READ ts WRITE setTs)
|
||||
@ -49,41 +44,24 @@ public:
|
||||
~ExtWeather();
|
||||
QString weatherFromInt(const int _id);
|
||||
// get methods
|
||||
int apiVersion();
|
||||
QString comment();
|
||||
QString fileName();
|
||||
int interval();
|
||||
bool isActive();
|
||||
QString name();
|
||||
int number();
|
||||
QString tag(const QString _type = QString("temperature"));
|
||||
QString city();
|
||||
QString country();
|
||||
int ts();
|
||||
// set methods
|
||||
void setApiVersion(const int _apiVersion = 0);
|
||||
void setActive(const bool _state = true);
|
||||
void setComment(const QString _comment = QString("empty"));
|
||||
void setInterval(const int _interval = 0);
|
||||
void setName(const QString _name = QString("none"));
|
||||
void setNumber(int _number = -1);
|
||||
void setCity(const QString _city = QString("New York"));
|
||||
void setCountry(const QString _country = QString("us"));
|
||||
void setCity(const QString _city = QString("London"));
|
||||
void setCountry(const QString _country = QString("uk"));
|
||||
void setTs(const int _ts = 0);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
QVariantMap run();
|
||||
int showConfiguration();
|
||||
bool tryDelete();
|
||||
void writeConfiguration();
|
||||
|
||||
private slots:
|
||||
void weatherReplyReceived(QNetworkReply *reply);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
bool debug;
|
||||
QNetworkAccessManager *manager;
|
||||
bool isRunning = false;
|
||||
@ -91,14 +69,8 @@ private:
|
||||
QVariantMap parseSingleJson(const QVariantMap json);
|
||||
QString url(const bool isForecast = false);
|
||||
// properties
|
||||
int m_apiVersion = 0;
|
||||
bool m_active = true;
|
||||
QString m_comment = QString("empty");
|
||||
int m_interval = 3600;
|
||||
QString m_name = QString("none");
|
||||
int m_number = -1;
|
||||
QString m_city = QString("New York");
|
||||
QString m_country = QString("us");
|
||||
QString m_city = QString("London");
|
||||
QString m_country = QString("uk");
|
||||
int m_ts = 0;
|
||||
// values
|
||||
int times = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user