2013-02-22 18:23:35 +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-09-11 15:18:19 +02:00
|
|
|
#include "private/configcategory_p.h"
|
2013-02-22 18:23:35 +01:00
|
|
|
#include "configview.h"
|
2013-09-11 14:40:11 +02:00
|
|
|
#include "configmodel.h"
|
2013-04-24 22:54:46 +02:00
|
|
|
#include "Plasma/Applet"
|
|
|
|
#include "Plasma/Containment"
|
|
|
|
//#include "plasmoid/wallpaperinterface.h"
|
|
|
|
#include "kdeclarative/configpropertymap.h"
|
2013-02-22 18:23:35 +01:00
|
|
|
|
|
|
|
#include <QDebug>
|
2013-02-28 21:24:30 +01:00
|
|
|
#include <QDir>
|
2013-02-22 18:23:35 +01:00
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlContext>
|
2013-04-24 22:54:46 +02:00
|
|
|
#include <QQuickItem>
|
2013-02-22 18:23:35 +01:00
|
|
|
|
2013-10-05 04:28:26 +02:00
|
|
|
#include <klocalizedstring.h>
|
2013-08-23 15:35:56 +02:00
|
|
|
#include <kdeclarative/kdeclarative.h>
|
2013-02-22 18:23:35 +01:00
|
|
|
|
|
|
|
#include <Plasma/Corona>
|
2013-02-28 21:24:30 +01:00
|
|
|
#include <Plasma/PluginLoader>
|
2013-02-22 18:23:35 +01:00
|
|
|
|
2014-02-19 19:37:30 +01:00
|
|
|
namespace PlasmaQuick
|
|
|
|
{
|
2013-02-27 17:39:16 +01:00
|
|
|
|
|
|
|
//////////////////////////////ConfigView
|
2013-08-27 21:07:55 +02:00
|
|
|
|
|
|
|
class ConfigViewPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConfigViewPrivate(Plasma::Applet *appl, ConfigView *view);
|
|
|
|
~ConfigViewPrivate();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
ConfigView *q;
|
2014-03-11 12:44:04 +01:00
|
|
|
QWeakPointer <Plasma::Applet> applet;
|
2013-08-27 21:07:55 +02:00
|
|
|
ConfigModel *configModel;
|
2014-05-07 13:08:55 +02:00
|
|
|
Plasma::Corona *corona;
|
2013-08-27 21:07:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ConfigViewPrivate::ConfigViewPrivate(Plasma::Applet *appl, ConfigView *view)
|
|
|
|
: q(view),
|
2014-05-07 13:08:55 +02:00
|
|
|
applet(appl),
|
|
|
|
corona(0)
|
2013-08-27 21:07:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigViewPrivate::init()
|
2013-02-22 18:23:35 +01:00
|
|
|
{
|
2014-03-11 12:44:04 +01:00
|
|
|
applet.data()->setUserConfiguring(true);
|
2013-08-27 21:07:55 +02:00
|
|
|
|
2014-01-13 21:21:14 +01:00
|
|
|
KDeclarative::KDeclarative kdeclarative;
|
2013-08-27 21:07:55 +02:00
|
|
|
kdeclarative.setDeclarativeEngine(q->engine());
|
2013-08-23 15:35:56 +02:00
|
|
|
kdeclarative.setupBindings();
|
2013-03-14 11:11:15 +01:00
|
|
|
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 2, 0, "ConfigModel");
|
|
|
|
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 2, 0, "ConfigCategory");
|
2013-02-27 17:39:16 +01:00
|
|
|
|
2013-02-22 18:23:35 +01:00
|
|
|
//FIXME: problem on nvidia, all windows should be transparent or won't show
|
2013-08-27 21:07:55 +02:00
|
|
|
q->setColor(Qt::transparent);
|
2014-03-11 12:44:04 +01:00
|
|
|
q->setTitle(i18n("%1 Settings", applet.data()->title()));
|
2013-02-22 18:23:35 +01:00
|
|
|
|
2014-05-07 13:08:55 +02:00
|
|
|
//systray case
|
|
|
|
if (!applet.data()->containment()->corona()) {
|
|
|
|
Plasma::Applet *a = qobject_cast<Plasma::Applet *>(applet.data()->containment()->parent());
|
|
|
|
if (a) {
|
|
|
|
corona = a->containment()->corona();
|
|
|
|
}
|
|
|
|
} else if (!applet.data()->containment()->corona()->package().isValid()) {
|
2013-02-22 18:23:35 +01:00
|
|
|
qWarning() << "Invalid home screen package";
|
2014-05-07 13:08:55 +02:00
|
|
|
} else {
|
|
|
|
corona = applet.data()->containment()->corona();
|
2013-02-22 18:23:35 +01:00
|
|
|
}
|
|
|
|
|
2013-08-27 21:07:55 +02:00
|
|
|
q->setResizeMode(QQuickView::SizeViewToRootObject);
|
2013-02-22 18:23:35 +01:00
|
|
|
|
2013-02-28 21:24:30 +01:00
|
|
|
//config model local of the applet
|
2014-03-11 12:44:04 +01:00
|
|
|
QQmlComponent *component = new QQmlComponent(q->engine(), QUrl::fromLocalFile(applet.data()->package().filePath("configmodel")), q);
|
2013-08-27 21:07:55 +02:00
|
|
|
QObject *object = component->beginCreate(q->engine()->rootContext());
|
|
|
|
configModel = qobject_cast<ConfigModel *>(object);
|
|
|
|
if (configModel) {
|
2014-03-11 12:44:04 +01:00
|
|
|
configModel->setApplet(applet.data());
|
2013-02-27 18:31:13 +01:00
|
|
|
} else {
|
|
|
|
delete object;
|
2013-02-22 18:23:35 +01:00
|
|
|
}
|
2013-02-22 20:58:54 +01:00
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
q->engine()->rootContext()->setContextProperty("plasmoid", applet.data()->property("_plasma_graphicObject").value<QObject *>());
|
2013-08-27 21:07:55 +02:00
|
|
|
q->engine()->rootContext()->setContextProperty("configDialog", q);
|
2013-05-03 18:07:47 +02:00
|
|
|
component->completeCreate();
|
|
|
|
delete component;
|
2013-02-22 18:23:35 +01:00
|
|
|
}
|
|
|
|
|
2013-08-27 21:07:55 +02:00
|
|
|
ConfigView::ConfigView(Plasma::Applet *applet, QWindow *parent)
|
|
|
|
: QQuickView(parent),
|
|
|
|
d(new ConfigViewPrivate(applet, this))
|
|
|
|
{
|
|
|
|
d->init();
|
|
|
|
qmlRegisterType<ConfigModel>("org.kde.plasma.configuration", 2, 0, "ConfigModel");
|
|
|
|
qmlRegisterType<ConfigCategory>("org.kde.plasma.configuration", 2, 0, "ConfigCategory");
|
2014-03-11 12:44:04 +01:00
|
|
|
connect(applet, &QObject::destroyed, this, &ConfigView::close);
|
2013-08-27 21:07:55 +02:00
|
|
|
}
|
|
|
|
|
2013-02-22 18:23:35 +01:00
|
|
|
ConfigView::~ConfigView()
|
|
|
|
{
|
2014-03-11 12:44:04 +01:00
|
|
|
if (d->applet) {
|
|
|
|
d->applet.data()->setUserConfiguring(false);
|
|
|
|
}
|
2013-02-22 18:23:35 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 17:53:03 +01:00
|
|
|
void ConfigView::init()
|
2013-03-06 14:19:39 +01:00
|
|
|
{
|
2014-05-07 13:08:55 +02:00
|
|
|
setSource(QUrl::fromLocalFile(d->corona->package().filePath("appletconfigurationui")));
|
2013-03-06 14:19:39 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 17:53:03 +01:00
|
|
|
ConfigModel *ConfigView::configModel() const
|
2013-03-01 20:01:54 +01:00
|
|
|
{
|
2013-08-27 21:07:55 +02:00
|
|
|
return d->configModel;
|
2013-03-06 14:19:39 +01:00
|
|
|
}
|
|
|
|
|
2014-02-14 17:28:10 +01:00
|
|
|
QString ConfigView::appletGlobalShortcut() const
|
|
|
|
{
|
2014-03-11 12:44:04 +01:00
|
|
|
if (!d->applet) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->applet.data()->globalShortcut().toString();
|
2014-02-14 17:28:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigView::setAppletGlobalShortcut(const QString &shortcut)
|
|
|
|
{
|
2014-03-11 12:44:04 +01:00
|
|
|
if (!d->applet || d->applet.data()->globalShortcut().toString().toLower() == shortcut.toLower()) {
|
2014-02-14 17:28:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 12:44:04 +01:00
|
|
|
d->applet.data()->setGlobalShortcut(shortcut);
|
2014-02-14 17:28:10 +01:00
|
|
|
emit appletGlobalShortcutChanged();
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:47:08 +01:00
|
|
|
//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
|
|
|
|
void ConfigView::hideEvent(QHideEvent *ev)
|
|
|
|
{
|
|
|
|
QQuickWindow::hideEvent(ev);
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
2013-02-27 14:03:36 +01:00
|
|
|
void ConfigView::resizeEvent(QResizeEvent *re)
|
|
|
|
{
|
2013-02-27 17:39:16 +01:00
|
|
|
if (!rootObject()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-27 14:03:36 +01:00
|
|
|
rootObject()->setWidth(re->size().width());
|
|
|
|
rootObject()->setHeight(re->size().height());
|
|
|
|
QQuickWindow::resizeEvent(re);
|
|
|
|
}
|
|
|
|
|
2014-02-19 19:37:30 +01:00
|
|
|
}
|
|
|
|
|
2013-02-22 18:23:35 +01:00
|
|
|
#include "moc_configview.cpp"
|