Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit c3fd6413 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[kcmkwin] Move effects model into a shared library

Summary:
The main motivation for moving it into a shared library is to share the
model between Desktop Effects and Virtual Desktops KCM.

The extracted model is quite the same as the one in Desktop Effects KCM,
except some minor changes, e.g. rename loadEffect and syncConfig to more
convenient names, add comments, some whitespace changes, fix coding
style in some parts, etc.

Test Plan: effectModelTest passes, Desktop Effects KCM works.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: hein, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D17765
parent 30b257be
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_KEYWORDS)
add_subdirectory( common )
add_subdirectory( kwincompositing )
add_subdirectory( kwinoptions )
add_subdirectory( kwindecoration )
......
# KI18N Translation Domain for this library
add_definitions(-DTRANSLATION_DOMAIN=\"kcmkwincommon\")
include_directories(${KWIN_SOURCE_DIR}/effects)
set(kcmkwincommon_SRC
effectmodel.cpp
)
qt5_add_dbus_interface(kcmkwincommon_SRC
${KWIN_SOURCE_DIR}/org.kde.kwin.Effects.xml kwin_effects_interface
)
add_library(kcmkwincommon SHARED ${kcmkwincommon_SRC})
target_link_libraries(kcmkwincommon
Qt5::Core
Qt5::DBus
KF5::CoreAddons
KF5::ConfigCore
KF5::I18n
KF5::Package
KF5::KCMUtils
kwin4_effect_builtins
)
set_target_properties(kcmkwincommon PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
install(TARGETS kcmkwincommon ${INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
#! /usr/bin/env bash
$XGETTEXT `find . -name \*.cpp` -o $podir/kcmkwincommon.pot
This diff is collapsed.
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com>
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#pragma once
#include <kwin_export.h>
#include <KPluginInfo>
#include <KSharedConfig>
#include <QAbstractItemModel>
#include <QString>
#include <QUrl>
namespace KWin
{
class KWIN_EXPORT EffectModel : public QAbstractItemModel
{
Q_OBJECT
public:
/**
* This enum type is used to specify data roles.
**/
enum AdditionalRoles {
/**
* The user-friendly name of the effect.
**/
NameRole = Qt::UserRole + 1,
/**
* The description of the effect.
**/
DescriptionRole,
/**
* The name of the effect's author. If there are several authors, they
* will be comma separated.
**/
AuthorNameRole,
/**
* The email of the effect's author. If there are several authors, the
* emails will be comma separated.
**/
AuthorEmailRole,
/**
* The license of the effect.
**/
LicenseRole,
/**
* The version of the effect.
**/
VersionRole,
/**
* The category of the effect.
**/
CategoryRole,
/**
* The service name(plugin name) of the effect.
**/
ServiceNameRole,
/**
* The icon name of the effect.
**/
IconNameRole,
/**
* Whether the effect is enabled or disabled.
**/
EffectStatusRole,
/**
* Link to a video demonstration of the effect.
**/
VideoRole,
/**
* Link to the home page of the effect.
**/
WebsiteRole,
/**
* Whether the effect is supported.
**/
SupportedRole,
/**
* The exclusive group of the effect.
**/
ExclusiveRole,
/**
* Whether the effect is internal.
**/
InternalRole,
/**
* Whether the effect has a KCM.
**/
ConfigurableRole,
/**
* Whether this is a scripted effect.
**/
ScriptedRole,
/**
* Whether the effect is enabled by default.
**/
EnabledByDefaultRole
};
/**
* This enum type is used to specify the status of a given effect.
**/
enum class Status {
/**
* The effect is disabled.
**/
Disabled = Qt::Unchecked,
/**
* An enable function is used to determine whether the effect is enabled.
* For example, such function can be useful to disable the blur effect
* when running in a virtual machine.
**/
EnabledUndeterminded = Qt::PartiallyChecked,
/**
* The effect is enabled.
**/
Enabled = Qt::Checked
};
explicit EffectModel(QObject *parent = nullptr);
// Reimplemented from QAbstractItemModel.
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = {}) const override;
int columnCount(const QModelIndex &parent = {}) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
/**
* Changes the status of a given effect.
*
* @param rowIndex An effect represented by the given index.
* @param effectState The new state.
* @note In order to actually apply the change, you have to call save().
**/
void updateEffectStatus(const QModelIndex &rowIndex, Status effectState);
/**
* Loads effects.
*
* You have to call this method in order to populate the model.
**/
void load();
/**
* Saves status of each modified effect.
**/
void save();
/**
* Resets the status of each effect to the default state.
*
* @note In order to actually apply the change, you have to call save().
**/
void defaults();
protected:
enum class Kind {
BuiltIn,
Binary,
Scripted
};
struct EffectData {
QString name;
QString description;
QString authorName;
QString authorEmail;
QString license;
QString version;
QString untranslatedCategory;
QString category;
QString serviceName;
QString iconName;
Status effectStatus;
bool enabledByDefault;
bool enabledByDefaultFunction;
QUrl video;
QUrl website;
bool supported;
QString exclusiveGroup;
bool internal;
bool configurable;
Kind kind;
bool changed = false;
};
/**
* Returns whether the given effect should be stored in the model.
*
* @param data The effect.
* @returns @c true if the effect should be stored, otherwise @c false.
**/
virtual bool shouldStore(const EffectData &data) const;
private:
void loadBuiltInEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
void loadJavascriptEffects(const KConfigGroup &kwinConfig);
void loadPluginEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
int findRowByServiceName(const QString &serviceName);
void syncEffectsToKWin();
QVector<EffectData> m_effectsList;
QVector<EffectData> m_effectsChanged;
Q_DISABLE_COPY(EffectModel)
};
}
......@@ -38,10 +38,9 @@ target_link_libraries(kwincompositing
KF5::ConfigCore
KF5::Declarative
KF5::I18n
KF5::Package
KF5::KCMUtils
KF5::NewStuff
kwin4_effect_builtins
kcmkwincommon
)
if (BUILD_TESTING)
......@@ -72,11 +71,10 @@ if (BUILD_TESTING)
KF5::ConfigCore
KF5::Declarative
KF5::I18n
KF5::Package
KF5::KCMUtils
KF5::NewStuff
kwineffects
kwin4_effect_builtins
kcmkwincommon
)
endif()
......
This diff is collapsed.
......@@ -24,95 +24,15 @@
#include <KColorScheme>
#include <KSharedConfig>
#include <QAbstractItemModel>
#include <QHash>
#include <QList>
#include <QQuickWidget>
#include <QSortFilterProxyModel>
#include <QString>
#include <KPluginInfo>
namespace KWin {
namespace Compositing {
enum class EffectStatus {
Disabled = Qt::Unchecked,
EnabledUndeterminded = Qt::PartiallyChecked,
Enabled = Qt::Checked
};
struct EffectData {
QString name;
QString description;
QString authorName;
QString authorEmail;
QString license;
QString version;
QString category;
QString serviceName;
EffectStatus effectStatus;
bool enabledByDefault;
bool enabledByDefaultFunction;
QUrl video;
bool supported;
QString exclusiveGroup;
bool internal;
bool configurable;
bool scripted;
bool changed = false;
};
class EffectModel : public QAbstractItemModel
{
Q_OBJECT
public:
enum EffectRoles {
NameRole = Qt::UserRole + 1,
DescriptionRole,
AuthorNameRole,
AuthorEmailRole,
LicenseRole,
VersionRole,
CategoryRole,
ServiceNameRole,
EffectStatusRole,
VideoRole,
SupportedRole,
ExclusiveRole,
InternalRole,
ConfigurableRole,
ScriptedRole
};
explicit EffectModel(QObject *parent = 0);
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
QString serviceName(const QString &effectName);
virtual QHash< int, QByteArray > roleNames() const override;
void updateEffectStatus(const QModelIndex &rowIndex, EffectStatus effectState);
void syncEffectsToKWin();
void syncConfig();
void loadEffects();
void defaults();
private:
void loadBuiltInEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
void loadJavascriptEffects(const KConfigGroup &kwinConfig);
void loadPluginEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
int findRowByServiceName(const QString &serviceName);
QList<EffectData> m_effectsList;
QList<EffectData> m_effectsChanged;
class EffectModel;
};
namespace Compositing {
class EffectView : public QQuickWidget
{
......
......@@ -21,6 +21,9 @@
#include "modeltest.h"
#include "../model.h"
#include "effectmodeltest.h"
#include "effectmodel.h"
#include <QtTest>
EffectModelTest::EffectModelTest(QObject *parent)
......@@ -29,7 +32,7 @@ EffectModelTest::EffectModelTest(QObject *parent)
}
void EffectModelTest::testEffectModel() {
KWin::Compositing::EffectModel *effectModel = new KWin::Compositing::EffectModel();
auto effectModel = new KWin::EffectModel();
new ModelTest(effectModel, this);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment