appletLoader doesn't depend from Declarativeappletscript

This commit is contained in:
Marco Martin 2014-02-05 12:51:31 +01:00
parent e2ee69bf08
commit 3325f24992
6 changed files with 52 additions and 47 deletions

View File

@ -415,6 +415,21 @@ class PLASMA_EXPORT Applet : public QObject
public Q_SLOTS:
//BOOKKEEPING
/**
* Call this method when the applet fails to launch properly. An
* optional reason can be provided.
*
* Not that all children items will be deleted when this method is
* called. If you have pointers to these items, you will need to
* reset them after calling this method.
*
* @param failed true when the applet failed, false when it succeeded
* @param reason an optional reason to show the user why the applet
* failed to launch
* @since 5.0
**/
void setLaunchErrorMessage(const QString &reason = QString());
/**
* Sets the immutability type for this applet (not immutable,
* user immutable or system immutable)
@ -488,22 +503,6 @@ class PLASMA_EXPORT Applet : public QObject
*/
Applet(QObject *parent, const QVariantList &args);
//BOOKEEPING
/**
* Call this method when the applet fails to launch properly. An
* optional reason can be provided.
*
* Not that all children items will be deleted when this method is
* called. If you have pointers to these items, you will need to
* reset them after calling this method.
*
* @param failed true when the applet failed, false when it succeeded
* @param reason an optional reason to show the user why the applet
* failed to launch
* @since 5.0
**/
void setLaunchErrorMessage(const QString &reason = QString());
//CONFIGURATION
/**
* When called, the Applet should write any information needed as part

View File

@ -53,8 +53,9 @@
Q_DECLARE_METATYPE(AppletInterface*)
AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *parent)
: AppletLoader(script, parent),
: AppletLoader(script->applet(), parent),
m_actionSignals(0),
m_appletScriptEngine(script),
m_backgroundHints(Plasma::Types::StandardBackground),
m_busy(false),
m_hideOnDeactivate(true)
@ -82,14 +83,17 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, QQuickItem *pa
connect(applet()->containment(), &Plasma::Containment::screenChanged,
this, &ContainmentInterface::screenChanged);
}
setProperty("_plasma_applet", QVariant::fromValue(applet()));
}
AppletInterface::~AppletInterface()
{
}
DeclarativeAppletScript *AppletInterface::appletScript() const
{
return m_appletScriptEngine;
}
void AppletInterface::init()
{
if (qmlObject()->rootObject() && m_configuration) {

View File

@ -154,12 +154,12 @@ public:
//API not intended for the QML part
DeclarativeAppletScript *appletScript() const;
QList<QAction*> contextualActions() const;
void executeAction(const QString &name);
Plasma::Applet *applet() const { return appletScript()->applet(); }
//QML API-------------------------------------------------------------------
/**
@ -302,6 +302,7 @@ private:
KDeclarative::ConfigPropertyMap *m_configuration;
DeclarativeAppletScript *m_appletScriptEngine;
//UI-specific members ------------------

View File

@ -32,7 +32,6 @@
#include <Plasma/Applet>
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/Package>
#include <kdeclarative/qmlobject.h>
#include <plasma/scripting/appletscript.h>
@ -40,16 +39,16 @@
QHash<QObject *, AppletLoader *> AppletLoader::s_rootObjects = QHash<QObject *, AppletLoader *>();
AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
AppletLoader::AppletLoader(Plasma::Applet *applet, QQuickItem *parent)
: QQuickItem(parent),
m_switchWidth(-1),
m_switchHeight(-1),
m_appletScriptEngine(script),
m_applet(applet),
m_expanded(false)
{
m_appletPackage = m_appletScriptEngine->package();
if (m_appletScriptEngine->applet() && m_appletScriptEngine->applet()->containment() && m_appletScriptEngine->applet()->containment()->corona()) {
m_coronaPackage = m_appletScriptEngine->applet()->containment()->corona()->package();
m_appletPackage = m_applet->package();
if (m_applet && m_applet->containment() && m_applet->containment()->corona()) {
m_coronaPackage = m_applet->containment()->corona()->package();
}
m_compactRepresentationCheckTimer.setSingleShot(true);
@ -62,7 +61,7 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
m_fullRepresentationResizeTimer.setInterval(250);
connect (&m_fullRepresentationResizeTimer, &QTimer::timeout,
[=]() {
KConfigGroup cg = m_appletScriptEngine->applet()->config();
KConfigGroup cg = m_applet->config();
cg = KConfigGroup(&cg, "PopupApplet");
cg.writeEntry("DialogWidth", m_fullRepresentationItem.data()->property("width").toInt());
cg.writeEntry("DialogHeight", m_fullRepresentationItem.data()->property("height").toInt());
@ -73,6 +72,10 @@ AppletLoader::AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent)
m_qmlObject = new KDeclarative::QmlObject(this);
m_qmlObject->setInitializationDelayed(true);
// set the graphicObject dynamic property on applet
m_applet->setProperty("graphicObject", QVariant::fromValue(this));
setProperty("_plasma_applet", QVariant::fromValue(applet));
}
AppletLoader::~AppletLoader()
@ -85,6 +88,11 @@ AppletLoader::~AppletLoader()
s_rootObjects.remove(m_qmlObject->engine());
}
Plasma::Applet *AppletLoader::applet() const
{
return m_applet;
}
void AppletLoader::init()
{
if (s_rootObjects.contains(this)) {
@ -93,16 +101,16 @@ void AppletLoader::init()
s_rootObjects[m_qmlObject->engine()] = this;
Q_ASSERT(m_appletScriptEngine);
Q_ASSERT(m_applet);
//Initialize the main QML file
QQmlEngine *engine = m_qmlObject->engine();
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, appletScript()->package());
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, m_applet->package());
interceptor->addAllowedPath(m_coronaPackage.path());
engine->setUrlInterceptor(interceptor);
m_qmlObject->setSource(QUrl::fromLocalFile(m_appletScriptEngine->mainScript()));
m_qmlObject->setSource(QUrl::fromLocalFile(m_applet->package().filePath("mainscript")));
if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || m_qmlObject->mainComponent()->isError()) {
QString reason;
@ -122,7 +130,7 @@ void AppletLoader::init()
m_qmlObject->rootObject()->setProperty("reason", reason);
}
appletScript()->setLaunchErrorMessage(reason);
m_applet->setLaunchErrorMessage(reason);
}
engine->rootContext()->setContextProperty("plasmoid", this);
@ -156,11 +164,6 @@ void AppletLoader::init()
}
DeclarativeAppletScript *AppletLoader::appletScript() const
{
return m_appletScriptEngine;
}
int AppletLoader::switchWidth() const
{
return m_switchWidth;
@ -259,7 +262,7 @@ bool AppletLoader::isExpanded() const
void AppletLoader::setExpanded(bool expanded)
{
if (m_appletScriptEngine->applet()->isContainment()) {
if (m_applet->isContainment()) {
expanded = true;
}
@ -506,7 +509,7 @@ void AppletLoader::compactRepresentationCheck()
bool full = false;
if (m_appletScriptEngine->applet()->isContainment()) {
if (m_applet->isContainment()) {
full = true;
} else {
@ -519,7 +522,7 @@ void AppletLoader::compactRepresentationCheck()
full = m_preferredRepresentation.data() == m_fullRepresentation.data();
//Otherwise, base on FormFactor
} else {
full = (m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Horizontal && m_appletScriptEngine->applet()->formFactor() != Plasma::Types::Vertical);
full = (m_applet->formFactor() != Plasma::Types::Horizontal && m_applet->formFactor() != Plasma::Types::Vertical);
}
}

View File

@ -23,15 +23,15 @@
#include <QQuickItem>
#include <QWeakPointer>
#include <QQmlComponent>
#include <QQmlEngine>
#include <QTimer>
#include "declarativeappletscript.h"
#include <Plasma/Package>
class QQmlComponent;
namespace Plasma {
class Applet;
class AppletScript;
}
namespace KDeclarative {
@ -68,10 +68,10 @@ class AppletLoader : public QQuickItem
Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
public:
AppletLoader(DeclarativeAppletScript *script, QQuickItem *parent = 0);
AppletLoader(Plasma::Applet *applet, QQuickItem *parent = 0);
~AppletLoader();
DeclarativeAppletScript *appletScript() const;
Plasma::Applet *applet() const;
int switchWidth() const;
void setSwitchWidth(int width);
@ -177,7 +177,7 @@ private:
QTimer m_compactRepresentationCheckTimer;
QTimer m_fullRepresentationResizeTimer;
DeclarativeAppletScript *m_appletScriptEngine;
Plasma::Applet *m_applet;
KDeclarative::QmlObject *m_qmlObject;
Plasma::Package m_appletPackage;

View File

@ -93,8 +93,6 @@ bool DeclarativeAppletScript::init()
}
m_interface->setParent(this);
// set the graphicObject dynamic property on applet
a->setProperty("graphicObject", QVariant::fromValue(m_interface));
return true;
}