Skip to content

Commit

Permalink
refactor: refresh aw plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arcan1s committed Apr 16, 2024
1 parent 54acc5f commit 397b523
Show file tree
Hide file tree
Showing 41 changed files with 252 additions and 306 deletions.
8 changes: 4 additions & 4 deletions sources/awdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ QString AWDebug::getAboutText(const QString &_type)
translator = QString("<li>%1</li>").arg(translator);
text = i18n("Translators:") + "<ul>" + translatorList.join("") + "</ul>";
} else if (_type == "3rdparty") {
QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(';', Qt::SkipEmptyParts);
for (int i = 0; i < trdPartyList.count(); i++)
auto trdPartyList = QString(TRDPARTY_LICENSE).split(';', Qt::SkipEmptyParts);
for (auto i = 0; i < trdPartyList.count(); ++i)
trdPartyList[i] = QString("<li><a href=\"%3\">%1</a> (%2 license)</li>")
.arg(trdPartyList.at(i).split(',')[0], trdPartyList.at(i).split(',')[1],
trdPartyList.at(i).split(',')[2]);
text = i18n("This software uses:") + "<ul>" + trdPartyList.join("") + "</ul>";
} else if (_type == "thanks") {
QStringList thanks = QString(SPECIAL_THANKS).split(';', Qt::SkipEmptyParts);
for (int i = 0; i < thanks.count(); i++)
auto thanks = QString(SPECIAL_THANKS).split(';', Qt::SkipEmptyParts);
for (auto i = 0; i < thanks.count(); ++i)
thanks[i]
= QString("<li><a href=\"%2\">%1</a></li>").arg(thanks.at(i).split(',')[0], thanks.at(i).split(',')[1]);
text = i18n("Special thanks to:") + "<ul>" + thanks.join("") + "</ul>";
Expand Down
11 changes: 6 additions & 5 deletions sources/awesome-widget/plugin/awabstractpairconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void AWAbstractPairConfig::addSelector(const QStringList &_keys, const QStringLi

void AWAbstractPairConfig::clearSelectors()
{
for (auto &selector : m_selectors) {
for (auto selector : m_selectors) {
disconnect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
ui->verticalLayout->removeWidget(selector);
selector->deleteLater();
Expand All @@ -130,9 +130,9 @@ void AWAbstractPairConfig::clearSelectors()

void AWAbstractPairConfig::execDialog()
{
int ret = exec();
auto ret = exec();
QHash<QString, QString> data;
for (auto &selector : m_selectors) {
for (auto selector : m_selectors) {
QPair<QString, QString> select = selector->current();
if (select.first.isEmpty())
continue;
Expand Down Expand Up @@ -160,6 +160,7 @@ QPair<QStringList, QStringList> AWAbstractPairConfig::initKeys() const
QStringList left = {""};
left.append(m_helper->leftKeys().isEmpty() ? m_keys : m_helper->leftKeys());
left.sort();

QStringList right = {""};
right.append(m_helper->rightKeys().isEmpty() ? m_keys : m_helper->rightKeys());
right.sort();
Expand All @@ -175,7 +176,7 @@ void AWAbstractPairConfig::updateDialog()
auto keys = initKeys();

for (auto &key : m_helper->keys())
addSelector(keys.first, keys.second, QPair<QString, QString>(key, pairs[key]));
addSelector(keys.first, keys.second, {key, pairs[key]});
// empty one
addSelector(keys.first, keys.second, QPair<QString, QString>());
addSelector(keys.first, keys.second, {});
}
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awabstractpairconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AWAbstractPairConfig : public QDialog
Q_OBJECT

public:
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = QStringList());
explicit AWAbstractPairConfig(QWidget *_parent = nullptr, bool _hasEdit = false, QStringList _keys = {});
~AWAbstractPairConfig() override;
template <class T> void initHelper()
{
Expand Down
27 changes: 10 additions & 17 deletions sources/awesome-widget/plugin/awabstractpairhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ AWAbstractPairHelper::AWAbstractPairHelper(QString _filePath, QString _section)
}


AWAbstractPairHelper::~AWAbstractPairHelper()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}


QStringList AWAbstractPairHelper::keys() const
{
return m_pairs.keys();
Expand Down Expand Up @@ -69,16 +63,16 @@ void AWAbstractPairHelper::initItems()
{
m_pairs.clear();

QStringList configs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, m_filePath);
auto configs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, m_filePath);

for (auto &fileName : configs) {
QSettings settings(fileName, QSettings::IniFormat);
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();

settings.beginGroup(m_section);
QStringList keys = settings.childKeys();
auto keys = settings.childKeys();
for (auto &key : keys) {
QString value = settings.value(key).toString();
auto value = settings.value(key).toString();
qCInfo(LOG_AW) << "Found key" << key << "for value" << value << "in" << settings.fileName();
if (value.isEmpty()) {
qCInfo(LOG_AW) << "Skip empty value for" << key;
Expand All @@ -95,8 +89,8 @@ bool AWAbstractPairHelper::writeItems(const QHash<QString, QString> &_configurat
{
qCDebug(LOG_AW) << "Write configuration" << _configuration;

QString fileName
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).arg(m_filePath);
auto fileName
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), m_filePath);
QSettings settings(fileName, QSettings::IniFormat);
qCInfo(LOG_AW) << "Configuration file" << fileName;

Expand All @@ -107,22 +101,21 @@ bool AWAbstractPairHelper::writeItems(const QHash<QString, QString> &_configurat

settings.sync();

return (settings.status() == QSettings::NoError);
return settings.status() == QSettings::NoError;
}


bool AWAbstractPairHelper::removeUnusedKeys(const QStringList &_keys) const
{
qCDebug(LOG_AW) << "Remove keys" << _keys;

QString fileName
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).arg(m_filePath);
auto fileName
= QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation), m_filePath);
QSettings settings(fileName, QSettings::IniFormat);
qCInfo(LOG_AW) << "Configuration file" << fileName;

settings.beginGroup(m_section);
QStringList foundKeys = settings.childKeys();
for (auto &key : foundKeys) {
for (auto &key : settings.childKeys()) {
if (_keys.contains(key))
continue;
settings.remove(key);
Expand All @@ -131,5 +124,5 @@ bool AWAbstractPairHelper::removeUnusedKeys(const QStringList &_keys) const

settings.sync();

return (settings.status() == QSettings::NoError);
return settings.status() == QSettings::NoError;
}
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awabstractpairhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AWAbstractPairHelper
{
public:
explicit AWAbstractPairHelper(QString _filePath = "", QString _section = "");
virtual ~AWAbstractPairHelper();
virtual ~AWAbstractPairHelper() = default;
[[nodiscard]] QStringList keys() const;
[[nodiscard]] QHash<QString, QString> pairs() const;
[[nodiscard]] QStringList values() const;
Expand Down
10 changes: 5 additions & 5 deletions sources/awesome-widget/plugin/awabstractselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ AWAbstractSelector::AWAbstractSelector(QWidget *_parent, const QPair<bool, bool>
ui->comboBox_key->setEditable(_editable.first);
ui->comboBox_value->setEditable(_editable.second);

connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectionChanged()));
connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this, SIGNAL(selectionChanged()));
connect(ui->comboBox_key, &QComboBox::currentIndexChanged, this, &AWAbstractSelector::selectionChanged);
connect(ui->comboBox_value, &QComboBox::currentIndexChanged, this, &AWAbstractSelector::selectionChanged);
}


Expand All @@ -46,10 +46,10 @@ AWAbstractSelector::~AWAbstractSelector()

QPair<QString, QString> AWAbstractSelector::current() const
{
QString key = ui->comboBox_key->currentText();
QString value = ui->comboBox_value->currentText();
auto key = ui->comboBox_key->currentText();
auto value = ui->comboBox_value->currentText();

return QPair<QString, QString>(key, value);
return {key, value};
}


Expand Down
16 changes: 5 additions & 11 deletions sources/awesome-widget/plugin/awactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ AWActions::AWActions(QObject *_parent)
}


AWActions::~AWActions()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}


void AWActions::checkUpdates(const bool _showAnyway)
{
qCDebug(LOG_AW) << "Show anyway" << _showAnyway;
Expand All @@ -65,7 +59,7 @@ QString AWActions::getFileContent(const QString &_path)
return "";
}

QString output = inputFile.readAll();
auto output = inputFile.readAll();
inputFile.close();
return output;
}
Expand Down Expand Up @@ -102,10 +96,10 @@ QVariantMap AWActions::getFont(const QVariantMap &_defaultFont)
qCDebug(LOG_AW) << "Default font is" << _defaultFont;

QVariantMap fontMap;
int ret = 0;
CFont defaultCFont = CFont(_defaultFont["family"].toString(), _defaultFont["size"].toInt(), 400, false,
_defaultFont["color"].toString());
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false, &ret);
auto ret = 0;
auto defaultCFont = CFont(_defaultFont["family"].toString(), _defaultFont["size"].toInt(), 400, false,
_defaultFont["color"].toString());
auto font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false, &ret);

fontMap["applied"] = ret;
fontMap["color"] = font.color().name();
Expand Down
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AWActions : public QObject

public:
explicit AWActions(QObject *_parent = nullptr);
~AWActions() override;
~AWActions() override = default;
Q_INVOKABLE void checkUpdates(bool _showAnyway = false);
Q_INVOKABLE static QString getFileContent(const QString &_path);
Q_INVOKABLE static bool runCmd(const QString &_cmd, const QStringList &_args);
Expand Down
1 change: 0 additions & 1 deletion sources/awesome-widget/plugin/awbugreporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <QObject>


class QAbstractButton;
class QNetworkReply;

class AWBugReporter : public QObject
Expand Down
36 changes: 15 additions & 21 deletions sources/awesome-widget/plugin/awconfighelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,11 @@ AWConfigHelper::AWConfigHelper(QObject *_parent)
}


AWConfigHelper::~AWConfigHelper()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}


QString AWConfigHelper::configurationDirectory()
{
// get readable directory
QString localDir = QString("%1/awesomewidgets/configs")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
auto localDir = QString("%1/awesomewidgets/configs")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));

// create directory and copy files from default settings
QDir localDirectory;
Expand All @@ -59,7 +53,7 @@ QString AWConfigHelper::configurationDirectory()

