some fixes inside extensions

* do not use private variables if there are special methods
* change macro call from `aw_*` to `aw_macro_*`
* add forgotten configuration reading/writting for list formatter
This commit is contained in:
Evgenii Alekseev 2016-07-06 14:23:01 +03:00
parent baf5085506
commit 085eec7a3d
13 changed files with 213 additions and 174 deletions

View File

@ -230,8 +230,8 @@ QString AWPatternFunctions::insertMacros(QString code)
QString name = macro.args.takeFirst(); QString name = macro.args.takeFirst();
// find macro usage // find macro usage
QList<AWPatternFunctions::AWFunction> macroUsage QList<AWPatternFunctions::AWFunction> macroUsage
= AWPatternFunctions::findFunctionCalls(QString("aw_%1").arg(name), = AWPatternFunctions::findFunctionCalls(
code); QString("aw_macro_%1").arg(name), code);
for (auto function : macroUsage) { for (auto function : macroUsage) {
if (function.args.count() != macro.args.count()) { if (function.args.count() != macro.args.count()) {
qCWarning(LOG_AW) << "Invalid args count found for call" qCWarning(LOG_AW) << "Invalid args count found for call"

View File

@ -60,11 +60,11 @@ void AbstractExtItem::bumpApi(const int _newVer)
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
{ {
_other->setActive(m_active); _other->setActive(isActive());
_other->setApiVersion(m_apiVersion); _other->setApiVersion(apiVersion());
_other->setComment(m_comment); _other->setComment(comment());
_other->setInterval(m_interval); _other->setInterval(interval());
_other->setName(m_name); _other->setName(name());
} }
@ -129,7 +129,7 @@ QString AbstractExtItem::tag(const QString _type) const
{ {
qCDebug(LOG_LIB) << "Tag type" << _type; qCDebug(LOG_LIB) << "Tag type" << _type;
return QString("%1%2").arg(_type).arg(m_number); return QString("%1%2").arg(_type).arg(number());
} }
@ -182,7 +182,8 @@ void AbstractExtItem::setNumber(int _number)
if (generateNumber) { if (generateNumber) {
_number = []() { _number = []() {
qCWarning(LOG_LIB) << "Number is empty, generate new one"; qCWarning(LOG_LIB) << "Number is empty, generate new one";
qsrand(QTime::currentTime().msec()); // we suppose that currentTIme().msec() is always valid time
qsrand(static_cast<uint>(QTime::currentTime().msec()));
int n = qrand() % 1000; int n = qrand() % 1000;
qCInfo(LOG_LIB) << "Generated number is" << n; qCInfo(LOG_LIB) << "Generated number is" << n;
return n; return n;
@ -200,15 +201,15 @@ void AbstractExtItem::readConfiguration()
QSettings settings(m_fileName, QSettings::IniFormat); QSettings settings(m_fileName, QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setName(settings.value(QString("Name"), m_name).toString()); setName(settings.value(QString("Name"), name()).toString());
setComment(settings.value(QString("Comment"), m_comment).toString()); setComment(settings.value(QString("Comment"), comment()).toString());
setApiVersion( setApiVersion(
settings.value(QString("X-AW-ApiVersion"), m_apiVersion).toInt()); settings.value(QString("X-AW-ApiVersion"), apiVersion()).toInt());
setActive( setActive(
settings.value(QString("X-AW-Active"), QVariant(m_active)).toString() settings.value(QString("X-AW-Active"), QVariant(isActive())).toString()
== QString("true")); == QString("true"));
setInterval(settings.value(QString("X-AW-Interval"), m_interval).toInt()); setInterval(settings.value(QString("X-AW-Interval"), interval()).toInt());
setNumber(settings.value(QString("X-AW-Number"), m_number).toInt()); setNumber(settings.value(QString("X-AW-Number"), number()).toInt());
settings.endGroup(); settings.endGroup();
} }
@ -229,12 +230,12 @@ void AbstractExtItem::writeConfiguration() const
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Encoding"), QString("UTF-8")); settings.setValue(QString("Encoding"), QString("UTF-8"));
settings.setValue(QString("Name"), m_name); settings.setValue(QString("Name"), name());
settings.setValue(QString("Comment"), m_comment); settings.setValue(QString("Comment"), comment());
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion); settings.setValue(QString("X-AW-ApiVersion"), apiVersion());
settings.setValue(QString("X-AW-Active"), QVariant(m_active).toString()); settings.setValue(QString("X-AW-Active"), QVariant(isActive()).toString());
settings.setValue(QString("X-AW-Interval"), m_interval); settings.setValue(QString("X-AW-Interval"), interval());
settings.setValue(QString("X-AW-Number"), m_number); settings.setValue(QString("X-AW-Number"), number());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();

View File

@ -40,7 +40,7 @@ void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const
{ {
AbstractExtItem::copyDefaults(_other); AbstractExtItem::copyDefaults(_other);
static_cast<AWAbstractFormatter *>(_other)->setType(m_type); static_cast<AWAbstractFormatter *>(_other)->setType(type());
} }

View File

@ -94,7 +94,7 @@ void AWDateTimeFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setFormat(settings.value(QString("X-AW-Format"), m_format).toString()); setFormat(settings.value(QString("X-AW-Format"), format()).toString());
settings.endGroup(); settings.endGroup();
bumpApi(AWEFAPI); bumpApi(AWEFAPI);
@ -108,7 +108,7 @@ int AWDateTimeFormatter::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("DateTime")); ui->label_typeValue->setText(QString("DateTime"));
ui->lineEdit_format->setText(m_format); ui->lineEdit_format->setText(format());
int ret = exec(); int ret = exec();
if (ret != 1) if (ret != 1)
@ -131,7 +131,7 @@ void AWDateTimeFormatter::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Format"), m_format); settings.setValue(QString("X-AW-Format"), format());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();

View File

@ -52,8 +52,8 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
{ {
qCDebug(LOG_LIB) << "Convert value" << _value; qCDebug(LOG_LIB) << "Convert value" << _value;
return QString("%1").arg(_value.toDouble() * m_multiplier + m_summand, return QString("%1").arg(_value.toDouble() * multiplier() + summand(),
m_count, m_format, m_precision, m_fillChar); count(), format(), precision(), fillChar());
} }
@ -174,18 +174,18 @@ void AWFloatFormatter::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Width"), m_count).toInt()); setCount(settings.value(QString("X-AW-Width"), count()).toInt());
setFillChar( setFillChar(
settings.value(QString("X-AW-FillChar"), m_fillChar).toString().at(0)); settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
setFormat(settings.value(QString("X-AW-Format"), QString(m_format)) setFormat(settings.value(QString("X-AW-Format"), QString(format()))
.toString() .toString()
.at(0) .at(0)
.toLatin1()); .toLatin1());
setMultiplier( setMultiplier(
settings.value(QString("X-AW-Multiplier"), m_multiplier).toDouble()); settings.value(QString("X-AW-Multiplier"), multiplier()).toDouble());
setPrecision( setPrecision(
settings.value(QString("X-AW-Precision"), m_precision).toInt()); settings.value(QString("X-AW-Precision"), precision()).toInt());
setSummand(settings.value(QString("X-AW-Summand"), m_summand).toDouble()); setSummand(settings.value(QString("X-AW-Summand"), summand()).toDouble());
settings.endGroup(); settings.endGroup();
bumpApi(AWEFAPI); bumpApi(AWEFAPI);
@ -200,12 +200,12 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("Float")); ui->label_typeValue->setText(QString("Float"));
ui->comboBox_format->setCurrentIndex( ui->comboBox_format->setCurrentIndex(
ui->comboBox_format->findText(QString(m_format))); ui->comboBox_format->findText(QString(format())));
ui->spinBox_precision->setValue(m_precision); ui->spinBox_precision->setValue(precision());
ui->spinBox_width->setValue(m_count); ui->spinBox_width->setValue(count());
ui->lineEdit_fill->setText(QString(m_fillChar)); ui->lineEdit_fill->setText(QString(fillChar()));
ui->doubleSpinBox_multiplier->setValue(m_multiplier); ui->doubleSpinBox_multiplier->setValue(multiplier());
ui->doubleSpinBox_summand->setValue(m_summand); ui->doubleSpinBox_summand->setValue(summand());
int ret = exec(); int ret = exec();
if (ret != 1) if (ret != 1)
@ -233,12 +233,12 @@ void AWFloatFormatter::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Width"), m_count); settings.setValue(QString("X-AW-Width"), count());
settings.setValue(QString("X-AW-FillChar"), m_fillChar); settings.setValue(QString("X-AW-FillChar"), fillChar());
settings.setValue(QString("X-AW-Format"), m_format); settings.setValue(QString("X-AW-Format"), format());
settings.setValue(QString("X-AW-Multiplier"), m_multiplier); settings.setValue(QString("X-AW-Multiplier"), multiplier());
settings.setValue(QString("X-AW-Precision"), m_precision); settings.setValue(QString("X-AW-Precision"), precision());
settings.setValue(QString("X-AW-Summand"), m_summand); settings.setValue(QString("X-AW-Summand"), summand());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();

View File

@ -21,6 +21,8 @@
#include <KI18n/KLocalizedString> #include <KI18n/KLocalizedString>
#include <QSettings>
#include "awdebug.h" #include "awdebug.h"
@ -117,6 +119,23 @@ void AWListFormatter::setSorted(const bool _sorted)
} }
void AWListFormatter::readConfiguration()
{
AWAbstractFormatter::readConfiguration();
QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry"));
setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
setSeparator(
settings.value(QString("X-AW-Separator"), separator()).toString());
setSorted(settings.value(QString("X-AW-Sort"), isSorted()).toBool());
settings.endGroup();
bumpApi(AWEFAPI);
}
int AWListFormatter::showConfiguration(const QVariant args) int AWListFormatter::showConfiguration(const QVariant args)
{ {
Q_UNUSED(args) Q_UNUSED(args)
@ -144,6 +163,23 @@ int AWListFormatter::showConfiguration(const QVariant args)
} }
void AWListFormatter::writeConfiguration() const
{
AWAbstractFormatter::writeConfiguration();
QSettings settings(writtableConfig(), QSettings::IniFormat);
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Filter"), filter());
settings.setValue(QString("X-AW-Separator"), separator());
settings.setValue(QString("X-AW-Sort"), isSorted());
settings.endGroup();
settings.sync();
}
void AWListFormatter::translate() void AWListFormatter::translate()
{ {
ui->label_name->setText(i18n("Name")); ui->label_name->setText(i18n("Name"));

View File

@ -48,7 +48,9 @@ public:
void setSorted(const bool _sorted); void setSorted(const bool _sorted);
public slots: public slots:
void readConfiguration();
int showConfiguration(const QVariant args = QVariant()); int showConfiguration(const QVariant args = QVariant());
void writeConfiguration() const;
private: private:
Ui::AWListFormatter *ui = nullptr; Ui::AWListFormatter *ui = nullptr;

View File

@ -146,10 +146,10 @@ void AWScriptFormatter::readConfiguration()
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setAppendCode( setAppendCode(
settings.value(QString("X-AW-AppendCode"), m_appendCode).toBool()); settings.value(QString("X-AW-AppendCode"), appendCode()).toBool());
setCode(settings.value(QString("X-AW-Code"), m_code).toString()); setCode(settings.value(QString("X-AW-Code"), code()).toString());
setHasReturn( setHasReturn(
settings.value(QString("X-AW-HasReturn"), m_hasReturn).toBool()); settings.value(QString("X-AW-HasReturn"), hasReturn()).toBool());
settings.endGroup(); settings.endGroup();
bumpApi(AWEFAPI); bumpApi(AWEFAPI);
@ -163,11 +163,11 @@ int AWScriptFormatter::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_typeValue->setText(QString("Script")); ui->label_typeValue->setText(QString("Script"));
ui->checkBox_appendCode->setCheckState(m_appendCode ? Qt::Checked ui->checkBox_appendCode->setCheckState(appendCode() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->checkBox_hasReturn->setCheckState(m_hasReturn ? Qt::Checked ui->checkBox_hasReturn->setCheckState(hasReturn() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->textEdit_code->setPlainText(m_code); ui->textEdit_code->setPlainText(code());
int ret = exec(); int ret = exec();
if (ret != 1) if (ret != 1)
@ -193,9 +193,9 @@ void AWScriptFormatter::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-AppendCode"), m_appendCode); settings.setValue(QString("X-AW-AppendCode"), appendCode());
settings.setValue(QString("X-AW-Code"), m_code); settings.setValue(QString("X-AW-Code"), code());
settings.setValue(QString("X-AW-HasReturn"), m_hasReturn); settings.setValue(QString("X-AW-HasReturn"), hasReturn());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();
@ -205,13 +205,13 @@ void AWScriptFormatter::writeConfiguration() const
void AWScriptFormatter::initProgram() void AWScriptFormatter::initProgram()
{ {
// init JS code // init JS code
if (m_appendCode) if (appendCode())
m_program m_program
= QString("(function(value) { %1%2 })") = QString("(function(value) { %1%2 })")
.arg(m_code) .arg(code())
.arg(m_hasReturn ? QString("") : QString("; return output;")); .arg(hasReturn() ? QString("") : QString("; return output;"));
else else
m_program = m_code; m_program = code();
qCInfo(LOG_LIB) << "Create JS engine with code" << m_program; qCInfo(LOG_LIB) << "Create JS engine with code" << m_program;
} }

View File

@ -96,7 +96,7 @@ QString ExtQuotes::ticker() const
QString ExtQuotes::uniq() const QString ExtQuotes::uniq() const
{ {
return m_ticker; return ticker();
} }
@ -116,7 +116,7 @@ void ExtQuotes::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setTicker(settings.value(QString("X-AW-Ticker"), m_ticker).toString()); setTicker(settings.value(QString("X-AW-Ticker"), ticker()).toString());
settings.endGroup(); settings.endGroup();
// update for current API // update for current API
@ -159,7 +159,7 @@ int ExtQuotes::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number())); ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_ticker->setText(m_ticker); ui->lineEdit_ticker->setText(ticker());
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->spinBox_interval->setValue(interval()); ui->spinBox_interval->setValue(interval());
@ -188,7 +188,7 @@ void ExtQuotes::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Ticker"), m_ticker); settings.setValue(QString("X-AW-Ticker"), ticker());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();
@ -260,7 +260,7 @@ void ExtQuotes::initUrl()
params.addQueryItem(QString("env"), params.addQueryItem(QString("env"),
QString("store://datatables.org/alltableswithkeys")); QString("store://datatables.org/alltableswithkeys"));
params.addQueryItem(QString("q"), params.addQueryItem(QString("q"),
QString(YAHOO_QUOTES_QUERY).arg(m_ticker)); QString(YAHOO_QUOTES_QUERY).arg(ticker()));
m_url.setQuery(params); m_url.setQuery(params);
} }

View File

@ -104,14 +104,14 @@ ExtScript::Redirect ExtScript::redirect() const
QString ExtScript::uniq() const QString ExtScript::uniq() const
{ {
return m_executable; return executable();
} }
QString ExtScript::strRedirect() const QString ExtScript::strRedirect() const
{ {
QString value; QString value;
switch (m_redirect) { switch (redirect()) {
case Redirect::stdout2stderr: case Redirect::stdout2stderr:
value = QString("stdout2stderr"); value = QString("stdout2stderr");
break; break;
@ -182,7 +182,7 @@ QString ExtScript::applyFilters(QString _value) const
{ {
qCDebug(LOG_LIB) << "Value" << _value; qCDebug(LOG_LIB) << "Value" << _value;
for (auto filt : m_filters) { for (auto filt : filters()) {
qCInfo(LOG_LIB) << "Found filter" << filt; qCInfo(LOG_LIB) << "Found filter" << filt;
QVariantMap filter = jsonFilters[filt].toMap(); QVariantMap filter = jsonFilters[filt].toMap();
if (filter.isEmpty()) { if (filter.isEmpty()) {
@ -203,7 +203,7 @@ void ExtScript::updateFilter(const QString _filter, const bool _add)
qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter; qCDebug(LOG_LIB) << "Should be added filters" << _add << "from" << _filter;
if (_add) { if (_add) {
if (m_filters.contains(_filter)) if (filters().contains(_filter))
return; return;
m_filters.append(_filter); m_filters.append(_filter);
} else { } else {
@ -219,12 +219,12 @@ void ExtScript::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), m_executable).toString()); setExecutable(settings.value(QString("Exec"), executable()).toString());
setPrefix(settings.value(QString("X-AW-Prefix"), m_prefix).toString()); setPrefix(settings.value(QString("X-AW-Prefix"), prefix()).toString());
setStrRedirect( setStrRedirect(
settings.value(QString("X-AW-Redirect"), strRedirect()).toString()); settings.value(QString("X-AW-Redirect"), strRedirect()).toString());
// api == 3 // api == 3
setFilters(settings.value(QString("X-AW-Filters"), m_filters) setFilters(settings.value(QString("X-AW-Filters"), filters())
.toString() .toString()
.split(QChar(','), QString::SkipEmptyParts)); .split(QChar(','), QString::SkipEmptyParts));
settings.endGroup(); settings.endGroup();
@ -270,9 +270,9 @@ QVariantHash ExtScript::run()
if ((times == 1) && (process->state() == QProcess::NotRunning)) { if ((times == 1) && (process->state() == QProcess::NotRunning)) {
QStringList cmdList; QStringList cmdList;
if (!m_prefix.isEmpty()) if (!prefix().isEmpty())
cmdList.append(m_prefix); cmdList.append(prefix());
cmdList.append(m_executable); cmdList.append(executable());
qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' ')); qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(QChar(' '));
process->start(cmdList.join(QChar(' '))); process->start(cmdList.join(QChar(' ')));
} }
@ -293,19 +293,19 @@ int ExtScript::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number())); ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_command->setText(m_executable); ui->lineEdit_command->setText(executable());
ui->lineEdit_prefix->setText(m_prefix); ui->lineEdit_prefix->setText(prefix());
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->comboBox_redirect->setCurrentIndex(static_cast<int>(m_redirect)); ui->comboBox_redirect->setCurrentIndex(static_cast<int>(redirect()));
ui->spinBox_interval->setValue(interval()); ui->spinBox_interval->setValue(interval());
// filters // filters
ui->checkBox_colorFilter->setCheckState( ui->checkBox_colorFilter->setCheckState(
m_filters.contains(QString("color")) ? Qt::Checked : Qt::Unchecked); filters().contains(QString("color")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_linesFilter->setCheckState( ui->checkBox_linesFilter->setCheckState(
m_filters.contains(QString("newline")) ? Qt::Checked : Qt::Unchecked); filters().contains(QString("newline")) ? Qt::Checked : Qt::Unchecked);
ui->checkBox_spaceFilter->setCheckState( ui->checkBox_spaceFilter->setCheckState(
m_filters.contains(QString("space")) ? Qt::Checked : Qt::Unchecked); filters().contains(QString("space")) ? Qt::Checked : Qt::Unchecked);
int ret = exec(); int ret = exec();
if (ret != 1) if (ret != 1)
@ -340,10 +340,10 @@ void ExtScript::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), m_executable); settings.setValue(QString("Exec"), executable());
settings.setValue(QString("X-AW-Prefix"), m_prefix); settings.setValue(QString("X-AW-Prefix"), prefix());
settings.setValue(QString("X-AW-Redirect"), strRedirect()); settings.setValue(QString("X-AW-Redirect"), strRedirect());
settings.setValue(QString("X-AW-Filters"), m_filters.join(QChar(','))); settings.setValue(QString("X-AW-Filters"), filters().join(QChar(',')));
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();
@ -363,7 +363,7 @@ void ExtScript::updateValue()
qCInfo(LOG_LIB) << "Output" << qoutput; qCInfo(LOG_LIB) << "Output" << qoutput;
QString strValue; QString strValue;
switch (m_redirect) { switch (redirect()) {
case Redirect::stdout2stderr: case Redirect::stdout2stderr:
break; break;
case Redirect::stderr2stdout: case Redirect::stderr2stdout:

View File

@ -93,7 +93,7 @@ int ExtUpgrade::null() const
QString ExtUpgrade::uniq() const QString ExtUpgrade::uniq() const
{ {
return m_executable; return executable();
} }
@ -130,10 +130,10 @@ void ExtUpgrade::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setExecutable(settings.value(QString("Exec"), m_executable).toString()); setExecutable(settings.value(QString("Exec"), executable()).toString());
setNull(settings.value(QString("X-AW-Null"), m_null).toInt()); setNull(settings.value(QString("X-AW-Null"), null()).toInt());
// api == 3 // api == 3
setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString()); setFilter(settings.value(QString("X-AW-Filter"), filter()).toString());
settings.endGroup(); settings.endGroup();
bumpApi(AWEUAPI); bumpApi(AWEUAPI);
@ -146,7 +146,7 @@ QVariantHash ExtUpgrade::run()
return value; return value;
if ((times == 1) && (process->state() == QProcess::NotRunning)) { if ((times == 1) && (process->state() == QProcess::NotRunning)) {
QString cmd = QString("sh -c \"%1\"").arg(m_executable); QString cmd = QString("sh -c \"%1\"").arg(executable());
qCInfo(LOG_LIB) << "Run cmd" << cmd; qCInfo(LOG_LIB) << "Run cmd" << cmd;
process->start(cmd); process->start(cmd);
} }
@ -167,11 +167,11 @@ int ExtUpgrade::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number())); ui->label_numberValue->setText(QString("%1").arg(number()));
ui->lineEdit_command->setText(m_executable); ui->lineEdit_command->setText(executable());
ui->lineEdit_filter->setText(m_filter); ui->lineEdit_filter->setText(filter());
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->spinBox_null->setValue(m_null); ui->spinBox_null->setValue(null());
ui->spinBox_interval->setValue(interval()); ui->spinBox_interval->setValue(interval());
int ret = exec(); int ret = exec();
@ -200,9 +200,9 @@ void ExtUpgrade::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("Exec"), m_executable); settings.setValue(QString("Exec"), executable());
settings.setValue(QString("X-AW-Filter"), m_filter); settings.setValue(QString("X-AW-Filter"), filter());
settings.setValue(QString("X-AW-Null"), m_null); settings.setValue(QString("X-AW-Null"), null());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();
@ -218,11 +218,11 @@ void ExtUpgrade::updateValue()
->toUnicode(process->readAllStandardOutput()) ->toUnicode(process->readAllStandardOutput())
.trimmed(); .trimmed();
value[tag(QString("pkgcount"))] = [this](QString output) { value[tag(QString("pkgcount"))] = [this](QString output) {
return m_filter.isEmpty() return filter().isEmpty()
? output.split(QChar('\n'), QString::SkipEmptyParts).count() ? output.split(QChar('\n'), QString::SkipEmptyParts).count()
- m_null - null()
: output.split(QChar('\n'), QString::SkipEmptyParts) : output.split(QChar('\n'), QString::SkipEmptyParts)
.filter(QRegExp(m_filter)) .filter(QRegExp(filter()))
.count(); .count();
}(qoutput); }(qoutput);

View File

@ -150,7 +150,7 @@ int ExtWeather::ts() const
QString ExtWeather::uniq() const QString ExtWeather::uniq() const
{ {
return QString("%1 (%2) at %3").arg(m_city).arg(m_country).arg(m_ts); return QString("%1 (%2) at %3").arg(city()).arg(country()).arg(ts());
} }
@ -216,11 +216,11 @@ void ExtWeather::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setCity(settings.value(QString("X-AW-City"), m_city).toString()); setCity(settings.value(QString("X-AW-City"), city()).toString());
setCountry(settings.value(QString("X-AW-Country"), m_country).toString()); setCountry(settings.value(QString("X-AW-Country"), country()).toString());
setTs(settings.value(QString("X-AW-TS"), m_ts).toInt()); setTs(settings.value(QString("X-AW-TS"), ts()).toInt());
// api == 2 // api == 2
setImage(settings.value(QString("X-AW-Image"), QVariant(m_image)).toString() setImage(settings.value(QString("X-AW-Image"), QVariant(image())).toString()
== QString("true")); == QString("true"));
// api == 3 // api == 3
setStrProvider( setStrProvider(
@ -286,11 +286,11 @@ int ExtWeather::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number())); ui->label_numberValue->setText(QString("%1").arg(number()));
ui->comboBox_provider->setCurrentIndex(static_cast<int>(m_provider)); ui->comboBox_provider->setCurrentIndex(static_cast<int>(provider()));
ui->lineEdit_city->setText(m_city); ui->lineEdit_city->setText(city());
ui->lineEdit_country->setText(m_country); ui->lineEdit_country->setText(country());
ui->spinBox_timestamp->setValue(m_ts); ui->spinBox_timestamp->setValue(ts());
ui->checkBox_image->setCheckState(m_image ? Qt::Checked : Qt::Unchecked); ui->checkBox_image->setCheckState(image() ? Qt::Checked : Qt::Unchecked);
ui->checkBox_active->setCheckState(isActive() ? Qt::Checked ui->checkBox_active->setCheckState(isActive() ? Qt::Checked
: Qt::Unchecked); : Qt::Unchecked);
ui->spinBox_interval->setValue(interval()); ui->spinBox_interval->setValue(interval());
@ -323,11 +323,11 @@ void ExtWeather::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-City"), m_city); settings.setValue(QString("X-AW-City"), city());
settings.setValue(QString("X-AW-Country"), m_country); settings.setValue(QString("X-AW-Country"), country());
settings.setValue(QString("X-AW-Image"), m_image); settings.setValue(QString("X-AW-Image"), image());
settings.setValue(QString("X-AW-Provider"), strProvider()); settings.setValue(QString("X-AW-Provider"), strProvider());
settings.setValue(QString("X-AW-TS"), m_ts); settings.setValue(QString("X-AW-TS"), ts());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();
@ -373,7 +373,7 @@ void ExtWeather::initProvider()
break; break;
} }
return m_providerObject->initUrl(m_city, m_country, m_ts); return m_providerObject->initUrl(city(), country(), ts());
} }

View File

@ -71,18 +71,18 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
GraphicalItem *item GraphicalItem *item
= new GraphicalItem(static_cast<QWidget *>(parent()), _fileName); = new GraphicalItem(static_cast<QWidget *>(parent()), _fileName);
copyDefaults(item); copyDefaults(item);
item->setActiveColor(m_activeColor); item->setActiveColor(activeColor());
item->setBar(m_bar); item->setBar(bar());
item->setCount(m_count); item->setCount(count());
item->setCustom(m_custom); item->setCustom(isCustom());
item->setDirection(m_direction); item->setDirection(direction());
item->setItemHeight(m_height); item->setItemHeight(itemHeight());
item->setInactiveColor(m_inactiveColor); item->setInactiveColor(inactiveColor());
item->setMaxValue(m_maxValue); item->setMaxValue(maxValue());
item->setMinValue(m_minValue); item->setMinValue(minValue());
item->setNumber(_number); item->setNumber(_number);
item->setType(m_type); item->setType(type());
item->setItemWidth(m_width); item->setItemWidth(itemWidth());
return item; return item;
} }
@ -95,34 +95,34 @@ QString GraphicalItem::image(const QVariant &value)
m_scene->clear(); m_scene->clear();
int scale[2] = {1, 1}; int scale[2] = {1, 1};
float converted float converted
= m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue); = m_helper->getPercents(value.toFloat(), minValue(), maxValue());
// paint // paint
switch (m_type) { switch (m_type) {
case Type::Vertical: case Type::Vertical:
m_helper->paintVertical(converted); m_helper->paintVertical(converted);
// scale // scale
scale[1] = -2 * static_cast<int>(m_direction) + 1; scale[1] = -2 * static_cast<int>(direction()) + 1;
break; break;
case Type::Circle: case Type::Circle:
m_helper->paintCircle(converted); m_helper->paintCircle(converted);
// scale // scale
scale[0] = -2 * static_cast<int>(m_direction) + 1; scale[0] = -2 * static_cast<int>(direction()) + 1;
break; break;
case Type::Graph: case Type::Graph:
m_helper->paintGraph(converted); m_helper->paintGraph(converted);
scale[0] = -2 * static_cast<int>(m_direction) + 1; scale[0] = -2 * static_cast<int>(direction()) + 1;
scale[1] = -1; scale[1] = -1;
break; break;
case Type::Bars: case Type::Bars:
m_helper->paintBars(converted); m_helper->paintBars(converted);
scale[0] = -2 * static_cast<int>(m_direction) + 1; scale[0] = -2 * static_cast<int>(direction()) + 1;
scale[1] = -1; scale[1] = -1;
break; break;
case Type::Horizontal: case Type::Horizontal:
m_helper->paintHorizontal(converted); m_helper->paintHorizontal(converted);
// scale // scale
scale[0] = -2 * static_cast<int>(m_direction) + 1; scale[0] = -2 * static_cast<int>(direction()) + 1;
break; break;
} }
@ -159,8 +159,8 @@ void GraphicalItem::initScene()
// init helper // init helper
m_helper = new GraphicalItemHelper(this, m_scene); m_helper = new GraphicalItemHelper(this, m_scene);
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height, m_helper->setParameters(activeColor(), inactiveColor(), itemWidth(),
m_count); itemHeight(), count());
} }
@ -227,7 +227,7 @@ GraphicalItem::Type GraphicalItem::type() const
QString GraphicalItem::strType() const QString GraphicalItem::strType() const
{ {
QString value; QString value;
switch (m_type) { switch (type()) {
case Type::Vertical: case Type::Vertical:
value = QString("Vertical"); value = QString("Vertical");
break; break;
@ -258,7 +258,7 @@ GraphicalItem::Direction GraphicalItem::direction() const
QString GraphicalItem::strDirection() const QString GraphicalItem::strDirection() const
{ {
QString value; QString value;
switch (m_direction) { switch (direction()) {
case Direction::RightToLeft: case Direction::RightToLeft:
value = QString("RightToLeft"); value = QString("RightToLeft");
break; break;
@ -279,7 +279,7 @@ QStringList GraphicalItem::usedKeys() const
QString GraphicalItem::uniq() const QString GraphicalItem::uniq() const
{ {
return m_bar; return bar();
} }
@ -411,11 +411,11 @@ void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
// remove dubs // remove dubs
// HACK converting to set may break order // HACK converting to set may break order
m_usedKeys.clear(); usedKeys().clear();
for (auto key : _usedKeys) { for (auto key : _usedKeys) {
if (m_usedKeys.contains(key)) if (usedKeys().contains(key))
continue; continue;
m_usedKeys.append(key); usedKeys().append(key);
} }
} }
@ -427,31 +427,31 @@ void GraphicalItem::readConfiguration()
QSettings settings(fileName(), QSettings::IniFormat); QSettings settings(fileName(), QSettings::IniFormat);
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
setCount(settings.value(QString("X-AW-Count"), m_count).toInt()); setCount(settings.value(QString("X-AW-Count"), count()).toInt());
setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool()); setCustom(settings.value(QString("X-AW-Custom"), isCustom()).toBool());
setBar(settings.value(QString("X-AW-Value"), m_bar).toString()); setBar(settings.value(QString("X-AW-Value"), bar()).toString());
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat()); setMaxValue(settings.value(QString("X-AW-Max"), maxValue()).toFloat());
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat()); setMinValue(settings.value(QString("X-AW-Min"), minValue()).toFloat());
setActiveColor( setActiveColor(
settings.value(QString("X-AW-ActiveColor"), m_activeColor).toString()); settings.value(QString("X-AW-ActiveColor"), activeColor()).toString());
setInactiveColor( setInactiveColor(
settings.value(QString("X-AW-InactiveColor"), m_inactiveColor) settings.value(QString("X-AW-InactiveColor"), inactiveColor())
.toString()); .toString());
setStrType(settings.value(QString("X-AW-Type"), strType()).toString()); setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
setStrDirection( setStrDirection(
settings.value(QString("X-AW-Direction"), strDirection()).toString()); settings.value(QString("X-AW-Direction"), strDirection()).toString());
setItemHeight(settings.value(QString("X-AW-Height"), m_height).toInt()); setItemHeight(settings.value(QString("X-AW-Height"), itemHeight()).toInt());
setItemWidth(settings.value(QString("X-AW-Width"), m_width).toInt()); setItemWidth(settings.value(QString("X-AW-Width"), itemWidth()).toInt());
// api == 5 // api == 5
if (apiVersion() < 5) { if (apiVersion() < 5) {
QString prefix; QString prefix;
prefix = m_activeColor.startsWith(QString("/")) ? QString("file://%1") prefix = activeColor().startsWith(QString("/")) ? QString("file://%1")
: QString("color://%1"); : QString("color://%1");
m_activeColor = prefix.arg(m_activeColor); m_activeColor = prefix.arg(activeColor());
prefix = m_inactiveColor.startsWith(QString("/")) prefix = inactiveColor().startsWith(QString("/"))
? QString("file://%1") ? QString("file://%1")
: QString("color://%1"); : QString("color://%1");
m_inactiveColor = prefix.arg(m_inactiveColor); m_inactiveColor = prefix.arg(inactiveColor());
} }
settings.endGroup(); settings.endGroup();
@ -468,31 +468,31 @@ int GraphicalItem::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name()); ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment()); ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number())); ui->label_numberValue->setText(QString("%1").arg(number()));
ui->checkBox_custom->setChecked(m_custom); ui->checkBox_custom->setChecked(isCustom());
ui->comboBox_value->addItems(tags); ui->comboBox_value->addItems(tags);
if (m_custom) { if (isCustom()) {
ui->lineEdit_customValue->setText(m_bar); ui->lineEdit_customValue->setText(bar());
} else { } else {
ui->comboBox_value->addItem(m_bar); ui->comboBox_value->addItem(bar());
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1); ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
} }
ui->doubleSpinBox_max->setValue(m_maxValue); ui->doubleSpinBox_max->setValue(maxValue());
ui->doubleSpinBox_min->setValue(m_minValue); ui->doubleSpinBox_min->setValue(minValue());
ui->spinBox_count->setValue(m_count); ui->spinBox_count->setValue(count());
if (m_helper->isColor(m_activeColor)) if (m_helper->isColor(activeColor()))
ui->comboBox_activeImageType->setCurrentIndex(0); ui->comboBox_activeImageType->setCurrentIndex(0);
else else
ui->comboBox_activeImageType->setCurrentIndex(1); ui->comboBox_activeImageType->setCurrentIndex(1);
ui->lineEdit_activeColor->setText(m_activeColor); ui->lineEdit_activeColor->setText(activeColor());
if (m_helper->isColor(m_inactiveColor)) if (m_helper->isColor(inactiveColor()))
ui->comboBox_inactiveImageType->setCurrentIndex(0); ui->comboBox_inactiveImageType->setCurrentIndex(0);
else else
ui->comboBox_inactiveImageType->setCurrentIndex(1); ui->comboBox_inactiveImageType->setCurrentIndex(1);
ui->lineEdit_inactiveColor->setText(m_inactiveColor); ui->lineEdit_inactiveColor->setText(inactiveColor());
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type)); ui->comboBox_type->setCurrentIndex(static_cast<int>(type()));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction)); ui->comboBox_direction->setCurrentIndex(static_cast<int>(direction()));
ui->spinBox_height->setValue(m_height); ui->spinBox_height->setValue(itemHeight());
ui->spinBox_width->setValue(m_width); ui->spinBox_width->setValue(itemWidth());
// update UI // update UI
emit(ui->comboBox_type->currentIndexChanged( emit(ui->comboBox_type->currentIndexChanged(
@ -532,17 +532,17 @@ void GraphicalItem::writeConfiguration() const
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName(); qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry")); settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-Value"), m_bar); settings.setValue(QString("X-AW-Value"), bar());
settings.setValue(QString("X-AW-Count"), m_count); settings.setValue(QString("X-AW-Count"), count());
settings.setValue(QString("X-AW-Custom"), m_custom); settings.setValue(QString("X-AW-Custom"), isCustom());
settings.setValue(QString("X-AW-Max"), m_maxValue); settings.setValue(QString("X-AW-Max"), maxValue());
settings.setValue(QString("X-AW-Min"), m_minValue); settings.setValue(QString("X-AW-Min"), minValue());
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor); settings.setValue(QString("X-AW-ActiveColor"), activeColor());
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor); settings.setValue(QString("X-AW-InactiveColor"), inactiveColor());
settings.setValue(QString("X-AW-Type"), strType()); settings.setValue(QString("X-AW-Type"), strType());
settings.setValue(QString("X-AW-Direction"), strDirection()); settings.setValue(QString("X-AW-Direction"), strDirection());
settings.setValue(QString("X-AW-Height"), m_height); settings.setValue(QString("X-AW-Height"), itemHeight());
settings.setValue(QString("X-AW-Width"), m_width); settings.setValue(QString("X-AW-Width"), itemWidth());
settings.endGroup(); settings.endGroup();
settings.sync(); settings.sync();