2013-03-06 17:53:03 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-08-27 20:34:38 +02:00
|
|
|
#include "currentcontainmentactionsmodel_p.h"
|
2013-08-31 15:59:09 +02:00
|
|
|
#include "containmentconfigview_p.h"
|
2013-09-02 18:16:25 +02:00
|
|
|
#include "configview_p.h"
|
2013-08-27 21:08:54 +02:00
|
|
|
|
2013-04-24 22:54:46 +02:00
|
|
|
#include <kdeclarative/configpropertymap.h>
|
2013-03-06 17:53:03 +01:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QQmlContext>
|
2013-04-24 22:54:46 +02:00
|
|
|
#include <QQmlEngine>
|
2013-08-23 18:52:57 +02:00
|
|
|
#include <QQmlComponent>
|
2013-03-06 17:53:03 +01:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
2013-04-25 15:07:02 +02:00
|
|
|
#include <Plasma/Corona>
|
2013-08-23 15:35:56 +02:00
|
|
|
#include <Plasma/ContainmentActions>
|
2013-03-06 17:53:03 +01:00
|
|
|
#include <Plasma/PluginLoader>
|
|
|
|
|
|
|
|
//////////////////////////////ContainmentConfigView
|
2013-04-24 22:54:46 +02:00
|
|
|
ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent)
|
|
|
|
: ConfigView(cont, parent),
|
|
|
|
m_containment(cont),
|
2013-03-06 17:53:03 +01:00
|
|
|
m_wallpaperConfigModel(0),
|
2013-08-22 21:44:10 +02:00
|
|
|
m_containmentActionConfigModel(0),
|
2013-08-23 18:52:57 +02:00
|
|
|
m_currentContainmentActionsModel(0),
|
2013-05-07 11:55:21 +02:00
|
|
|
m_currentWallpaperConfig(0),
|
|
|
|
m_ownWallpaperConfig(0)
|
2013-03-06 17:53:03 +01:00
|
|
|
{
|
2013-08-23 18:52:57 +02:00
|
|
|
qmlRegisterType<QStandardItemModel>();
|
2013-03-06 17:53:03 +01:00
|
|
|
engine()->rootContext()->setContextProperty("configDialog", this);
|
2013-04-24 22:54:46 +02:00
|
|
|
setCurrentWallpaper(cont->containment()->wallpaper());
|
2013-04-25 14:11:53 +02:00
|
|
|
|
2013-09-10 17:57:51 +02:00
|
|
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Wallpaper");
|
2013-04-25 14:11:53 +02:00
|
|
|
pkg.setPath(m_containment->wallpaper());
|
|
|
|
QFile file(pkg.filePath("config", "main.xml"));
|
|
|
|
KConfigGroup cfg = m_containment->config();
|
|
|
|
cfg = KConfigGroup(&cfg, "Wallpaper");
|
2013-05-07 11:55:21 +02:00
|
|
|
|
|
|
|
syncWallpaperObjects();
|
2013-03-06 17:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ContainmentConfigView::~ContainmentConfigView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-25 15:07:02 +02:00
|
|
|
void ContainmentConfigView::init()
|
|
|
|
{
|
2013-09-02 20:54:11 +02:00
|
|
|
setSource(QUrl::fromLocalFile(m_containment->corona()->package().filePath("containmentconfigurationui")));
|
2013-04-25 15:07:02 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 21:44:10 +02:00
|
|
|
ConfigModel *ContainmentConfigView::containmentActionConfigModel()
|
|
|
|
{
|
|
|
|
if (!m_containmentActionConfigModel) {
|
|
|
|
m_containmentActionConfigModel = new ConfigModel(this);
|
|
|
|
|
|
|
|
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(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;
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:52:57 +02:00
|
|
|
QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel()
|
2013-08-23 15:35:56 +02:00
|
|
|
{
|
2013-08-23 18:52:57 +02:00
|
|
|
if (!m_currentContainmentActionsModel) {
|
|
|
|
m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this);
|
2013-08-23 16:31:09 +02:00
|
|
|
}
|
2013-08-23 18:52:57 +02:00
|
|
|
return m_currentContainmentActionsModel;
|
2013-08-23 15:35:56 +02:00
|
|
|
}
|
|
|
|
|
2013-03-06 17:53:03 +01:00
|
|
|
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);
|
2013-03-28 01:58:52 +01:00
|
|
|
if (!pkg.isValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-06 17:53:03 +01:00
|
|
|
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)
|
|
|
|
{
|
2013-04-25 14:11:53 +02:00
|
|
|
if (m_currentWallpaper == wallpaper) {
|
2013-03-06 17:53:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-07 11:55:21 +02:00
|
|
|
delete m_ownWallpaperConfig;
|
|
|
|
m_ownWallpaperConfig = 0;
|
|
|
|
|
2013-04-25 11:43:00 +02:00
|
|
|
if (m_containment->wallpaper() == wallpaper) {
|
2013-05-07 11:55:21 +02:00
|
|
|
syncWallpaperObjects();
|
2013-03-06 17:53:03 +01:00
|
|
|
} 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"));
|
2013-04-25 11:43:00 +02:00
|
|
|
KConfigGroup cfg = m_containment->config();
|
2013-03-06 17:53:03 +01:00
|
|
|
cfg = KConfigGroup(&cfg, "Wallpaper");
|
2013-05-07 11:55:21 +02:00
|
|
|
m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this);
|
2013-04-25 14:11:53 +02:00
|
|
|
}
|
2013-03-06 17:53:03 +01:00
|
|
|
|
|
|
|
m_currentWallpaper = wallpaper;
|
|
|
|
emit currentWallpaperChanged();
|
2013-03-07 16:59:32 +01:00
|
|
|
emit wallpaperConfigurationChanged();
|
2013-03-06 17:53:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 15:27:53 +01:00
|
|
|
void ContainmentConfigView::applyWallpaper()
|
|
|
|
{
|
2013-04-25 11:43:00 +02:00
|
|
|
m_containment->setWallpaper(m_currentWallpaper);
|
2013-03-07 16:59:32 +01:00
|
|
|
|
2013-05-07 11:55:21 +02:00
|
|
|
delete m_ownWallpaperConfig;
|
|
|
|
m_ownWallpaperConfig = 0;
|
|
|
|
|
|
|
|
syncWallpaperObjects();
|
|
|
|
emit wallpaperConfigurationChanged();
|
2013-03-07 15:27:53 +01:00
|
|
|
}
|
|
|
|
|
2013-05-07 11:55:21 +02:00
|
|
|
void ContainmentConfigView::syncWallpaperObjects()
|
|
|
|
{
|
|
|
|
QObject *wallpaperGraphicsObject = m_containment->property("wallpaperGraphicsObject").value<QObject *>();
|
|
|
|
engine()->rootContext()->setContextProperty("wallpaper", wallpaperGraphicsObject);
|
|
|
|
|
|
|
|
//FIXME: why m_wallpaperGraphicsObject->property("configuration").value<ConfigPropertyMap *>() doesn't work?
|
|
|
|
m_currentWallpaperConfig = static_cast<ConfigPropertyMap *>(wallpaperGraphicsObject->property("configuration").value<QObject *>());
|
|
|
|
}
|
2013-04-25 14:11:53 +02:00
|
|
|
|
2013-08-31 15:59:09 +02:00
|
|
|
#include "moc_containmentconfigview_p.cpp"
|