allow applets to note whether or not they provide a configure interface

and pay attention to that when creating the context menu

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=682287
This commit is contained in:
Aaron J. Seigo 2007-07-02 10:47:34 +00:00
parent 32ea32d1c7
commit 8e6578bf18
3 changed files with 46 additions and 7 deletions

View File

@ -45,6 +45,7 @@ class Applet::Private
appletConfig( 0 ),
appletDescription(new KPluginInfo(appletDescription)),
immutable(false),
hasConfigurationInterface(false),
background(0)
{
if (appletId > s_maxAppletId) {
@ -75,6 +76,7 @@ class Applet::Private
QStringList loadedEngines;
static uint s_maxAppletId;
bool immutable;
bool hasConfigurationInterface;
Plasma::Svg *background;
};
@ -269,6 +271,16 @@ void Applet::needsFocus(bool focus)
emit requestFocus(focus);
}
bool Applet::hasConfigurationInterface()
{
return d->hasConfigurationInterface;
}
void Applet::setHasConfigurationInterface(bool hasInterface)
{
d->hasConfigurationInterface = hasInterface;
}
bool Applet::eventFilter( QObject *o, QEvent * e )
{
if ( !d->watchedForFocus.contains( o ) )
@ -284,6 +296,10 @@ bool Applet::eventFilter( QObject *o, QEvent * e )
return QObject::eventFilter(o, e);
}
void Applet::configureDialog()
{
}
KPluginInfo::List Applet::knownApplets()
{
QHash<QString, KPluginInfo> applets;

View File

@ -135,12 +135,17 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
**/
static KPluginInfo::List knownApplets();
/**
* @return true if this plasmoid provides a GUI configuration
**/
bool hasConfigurationInterface();
/**
* Reimplement this slot to show a configuration dialog and let the user
* play with the plasmoid options. Called when the user selects the configure entry
* from the contextual menu.
* from the context menu.
*/
virtual void configureDialog(){} //default implementation is empty
virtual void configureDialog();
/**
* Attempts to load an applet, returning a pointer to the applet if
@ -259,6 +264,15 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
*/
void needsFocus(bool focus);
/**
* Sets whether or not this applet provides a user interface for configuring
* the applet. It defaults to false, and if true is passed in you should
* also reimplement configureDialog()
*
* @arg hasInterface whether or not there is a user interface available
**/
void setHasConfigurationInterface(bool hasInterface);
/**
* @internal event filter; used for focus watching
**/

View File

@ -313,17 +313,26 @@ void Corona::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
} else if (applet->immutable()) {
return;
} else {
desktopMenu.addSeparator();
QAction* configureApplet = new QAction(i18n("Settings..."), this);
//desktopMenu.addSeparator();
bool hasEntries = false;
if (applet->hasConfigurationInterface()) {
QAction* configureApplet = new QAction(i18n("%1 Settings...", applet->name()), this);
connect(configureApplet, SIGNAL(triggered(bool)),
applet, SLOT(configureDialog())); //This isn't implemented in Applet yet...
applet, SLOT(configureDialog()));
desktopMenu.addAction(configureApplet);
hasEntries = true;
}
if (!d->immutable) {
QAction* closeApplet = new QAction(i18n("Close"), this);
QAction* closeApplet = new QAction(i18n("Close this %1", applet->name()), this);
connect(closeApplet, SIGNAL(triggered(bool)),
applet, SLOT(deleteLater()));
desktopMenu.addAction(closeApplet);
hasEntries = true;
}
if (!hasEntries) {
return;
}
}
desktopMenu.exec(point.toPoint());