2005-12-29 22:55:22 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2006-2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
2006-01-23 12:37:31 +01:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-29 22:55:22 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_APPLET_H
|
|
|
|
#define PLASMA_APPLET_H
|
|
|
|
|
2007-06-20 08:45:08 +02:00
|
|
|
#include <QtGui/QGraphicsItem>
|
2007-04-22 11:35:04 +02:00
|
|
|
#include <QtGui/QWidget>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-06-17 01:38:56 +02:00
|
|
|
#include <kplugininfo.h>
|
|
|
|
#include <ksharedconfig.h>
|
|
|
|
#include <kgenericfactory.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-30 18:19:07 +02:00
|
|
|
#include <plasma/configxml.h>
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma.h>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <plasma/widgets/widget.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2007-06-02 19:29:39 +02:00
|
|
|
|
2007-09-18 23:22:45 +02:00
|
|
|
class Containment;
|
2007-06-02 19:29:39 +02:00
|
|
|
class DataEngine;
|
2007-07-20 05:34:20 +02:00
|
|
|
class Package;
|
2007-06-02 19:29:39 +02:00
|
|
|
|
2007-05-22 20:29:12 +02:00
|
|
|
/**
|
2007-07-28 21:59:22 +02:00
|
|
|
* @short The base Applet class
|
2007-05-22 20:29:12 +02:00
|
|
|
*
|
2007-07-28 21:59:22 +02:00
|
|
|
* Applet provides several important roles for add-ons widgets in Plasma.
|
2007-05-23 17:47:27 +02:00
|
|
|
*
|
2007-07-28 21:59:22 +02:00
|
|
|
* First, it is the base class for the plugin system and therefore is the
|
|
|
|
* interface to applets for host applications. It also handles the life time
|
|
|
|
* management of data engines (e.g. all data engines accessed via
|
|
|
|
* Applet::datEngine(const QString&) are properly deref'd on Applet
|
|
|
|
* destruction), background painting (allowing for consistent and complex
|
|
|
|
* look and feel in just one line of code for applets), loading and starting
|
|
|
|
* of scripting support for each applet, providing access to the associated
|
|
|
|
* plasmoid package (if any) and access to configuration data.
|
|
|
|
*
|
|
|
|
* See techbase.kde.org for tutorial on writing Applets using this class.
|
2007-05-22 20:29:12 +02:00
|
|
|
*/
|
2007-09-28 07:46:37 +02:00
|
|
|
class PLASMA_EXPORT Applet : public Widget
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2007-07-24 23:04:31 +02:00
|
|
|
// Q_PROPERTY( QRectF maxSizeHint READ maxSizeHint )
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_PROPERTY( bool hasConfigurationInterface READ hasConfigurationInterface WRITE setHasConfigurationInterface )
|
|
|
|
Q_PROPERTY( QString name READ name )
|
|
|
|
Q_PROPERTY( QString category READ category )
|
2007-07-23 02:24:36 +02:00
|
|
|
Q_PROPERTY( bool immutable READ isImmutable WRITE setImmutable )
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_PROPERTY( bool drawStandardBackground READ drawStandardBackground WRITE setDrawStandardBackground )
|
|
|
|
Q_PROPERTY( bool failedToLaunch READ failedToLaunch WRITE setFailedToLaunch )
|
2007-08-03 17:23:56 +02:00
|
|
|
Q_PROPERTY( bool needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring )
|
2007-07-20 23:00:11 +02:00
|
|
|
Q_PROPERTY( QRectF boundingRect READ boundingRect )
|
2007-09-28 07:46:37 +02:00
|
|
|
Q_PROPERTY( QRectF geometry READ geometry WRITE setGeometry )
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef QList<Applet*> List;
|
2007-05-24 22:01:12 +02:00
|
|
|
typedef QHash<QString, Applet*> Dict;
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-05-22 20:29:12 +02:00
|
|
|
/**
|
|
|
|
* @arg parent the QGraphicsItem this applet is parented to
|
|
|
|
* @arg servideId the name of the .desktop file containing the
|
|
|
|
* information about the widget
|
|
|
|
* @arg appletId a unique id used to differentiate between multiple
|
|
|
|
* instances of the same Applet type
|
|
|
|
*/
|
2007-07-12 20:34:53 +02:00
|
|
|
explicit Applet(QGraphicsItem* parent = 0,
|
|
|
|
const QString& serviceId = QString(),
|
|
|
|
uint appletId = 0);
|
2007-05-25 04:36:22 +02:00
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
/**
|
|
|
|
* This constructor is to be used with the plugin loading systems
|
|
|
|
* found in KPluginInfo and KService. The argument list is expected
|
|
|
|
* to have two elements: the KService service ID for the desktop entry
|
|
|
|
* and an applet ID which must be a base 10 number.
|
|
|
|
*
|
|
|
|
* @arg parent a QObject parent; you probably want to pass in 0
|
|
|
|
* @arg args a list of strings containing two entries: the service id
|
|
|
|
* and the applet id
|
|
|
|
*/
|
2007-08-29 04:33:22 +02:00
|
|
|
Applet(QObject* parent, const QVariantList& args);
|
2007-05-24 22:01:12 +02:00
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
~Applet();
|
|
|
|
|
2007-09-13 19:00:57 +02:00
|
|
|
/**
|
|
|
|
* This method is called once the applet is loaded and added to a Corona.
|
|
|
|
* If the applet requires a QGraphicsScene or has an particularly intensive
|
|
|
|
* set of initialization routines to go through, consider implementing it
|
2007-10-19 23:43:27 +02:00
|
|
|
* in this method instead of the constructor.
|
2007-09-13 19:00:57 +02:00
|
|
|
**/
|
|
|
|
virtual void init();
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
/**
|
|
|
|
* @return the id of this applet
|
|
|
|
*/
|
|
|
|
uint id() const;
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
/**
|
2007-05-25 04:36:22 +02:00
|
|
|
* Returns the KConfigGroup to access the applets configuration.
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
2007-05-25 04:36:22 +02:00
|
|
|
* This config object will write to an instance
|
2006-04-13 02:11:16 +02:00
|
|
|
* specific config file named \<appletname\>\<instanceid\>rc
|
2007-05-25 04:36:22 +02:00
|
|
|
* in the Plasma appdata directory.
|
2005-12-29 22:55:22 +01:00
|
|
|
**/
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup config() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a config group with the name provided. This ensures
|
|
|
|
* that the group name is properly namespaced to avoid collision
|
|
|
|
* with other applets that may be sharing this config file
|
|
|
|
*
|
|
|
|
* @param group the name of the group to access
|
|
|
|
**/
|
2007-11-25 00:38:37 +01:00
|
|
|
KConfigGroup config(const QString &group) const;
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-09-18 23:22:45 +02:00
|
|
|
/**
|
|
|
|
* Saves state information about this applet.
|
|
|
|
**/
|
|
|
|
void save(KConfigGroup* group) const;
|
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
/**
|
2007-05-25 04:36:22 +02:00
|
|
|
* Returns a KConfigGroup object to be shared by all applets of this
|
|
|
|
* type.
|
|
|
|
*
|
|
|
|
* This config object will write to an applet-specific config object
|
|
|
|
* named plasma_\<appletname\>rc in the local config directory.
|
2006-04-13 02:11:16 +02:00
|
|
|
*/
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup globalConfig() const;
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-07-30 18:19:07 +02:00
|
|
|
/**
|
|
|
|
* Returns the config skeleton object from this applet's package,
|
|
|
|
* if any.
|
|
|
|
*
|
|
|
|
* @return config skeleton object, or 0 if none
|
|
|
|
**/
|
2007-08-05 11:39:32 +02:00
|
|
|
ConfigXml* configXml() const;
|
2007-07-30 18:19:07 +02:00
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
/**
|
2007-07-11 03:24:43 +02:00
|
|
|
* Loads the given DataEngine
|
2006-04-13 02:11:16 +02:00
|
|
|
*
|
2007-07-11 03:24:43 +02:00
|
|
|
* Tries to load the data engine given by @p name. Each engine is
|
|
|
|
* only loaded once, and that instance is re-used on all subsequent
|
|
|
|
* requests.
|
|
|
|
*
|
|
|
|
* If the data engine was not found, an invalid data engine is returned
|
|
|
|
* (see DataEngine::isValid()).
|
|
|
|
*
|
|
|
|
* Note that you should <em>not</em> delete the returned engine.
|
|
|
|
*
|
|
|
|
* @param name Name of the data engine to load
|
|
|
|
* @return pointer to the data engine if it was loaded,
|
|
|
|
* or an invalid data engine if the requested engine
|
|
|
|
* could not be loaded
|
2006-04-13 02:11:16 +02:00
|
|
|
*/
|
2007-08-05 14:39:13 +02:00
|
|
|
Q_INVOKABLE DataEngine* dataEngine(const QString& name) const;
|
2007-07-20 05:34:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Accessor for the associated Package object if any.
|
|
|
|
* Generally, only Plasmoids come in a Package.
|
|
|
|
*
|
|
|
|
* @return the Package object, or 0 if none
|
|
|
|
**/
|
|
|
|
const Package* package() const;
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
|
|
|
* Called when any of the geometry constraints have been updated.
|
|
|
|
* This method calls constraintsUpdated, which may be reimplemented,
|
|
|
|
* once the Applet has been prepared for updating the constraints.
|
2007-10-02 01:24:38 +02:00
|
|
|
*
|
|
|
|
* @param constraints the type of constraints that were updated
|
2007-08-05 10:41:55 +02:00
|
|
|
*/
|
2007-10-02 01:30:47 +02:00
|
|
|
void updateConstraints(Plasma::Constraints constraints = Plasma::AllConstraints);
|
2007-08-05 10:41:55 +02:00
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Called when any of the geometry constraints have been updated.
|
|
|
|
*
|
|
|
|
* This is always called prior to painting and should be used as an
|
2005-12-29 22:55:22 +01:00
|
|
|
* opportunity to layout the widget, calculate sizings, etc.
|
2007-06-01 00:40:38 +02:00
|
|
|
*
|
|
|
|
* Do not call update() from this method; an update() will be triggered
|
|
|
|
* at the appropriate time for the applet.
|
|
|
|
*
|
2007-10-02 01:24:38 +02:00
|
|
|
* @param constraints the type of constraints that were updated
|
2005-12-29 22:55:22 +01:00
|
|
|
* @property constraint
|
|
|
|
*/
|
2007-10-02 01:24:38 +02:00
|
|
|
virtual void constraintsUpdated(Plasma::Constraints constraints);
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
/**
|
|
|
|
* Returns the current form factor the applet is being displayed in.
|
2007-07-07 00:20:57 +02:00
|
|
|
*
|
2007-06-01 00:40:38 +02:00
|
|
|
* @see Plasma::FormFactor
|
|
|
|
*/
|
2007-09-18 23:22:45 +02:00
|
|
|
virtual FormFactor formFactor() const;
|
2007-06-01 00:40:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the location of the scene which is displaying applet.
|
2007-07-07 00:20:57 +02:00
|
|
|
*
|
2007-06-01 00:40:38 +02:00
|
|
|
* @see Plasma::Location
|
|
|
|
*/
|
2007-09-18 23:22:45 +02:00
|
|
|
virtual Location location() const;
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-06-02 06:47:09 +02:00
|
|
|
/**
|
2007-09-01 14:34:22 +02:00
|
|
|
* Returns the area within which contents can be painted. If there is no
|
|
|
|
* background, then this is equivalent to boundingRect().size()
|
|
|
|
**/
|
|
|
|
QSizeF contentSize() const;
|
2007-07-24 23:04:31 +02:00
|
|
|
|
2007-11-29 21:38:13 +01:00
|
|
|
/**
|
|
|
|
* Sets the content size.
|
|
|
|
*
|
|
|
|
* @note Normally an applet should never
|
|
|
|
* call this directly except in the constructor to provide a default
|
|
|
|
* size
|
|
|
|
*
|
|
|
|
* @arg size the new size of the contents area
|
|
|
|
*/
|
|
|
|
void setContentSize(const QSizeF &size);
|
|
|
|
|
2007-07-24 23:04:31 +02:00
|
|
|
/**
|
2007-09-28 07:46:37 +02:00
|
|
|
* Returns an ideal size for the applet's content.
|
2007-09-01 14:34:22 +02:00
|
|
|
* Applets can re-implement this to provide a suitable size based
|
|
|
|
* on their contents.
|
2007-07-25 21:15:23 +02:00
|
|
|
*
|
2007-09-28 07:46:37 +02:00
|
|
|
* Unlike sizeHint() , contentSizeHint() does not include the
|
|
|
|
* size of any borders surrounding the content area.
|
2007-07-26 01:00:25 +02:00
|
|
|
*
|
2007-09-01 14:34:22 +02:00
|
|
|
* The default implementation returns the sizeHint() of the applet's
|
2007-09-28 07:46:37 +02:00
|
|
|
* layout if it has one, or a null size otherwise.
|
2007-09-01 14:34:22 +02:00
|
|
|
*/
|
|
|
|
virtual QSizeF contentSizeHint() const;
|
2007-06-02 06:47:09 +02:00
|
|
|
|
2007-11-28 22:08:12 +01:00
|
|
|
/**
|
|
|
|
* Sets the minimum size for the content of this applet
|
|
|
|
*/
|
|
|
|
void setMinimumContentSize(const QSizeF &minSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the minimum size for the content of this applet
|
|
|
|
*/
|
|
|
|
QSizeF minimumContentSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the maximum size for the content of this applet.
|
|
|
|
*/
|
|
|
|
void setMaximumContentSize(const QSizeF &maxSize);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the minimum size for the content of this applet
|
|
|
|
*/
|
|
|
|
QSizeF maximumContentSize() const;
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
/**
|
2007-09-18 23:22:45 +02:00
|
|
|
* Returns a list of all known applets.
|
2007-05-24 22:01:12 +02:00
|
|
|
*
|
2007-07-17 23:30:27 +02:00
|
|
|
* @param category Only applets matchin this category will be returned.
|
|
|
|
* Useful in conjunction with knownCategories.
|
2007-09-28 07:46:37 +02:00
|
|
|
* If "Misc" is passed in, then applets without a
|
2007-07-18 00:26:18 +02:00
|
|
|
* Categories= entry are also returned.
|
2007-07-17 23:30:27 +02:00
|
|
|
* If an empty string is passed in, all applets are
|
|
|
|
* returned.
|
2007-09-28 07:46:37 +02:00
|
|
|
* @param parentApp the application to filter applets on. Uses the
|
2007-07-17 23:30:27 +02:00
|
|
|
* X-KDE-ParentApp entry (if any) in the plugin info.
|
|
|
|
* The default value of QString() will result in a
|
|
|
|
* list containing only applets not specifically
|
|
|
|
* registered to an application.
|
2007-05-24 22:01:12 +02:00
|
|
|
* @return list of applets
|
|
|
|
**/
|
2007-07-17 23:30:27 +02:00
|
|
|
static KPluginInfo::List knownApplets(const QString &category = QString(),
|
|
|
|
const QString &parentApp = QString());
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-07-31 12:52:05 +02:00
|
|
|
/**
|
2007-09-18 23:22:45 +02:00
|
|
|
* Returns a list of all known applets associated with a certain mimetype.
|
2007-07-31 12:52:05 +02:00
|
|
|
*
|
|
|
|
* @return list of applets
|
|
|
|
**/
|
2007-07-31 12:56:05 +02:00
|
|
|
static KPluginInfo::List knownAppletsForMimetype(const QString &mimetype);
|
2007-07-31 12:52:05 +02:00
|
|
|
|
2007-07-12 15:24:35 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of all the categories used by
|
|
|
|
* installed applets.
|
2007-07-17 23:30:27 +02:00
|
|
|
*
|
2007-09-28 07:46:37 +02:00
|
|
|
* @param parentApp the application to filter applets on. Uses the
|
2007-07-17 23:30:27 +02:00
|
|
|
* X-KDE-ParentApp entry (if any) in the plugin info.
|
|
|
|
* The default value of QString() will result in a
|
|
|
|
* list containing only applets not specifically
|
|
|
|
* registered to an application.
|
|
|
|
* @return list of categories
|
2007-11-19 10:46:52 +01:00
|
|
|
* @param visibleOnly true if it should only return applets that are marked as visible
|
2007-07-12 15:24:35 +02:00
|
|
|
*/
|
2007-11-19 10:46:52 +01:00
|
|
|
static QStringList knownCategories(const QString &parentApp = QString(), bool visibleOnly = true);
|
2007-07-12 15:24:35 +02:00
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
/**
|
|
|
|
* @return true if this plasmoid provides a GUI configuration
|
|
|
|
**/
|
|
|
|
bool hasConfigurationInterface();
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Attempts to load an applet
|
|
|
|
*
|
|
|
|
* Returns a pointer to the applet if successful.
|
|
|
|
* The caller takes responsibility for the applet, including
|
2007-05-24 22:01:12 +02:00
|
|
|
* deleting it when no longer needed.
|
|
|
|
*
|
|
|
|
* @param name the plugin name, as returned by KPluginInfo::pluginName()
|
|
|
|
* @param applet unique ID to assign the applet, or zero to have one
|
|
|
|
* assigned automatically.
|
2007-06-20 10:11:59 +02:00
|
|
|
* @param args to send the applet extra arguments
|
2007-05-24 22:01:12 +02:00
|
|
|
* @return a pointer to the loaded applet, or 0 on load failure
|
|
|
|
**/
|
2007-06-20 10:11:59 +02:00
|
|
|
static Applet* loadApplet(const QString &name, uint appletId = 0,
|
2007-08-29 04:33:22 +02:00
|
|
|
const QVariantList& args = QVariantList());
|
2007-05-23 17:47:27 +02:00
|
|
|
|
2007-05-24 22:51:59 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Attempts to load an applet
|
|
|
|
*
|
|
|
|
* Returns a pointer to the applet if successful.
|
|
|
|
* The caller takes responsibility for the applet, including
|
2007-05-24 22:51:59 +02:00
|
|
|
* deleting it when no longer needed.
|
|
|
|
*
|
|
|
|
* @param info KPluginInfo object for the desired applet
|
|
|
|
* @param applet unique ID to assign the applet, or zero to have one
|
|
|
|
* assigned automatically.
|
|
|
|
* @return a pointer to the loaded applet, or 0 on load failure
|
|
|
|
**/
|
2007-07-23 01:10:53 +02:00
|
|
|
static Applet* loadApplet(const KPluginInfo& info, uint appletId = 0,
|
2007-08-29 04:33:22 +02:00
|
|
|
const QVariantList& args = QVariantList());
|
2007-05-24 22:51:59 +02:00
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
/**
|
|
|
|
* This method is called when the interface should be painted.
|
2007-07-07 00:20:57 +02:00
|
|
|
*
|
2007-07-24 23:04:31 +02:00
|
|
|
* @param painter the QPainter to use to do the paintiner
|
|
|
|
* @param option the style options object
|
|
|
|
* @param contentsRect the rect to paint within; automatically adjusted for
|
|
|
|
* the background, if any
|
2007-06-22 22:28:42 +02:00
|
|
|
**/
|
|
|
|
virtual void paintInterface(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
2007-07-24 23:04:31 +02:00
|
|
|
const QRect& contentsRect);
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2007-06-05 21:31:48 +02:00
|
|
|
/**
|
|
|
|
* Returns the user-visible name for the applet, as specified in the
|
|
|
|
* .desktop file.
|
2007-07-07 00:20:57 +02:00
|
|
|
*
|
2007-06-05 21:31:48 +02:00
|
|
|
* @return the user-visible name for the applet.
|
|
|
|
**/
|
2007-06-21 20:24:05 +02:00
|
|
|
QString name() const;
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
/**
|
|
|
|
* Returns the plugin name for the applet
|
|
|
|
*/
|
|
|
|
QString pluginName() const;
|
|
|
|
|
2007-07-23 08:12:38 +02:00
|
|
|
/**
|
|
|
|
* Returns the icon related to this applet
|
|
|
|
**/
|
|
|
|
QString icon() const;
|
|
|
|
|
2007-07-12 15:24:35 +02:00
|
|
|
/**
|
|
|
|
* Returns the category the applet is in, as specified in the
|
|
|
|
* .desktop file.
|
|
|
|
*/
|
|
|
|
QString category() const;
|
2007-07-29 01:41:40 +02:00
|
|
|
|
2007-07-27 00:58:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the color corresponding to the applet's category.
|
|
|
|
*/
|
|
|
|
QColor color() const;
|
2007-07-12 15:24:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category of the given applet
|
|
|
|
*
|
|
|
|
* @param a KPluginInfo object for the applet
|
|
|
|
*/
|
2007-07-23 01:10:53 +02:00
|
|
|
static QString category(const KPluginInfo& applet);
|
2007-07-12 15:24:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category of the given applet
|
|
|
|
*
|
|
|
|
* @param the name of the applet
|
|
|
|
*/
|
|
|
|
static QString category(const QString& appletName);
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
/**
|
|
|
|
* @return true if this applet is immutable
|
|
|
|
**/
|
2007-07-23 02:24:36 +02:00
|
|
|
bool isImmutable() const;
|
2007-06-21 20:24:05 +02:00
|
|
|
|
2007-09-28 07:46:37 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Sets whether or not this applet is immutable or not.
|
2007-06-21 20:24:05 +02:00
|
|
|
*
|
2007-07-20 10:06:27 +02:00
|
|
|
* @arg immutable true if this applet should not be changeable
|
2007-06-21 20:24:05 +02:00
|
|
|
**/
|
|
|
|
void setImmutable(bool immutable);
|
2007-06-05 21:31:48 +02:00
|
|
|
|
2007-06-20 08:45:08 +02:00
|
|
|
/**
|
2007-06-22 22:28:42 +02:00
|
|
|
* @return returns whether or not the applet is using the standard
|
|
|
|
* background
|
2007-06-20 08:45:08 +02:00
|
|
|
**/
|
2007-06-22 22:28:42 +02:00
|
|
|
bool drawStandardBackground();
|
|
|
|
|
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Sets whether the applet should automatically draw the standard
|
|
|
|
* background.
|
|
|
|
*
|
2007-11-08 08:53:56 +01:00
|
|
|
* Defaults to true
|
2007-06-22 22:28:42 +02:00
|
|
|
**/
|
|
|
|
void setDrawStandardBackground(bool drawBackground);
|
2007-06-20 08:45:08 +02:00
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
/**
|
|
|
|
* If for some reason, the applet fails to get up on its feet (the
|
|
|
|
* library couldn't be loaded, necessary hardware support wasn't found,
|
|
|
|
* etc..) this method returns true
|
|
|
|
**/
|
|
|
|
bool failedToLaunch() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this method when the applet fails to launch properly. An
|
|
|
|
* optional reason can be provided.
|
|
|
|
*
|
|
|
|
* Not that all children items will be deleted when this method is
|
|
|
|
* called. If you have pointers to these items, you will need to
|
|
|
|
* reset them after calling this method.
|
|
|
|
*
|
|
|
|
* @param failed true when the applet failed, false when it succeeded
|
|
|
|
* @param reason an optional reason to show the user why the applet
|
|
|
|
* failed to launch
|
|
|
|
**/
|
|
|
|
void setFailedToLaunch(bool failed, const QString& reason = QString());
|
|
|
|
|
2007-08-03 17:23:56 +02:00
|
|
|
/**
|
2007-09-28 07:46:37 +02:00
|
|
|
* @return true if the applet currently needs to be configured,
|
2007-08-03 17:23:56 +02:00
|
|
|
* otherwise, false
|
|
|
|
*/
|
|
|
|
bool needsConfiguring() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the applet needs to be configured before being usable, this
|
|
|
|
* method can be called to show a standard interface prompting the user
|
|
|
|
* to configure the applet
|
|
|
|
*
|
|
|
|
* Not that all children items will be deleted when this method is
|
|
|
|
* called. If you have pointers to these items, you will need to
|
|
|
|
* reset them after calling this method.
|
|
|
|
*
|
|
|
|
* @param needsConfiguring true if the applet needs to be configured,
|
|
|
|
* or false if it doesn't
|
|
|
|
*/
|
|
|
|
void setNeedsConfiguring(bool needsConfiguring);
|
2007-06-21 20:07:39 +02:00
|
|
|
enum { Type = Plasma::AppletType };
|
2007-07-20 10:12:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
2007-07-23 00:01:10 +02:00
|
|
|
int type() const;
|
2007-07-20 10:12:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
2007-07-12 20:34:53 +02:00
|
|
|
QRectF boundingRect () const;
|
2007-06-21 20:07:39 +02:00
|
|
|
|
2007-07-31 02:20:19 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of context-related QAction instances.
|
|
|
|
*
|
|
|
|
* This is used e.g. within the \a DesktopView to display a
|
|
|
|
* contextmenu.
|
|
|
|
*
|
|
|
|
* @return A list of actions. The default implementation returns an
|
|
|
|
* empty list.
|
|
|
|
**/
|
|
|
|
virtual QList<QAction*> contextActions();
|
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
|
|
|
* Sets shadow for the given applet.
|
|
|
|
*/
|
|
|
|
void setShadowShown(bool);
|
|
|
|
/**
|
|
|
|
* Returns true if the given item has a shadow shown.
|
|
|
|
*/
|
|
|
|
bool isShadowShown() const;
|
|
|
|
|
2007-09-01 14:34:22 +02:00
|
|
|
// reimplemented from LayoutItem
|
|
|
|
// value is the same as contentSizeHint() if drawStandardBackground() is false
|
2007-09-28 07:46:37 +02:00
|
|
|
// or contentSizeHint() plus the size of the border otherwise.
|
2007-09-01 14:34:22 +02:00
|
|
|
virtual QSizeF sizeHint() const;
|
|
|
|
|
2007-09-28 07:46:37 +02:00
|
|
|
/**
|
2007-11-15 10:39:46 +01:00
|
|
|
* Sets the geometry of this Plasma::Applet
|
|
|
|
* @param geometry the geometry to apply to this Plasma::Applet.
|
|
|
|
*/
|
2007-09-28 07:46:37 +02:00
|
|
|
void setGeometry(const QRectF &geometry);
|
|
|
|
|
2007-11-15 10:39:46 +01:00
|
|
|
/**
|
|
|
|
* Sets whether or not this Applet is acting as a Containment
|
|
|
|
*/
|
|
|
|
void setIsContainment(bool isContainment);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if this Applet is currently being used as a Containment, false otherwise
|
|
|
|
*/
|
|
|
|
bool isContainment() const;
|
|
|
|
|
2007-11-27 07:01:06 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
void resetConfigurationObject();
|
|
|
|
|
2006-01-20 12:09:06 +01:00
|
|
|
Q_SIGNALS:
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Emitted when the applet needs to take (or lose) keyboard focus.
|
|
|
|
*
|
|
|
|
* An applet should emit this signal to ensure that autohiding
|
|
|
|
* elements stay unhidden and other bits of bookkeeping are
|
|
|
|
* performed to ensure proper function.
|
2007-05-27 10:01:31 +02:00
|
|
|
*
|
|
|
|
* If you call watchForFocus on your applet, then this is handled for
|
|
|
|
* the applet and it is not necessary to emit the signal directly.
|
|
|
|
*
|
|
|
|
* @param focus true if the applet is taking keyboard focus, false if
|
|
|
|
* it is giving it up
|
|
|
|
**/
|
2007-03-03 02:41:27 +01:00
|
|
|
void requestFocus( bool focus );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-11-09 01:42:18 +01:00
|
|
|
/**
|
|
|
|
* Emitted whenever the applet makes a geometry change, so that views
|
|
|
|
* can coordinate themselves with these changes if they desire.
|
|
|
|
*/
|
|
|
|
void geometryChanged();
|
|
|
|
|
2007-08-05 11:39:32 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
/**
|
|
|
|
* Destroys the applet; it will be deleted and configurations reset.
|
|
|
|
*/
|
|
|
|
void destroy();
|
|
|
|
|
2007-10-19 23:43:27 +02:00
|
|
|
/**
|
|
|
|
* Reimplement this slot to show a configuration dialog.
|
|
|
|
*
|
|
|
|
* Let the user play with the plasmoid options.
|
|
|
|
* Called when the user selects the configure entry
|
|
|
|
* from the context menu.
|
|
|
|
*/
|
|
|
|
virtual void showConfigurationInterface();
|
|
|
|
|
2007-10-26 03:04:56 +02:00
|
|
|
/**
|
|
|
|
* Sends all pending contraints updates to the applet. Will usually
|
|
|
|
* be called automatically, but can also be called manually if needed.
|
|
|
|
*/
|
|
|
|
void flushUpdatedConstraints();
|
|
|
|
|
2007-11-27 07:01:06 +01:00
|
|
|
/**
|
|
|
|
* @return the Containment, if any, this applet belongs to
|
|
|
|
**/
|
|
|
|
Containment* containment() const;
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
protected:
|
2007-09-18 23:22:45 +02:00
|
|
|
/**
|
|
|
|
* Called when a request to save the state of the applet is made
|
|
|
|
* during runtime
|
|
|
|
**/
|
|
|
|
virtual void saveState(KConfigGroup* config) const;
|
|
|
|
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Returns the name of the applet.
|
|
|
|
*
|
|
|
|
* This will be the same for all instances of this applet.
|
2007-05-27 10:01:31 +02:00
|
|
|
**/
|
2005-12-29 22:55:22 +01:00
|
|
|
QString globalName() const;
|
2007-05-27 10:01:31 +02:00
|
|
|
|
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Returns a name unique to the instance of this applet.
|
|
|
|
*
|
|
|
|
* Useful for being able to refer directly to a particular
|
|
|
|
* applet. Combines the global name with the applet id
|
2007-05-27 10:01:31 +02:00
|
|
|
**/
|
2005-12-29 22:55:22 +01:00
|
|
|
QString instanceName() const;
|
|
|
|
|
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Register widgets that can receive keyboard focus.
|
|
|
|
*
|
|
|
|
* Calling this results in an eventFilter being places on the widget.
|
|
|
|
*
|
2005-12-29 22:55:22 +01:00
|
|
|
* @param widget the widget to watch for keyboard focus
|
|
|
|
* @param watch whether to start watching the widget, or to stop doing so
|
|
|
|
*/
|
2007-03-03 02:41:27 +01:00
|
|
|
void watchForFocus( QObject *widget, bool watch = true );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* Call this whenever focus is needed or not needed.
|
|
|
|
*
|
|
|
|
* You do not have to call this method for widgets that have
|
|
|
|
* been registered with watchForFocus
|
|
|
|
*
|
2005-12-29 22:55:22 +01:00
|
|
|
* @see watchForFocus
|
|
|
|
* @param focus whether to or not to request focus
|
|
|
|
*/
|
2007-06-21 20:24:05 +02:00
|
|
|
void needsFocus(bool focus);
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
/**
|
2007-07-07 00:20:57 +02:00
|
|
|
* 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
|
2007-07-02 12:58:03 +02:00
|
|
|
* also reimplement showConfigurationInterface()
|
2007-07-02 12:47:34 +02:00
|
|
|
*
|
|
|
|
* @arg hasInterface whether or not there is a user interface available
|
|
|
|
**/
|
|
|
|
void setHasConfigurationInterface(bool hasInterface);
|
|
|
|
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
|
|
|
* @internal event filter; used for focus watching
|
|
|
|
**/
|
2007-03-03 02:41:27 +01:00
|
|
|
bool eventFilter( QObject *o, QEvent *e );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-09-27 01:01:57 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
*/
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent);
|
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
2007-11-27 07:01:06 +01:00
|
|
|
* Reimplemented from QGraphicsItem
|
2007-08-05 10:41:55 +02:00
|
|
|
*/
|
|
|
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
|
|
|
|
2007-08-03 17:23:56 +02:00
|
|
|
protected Q_SLOTS:
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
|
|
|
* @internal used to show the configuration of an applet on first show
|
|
|
|
*/
|
2007-08-03 17:23:56 +02:00
|
|
|
void performSetupConfig();
|
|
|
|
|
2007-11-27 07:01:06 +01:00
|
|
|
/**
|
|
|
|
* @internal used to check the immutability of the item in the config file
|
|
|
|
*/
|
|
|
|
void checkImmutability();
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
private:
|
2007-07-20 05:34:20 +02:00
|
|
|
Q_DISABLE_COPY(Applet)
|
|
|
|
|
2007-07-20 10:12:20 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
2007-09-10 20:50:36 +02:00
|
|
|
void paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
class Private;
|
2007-05-21 16:28:03 +02:00
|
|
|
Private* const d;
|
2005-12-29 22:55:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-07-07 00:20:57 +02:00
|
|
|
/**
|
|
|
|
* Register an applet when it is contained in a loadable module
|
|
|
|
*/
|
2007-05-24 22:01:12 +02:00
|
|
|
#define K_EXPORT_PLASMA_APPLET(libname, classname) \
|
2007-08-29 04:33:22 +02:00
|
|
|
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
|
|
|
|
K_EXPORT_PLUGIN(factory("plasma_applet_" #libname))
|
2007-05-24 22:01:12 +02:00
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
#endif // multiple inclusion guard
|