move backgroundhints managment in Applet
Summary: Applet is the more proper way to do it (and will make easier porting to KF6) this also make it possible for the scripting interface to access userBackgroundHints Test Plan: everything behaves the same in plasmashell, the background button in the handle works Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D25742
This commit is contained in:
parent
1da69dd751
commit
af861eb2a4
@ -32,6 +32,7 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
#include <kactioncollection.h>
|
#include <kactioncollection.h>
|
||||||
#include <kauthorized.h>
|
#include <kauthorized.h>
|
||||||
@ -223,6 +224,21 @@ void Applet::restore(KConfigGroup &group)
|
|||||||
//TODO: implement; the shortcut
|
//TODO: implement; the shortcut
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// User background hints
|
||||||
|
// TODO support flags in the config
|
||||||
|
QByteArray hintsString = config().readEntry("UserBackgroundHints", QString()).toUtf8();
|
||||||
|
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
||||||
|
bool ok;
|
||||||
|
int value = hintEnum.keyToValue(hintsString.constData(), &ok);
|
||||||
|
if (ok) {
|
||||||
|
d->userBackgroundHints = Plasma::Types::BackgroundHints(value);
|
||||||
|
d->userBackgroundHintsInitialized = true;
|
||||||
|
emit userBackgroundHintsChanged();
|
||||||
|
if (d->backgroundHints & Plasma::Types::ConfigurableBackground) {
|
||||||
|
emit effectiveBackgroundHintsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::setLaunchErrorMessage(const QString &message)
|
void Applet::setLaunchErrorMessage(const QString &message)
|
||||||
@ -399,6 +415,64 @@ void Applet::setBusy(bool busy)
|
|||||||
emit busyChanged(busy);
|
emit busyChanged(busy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plasma::Types::BackgroundHints Applet::backgroundHints() const
|
||||||
|
{
|
||||||
|
return d->backgroundHints;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Applet::setBackgroundHints(Plasma::Types::BackgroundHints hint)
|
||||||
|
{
|
||||||
|
if (d->backgroundHints == hint) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::Types::BackgroundHints oldeffectiveHints = effectiveBackgroundHints();
|
||||||
|
|
||||||
|
d->backgroundHints = hint;
|
||||||
|
emit backgroundHintsChanged();
|
||||||
|
|
||||||
|
if (oldeffectiveHints != effectiveBackgroundHints()) {
|
||||||
|
emit effectiveBackgroundHintsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::Types::BackgroundHints Applet::effectiveBackgroundHints() const
|
||||||
|
{
|
||||||
|
if (d->userBackgroundHintsInitialized
|
||||||
|
&& (d->backgroundHints & Plasma::Types::ConfigurableBackground)) {
|
||||||
|
return d->userBackgroundHints;
|
||||||
|
} else {
|
||||||
|
return d->backgroundHints;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::Types::BackgroundHints Applet::userBackgroundHints() const
|
||||||
|
{
|
||||||
|
return d->userBackgroundHints;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Applet::setUserBackgroundHints(Plasma::Types::BackgroundHints hint)
|
||||||
|
{
|
||||||
|
if (d->userBackgroundHints == hint && d->userBackgroundHintsInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->userBackgroundHints = hint;
|
||||||
|
d->userBackgroundHintsInitialized = true;
|
||||||
|
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
||||||
|
config().writeEntry("UserBackgroundHints", hintEnum.valueToKey(d->userBackgroundHints));
|
||||||
|
if (containment() && containment()->corona()) {
|
||||||
|
containment()->corona()->requestConfigSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit userBackgroundHintsChanged();
|
||||||
|
|
||||||
|
if (d->backgroundHints & Plasma::Types::ConfigurableBackground) {
|
||||||
|
emit effectiveBackgroundHintsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
KPluginInfo Applet::pluginInfo() const
|
KPluginInfo Applet::pluginInfo() const
|
||||||
{
|
{
|
||||||
return KPluginInfo(d->appletDescription);
|
return KPluginInfo(d->appletDescription);
|
||||||
|
@ -75,6 +75,21 @@ class PLASMA_EXPORT Applet : public QObject
|
|||||||
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged FINAL)
|
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged FINAL)
|
||||||
Q_PROPERTY(bool busy READ isBusy WRITE setBusy NOTIFY busyChanged FINAL)
|
Q_PROPERTY(bool busy READ isBusy WRITE setBusy NOTIFY busyChanged FINAL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How the applet wants its background to be drawn. The containment may chose to ignore this hint.
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(Plasma::Types::BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints NOTIFY backgroundHintsChanged FINAL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The containment (and/or the user) may decide to use another kind of background instead (if supported by the applet)
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(Plasma::Types::BackgroundHints userBackgroundHints WRITE setUserBackgroundHints READ userBackgroundHints NOTIFY userBackgroundHintsChanged FINAL)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The effective background hints the applet has, internally decided how to mix with userBackgroundHints
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(Plasma::Types::BackgroundHints effectiveBackgroundHints READ effectiveBackgroundHints NOTIFY effectiveBackgroundHintsChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//CONSTRUCTORS
|
//CONSTRUCTORS
|
||||||
/**
|
/**
|
||||||
@ -370,6 +385,38 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setBusy(bool busy);
|
void setBusy(bool busy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How the applet wants its background to be drawn. The containment may chose to ignore this hint.
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
Plasma::Types::BackgroundHints backgroundHints() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the applet background hints. Only Applet implementations should write this property
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
void setBackgroundHints(Plasma::Types::BackgroundHints hint);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The containment (and/or the user) may decide to use another kind of background instead if supported by the applet.
|
||||||
|
* In order for an applet to support user configuration of the
|
||||||
|
* background, it needs to have the Plasma::Types::ConfigurableBackground flag set in its backgroundHints
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
Plasma::Types::BackgroundHints userBackgroundHints() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the hints the user wished the background style for the applet to be.
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
void setUserBackgroundHints(Plasma::Types::BackgroundHints hint);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The effective background hints the applet will have: it will follow userBackgroundHints only if backgroundHints has the Plasma::Types::ConfigurableBackground flag set
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
Plasma::Types::BackgroundHints effectiveBackgroundHints() const;
|
||||||
|
|
||||||
//ACTIONS
|
//ACTIONS
|
||||||
/**
|
/**
|
||||||
* Returns a list of context-related QAction instances.
|
* Returns a list of context-related QAction instances.
|
||||||
@ -484,6 +531,24 @@ Q_SIGNALS:
|
|||||||
*/
|
*/
|
||||||
void busyChanged(bool busy);
|
void busyChanged(bool busy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the background hints have changed
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
void backgroundHintsChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the user background hints have changed
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
void userBackgroundHintsChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the effective background hints have changed
|
||||||
|
* @since 5.65
|
||||||
|
*/
|
||||||
|
void effectiveBackgroundHintsChanged();
|
||||||
|
|
||||||
//CONFIGURATION
|
//CONFIGURATION
|
||||||
/**
|
/**
|
||||||
* Emitted when an applet has changed values in its configuration
|
* Emitted when an applet has changed values in its configuration
|
||||||
@ -578,6 +643,7 @@ public Q_SLOTS:
|
|||||||
/**
|
/**
|
||||||
* Called when applet configuration values have changed.
|
* Called when applet configuration values have changed.
|
||||||
*/
|
*/
|
||||||
|
//TODO KF6: make it not a slot anymore and protected
|
||||||
virtual void configChanged();
|
virtual void configChanged();
|
||||||
|
|
||||||
//UTILS
|
//UTILS
|
||||||
|
@ -111,7 +111,11 @@ public:
|
|||||||
|
|
||||||
QString configurationRequiredReason;
|
QString configurationRequiredReason;
|
||||||
|
|
||||||
|
Types::BackgroundHints backgroundHints = Types::DefaultBackground;
|
||||||
|
Types::BackgroundHints userBackgroundHints = Types::DefaultBackground;
|
||||||
|
|
||||||
// a great green field of booleans :)
|
// a great green field of booleans :)
|
||||||
|
bool userBackgroundHintsInitialized = false;
|
||||||
bool hasConfigurationInterface : 1;
|
bool hasConfigurationInterface : 1;
|
||||||
bool failed : 1;
|
bool failed : 1;
|
||||||
bool transient : 1;
|
bool transient : 1;
|
||||||
|
@ -53,8 +53,6 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant
|
|||||||
m_toolTipTextFormat(0),
|
m_toolTipTextFormat(0),
|
||||||
m_toolTipItem(nullptr),
|
m_toolTipItem(nullptr),
|
||||||
m_args(args),
|
m_args(args),
|
||||||
m_backgroundHints(Plasma::Types::StandardBackground),
|
|
||||||
m_userBackgroundHints(Plasma::Types::StandardBackground),
|
|
||||||
m_hideOnDeactivate(true),
|
m_hideOnDeactivate(true),
|
||||||
m_oldKeyboardShortcut(0),
|
m_oldKeyboardShortcut(0),
|
||||||
m_dummyNativeInterface(nullptr),
|
m_dummyNativeInterface(nullptr),
|
||||||
@ -94,6 +92,13 @@ AppletInterface::AppletInterface(DeclarativeAppletScript *script, const QVariant
|
|||||||
connect(applet(), &Plasma::Applet::busyChanged,
|
connect(applet(), &Plasma::Applet::busyChanged,
|
||||||
this, &AppletInterface::busyChanged);
|
this, &AppletInterface::busyChanged);
|
||||||
|
|
||||||
|
connect(applet(), &Plasma::Applet::backgroundHintsChanged,
|
||||||
|
this, &AppletInterface::backgroundHintsChanged);
|
||||||
|
connect(applet(), &Plasma::Applet::effectiveBackgroundHintsChanged,
|
||||||
|
this, &AppletInterface::effectiveBackgroundHintsChanged);
|
||||||
|
connect(applet(), &Plasma::Applet::userBackgroundHintsChanged,
|
||||||
|
this, &AppletInterface::userBackgroundHintsChanged);
|
||||||
|
|
||||||
connect(applet(), &Plasma::Applet::configurationRequiredChanged, this,
|
connect(applet(), &Plasma::Applet::configurationRequiredChanged, this,
|
||||||
[this](bool configurationRequired, const QString &reason) {
|
[this](bool configurationRequired, const QString &reason) {
|
||||||
Q_UNUSED(configurationRequired);
|
Q_UNUSED(configurationRequired);
|
||||||
@ -194,19 +199,6 @@ void AppletInterface::init()
|
|||||||
} else if (!m_args.isEmpty()) {
|
} else if (!m_args.isEmpty()) {
|
||||||
emit externalData(QString(), m_args);
|
emit externalData(QString(), m_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray hintsString = applet()->config().readEntry("UserBackgroundHints", QString()).toUtf8();
|
|
||||||
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
|
||||||
bool ok;
|
|
||||||
int value = hintEnum.keyToValue(hintsString.constData(), &ok);
|
|
||||||
if (ok) {
|
|
||||||
m_userBackgroundHints = Plasma::Types::BackgroundHints(value);
|
|
||||||
m_userBackgroundHintsInitialized = true;
|
|
||||||
emit userBackgroundHintsChanged();
|
|
||||||
if (m_backgroundHints & Plasma::Types::ConfigurableBackground) {
|
|
||||||
emit effectiveBackgroundHintsChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::destroyedChanged(bool destroyed)
|
void AppletInterface::destroyedChanged(bool destroyed)
|
||||||
@ -400,59 +392,27 @@ void AppletInterface::setBusy(bool busy)
|
|||||||
|
|
||||||
Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const
|
Plasma::Types::BackgroundHints AppletInterface::backgroundHints() const
|
||||||
{
|
{
|
||||||
return m_backgroundHints;
|
return applet()->backgroundHints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint)
|
void AppletInterface::setBackgroundHints(Plasma::Types::BackgroundHints hint)
|
||||||
{
|
{
|
||||||
if (m_backgroundHints == hint) {
|
applet()->setBackgroundHints(hint);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Plasma::Types::BackgroundHints oldeffectiveHints = effectiveBackgroundHints();
|
|
||||||
|
|
||||||
m_backgroundHints = hint;
|
|
||||||
emit backgroundHintsChanged();
|
|
||||||
|
|
||||||
if (oldeffectiveHints != effectiveBackgroundHints()) {
|
|
||||||
emit effectiveBackgroundHintsChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Types::BackgroundHints AppletInterface::effectiveBackgroundHints() const
|
Plasma::Types::BackgroundHints AppletInterface::effectiveBackgroundHints() const
|
||||||
{
|
{
|
||||||
if (m_userBackgroundHintsInitialized
|
return applet()->effectiveBackgroundHints();
|
||||||
&& (m_backgroundHints & Plasma::Types::ConfigurableBackground)) {
|
|
||||||
return m_userBackgroundHints;
|
|
||||||
} else {
|
|
||||||
return m_backgroundHints;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Types::BackgroundHints AppletInterface::userBackgroundHints() const
|
Plasma::Types::BackgroundHints AppletInterface::userBackgroundHints() const
|
||||||
{
|
{
|
||||||
return m_userBackgroundHints;
|
return applet()->userBackgroundHints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::setUserBackgroundHints(Plasma::Types::BackgroundHints hint)
|
void AppletInterface::setUserBackgroundHints(Plasma::Types::BackgroundHints hint)
|
||||||
{
|
{
|
||||||
if (m_userBackgroundHints == hint && m_userBackgroundHintsInitialized) {
|
applet()->setUserBackgroundHints(hint);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_userBackgroundHints = hint;
|
|
||||||
m_userBackgroundHintsInitialized = true;
|
|
||||||
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
|
||||||
applet()->config().writeEntry("UserBackgroundHints", hintEnum.valueToKey(m_userBackgroundHints));
|
|
||||||
if (applet()->containment() && applet()->containment()->corona()) {
|
|
||||||
applet()->containment()->corona()->requestConfigSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit userBackgroundHintsChanged();
|
|
||||||
|
|
||||||
if (m_backgroundHints & Plasma::Types::ConfigurableBackground) {
|
|
||||||
emit effectiveBackgroundHintsChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
|
void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
|
||||||
|
@ -502,9 +502,6 @@ private:
|
|||||||
int m_toolTipTextFormat;
|
int m_toolTipTextFormat;
|
||||||
QPointer<QQuickItem> m_toolTipItem;
|
QPointer<QQuickItem> m_toolTipItem;
|
||||||
QVariantList m_args;
|
QVariantList m_args;
|
||||||
Plasma::Types::BackgroundHints m_backgroundHints;
|
|
||||||
Plasma::Types::BackgroundHints m_userBackgroundHints;
|
|
||||||
bool m_userBackgroundHintsInitialized = false;
|
|
||||||
bool m_hideOnDeactivate : 1;
|
bool m_hideOnDeactivate : 1;
|
||||||
bool m_loading = false;
|
bool m_loading = false;
|
||||||
//this is used to build an emacs style shortcut
|
//this is used to build an emacs style shortcut
|
||||||
|
Loading…
Reference in New Issue
Block a user