diff --git a/src/plasmaview/containmentconfigview.cpp b/src/plasmaview/containmentconfigview.cpp index 733e4c8b2..04714dc39 100644 --- a/src/plasmaview/containmentconfigview.cpp +++ b/src/plasmaview/containmentconfigview.cpp @@ -1,3 +1,22 @@ +/* + * 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 "currentcontainmentactionsmodel_p.h" #include "containmentconfigview.h" @@ -15,80 +34,74 @@ #include #include -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) { -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); + qmlRegisterType(); + engine()->rootContext()->setContextProperty("configDialog", this); setCurrentWallpaper(cont->containment()->wallpaper()); Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); pkg.setDefaultPackageRoot("plasma/wallpapers"); - pkg.setPath(containment->wallpaper()); + pkg.setPath(m_containment->wallpaper()); QFile file(pkg.filePath("config", "main.xml")); - KConfigGroup cfg = containment->config(); + KConfigGroup cfg = m_containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); syncWallpaperObjects(); } -ContainmentConfigViewPrivate::~ContainmentConfigViewPrivate() +ContainmentConfigView::~ContainmentConfigView() { } -void ContainmentConfigViewPrivate::syncWallpaperObjects() +void ContainmentConfigView::init() { - 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()); + setSource(QUrl::fromLocalFile(m_containment->containment()->corona()->package().filePath("containmentconfigurationui"))); } -void ContainmentConfigViewPrivate::applyWallpaper() +ConfigModel *ContainmentConfigView::containmentActionConfigModel() { - containment->setWallpaper(currentWallpaper); + if (!m_containmentActionConfigModel) { + m_containmentActionConfigModel = new ConfigModel(this); - delete ownWallpaperConfig; - ownWallpaperConfig = 0; + KPluginInfo::List actions = Plasma::PluginLoader::self()->listContainmentActionsInfo(QString()); - syncWallpaperObjects(); - emit q->wallpaperConfigurationChanged(); + 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; } -ConfigModel *ContainmentConfigViewPrivate::doWallpaperConfigModel() +QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel() { - if (!wallpaperConfigModel) { - wallpaperConfigModel = new ConfigModel(q); + if (!m_currentContainmentActionsModel) { + m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this); + } + return m_currentContainmentActionsModel; +} + +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) { @@ -108,134 +121,74 @@ ConfigModel *ContainmentConfigViewPrivate::doWallpaperConfigModel() if (!pkg.isValid()) { continue; } - ConfigCategory *cat = new ConfigCategory(wallpaperConfigModel); + 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); - wallpaperConfigModel->appendCategory(cat); + m_wallpaperConfigModel->appendCategory(cat); } } } - return wallpaperConfigModel; + return m_wallpaperConfigModel; } -void ContainmentConfigViewPrivate::setCurrentWallpaper(const QString &wallpaper) +ConfigPropertyMap *ContainmentConfigView::wallpaperConfiguration() const { - if (currentWallpaper == wallpaper) { + return m_currentWallpaperConfig; +} + +QString ContainmentConfigView::currentWallpaper() const +{ + return m_currentWallpaper; +} + +void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) +{ + if (m_currentWallpaper == wallpaper) { return; } - delete ownWallpaperConfig; - ownWallpaperConfig = 0; + delete m_ownWallpaperConfig; + m_ownWallpaperConfig = 0; - if (containment->wallpaper() == wallpaper) { + if (m_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 = containment->config(); + KConfigGroup cfg = m_containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); - currentWallpaperConfig = ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), q); + m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); } - 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); + m_currentWallpaper = wallpaper; + emit currentWallpaperChanged(); + emit wallpaperConfigurationChanged(); } void ContainmentConfigView::applyWallpaper() { - d->applyWallpaper(); + m_containment->setWallpaper(m_currentWallpaper); + + delete m_ownWallpaperConfig; + m_ownWallpaperConfig = 0; + + syncWallpaperObjects(); + emit wallpaperConfigurationChanged(); } void ContainmentConfigView::syncWallpaperObjects() { - d->syncWallpaperObjects(); -} + QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value(); + engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject); -ConfigModel *ContainmentConfigView::containmentActionConfigModel() -{ - return d->doContainmentActionConfigModel(); -} - -QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel() -{ - return d->doCurrentContainmentActionsModel(); + //FIXME: why m_wallpaperGraphicsObject->property("configuration").value() doesn't work? + m_currentWallpaperConfig = static_cast(wallpaperGraphicsObject->property("configuration").value()); } #include "moc_containmentconfigview.cpp" diff --git a/src/plasmaview/containmentconfigview.h b/src/plasmaview/containmentconfigview.h index a2f9f017f..619fa141e 100644 --- a/src/plasmaview/containmentconfigview.h +++ b/src/plasmaview/containmentconfigview.h @@ -30,7 +30,6 @@ namespace Plasma { class ConfigPropertyMap; class CurrentContainmentActionsModel; -class ContainmentConfigViewPrivate; //TODO: is it possible to move this in the shell? class ContainmentConfigView : public ConfigView @@ -65,7 +64,13 @@ protected: void syncWallpaperObjects(); private: - ContainmentConfigViewPrivate *const d; + Plasma::Containment *m_containment; + ConfigModel *m_wallpaperConfigModel; + ConfigModel *m_containmentActionConfigModel; + CurrentContainmentActionsModel *m_currentContainmentActionsModel; + QString m_currentWallpaper; + ConfigPropertyMap *m_currentWallpaperConfig; + ConfigPropertyMap *m_ownWallpaperConfig; }; #endif // multiple inclusion guard