Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/appletinterface.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
49 | AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariantList &args, QQuickItem *parent) | 49 | AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariantList &args, QQuickItem *parent) | ||
50 | : AppletQuickItem(script->applet(), parent), | 50 | : AppletQuickItem(script->applet(), parent), | ||
51 | m_configuration(nullptr), | 51 | m_configuration(nullptr), | ||
52 | m_appletScriptEngine(script), | 52 | m_appletScriptEngine(script), | ||
53 | m_toolTipTextFormat(0), | 53 | m_toolTipTextFormat(0), | ||
54 | m_toolTipItem(nullptr), | 54 | m_toolTipItem(nullptr), | ||
55 | m_args(args), | 55 | m_args(args), | ||
56 | m_backgroundHints(Plasma::Types::StandardBackground), | 56 | m_backgroundHints(Plasma::Types::StandardBackground), | ||
57 | m_userBackgroundHints(Plasma::Types::StandardBackground), | ||||
57 | m_hideOnDeactivate(true), | 58 | m_hideOnDeactivate(true), | ||
58 | m_oldKeyboardShortcut(0), | 59 | m_oldKeyboardShortcut(0), | ||
59 | m_dummyNativeInterface(nullptr), | 60 | m_dummyNativeInterface(nullptr), | ||
60 | m_positionBeforeRemoval(QPointF(-1, -1)) | 61 | m_positionBeforeRemoval(QPointF(-1, -1)) | ||
61 | { | 62 | { | ||
62 | qmlRegisterType<QAction>(); | 63 | qmlRegisterType<QAction>(); | ||
63 | 64 | | |||
64 | connect(this, &AppletInterface::configNeedsSaving, | 65 | connect(this, &AppletInterface::configNeedsSaving, | ||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 178 | [ = ]() { | |||
188 | } | 189 | } | ||
189 | }); | 190 | }); | ||
190 | 191 | | |||
191 | if (m_args.count() == 1) { | 192 | if (m_args.count() == 1) { | ||
192 | emit externalData(QString(), m_args.first()); | 193 | emit externalData(QString(), m_args.first()); | ||
193 | } else if (!m_args.isEmpty()) { | 194 | } else if (!m_args.isEmpty()) { | ||
194 | emit externalData(QString(), m_args); | 195 | emit externalData(QString(), m_args); | ||
195 | } | 196 | } | ||
197 | | ||||
198 | QByteArray hintsString = applet()->config().readEntry("UserBackgroundHints", QString()).toUtf8(); | ||||
199 | QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>(); | ||||
200 | bool ok; | ||||
201 | int value = hintEnum.keyToValue(hintsString.constData(), &ok); | ||||
202 | if (ok) { | ||||
davidedmundson: 0 == NoBackground which is a perfectly valid entry
I think we need to use the
keyToValue… | |||||
203 | m_userBackgroundHints = Plasma::Types::BackgroundHints(value); | ||||
204 | m_userBackgroundHintsInitialized = true; | ||||
205 | emit userBackgroundHintsChanged(); | ||||
206 | if (m_backgroundHints & Plasma::Types::ConfigurableBackground) { | ||||
207 | emit effectiveBackgroundHintsChanged(); | ||||
208 | } | ||||
209 | } | ||||
196 | } | 210 | } | ||
197 | 211 | | |||
198 | void AppletInterface::destroyedChanged(bool destroyed) | 212 | void AppletInterface::destroyedChanged(bool destroyed) | ||
199 | { | 213 | { | ||
200 | //if an item loses its scene before losing the focus, will never | 214 | //if an item loses its scene before losing the focus, will never | ||
201 | //be able to gain focus again | 215 | //be able to gain focus again | ||
202 | if (destroyed && window() && window()->activeFocusItem()) { | 216 | if (destroyed && window() && window()->activeFocusItem()) { | ||
203 | QQuickItem *focus = window()->activeFocusItem(); | 217 | QQuickItem *focus = window()->activeFocusItem(); | ||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Line(s) | |||||
390 | } | 404 | } | ||
391 | 405 | | |||
392 | void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint) | 406 | void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint) | ||
393 | { | 407 | { | ||
394 | if (m_backgroundHints == hint) { | 408 | if (m_backgroundHints == hint) { | ||
395 | return; | 409 | return; | ||
396 | } | 410 | } | ||
397 | 411 | | |||
412 | Plasma::Types::BackgroundHints oldeffectiveHints = effectiveBackgroundHints(); | ||||
413 | | ||||
398 | m_backgroundHints = hint; | 414 | m_backgroundHints = hint; | ||
399 | emit backgroundHintsChanged(); | 415 | emit backgroundHintsChanged(); | ||
416 | | ||||
I think technically has a bug. if m_userBackgroundHintsInitialized == true and the m_backgroundHints changed from !configurable -> configurable then the effectiveBackgroundHints will change, but we're not emitting it. i.e this should be if (!m_userBackgroundHintsInitialized || !(newbackgroundHints & Plasma::Types::ConfigurableBackground)) !(oldbackgroundHints & Plasma::Types::ConfigurableBackground) Though personally I would just call effectiveBackgroundHints() before and after, it's more robust than duplicating the logic. davidedmundson: I think technically has a bug.
if m_userBackgroundHintsInitialized == true
and the… | |||||
417 | if (oldeffectiveHints != effectiveBackgroundHints()) { | ||||
418 | emit effectiveBackgroundHintsChanged(); | ||||
419 | } | ||||
420 | } | ||||
421 | | ||||
422 | Plasma::Types::BackgroundHints AppletInterface::effectiveBackgroundHints() const | ||||
423 | { | ||||
424 | if (m_userBackgroundHintsInitialized | ||||
425 | && (m_backgroundHints & Plasma::Types::ConfigurableBackground)) { | ||||
426 | return m_userBackgroundHints; | ||||
427 | } else { | ||||
428 | return m_backgroundHints; | ||||
429 | } | ||||
430 | } | ||||
431 | | ||||
432 | Plasma::Types::BackgroundHints AppletInterface::userBackgroundHints() const | ||||
433 | { | ||||
434 | return m_userBackgroundHints; | ||||
435 | } | ||||
436 | | ||||
437 | void AppletInterface::setUserBackgroundHints(Plasma::Types::BackgroundHints hint) | ||||
438 | { | ||||
439 | if (m_userBackgroundHints == hint && m_userBackgroundHintsInitialized) { | ||||
440 | return; | ||||
441 | } | ||||
442 | | ||||
443 | m_userBackgroundHints = hint; | ||||
444 | m_userBackgroundHintsInitialized = true; | ||||
445 | QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>(); | ||||
446 | applet()->config().writeEntry("UserBackgroundHints", hintEnum.valueToKey(m_userBackgroundHints)); | ||||
447 | if (applet()->containment() && applet()->containment()->corona()) { | ||||
448 | applet()->containment()->corona()->requestConfigSync(); | ||||
449 | } | ||||
450 | | ||||
451 | emit userBackgroundHintsChanged(); | ||||
452 | | ||||
453 | if (m_backgroundHints & Plasma::Types::ConfigurableBackground) { | ||||
454 | emit effectiveBackgroundHintsChanged(); | ||||
455 | } | ||||
400 | } | 456 | } | ||
401 | 457 | | |||
402 | void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason) | 458 | void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason) | ||
403 | { | 459 | { | ||
404 | appletScript()->setConfigurationRequired(needsConfiguring, reason); | 460 | appletScript()->setConfigurationRequired(needsConfiguring, reason); | ||
405 | } | 461 | } | ||
406 | 462 | | |||
407 | QString AppletInterface::file(const QString &fileType) | 463 | QString AppletInterface::file(const QString &fileType) | ||
▲ Show 20 Lines • Show All 461 Lines • Show Last 20 Lines |
0 == NoBackground which is a perfectly valid entry
I think we need to use the
keyToValue(QString, bool*) overload and check the return value.