From 042ed56b39f6853dfa8c5ccc960b062e23452aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20Damst=C3=A9n?= Date: Fri, 23 Oct 2009 13:48:29 +0000 Subject: [PATCH] * Add support to load PopupApplet and Containment from path * AppletScript::addStandardConfigurationPages adds also publish page * AppletScript::standardConfigurationDialog does not add standard pages (there is addStandardConfigurationPages) svn path=/trunk/KDE/kdelibs/; revision=1039471 --- applet.cpp | 20 +++++++++++++++++--- containment.cpp | 11 +++++++++++ containment.h | 10 ++++++++++ popupapplet.cpp | 11 +++++++++++ popupapplet.h | 14 ++++++++++++-- private/applet_p.h | 1 + scripting/appletscript.cpp | 2 +- 7 files changed, 63 insertions(+), 6 deletions(-) diff --git a/applet.cpp b/applet.cpp index a321278b0..5e8135406 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1738,6 +1738,7 @@ void Applet::showConfigurationInterface() } else { KConfigDialog *dialog = d->generateGenericConfigDialog(); //createConfigurationInterface(dialog); + d->addStandardConfigurationPages(dialog); dialog->show(); } @@ -1789,8 +1790,6 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog() dialog->setWindowTitle(configWindowTitle()); dialog->setAttribute(Qt::WA_DeleteOnClose, true); q->createConfigurationInterface(dialog); - addGlobalShortcutsPage(dialog); - addPublishPage(dialog); //TODO: Apply button does not correctly work for now, so do not show it dialog->showButton(KDialog::Apply, false); QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished())); @@ -1799,6 +1798,12 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog() return dialog; } +void AppletPrivate::addStandardConfigurationPages(KConfigDialog *dialog) +{ + addGlobalShortcutsPage(dialog); + addPublishPage(dialog); +} + void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog) { if (isContainment) { @@ -2137,7 +2142,16 @@ Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &ar Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args) { if (QFile::exists(path + "/metadata.desktop")) { - return new Applet(path, appletId, args); + KService service(path + "/metadata.desktop"); + const QStringList& types = service.serviceTypes(); + + if (types.contains("Plasma/Containment")) { + return new Containment(path, appletId, args); + } else if (types.contains("Plasma/PopupApplet")) { + return new PopupApplet(path, appletId, args); + } else { + return new Applet(path, appletId, args); + } } return 0; diff --git a/containment.cpp b/containment.cpp index 86bf8770d..fed7e3e0e 100644 --- a/containment.cpp +++ b/containment.cpp @@ -123,6 +123,17 @@ Containment::Containment(QObject *parent, const QVariantList &args) setHasConfigurationInterface(false); } +Containment::Containment(const QString &packagePath, uint appletId, const QVariantList &args) + : Plasma::Applet(packagePath, appletId, args), + d(new ContainmentPrivate(this)) +{ + // WARNING: do not access config() OR globalConfig() in this method! + // that requires a scene, which is not available at this point + setPos(0, 0); + setBackgroundHints(NoBackground); + setHasConfigurationInterface(false); +} + Containment::~Containment() { delete d; diff --git a/containment.h b/containment.h index c441a5cec..e69c4a5a4 100644 --- a/containment.h +++ b/containment.h @@ -593,6 +593,16 @@ class PLASMA_EXPORT Containment : public Applet AbstractToolBox *toolBox() const; private: + /** + * @internal This constructor is to be used with the Package loading system. + * + * @param parent a QObject parent; you probably want to pass in 0 + * @param args a list of strings containing two entries: the service id + * and the applet id + * @since 4.3 + */ + Containment(const QString &packagePath, uint appletId, const QVariantList &args); + Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *, Plasma::Animator::Animation anim)) diff --git a/popupapplet.cpp b/popupapplet.cpp index 4559427ec..b891050c7 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -62,6 +62,17 @@ PopupApplet::PopupApplet(QObject *parent, const QVariantList &args) setAcceptDrops(true); } +PopupApplet::PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args) + : Plasma::Applet(packagePath, appletId, args), + d(new PopupAppletPrivate(this)) +{ + int iconSize = IconSize(KIconLoader::Desktop); + resize(iconSize, iconSize); + disconnect(this, SIGNAL(activate()), (Applet*)this, SLOT(setFocus())); + connect(this, SIGNAL(activate()), this, SLOT(internalTogglePopup())); + setAcceptDrops(true); +} + PopupApplet::~PopupApplet() { delete widget(); diff --git a/popupapplet.h b/popupapplet.h index 656b87325..590fee37a 100644 --- a/popupapplet.h +++ b/popupapplet.h @@ -45,7 +45,7 @@ class PopupAppletPrivate; * * If you use this class as a base class for your extender using applet, the extender will * automatically be used for the popup; reimplementing graphicsWidget() is unnecessary in this case. - * If you need a popup that does not steal window focus when openend or used, set window flag + * If you need a popup that does not steal window focus when openend or used, set window flag * Qt::X11BypassWindowManagerHint the widget returned by widget() or graphicsWidget(). */ @@ -100,7 +100,7 @@ public: /** * Sets whether or not the dialog popup that gets created should be a "passive" popup - * that does not steal focus from other windows or not. + * that does not steal focus from other windows or not. * * @arg passive true if the dialog should be treated as a passive popup */ @@ -152,6 +152,16 @@ protected: void dropEvent(QGraphicsSceneDragDropEvent *event); private: + /** + * @internal This constructor is to be used with the Package loading system. + * + * @param parent a QObject parent; you probably want to pass in 0 + * @param args a list of strings containing two entries: the service id + * and the applet id + * @since 4.3 + */ + PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args); + Q_PRIVATE_SLOT(d, void internalTogglePopup()) Q_PRIVATE_SLOT(d, void hideTimedPopup()) Q_PRIVATE_SLOT(d, void clearPopupLostFocus()) diff --git a/private/applet_p.h b/private/applet_p.h index 8333b172a..0eb30ff59 100644 --- a/private/applet_p.h +++ b/private/applet_p.h @@ -102,6 +102,7 @@ public: void clearShortcutEditorPtr(); void configDialogFinished(); KConfigDialog *generateGenericConfigDialog(); + void addStandardConfigurationPages(KConfigDialog *dialog); QString configDialogId() const; QString configWindowTitle() const; void updateShortcuts(); diff --git a/scripting/appletscript.cpp b/scripting/appletscript.cpp index fb7e20ded..d9477c7cd 100644 --- a/scripting/appletscript.cpp +++ b/scripting/appletscript.cpp @@ -143,7 +143,7 @@ KConfigDialog *AppletScript::standardConfigurationDialog() void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog) { if (applet()) { - applet()->d->addGlobalShortcutsPage(dialog); + applet()->d->addStandardConfigurationPages(dialog); } }