diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index 19823bc48..0092adbdb 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -73,8 +73,8 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int } else if (appletId > s_maxAppletId) { s_maxAppletId = appletId; } - QObject::connect(actions->action("configure"), SIGNAL(QAction::triggered()), - q, SLOT(Applet::requestConfiguration)); + QObject::connect(actions->action("configure"), SIGNAL(triggered()), + q, SLOT(requestConfiguration())); } AppletPrivate::~AppletPrivate() diff --git a/src/plasma/private/packages.cpp b/src/plasma/private/packages.cpp index bcfa3ae38..b5f70702c 100644 --- a/src/plasma/private/packages.cpp +++ b/src/plasma/private/packages.cpp @@ -109,7 +109,7 @@ void PlasmoidPackage::initPackage(Package *package) package->setServicePrefix("plasma-applet-"); package->setDefaultPackageRoot("plasma/plasmoids/"); - package->addFileDefinition("configmodel", "ui/config.qml", i18n("Configuration UI pages model")); + package->addFileDefinition("configmodel", "config/config.qml", i18n("Configuration UI pages model")); package->addFileDefinition("mainconfigxml", "config/main.xml", i18n("Configuration XML file")); } diff --git a/src/scriptengines/qml/CMakeLists.txt b/src/scriptengines/qml/CMakeLists.txt index 01164c8e8..af2609f02 100644 --- a/src/scriptengines/qml/CMakeLists.txt +++ b/src/scriptengines/qml/CMakeLists.txt @@ -13,13 +13,9 @@ include_directories(${KDE4_INCLUDE_DIR}/KDE ${PHONON_INCLUDES} ${CMAKE_CURRENT_S #DECLARATIVE APPLET set(declarative_appletscript_SRCS - declarative/configpropertymap.cpp declarative/packageaccessmanager.cpp declarative/packageaccessmanagerfactory.cpp - declarative/qmlobject.cpp plasmoid/appletinterface.cpp - plasmoid/configview.cpp - plasmoid/containmentconfigview.cpp plasmoid/containmentinterface.cpp plasmoid/declarativeappletscript.cpp plasmoid/wallpaperinterface.cpp diff --git a/src/scriptengines/qml/declarative/configpropertymap.cpp b/src/scriptengines/qml/declarative/configpropertymap.cpp deleted file mode 100644 index 8d8270211..000000000 --- a/src/scriptengines/qml/declarative/configpropertymap.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 "configpropertymap.h" - -#include - -#include - - -ConfigPropertyMap::ConfigPropertyMap(KConfigSkeleton *config, QObject *parent) - : QQmlPropertyMap(parent), - m_config(config) -{ - connect(config, &KConfigSkeleton::configChanged, - this, &ConfigPropertyMap::loadConfig); - connect(this, &ConfigPropertyMap::valueChanged, - this, &ConfigPropertyMap::writeConfigValue); - - loadConfig(); -} - -ConfigPropertyMap::~ConfigPropertyMap() -{ - writeConfig(); -} - -void ConfigPropertyMap::loadConfig() -{ - if (!m_config) { - return; - } - - foreach (KConfigSkeletonItem *item, m_config.data()->items()) { - insert(item->key(), item->property()); - } -} - -void ConfigPropertyMap::writeConfig() -{ - if (!m_config) { - return; - } - - foreach (KConfigSkeletonItem *item, m_config.data()->items()) { - item->setProperty(value(item->key())); - } - - m_config.data()->blockSignals(true); - m_config.data()->writeConfig(); - m_config.data()->blockSignals(false); -} - -void ConfigPropertyMap::writeConfigValue(const QString &key, const QVariant &value) -{ - KConfigSkeletonItem *item = m_config.data()->findItem(key); - if (item) { - item->setProperty(value); - m_config.data()->blockSignals(true); - m_config.data()->writeConfig(); - m_config.data()->blockSignals(false); - } -} - -#include "moc_configpropertymap.cpp" - - - diff --git a/src/scriptengines/qml/declarative/configpropertymap.h b/src/scriptengines/qml/declarative/configpropertymap.h deleted file mode 100644 index 38e1ef208..000000000 --- a/src/scriptengines/qml/declarative/configpropertymap.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -#ifndef CONFIGPROPERTYMAP_P -#define CONFIGPROPERTYMAP_P - -#include - -#include - - -class ConfigPropertyMap : public QQmlPropertyMap -{ - Q_OBJECT - -public: - ConfigPropertyMap(KConfigSkeleton *config, QObject *parent = 0); - ~ConfigPropertyMap(); - -private Q_SLOTS: - void loadConfig(); - void writeConfig(); - void writeConfigValue(const QString &key, const QVariant &value); - -private: - QWeakPointerm_config; -}; - -#endif diff --git a/src/scriptengines/qml/declarative/qmlobject.cpp b/src/scriptengines/qml/declarative/qmlobject.cpp deleted file mode 100644 index e6377d943..000000000 --- a/src/scriptengines/qml/declarative/qmlobject.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright 2010 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 "qmlobject.h" - - -#include -#include -#include -#include -#include - -#include -#include - - -#include "packageaccessmanagerfactory.h" -//#include "private/declarative/dataenginebindings_p.h" - - -class QmlObjectPrivate -{ -public: - QmlObjectPrivate(QmlObject *parent) - : q(parent), - engine(0), - component(0), - delay(false) - { - } - - ~QmlObjectPrivate() - { - delete root.data(); - } - - void errorPrint(QQmlComponent *component); - void execute(const QUrl &source); - void scheduleExecutionEnd(); - void minimumWidthChanged(); - void minimumHeightChanged(); - void maximumWidthChanged(); - void maximumHeightChanged(); - void preferredWidthChanged(); - void preferredHeightChanged(); - - - QmlObject *q; - - QUrl source; - QQmlEngine* engine; - QQmlIncubator incubator; - QQmlComponent* component; - QWeakPointer root; - bool delay : 1; -}; - -void QmlObjectPrivate::errorPrint(QQmlComponent *component) -{ - QString errorStr = "Error loading QML file.\n"; - if(component->isError()){ - QList errors = component->errors(); - foreach (const QQmlError &error, errors) { - errorStr += (error.line()>0?QString(QString::number(error.line()) + QLatin1String(": ")):QLatin1String("")) - + error.description() + '\n'; - } - } - kWarning() << component->url().toString() + '\n' + errorStr; -} - -void QmlObjectPrivate::execute(const QUrl &source) -{ - if (source.isEmpty()) { -#ifndef NDEBUG - kDebug() << "File name empty!"; -#endif - return; - } - - delete component; - component = new QQmlComponent(engine, q); - delete root.data(); - - KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine); - kdeclarative.initialize(); - //binds things like kconfig and icons - kdeclarative.setupBindings(); - - component->loadUrl(source); - - if (delay) { - QTimer::singleShot(0, q, SLOT(scheduleExecutionEnd())); - } else { - scheduleExecutionEnd(); - } -} - -void QmlObjectPrivate::scheduleExecutionEnd() -{ - if (component->isReady() || component->isError()) { - q->completeInitialization(); - } else { - QObject::connect(component, SIGNAL(statusChanged(QQmlComponent::Status)), q, SLOT(completeInitialization())); - } -} - -QmlObject::QmlObject(QObject *parent) - : QObject(parent), - d(new QmlObjectPrivate(this)) -{ - d->engine = new QQmlEngine(this); - d->engine->setIncubationController(new QmlObjectIncubationController(0)); - //d->engine->setNetworkAccessManagerFactory(new PackageAccessManagerFactory()); -} - -QmlObject::~QmlObject() -{ -// QDeclarativeNetworkAccessManagerFactory *factory = d->engine->networkAccessManagerFactory(); -// d->engine->setNetworkAccessManagerFactory(0); -// delete factory; - delete d; -} - -void QmlObject::setSource(const QUrl &source) -{ - qDebug() << "Opening" << source; - d->source = source; - d->execute(source); -} - -QUrl QmlObject::source() const -{ - return d->source; -} - -void QmlObject::setInitializationDelayed(const bool delay) -{ - d->delay = delay; -} - -bool QmlObject::isInitializationDelayed() const -{ - return d->delay; -} - -QQmlEngine* QmlObject::engine() -{ - return d->engine; -} - -QObject *QmlObject::rootObject() const -{ - return d->root.data(); -} - -QQmlComponent *QmlObject::mainComponent() const -{ - return d->component; -} - -void QmlObject::completeInitialization() -{ - if (d->root) { - return; - } - if (d->component->status() != QQmlComponent::Ready || d->component->isError()) { - d->errorPrint(d->component); - return; - } - - d->component->create(d->incubator); - - while (!d->incubator.isReady() && d->incubator.status() != QQmlIncubator::Error) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 50); - } - - d->root = d->incubator.object(); - //d->root = d->component->create(); - - if (!d->root) { - d->errorPrint(d->component); - } - -#ifndef NDEBUG - kDebug() << "Execution of QML done!"; -#endif - - emit finished(); -} - -QObject *QmlObject::createObjectFromSource(const QUrl &source) -{ - QQmlComponent *component = new QQmlComponent(d->engine, this); - component->loadUrl(source); - component->create(d->incubator, d->engine->rootContext()); - while (!d->incubator.isReady() && d->incubator.status() != QQmlIncubator::Error) { - QCoreApplication::processEvents(QEventLoop::AllEvents, 50); - } - QObject *object = d->incubator.object(); - - if (!component->isError() && d->root && object) { - //memory management - component->setParent(object); - object->setProperty("parent", QVariant::fromValue(d->root.data())); - return object; - - } else { - d->errorPrint(component); - delete component; - delete object; - return 0; - } -} - - -#include "moc_qmlobject.cpp" diff --git a/src/scriptengines/qml/declarative/qmlobject.h b/src/scriptengines/qml/declarative/qmlobject.h deleted file mode 100644 index 0c17bc448..000000000 --- a/src/scriptengines/qml/declarative/qmlobject.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2010 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. - */ - -#ifndef QMLOBJECT_H -#define QMLOBJECT_H - -#include -#include - -#include -#include -#include -#include - -class QQmlEngine; -class QQmlComponent; - - -class QmlObjectPrivate; - -class QmlObjectIncubationController : public QObject, public QQmlIncubationController -{ - Q_OBJECT - -public: - QmlObjectIncubationController(QObject *parent) - : QObject(parent), - QQmlIncubationController() - { - // Allow incubation for 1/3 of a frame. - m_incubation_time = qMax(1, int(1000 / QGuiApplication::primaryScreen()->refreshRate()) / 3); - } - -protected: - virtual bool event(QEvent *e) - { - if (e->type() == QEvent::User) { - incubate(); - return true; - } - return QObject::event(e); - } - -public slots: - void incubate() - { - if (incubatingObjectCount()) { - incubateFor(m_incubation_time * 2); - if (incubatingObjectCount()) { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - } - } - - void animationStopped() { incubate(); } - -protected: - virtual void incubatingObjectCountChanged(int count) - { - if (count) { - QCoreApplication::postEvent(this, new QEvent(QEvent::User)); - } - } -private: - int m_incubation_time; -}; - -/** - * @class QmlObject plasma/declarativewidget.h - * - * @author Marco Martin - * - * @short An object that instantiates an entire QML context, with its own declarative engine - * - * Plasma::QmlObject provides a class for conveniently use QML based - * declarative user interfaces inside Plasma widgets. - * To one QmlObject corresponds one QML file (that can eventually include others) - * tere will be its own QQmlEngine with a single root object, - * described in the QML file. - */ -class QmlObject : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QUrl source READ source WRITE setSource) - Q_PROPERTY(bool initializationDelayed READ isInitializationDelayed WRITE setInitializationDelayed) - Q_PROPERTY(QObject * rootObject READ rootObject) - -public: - - /** - * Constructs a new QmlObject - * - * @param parent the parent of this object - */ - explicit QmlObject(QObject *parent = 0); - ~QmlObject(); - - /** - * Sets the path of the QML file to parse and execute - * - * @param path the absolute path of a QML file - */ - void setSource(const QUrl &source); - - /** - * @return the absolute path of the current QML file - */ - QUrl source() const; - - /** - * Sets whether the execution of the QML file has to be delayed later in the event loop. It has to be called before setQmlPath(). - * In this case will be possible to assign new objects in the main engine context - * before the main component gets initialized. - * So it will be possible to access it immediately from the QML code. - * The initialization will either be completed automatically asyncronously - * or explicitly by calling completeInitialization() - * - * @param delay if true the initialization of the QML file will be delayed - * at the end of the event loop - */ - void setInitializationDelayed(const bool delay); - - /** - * @return true if the initialization of the QML file will be delayed - * at the end of the event loop - */ - bool isInitializationDelayed() const; - - /** - * @return the declarative engine that runs the qml file assigned to this widget. - */ - QQmlEngine* engine(); - - /** - * @return the root object of the declarative object tree - */ - QObject *rootObject() const; - - /** - * @return the main QQmlComponent of the engine - */ - QQmlComponent *mainComponent() const; - - /** - * Creates and returns an object based on the provided url to a Qml file - * with the same QQmlEngine and the same root context as the amin object, - * that will be the parent of the newly created object - * @param source url where the QML file is located - */ - QObject *createObjectFromSource(const QUrl &source); - -public Q_SLOTS: - /** - * Finishes the process of initialization. - * If isInitializationDelayed() is false, calling this will have no effect. - */ - void completeInitialization(); - -Q_SIGNALS: - /** - * Emitted when the parsing and execution of the QML file is terminated - */ - void finished(); - -private: - friend class QmlObjectPrivate; - QmlObjectPrivate * const d; - - Q_PRIVATE_SLOT(d, void scheduleExecutionEnd()) -}; - - -#endif // multiple inclusion guard diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 8485e47c9..fe9b0ae91 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -46,10 +46,8 @@ #include #include "containmentinterface.h" -#include "configview.h" -#include "containmentconfigview.h" -#include "declarative/configpropertymap.h" -#include "declarative/qmlobject.h" +#include +#include #include "declarative/packageaccessmanagerfactory.h" Q_DECLARE_METATYPE(AppletInterface*) @@ -76,9 +74,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa connect(m_appletScriptEngine, SIGNAL(contextChanged()), this, SIGNAL(contextChanged())); - connect(applet()->actions()->action("configure"), &QAction::triggered, - this, &AppletInterface::configureTriggered); - m_qmlObject = new QmlObject(this); m_qmlObject->setInitializationDelayed(true); @@ -457,7 +452,8 @@ bool AppletInterface::immutable() const bool AppletInterface::userConfiguring() const { - return m_configView.data()->isVisible(); + //FIXME + return false; } int AppletInterface::apiVersion() const @@ -620,37 +616,4 @@ QmlObject *AppletInterface::qmlObject() return m_qmlObject; } -void AppletInterface::configureTriggered() -{ - setConfigurationInterfaceShown(true); -} - -void AppletInterface::setConfigurationInterfaceShown(bool show) -{ - if (!applet()->containment() || !applet()->containment()->corona()) { - return; - } - - if (show) { - if (!m_configView) { - ContainmentInterface *ci = qobject_cast(this); - - if (ci) { - m_configView = new ContainmentConfigView(ci); - } else { - m_configView = new ConfigView(this); - } - m_configView.data()->init(); - } - - m_configView.data()->show(); - - } else { - if (m_configView) { - m_configView.data()->hide(); - m_configView.data()->deleteLater(); - } - } -} - #include "moc_appletinterface.cpp" diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 2a501fc8e..1de9bcd1b 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -231,15 +231,10 @@ Q_SIGNALS: void busyChanged(); void expandedChanged(); -//it's important those slots are private because must not be invokable by qml -private Q_SLOTS: - void configureTriggered(); - protected: virtual void init(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void itemChange(ItemChange change, const ItemChangeData &value); - void setConfigurationInterfaceShown(bool show); DeclarativeAppletScript *m_appletScriptEngine; @@ -255,7 +250,6 @@ private: //UI-specific members ------------------ QmlObject *m_qmlObject; QWeakPointer m_compactUiObject; - QWeakPointer m_configView; QTimer *m_creationTimer; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 4abd100fd..249b1092b 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -21,7 +21,7 @@ #include "containmentinterface.h" #include "wallpaperinterface.h" -#include "declarative/qmlobject.h" +#include #include #include diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index fc3dcbec7..e48e393d4 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -46,9 +46,9 @@ #include "plasmoid/appletinterface.h" #include "plasmoid/containmentinterface.h" -#include "declarative/qmlobject.h" +#include #include "declarative/packageaccessmanagerfactory.h" -#include "declarative/configpropertymap.h" +#include K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScript) diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp index ef1914093..98ba87130 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -20,8 +20,8 @@ #include "wallpaperinterface.h" #include "containmentinterface.h" -#include "declarative/configpropertymap.h" -#include "declarative/qmlobject.h" +#include +#include #include #include diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 1ff12f232..c4529baac 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -56,6 +56,8 @@ set(widgetexplorer_SRC add_executable(plasma-shell main.cpp + configview.cpp + containmentconfigview.cpp desktopcorona.cpp panelview.cpp shellpluginloader.cpp @@ -81,6 +83,7 @@ target_link_libraries(plasma-shell ${KDE4_KDEUI_LIBS} KDE4__kde4support ${Solid_LIBRARIES} + kdeclarative ) message("+++ kde4support : ${kde4support_LIBRARY}") diff --git a/src/scriptengines/qml/plasmoid/configview.cpp b/src/shell/configview.cpp similarity index 87% rename from src/scriptengines/qml/plasmoid/configview.cpp rename to src/shell/configview.cpp index 99e00f912..50f9dbd61 100644 --- a/src/scriptengines/qml/plasmoid/configview.cpp +++ b/src/shell/configview.cpp @@ -18,16 +18,17 @@ */ #include "configview.h" -#include "plasmoid/appletinterface.h" -#include "plasmoid/containmentinterface.h" -#include "plasmoid/wallpaperinterface.h" -#include "declarative/configpropertymap.h" +#include "Plasma/Applet" +#include "Plasma/Containment" +//#include "plasmoid/wallpaperinterface.h" +#include "kdeclarative/configpropertymap.h" #include #include #include #include #include +#include #include #include @@ -146,7 +147,7 @@ QVariant ConfigModel::data(const QModelIndex& index, int role) const return m_categories.at(index.row())->icon(); case SourceRole: if (m_appletInterface) { - return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("ui", m_categories.at(index.row())->source())); + return QUrl::fromLocalFile(m_appletInterface.data()->package().filePath("ui", m_categories.at(index.row())->source())); } else { return m_categories.at(index.row())->source(); } @@ -167,7 +168,7 @@ QVariant ConfigModel::get(int row) const value["name"] = m_categories.at(row)->name(); value["icon"] = m_categories.at(row)->icon(); if (m_appletInterface) { - value["source"] = QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("components", m_categories.at(row)->source())); + value["source"] = QUrl::fromLocalFile(m_appletInterface.data()->package().filePath("components", m_categories.at(row)->source())); } else { value["source"] = m_categories.at(row)->source(); } @@ -193,12 +194,12 @@ void ConfigModel::clear() emit countChanged(); } -void ConfigModel::setAppletInterface(AppletInterface *interface) +void ConfigModel::setApplet(Plasma::Applet *interface) { m_appletInterface = interface; } -AppletInterface *ConfigModel::appletInterface() const +Plasma::Applet *ConfigModel::applet() const { return m_appletInterface.data(); } @@ -259,19 +260,19 @@ void ConfigModel::categories_clear(QQmlListProperty *prop) //////////////////////////////ConfigView -ConfigView::ConfigView(AppletInterface *interface, QWindow *parent) +ConfigView::ConfigView(Plasma::Applet *interface, QWindow *parent) : QQuickView(parent), - m_appletInterface(interface) + m_applet(interface) { qmlRegisterType("org.kde.plasma.configuration", 2, 0, "ConfigModel"); qmlRegisterType("org.kde.plasma.configuration", 2, 0, "ConfigCategory"); //FIXME: problem on nvidia, all windows should be transparent or won't show setColor(Qt::transparent); - setTitle(i18n("%1 Settings", m_appletInterface->applet()->title())); + setTitle(i18n("%1 Settings", m_applet->title())); - if (!m_appletInterface->applet()->containment()->corona()->package().isValid()) { + if (!m_applet->containment()->corona()->package().isValid()) { qWarning() << "Invalid home screen package"; } @@ -279,17 +280,17 @@ ConfigView::ConfigView(AppletInterface *interface, QWindow *parent) //config model local of the applet - QQmlComponent *component = new QQmlComponent(engine(), QUrl::fromLocalFile(m_appletInterface->applet()->package().filePath("configmodel")), this); + QQmlComponent *component = new QQmlComponent(engine(), QUrl::fromLocalFile(m_applet->package().filePath("configmodel")), this); QObject *object = component->create(engine()->rootContext()); m_configModel = qobject_cast(object); if (m_configModel) { - m_configModel->setAppletInterface(m_appletInterface); + m_configModel->setApplet(m_applet); } else { delete object; } delete component; - ContainmentInterface *cont = qobject_cast(m_appletInterface); + Plasma::Containment *cont = qobject_cast(m_applet); engine()->rootContext()->setContextProperty("plasmoid", interface); engine()->rootContext()->setContextProperty("configDialog", this); @@ -301,7 +302,7 @@ ConfigView::~ConfigView() void ConfigView::init() { - setSource(QUrl::fromLocalFile(m_appletInterface->applet()->containment()->corona()->package().filePath("configurationui"))); + setSource(QUrl::fromLocalFile(m_applet->containment()->corona()->package().filePath("appletconfigurationui"))); } ConfigModel *ConfigView::configModel() const diff --git a/src/scriptengines/qml/plasmoid/configview.h b/src/shell/configview.h similarity index 92% rename from src/scriptengines/qml/plasmoid/configview.h rename to src/shell/configview.h index 436763a80..a4c7ffb3c 100644 --- a/src/scriptengines/qml/plasmoid/configview.h +++ b/src/shell/configview.h @@ -26,7 +26,10 @@ #include #include -class AppletInterface; +namespace Plasma { + class Applet; +} + class ConfigPropertyMap; @@ -87,8 +90,8 @@ public: void appendCategory(ConfigCategory *c); void clear(); - void setAppletInterface(AppletInterface *interface); - AppletInterface *appletInterface() const; + void setApplet(Plasma::Applet *interface); + Plasma::Applet *applet() const; int count() {return rowCount();} virtual int rowCount(const QModelIndex &index = QModelIndex()) const; @@ -107,7 +110,7 @@ Q_SIGNALS: private: QListm_categories; - QWeakPointer m_appletInterface; + QWeakPointer m_appletInterface; }; @@ -119,10 +122,10 @@ class ConfigView : public QQuickView Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT) public: - ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0); + ConfigView(Plasma::Applet *applet, QWindow *parent = 0); virtual ~ConfigView(); - void init(); + virtual void init(); ConfigModel *configModel() const; @@ -131,7 +134,7 @@ protected: void resizeEvent(QResizeEvent *re); private: - AppletInterface *m_appletInterface; + Plasma::Applet *m_applet; ConfigModel *m_configModel; }; diff --git a/src/scriptengines/qml/plasmoid/containmentconfigview.cpp b/src/shell/containmentconfigview.cpp similarity index 74% rename from src/scriptengines/qml/plasmoid/containmentconfigview.cpp rename to src/shell/containmentconfigview.cpp index 95c8e6a38..b26a70bfa 100644 --- a/src/scriptengines/qml/plasmoid/containmentconfigview.cpp +++ b/src/shell/containmentconfigview.cpp @@ -18,35 +18,50 @@ */ #include "containmentconfigview.h" -#include "plasmoid/containmentinterface.h" -#include "plasmoid/wallpaperinterface.h" -#include "declarative/configpropertymap.h" +#include +//#include "plasmoid/wallpaperinterface.h" +#include #include #include #include +#include #include +#include #include //////////////////////////////ContainmentConfigView -ContainmentConfigView::ContainmentConfigView(ContainmentInterface *interface, QWindow *parent) - : ConfigView(interface, parent), - m_containmentInterface(interface), +ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent) + : ConfigView(cont, parent), + m_containment(cont), m_wallpaperConfigModel(0), m_currentWallpaperConfig(0) { engine()->rootContext()->setContextProperty("configDialog", this); - setCurrentWallpaper(interface->containment()->wallpaper()); + setCurrentWallpaper(cont->containment()->wallpaper()); + + Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic"); + pkg.setDefaultPackageRoot("plasma/wallpapers"); + pkg.setPath(m_containment->wallpaper()); + QFile file(pkg.filePath("config", "main.xml")); + KConfigGroup cfg = m_containment->config(); + cfg = KConfigGroup(&cfg, "Wallpaper"); + m_currentWallpaperConfig = m_ownWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); } ContainmentConfigView::~ContainmentConfigView() { } +void ContainmentConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_containment->containment()->corona()->package().filePath("containmentconfigurationui"))); +} + ConfigModel *ContainmentConfigView::wallpaperConfigModel() { if (!m_wallpaperConfigModel) { @@ -98,13 +113,11 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) return; } - if (m_containmentInterface->containment()->wallpaper() == wallpaper) { + if (m_containment->wallpaper() == wallpaper) { delete m_currentWallpaperConfig; - if (m_containmentInterface->wallpaperInterface()) { - m_currentWallpaperConfig = m_containmentInterface->wallpaperInterface()->configuration(); - } + m_currentWallpaperConfig = m_ownWallpaperConfig; } else { - if (m_containmentInterface->containment()->wallpaper() != m_currentWallpaper) { + if (m_containment->wallpaper() != m_currentWallpaper) { delete m_currentWallpaperConfig; } @@ -113,7 +126,7 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) pkg.setDefaultPackageRoot("plasma/wallpapers"); pkg.setPath(wallpaper); QFile file(pkg.filePath("config", "main.xml")); - KConfigGroup cfg = m_containmentInterface->containment()->config(); + KConfigGroup cfg = m_containment->config(); cfg = KConfigGroup(&cfg, "Wallpaper"); m_currentWallpaperConfig = new ConfigPropertyMap(new Plasma::ConfigLoader(&cfg, &file), this); } @@ -125,13 +138,14 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) void ContainmentConfigView::applyWallpaper() { - m_containmentInterface->containment()->setWallpaper(m_currentWallpaper); + m_containment->setWallpaper(m_currentWallpaper); - if (m_currentWallpaperConfig != m_containmentInterface->wallpaperInterface()->configuration()) { + if (m_currentWallpaperConfig != m_ownWallpaperConfig) { delete m_currentWallpaperConfig; - m_currentWallpaperConfig = m_containmentInterface->wallpaperInterface()->configuration(); + m_currentWallpaperConfig = m_ownWallpaperConfig; emit wallpaperConfigurationChanged(); } } + #include "moc_containmentconfigview.cpp" diff --git a/src/scriptengines/qml/plasmoid/containmentconfigview.h b/src/shell/containmentconfigview.h similarity index 89% rename from src/scriptengines/qml/plasmoid/containmentconfigview.h rename to src/shell/containmentconfigview.h index 8363c5948..19f719c4a 100644 --- a/src/scriptengines/qml/plasmoid/containmentconfigview.h +++ b/src/shell/containmentconfigview.h @@ -23,7 +23,9 @@ #include "configview.h" -class ContainmentInterface; +namespace Plasma { + class Containment; +} class ConfigPropertyMap; @@ -36,9 +38,11 @@ class ContainmentConfigView : public ConfigView Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) public: - ContainmentConfigView(ContainmentInterface *interface, QWindow *parent = 0); + ContainmentConfigView(Plasma::Containment *interface, QWindow *parent = 0); virtual ~ContainmentConfigView(); + virtual void init(); + ConfigModel *wallpaperConfigModel(); QString currentWallpaper() const; void setCurrentWallpaper(const QString &wallpaper); @@ -51,10 +55,11 @@ Q_SIGNALS: void wallpaperConfigurationChanged(); private: - ContainmentInterface *m_containmentInterface; + Plasma::Containment *m_containment; ConfigModel *m_wallpaperConfigModel; QString m_currentWallpaper; ConfigPropertyMap *m_currentWallpaperConfig; + ConfigPropertyMap *m_ownWallpaperConfig; }; #endif // multiple inclusion guard diff --git a/src/shell/desktopcorona.cpp b/src/shell/desktopcorona.cpp index 0f33b368a..fc04abd1d 100644 --- a/src/shell/desktopcorona.cpp +++ b/src/shell/desktopcorona.cpp @@ -29,6 +29,7 @@ #include #include +#include "containmentconfigview.h" #include "panelview.h" #include "view.h" #include "scripting/desktopscriptengine.h" @@ -266,7 +267,8 @@ void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Conta void DesktopCorona::handleContainmentAdded(Plasma::Containment* c) { - connect(c, &Plasma::Containment::showAddWidgetsInterface, this, &DesktopCorona::showWidgetExplorer); + connect(c, &Plasma::Containment::showAddWidgetsInterface, + this, &DesktopCorona::showWidgetExplorer); } void DesktopCorona::showWidgetExplorer() diff --git a/src/shell/desktopcorona.h b/src/shell/desktopcorona.h index a0a8dcf08..cbdc1a6e8 100644 --- a/src/shell/desktopcorona.h +++ b/src/shell/desktopcorona.h @@ -23,6 +23,8 @@ class * Free Software Foundation, Inc., #include "plasma/corona.h" +#include "configview.h" + class QDesktopWidget; class QQuickView; class PanelView; diff --git a/src/shell/panelconfigview.cpp b/src/shell/panelconfigview.cpp index caf9c641c..eebd11c7d 100644 --- a/src/shell/panelconfigview.cpp +++ b/src/shell/panelconfigview.cpp @@ -36,27 +36,15 @@ //////////////////////////////PanelConfigView PanelConfigView::PanelConfigView(Plasma::Containment *containment, PanelView *panelView, QWindow *parent) - : QQuickView(parent), + : ConfigView(containment, parent), m_containment(containment), m_panelView(panelView) { setFlags(Qt::FramelessWindowHint); - //FIXME: problem on nvidia, all windows should be transparent or won't show - setColor(Qt::transparent); - setTitle(i18n("%1 Settings", m_containment->title())); - - - if (!m_containment->corona()->package().isValid()) { - qWarning() << "Invalid home screen package"; - } - - setResizeMode(QQuickView::SizeViewToRootObject); engine()->rootContext()->setContextProperty("panel", panelView); engine()->rootContext()->setContextProperty("configDialog", this); - setSource(QUrl::fromLocalFile(panelView->corona()->package().filePath("panelconfigurationui"))); - syncGeometry(); connect(containment, &Plasma::Containment::formFactorChanged, this, &PanelConfigView::syncGeometry); } @@ -65,6 +53,12 @@ PanelConfigView::~PanelConfigView() { } +void PanelConfigView::init() +{ + setSource(QUrl::fromLocalFile(m_containment->corona()->package().filePath("panelconfigurationui"))); + syncGeometry(); +} + void PanelConfigView::syncGeometry() { if (!m_containment) { @@ -91,22 +85,5 @@ void PanelConfigView::syncGeometry() } } -//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have -void PanelConfigView::hideEvent(QHideEvent *ev) -{ - QQuickWindow::hideEvent(ev); - deleteLater(); -} - -void PanelConfigView::resizeEvent(QResizeEvent *re) -{ - if (!rootObject()) { - return; - } - rootObject()->setWidth(re->size().width()); - rootObject()->setHeight(re->size().height()); - QQuickWindow::resizeEvent(re); -} - #include "moc_panelconfigview.cpp" diff --git a/src/shell/panelconfigview.h b/src/shell/panelconfigview.h index b215f435f..ce7b56948 100644 --- a/src/shell/panelconfigview.h +++ b/src/shell/panelconfigview.h @@ -20,6 +20,8 @@ #ifndef PANELCONFIGVIEW_H #define PANELCONFIGVIEW_H +#include "configview.h" + #include #include #include @@ -36,7 +38,7 @@ namespace Plasma { //TODO: this should be a subclass of ConfigView currently in the scriptengine //TODO: that class should be moved here -class PanelConfigView : public QQuickView +class PanelConfigView : public ConfigView { Q_OBJECT @@ -44,13 +46,11 @@ public: PanelConfigView(Plasma::Containment *interface, PanelView *panelView, QWindow *parent = 0); virtual ~PanelConfigView(); + void init(); + protected Q_SLOTS: void syncGeometry(); -protected: - void hideEvent(QHideEvent *ev); - void resizeEvent(QResizeEvent *re); - private: Plasma::Containment *m_containment; PanelView *m_panelView; diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index c408b922f..c4e33da89 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -167,6 +167,7 @@ void PanelView::showPanelController() { if (!m_panelConfigView) { m_panelConfigView = new PanelConfigView(containment(), this); + m_panelConfigView->init(); } m_panelConfigView->show(); } diff --git a/src/shell/qmlpackages/desktop/contents/components/Configuration.qml b/src/shell/qmlpackages/desktop/contents/components/AppletConfiguration.qml similarity index 94% rename from src/shell/qmlpackages/desktop/contents/components/Configuration.qml rename to src/shell/qmlpackages/desktop/contents/components/AppletConfiguration.qml index bfd68f1a6..0bab3fa70 100644 --- a/src/shell/qmlpackages/desktop/contents/components/Configuration.qml +++ b/src/shell/qmlpackages/desktop/contents/components/AppletConfiguration.qml @@ -36,7 +36,8 @@ Rectangle { //END properties //BEGIN model - property ConfigModel globalConfigModel: plasmoid.containmentType !== undefined ? globalContainmentConfigModel : globalAppletConfigModel + property ConfigModel globalConfigModel: globalAppletConfigModel + ConfigModel { id: globalAppletConfigModel ConfigCategory { @@ -45,19 +46,6 @@ Rectangle { source: "ConfigurationShortcuts.qml" } } - ConfigModel { - id: globalContainmentConfigModel - ConfigCategory { - name: "Appearance" - icon: "preferences-desktop-wallpaper" - source: "ConfigurationContainmentAppearance.qml" - } - ConfigCategory { - name: "Mouse Actions" - icon: "preferences-desktop-mouse" - source: "ConfigurationContainmentActions.qml" - } - } //END model //BEGIN functions diff --git a/src/shell/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml b/src/shell/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml new file mode 100644 index 000000000..c500657b0 --- /dev/null +++ b/src/shell/qmlpackages/desktop/contents/components/ContainmentConfiguration.qml @@ -0,0 +1,47 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. + */ + +import QtQuick 2.0 +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.configuration 2.0 + + +AppletConfiguration { + id: root + +//BEGIN model + globalConfigModel: globalContainmentConfigModel + + ConfigModel { + id: globalContainmentConfigModel + ConfigCategory { + name: "Appearance" + icon: "preferences-desktop-wallpaper" + source: "ConfigurationContainmentAppearance.qml" + } + ConfigCategory { + name: "Mouse Actions" + icon: "preferences-desktop-mouse" + source: "ConfigurationContainmentActions.qml" + } + } +//END model + +} diff --git a/src/shell/shellpackage.cpp b/src/shell/shellpackage.cpp index 3d9c6e5c7..623021649 100644 --- a/src/shell/shellpackage.cpp +++ b/src/shell/shellpackage.cpp @@ -45,7 +45,8 @@ void ShellPackageStructure::initPackage(Plasma::Package *package) package->addFileDefinition("appleterror", "components/AppletError.qml", i18n("Error message shown when an applet fails to load")); package->addFileDefinition("compactapplet", "components/CompactApplet.qml", i18n("QML component that shows an applet in a popup")); - package->addFileDefinition("configurationui", "components/Configuration.qml", i18n("QML component for the configuration dialog")); + package->addFileDefinition("appletconfigurationui", "components/AppletConfiguration.qml", i18n("QML component for the configuration dialog for applets")); + package->addFileDefinition("containmentconfigurationui", "components/ContainmentConfiguration.qml", i18n("QML component for the configuration dialog for containments")); package->addFileDefinition("defaultcompactrepresentation", "components/DefaultCompactRepresentation.qml", i18n("Compact representation of an applet when collapsed in a popup, for instance as an icon. applets can override this component.")); package->addFileDefinition("widgetexplorer", "explorer/WidgetExplorer.qml", i18n("Widgets explorer UI")); package->addFileDefinition("panelconfigurationui", "components/PanelConfiguration.qml", i18n("Panel configuration UI")); diff --git a/src/shell/view.cpp b/src/shell/view.cpp index 81e359d45..2e48be3ba 100644 --- a/src/shell/view.cpp +++ b/src/shell/view.cpp @@ -17,6 +17,10 @@ */ #include "view.h" +#include "containmentconfigview.h" +#include "panelconfigview.h" +#include "panelview.h" + #include #include @@ -99,6 +103,8 @@ void View::setContainment(Plasma::Containment *cont) this, &View::locationChanged); connect(cont, &Plasma::Containment::formFactorChanged, this, &View::formFactorChanged); + connect(cont, &Plasma::Containment::configureRequested, + this, &View::showConfigurationInterface); } else { return; } @@ -152,4 +158,30 @@ QRectF View::screenGeometry() return screen()->geometry(); } +void View::showConfigurationInterface(Plasma::Applet *applet) +{ + if (m_configView) { + m_configView.data()->hide(); + m_configView.data()->deleteLater(); + } + + if (!applet || !applet->containment()) { + return; + } + + Plasma::Containment *cont = qobject_cast(applet); + PanelView *pv = qobject_cast< PanelView* >(this); + + if (cont && pv) { + m_configView = new PanelConfigView(cont, pv); + } else if (cont) { + m_configView = new ContainmentConfigView(cont); + } else { + m_configView = new ConfigView(applet); + } + m_configView.data()->init(); + + m_configView.data()->show(); +} + #include "moc_view.cpp" diff --git a/src/shell/view.h b/src/shell/view.h index d01a889e7..ff859ee89 100644 --- a/src/shell/view.h +++ b/src/shell/view.h @@ -25,6 +25,7 @@ #include "plasma/corona.h" #include "plasma/containment.h" +#include "configview.h" class View : public QQuickView { @@ -54,6 +55,9 @@ public: QRectF screenGeometry(); +protected Q_SLOTS: + void showConfigurationInterface(Plasma::Applet *applet); + Q_SIGNALS: void locationChanged(Plasma::Location location); void formFactorChanged(Plasma::FormFactor formFactor); @@ -63,6 +67,7 @@ Q_SIGNALS: private: Plasma::Corona *m_corona; QWeakPointer m_containment; + QWeakPointer m_configView; }; #endif // VIEW_H