use d pointer in containmentconfigview
This commit is contained in:
parent
8c4bbf10c2
commit
38afa72e8d
@ -1,25 +1,4 @@
|
|||||||
/*
|
#include "currentcontainmentactionsmodel_p.h"
|
||||||
* 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 <Plasma/Containment>
|
|
||||||
#include "currentcontainmentactionsmodel.h"
|
|
||||||
#include <kdeclarative/configpropertymap.h>
|
#include <kdeclarative/configpropertymap.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -34,78 +13,80 @@
|
|||||||
#include <Plasma/ContainmentActions>
|
#include <Plasma/ContainmentActions>
|
||||||
#include <Plasma/PluginLoader>
|
#include <Plasma/PluginLoader>
|
||||||
|
|
||||||
|
class ContainmentConfigViewPrivate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////ContainmentConfigView
|
|
||||||
ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent)
|
|
||||||
: ConfigView(cont, parent),
|
|
||||||
m_containment(cont),
|
|
||||||
m_wallpaperConfigModel(0),
|
|
||||||
m_containmentActionConfigModel(0),
|
|
||||||
m_currentContainmentActionsModel(0),
|
|
||||||
m_currentWallpaperConfig(0),
|
|
||||||
m_ownWallpaperConfig(0)
|
|
||||||
{
|
{
|
||||||
qmlRegisterType<QStandardItemModel>();
|
public:
|
||||||
engine()->rootContext()->setContextProperty("configDialog", this);
|
ContainmentConfigViewPrivate(Plasma::Containment *cont, ContainmentConfigView *view);
|
||||||
|
~ContainmentConfigViewPrivate();
|
||||||
|
|
||||||
|
void syncWallpaperObjects();
|
||||||
|
void applyWallpaper();
|
||||||
|
ConfigModel *doWallpaperConfigModel();
|
||||||
|
void setCurrentWallpaper(const QString &wallpaper);
|
||||||
|
ConfigModel *doContainmentActionConfigModel();
|
||||||
|
QStandardItemModel *doCurrentContainmentActionsModel();
|
||||||
|
|
||||||
|
|
||||||
|
ContainmentConfigView *q;
|
||||||
|
Plasma::Containment *containment;
|
||||||
|
ConfigModel *wallpaperConfigModel;
|
||||||
|
QString currentWallpaper;
|
||||||
|
ConfigModel *containmentActionConfigModel;
|
||||||
|
CurrentContainmentActionsModel *currentContainmentActionsModel;
|
||||||
|
ConfigPropertyMap *currentWallpaperConfig;
|
||||||
|
ConfigPropertyMap *ownWallpaperConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
ContainmentConfigViewPrivate::ContainmentConfigViewPrivate(Plasma::Containment *cont, ContainmentConfigView *view)
|
||||||
|
: q(view),
|
||||||
|
containment(cont),
|
||||||
|
wallpaperConfigModel(0),
|
||||||
|
containmentActionConfigModel(0),
|
||||||
|
currentContainmentActionsModel(0),
|
||||||
|
currentWallpaperConfig(0),
|
||||||
|
ownWallpaperConfig(0)
|
||||||
|
{
|
||||||
|
q->engine()->rootContext()->setContextProperty("configDialog", q);
|
||||||
setCurrentWallpaper(cont->containment()->wallpaper());
|
setCurrentWallpaper(cont->containment()->wallpaper());
|
||||||
|
|
||||||
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
pkg.setDefaultPackageRoot("plasma/wallpapers");
|
pkg.setDefaultPackageRoot("plasma/wallpapers");
|
||||||
pkg.setPath(m_containment->wallpaper());
|
pkg.setPath(containment->wallpaper());
|
||||||
QFile file(pkg.filePath("config", "main.xml"));
|
QFile file(pkg.filePath("config", "main.xml"));
|
||||||
KConfigGroup cfg = m_containment->config();
|
KConfigGroup cfg = containment->config();
|
||||||
cfg = KConfigGroup(&cfg, "Wallpaper");
|
cfg = KConfigGroup(&cfg, "Wallpaper");
|
||||||
|
|
||||||
syncWallpaperObjects();
|
syncWallpaperObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainmentConfigView::~ContainmentConfigView()
|
ContainmentConfigViewPrivate::~ContainmentConfigViewPrivate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainmentConfigView::init()
|
void ContainmentConfigViewPrivate::syncWallpaperObjects()
|
||||||
{
|
{
|
||||||
setSource(QUrl::fromLocalFile(m_containment->containment()->corona()->package().filePath("containmentconfigurationui")));
|
QObject *wallpaperGraphicsObject = containment->property("wallpaperGraphicsObject").value<QObject *>();
|
||||||
|
q->engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject);
|
||||||
|
|
||||||
|
//FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work?
|
||||||
|
currentWallpaperConfig = static_cast<ConfigPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigModel *ContainmentConfigView::containmentActionConfigModel()
|
void ContainmentConfigViewPrivate::applyWallpaper()
|
||||||
{
|
{
|
||||||
if (!m_containmentActionConfigModel) {
|
containment->setWallpaper(currentWallpaper);
|
||||||
m_containmentActionConfigModel = new ConfigModel(this);
|
|
||||||
|
|
||||||
KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentActionsInfo(QString());
|
delete ownWallpaperConfig;
|
||||||
|
ownWallpaperConfig = 0;
|
||||||
|
|
||||||
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
syncWallpaperObjects();
|
||||||
|
emit q->wallpaperConfigurationChanged();
|
||||||
foreach (const KPluginInfo &info, actions) {
|
|
||||||
pkg.setDefaultPackageRoot(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "plasma/containmentactions", QStandardPaths::LocateDirectory));
|
|
||||||
ConfigCategory *cat = new ConfigCategory(m_containmentActionConfigModel);
|
|
||||||
cat->setName(info.name());
|
|
||||||
cat->setIcon(info.icon());
|
|
||||||
cat->setSource(pkg.filePath("ui", "config.qml"));
|
|
||||||
cat->setPluginName(info.pluginName());
|
|
||||||
m_containmentActionConfigModel->appendCategory(cat);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return m_containmentActionConfigModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel()
|
ConfigModel *ContainmentConfigViewPrivate::doWallpaperConfigModel()
|
||||||
{
|
{
|
||||||
if (!m_currentContainmentActionsModel) {
|
if (!wallpaperConfigModel) {
|
||||||
m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this);
|
wallpaperConfigModel = new ConfigModel(q);
|
||||||
}
|
|
||||||
return m_currentContainmentActionsModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigModel *ContainmentConfigView::wallpaperConfigModel()
|
|
||||||
{
|
|
||||||
if (!m_wallpaperConfigModel) {
|
|
||||||
m_wallpaperConfigModel = new ConfigModel(this);
|
|
||||||
QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory));
|
QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory));
|
||||||
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
foreach (const QString &dirPath, dirs) {
|
foreach (const QString &dirPath, dirs) {
|
||||||
@ -125,74 +106,134 @@ ConfigModel *ContainmentConfigView::wallpaperConfigModel()
|
|||||||
if (!pkg.isValid()) {
|
if (!pkg.isValid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ConfigCategory *cat = new ConfigCategory(m_wallpaperConfigModel);
|
ConfigCategory *cat = new ConfigCategory(wallpaperConfigModel);
|
||||||
cat->setName(pkg.metadata().name());
|
cat->setName(pkg.metadata().name());
|
||||||
cat->setIcon(pkg.metadata().icon());
|
cat->setIcon(pkg.metadata().icon());
|
||||||
cat->setSource(pkg.filePath("ui", "config.qml"));
|
cat->setSource(pkg.filePath("ui", "config.qml"));
|
||||||
cat->setPluginName(package);
|
cat->setPluginName(package);
|
||||||
m_wallpaperConfigModel->appendCategory(cat);
|
wallpaperConfigModel->appendCategory(cat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m_wallpaperConfigModel;
|
return wallpaperConfigModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const
|
void ContainmentConfigViewPrivate::setCurrentWallpaper(const QString &wallpaper)
|
||||||
{
|
{
|
||||||
return m_currentWallpaperConfig;
|
if (currentWallpaper == wallpaper) {
|
||||||
}
|
|
||||||
|
|
||||||
QString ContainmentConfigView::currentWallpaper() const
|
|
||||||
{
|
|
||||||
return m_currentWallpaper;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper)
|
|
||||||
{
|
|
||||||
if (m_currentWallpaper == wallpaper) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_ownWallpaperConfig;
|
delete ownWallpaperConfig;
|
||||||
m_ownWallpaperConfig = 0;
|
ownWallpaperConfig = 0;
|
||||||
|
|
||||||
if (m_containment->wallpaper() == wallpaper) {
|
if (containment->wallpaper() == wallpaper) {
|
||||||
syncWallpaperObjects();
|
syncWallpaperObjects();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//we have to construct an independent ConfigPropertyMap when we want to configure wallpapers that are not the current one
|
//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");
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
pkg.setDefaultPackageRoot("plasma/wallpapers");
|
pkg.setDefaultPackageRoot("plasma/wallpapers");
|
||||||
pkg.setPath(wallpaper);
|
pkg.setPath(wallpaper);
|
||||||
QFile file(pkg.filePath("config", "main.xml"));
|
QFile file(pkg.filePath("config", "main.xml"));
|
||||||
KConfigGroup cfg = m_containment->config();
|
KConfigGroup cfg = containment->config();
|
||||||
cfg = KConfigGroup(&cfg, "Wallpaper");
|
cfg = KConfigGroup(&cfg, "Wallpaper");
|
||||||
m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
|
currentWallpaperConfig = ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), q);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentWallpaper = wallpaper;
|
currentWallpaper = wallpaper;
|
||||||
emit currentWallpaperChanged();
|
emit q->currentWallpaperChanged();
|
||||||
emit wallpaperConfigurationChanged();
|
emit q->wallpaperConfigurationChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigModel *ContainmentConfigViewPrivate::doContainmentActionConfigModel()
|
||||||
|
{
|
||||||
|
if (!containmentActionConfigModel) {
|
||||||
|
containmentActionConfigModel = new ConfigModel(q);
|
||||||
|
|
||||||
|
KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentActionsInfo(QString());
|
||||||
|
|
||||||
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
|
|
||||||
|
foreach (const KPluginInfo &info, actions) {
|
||||||
|
pkg.setDefaultPackageRoot(QStandardPaths::locate(QStandardPaths::GenericDataLocation, "plasma/containmentactions", QStandardPaths::LocateDirectory));
|
||||||
|
ConfigCategory *cat = new ConfigCategory(containmentActionConfigModel);
|
||||||
|
cat->setName(info.name());
|
||||||
|
cat->setIcon(info.icon());
|
||||||
|
cat->setSource(pkg.filePath("ui", "config.qml"));
|
||||||
|
cat->setPluginName(info.pluginName());
|
||||||
|
containmentActionConfigModel->appendCategory(cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return containmentActionConfigModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStandardItemModel *ContainmentConfigViewPrivate::doCurrentContainmentActionsModel()
|
||||||
|
{
|
||||||
|
if (!currentContainmentActionsModel) {
|
||||||
|
currentContainmentActionsModel = new CurrentContainmentActionsModel(containment, q);
|
||||||
|
}
|
||||||
|
return currentContainmentActionsModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////ContainmentConfigView
|
||||||
|
ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent)
|
||||||
|
: ConfigView(cont, parent),
|
||||||
|
d(new ContainmentConfigViewPrivate(cont, this))
|
||||||
|
{
|
||||||
|
qmlRegisterType<QStandardItemModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
ContainmentConfigView::~ContainmentConfigView()
|
||||||
|
{
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainmentConfigView::init()
|
||||||
|
{
|
||||||
|
setSource(QUrl::fromLocalFile(d->containment->containment()->corona()->package().filePath("containmentconfigurationui")));
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigModel *ContainmentConfigView::wallpaperConfigModel()
|
||||||
|
{
|
||||||
|
return d->doWallpaperConfigModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const
|
||||||
|
{
|
||||||
|
return d->currentWallpaperConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ContainmentConfigView::currentWallpaper() const
|
||||||
|
{
|
||||||
|
return d->currentWallpaper;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper)
|
||||||
|
{
|
||||||
|
d->setCurrentWallpaper(wallpaper);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainmentConfigView::applyWallpaper()
|
void ContainmentConfigView::applyWallpaper()
|
||||||
{
|
{
|
||||||
m_containment->setWallpaper(m_currentWallpaper);
|
d->applyWallpaper();
|
||||||
|
|
||||||
delete m_ownWallpaperConfig;
|
|
||||||
m_ownWallpaperConfig = 0;
|
|
||||||
|
|
||||||
syncWallpaperObjects();
|
|
||||||
emit wallpaperConfigurationChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainmentConfigView::syncWallpaperObjects()
|
void ContainmentConfigView::syncWallpaperObjects()
|
||||||
{
|
{
|
||||||
QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>();
|
d->syncWallpaperObjects();
|
||||||
engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject);
|
}
|
||||||
|
|
||||||
//FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work?
|
ConfigModel *ContainmentConfigView::containmentActionConfigModel()
|
||||||
m_currentWallpaperConfig = static_cast<ConfigPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>());
|
{
|
||||||
|
return d->doContainmentActionConfigModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel()
|
||||||
|
{
|
||||||
|
return d->doCurrentContainmentActionsModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_containmentconfigview.cpp"
|
#include "moc_containmentconfigview.cpp"
|
||||||
|
@ -30,6 +30,7 @@ namespace Plasma {
|
|||||||
|
|
||||||
class ConfigPropertyMap;
|
class ConfigPropertyMap;
|
||||||
class CurrentContainmentActionsModel;
|
class CurrentContainmentActionsModel;
|
||||||
|
class ContainmentConfigViewPrivate;
|
||||||
|
|
||||||
//TODO: is it possible to move this in the shell?
|
//TODO: is it possible to move this in the shell?
|
||||||
class ContainmentConfigView : public ConfigView
|
class ContainmentConfigView : public ConfigView
|
||||||
@ -64,6 +65,7 @@ protected:
|
|||||||
void syncWallpaperObjects();
|
void syncWallpaperObjects();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ContainmentConfigViewPrivate *const d;
|
||||||
Plasma::Containment *m_containment;
|
Plasma::Containment *m_containment;
|
||||||
ConfigModel *m_wallpaperConfigModel;
|
ConfigModel *m_wallpaperConfigModel;
|
||||||
ConfigModel *m_containmentActionConfigModel;
|
ConfigModel *m_containmentActionConfigModel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user