Changeset View
Changeset View
Standalone View
Standalone View
src/plasmaquick/appletquickitem.cpp
Show First 20 Lines • Show All 487 Lines • ▼ Show 20 Line(s) | 482 | { | |||
---|---|---|---|---|---|
488 | AppletQuickItemPrivate::s_rootObjects[d->qmlObject->rootContext()] = this; | 488 | AppletQuickItemPrivate::s_rootObjects[d->qmlObject->rootContext()] = this; | ||
489 | 489 | | |||
490 | Q_ASSERT(d->applet); | 490 | Q_ASSERT(d->applet); | ||
491 | 491 | | |||
492 | //Initialize the main QML file | 492 | //Initialize the main QML file | ||
493 | QQmlEngine *engine = d->qmlObject->engine(); | 493 | QQmlEngine *engine = d->qmlObject->engine(); | ||
494 | 494 | | |||
495 | //if the engine of the qmlObject is different from the static one, then we | 495 | //if the engine of the qmlObject is different from the static one, then we | ||
496 | //are using an old version of the api in which every applet had one engine | 496 | //are using an old version of the api in which every applet had one engine | ||
davidedmundson: if you were to do this:
just do c = new QQmlComponent(qApp);
and you have the cleanup done for… | |||||
497 | //so initialize a private url interceptor | 497 | //so initialize a private url interceptor | ||
498 | if (d->applet->kPackage().isValid() && !qobject_cast<KDeclarative::QmlObjectSharedEngine *>(d->qmlObject)) { | 498 | if (d->applet->kPackage().isValid() && !qobject_cast<KDeclarative::QmlObjectSharedEngine *>(d->qmlObject)) { | ||
499 | PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->kPackage()); | 499 | PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine, d->applet->kPackage()); | ||
500 | interceptor->addAllowedPath(d->coronaPackage.path()); | 500 | interceptor->addAllowedPath(d->coronaPackage.path()); | ||
501 | engine->setUrlInterceptor(interceptor); | 501 | engine->setUrlInterceptor(interceptor); | ||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | //Force QtQuickControls to use the "Plasma" style for this engine. | 504 | //Force QtQuickControls to use the "Plasma" style for this engine. | ||
505 | //this way is possible to mix QtQuickControls and plasma components in applets | 505 | //this way is possible to mix QtQuickControls and plasma components in applets | ||
506 | //while still having the desktop style in configuration dialogs | 506 | //while still having the desktop style in configuration dialogs | ||
507 | if (!engine->property("_plasma_qqc_style_set").toBool()) { | ||||
507 | QQmlComponent c(engine); | 508 | QQmlComponent c(engine); | ||
508 | c.setData(QByteArrayLiteral("import QtQuick 2.1\n\ | 509 | c.setData(QByteArrayLiteral("import QtQuick 2.1\n\ | ||
509 | import QtQuick.Controls 1.0\n\ | 510 | import QtQuick.Controls 1.0\n\ | ||
510 | import QtQuick.Controls.Private 1.0\n \ | 511 | import QtQuick.Controls.Private 1.0\n \ | ||
511 | Item {\ | 512 | QtObject {\ | ||
512 | Component.onCompleted: {\ | 513 | Component.onCompleted: {\ | ||
513 | Settings.styleName = \"Plasma\";\ | 514 | Settings.styleName = \"Plasma\";\ | ||
514 | }\ | 515 | }\ | ||
515 | }"), QUrl()); | 516 | }"), QUrl()); | ||
516 | QObject *o = c.create(); | 517 | QObject *o = c.create(); | ||
517 | o->deleteLater(); | 518 | o->deleteLater(); | ||
519 | engine->setProperty(("_plasma_qqc_style_set"), true); | ||||
520 | } | ||||
518 | 521 | | |||
519 | d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->kPackage().filePath("mainscript"))); | 522 | d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->kPackage().filePath("mainscript"))); | ||
520 | 523 | | |||
521 | if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || !d->qmlObject->mainComponent() || d->qmlObject->mainComponent()->isError() || d->applet->failedToLaunch()) { | 524 | if (!engine || !engine->rootContext() || !engine->rootContext()->isValid() || !d->qmlObject->mainComponent() || d->qmlObject->mainComponent()->isError() || d->applet->failedToLaunch()) { | ||
522 | QString reason; | 525 | QString reason; | ||
523 | if (d->applet->failedToLaunch()) { | 526 | if (d->applet->failedToLaunch()) { | ||
524 | reason = d->applet->launchErrorMessage(); | 527 | reason = d->applet->launchErrorMessage(); | ||
525 | } else if (d->applet->kPackage().isValid()) { | 528 | } else if (d->applet->kPackage().isValid()) { | ||
▲ Show 20 Lines • Show All 293 Lines • Show Last 20 Lines |
if you were to do this:
just do c = new QQmlComponent(qApp);
and you have the cleanup done for you.