introduce createConfigurationInterface, it's now the prefered mechanism. showConfigurationInterface remains for the convenience of Applet itself, and remains virtual so as not to break existing applets.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=792927
This commit is contained in:
Aaron J. Seigo 2008-04-02 15:37:17 +00:00
parent def626b080
commit 2558d5c305
2 changed files with 54 additions and 9 deletions

View File

@ -39,11 +39,12 @@
#include <KColorScheme>
#include <KConfigDialog>
#include <KDialog>
#include <KIconLoader>
#include <KPluginInfo>
#include <KStandardDirs>
#include <KService>
#include <KServiceTypeTrader>
#include <KIconLoader>
#include <KWindowSystem>
#include <Solid/PowerManagement>
@ -1296,14 +1297,29 @@ void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void Applet::showConfigurationInterface()
{
if (!hasConfigurationInterface()) {
return;
}
const QString dialogId = QString("%1settings%2").arg(id()).arg(name());
KConfigDialog * dlg = KConfigDialog::exists(dialogId);
if (dlg) {
KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop());
dlg->show();
KWindowSystem::activateWindow(dlg->winId());
return;
}
const QString windowTitle = i18nc("@title:window", "%1 Settings", name());
if (d->package && d->configXml) {
QString uiFile = d->package->filePath("mainconfigui");
if (uiFile.isEmpty()) {
return;
}
KConfigDialog *dialog = new KConfigDialog(0, "", d->configXml);
dialog->setWindowTitle(i18n("%1 Settings", name()));
KConfigDialog *dialog = new KConfigDialog(0, dialogId, d->configXml);
dialog->setWindowTitle(windowTitle);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
QUiLoader loader;
@ -1318,12 +1334,29 @@ void Applet::showConfigurationInterface()
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
dialog->show();
}
else if(d->script) {
} else if (d->script) {
d->script->showConfigurationInterface();
} else {
KConfigSkeleton *nullManager = new KConfigSkeleton(0);
KConfigDialog *dialog = new KConfigDialog(0, dialogId, nullManager);
dialog->setFaceType(KPageDialog::Auto);
dialog->setWindowTitle(windowTitle);
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
createConfigurationInterface(dialog);
//TODO: would be nice to not show dialog if there are no pages added?
connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
dialog->show();
dialog->enableButtonApply(true);
}
}
void Applet::createConfigurationInterface(KConfigDialog *parent)
{
Q_UNUSED(parent)
// virtual method reimplemented by subclasses.
// do not put anything here ...
}
KPluginInfo::List Applet::knownApplets(const QString &category,
const QString &parentApp)
{

View File

@ -25,7 +25,6 @@
#include <QtGui/QWidget>
#include <KDE/KPluginInfo>
#include <KDE/KSharedConfig>
#include <KDE/KGenericFactory>
#include <plasma/configxml.h>
@ -33,6 +32,8 @@
#include <plasma/plasma.h>
#include <plasma/widgets/widget.h>
class KConfigDialog;
namespace Plasma
{
@ -673,14 +674,25 @@ class PLASMA_EXPORT Applet : public Widget
void destroy();
/**
* Reimplement this slot to show a configuration dialog.
*
* Let the user play with the plasmoid options.
* Lets the user interact with the plasmoid options.
* Called when the user selects the configure entry
* from the context menu.
*
* Applets should NOT reimplement this method unless there is good
* reason to do so, but instead reimplment createConfigurationInterface
*/
virtual void showConfigurationInterface();
/**
* Reimplement this method so provide a configuration interface,
* parented to the supplied widget. Ownership of the widgets is passed
* to the parent widget.
*
* @param parent the dialog which is the parent of the configuration
* widgets
*/
virtual void createConfigurationInterface(KConfigDialog *parent);
/**
* Sends all pending contraints updates to the applet. Will usually
* be called automatically, but can also be called manually if needed.