access to widget/containment global configuration
svn path=/trunk/KDE/kdebase/workspace/; revision=1118736
This commit is contained in:
parent
7fd48e2b47
commit
dbe17cfa6f
110
applet.cpp
110
applet.cpp
@ -26,45 +26,62 @@
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Corona>
|
||||
|
||||
class Applet::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
: configDirty(false)
|
||||
{
|
||||
}
|
||||
|
||||
KConfigGroup configGroup;
|
||||
QStringList configGroupPath;
|
||||
KConfigGroup globalConfigGroup;
|
||||
QStringList globalConfigGroupPath;
|
||||
bool configDirty;
|
||||
};
|
||||
|
||||
Applet::Applet(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_configDirty(false)
|
||||
d(new Applet::Private)
|
||||
{
|
||||
}
|
||||
|
||||
Applet::~Applet()
|
||||
{
|
||||
if (m_configDirty) {
|
||||
if (d->configDirty) {
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Applet::setCurrentConfigGroup(const QStringList &groupNames)
|
||||
{
|
||||
Plasma::Applet *app = applet();
|
||||
if (!app) {
|
||||
m_configGroup = KConfigGroup();
|
||||
m_configGroupPath.clear();
|
||||
d->configGroup = KConfigGroup();
|
||||
d->configGroupPath.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
m_configGroup = app->config();
|
||||
m_configGroupPath = groupNames;
|
||||
d->configGroup = app->config();
|
||||
d->configGroupPath = groupNames;
|
||||
|
||||
foreach (const QString &groupName, groupNames) {
|
||||
m_configGroup = KConfigGroup(&m_configGroup, groupName);
|
||||
d->configGroup = KConfigGroup(&d->configGroup, groupName);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList Applet::currentConfigGroup() const
|
||||
{
|
||||
return m_configGroupPath;
|
||||
return d->configGroupPath;
|
||||
}
|
||||
|
||||
QStringList Applet::configKeys() const
|
||||
{
|
||||
if (m_configGroup.isValid()) {
|
||||
return m_configGroup.keyList();
|
||||
if (d->configGroup.isValid()) {
|
||||
return d->configGroup.keyList();
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
@ -72,8 +89,8 @@ QStringList Applet::configKeys() const
|
||||
|
||||
QStringList Applet::configGroups() const
|
||||
{
|
||||
if (m_configGroup.isValid()) {
|
||||
return m_configGroup.groupList();
|
||||
if (d->configGroup.isValid()) {
|
||||
return d->configGroup.groupList();
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
@ -81,8 +98,8 @@ QStringList Applet::configGroups() const
|
||||
|
||||
QVariant Applet::readConfig(const QString &key, const QVariant &def) const
|
||||
{
|
||||
if (m_configGroup.isValid()) {
|
||||
return m_configGroup.readEntry(key, def);
|
||||
if (d->configGroup.isValid()) {
|
||||
return d->configGroup.readEntry(key, def);
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
@ -90,9 +107,66 @@ QVariant Applet::readConfig(const QString &key, const QVariant &def) const
|
||||
|
||||
void Applet::writeConfig(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (m_configGroup.isValid()) {
|
||||
m_configGroup.writeEntry(key, value);
|
||||
m_configDirty = true;
|
||||
if (d->configGroup.isValid()) {
|
||||
d->configGroup.writeEntry(key, value);
|
||||
d->configDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Applet::setCurrentGlobalConfigGroup(const QStringList &groupNames)
|
||||
{
|
||||
Plasma::Applet *app = applet();
|
||||
if (!app) {
|
||||
d->globalConfigGroup = KConfigGroup();
|
||||
d->globalConfigGroupPath.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
d->globalConfigGroup = app->globalConfig();
|
||||
d->globalConfigGroupPath = groupNames;
|
||||
|
||||
foreach (const QString &groupName, groupNames) {
|
||||
d->globalConfigGroup = KConfigGroup(&d->globalConfigGroup, groupName);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList Applet::currentGlobalConfigGroup() const
|
||||
{
|
||||
return d->globalConfigGroupPath;
|
||||
}
|
||||
|
||||
QStringList Applet::globalConfigKeys() const
|
||||
{
|
||||
if (d->globalConfigGroup.isValid()) {
|
||||
return d->globalConfigGroup.keyList();
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList Applet::globalConfigGroups() const
|
||||
{
|
||||
if (d->globalConfigGroup.isValid()) {
|
||||
return d->globalConfigGroup.groupList();
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QVariant Applet::readGlobalConfig(const QString &key, const QVariant &def) const
|
||||
{
|
||||
if (d->globalConfigGroup.isValid()) {
|
||||
return d->globalConfigGroup.readEntry(key, def);
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void Applet::writeGlobalConfig(const QString &key, const QVariant &value)
|
||||
{
|
||||
if (d->globalConfigGroup.isValid()) {
|
||||
d->globalConfigGroup.writeEntry(key, value);
|
||||
d->configDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +186,7 @@ void Applet::reloadConfig()
|
||||
app->containment()->corona()->requestConfigSync();
|
||||
}
|
||||
|
||||
m_configDirty = false;
|
||||
d->configDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
13
applet.h
13
applet.h
@ -46,17 +46,24 @@ public:
|
||||
void setCurrentConfigGroup(const QStringList &groupNames);
|
||||
QStringList currentConfigGroup() const;
|
||||
|
||||
QStringList globalConfigKeys() const;
|
||||
QStringList globalConfigGroups() const;
|
||||
|
||||
void setCurrentGlobalConfigGroup(const QStringList &groupNames);
|
||||
QStringList currentGlobalConfigGroup() const;
|
||||
|
||||
virtual Plasma::Applet *applet() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual QVariant readConfig(const QString &key, const QVariant &def = QString()) const;
|
||||
virtual void writeConfig(const QString &key, const QVariant &value);
|
||||
virtual QVariant readGlobalConfig(const QString &key, const QVariant &def = QString()) const;
|
||||
virtual void writeGlobalConfig(const QString &key, const QVariant &value);
|
||||
virtual void reloadConfig();
|
||||
|
||||
private:
|
||||
KConfigGroup m_configGroup;
|
||||
QStringList m_configGroupPath;
|
||||
bool m_configDirty;
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
|
||||
|
@ -44,6 +44,7 @@ Containment::Containment(Plasma::Containment *containment, QObject *parent)
|
||||
{
|
||||
d->containment = containment;
|
||||
setCurrentConfigGroup(QStringList());
|
||||
setCurrentGlobalConfigGroup(QStringList());
|
||||
if (containment && containment->wallpaper()) {
|
||||
d->oldWallpaperPlugin = d->wallpaperPlugin = containment->wallpaper()->pluginName();
|
||||
d->oldWallpaperMode = d->wallpaperMode = containment->wallpaper()->renderingMode().name();
|
||||
|
@ -41,6 +41,8 @@ class PLASMAGENERICSHELL_EXPORT Containment : public Applet
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QStringList configKeys READ configKeys)
|
||||
Q_PROPERTY(QStringList configGroups READ configGroups)
|
||||
Q_PROPERTY(QStringList globalConfigKeys READ globalConfigKeys)
|
||||
Q_PROPERTY(QStringList globalConfigGroups READ globalConfigGroups)
|
||||
Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString wallpaperPlugin READ wallpaperPlugin WRITE setWallpaperPlugin)
|
||||
@ -88,6 +90,10 @@ public Q_SLOTS:
|
||||
// from the applet interface
|
||||
QVariant readConfig(const QString &key, const QVariant &def = QString()) const { return Applet::readConfig(key, def); }
|
||||
void writeConfig(const QString &key, const QVariant &value) { Applet::writeConfig(key, value); }
|
||||
|
||||
QVariant readGlobalConfig(const QString &key, const QVariant &def = QString()) const { return Applet::readConfig(key, def); }
|
||||
void writeGlobalConfig(const QString &key, const QVariant &value) { Applet::writeConfig(key, value); }
|
||||
|
||||
void reloadConfig() { Applet::reloadConfig(); }
|
||||
|
||||
private:
|
||||
|
59
widget.cpp
59
widget.cpp
@ -26,21 +26,34 @@
|
||||
#include <Plasma/Containment>
|
||||
#include <Plasma/Corona>
|
||||
|
||||
class Widget::Private
|
||||
{
|
||||
public:
|
||||
Private()
|
||||
{
|
||||
}
|
||||
|
||||
QWeakPointer<Plasma::Applet> applet;
|
||||
};
|
||||
|
||||
Widget::Widget(Plasma::Applet *applet, QObject *parent)
|
||||
: Applet(parent),
|
||||
m_applet(applet)
|
||||
d(new Widget::Private)
|
||||
{
|
||||
d->applet = applet;
|
||||
setCurrentConfigGroup(QStringList());
|
||||
setCurrentGlobalConfigGroup(QStringList());
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
uint Widget::id() const
|
||||
{
|
||||
if (m_applet) {
|
||||
return m_applet.data()->id();
|
||||
if (d->applet) {
|
||||
return d->applet.data()->id();
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -48,8 +61,8 @@ uint Widget::id() const
|
||||
|
||||
QString Widget::type() const
|
||||
{
|
||||
if (m_applet) {
|
||||
return m_applet.data()->pluginName();
|
||||
if (d->applet) {
|
||||
return d->applet.data()->pluginName();
|
||||
}
|
||||
|
||||
return QString();
|
||||
@ -57,23 +70,23 @@ QString Widget::type() const
|
||||
|
||||
void Widget::remove()
|
||||
{
|
||||
if (m_applet) {
|
||||
m_applet.data()->destroy();
|
||||
m_applet.clear();
|
||||
if (d->applet) {
|
||||
d->applet.data()->destroy();
|
||||
d->applet.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::setGlobalShortcut(const QString &shortcut)
|
||||
{
|
||||
if (m_applet) {
|
||||
m_applet.data()->setGlobalShortcut(KShortcut(shortcut));
|
||||
if (d->applet) {
|
||||
d->applet.data()->setGlobalShortcut(KShortcut(shortcut));
|
||||
}
|
||||
}
|
||||
|
||||
QString Widget::globalShorcut() const
|
||||
{
|
||||
if (m_applet) {
|
||||
return m_applet.data()->globalShortcut().toString();
|
||||
if (d->applet) {
|
||||
return d->applet.data()->globalShortcut().toString();
|
||||
}
|
||||
|
||||
return QString();
|
||||
@ -81,16 +94,16 @@ QString Widget::globalShorcut() const
|
||||
|
||||
Plasma::Applet *Widget::applet() const
|
||||
{
|
||||
return m_applet.data();
|
||||
return d->applet.data();
|
||||
}
|
||||
|
||||
int Widget::index() const
|
||||
{
|
||||
if (!m_applet) {
|
||||
if (!d->applet) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Plasma::Applet *applet = m_applet.data();
|
||||
Plasma::Applet *applet = d->applet.data();
|
||||
Plasma::Containment *c = applet->containment();
|
||||
if (!c) {
|
||||
return -1;
|
||||
@ -112,11 +125,11 @@ int Widget::index() const
|
||||
|
||||
void Widget::setIndex(int index)
|
||||
{
|
||||
if (!m_applet) {
|
||||
if (!d->applet) {
|
||||
return;
|
||||
}
|
||||
|
||||
Plasma::Applet *applet = m_applet.data();
|
||||
Plasma::Applet *applet = d->applet.data();
|
||||
Plasma::Containment *c = applet->containment();
|
||||
if (!c) {
|
||||
return;
|
||||
@ -133,8 +146,8 @@ void Widget::setIndex(int index)
|
||||
|
||||
QRectF Widget::geometry() const
|
||||
{
|
||||
if (m_applet) {
|
||||
return m_applet.data()->geometry();
|
||||
if (d->applet) {
|
||||
return d->applet.data()->geometry();
|
||||
}
|
||||
|
||||
return QRectF();
|
||||
@ -142,15 +155,15 @@ QRectF Widget::geometry() const
|
||||
|
||||
void Widget::setGeometry(const QRectF &geometry)
|
||||
{
|
||||
if (m_applet) {
|
||||
m_applet.data()->setGeometry(geometry);
|
||||
if (d->applet) {
|
||||
d->applet.data()->setGeometry(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::showConfigurationInterface()
|
||||
{
|
||||
if (m_applet) {
|
||||
m_applet.data()->showConfigurationInterface();
|
||||
if (d->applet) {
|
||||
d->applet.data()->showConfigurationInterface();
|
||||
}
|
||||
}
|
||||
|
||||
|
9
widget.h
9
widget.h
@ -38,6 +38,8 @@ class PLASMAGENERICSHELL_EXPORT Widget : public Applet
|
||||
Q_PROPERTY(int id READ id)
|
||||
Q_PROPERTY(QStringList configKeys READ configKeys)
|
||||
Q_PROPERTY(QStringList configGroups READ configGroups)
|
||||
Q_PROPERTY(QStringList globalConfigKeys READ globalConfigKeys)
|
||||
Q_PROPERTY(QStringList globalConfigGroups READ globalConfigGroups)
|
||||
Q_PROPERTY(int index WRITE setIndex READ index)
|
||||
Q_PROPERTY(QRectF geometry WRITE setGeometry READ geometry)
|
||||
Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup)
|
||||
@ -69,10 +71,15 @@ public Q_SLOTS:
|
||||
// from the applet interface
|
||||
QVariant readConfig(const QString &key, const QVariant &def = QString()) const { return Applet::readConfig(key, def); }
|
||||
void writeConfig(const QString &key, const QVariant &value) { Applet::writeConfig(key, value); }
|
||||
|
||||
QVariant readGlobalConfig(const QString &key, const QVariant &def = QString()) const { return Applet::readConfig(key, def); }
|
||||
void writeGlobalConfig(const QString &key, const QVariant &value) { Applet::writeConfig(key, value); }
|
||||
|
||||
void reloadConfig() { Applet::reloadConfig(); }
|
||||
|
||||
private:
|
||||
QWeakPointer<Plasma::Applet> m_applet;
|
||||
class Private;
|
||||
Private * const d;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user