possible to configure wallpapers != from current
This commit is contained in:
parent
068dadc6d2
commit
132adc7f21
@ -21,6 +21,7 @@
|
||||
#include "plasmoid/appletinterface.h"
|
||||
#include "plasmoid/containmentinterface.h"
|
||||
#include "plasmoid/wallpaperinterface.h"
|
||||
#include "declarative/configpropertymap.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@ -91,6 +92,22 @@ void ConfigCategory::setSource(const QString &source)
|
||||
emit sourceChanged();
|
||||
}
|
||||
|
||||
QString ConfigCategory::pluginName() const
|
||||
{
|
||||
return m_pluginName;
|
||||
}
|
||||
|
||||
void ConfigCategory::setPluginName(const QString &name)
|
||||
{
|
||||
if (m_pluginName == name) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pluginName = name;
|
||||
emit pluginNameChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////ConfigModel
|
||||
ConfigModel::ConfigModel(QObject *parent)
|
||||
@ -100,6 +117,7 @@ ConfigModel::ConfigModel(QObject *parent)
|
||||
roleNames[NameRole] = "name";
|
||||
roleNames[IconRole] = "icon";
|
||||
roleNames[SourceRole] = "source";
|
||||
roleNames[PluginNameRole] = "pluginName";
|
||||
|
||||
setRoleNames(roleNames);
|
||||
}
|
||||
@ -131,6 +149,8 @@ QVariant ConfigModel::data(const QModelIndex& index, int role) const
|
||||
} else {
|
||||
return m_categories.at(index.row())->source();
|
||||
}
|
||||
case PluginNameRole:
|
||||
return m_categories.at(index.row())->pluginName();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -241,7 +261,8 @@ void ConfigModel::categories_clear(QQmlListProperty<ConfigCategory> *prop)
|
||||
ConfigView::ConfigView(AppletInterface *interface, QWindow *parent)
|
||||
: QQuickView(parent),
|
||||
m_appletInterface(interface),
|
||||
m_wallpaperConfigModel(0)
|
||||
m_wallpaperConfigModel(0),
|
||||
m_currentWallpaperConfig(0)
|
||||
{
|
||||
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 0, 1, "ConfigModel");
|
||||
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 0, 1, "ConfigCategory");
|
||||
@ -269,6 +290,11 @@ ConfigView::ConfigView(AppletInterface *interface, QWindow *parent)
|
||||
}
|
||||
delete component;
|
||||
|
||||
ContainmentInterface *cont = qobject_cast<ContainmentInterface *>(m_appletInterface);
|
||||
|
||||
if (cont) {
|
||||
setCurrentWallpaper(cont->containment()->wallpaper());
|
||||
}
|
||||
|
||||
engine()->rootContext()->setContextProperty("plasmoid", interface);
|
||||
engine()->rootContext()->setContextProperty("configDialog", this);
|
||||
@ -309,6 +335,7 @@ ConfigModel *ConfigView::wallpaperConfigModel()
|
||||
cat->setName(pkg.metadata().name());
|
||||
cat->setIcon(pkg.metadata().icon());
|
||||
cat->setSource(pkg.filePath("ui", "config.qml"));
|
||||
cat->setPluginName(package);
|
||||
m_wallpaperConfigModel->appendCategory(cat);
|
||||
}
|
||||
}
|
||||
@ -316,13 +343,50 @@ ConfigModel *ConfigView::wallpaperConfigModel()
|
||||
return m_wallpaperConfigModel;
|
||||
}
|
||||
|
||||
QObject *ConfigView::wallpaperConfiguration() const
|
||||
ConfigPropertyMap *ConfigView::wallpaperConfiguration() const
|
||||
{
|
||||
ContainmentInterface *cont = qobject_cast<ContainmentInterface *>(m_appletInterface);
|
||||
if (cont) {
|
||||
return cont->wallpaperInterface()->configuration();
|
||||
return m_currentWallpaperConfig;
|
||||
}
|
||||
|
||||
QString ConfigView::currentWallpaper() const
|
||||
{
|
||||
return m_currentWallpaper;
|
||||
}
|
||||
|
||||
void ConfigView::setCurrentWallpaper(const QString &wallpaper)
|
||||
{
|
||||
if (m_currentWallpaper == wallpaper) {
|
||||
return;
|
||||
}
|
||||
return 0;
|
||||
|
||||
ContainmentInterface *cont = qobject_cast<ContainmentInterface *>(m_appletInterface);
|
||||
|
||||
if (!cont) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (cont->containment()->wallpaper() == wallpaper) {
|
||||
delete m_currentWallpaperConfig;
|
||||
m_currentWallpaperConfig = cont->wallpaperInterface()->configuration();
|
||||
} else {
|
||||
if (cont->containment()->wallpaper() != m_currentWallpaper) {
|
||||
delete m_currentWallpaperConfig;
|
||||
}
|
||||
|
||||
//we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one
|
||||
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||
pkg.setDefaultPackageRoot("plasma/wallpapers");
|
||||
pkg.setPath(wallpaper);
|
||||
QFile file(pkg.filePath("config", "main.xml"));
|
||||
KConfigGroup cfg = cont->containment()->config();
|
||||
cfg = KConfigGroup(&cfg, "Wallpaper");
|
||||
m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
|
||||
}
|
||||
|
||||
m_currentWallpaper = wallpaper;
|
||||
emit currentWallpaperChanged();
|
||||
}
|
||||
|
||||
//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <QStandardItemModel>
|
||||
|
||||
class AppletInterface;
|
||||
class ConfigPropertyMap;
|
||||
|
||||
|
||||
class ConfigCategory : public QObject
|
||||
@ -35,6 +36,7 @@ class ConfigCategory : public QObject
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
|
||||
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
|
||||
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged)
|
||||
|
||||
public:
|
||||
ConfigCategory(QObject *parent = 0);
|
||||
@ -49,15 +51,20 @@ public:
|
||||
QString source() const;
|
||||
void setSource(const QString &source);
|
||||
|
||||
QString pluginName() const;
|
||||
void setPluginName(const QString &pluginName);
|
||||
|
||||
Q_SIGNALS:
|
||||
void nameChanged();
|
||||
void iconChanged();
|
||||
void sourceChanged();
|
||||
void pluginNameChanged();
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_icon;
|
||||
QString m_source;
|
||||
QString m_pluginName;
|
||||
};
|
||||
|
||||
class ConfigModel : public QAbstractListModel
|
||||
@ -71,7 +78,8 @@ public:
|
||||
enum Roles {
|
||||
NameRole = Qt::UserRole+1,
|
||||
IconRole,
|
||||
SourceRole
|
||||
SourceRole,
|
||||
PluginNameRole
|
||||
};
|
||||
ConfigModel(QObject *parent = 0);
|
||||
~ConfigModel();
|
||||
@ -110,15 +118,22 @@ class ConfigView : public QQuickView
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT)
|
||||
Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT)
|
||||
Q_PROPERTY(QObject *wallpaperConfiguration READ wallpaperConfiguration CONSTANT)
|
||||
Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration CONSTANT)
|
||||
Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged)
|
||||
|
||||
public:
|
||||
ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0);
|
||||
virtual ~ConfigView();
|
||||
|
||||
ConfigModel *configModel() const;
|
||||
|
||||
ConfigModel *wallpaperConfigModel();
|
||||
QObject *wallpaperConfiguration() const;
|
||||
QString currentWallpaper() const;
|
||||
void setCurrentWallpaper(const QString &wallpaper);
|
||||
ConfigPropertyMap *wallpaperConfiguration() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentWallpaperChanged();
|
||||
|
||||
protected:
|
||||
void hideEvent(QHideEvent *ev);
|
||||
@ -128,6 +143,8 @@ private:
|
||||
AppletInterface *m_appletInterface;
|
||||
ConfigModel *m_configModel;
|
||||
ConfigModel *m_wallpaperConfigModel;
|
||||
QString m_currentWallpaper;
|
||||
ConfigPropertyMap *m_currentWallpaperConfig;
|
||||
};
|
||||
|
||||
#endif // multiple inclusion guard
|
||||
|
@ -48,6 +48,7 @@
|
||||
|
||||
#include "declarative/qmlobject.h"
|
||||
#include "declarative/packageaccessmanagerfactory.h"
|
||||
#include "declarative/configpropertymap.h"
|
||||
|
||||
|
||||
K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScript)
|
||||
@ -58,6 +59,7 @@ DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariant
|
||||
m_interface(0)
|
||||
{
|
||||
qmlRegisterType<AppletInterface>();
|
||||
qmlRegisterType<ConfigPropertyMap>();
|
||||
Q_UNUSED(args);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ Plasma::Package WallpaperInterface::package() const
|
||||
return m_pkg;
|
||||
}
|
||||
|
||||
QObject* WallpaperInterface::configuration() const
|
||||
ConfigPropertyMap *WallpaperInterface::configuration() const
|
||||
{
|
||||
return m_configuration;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class WallpaperInterface : public QQuickItem
|
||||
Q_OBJECT
|
||||
|
||||
//Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
|
||||
Q_PROPERTY(QObject* configuration READ configuration NOTIFY configurationChanged)
|
||||
Q_PROPERTY(ConfigPropertyMap *configuration READ configuration NOTIFY configurationChanged)
|
||||
|
||||
public:
|
||||
WallpaperInterface(ContainmentInterface *parent = 0);
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
Plasma::Package package() const;
|
||||
|
||||
QObject* configuration() const;
|
||||
ConfigPropertyMap *configuration() const;
|
||||
|
||||
Plasma::ConfigLoader *configScheme();
|
||||
|
||||
|
@ -43,6 +43,15 @@ Column {
|
||||
right: undefined
|
||||
}
|
||||
width: 64
|
||||
onClicked: {
|
||||
if (delegate.current) {
|
||||
return
|
||||
} else {
|
||||
configDialog.currentWallpaper = model.pluginName
|
||||
main.sourceFile = model.source
|
||||
root.restoreConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PlasmaComponents.PageStack {
|
||||
|
Loading…
Reference in New Issue
Block a user