mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
More consistent formatters
This commit is contained in:
parent
51c7299ad0
commit
6bd7788aa9
@ -44,6 +44,7 @@ const QStringList getBuildData()
|
||||
metadata.append(QString(" AWESAPI: %1").arg(AWESAPI));
|
||||
metadata.append(QString(" AWEUAPI: %1").arg(AWEUAPI));
|
||||
metadata.append(QString(" AWEWAPI: %1").arg(AWEWAPI));
|
||||
metadata.append(QString(" AWEFAPI: %1").arg(AWEFAPI));
|
||||
metadata.append(QString(" TIME_KEYS: %1").arg(TIME_KEYS));
|
||||
metadata.append(QString(" STATIC_KEYS: %1").arg(STATIC_KEYS));
|
||||
// cmake properties
|
||||
|
@ -201,7 +201,7 @@ QVariantMap AWConfigHelper::readDataEngineConfiguration() const
|
||||
}
|
||||
|
||||
|
||||
void AWConfigHelper::writeDataEngineConfiguration(
|
||||
bool AWConfigHelper::writeDataEngineConfiguration(
|
||||
const QVariantMap configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Configuration" << configuration;
|
||||
@ -228,6 +228,8 @@ void AWConfigHelper::writeDataEngineConfiguration(
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
const bool importAdds) const;
|
||||
// dataengine
|
||||
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const;
|
||||
Q_INVOKABLE void
|
||||
Q_INVOKABLE bool
|
||||
writeDataEngineConfiguration(const QVariantMap configuration) const;
|
||||
|
||||
private:
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QBuffer>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QPixmap>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
#include <QInputDialog>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awdatetimeformatter.h"
|
||||
#include "awdebug.h"
|
||||
#include "awfloatformatter.h"
|
||||
#include "awnoformatter.h"
|
||||
#include "awscriptformatter.h"
|
||||
@ -66,11 +66,13 @@ QStringList AWFormatterHelper::definedFormatters() const
|
||||
}
|
||||
|
||||
|
||||
QString AWFormatterHelper::formatterByTag(const QString tag) const
|
||||
QVariantMap AWFormatterHelper::getFormatters() const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for tag" << tag;
|
||||
QVariantMap map;
|
||||
for (auto tag : m_formatters.keys())
|
||||
map[tag] = m_formatters[tag]->name();
|
||||
|
||||
return m_formatters.contains(tag) ? m_formatters[tag]->name() : QString();
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@ -80,6 +82,25 @@ QStringList AWFormatterHelper::knownFormatters() const
|
||||
}
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const
|
||||
{
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << fileName;
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
for (auto key : configuration.keys())
|
||||
settings.setValue(key, configuration[key]);
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
@ -155,19 +176,28 @@ void AWFormatterHelper::initKeys()
|
||||
{
|
||||
m_formatters.clear();
|
||||
|
||||
QSettings settings(m_formatterConfig, QSettings::IniFormat);
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
QStringList keys = settings.childKeys();
|
||||
for (auto key : keys) {
|
||||
QString name = settings.value(key).toString();
|
||||
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key;
|
||||
if (!m_formattersClasses.contains(name)) {
|
||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
||||
<< key;
|
||||
QStringList configs = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters/formatters.ini"));
|
||||
|
||||
for (auto fileName : configs) {
|
||||
QSettings settings(fileName, QSettings::IniFormat);
|
||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Formatters"));
|
||||
QStringList keys = settings.childKeys();
|
||||
for (auto key : keys) {
|
||||
QString name = settings.value(key).toString();
|
||||
qCInfo(LOG_AW) << "Found formatter" << name << "for key" << key
|
||||
<< "in" << settings.fileName();
|
||||
if (!m_formattersClasses.contains(name)) {
|
||||
qCWarning(LOG_AW) << "Invalid formatter" << name << "found in"
|
||||
<< key;
|
||||
}
|
||||
m_formatters[key] = m_formattersClasses[name];
|
||||
}
|
||||
m_formatters[key] = m_formattersClasses[name];
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
@ -184,10 +214,6 @@ void AWFormatterHelper::installDirectories()
|
||||
m_directories = QStandardPaths::locateAll(
|
||||
QStandardPaths::GenericDataLocation,
|
||||
QString("awesomewidgets/formatters"), QStandardPaths::LocateDirectory);
|
||||
|
||||
m_formatterConfig = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,8 +35,9 @@ public:
|
||||
virtual ~AWFormatterHelper();
|
||||
QString convert(const QVariant &value, const QString name) const;
|
||||
Q_INVOKABLE QStringList definedFormatters() const;
|
||||
Q_INVOKABLE QString formatterByTag(const QString tag) const;
|
||||
Q_INVOKABLE QVariantMap getFormatters() const;
|
||||
Q_INVOKABLE QStringList knownFormatters() const;
|
||||
Q_INVOKABLE bool writeFormatters(const QVariantMap configuration) const;
|
||||
QList<AbstractExtItem *> items() const;
|
||||
|
||||
private:
|
||||
@ -53,7 +54,6 @@ private:
|
||||
void initItems();
|
||||
// properties
|
||||
QStringList m_directories;
|
||||
QString m_formatterConfig;
|
||||
QHash<QString, AWAbstractFormatter *> m_formatters;
|
||||
QHash<QString, AWAbstractFormatter *> m_formattersClasses;
|
||||
};
|
||||
|
@ -194,12 +194,14 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
else if (key.startsWith(QString("custom")))
|
||||
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("disk")]
|
||||
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
else if (key.contains(QRegExp(
|
||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"mount")][key
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("mount")]
|
||||
[key
|
||||
.remove(QRegExp(QString(
|
||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||
.toInt()]);
|
||||
@ -207,8 +209,9 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("net")]
|
||||
[key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
#include "awkeys.h"
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QJSEngine>
|
||||
#include <QRegExp>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "awdataaggregator.h"
|
||||
#include "awdataengineaggregator.h"
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSettings>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QTime>
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "abstractextitemaggregator.h"
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString filePath)
|
||||
@ -44,6 +44,20 @@ AbstractExtItem::~AbstractExtItem()
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::bumpApi(const int _newVer)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Bump API using new version" << _newVer;
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < _newVer)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< _newVer;
|
||||
setApiVersion(_newVer);
|
||||
writeConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
{
|
||||
_other->setActive(m_active);
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
explicit AbstractExtItem(QWidget *parent = nullptr,
|
||||
const QString filePath = QString());
|
||||
virtual ~AbstractExtItem();
|
||||
virtual void bumpApi(const int _newVer);
|
||||
virtual AbstractExtItem *copy(const QString _fileName, const int _number)
|
||||
= 0;
|
||||
virtual void copyDefaults(AbstractExtItem *_other) const;
|
||||
|
@ -108,6 +108,8 @@ void AWDateTimeFormatter::readConfiguration()
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setFormat(settings.value(QString("X-AW-Format"), m_format).toString());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,6 +207,8 @@ void AWFloatFormatter::readConfiguration()
|
||||
settings.value(QString("X-AW-Precision"), m_precision).toInt());
|
||||
setSummand(settings.value(QString("X-AW-Summand"), m_summand).toDouble());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,6 +165,9 @@ void AWScriptFormatter::readConfiguration()
|
||||
settings.value(QString("X-AW-HasReturn"), m_hasReturn).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
|
||||
// init JS code
|
||||
initProgram();
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,8 @@ void ExtQuotes::readConfiguration()
|
||||
writeConfiguration();
|
||||
}
|
||||
|
||||
bumpApi(AWEQAPI);
|
||||
|
||||
// init query
|
||||
m_url = QUrl(YAHOO_QUOTES_URL);
|
||||
QUrlQuery params;
|
||||
|
@ -227,13 +227,7 @@ void ExtScript::readConfiguration()
|
||||
.split(QChar(','), QString::SkipEmptyParts));
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWESAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWESAPI;
|
||||
setApiVersion(AWESAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWESAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,13 +135,7 @@ void ExtUpgrade::readConfiguration()
|
||||
setFilter(settings.value(QString("X-AW-Filter"), m_filter).toString());
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWEUAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWEUAPI;
|
||||
setApiVersion(AWEUAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWEUAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,6 +183,8 @@ void ExtWeather::readConfiguration()
|
||||
writeConfiguration();
|
||||
}
|
||||
|
||||
bumpApi(AWEWAPI);
|
||||
|
||||
// init query
|
||||
m_url = QUrl(YAHOO_WEATHER_URL);
|
||||
QUrlQuery params;
|
||||
|
@ -431,13 +431,7 @@ void GraphicalItem::readConfiguration()
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
// update for current API
|
||||
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
|
||||
qCWarning(LOG_LIB) << "Bump API version from" << apiVersion() << "to"
|
||||
<< AWGIAPI;
|
||||
setApiVersion(AWGIAPI);
|
||||
writeConfiguration();
|
||||
}
|
||||
bumpApi(AWGIAPI);
|
||||
}
|
||||
|
||||
|
||||
|
@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const
|
||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap desktop = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(desktop)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(desktop)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
});
|
||||
} else if (m_tooltipType == QString("windows")) {
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap desktop = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(desktop)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(desktop)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
});
|
||||
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap window = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(window)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(window)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
});
|
||||
}
|
||||
|
||||
@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
|
||||
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
||||
.replace(QString(" "), QString(" "));
|
||||
else if (key == QString("name"))
|
||||
return KWindowSystem::desktopName(desktop)
|
||||
.replace(QString(" "), QString(" "));
|
||||
return KWindowSystem::desktopName(desktop).replace(QString(" "),
|
||||
QString(" "));
|
||||
else if (key == QString("number"))
|
||||
return QString::number(desktop);
|
||||
else if (key == QString("total"))
|
||||
|
@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration()
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")]
|
||||
= settings.value(QString("ACPIPATH"),
|
||||
QString("/sys/class/power_supply/"))
|
||||
= settings
|
||||
.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"))
|
||||
.toString();
|
||||
rawConfig[QString("GPUDEV")]
|
||||
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||
|
@ -33,6 +33,8 @@
|
||||
#define AWEUAPI 3
|
||||
// extweather api version
|
||||
#define AWEWAPI 2
|
||||
// formatter api version
|
||||
#define AWEFAPI 1
|
||||
// network requests timeout, ms
|
||||
#define REQUEST_TIMEOUT 5000
|
||||
// available time keys
|
||||
|
Loading…
Reference in New Issue
Block a user