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: public Q_SLOTS:
//BOOKKEEPING //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, * Sets the immutability type for this applet (not immutable,
* user immutable or system immutable) * user immutable or system immutable)
@ -488,22 +503,6 @@ class PLASMA_EXPORT Applet : public QObject
*/ */
Applet(QObject *parent, const QVariantList &args); 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 //CONFIGURATION
/** /**
* When called, the Applet should write any information needed as part * When called, the Applet should write any information needed as part

View File

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

View File

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

View File

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

View File

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