configview exposes more stuff for containments: subclass

This commit is contained in:
Marco Martin 2013-03-06 17:53:03 +01:00
parent 132adc7f21
commit 6cede145d5
6 changed files with 195 additions and 101 deletions

View File

@ -19,6 +19,7 @@ set(declarative_appletscript_SRCS
declarative/qmlobject.cpp declarative/qmlobject.cpp
plasmoid/appletinterface.cpp plasmoid/appletinterface.cpp
plasmoid/configview.cpp plasmoid/configview.cpp
plasmoid/containmentconfigview.cpp
plasmoid/containmentinterface.cpp plasmoid/containmentinterface.cpp
plasmoid/declarativeappletscript.cpp plasmoid/declarativeappletscript.cpp
plasmoid/wallpaperinterface.cpp plasmoid/wallpaperinterface.cpp

View File

@ -47,6 +47,7 @@
#include "containmentinterface.h" #include "containmentinterface.h"
#include "configview.h" #include "configview.h"
#include "containmentconfigview.h"
#include "declarative/configpropertymap.h" #include "declarative/configpropertymap.h"
#include "declarative/qmlobject.h" #include "declarative/qmlobject.h"
#include "declarative/packageaccessmanagerfactory.h" #include "declarative/packageaccessmanagerfactory.h"
@ -620,7 +621,14 @@ void AppletInterface::setConfigurationInterfaceShown(bool show)
if (show) { if (show) {
if (!m_configView) { if (!m_configView) {
m_configView = new ConfigView(this); ContainmentInterface *ci = qobject_cast<ContainmentInterface *>(this);
if (ci) {
m_configView = new ContainmentConfigView(ci);
} else {
m_configView = new ConfigView(this);
}
m_configView.data()->init();
} }
m_configView.data()->show(); m_configView.data()->show();

View File

@ -145,7 +145,7 @@ QVariant ConfigModel::data(const QModelIndex& index, int role) const
return m_categories.at(index.row())->icon(); return m_categories.at(index.row())->icon();
case SourceRole: case SourceRole:
if (m_appletInterface) { if (m_appletInterface) {
return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("components", m_categories.at(index.row())->source())); return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("ui", m_categories.at(index.row())->source()));
} else { } else {
return m_categories.at(index.row())->source(); return m_categories.at(index.row())->source();
} }
@ -260,9 +260,7 @@ void ConfigModel::categories_clear(QQmlListProperty<ConfigCategory> *prop)
//////////////////////////////ConfigView //////////////////////////////ConfigView
ConfigView::ConfigView(AppletInterface *interface, QWindow *parent) ConfigView::ConfigView(AppletInterface *interface, QWindow *parent)
: QQuickView(parent), : QQuickView(parent),
m_appletInterface(interface), m_appletInterface(interface)
m_wallpaperConfigModel(0),
m_currentWallpaperConfig(0)
{ {
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 0, 1, "ConfigModel"); qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 0, 1, "ConfigModel");
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 0, 1, "ConfigCategory"); qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 0, 1, "ConfigCategory");
@ -292,102 +290,24 @@ ConfigView::ConfigView(AppletInterface *interface, QWindow *parent)
ContainmentInterface *cont = qobject_cast<ContainmentInterface *>(m_appletInterface); ContainmentInterface *cont = qobject_cast<ContainmentInterface *>(m_appletInterface);
if (cont) {
setCurrentWallpaper(cont->containment()->wallpaper());
}
engine()->rootContext()->setContextProperty("plasmoid", interface); engine()->rootContext()->setContextProperty("plasmoid", interface);
engine()->rootContext()->setContextProperty("configDialog", this); engine()->rootContext()->setContextProperty("configDialog", this);
setSource(QUrl::fromLocalFile(m_appletInterface->applet()->containment()->corona()->package().filePath("configurationui")));
} }
ConfigView::~ConfigView() ConfigView::~ConfigView()
{ {
} }
void ConfigView::init()
{
setSource(QUrl::fromLocalFile(m_appletInterface->applet()->containment()->corona()->package().filePath("configurationui")));
}
ConfigModel *ConfigView::configModel() const ConfigModel *ConfigView::configModel() const
{ {
return m_configModel; return m_configModel;
} }
ConfigModel *ConfigView::wallpaperConfigModel()
{
if (!m_wallpaperConfigModel) {
m_wallpaperConfigModel = new ConfigModel(this);
QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory));
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
foreach (const QString &dirPath, dirs) {
QDir dir(dirPath);
pkg.setDefaultPackageRoot(dirPath);
QStringList packages;
foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) {
QString metadata = dirPath + '/' + sdir + "/metadata.desktop";
if (QFile::exists(metadata)) {
packages << sdir;
}
}
foreach (const QString &package, packages) {
pkg.setPath(package);
ConfigCategory *cat = new ConfigCategory(m_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);
}
}
}
return m_wallpaperConfigModel;
}
ConfigPropertyMap *ConfigView::wallpaperConfiguration() const
{
return m_currentWallpaperConfig;
}
QString ConfigView::currentWallpaper() const
{
return m_currentWallpaper;
}
void ConfigView::setCurrentWallpaper(const QString &wallpaper)
{
if (m_currentWallpaper == wallpaper) {
return;
}
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 //To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
void ConfigView::hideEvent(QHideEvent *ev) void ConfigView::hideEvent(QHideEvent *ev)

View File

@ -117,24 +117,15 @@ class ConfigView : public QQuickView
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT) Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT)
Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT)
Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration CONSTANT)
Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged)
public: public:
ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0); ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0);
virtual ~ConfigView(); virtual ~ConfigView();
void init();
ConfigModel *configModel() const; ConfigModel *configModel() const;
ConfigModel *wallpaperConfigModel();
QString currentWallpaper() const;
void setCurrentWallpaper(const QString &wallpaper);
ConfigPropertyMap *wallpaperConfiguration() const;
Q_SIGNALS:
void currentWallpaperChanged();
protected: protected:
void hideEvent(QHideEvent *ev); void hideEvent(QHideEvent *ev);
void resizeEvent(QResizeEvent *re); void resizeEvent(QResizeEvent *re);
@ -142,9 +133,6 @@ protected:
private: private:
AppletInterface *m_appletInterface; AppletInterface *m_appletInterface;
ConfigModel *m_configModel; ConfigModel *m_configModel;
ConfigModel *m_wallpaperConfigModel;
QString m_currentWallpaper;
ConfigPropertyMap *m_currentWallpaperConfig;
}; };
#endif // multiple inclusion guard #endif // multiple inclusion guard

