mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-13 05:45:49 +00:00
more correct logging, use qt logging for qml as well
This commit is contained in:
@ -27,14 +27,14 @@
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
const QStringList directories)
|
||||
: QDialog(parent),
|
||||
m_fileName(desktopName),
|
||||
m_dirs(directories)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Desktop name" << desktopName;
|
||||
qCDebug(LOG_LIB) << "Directories" << directories;
|
||||
|
||||
m_name = m_fileName;
|
||||
}
|
||||
@ -42,16 +42,16 @@ AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
|
||||
AbstractExtItem::~AbstractExtItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
T *AbstractExtItem::copy(const QString fileName, const int number)
|
||||
T *AbstractExtItem::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
Q_UNUSED(fileName)
|
||||
Q_UNUSED(number)
|
||||
qCDebug(LOG_ESM);
|
||||
Q_UNUSED(_fileName)
|
||||
Q_UNUSED(_number)
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
// an analog of pure virtual method
|
||||
return new T();
|
||||
@ -61,7 +61,7 @@ T *AbstractExtItem::copy(const QString fileName, const int number)
|
||||
|
||||
int AbstractExtItem::apiVersion() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_apiVersion;
|
||||
}
|
||||
@ -69,7 +69,7 @@ int AbstractExtItem::apiVersion() const
|
||||
|
||||
QString AbstractExtItem::comment() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_comment;
|
||||
}
|
||||
@ -77,7 +77,7 @@ QString AbstractExtItem::comment() const
|
||||
|
||||
QStringList AbstractExtItem::directories() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_dirs;
|
||||
}
|
||||
@ -85,7 +85,7 @@ QStringList AbstractExtItem::directories() const
|
||||
|
||||
QString AbstractExtItem::fileName() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_fileName;
|
||||
}
|
||||
@ -93,7 +93,7 @@ QString AbstractExtItem::fileName() const
|
||||
|
||||
int AbstractExtItem::interval() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_interval;
|
||||
}
|
||||
@ -101,7 +101,7 @@ int AbstractExtItem::interval() const
|
||||
|
||||
bool AbstractExtItem::isActive() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_active;
|
||||
}
|
||||
@ -109,7 +109,7 @@ bool AbstractExtItem::isActive() const
|
||||
|
||||
QString AbstractExtItem::name() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_name;
|
||||
}
|
||||
@ -117,7 +117,7 @@ QString AbstractExtItem::name() const
|
||||
|
||||
int AbstractExtItem::number() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_number;
|
||||
}
|
||||
@ -125,8 +125,8 @@ int AbstractExtItem::number() const
|
||||
|
||||
QString AbstractExtItem::tag(const QString _type) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Tag type" << _type;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Tag type" << _type;
|
||||
|
||||
return QString("%1%2").arg(_type).arg(m_number);
|
||||
}
|
||||
@ -134,8 +134,8 @@ QString AbstractExtItem::tag(const QString _type) const
|
||||
|
||||
void AbstractExtItem::setApiVersion(const int _apiVersion)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Version" << _apiVersion;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Version" << _apiVersion;
|
||||
|
||||
m_apiVersion = _apiVersion;
|
||||
}
|
||||
@ -143,8 +143,8 @@ void AbstractExtItem::setApiVersion(const int _apiVersion)
|
||||
|
||||
void AbstractExtItem::setActive(const bool _state)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "State" << _state;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "State" << _state;
|
||||
|
||||
m_active = _state;
|
||||
}
|
||||
@ -152,8 +152,8 @@ void AbstractExtItem::setActive(const bool _state)
|
||||
|
||||
void AbstractExtItem::setComment(const QString _comment)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Comment" << _comment;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Comment" << _comment;
|
||||
|
||||
m_comment = _comment;
|
||||
}
|
||||
@ -161,8 +161,8 @@ void AbstractExtItem::setComment(const QString _comment)
|
||||
|
||||
void AbstractExtItem::setInterval(const int _interval)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Interval" << _interval;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Interval" << _interval;
|
||||
if (_interval <= 0) return;
|
||||
|
||||
m_interval = _interval;
|
||||
@ -171,8 +171,8 @@ void AbstractExtItem::setInterval(const int _interval)
|
||||
|
||||
void AbstractExtItem::setName(const QString _name)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Name" << _name;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Name" << _name;
|
||||
|
||||
m_name = _name;
|
||||
}
|
||||
@ -180,14 +180,14 @@ void AbstractExtItem::setName(const QString _name)
|
||||
|
||||
void AbstractExtItem::setNumber(int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Number" << _number;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
if (_number == -1)
|
||||
_number = []() {
|
||||
qCWarning(LOG_ESM) << "Number is empty, generate new one";
|
||||
qCWarning(LOG_LIB) << "Number is empty, generate new one";
|
||||
qsrand(QTime::currentTime().msec());
|
||||
int n = qrand() % 1000;
|
||||
qCDebug(LOG_ESM) << "Generated number is" << n;
|
||||
qCInfo(LOG_LIB) << "Generated number is" << n;
|
||||
return n;
|
||||
}();
|
||||
|
||||
@ -197,7 +197,7 @@ void AbstractExtItem::setNumber(int _number)
|
||||
|
||||
void AbstractExtItem::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
for (int i=m_dirs.count()-1; i>=0; i--) {
|
||||
if (!QDir(m_dirs.at(i)).entryList(QDir::Files).contains(m_fileName)) continue;
|
||||
@ -217,11 +217,11 @@ void AbstractExtItem::readConfiguration()
|
||||
|
||||
bool AbstractExtItem::tryDelete() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
foreach(QString dir, m_dirs) {
|
||||
bool status = QFile::remove(QString("%1/%2").arg(dir).arg(m_fileName));
|
||||
qCDebug(LOG_ESM) << "Remove file" << QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
||||
qCInfo(LOG_LIB) << "Remove file" << QString("%1/%2").arg(dir).arg(m_fileName) << status;
|
||||
}
|
||||
|
||||
// check if exists
|
||||
@ -233,10 +233,10 @@ bool AbstractExtItem::tryDelete() const
|
||||
|
||||
void AbstractExtItem::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(m_dirs.first()).arg(m_fileName), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
||||
|
@ -38,10 +38,9 @@ class AbstractExtItem : public QDialog
|
||||
|
||||
public:
|
||||
explicit AbstractExtItem(QWidget *parent = nullptr, const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~AbstractExtItem();
|
||||
template <class T> T *copy(const QString fileName, const int number);
|
||||
template <class T> T *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
int apiVersion() const;
|
||||
QString comment() const;
|
||||
|
@ -26,12 +26,10 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool debugCmd)
|
||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
dialog = new QDialog(this);
|
||||
widgetDialog = new QListWidget(dialog);
|
||||
@ -55,7 +53,7 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool
|
||||
|
||||
AbstractExtItemAggregator::~AbstractExtItemAggregator()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
@ -63,7 +61,7 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator()
|
||||
|
||||
QString AbstractExtItemAggregator::getName()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(this, i18n("Enter file name"),
|
||||
@ -78,7 +76,7 @@ QString AbstractExtItemAggregator::getName()
|
||||
|
||||
QVariant AbstractExtItemAggregator::configArgs() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_configArgs;
|
||||
}
|
||||
@ -86,8 +84,8 @@ QVariant AbstractExtItemAggregator::configArgs() const
|
||||
|
||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Configuration arguments" << _configArgs;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
||||
|
||||
m_configArgs = _configArgs;
|
||||
}
|
||||
@ -96,7 +94,7 @@ void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
|
||||
{
|
||||
Q_UNUSED(item)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return editItem();
|
||||
}
|
||||
@ -104,7 +102,7 @@ void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
|
||||
|
||||
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
if (static_cast<QPushButton *>(button) == copyButton)
|
||||
return copyItem();
|
||||
|
@ -33,7 +33,7 @@ class AbstractExtItemAggregator : public QWidget
|
||||
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
||||
|
||||
public:
|
||||
AbstractExtItemAggregator(QWidget *parent = nullptr, const bool debugCmd = false);
|
||||
explicit AbstractExtItemAggregator(QWidget *parent = nullptr);
|
||||
virtual ~AbstractExtItemAggregator();
|
||||
QString getName();
|
||||
// ui
|
||||
|
@ -33,13 +33,17 @@ template <class T>
|
||||
class ExtItemAggregator : public AbstractExtItemAggregator
|
||||
{
|
||||
public:
|
||||
explicit ExtItemAggregator(QWidget *parent, const QString type,
|
||||
const bool debugCmd = false)
|
||||
: AbstractExtItemAggregator(parent, debugCmd),
|
||||
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
||||
: AbstractExtItemAggregator(parent),
|
||||
m_type(type)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Type" << type;
|
||||
|
||||
// disable info because QtMsgType has invalid enum order
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
|
||||
const_cast<QLoggingCategory &>(LOG_LIB()).setEnabled(QtMsgType::QtInfoMsg, false);
|
||||
#endif /* QT_VERSION */
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
|
||||
initItems();
|
||||
@ -47,23 +51,23 @@ public:
|
||||
|
||||
virtual ~ExtItemAggregator()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
void editItems()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
repaint();
|
||||
int ret = dialog->exec();
|
||||
qCDebug(LOG_ESM) << "Dialog returns" << ret;
|
||||
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
||||
};
|
||||
|
||||
void initItems()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
m_items.clear();
|
||||
m_items = getItems();
|
||||
@ -71,7 +75,8 @@ public:
|
||||
|
||||
T *itemByTag(const QString _tag) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Tag" << _tag;
|
||||
|
||||
T *found = nullptr;
|
||||
foreach(T *item, m_items) {
|
||||
@ -79,13 +84,16 @@ public:
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
qCWarning(LOG_LIB) << "Could not find item by tag" << _tag;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
T *itemByTagNumber(const int _number) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
T *found = nullptr;
|
||||
foreach(T *item, m_items) {
|
||||
@ -93,13 +101,15 @@ public:
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
qCWarning(LOG_LIB) << "Could not find item by number" << _number;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
T *itemFromWidget() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
||||
if (widgetItem == nullptr) return nullptr;
|
||||
@ -110,20 +120,22 @@ public:
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
if (found == nullptr)
|
||||
qCWarning(LOG_LIB) << "Could not find item by name" << widgetItem->text();
|
||||
|
||||
return found;
|
||||
};
|
||||
|
||||
QList<T *> items() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_items;
|
||||
};
|
||||
|
||||
int uniqNumber() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QList<int> tagList;
|
||||
foreach(T *item, m_items) tagList.append(item->number());
|
||||
@ -140,7 +152,7 @@ private:
|
||||
// init method
|
||||
QList<T *> getItems()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
// create directory at $HOME
|
||||
QString localDir = QString("%1/awesomewidgets/%2")
|
||||
@ -148,7 +160,7 @@ private:
|
||||
.arg(m_type);
|
||||
QDir localDirectory;
|
||||
if (localDirectory.mkpath(localDir))
|
||||
qCDebug(LOG_ESM) << "Created directory" << localDir;
|
||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(m_type),
|
||||
@ -160,9 +172,9 @@ private:
|
||||
foreach(QString file, files) {
|
||||
if (!file.endsWith(QString(".desktop"))) continue;
|
||||
if (names.contains(file)) continue;
|
||||
qCDebug(LOG_ESM) << "Found file" << file << "in" << dir;
|
||||
qCInfo(LOG_LIB) << "Found file" << file << "in" << dir;
|
||||
names.append(file);
|
||||
items.append(new T(this, file, dirs, LOG_ESM().isDebugEnabled()));
|
||||
items.append(new T(this, file, dirs));
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +183,8 @@ private:
|
||||
|
||||
void repaint()
|
||||
{
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
widgetDialog->clear();
|
||||
foreach(T *_item, m_items) {
|
||||
QListWidgetItem *item = new QListWidgetItem(_item->fileName(), widgetDialog);
|
||||
@ -186,12 +200,15 @@ private:
|
||||
// methods
|
||||
void copyItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
T *source = itemFromWidget();
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
if ((source == nullptr) || (fileName.isEmpty())) return;
|
||||
if ((source == nullptr) || (fileName.isEmpty())) {
|
||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||
return;
|
||||
}
|
||||
|
||||
T *newItem = source->copy(fileName, number);
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
@ -202,16 +219,19 @@ private:
|
||||
|
||||
void createItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString fileName = getName();
|
||||
int number = uniqNumber();
|
||||
QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/%1").arg(m_type),
|
||||
QStandardPaths::LocateDirectory);
|
||||
if (fileName.isEmpty()) return;
|
||||
if (fileName.isEmpty()) {
|
||||
qCWarning(LOG_LIB) << "Nothing to create";
|
||||
return;
|
||||
};
|
||||
|
||||
T *newItem = new T(this, fileName, dirs, LOG_ESM().isDebugEnabled());
|
||||
T *newItem = new T(this, fileName, dirs);
|
||||
newItem->setNumber(number);
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
@ -221,10 +241,13 @@ private:
|
||||
|
||||
void deleteItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
T *source = itemFromWidget();
|
||||
if (source == nullptr) return;
|
||||
if (source == nullptr) {
|
||||
qCWarning(LOG_LIB) << "Nothing to delete";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->tryDelete()) {
|
||||
initItems();
|
||||
@ -234,10 +257,13 @@ private:
|
||||
|
||||
void editItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
T *source = itemFromWidget();
|
||||
if (source == nullptr) return;
|
||||
if (source == nullptr) {
|
||||
qCWarning(LOG_LIB) << "Nothing to edit";
|
||||
return;
|
||||
};
|
||||
|
||||
if (source->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
|
@ -34,13 +34,11 @@
|
||||
|
||||
|
||||
ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: AbstractExtItem(parent, quotesName, directories, debugCmd),
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, quotesName, directories),
|
||||
ui(new Ui::ExtQuotes)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
@ -64,7 +62,7 @@ ExtQuotes::ExtQuotes(QWidget *parent, const QString quotesName,
|
||||
|
||||
ExtQuotes::~ExtQuotes()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(quotesReplyReceived(QNetworkReply *)));
|
||||
|
||||
@ -73,18 +71,19 @@ ExtQuotes::~ExtQuotes()
|
||||
}
|
||||
|
||||
|
||||
ExtQuotes *ExtQuotes::copy(const QString fileName, const int number)
|
||||
ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), fileName,
|
||||
directories(), LOG_ESM().isDebugEnabled());
|
||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(number);
|
||||
item->setNumber(_number);
|
||||
item->setTicker(ticker());
|
||||
|
||||
return item;
|
||||
@ -93,7 +92,7 @@ ExtQuotes *ExtQuotes::copy(const QString fileName, const int number)
|
||||
|
||||
QString ExtQuotes::ticker() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_ticker;
|
||||
}
|
||||
@ -101,7 +100,7 @@ QString ExtQuotes::ticker() const
|
||||
|
||||
QString ExtQuotes::uniq() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_ticker;
|
||||
}
|
||||
@ -109,8 +108,8 @@ QString ExtQuotes::uniq() const
|
||||
|
||||
void ExtQuotes::setTicker(const QString _ticker)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Ticker" << _ticker;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Ticker" << _ticker;
|
||||
|
||||
m_ticker = _ticker;
|
||||
}
|
||||
@ -118,7 +117,7 @@ void ExtQuotes::setTicker(const QString _ticker)
|
||||
|
||||
void ExtQuotes::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
@ -132,6 +131,7 @@ void ExtQuotes::readConfiguration()
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEQAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEQAPI;
|
||||
setApiVersion(AWEQAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -140,11 +140,11 @@ void ExtQuotes::readConfiguration()
|
||||
|
||||
QVariantHash ExtQuotes::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
if ((!isActive()) || (isRunning)) return values;
|
||||
|
||||
if (times == 1) {
|
||||
qCDebug(LOG_ESM) << "Send request";
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url())));
|
||||
new QReplyTimeout(reply, 1000);
|
||||
@ -161,7 +161,7 @@ QVariantHash ExtQuotes::run()
|
||||
int ExtQuotes::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -187,11 +187,11 @@ int ExtQuotes::showConfiguration(const QVariant args)
|
||||
|
||||
void ExtQuotes::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Ticker"), m_ticker);
|
||||
@ -202,9 +202,9 @@ void ExtQuotes::writeConfiguration() const
|
||||
|
||||
void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Return code" << reply->error();
|
||||
qCDebug(LOG_ESM) << "Reply error message" << reply->errorString();
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error();
|
||||
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
QJsonParseError error;
|
||||
@ -212,7 +212,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
reply->deleteLater();
|
||||
if ((reply->error() != QNetworkReply::NoError) ||
|
||||
(error.error != QJsonParseError::NoError)) {
|
||||
qCWarning(LOG_ESM) << "Parse error" << error.errorString();
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
QVariantMap jsonQuotes = jsonDoc.toVariant().toMap()[QString("query")].toMap();
|
||||
@ -222,21 +222,21 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
// ask
|
||||
value = jsonQuotes[QString("Ask")].toString().toFloat();
|
||||
values[tag(QString("askchg"))] = values[QString("ask")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("ask")].toFloat();
|
||||
value - values[QString("ask")].toFloat();
|
||||
values[tag(QString("percaskchg"))] = 100.0 * values[QString("askchg")].toFloat() / values[QString("ask")].toFloat();
|
||||
values[tag(QString("ask"))] = value;
|
||||
|
||||
// bid
|
||||
value = jsonQuotes[QString("Bid")].toString().toFloat();
|
||||
values[tag(QString("bidchg"))] = values[QString("bid")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("bid")].toFloat();
|
||||
value - values[QString("bid")].toFloat();
|
||||
values[tag(QString("percbidchg"))] = 100.0 * values[QString("bidchg")].toFloat() / values[QString("bid")].toFloat();
|
||||
values[tag(QString("bid"))] = value;
|
||||
|
||||
// last trade
|
||||
value = jsonQuotes[QString("LastTradePriceOnly")].toString().toFloat();
|
||||
values[tag(QString("pricechg"))] = values[QString("price")].toFloat() == 0.0 ? 0.0 :
|
||||
value - values[QString("price")].toFloat();
|
||||
value - values[QString("price")].toFloat();
|
||||
values[tag(QString("percpricechg"))] = 100.0 * values[QString("pricechg")].toFloat() / values[QString("price")].toFloat();
|
||||
values[tag(QString("price"))] = value;
|
||||
}
|
||||
@ -244,7 +244,7 @@ void ExtQuotes::quotesReplyReceived(QNetworkReply *reply)
|
||||
|
||||
void ExtQuotes::translate()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
@ -258,11 +258,11 @@ void ExtQuotes::translate()
|
||||
|
||||
QString ExtQuotes::url() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString apiUrl = QString(YAHOO_URL);
|
||||
apiUrl.replace(QString("$TICKER"), m_ticker);
|
||||
qCDebug(LOG_ESM) << "API url" << apiUrl;
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ class ExtQuotes : public AbstractExtItem
|
||||
|
||||
public:
|
||||
explicit ExtQuotes(QWidget *parent = nullptr, const QString quotesName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~ExtQuotes();
|
||||
ExtQuotes *copy(const QString fileName, const int number);
|
||||
ExtQuotes *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
QString ticker() const;
|
||||
QString uniq() const;
|
||||
|
@ -32,13 +32,11 @@
|
||||
|
||||
|
||||
ExtScript::ExtScript(QWidget *parent, const QString scriptName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: AbstractExtItem(parent, scriptName, directories, debugCmd),
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, scriptName, directories),
|
||||
ui(new Ui::ExtScript)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
readConfiguration();
|
||||
readJsonFilters();
|
||||
@ -55,7 +53,7 @@ ExtScript::ExtScript(QWidget *parent, const QString scriptName,
|
||||
|
||||
ExtScript::~ExtScript()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
process->kill();
|
||||
delete process;
|
||||
@ -63,12 +61,13 @@ ExtScript::~ExtScript()
|
||||
}
|
||||
|
||||
|
||||
ExtScript *ExtScript::copy(const QString fileName, const int number)
|
||||
ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), fileName,
|
||||
directories(), LOG_ESM().isDebugEnabled());
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
@ -76,7 +75,7 @@ ExtScript *ExtScript::copy(const QString fileName, const int number)
|
||||
item->setHasOutput(hasOutput());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(number);
|
||||
item->setNumber(_number);
|
||||
item->setPrefix(prefix());
|
||||
item->setRedirect(redirect());
|
||||
|
||||
@ -86,7 +85,7 @@ ExtScript *ExtScript::copy(const QString fileName, const int number)
|
||||
|
||||
QString ExtScript::executable() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_executable;
|
||||
}
|
||||
@ -94,7 +93,7 @@ QString ExtScript::executable() const
|
||||
|
||||
QStringList ExtScript::filters() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_filters;
|
||||
}
|
||||
@ -102,7 +101,7 @@ QStringList ExtScript::filters() const
|
||||
|
||||
bool ExtScript::hasOutput() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_output;
|
||||
}
|
||||
@ -110,7 +109,7 @@ bool ExtScript::hasOutput() const
|
||||
|
||||
QString ExtScript::prefix() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_prefix;
|
||||
}
|
||||
@ -118,7 +117,7 @@ QString ExtScript::prefix() const
|
||||
|
||||
ExtScript::Redirect ExtScript::redirect() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_redirect;
|
||||
}
|
||||
@ -126,7 +125,7 @@ ExtScript::Redirect ExtScript::redirect() const
|
||||
|
||||
QString ExtScript::uniq() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_executable;
|
||||
}
|
||||
@ -134,7 +133,7 @@ QString ExtScript::uniq() const
|
||||
|
||||
QString ExtScript::strRedirect() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString value;
|
||||
switch (m_redirect) {
|
||||
@ -156,8 +155,8 @@ QString ExtScript::strRedirect() const
|
||||
|
||||
void ExtScript::setExecutable(const QString _executable)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Executable" << _executable;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Executable" << _executable;
|
||||
|
||||
m_executable = _executable;
|
||||
}
|
||||
@ -165,18 +164,20 @@ void ExtScript::setExecutable(const QString _executable)
|
||||
|
||||
void ExtScript::setFilters(const QStringList _filters)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Filters" << _filters;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Filters" << _filters;
|
||||
|
||||
foreach(QString filter, _filters)
|
||||
updateFilter(filter);
|
||||
std::for_each(_filters.cbegin(), _filters.cend(),
|
||||
[this](QString filter) { return updateFilter(filter); });
|
||||
// foreach(QString filter, _filters)
|
||||
// updateFilter(filter);
|
||||
}
|
||||
|
||||
|
||||
void ExtScript::setHasOutput(const bool _state)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "State" << _state;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "State" << _state;
|
||||
|
||||
m_output = _state;
|
||||
}
|
||||
@ -184,8 +185,8 @@ void ExtScript::setHasOutput(const bool _state)
|
||||
|
||||
void ExtScript::setPrefix(const QString _prefix)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Prefix" << _prefix;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Prefix" << _prefix;
|
||||
|
||||
m_prefix = _prefix;
|
||||
}
|
||||
@ -193,8 +194,8 @@ void ExtScript::setPrefix(const QString _prefix)
|
||||
|
||||
void ExtScript::setRedirect(const Redirect _redirect)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Redirect" << _redirect;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
m_redirect = _redirect;
|
||||
}
|
||||
@ -202,8 +203,8 @@ void ExtScript::setRedirect(const Redirect _redirect)
|
||||
|
||||
void ExtScript::setStrRedirect(const QString _redirect)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Redirect" << _redirect;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
if (_redirect == QString("stdout2sdterr"))
|
||||
m_redirect = stdout2stderr;
|
||||
@ -216,14 +217,14 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
||||
|
||||
QString ExtScript::applyFilters(QString _value) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Value" << _value;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Value" << _value;
|
||||
|
||||
foreach(QString filt, m_filters) {
|
||||
qCDebug(LOG_ESM) << "Found filter" << filt;
|
||||
qCInfo(LOG_LIB) << "Found filter" << filt;
|
||||
QVariantMap filter = jsonFilters[filt].toMap();
|
||||
if (filter.isEmpty()) {
|
||||
qCWarning(LOG_ESM) << "Could not find filter in the json";
|
||||
qCWarning(LOG_LIB) << "Could not find filter" << _value << "in the json";
|
||||
continue;
|
||||
}
|
||||
foreach(QString f, filter.keys())
|
||||
@ -236,9 +237,9 @@ QString ExtScript::applyFilters(QString _value) const
|
||||
|
||||
void ExtScript::updateFilter(const QString _filter, const bool _add)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Filter" << _filter;
|
||||
qCDebug(LOG_ESM) << "Should be added" << _add;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
qCDebug(LOG_LIB) << "Should be added" << _add;
|
||||
|
||||
if (_add) {
|
||||
if (m_filters.contains(_filter)) return;
|
||||
@ -251,7 +252,7 @@ void ExtScript::updateFilter(const QString _filter, const bool _add)
|
||||
|
||||
void ExtScript::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
@ -274,6 +275,7 @@ void ExtScript::readConfiguration()
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWESAPI;
|
||||
setApiVersion(AWESAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -282,39 +284,41 @@ void ExtScript::readConfiguration()
|
||||
|
||||
void ExtScript::readJsonFilters()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/scripts/awesomewidgets-extscripts-filters.json"));
|
||||
qCDebug(LOG_ESM) << "Configuration file" << fileName;
|
||||
qCInfo(LOG_LIB) << "Configuration file" << fileName;
|
||||
QFile jsonFile(fileName);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qCWarning(LOG_LIB) << "Could not open" << fileName;
|
||||
return;
|
||||
}
|
||||
QString jsonText = jsonFile.readAll();
|
||||
jsonFile.close();
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(LOG_ESM) << "Json parse error" << error.errorString();
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
jsonFilters = jsonDoc.toVariant().toMap();
|
||||
|
||||
qCDebug(LOG_ESM) << "Filters" << jsonFilters;
|
||||
qCDebug(LOG_LIB) << "Filters" << jsonFilters;
|
||||
}
|
||||
|
||||
|
||||
QVariantHash ExtScript::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
if (!isActive()) return value;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
QStringList cmdList;
|
||||
if (!m_prefix.isEmpty()) cmdList.append(m_prefix);
|
||||
cmdList.append(m_executable);
|
||||
qCDebug(LOG_ESM) << "cmd" << cmdList.join(QChar(' '));
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
|
||||
process->start(cmdList.join(QChar(' ')));
|
||||
} else if (times >= interval())
|
||||
times = 0;
|
||||
@ -327,7 +331,7 @@ QVariantHash ExtScript::run()
|
||||
int ExtScript::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -367,11 +371,11 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
|
||||
void ExtScript::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
@ -387,13 +391,13 @@ void ExtScript::writeConfiguration() const
|
||||
|
||||
void ExtScript::updateValue()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
qCDebug(LOG_ESM) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
QString qdebug = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardError()).trimmed();
|
||||
qCDebug(LOG_ESM) << "Error" << qdebug;
|
||||
qCInfo(LOG_LIB) << "Error" << qdebug;
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
|
||||
qCDebug(LOG_ESM) << "Error" << qoutput;
|
||||
qCInfo(LOG_LIB) << "Error" << qoutput;
|
||||
QString strValue;
|
||||
|
||||
switch (m_redirect) {
|
||||
@ -415,7 +419,7 @@ void ExtScript::updateValue()
|
||||
|
||||
void ExtScript::translate()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
|
@ -45,10 +45,9 @@ public:
|
||||
};
|
||||
|
||||
explicit ExtScript(QWidget *parent = nullptr, const QString scriptName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
~ExtScript();
|
||||
ExtScript *copy(const QString fileName, const int number);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~ExtScript();
|
||||
ExtScript *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
QString executable() const;
|
||||
QStringList filters() const;
|
||||
|
@ -30,13 +30,11 @@
|
||||
|
||||
|
||||
ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: AbstractExtItem(parent, upgradeName, directories, debugCmd),
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, upgradeName, directories),
|
||||
ui(new Ui::ExtUpgrade)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
@ -52,7 +50,7 @@ ExtUpgrade::ExtUpgrade(QWidget *parent, const QString upgradeName,
|
||||
|
||||
ExtUpgrade::~ExtUpgrade()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
process->kill();
|
||||
delete process;
|
||||
@ -60,12 +58,13 @@ ExtUpgrade::~ExtUpgrade()
|
||||
}
|
||||
|
||||
|
||||
ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number)
|
||||
ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()), fileName,
|
||||
directories(), LOG_ESM().isDebugEnabled());
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()), _fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
@ -73,7 +72,7 @@ ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number)
|
||||
item->setFilter(filter());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(number);
|
||||
item->setNumber(_number);
|
||||
item->setNull(null());
|
||||
|
||||
return item;
|
||||
@ -82,7 +81,7 @@ ExtUpgrade *ExtUpgrade::copy(const QString fileName, const int number)
|
||||
|
||||
QString ExtUpgrade::executable() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_executable;
|
||||
}
|
||||
@ -90,7 +89,7 @@ QString ExtUpgrade::executable() const
|
||||
|
||||
QString ExtUpgrade::filter() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_filter;
|
||||
}
|
||||
@ -98,7 +97,7 @@ QString ExtUpgrade::filter() const
|
||||
|
||||
int ExtUpgrade::null() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_null;
|
||||
}
|
||||
@ -106,7 +105,7 @@ int ExtUpgrade::null() const
|
||||
|
||||
QString ExtUpgrade::uniq() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_executable;
|
||||
}
|
||||
@ -114,8 +113,8 @@ QString ExtUpgrade::uniq() const
|
||||
|
||||
void ExtUpgrade::setExecutable(const QString _executable)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Executable" << _executable;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Executable" << _executable;
|
||||
|
||||
m_executable = _executable;
|
||||
}
|
||||
@ -123,8 +122,8 @@ void ExtUpgrade::setExecutable(const QString _executable)
|
||||
|
||||
void ExtUpgrade::setFilter(const QString _filter)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Filter" << _filter;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
|
||||
m_filter = _filter;
|
||||
}
|
||||
@ -132,8 +131,8 @@ void ExtUpgrade::setFilter(const QString _filter)
|
||||
|
||||
void ExtUpgrade::setNull(const int _null)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Null lines" << _null;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Null lines" << _null;
|
||||
if (_null < 0) return;
|
||||
|
||||
m_null = _null;
|
||||
@ -142,7 +141,7 @@ void ExtUpgrade::setNull(const int _null)
|
||||
|
||||
void ExtUpgrade::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
@ -159,6 +158,7 @@ void ExtUpgrade::readConfiguration()
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEUAPI;
|
||||
setApiVersion(AWEUAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -167,12 +167,14 @@ void ExtUpgrade::readConfiguration()
|
||||
|
||||
QVariantHash ExtUpgrade::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
if (!isActive()) return value;
|
||||
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning))
|
||||
process->start(QString("sh -c \"%1\"").arg(m_executable));
|
||||
else if (times >= interval())
|
||||
if ((times == 1) && (process->state() == QProcess::NotRunning)) {
|
||||
QString cmd = QString("sh -c \"%1\"").arg(m_executable);
|
||||
qCInfo(LOG_LIB) << "Run cmd" << cmd;
|
||||
process->start(cmd);
|
||||
} else if (times >= interval())
|
||||
times = 0;
|
||||
times++;
|
||||
|
||||
@ -183,7 +185,7 @@ QVariantHash ExtUpgrade::run()
|
||||
int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -213,11 +215,11 @@ int ExtUpgrade::showConfiguration(const QVariant args)
|
||||
|
||||
void ExtUpgrade::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("Exec"), m_executable);
|
||||
@ -231,10 +233,10 @@ void ExtUpgrade::writeConfiguration() const
|
||||
|
||||
void ExtUpgrade::updateValue()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
qCDebug(LOG_ESM) << "Cmd returns" << process->exitCode();
|
||||
qCDebug(LOG_ESM) << "Error" << process->readAllStandardError();
|
||||
qCInfo(LOG_LIB) << "Cmd returns" << process->exitCode();
|
||||
qCInfo(LOG_LIB) << "Error" << process->readAllStandardError();
|
||||
|
||||
QString qoutput = QTextCodec::codecForMib(106)->toUnicode(process->readAllStandardOutput()).trimmed();
|
||||
value[tag(QString("pkgcount"))] = [this](QString output) {
|
||||
@ -247,7 +249,7 @@ void ExtUpgrade::updateValue()
|
||||
|
||||
void ExtUpgrade::translate()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
|
@ -36,10 +36,9 @@ class ExtUpgrade : public AbstractExtItem
|
||||
|
||||
public:
|
||||
explicit ExtUpgrade(QWidget *parent = nullptr, const QString upgradeName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
~ExtUpgrade();
|
||||
ExtUpgrade *copy(const QString fileName, const int number);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~ExtUpgrade();
|
||||
ExtUpgrade *copy(const QString _fileName, const int _number);
|
||||
// get methods
|
||||
QString executable() const;
|
||||
QString filter() const;
|
||||
|
@ -34,13 +34,11 @@
|
||||
|
||||
|
||||
ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: AbstractExtItem(parent, weatherName, directories, debugCmd),
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, weatherName, directories),
|
||||
ui(new Ui::ExtWeather)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
@ -60,7 +58,7 @@ ExtWeather::ExtWeather(QWidget *parent, const QString weatherName,
|
||||
|
||||
ExtWeather::~ExtWeather()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
disconnect(manager, SIGNAL(finished(QNetworkReply *)),
|
||||
this, SLOT(weatherReplyReceived(QNetworkReply *)));
|
||||
@ -70,12 +68,13 @@ ExtWeather::~ExtWeather()
|
||||
}
|
||||
|
||||
|
||||
ExtWeather *ExtWeather::copy(const QString fileName, const int number)
|
||||
ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), fileName,
|
||||
directories(), LOG_ESM().isDebugEnabled());
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()), _fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setCity(city());
|
||||
@ -83,7 +82,7 @@ ExtWeather *ExtWeather::copy(const QString fileName, const int number)
|
||||
item->setCountry(country());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(number);
|
||||
item->setNumber(_number);
|
||||
item->setTs(ts());
|
||||
|
||||
return item;
|
||||
@ -92,8 +91,8 @@ ExtWeather *ExtWeather::copy(const QString fileName, const int number)
|
||||
|
||||
QString ExtWeather::weatherFromInt(const int _id) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "ID" << _id;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "ID" << _id;
|
||||
// refer to http://openweathermap.org/weather-conditions
|
||||
|
||||
QString weather;
|
||||
@ -192,7 +191,7 @@ QString ExtWeather::weatherFromInt(const int _id) const
|
||||
|
||||
QString ExtWeather::city() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_city;
|
||||
}
|
||||
@ -200,7 +199,7 @@ QString ExtWeather::city() const
|
||||
|
||||
QString ExtWeather::country() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_country;
|
||||
}
|
||||
@ -208,7 +207,7 @@ QString ExtWeather::country() const
|
||||
|
||||
int ExtWeather::ts() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_ts;
|
||||
}
|
||||
@ -216,7 +215,7 @@ int ExtWeather::ts() const
|
||||
|
||||
QString ExtWeather::uniq() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts);
|
||||
}
|
||||
@ -224,8 +223,8 @@ QString ExtWeather::uniq() const
|
||||
|
||||
void ExtWeather::setCity(const QString _city)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "City" << _city;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "City" << _city;
|
||||
|
||||
m_city = _city;
|
||||
}
|
||||
@ -233,8 +232,8 @@ void ExtWeather::setCity(const QString _city)
|
||||
|
||||
void ExtWeather::setCountry(const QString _country)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Country" << _country;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Country" << _country;
|
||||
|
||||
m_country = _country;
|
||||
}
|
||||
@ -242,8 +241,8 @@ void ExtWeather::setCountry(const QString _country)
|
||||
|
||||
void ExtWeather::setTs(const int _ts)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Timestamp" << _ts;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Timestamp" << _ts;
|
||||
|
||||
m_ts = _ts;
|
||||
}
|
||||
@ -251,7 +250,7 @@ void ExtWeather::setTs(const int _ts)
|
||||
|
||||
void ExtWeather::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
@ -267,6 +266,7 @@ void ExtWeather::readConfiguration()
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEWAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWEWAPI;
|
||||
setApiVersion(AWEWAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -275,11 +275,11 @@ void ExtWeather::readConfiguration()
|
||||
|
||||
QVariantHash ExtWeather::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
if ((!isActive()) || (isRunning)) return values;
|
||||
|
||||
if (times == 1) {
|
||||
qCDebug(LOG_ESM) << "Send request";
|
||||
qCInfo(LOG_LIB) << "Send request";
|
||||
isRunning = true;
|
||||
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url(m_ts != 0))));
|
||||
new QReplyTimeout(reply, 1000);
|
||||
@ -296,7 +296,7 @@ QVariantHash ExtWeather::run()
|
||||
int ExtWeather::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
@ -326,11 +326,11 @@ int ExtWeather::showConfiguration(const QVariant args)
|
||||
|
||||
void ExtWeather::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-City"), m_city);
|
||||
@ -344,9 +344,9 @@ void ExtWeather::writeConfiguration() const
|
||||
|
||||
void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Return code" << reply->error();
|
||||
qCDebug(LOG_ESM) << "Reply error message" << reply->errorString();
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Return code" << reply->error();
|
||||
qCDebug(LOG_LIB) << "Reply error message" << reply->errorString();
|
||||
|
||||
isRunning = false;
|
||||
QJsonParseError error;
|
||||
@ -354,14 +354,14 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
reply->deleteLater();
|
||||
if ((reply->error() != QNetworkReply::NoError) ||
|
||||
(error.error != QJsonParseError::NoError)) {
|
||||
qCWarning(LOG_ESM) << "Parse error" << error.errorString();
|
||||
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
// convert to map
|
||||
QVariantMap json = jsonDoc.toVariant().toMap();
|
||||
if (json[QString("cod")].toInt() != 200) {
|
||||
qCWarning(LOG_ESM) << "Invalid return code";
|
||||
qCWarning(LOG_LIB) << "Invalid return code";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -378,7 +378,8 @@ void ExtWeather::weatherReplyReceived(QNetworkReply *reply)
|
||||
|
||||
QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Single json data" << json;
|
||||
|
||||
QVariantHash output;
|
||||
|
||||
@ -404,7 +405,7 @@ QVariantHash ExtWeather::parseSingleJson(const QVariantMap json) const
|
||||
|
||||
void ExtWeather::translate()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
@ -419,13 +420,13 @@ void ExtWeather::translate()
|
||||
|
||||
QString ExtWeather::url(const bool isForecast) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Is forecast" << isForecast;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Is forecast" << isForecast;
|
||||
|
||||
QString apiUrl = isForecast ? QString(OWM_FORECAST_URL) : QString(OWM_URL);
|
||||
apiUrl.replace(QString("$CITY"), m_city);
|
||||
apiUrl.replace(QString("$COUNTRY"), m_country);
|
||||
qCDebug(LOG_ESM) << "API url" << apiUrl;
|
||||
qCInfo(LOG_LIB) << "API url" << apiUrl;
|
||||
|
||||
return apiUrl;
|
||||
}
|
||||
|
@ -40,10 +40,9 @@ class ExtWeather : public AbstractExtItem
|
||||
|
||||
public:
|
||||
explicit ExtWeather(QWidget *parent = nullptr, const QString weatherName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
~ExtWeather();
|
||||
ExtWeather *copy(const QString fileName, const int number);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~ExtWeather();
|
||||
ExtWeather *copy(const QString _fileName, const int _number);
|
||||
QString weatherFromInt(const int _id) const;
|
||||
// get methods
|
||||
QString city() const;
|
||||
|
@ -33,13 +33,11 @@
|
||||
|
||||
|
||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
const QStringList directories, const bool debugCmd)
|
||||
: AbstractExtItem(parent, desktopName, directories, debugCmd),
|
||||
const QStringList directories)
|
||||
: AbstractExtItem(parent, desktopName, directories),
|
||||
ui(new Ui::GraphicalItem)
|
||||
{
|
||||
// logging
|
||||
const_cast<QLoggingCategory &>(LOG_ESM()).setEnabled(QtMsgType::QtDebugMsg, debugCmd);
|
||||
qSetMessagePattern(LOG_FORMAT);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
@ -52,18 +50,19 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
|
||||
GraphicalItem::~GraphicalItem()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
GraphicalItem *GraphicalItem::copy(const QString fileName, const int number)
|
||||
GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
||||
qCDebug(LOG_LIB) << "Number" << _number;
|
||||
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
|
||||
fileName, directories(), LOG_ESM().isDebugEnabled());
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()), _fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setActiveColor(activeColor());
|
||||
item->setApiVersion(apiVersion());
|
||||
@ -73,8 +72,8 @@ GraphicalItem *GraphicalItem::copy(const QString fileName, const int number)
|
||||
item->setHeight(height());
|
||||
item->setInactiveColor(inactiveColor());
|
||||
item->setInterval(interval());
|
||||
item->setName(QString("bar%1").arg(number));
|
||||
item->setNumber(number);
|
||||
item->setName(QString("bar%1").arg(_number));
|
||||
item->setNumber(_number);
|
||||
item->setType(type());
|
||||
item->setWidth(width());
|
||||
|
||||
@ -84,14 +83,14 @@ GraphicalItem *GraphicalItem::copy(const QString fileName, const int number)
|
||||
|
||||
QString GraphicalItem::image(const float value) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Value" << value;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Value" << value;
|
||||
if (m_bar == QString("none")) return QString("");
|
||||
|
||||
QColor active = stringToColor(m_activeColor);
|
||||
QColor inactive = stringToColor(m_inactiveColor);
|
||||
float percent = value / 100.0;
|
||||
int scale[2] = {1, 1};
|
||||
int scale[2] = { 1, 1 };
|
||||
QPen pen = QPen();
|
||||
QGraphicsScene *scene = new QGraphicsScene();
|
||||
scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
@ -164,7 +163,7 @@ QString GraphicalItem::image(const float value) const
|
||||
|
||||
QString GraphicalItem::bar() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_bar;
|
||||
}
|
||||
@ -172,7 +171,7 @@ QString GraphicalItem::bar() const
|
||||
|
||||
QString GraphicalItem::activeColor() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_activeColor;
|
||||
}
|
||||
@ -180,7 +179,7 @@ QString GraphicalItem::activeColor() const
|
||||
|
||||
QString GraphicalItem::inactiveColor() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_inactiveColor;
|
||||
}
|
||||
@ -188,7 +187,7 @@ QString GraphicalItem::inactiveColor() const
|
||||
|
||||
QString GraphicalItem::tag() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return name() + m_bar;
|
||||
}
|
||||
@ -196,7 +195,7 @@ QString GraphicalItem::tag() const
|
||||
|
||||
GraphicalItem::Type GraphicalItem::type() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_type;
|
||||
}
|
||||
@ -204,7 +203,7 @@ GraphicalItem::Type GraphicalItem::type() const
|
||||
|
||||
QString GraphicalItem::strType() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
@ -225,7 +224,7 @@ QString GraphicalItem::strType() const
|
||||
|
||||
GraphicalItem::Direction GraphicalItem::direction() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_direction;
|
||||
}
|
||||
@ -233,7 +232,7 @@ GraphicalItem::Direction GraphicalItem::direction() const
|
||||
|
||||
QString GraphicalItem::strDirection() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QString value;
|
||||
switch (m_direction) {
|
||||
@ -251,7 +250,7 @@ QString GraphicalItem::strDirection() const
|
||||
|
||||
int GraphicalItem::height() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_height;
|
||||
}
|
||||
@ -259,7 +258,7 @@ int GraphicalItem::height() const
|
||||
|
||||
int GraphicalItem::width() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_width;
|
||||
}
|
||||
@ -267,7 +266,7 @@ int GraphicalItem::width() const
|
||||
|
||||
QString GraphicalItem::uniq() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
return m_bar;
|
||||
}
|
||||
@ -275,25 +274,21 @@ QString GraphicalItem::uniq() const
|
||||
|
||||
void GraphicalItem::setBar(const QString _bar)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Bar" << _bar;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Bar" << _bar;
|
||||
|
||||
if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) &&
|
||||
(!_bar.contains(QRegExp(QString("gpu")))) &&
|
||||
(!_bar.contains(QRegExp(QString("mem")))) &&
|
||||
(!_bar.contains(QRegExp(QString("swap")))) &&
|
||||
(!_bar.contains(QRegExp(QString("hdd[0-9].*")))) &&
|
||||
(!_bar.contains(QRegExp(QString("bat.*")))))
|
||||
if (!_bar.contains(QRegExp(QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) {
|
||||
qCWarning(LOG_LIB) << "Unsupported bar type" << _bar;
|
||||
m_bar = QString("none");
|
||||
else
|
||||
} else
|
||||
m_bar = _bar;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setActiveColor(const QString _color)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Color" << _color;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Color" << _color;
|
||||
|
||||
m_activeColor = _color;
|
||||
}
|
||||
@ -301,8 +296,8 @@ void GraphicalItem::setActiveColor(const QString _color)
|
||||
|
||||
void GraphicalItem::setInactiveColor(const QString _color)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Color" << _color;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Color" << _color;
|
||||
|
||||
m_inactiveColor = _color;
|
||||
}
|
||||
@ -310,8 +305,8 @@ void GraphicalItem::setInactiveColor(const QString _color)
|
||||
|
||||
void GraphicalItem::setType(const Type _type)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Type" << _type;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
m_type = _type;
|
||||
}
|
||||
@ -319,8 +314,8 @@ void GraphicalItem::setType(const Type _type)
|
||||
|
||||
void GraphicalItem::setStrType(const QString _type)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Type" << _type;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
if (_type == QString("Vertical"))
|
||||
setType(Vertical);
|
||||
@ -333,8 +328,8 @@ void GraphicalItem::setStrType(const QString _type)
|
||||
|
||||
void GraphicalItem::setDirection(const Direction _direction)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Direction" << _direction;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Direction" << _direction;
|
||||
|
||||
m_direction = _direction;
|
||||
}
|
||||
@ -342,8 +337,8 @@ void GraphicalItem::setDirection(const Direction _direction)
|
||||
|
||||
void GraphicalItem::setStrDirection(const QString _direction)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Direction" << _direction;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Direction" << _direction;
|
||||
|
||||
if (_direction == QString("RightToLeft"))
|
||||
setDirection(RightToLeft);
|
||||
@ -354,8 +349,8 @@ void GraphicalItem::setStrDirection(const QString _direction)
|
||||
|
||||
void GraphicalItem::setHeight(const int _height)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Height" << _height;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Height" << _height;
|
||||
if (_height <= 0) return;
|
||||
|
||||
m_height = _height;
|
||||
@ -364,8 +359,8 @@ void GraphicalItem::setHeight(const int _height)
|
||||
|
||||
void GraphicalItem::setWidth(const int _width)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Width" << _width;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Width" << _width;
|
||||
if (_width <= 0) return;
|
||||
|
||||
m_width = _width;
|
||||
@ -374,7 +369,7 @@ void GraphicalItem::setWidth(const int _width)
|
||||
|
||||
void GraphicalItem::readConfiguration()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::readConfiguration();
|
||||
|
||||
for (int i=directories().count()-1; i>=0; i--) {
|
||||
@ -396,6 +391,7 @@ void GraphicalItem::readConfiguration()
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to" << AWGIAPI;
|
||||
setApiVersion(AWGIAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
@ -404,7 +400,7 @@ void GraphicalItem::readConfiguration()
|
||||
|
||||
QVariantHash GraphicalItem::run()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
// required by abstract class
|
||||
return QVariantHash();
|
||||
@ -413,7 +409,8 @@ QVariantHash GraphicalItem::run()
|
||||
|
||||
int GraphicalItem::showConfiguration(const QVariant args)
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Combobox arguments" << args;
|
||||
QStringList tags = args.toStringList();
|
||||
|
||||
ui->label_nameValue->setText(name());
|
||||
@ -449,11 +446,11 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
|
||||
void GraphicalItem::writeConfiguration() const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
AbstractExtItem::writeConfiguration();
|
||||
|
||||
QSettings settings(QString("%1/%2").arg(directories().first()).arg(fileName()), QSettings::IniFormat);
|
||||
qCDebug(LOG_ESM) << "Configuration file" << settings.fileName();
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Value"), m_bar);
|
||||
@ -471,12 +468,13 @@ void GraphicalItem::writeConfiguration() const
|
||||
|
||||
void GraphicalItem::changeColor()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
QColor color = stringToColor((static_cast<QPushButton *>(sender()))->text());
|
||||
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
|
||||
QColorDialog::ShowAlphaChannel);
|
||||
if (!newColor.isValid()) return;
|
||||
qCInfo(LOG_LIB) << "Selected color" << newColor;
|
||||
|
||||
QStringList colorText;
|
||||
colorText.append(QString("%1").arg(newColor.red()));
|
||||
@ -490,8 +488,8 @@ void GraphicalItem::changeColor()
|
||||
|
||||
QColor GraphicalItem::stringToColor(const QString _color) const
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_ESM) << "Color" << _color;
|
||||
qCDebug(LOG_LIB);
|
||||
qCDebug(LOG_LIB) << "Color" << _color;
|
||||
|
||||
QColor qcolor;
|
||||
QStringList listColor = _color.split(QChar(','));
|
||||
@ -508,7 +506,7 @@ QColor GraphicalItem::stringToColor(const QString _color) const
|
||||
|
||||
void GraphicalItem::translate()
|
||||
{
|
||||
qCDebug(LOG_ESM);
|
||||
qCDebug(LOG_LIB);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
|
@ -50,10 +50,9 @@ public:
|
||||
};
|
||||
|
||||
explicit GraphicalItem(QWidget *parent = nullptr, const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList(),
|
||||
const bool debugCmd = false);
|
||||
~GraphicalItem();
|
||||
GraphicalItem *copy(const QString fileName, const int number);
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~GraphicalItem();
|
||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||
QString image(const float value) const;
|
||||
// get methods
|
||||
QString bar() const;
|
||||
|
Reference in New Issue
Block a user