bool AWConfigHelper::dropCache()
{
QString fileName
auto fileName
= QString("%1/awesomewidgets.ndx").arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));

return QFile(fileName).remove();
Expand All @@ -75,7 +69,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &
auto configuration = dynamic_cast<const QQmlPropertyMap *>(_nativeConfig);
settings.beginGroup("plasmoid");
for (auto &key : configuration->keys()) {
QVariant value = configuration->value(key);
auto value = configuration->value(key);
if (!value.isValid())
continue;
settings.setValue(key, value);
Expand All @@ -84,7 +78,7 @@ bool AWConfigHelper::exportConfiguration(QObject *_nativeConfig, const QString &

// extensions
for (auto &item : m_dirs) {
QStringList items = QDir(QString("%1/%2").arg(m_baseDir, item)).entryList({"*.desktop"}, QDir::Files);
auto items = QDir(QString("%1/%2").arg(m_baseDir, item)).entryList({"*.desktop"}, QDir::Files);
settings.beginGroup(item);
for (auto &it : items)
copyExtensions(it, item, settings, false);
Expand Down Expand Up @@ -162,7 +156,7 @@ QVariantMap AWConfigHelper::importConfiguration(const QString &_fileName, const

QVariantMap AWConfigHelper::readDataEngineConfiguration()
{
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
auto fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "plasma-dataengine-extsysmon.conf");
qCInfo(LOG_AW) << "Configuration file" << fileName;
QSettings settings(fileName, QSettings::IniFormat);
QVariantMap configuration;
Expand All @@ -186,8 +180,8 @@ bool AWConfigHelper::writeDataEngineConfiguration(const QVariantMap &_configurat
{
qCDebug(LOG_AW) << "Configuration" << _configuration;

QString fileName = QString("%1/plasma-dataengine-extsysmon.conf")
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
auto fileName = QString("%1/plasma-dataengine-extsysmon.conf")
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
QSettings settings(fileName, QSettings::IniFormat);
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();

Expand All @@ -210,15 +204,15 @@ void AWConfigHelper::copyConfigs(const QString &_localDir)
{
qCDebug(LOG_AW) << "Local directory" << _localDir;

QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "awesomewidgets/configs",
QStandardPaths::LocateDirectory);
auto dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "awesomewidgets/configs",
QStandardPaths::LocateDirectory);
for (auto &dir : dirs) {
if (dir == _localDir)
continue;
QStringList files = QDir(dir).entryList(QDir::Files);
auto files = QDir(dir).entryList(QDir::Files);
for (auto &source : files) {
QString destination = QString("%1/%2").arg(_localDir).arg(source);
bool status = QFile::copy(QString("%1/%2").arg(dir).arg(source), destination);
auto destination = QString("%1/%2").arg(_localDir, source);
auto status = QFile::copy(QString("%1/%2").arg(dir, source), destination);
qCInfo(LOG_AW) << "File" << source << "has been copied to" << destination << "with status" << status;
}
}
Expand All @@ -231,7 +225,7 @@ void AWConfigHelper::copyExtensions(const QString &_item, const QString &_type,
qCDebug(LOG_AW) << "Extension" << _item << "has type" << _type << "inverse copying" << _inverse;

_settings.beginGroup(_item);
QSettings itemSettings(QString("%1/%2/%3").arg(m_baseDir).arg(_type).arg(_item), QSettings::IniFormat);
QSettings itemSettings(QString("%1/%2/%3").arg(m_baseDir, _type, _item), QSettings::IniFormat);
itemSettings.beginGroup("Desktop Entry");
if (_inverse)
copySettings(_settings, itemSettings);
Expand All @@ -258,7 +252,7 @@ void AWConfigHelper::readFile(QSettings &_settings, const QString &_key, const Q

QFile file(_fileName);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString text = QString::fromUtf8(file.readAll());
auto text = QString::fromUtf8(file.readAll());
file.close();
_settings.setValue(_key, text);
} else {
Expand Down
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awconfighelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AWConfigHelper : public QObject

public:
explicit AWConfigHelper(QObject *_parent = nullptr);
~AWConfigHelper() override;
~AWConfigHelper() override = default;
Q_INVOKABLE [[nodiscard]] static QString configurationDirectory();
Q_INVOKABLE static bool dropCache();
Q_INVOKABLE bool exportConfiguration(QObject *_nativeConfig, const QString &_fileName) const;
Expand Down
6 changes: 0 additions & 6 deletions sources/awesome-widget/plugin/awcustomkeysconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ AWCustomKeysConfig::AWCustomKeysConfig(QWidget *_parent, const QStringList &_key
setEditable(true, false);
initHelper<AWCustomKeysHelper>();
}


AWCustomKeysConfig::~AWCustomKeysConfig()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
2 changes: 1 addition & 1 deletion sources/awesome-widget/plugin/awcustomkeysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class AWCustomKeysConfig : public AWAbstractPairConfig

public:
explicit AWCustomKeysConfig(QWidget *_parent = nullptr, const QStringList &_keys = QStringList());
~AWCustomKeysConfig() override;
~AWCustomKeysConfig() override = default;
};
6 changes: 0 additions & 6 deletions sources/awesome-widget/plugin/awcustomkeyshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ AWCustomKeysHelper::AWCustomKeysHelper(QObject *_parent)
}


AWCustomKeysHelper::~AWCustomKeysHelper()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}


QString AWCustomKeysHelper::source(const QString &_key) const
{
qCDebug(LOG_AW) << "Get source by key" << _key;
Expand Down
4 changes: 1 addition & 3 deletions sources/awesome-widget/plugin/awcustomkeyshelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AWCustomKeysHelper : public QObject, public AWAbstractPairHelper

public:
explicit AWCustomKeysHelper(QObject *_parent = nullptr);
~AWCustomKeysHelper() override;
~AWCustomKeysHelper() override = default;
// get
[[nodiscard]] QString source(const QString &_key) const;
[[nodiscard]] QStringList sources() const;
Expand All @@ -37,6 +37,4 @@ class AWCustomKeysHelper : public QObject, public AWAbstractPairHelper
void editPairs() override{};
QStringList leftKeys() override;
QStringList rightKeys() override;

private:
};
Loading

0 comments on commit 397b523

Please sign in to comment.