View File

@ -0,0 +1,120 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "containmentconfigview.h"
#include "plasmoid/containmentinterface.h"
#include "plasmoid/wallpaperinterface.h"
#include "declarative/configpropertymap.h"
#include <QDebug>
#include <QDir>
#include <QQmlContext>
#include <KLocalizedString>
#include <Plasma/PluginLoader>
//////////////////////////////ContainmentConfigView
ContainmentConfigView::ContainmentConfigView(ContainmentInterface *interface, QWindow *parent)
: ConfigView(interface, parent),
m_contianmentInterface(interface),
m_wallpaperConfigModel(0),
m_currentWallpaperConfig(0)
{
engine()->rootContext()->setContextProperty("configDialog", this);
setCurrentWallpaper(interface->containment()->wallpaper());
}
ContainmentConfigView::~ContainmentConfigView()
{
}
ConfigModel *ContainmentConfigView::wallpaperConfigModel()
{
if (!m_wallpaperConfigModel) {
m_wallpaperConfigModel = new ConfigModel(this);
QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory));
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
foreach (const QString &dirPath, dirs) {
QDir dir(dirPath);
pkg.setDefaultPackageRoot(dirPath);
QStringList packages;
foreach (const QString &sdir, dir.entryList(QDir::AllDirs | QDir::Readable)) {
QString metadata = dirPath + '/' + sdir + "/metadata.desktop";
if (QFile::exists(metadata)) {
packages << sdir;
}
}
foreach (const QString &package, packages) {
pkg.setPath(package);
ConfigCategory *cat = new ConfigCategory(m_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);
}
}
}
return m_wallpaperConfigModel;
}
ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const
{
return m_currentWallpaperConfig;
}
QString ContainmentConfigView::currentWallpaper() const
{
return m_currentWallpaper;
}
void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper)
{
if (m_currentWallpaper == wallpaper) {
return;
}
if (m_contianmentInterface->containment()->wallpaper() == wallpaper) {
delete m_currentWallpaperConfig;
m_currentWallpaperConfig = m_contianmentInterface->wallpaperInterface()->configuration();
} else {
if (m_contianmentInterface->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 = m_contianmentInterface->containment()->config();
cfg = KConfigGroup(&cfg, "Wallpaper");
m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
}
m_currentWallpaper = wallpaper;
emit currentWallpaperChanged();
}
#include "moc_containmentconfigview.cpp"

View File

@ -0,0 +1,57 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CONTAINMENTCONFIGVIEW_H
#define CONTAINMENTCONFIGVIEW_H
#include "configview.h"
class ContainmentInterface;
class ConfigPropertyMap;
//TODO: is it possible to move this in the shell?
class ContainmentConfigView : public ConfigView
{
Q_OBJECT
Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT)
Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration CONSTANT)
Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged)
public:
ContainmentConfigView(ContainmentInterface *interface, QWindow *parent = 0);
virtual ~ContainmentConfigView();
ConfigModel *wallpaperConfigModel();
QString currentWallpaper() const;
void setCurrentWallpaper(const QString &wallpaper);
ConfigPropertyMap *wallpaperConfiguration() const;
Q_SIGNALS:
void currentWallpaperChanged();
private:
ContainmentInterface *m_contianmentInterface;
ConfigModel *m_wallpaperConfigModel;
QString m_currentWallpaper;
ConfigPropertyMap *m_currentWallpaperConfig;
};
#endif // multiple inclusion guard