toolbox works again, simplify creation
This commit is contained in:
parent
21d96f9dbf
commit
b6ae310780
@ -57,7 +57,6 @@ K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScr
|
|||||||
DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args)
|
DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args)
|
||||||
: Plasma::AppletScript(parent),
|
: Plasma::AppletScript(parent),
|
||||||
m_qmlObject(0),
|
m_qmlObject(0),
|
||||||
m_toolBoxObject(0),
|
|
||||||
m_interface(0),
|
m_interface(0),
|
||||||
m_env(0)
|
m_env(0)
|
||||||
{
|
{
|
||||||
@ -73,7 +72,6 @@ bool DeclarativeAppletScript::init()
|
|||||||
{
|
{
|
||||||
m_qmlObject = new QmlObject(applet());
|
m_qmlObject = new QmlObject(applet());
|
||||||
m_qmlObject->setInitializationDelayed(true);
|
m_qmlObject->setInitializationDelayed(true);
|
||||||
connect(m_qmlObject, SIGNAL(finished()), this, SLOT(qmlCreationFinished()));
|
|
||||||
//FIXME: what replaced this?
|
//FIXME: what replaced this?
|
||||||
//KGlobal::locale()->insertCatalog("plasma_applet_" % description().pluginName());
|
//KGlobal::locale()->insertCatalog("plasma_applet_" % description().pluginName());
|
||||||
|
|
||||||
@ -138,65 +136,36 @@ bool DeclarativeAppletScript::init()
|
|||||||
a->setProperty("graphicObject", QVariant::fromValue(m_interface));
|
a->setProperty("graphicObject", QVariant::fromValue(m_interface));
|
||||||
qDebug() << "Graphic object created:" << a << a->property("graphicObject");
|
qDebug() << "Graphic object created:" << a << a->property("graphicObject");
|
||||||
|
|
||||||
return true;
|
//Is this a containment?
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeAppletScript::qmlCreationFinished()
|
|
||||||
{
|
|
||||||
//If it's a popupapplet and the root object has a "compactRepresentation" component, use that instead of the icon
|
|
||||||
Plasma::Applet *a = applet();
|
|
||||||
|
|
||||||
//TODO: access rootItem from m_interface
|
|
||||||
//m_self->setProperty("rootItem", QVariant::fromValue(m_qmlObject->rootObject()));
|
|
||||||
|
|
||||||
/*TODO: all applets must become pa
|
|
||||||
if (pa) {
|
|
||||||
QQmlComponent *iconComponent = m_qmlObject->rootObject()->property("compactRepresentation").value<QQmlComponent *>();
|
|
||||||
if (iconComponent) {
|
|
||||||
QDeclarativeItem *declarativeIcon = qobject_cast<QDeclarativeItem *>(iconComponent->create(iconComponent->creationContext()));
|
|
||||||
if (declarativeIcon) {
|
|
||||||
pa->setPopupIcon(QIcon());
|
|
||||||
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(a);
|
|
||||||
lay->setContentsMargins(0, 0, 0, 0);
|
|
||||||
DeclarativeItemContainer *declarativeItemContainer = new DeclarativeItemContainer(a);
|
|
||||||
lay->addItem(declarativeItemContainer);
|
|
||||||
declarativeItemContainer->setDeclarativeItem(declarativeIcon, true);
|
|
||||||
} else {
|
|
||||||
pa->setPopupIcon(a->icon());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pa->setPopupIcon(a->icon());
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Plasma::Containment *pc = qobject_cast<Plasma::Containment *>(a);
|
Plasma::Containment *pc = qobject_cast<Plasma::Containment *>(a);
|
||||||
|
|
||||||
if (pc) {
|
if (pc) {
|
||||||
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
Plasma::Package pkg = Plasma::PluginLoader::self()->loadPackage("Plasma/Generic");
|
||||||
pkg.setPath("org.kde.toolbox");
|
pkg.setPath("org.kde.toolbox");
|
||||||
|
|
||||||
if (pkg.isValid()) {
|
if (pkg.isValid()) {
|
||||||
const QString qmlPath = pkg.filePath("mainscript");
|
QQmlComponent *toolBoxComponent = new QQmlComponent(m_qmlObject->engine(), this);
|
||||||
|
toolBoxComponent->loadUrl(QUrl::fromLocalFile(pkg.filePath("mainscript")));
|
||||||
|
QObject *toolBoxObject = toolBoxComponent->create(engine->rootContext());
|
||||||
|
|
||||||
m_toolBoxObject = new QmlObject(pc);
|
QObject *containmentGraphicObject = m_interface->uiObject();
|
||||||
m_toolBoxObject->setInitializationDelayed(true);
|
|
||||||
m_toolBoxObject->setQmlPath(qmlPath);
|
|
||||||
|
|
||||||
if (m_toolBoxObject->rootObject()) {
|
if (containmentGraphicObject && toolBoxObject) {
|
||||||
m_toolBoxObject->rootObject()->setProperty("plasmoid", QVariant::fromValue(m_interface));
|
//memory management
|
||||||
}
|
toolBoxComponent->setParent(toolBoxObject);
|
||||||
|
toolBoxObject->setProperty("parent", QVariant::fromValue(containmentGraphicObject));
|
||||||
|
|
||||||
m_toolBoxObject->completeInitialization();
|
containmentGraphicObject->setProperty("toolBox", QVariant::fromValue(toolBoxObject));
|
||||||
|
} else {
|
||||||
QObject *containmentGraphicObject = pc->property("graphicObject").value<QObject *>();
|
delete toolBoxComponent;
|
||||||
|
delete toolBoxObject;
|
||||||
if (containmentGraphicObject && m_toolBoxObject->rootObject()) {
|
|
||||||
m_toolBoxObject->rootObject()->setProperty("parent", QVariant::fromValue(containmentGraphicObject));
|
|
||||||
|
|
||||||
containmentGraphicObject->setProperty("toolBox", QVariant::fromValue(m_toolBoxObject->rootObject()));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
kWarning() << "Could not load org.kde.toolbox package.";
|
kWarning() << "Could not load org.kde.toolbox package.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return !a->failedToLaunch();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeclarativeAppletScript::filePath(const QString &type, const QString &file) const
|
QString DeclarativeAppletScript::filePath(const QString &type, const QString &file) const
|
||||||
|
@ -59,7 +59,6 @@ public Q_SLOTS:
|
|||||||
void executeAction(const QString &name);
|
void executeAction(const QString &name);
|
||||||
void activate();
|
void activate();
|
||||||
void configChanged();
|
void configChanged();
|
||||||
void qmlCreationFinished();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool init();
|
bool init();
|
||||||
@ -72,7 +71,6 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QmlObject *m_qmlObject;
|
QmlObject *m_qmlObject;
|
||||||
QmlObject *m_toolBoxObject;
|
|
||||||
AppletInterface *m_interface;
|
AppletInterface *m_interface;
|
||||||
ScriptEnv *m_env;
|
ScriptEnv *m_env;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user