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