* 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
This commit is contained in:
Petri Damstén 2009-10-23 13:48:29 +00:00
parent d9de800d36
commit 042ed56b39
7 changed files with 63 additions and 6 deletions

View File

@ -1738,6 +1738,7 @@ void Applet::showConfigurationInterface()
} else { } else {
KConfigDialog *dialog = d->generateGenericConfigDialog(); KConfigDialog *dialog = d->generateGenericConfigDialog();
//createConfigurationInterface(dialog); //createConfigurationInterface(dialog);
d->addStandardConfigurationPages(dialog);
dialog->show(); dialog->show();
} }
@ -1789,8 +1790,6 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog()
dialog->setWindowTitle(configWindowTitle()); dialog->setWindowTitle(configWindowTitle());
dialog->setAttribute(Qt::WA_DeleteOnClose, true); dialog->setAttribute(Qt::WA_DeleteOnClose, true);
q->createConfigurationInterface(dialog); q->createConfigurationInterface(dialog);
addGlobalShortcutsPage(dialog);
addPublishPage(dialog);
//TODO: Apply button does not correctly work for now, so do not show it //TODO: Apply button does not correctly work for now, so do not show it
dialog->showButton(KDialog::Apply, false); dialog->showButton(KDialog::Apply, false);
QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished())); QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished()));
@ -1799,6 +1798,12 @@ KConfigDialog *AppletPrivate::generateGenericConfigDialog()
return dialog; return dialog;
} }
void AppletPrivate::addStandardConfigurationPages(KConfigDialog *dialog)
{
addGlobalShortcutsPage(dialog);
addPublishPage(dialog);
}
void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog) void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog)
{ {
if (isContainment) { if (isContainment) {
@ -2137,8 +2142,17 @@ Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &ar
Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args) Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args)
{ {
if (QFile::exists(path + "/metadata.desktop")) { if (QFile::exists(path + "/metadata.desktop")) {
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 new Applet(path, appletId, args);
} }
}
return 0; return 0;
} }

View File

@ -123,6 +123,17 @@ Containment::Containment(QObject *parent, const QVariantList &args)
setHasConfigurationInterface(false); 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() Containment::~Containment()
{ {
delete d; delete d;

View File

@ -593,6 +593,16 @@ class PLASMA_EXPORT Containment : public Applet
AbstractToolBox *toolBox() const; AbstractToolBox *toolBox() const;
private: 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 appletDestroyed(Plasma::Applet*))
Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *, Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *,
Plasma::Animator::Animation anim)) Plasma::Animator::Animation anim))

View File

@ -62,6 +62,17 @@ PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
setAcceptDrops(true); 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() PopupApplet::~PopupApplet()
{ {
delete widget(); delete widget();

View File

@ -152,6 +152,16 @@ protected:
void dropEvent(QGraphicsSceneDragDropEvent *event); void dropEvent(QGraphicsSceneDragDropEvent *event);
private: 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 internalTogglePopup())
Q_PRIVATE_SLOT(d, void hideTimedPopup()) Q_PRIVATE_SLOT(d, void hideTimedPopup())
Q_PRIVATE_SLOT(d, void clearPopupLostFocus()) Q_PRIVATE_SLOT(d, void clearPopupLostFocus())

View File

@ -102,6 +102,7 @@ public:
void clearShortcutEditorPtr(); void clearShortcutEditorPtr();
void configDialogFinished(); void configDialogFinished();
KConfigDialog *generateGenericConfigDialog(); KConfigDialog *generateGenericConfigDialog();
void addStandardConfigurationPages(KConfigDialog *dialog);
QString configDialogId() const; QString configDialogId() const;
QString configWindowTitle() const; QString configWindowTitle() const;
void updateShortcuts(); void updateShortcuts();

View File

@ -143,7 +143,7 @@ KConfigDialog *AppletScript::standardConfigurationDialog()
void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog) void AppletScript::addStandardConfigurationPages(KConfigDialog *dialog)
{ {
if (applet()) { if (applet()) {
applet()->d->addGlobalShortcutsPage(dialog); applet()->d->addStandardConfigurationPages(dialog);
} }
} }