Changeset View
Changeset View
Standalone View
Standalone View
src/quickaddons/configmodule.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 48 | public: | |||
---|---|---|---|---|---|
60 | void authStatusChanged(int status); | 60 | void authStatusChanged(int status); | ||
61 | 61 | | |||
62 | ConfigModule *_q; | 62 | ConfigModule *_q; | ||
63 | KDeclarative::QmlObject *_qmlObject; | 63 | KDeclarative::QmlObject *_qmlObject; | ||
64 | ConfigModule::Buttons _buttons; | 64 | ConfigModule::Buttons _buttons; | ||
65 | const KAboutData *_about; | 65 | const KAboutData *_about; | ||
66 | QString _rootOnlyMessage; | 66 | QString _rootOnlyMessage; | ||
67 | QString _quickHelp; | 67 | QString _quickHelp; | ||
68 | QString _errorString; | ||||
68 | QList<QQuickItem *> subPages; | 69 | QList<QQuickItem *> subPages; | ||
69 | int _columnWidth = -1; | 70 | int _columnWidth = -1; | ||
70 | int currentIndex = 0; | 71 | int currentIndex = 0; | ||
71 | bool _useRootOnlyMessage : 1; | 72 | bool _useRootOnlyMessage : 1; | ||
72 | 73 | | |||
73 | bool _needsAuthorization : 1; | 74 | bool _needsAuthorization : 1; | ||
74 | bool _needsSave :1; | 75 | bool _needsSave :1; | ||
75 | QString _authActionName; | 76 | QString _authActionName; | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
140 | } | 141 | } | ||
141 | 142 | | |||
142 | QQuickItem *ConfigModule::mainUi() | 143 | QQuickItem *ConfigModule::mainUi() | ||
143 | { | 144 | { | ||
144 | if (d->_qmlObject) { | 145 | if (d->_qmlObject) { | ||
145 | return qobject_cast<QQuickItem *>(d->_qmlObject->rootObject()); | 146 | return qobject_cast<QQuickItem *>(d->_qmlObject->rootObject()); | ||
146 | } | 147 | } | ||
147 | 148 | | |||
149 | d->_errorString.clear(); | ||||
150 | | ||||
148 | // if we have a qml context, hook up to it and use its engine | 151 | // if we have a qml context, hook up to it and use its engine | ||
149 | // this ensure that in e.g. Plasma config dialogs that use a different engine | 152 | // this ensure that in e.g. Plasma config dialogs that use a different engine | ||
150 | // so they can have different QtQuick Controls styles, we don't end up using | 153 | // so they can have different QtQuick Controls styles, we don't end up using | ||
151 | // the shared engine that is used by the rest of plasma | 154 | // the shared engine that is used by the rest of plasma | ||
152 | 155 | | |||
153 | QQmlContext *ctx = QQmlEngine::contextForObject(this); | 156 | QQmlContext *ctx = QQmlEngine::contextForObject(this); | ||
154 | 157 | | |||
155 | if (ctx && ctx->engine()) { | 158 | if (ctx && ctx->engine()) { | ||
156 | d->_qmlObject = new KDeclarative::QmlObject(ctx->engine(), ctx, this); | 159 | d->_qmlObject = new KDeclarative::QmlObject(ctx->engine(), ctx, this); | ||
157 | } else { | 160 | } else { | ||
158 | d->_qmlObject = new KDeclarative::QmlObjectSharedEngine(this); | 161 | d->_qmlObject = new KDeclarative::QmlObjectSharedEngine(this); | ||
159 | } | 162 | } | ||
160 | 163 | | |||
161 | ConfigModulePrivate::s_rootObjects[d->_qmlObject->rootContext()] = this; | 164 | ConfigModulePrivate::s_rootObjects[d->_qmlObject->rootContext()] = this; | ||
162 | d->_qmlObject->setTranslationDomain(aboutData()->componentName()); | 165 | d->_qmlObject->setTranslationDomain(aboutData()->componentName()); | ||
163 | d->_qmlObject->setInitializationDelayed(true); | 166 | d->_qmlObject->setInitializationDelayed(true); | ||
164 | 167 | | |||
165 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML")); | 168 | KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("KPackage/GenericQML")); | ||
166 | package.setDefaultPackageRoot(QStringLiteral("kpackage/kcms")); | 169 | package.setDefaultPackageRoot(QStringLiteral("kpackage/kcms")); | ||
167 | package.setPath(aboutData()->componentName()); | 170 | package.setPath(aboutData()->componentName()); | ||
168 | 171 | | |||
169 | if (!package.isValid()) { | 172 | if (!package.isValid()) { | ||
173 | d->_errorString = i18n("Invalid KPackage"); | ||||
170 | qWarning() << "Error loading the module" << aboutData()->componentName() << ": invalid KPackage"; | 174 | qWarning() << "Error loading the module" << aboutData()->componentName() << ": invalid KPackage"; | ||
171 | return nullptr; | 175 | return nullptr; | ||
172 | } | 176 | } | ||
173 | 177 | | |||
174 | if (!package.filePath("mainscript").isEmpty()) { | 178 | if (package.filePath("mainscript").isEmpty()) { | ||
179 | d->_errorString = i18n("No QML file provided"); | ||||
180 | qWarning() << "Error loading the module" << aboutData()->componentName() << ": no QML file provided"; | ||||
181 | return nullptr; | ||||
182 | } | ||||
183 | | ||||
175 | d->_qmlObject->setSource(package.fileUrl("mainscript")); | 184 | d->_qmlObject->setSource(package.fileUrl("mainscript")); | ||
176 | d->_qmlObject->rootContext()->setContextProperty(QStringLiteral("kcm"), this); | 185 | d->_qmlObject->rootContext()->setContextProperty(QStringLiteral("kcm"), this); | ||
177 | d->_qmlObject->completeInitialization(); | 186 | d->_qmlObject->completeInitialization(); | ||
178 | 187 | | |||
179 | return qobject_cast<QQuickItem *>(d->_qmlObject->rootObject()); | 188 | if (d->_qmlObject->status() != QQmlComponent::Ready) { | ||
180 | } else { | 189 | d->_errorString = d->_qmlObject->mainComponent()->errorString(); | ||
181 | qWarning() << "Error loading the module" << aboutData()->componentName() << ": no QML file provided"; | | |||
182 | return nullptr; | 190 | return nullptr; | ||
183 | } | 191 | } | ||
192 | | ||||
193 | return qobject_cast<QQuickItem *>(d->_qmlObject->rootObject()); | ||||
184 | } | 194 | } | ||
185 | 195 | | |||
186 | void ConfigModule::push(const QString &fileName, const QVariantMap &propertyMap) | 196 | void ConfigModule::push(const QString &fileName, const QVariantMap &propertyMap) | ||
187 | { | 197 | { | ||
188 | //ensure main ui is created | 198 | //ensure main ui is created | ||
189 | if (!mainUi()) { | 199 | if (!mainUi()) { | ||
190 | return; | 200 | return; | ||
191 | } | 201 | } | ||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Line(s) | 354 | { | |||
345 | return d->_authActionName; | 355 | return d->_authActionName; | ||
346 | } | 356 | } | ||
347 | 357 | | |||
348 | QQmlEngine *ConfigModule::engine() const | 358 | QQmlEngine *ConfigModule::engine() const | ||
349 | { | 359 | { | ||
350 | return d->_qmlObject->engine(); | 360 | return d->_qmlObject->engine(); | ||
351 | } | 361 | } | ||
352 | 362 | | |||
363 | QQmlComponent::Status ConfigModule::status() const | ||||
364 | { | ||||
365 | if (!d->_qmlObject) { | ||||
366 | return QQmlComponent::Null; | ||||
367 | } | ||||
368 | | ||||
369 | return d->_qmlObject->status(); | ||||
370 | } | ||||
371 | | ||||
372 | QString ConfigModule::errorString() const | ||||
373 | { | ||||
374 | return d->_errorString; | ||||
375 | } | ||||
376 | | ||||
353 | void ConfigModule::load() | 377 | void ConfigModule::load() | ||
354 | { | 378 | { | ||
355 | setNeedsSave(false); | 379 | setNeedsSave(false); | ||
356 | } | 380 | } | ||
357 | 381 | | |||
358 | void ConfigModule::save() | 382 | void ConfigModule::save() | ||
359 | { | 383 | { | ||
360 | setNeedsSave(false); | 384 | setNeedsSave(false); | ||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |