From 38afa72e8d0506500545ec971b78ea9c09a63e2e Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliokas Date: Tue, 27 Aug 2013 21:34:38 +0300 Subject: [PATCH] use d pointer in containmentconfigview --- src/plasmaview/containmentconfigview.cpp | 253 +++++++++++++---------- src/plasmaview/containmentconfigview.h | 2 + 2 files changed, 149 insertions(+), 106 deletions(-) diff --git a/src/plasmaview/containmentconfigview.cpp b/src/plasmaview/containmentconfigview.cpp index 235a33f8b..2c75b9922 100644 --- a/src/plasmaview/containmentconfigview.cpp +++ b/src/plasmaview/containmentconfigview.cpp @@ -1,25 +1,4 @@ -/* - * Copyright 2013 Marco Martin - * - * 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 -#include "currentcontainmentactionsmodel.h" +#include "currentcontainmentactionsmodel_p.h" #include #include @@ -34,78 +13,80 @@ #include #include - - - - -//////////////////////////////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) +class ContainmentConfigViewPrivate { - qmlRegisterType(); - engine()->rootContext()->setContextProperty("configDialog", this); +public: + 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()); Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); pkg.setDefaultPackageRoot("plasma/wallpapers"); - pkg.setPath(m_containment->wallpaper()); + pkg.setPath(containment->wallpaper()); QFile file(pkg.filePath("config", "main.xml")); - KConfigGroup cfg = m_containment->config(); + KConfigGroup cfg = containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); 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(); + q->engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject); + + //FIXME: why m_wallpaperGraphicsObject->property("configuration").value() doesn't work? + currentWallpaperConfig = static_cast(wallpaperGraphicsObject->property("configuration").value()); } -ConfigModel *ContainmentConfigView::containmentActionConfigModel() +void ContainmentConfigViewPrivate::applyWallpaper() { - if (!m_containmentActionConfigModel) { - m_containmentActionConfigModel = new ConfigModel(this); + containment->setWallpaper(currentWallpaper); - KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentActionsInfo(QString()); + delete ownWallpaperConfig; + ownWallpaperConfig = 0; - 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(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; + syncWallpaperObjects(); + emit q->wallpaperConfigurationChanged(); } -QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel() +ConfigModel *ContainmentConfigViewPrivate::doWallpaperConfigModel() { - if (!m_currentContainmentActionsModel) { - m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this); - } - return m_currentContainmentActionsModel; -} - -ConfigModel *ContainmentConfigView::wallpaperConfigModel() -{ - if (!m_wallpaperConfigModel) { - m_wallpaperConfigModel = new ConfigModel(this); + if (!wallpaperConfigModel) { + wallpaperConfigModel = new ConfigModel(q); QStringList dirs(QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "plasma/wallpapers", QStandardPaths::LocateDirectory)); Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); foreach (const QString &dirPath, dirs) { @@ -125,74 +106,134 @@ ConfigModel *ContainmentConfigView::wallpaperConfigModel() if (!pkg.isValid()) { continue; } - ConfigCategory *cat = new ConfigCategory(m_wallpaperConfigModel); + ConfigCategory *cat = new ConfigCategory(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); + wallpaperConfigModel->appendCategory(cat); } } } - return m_wallpaperConfigModel; + return wallpaperConfigModel; } -ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const +void ContainmentConfigViewPrivate::setCurrentWallpaper(const QString &wallpaper) { - return m_currentWallpaperConfig; -} - -QString ContainmentConfigView::currentWallpaper() const -{ - return m_currentWallpaper; -} - -void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) -{ - if (m_currentWallpaper == wallpaper) { + if (currentWallpaper == wallpaper) { return; } - delete m_ownWallpaperConfig; - m_ownWallpaperConfig = 0; + delete ownWallpaperConfig; + ownWallpaperConfig = 0; - if (m_containment->wallpaper() == wallpaper) { + if (containment->wallpaper() == wallpaper) { syncWallpaperObjects(); } else { - //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_containment->config(); + KConfigGroup cfg = containment->config(); 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; - emit currentWallpaperChanged(); - emit wallpaperConfigurationChanged(); + currentWallpaper = wallpaper; + emit q->currentWallpaperChanged(); + 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(); +} + +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() { - m_containment->setWallpaper(m_currentWallpaper); - - delete m_ownWallpaperConfig; - m_ownWallpaperConfig = 0; - - syncWallpaperObjects(); - emit wallpaperConfigurationChanged(); + d->applyWallpaper(); } void ContainmentConfigView::syncWallpaperObjects() { - QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value(); - engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject); + d->syncWallpaperObjects(); +} - //FIXME: why m_wallpaperGraphicsObject->property("configuration").value() doesn't work? - m_currentWallpaperConfig = static_cast(wallpaperGraphicsObject->property("configuration").value()); +ConfigModel *ContainmentConfigView::containmentActionConfigModel() +{ + return d->doContainmentActionConfigModel(); +} + +QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel() +{ + return d->doCurrentContainmentActionsModel(); } #include "moc_containmentconfigview.cpp" diff --git a/src/plasmaview/containmentconfigview.h b/src/plasmaview/containmentconfigview.h index 619fa141e..fb0612e0e 100644 --- a/src/plasmaview/containmentconfigview.h +++ b/src/plasmaview/containmentconfigview.h @@ -30,6 +30,7 @@ namespace Plasma { class ConfigPropertyMap; class CurrentContainmentActionsModel; +class ContainmentConfigViewPrivate; //TODO: is it possible to move this in the shell? class ContainmentConfigView : public ConfigView @@ -64,6 +65,7 @@ protected: void syncWallpaperObjects(); private: + ContainmentConfigViewPrivate *const d; Plasma::Containment *m_containment; ConfigModel *m_wallpaperConfigModel; ConfigModel *m_containmentActionConfigModel;