Make our model able to be reloaded.
Also fix the coding style and make krazy happy.
This commit is contained in:
parent
f44691b61c
commit
34cccc91ed
5 changed files with 17 additions and 16 deletions
|
@ -40,9 +40,9 @@ EffectConfig::EffectConfig(QObject *parent)
|
||||||
|
|
||||||
bool EffectConfig::effectUiConfigExists(const QString &serviceName) {
|
bool EffectConfig::effectUiConfigExists(const QString &serviceName) {
|
||||||
|
|
||||||
//Our effect UI config is something like showfps_config.dekstop
|
//Our effect UI config is something like showfps_config.desktop
|
||||||
QString tmp = serviceName;
|
QString tmp = serviceName;
|
||||||
const QString effectConfig = tmp.replace("kwin4_effect_", "") + "_config.desktop";
|
const QString effectConfig = tmp.remove("kwin4_effect_") + "_config.desktop";
|
||||||
QString effectConfigFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kde5/services/kwin/" + effectConfig , QStandardPaths::LocateFile);
|
QString effectConfigFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "kde5/services/kwin/" + effectConfig , QStandardPaths::LocateFile);
|
||||||
return !effectConfigFile.isEmpty();
|
return !effectConfigFile.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ void EffectConfig::openConfig(const QString &effectName) {
|
||||||
for(KService::Ptr service : offers) {
|
for(KService::Ptr service : offers) {
|
||||||
KPluginInfo plugin(service);
|
KPluginInfo plugin(service);
|
||||||
if (plugin.name() == effectName) {
|
if (plugin.name() == effectName) {
|
||||||
QString effectConfig = effectName.toLower().replace(" ", "") + "_config";
|
QString effectConfig = effectName.toLower().remove(" ") + "_config";
|
||||||
KCModuleProxy *proxy = new KCModuleProxy(effectConfig);
|
KCModuleProxy *proxy = new KCModuleProxy(effectConfig);
|
||||||
|
|
||||||
//setup the Layout of our UI
|
//setup the Layout of our UI
|
||||||
|
|
|
@ -21,11 +21,8 @@
|
||||||
|
|
||||||
#ifndef EFFECTCONFIG_H
|
#ifndef EFFECTCONFIG_H
|
||||||
#define EFFECTCONFIG_H
|
#define EFFECTCONFIG_H
|
||||||
#include <QAbstractListModel>
|
#include <QObject>
|
||||||
#include <QHash>
|
class QString;
|
||||||
#include <QList>
|
|
||||||
#include <QQuickView>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
namespace KWin {
|
namespace KWin {
|
||||||
namespace Compositing {
|
namespace Compositing {
|
||||||
|
@ -35,7 +32,7 @@ class EffectConfig : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EffectConfig(QObject *parent = 0);
|
explicit EffectConfig(QObject *parent = 0);
|
||||||
QString serviceName(const QString &serviceName);
|
QString serviceName(const QString &serviceName);
|
||||||
|
|
||||||
Q_INVOKABLE bool effectUiConfigExists(const QString &effectName);
|
Q_INVOKABLE bool effectUiConfigExists(const QString &effectName);
|
||||||
|
|
|
@ -131,7 +131,7 @@ void EffectModel::loadEffects() {
|
||||||
QString EffectModel::serviceName(const QString &effectName) {
|
QString EffectModel::serviceName(const QString &effectName) {
|
||||||
//The effect name is something like "Show Fps" and
|
//The effect name is something like "Show Fps" and
|
||||||
//we want something like "showfps"
|
//we want something like "showfps"
|
||||||
return "kwin4_effect_" + effectName.toLower().replace(" ", "");
|
return "kwin4_effect_" + effectName.toLower().remove(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EffectModel::findImage(const QString &imagePath, int size) {
|
QString EffectModel::findImage(const QString &imagePath, int size) {
|
||||||
|
@ -140,6 +140,11 @@ QString EffectModel::findImage(const QString &imagePath, int size) {
|
||||||
return fullImagePath;
|
return fullImagePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EffectModel::reload() {
|
||||||
|
m_effectsList.clear();
|
||||||
|
loadEffects();
|
||||||
|
}
|
||||||
|
|
||||||
EffectView::EffectView(QWindow *parent)
|
EffectView::EffectView(QWindow *parent)
|
||||||
: QQuickView(parent)
|
: QQuickView(parent)
|
||||||
{
|
{
|
||||||
|
@ -150,7 +155,6 @@ EffectView::EffectView(QWindow *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectView::init() {
|
void EffectView::init() {
|
||||||
EffectModel *model = new EffectModel();
|
|
||||||
QString mainFile = QStandardPaths::locate(QStandardPaths::DataLocation, "qml/main.qml", QStandardPaths::LocateFile);
|
QString mainFile = QStandardPaths::locate(QStandardPaths::DataLocation, "qml/main.qml", QStandardPaths::LocateFile);
|
||||||
setResizeMode(QQuickView::SizeRootObjectToView);
|
setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
rootContext()->setContextProperty("engineObject", this);
|
rootContext()->setContextProperty("engineObject", this);
|
||||||
|
@ -162,16 +166,14 @@ void EffectView::effectStatus(const QString &effectName, bool status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EffectView::syncConfig() {
|
void EffectView::syncConfig() {
|
||||||
auto it = m_effectStatus.begin();
|
|
||||||
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins");
|
KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins");
|
||||||
QHash<QString, bool> effectsChanged;
|
QHash<QString, bool> effectsChanged;
|
||||||
|
|
||||||
while (it != m_effectStatus.end()) {
|
for (auto it = m_effectStatus.constBegin(); it != m_effectStatus.constEnd(); it++) {
|
||||||
QVariant boolToString(it.value());
|
QVariant boolToString(it.value());
|
||||||
QString effectName = it.key().toLower();
|
QString effectName = it.key().toLower();
|
||||||
QString effectEntry = effectName.replace(" ", "");
|
QString effectEntry = effectName.remove(" ");
|
||||||
kwinConfig.writeEntry("kwin4_effect_" + effectEntry + "Enabled", boolToString.toString());
|
kwinConfig.writeEntry("kwin4_effect_" + effectEntry + "Enabled", boolToString.toString());
|
||||||
it++;
|
|
||||||
effectsChanged["kwin4_effect_" + effectEntry] = boolToString.toBool();
|
effectsChanged["kwin4_effect_" + effectEntry] = boolToString.toBool();
|
||||||
}
|
}
|
||||||
kwinConfig.sync();
|
kwinConfig.sync();
|
||||||
|
|
|
@ -59,12 +59,13 @@ public:
|
||||||
EffectStatusRole
|
EffectStatusRole
|
||||||
};
|
};
|
||||||
|
|
||||||
EffectModel(QObject *parent = 0);
|
explicit EffectModel(QObject *parent = 0);
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
QString serviceName(const QString &effectName);
|
QString serviceName(const QString &effectName);
|
||||||
|
|
||||||
Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128);
|
Q_INVOKABLE QString findImage(const QString &imagePath, int size = 128);
|
||||||
|
Q_INVOKABLE void reload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadEffects();
|
void loadEffects();
|
||||||
|
|
|
@ -106,6 +106,7 @@ Item {
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
engineObject.syncConfig();
|
engineObject.syncConfig();
|
||||||
|
effectModel.reload();
|
||||||
apply.enabled = false;
|
apply.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue