* use a dptr
* add wallpaper plugin/mode svn path=/trunk/KDE/kdebase/workspace/; revision=1113079
This commit is contained in:
parent
a93be26e8b
commit
818a3a15b4
110
containment.cpp
110
containment.cpp
@ -23,60 +23,104 @@
|
|||||||
|
|
||||||
#include <Plasma/Corona>
|
#include <Plasma/Corona>
|
||||||
#include <Plasma/Containment>
|
#include <Plasma/Containment>
|
||||||
|
#include <Plasma/Wallpaper>
|
||||||
|
|
||||||
#include "scriptengine.h"
|
#include "scriptengine.h"
|
||||||
#include "widget.h"
|
#include "widget.h"
|
||||||
|
|
||||||
|
class Containment::Private
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QWeakPointer<Plasma::Containment> containment;
|
||||||
|
QString oldWallpaperPlugin;
|
||||||
|
QString wallpaperPlugin;
|
||||||
|
QString oldWallpaperMode;
|
||||||
|
QString wallpaperMode;
|
||||||
|
};
|
||||||
|
|
||||||
Containment::Containment(Plasma::Containment *containment, QObject *parent)
|
Containment::Containment(Plasma::Containment *containment, QObject *parent)
|
||||||
: Applet(parent),
|
: Applet(parent),
|
||||||
m_containment(containment)
|
d(new Containment::Private)
|
||||||
{
|
{
|
||||||
|
d->containment = containment;
|
||||||
setCurrentConfigGroup(QStringList());
|
setCurrentConfigGroup(QStringList());
|
||||||
|
if (containment && containment->wallpaper()) {
|
||||||
|
d->oldWallpaperPlugin = d->wallpaperPlugin = containment->wallpaper()->pluginName();
|
||||||
|
d->oldWallpaperMode = d->wallpaperMode = containment->wallpaper()->renderingMode().name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Containment::~Containment()
|
Containment::~Containment()
|
||||||
{
|
{
|
||||||
|
if (d->containment && (d->oldWallpaperPlugin != d->wallpaperPlugin ||
|
||||||
|
d->oldWallpaperMode != d->wallpaperMode)) {
|
||||||
|
Plasma::Containment *containment = d->containment.data();
|
||||||
|
containment->setWallpaper(d->wallpaperPlugin, d->wallpaperMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Containment::screen() const
|
int Containment::screen() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_containment.data()->screen();
|
return d->containment.data()->screen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::setScreen(int screen)
|
void Containment::setScreen(int screen)
|
||||||
{
|
{
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
m_containment.data()->setScreen(screen);
|
d->containment.data()->setScreen(screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Containment::wallpaperPlugin() const
|
||||||
|
{
|
||||||
|
return d->wallpaperPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Containment::setWallpaperPlugin(const QString &wallpaperPlugin)
|
||||||
|
{
|
||||||
|
d->wallpaperPlugin = wallpaperPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString Containment::wallpaperMode() const
|
||||||
|
{
|
||||||
|
return d->wallpaperMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Containment::setWallpaperMode(const QString &wallpaperMode)
|
||||||
|
{
|
||||||
|
d->wallpaperMode = wallpaperMode;
|
||||||
|
}
|
||||||
|
|
||||||
int Containment::desktop() const
|
int Containment::desktop() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_containment.data()->desktop();
|
return d->containment.data()->desktop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::setDesktop(int desktop)
|
void Containment::setDesktop(int desktop)
|
||||||
{
|
{
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
m_containment.data()->setScreen(m_containment.data()->screen(), desktop);
|
d->containment.data()->setScreen(d->containment.data()->screen(), desktop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Containment::formFactor() const
|
QString Containment::formFactor() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return "Planar";
|
return "Planar";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_containment.data()->formFactor()) {
|
switch (d->containment.data()->formFactor()) {
|
||||||
case Plasma::Planar:
|
case Plasma::Planar:
|
||||||
return "planar";
|
return "planar";
|
||||||
break;
|
break;
|
||||||
@ -100,8 +144,8 @@ QList<int> Containment::widgetIds() const
|
|||||||
// however QScript deals with QList<uint> very, very poory
|
// however QScript deals with QList<uint> very, very poory
|
||||||
QList<int> w;
|
QList<int> w;
|
||||||
|
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
foreach (const Plasma::Applet *applet, m_containment.data()->applets()) {
|
foreach (const Plasma::Applet *applet, d->containment.data()->applets()) {
|
||||||
w.append(applet->id());
|
w.append(applet->id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,8 +166,8 @@ QScriptValue Containment::widgetById(QScriptContext *context, QScriptEngine *eng
|
|||||||
return engine->undefinedValue();
|
return engine->undefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->m_containment) {
|
if (c->d->containment) {
|
||||||
foreach (Plasma::Applet *w, c->m_containment.data()->applets()) {
|
foreach (Plasma::Applet *w, c->d->containment.data()->applets()) {
|
||||||
if (w->id() == id) {
|
if (w->id() == id) {
|
||||||
ScriptEngine *env = ScriptEngine::envFor(engine);
|
ScriptEngine *env = ScriptEngine::envFor(engine);
|
||||||
return env->wrap(w, engine);
|
return env->wrap(w, engine);
|
||||||
@ -142,21 +186,21 @@ QScriptValue Containment::addWidget(QScriptContext *context, QScriptEngine *engi
|
|||||||
|
|
||||||
Containment *c = qobject_cast<Containment*>(context->thisObject().toQObject());
|
Containment *c = qobject_cast<Containment*>(context->thisObject().toQObject());
|
||||||
|
|
||||||
if (!c || !c->m_containment) {
|
if (!c || !c->d->containment) {
|
||||||
return engine->undefinedValue();
|
return engine->undefinedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue v = context->argument(0);
|
QScriptValue v = context->argument(0);
|
||||||
Plasma::Applet *applet = 0;
|
Plasma::Applet *applet = 0;
|
||||||
if (v.isString()) {
|
if (v.isString()) {
|
||||||
applet = c->m_containment.data()->addApplet(v.toString());
|
applet = c->d->containment.data()->addApplet(v.toString());
|
||||||
if (applet) {
|
if (applet) {
|
||||||
ScriptEngine *env = ScriptEngine::envFor(engine);
|
ScriptEngine *env = ScriptEngine::envFor(engine);
|
||||||
return env->wrap(applet, engine);
|
return env->wrap(applet, engine);
|
||||||
}
|
}
|
||||||
} else if (Widget *widget = qobject_cast<Widget*>(v.toQObject())) {
|
} else if (Widget *widget = qobject_cast<Widget*>(v.toQObject())) {
|
||||||
applet = widget->applet();
|
applet = widget->applet();
|
||||||
c->m_containment.data()->addApplet(applet);
|
c->d->containment.data()->addApplet(applet);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,49 +209,49 @@ QScriptValue Containment::addWidget(QScriptContext *context, QScriptEngine *engi
|
|||||||
|
|
||||||
uint Containment::id() const
|
uint Containment::id() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_containment.data()->id();
|
return d->containment.data()->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Containment::name() const
|
QString Containment::name() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_containment.data()->activity();
|
return d->containment.data()->activity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::setName(const QString &name)
|
void Containment::setName(const QString &name)
|
||||||
{
|
{
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
m_containment.data()->setActivity(name);
|
d->containment.data()->setActivity(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Containment::type() const
|
QString Containment::type() const
|
||||||
{
|
{
|
||||||
if (!m_containment) {
|
if (!d->containment) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_containment.data()->pluginName();
|
return d->containment.data()->pluginName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::remove()
|
void Containment::remove()
|
||||||
{
|
{
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
m_containment.data()->destroy(false);
|
d->containment.data()->destroy(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::showConfigurationInterface()
|
void Containment::showConfigurationInterface()
|
||||||
{
|
{
|
||||||
if (m_containment) {
|
if (d->containment) {
|
||||||
QAction *configAction = m_containment.data()->action("configure");
|
QAction *configAction = d->containment.data()->action("configure");
|
||||||
if (configAction && configAction->isEnabled()) {
|
if (configAction && configAction->isEnabled()) {
|
||||||
configAction->trigger();
|
configAction->trigger();
|
||||||
}
|
}
|
||||||
@ -216,12 +260,12 @@ void Containment::showConfigurationInterface()
|
|||||||
|
|
||||||
Plasma::Applet *Containment::applet() const
|
Plasma::Applet *Containment::applet() const
|
||||||
{
|
{
|
||||||
return m_containment.data();
|
return d->containment.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasma::Containment *Containment::containment() const
|
Plasma::Containment *Containment::containment() const
|
||||||
{
|
{
|
||||||
return m_containment.data();
|
return d->containment.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "containment.moc"
|
#include "containment.moc"
|
||||||
|
@ -42,8 +42,9 @@ class PLASMAGENERICSHELL_EXPORT Containment : public Applet
|
|||||||
Q_PROPERTY(QStringList configKeys READ configKeys)
|
Q_PROPERTY(QStringList configKeys READ configKeys)
|
||||||
Q_PROPERTY(QStringList configGroups READ configGroups)
|
Q_PROPERTY(QStringList configGroups READ configGroups)
|
||||||
Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup)
|
Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup)
|
||||||
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
|
Q_PROPERTY(QString wallpaperPlugin READ wallpaperPlugin WRITE setWallpaperPlugin)
|
||||||
|
Q_PROPERTY(QString wallpaperMode READ wallpaperMode WRITE setWallpaperMode)
|
||||||
Q_PROPERTY(QString type READ type)
|
Q_PROPERTY(QString type READ type)
|
||||||
Q_PROPERTY(QString formFactor READ formFactor)
|
Q_PROPERTY(QString formFactor READ formFactor)
|
||||||
Q_PROPERTY(QList<int> widgetIds READ widgetIds)
|
Q_PROPERTY(QList<int> widgetIds READ widgetIds)
|
||||||
@ -72,6 +73,11 @@ public:
|
|||||||
Plasma::Applet *applet() const;
|
Plasma::Applet *applet() const;
|
||||||
Plasma::Containment *containment() const;
|
Plasma::Containment *containment() const;
|
||||||
|
|
||||||
|
QString wallpaperPlugin() const;
|
||||||
|
void setWallpaperPlugin(const QString &wallpaperPlugin);
|
||||||
|
QString wallpaperMode() const;
|
||||||
|
void setWallpaperMode(const QString &wallpaperMode);
|
||||||
|
|
||||||
static QScriptValue widgetById(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue widgetById(QScriptContext *context, QScriptEngine *engine);
|
||||||
static QScriptValue addWidget(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue addWidget(QScriptContext *context, QScriptEngine *engine);
|
||||||
|
|
||||||
@ -85,7 +91,8 @@ public Q_SLOTS:
|
|||||||
void reloadConfig() { Applet::reloadConfig(); }
|
void reloadConfig() { Applet::reloadConfig(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer<Plasma::Containment> m_containment;
|
class Private;
|
||||||
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user