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>
|
2008-04-14 12:48:32 +02:00
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
|
|
|
|
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>
|
2008-04-14 18:02:23 +02:00
|
|
|
#include <QtGui/QGraphicsWidget>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2008-03-02 03:18:10 +01:00
|
|
|
#include <KDE/KPluginInfo>
|
|
|
|
#include <KDE/KGenericFactory>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-30 18:19:07 +02:00
|
|
|
#include <plasma/configxml.h>
|
2008-02-15 11:35:00 +01:00
|
|
|
#include <plasma/packagestructure.h>
|
2007-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2008-04-02 17:37:17 +02:00
|
|
|
class KConfigDialog;
|
2008-04-14 18:02:23 +02:00
|
|
|
class QGraphicsView;
|
2008-04-02 17:37:17 +02:00
|
|
|
|
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
|
2007-12-05 23:31:23 +01:00
|
|
|
* Applet::dataEngine(const QString&) are properly deref'd on Applet
|
2007-07-28 21:59:22 +02:00
|
|
|
* 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
|
|
|
*/
|
2008-04-14 18:02:23 +02:00
|
|
|
class PLASMA_EXPORT Applet : public QGraphicsWidget
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2008-04-16 23:15:38 +02:00
|
|
|
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
|
2008-01-10 20:02:05 +01:00
|
|
|
Q_PROPERTY(QString name READ name)
|
|
|
|
Q_PROPERTY(QString category READ category)
|
2008-04-24 20:24:11 +02:00
|
|
|
Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
|
2008-04-16 23:15:38 +02:00
|
|
|
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
|
2008-04-29 04:34:21 +02:00
|
|
|
Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
|
2008-01-10 20:02:05 +01:00
|
|
|
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
|
|
|
|
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
|
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
|
|
|
|
2008-04-26 11:13:57 +02:00
|
|
|
/**
|
|
|
|
* Description on how draw a background for the applet
|
|
|
|
*/
|
|
|
|
enum BackgroundHint { NoBackground = 0 /** Not drawing a background under the applet, the applet has its own implementation */,
|
|
|
|
StandardBackground /** The standard background from the theme is drawn */,
|
|
|
|
ShadowedBackground /** The applet has a drop shadow */,
|
|
|
|
DefaultBackground = StandardBackground | ShadowedBackground /** Default settings: both standard background and shadow */
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
~Applet();
|
|
|
|
|
2008-02-15 11:35:00 +01:00
|
|
|
/**
|
|
|
|
* @return a package structure representing a Theme
|
|
|
|
*/
|
2008-02-26 05:08:51 +01:00
|
|
|
static PackageStructure::Ptr packageStructure();
|
2008-02-15 11:35:00 +01:00
|
|
|
|
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;
|
|
|
|
|
2008-02-13 02:52:02 +01:00
|
|
|
/**
|
|
|
|
* Restores state information about this applet.
|
|
|
|
**/
|
|
|
|
void restore(KConfigGroup* group);
|
|
|
|
|
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
|
|
|
|
**/
|
2008-04-29 04:28:35 +02:00
|
|
|
ConfigXml* configScheme() 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
|
|
|
|
2008-04-14 23:07:25 +02:00
|
|
|
/**
|
|
|
|
* Returns the view this widget is visible on
|
|
|
|
*/
|
|
|
|
QGraphicsView *view() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a QRect from a view's coordinates to local coordinates.
|
|
|
|
* @param view the view from which rect should be mapped
|
|
|
|
* @param rect the rect to be mapped
|
|
|
|
*/
|
|
|
|
QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a QRectF from local coordinates to a view's coordinates.
|
|
|
|
* @param view the view to which rect should be mapped
|
|
|
|
* @param rect the rect to be mapped
|
|
|
|
*/
|
|
|
|
QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recomended position for a popup window like a menu or a tooltip
|
|
|
|
* given its size
|
|
|
|
* @param s size of the popup
|
|
|
|
* @returns recomended position
|
|
|
|
*/
|
|
|
|
QPoint popupPosition(const QSize &s) const;
|
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
|
|
|
* Called when any of the geometry constraints have been updated.
|
2008-04-27 13:04:43 +02:00
|
|
|
* This method calls constraintsEvent, which may be reimplemented,
|
2007-08-05 10:41:55 +02:00
|
|
|
* 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
|
|
|
|
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;
|
2008-05-01 00:13:27 +02:00
|
|
|
|
|
|
|
/**
|
2008-01-10 20:02:05 +01:00
|
|
|
* @return the prefered aspect ratio mode for placement and resizing
|
|
|
|
*/
|
2008-05-01 00:13:27 +02:00
|
|
|
Plasma::AspectRatioMode aspectRatioMode() const;
|
2008-01-10 20:02:05 +01:00
|
|
|
|
|
|
|
/**
|
2008-01-25 01:08:25 +01:00
|
|
|
* Sets the prefered aspect ratio mode for placement and resizing
|
2008-01-10 20:02:05 +01:00
|
|
|
*/
|
2008-05-01 00:13:27 +02:00
|
|
|
void setAspectRatioMode(Plasma::AspectRatioMode);
|
2008-01-25 01:08:25 +01:00
|
|
|
|
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
|
|
|
|
**/
|
2008-04-16 23:15:38 +02:00
|
|
|
static KPluginInfo::List listAppletInfo(const QString &category = QString(),
|
2007-07-17 23:30:27 +02:00
|
|
|
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
|
|
|
|
**/
|
2008-04-16 23:15:38 +02:00
|
|
|
static KPluginInfo::List listAppletInfoForMimetype(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
|
|
|
*/
|
2008-04-16 23:15:38 +02:00
|
|
|
static QStringList listCategories(const QString &parentApp = QString(), bool visibleOnly = true);
|
2007-07-12 15:24:35 +02:00
|
|
|
|
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()
|
2008-03-28 08:42:25 +01:00
|
|
|
* @param appletId unique ID to assign the applet, or zero to have one
|
2007-05-24 22:01:12 +02:00
|
|
|
* 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
|
|
|
|
**/
|
2008-02-26 02:48:52 +01:00
|
|
|
static Applet* load(const QString &name, uint appletId = 0,
|
|
|
|
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
|
2008-03-28 08:42:25 +01:00
|
|
|
* @param appletId unique ID to assign the applet, or zero to have one
|
2007-05-24 22:51:59 +02:00
|
|
|
* assigned automatically.
|
2008-03-28 08:42:25 +01:00
|
|
|
* @param args to send the applet extra arguments
|
2007-05-24 22:51:59 +02:00
|
|
|
* @return a pointer to the loaded applet, or 0 on load failure
|
|
|
|
**/
|
2008-02-26 02:48:52 +01:00
|
|
|
static Applet* load(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
|
|
|
|
2008-01-12 07:02:29 +01:00
|
|
|
/**
|
|
|
|
* Get the category of the given applet
|
|
|
|
*
|
2008-03-28 08:42:25 +01:00
|
|
|
* @param applet a KPluginInfo object for the applet
|
2008-01-12 07:02:29 +01:00
|
|
|
*/
|
|
|
|
static QString category(const KPluginInfo& applet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category of the given applet
|
|
|
|
*
|
2008-03-28 08:42:25 +01:00
|
|
|
* @param appletName the name of the applet
|
2008-01-12 07:02:29 +01:00
|
|
|
*/
|
|
|
|
static QString category(const QString& appletName);
|
|
|
|
|
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;
|
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
/**
|
|
|
|
* @return the font currently set for this widget
|
|
|
|
**/
|
|
|
|
QFont font() const;
|
2008-04-14 17:15:26 +02:00
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
/**
|
|
|
|
* Returns the plugin name for the applet
|
|
|
|
*/
|
|
|
|
QString pluginName() const;
|
|
|
|
|
2007-12-21 13:27:29 +01:00
|
|
|
/**
|
|
|
|
* Whether the applet should conserve resources. If true, try to avoid doing stuff which
|
|
|
|
* is computationally heavy. Try to conserve power and resources.
|
|
|
|
*
|
|
|
|
* @return true if it should conserve resources, false if it does not.
|
|
|
|
*/
|
2007-12-21 13:34:40 +01:00
|
|
|
bool shouldConserveResources() const;
|
2007-12-21 13:27:29 +01:00
|
|
|
|
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-06-21 20:24:05 +02:00
|
|
|
/**
|
2008-04-24 20:24:11 +02:00
|
|
|
* @return The type of immutability of this applet
|
|
|
|
*/
|
|
|
|
ImmutabilityType immutability() const;
|
2007-06-21 20:24:05 +02:00
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
2008-04-13 15:23:39 +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
|
|
|
|
**/
|
2008-04-16 23:15:38 +02:00
|
|
|
bool hasFailedToLaunch() const;
|
2007-07-12 20:34:53 +02:00
|
|
|
|
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
|
|
|
|
*/
|
2008-04-29 04:34:21 +02:00
|
|
|
bool configurationRequired() const;
|
2007-08-03 17:23:56 +02:00
|
|
|
|
2007-07-20 10:12:20 +02:00
|
|
|
/**
|
2008-01-12 07:02:29 +01:00
|
|
|
* @return true if this plasmoid provides a GUI configuration
|
2007-07-20 10:12:20 +02:00
|
|
|
**/
|
2008-04-16 23:15:38 +02:00
|
|
|
bool hasConfigurationInterface() 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.
|
|
|
|
**/
|
2008-04-25 21:55:24 +02:00
|
|
|
virtual QList<QAction*> contextualActions();
|
2007-07-31 02:20:19 +02:00
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
/**
|
2008-04-26 11:13:57 +02:00
|
|
|
* @return BackgroundHints flags combination telling if the standard background is shown
|
|
|
|
* and if it has a drop shadow
|
2007-08-05 10:41:55 +02:00
|
|
|
*/
|
2008-04-26 11:13:57 +02:00
|
|
|
BackgroundHints backgroundHints() const;
|
2007-08-05 10:41:55 +02:00
|
|
|
|
2007-09-28 07:46:37 +02:00
|
|
|
/**
|
2008-01-12 07:02:29 +01:00
|
|
|
* @return true if this Applet is currently being used as a Containment, false otherwise
|
|
|
|
*/
|
2008-04-27 21:05:06 +02:00
|
|
|
bool isContainment() const;
|
2008-01-12 07:02:29 +01:00
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
/**
|
2008-01-12 07:02:29 +01:00
|
|
|
* Sets the geometry of this Plasma::Applet. Should not be used directly by
|
|
|
|
* applet subclasses.
|
2007-11-15 10:39:46 +01:00
|
|
|
* @param geometry the geometry to apply to this Plasma::Applet.
|
|
|
|
*/
|
2007-09-28 07:46:37 +02:00
|
|
|
void setGeometry(const QRectF &geometry);
|
2008-04-14 23:50:41 +02:00
|
|
|
|
2007-11-15 10:39:46 +01:00
|
|
|
/**
|
2008-01-12 07:02:29 +01:00
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
|
|
|
int type() const;
|
|
|
|
enum { Type = Plasma::AppletType };
|
|
|
|
|
2008-01-18 01:09:33 +01:00
|
|
|
/**
|
|
|
|
* @return the Containment, if any, this applet belongs to
|
|
|
|
**/
|
|
|
|
Containment* containment() const;
|
|
|
|
|
2006-01-20 12:09:06 +01:00
|
|
|
Q_SIGNALS:
|
2008-04-25 19:21:24 +02:00
|
|
|
/**
|
|
|
|
* This signal indicates that an application launch, window
|
|
|
|
* creation or window focus event was triggered. This is used, for instance,
|
|
|
|
* to ensure that the Dashboard view in Plasma hides when such an event is
|
|
|
|
* triggered by an item it is displaying.
|
|
|
|
*/
|
2008-04-29 04:28:35 +02:00
|
|
|
void releaseVisualFocus();
|
2008-04-25 19:21:24 +02: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();
|
|
|
|
|
2008-01-01 23:44:56 +01:00
|
|
|
/**
|
|
|
|
* Emitted when an applet has changed values in its configuration
|
|
|
|
* and wishes for them to be saved at the next save point. As this implies
|
|
|
|
* disk activity, this signal should be used with care.
|
|
|
|
*
|
|
|
|
* @note This does not need to be emitted from saveState by individual
|
|
|
|
* applets.
|
|
|
|
*/
|
2008-01-01 23:54:33 +01:00
|
|
|
void configNeedsSaving();
|
2008-01-01 23:44:56 +01:00
|
|
|
|
2007-08-05 11:39:32 +02:00
|
|
|
public Q_SLOTS:
|
2007-12-04 03:17:21 +01:00
|
|
|
/**
|
2008-04-24 20:24:11 +02:00
|
|
|
* Sets the immutability type for this applet (not immutable, user immutable or system immutable)
|
|
|
|
* @arg immutable the new immutability type of this applet
|
|
|
|
*/
|
|
|
|
void setImmutability(const ImmutabilityType immutable);
|
2007-12-04 03:17:21 +01:00
|
|
|
|
2007-08-05 11:39:32 +02:00
|
|
|
/**
|
|
|
|
* Destroys the applet; it will be deleted and configurations reset.
|
|
|
|
*/
|
|
|
|
void destroy();
|
|
|
|
|
2007-10-19 23:43:27 +02:00
|
|
|
/**
|
2008-04-02 17:37:17 +02:00
|
|
|
* Lets the user interact with the plasmoid options.
|
2007-10-19 23:43:27 +02:00
|
|
|
* Called when the user selects the configure entry
|
|
|
|
* from the context menu.
|
|
|
|
*/
|
2008-04-28 23:23:27 +02:00
|
|
|
void showConfigurationInterface();
|
2007-10-19 23:43:27 +02:00
|
|
|
|
2008-04-23 22:27:44 +02:00
|
|
|
/**
|
|
|
|
* Causes this applet to raise above all other applets.
|
|
|
|
*/
|
|
|
|
void raise();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes this applet to lower below all the other applets.
|
|
|
|
*/
|
|
|
|
void lower();
|
2008-04-25 19:21:24 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2008-04-26 19:13:59 +02:00
|
|
|
void flushPendingConstraintsEvents();
|
2007-10-26 03:04:56 +02:00
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
protected:
|
2008-04-26 14:06:18 +02:00
|
|
|
/**
|
|
|
|
* @param parent the QGraphicsItem this applet is parented to
|
|
|
|
* @param serviceId the name of the .desktop file containing the
|
|
|
|
* information about the widget
|
|
|
|
* @param appletId a unique id used to differentiate between multiple
|
|
|
|
* instances of the same Applet type
|
|
|
|
*/
|
|
|
|
explicit Applet(QGraphicsItem* parent = 0,
|
|
|
|
const QString& serviceId = QString(),
|
|
|
|
uint appletId = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
Applet(QObject* parent, const QVariantList& args);
|
|
|
|
|
2008-04-18 18:05:20 +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
|
|
|
|
* in this method instead of the constructor.
|
|
|
|
**/
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-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;
|
|
|
|
|
2008-04-16 23:15:38 +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
|
2008-05-04 01:37:55 +02:00
|
|
|
* also reimplement createConfigurationInterface()
|
2008-04-16 23:15:38 +02:00
|
|
|
*
|
|
|
|
* @param hasInterface whether or not there is a user interface available
|
|
|
|
**/
|
|
|
|
void setHasConfigurationInterface(bool hasInterface);
|
|
|
|
|
2008-04-29 04:35:56 +02:00
|
|
|
/**
|
|
|
|
* 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 setConfigurationRequired(bool needsConfiguring);
|
|
|
|
|
2008-04-28 20:32:34 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2008-04-26 17:52:48 +02:00
|
|
|
/**
|
|
|
|
* Sets whether or not this Applet is acting as a Containment
|
|
|
|
*/
|
2008-04-27 21:05:06 +02:00
|
|
|
void setIsContainment(bool isContainment);
|
2008-04-26 17:52:48 +02:00
|
|
|
|
2008-04-27 13:04:43 +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
|
|
|
|
* opportunity to layout the widget, calculate sizings, etc.
|
|
|
|
*
|
|
|
|
* Do not call update() from this method; an update() will be triggered
|
|
|
|
* at the appropriate time for the applet.
|
|
|
|
*
|
|
|
|
* @param constraints the type of constraints that were updated
|
|
|
|
* @property constraint
|
|
|
|
*/
|
|
|
|
virtual void constraintsEvent(Plasma::Constraints constraints);
|
|
|
|
|
2008-04-26 11:13:57 +02:00
|
|
|
/**
|
|
|
|
* Sets the BackgroundHints for this applet @see BackgroundHint
|
|
|
|
*
|
|
|
|
* @param hints the BackgroundHint combination for this applet
|
|
|
|
*/
|
|
|
|
void setBackgroundHints(const BackgroundHints hints);
|
|
|
|
|
2008-02-21 11:26:40 +01:00
|
|
|
/**
|
2008-04-30 17:04:49 +02:00
|
|
|
* Register the widgets that manage mouse clicks but you still want
|
2008-02-21 11:26:40 +01:00
|
|
|
* to be able to drag the applet around when holding the mouse pointer
|
2008-04-30 17:04:49 +02:00
|
|
|
* on that widget.
|
2008-02-21 11:26:40 +01:00
|
|
|
*
|
|
|
|
* Calling this results in an eventFilter being places on the widget.
|
|
|
|
*
|
2008-04-30 17:04:49 +02:00
|
|
|
* @param item the item to watch for mouse move
|
2008-02-21 11:26:40 +01:00
|
|
|
*/
|
2008-05-02 17:12:52 +02:00
|
|
|
void registerAsDragHandle(QGraphicsItem *item);
|
2008-04-30 17:04:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister a widget registered with registerAsDragHandle.
|
|
|
|
*
|
|
|
|
* @param item the item to unregister
|
|
|
|
*/
|
2008-05-02 17:12:52 +02:00
|
|
|
void unregisterAsDragHandle(QGraphicsItem *item);
|
2008-04-30 17:04:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param item the item to look for if it is registered or not
|
|
|
|
* @return true if it is registered, false otherwise
|
|
|
|
*/
|
2008-05-02 17:12:52 +02:00
|
|
|
bool isRegisteredAsDragHandle(QGraphicsItem *item);
|
2005-12-29 22:55:22 +01:00
|
|
|
|
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 );
|
2007-09-27 01:01:57 +02:00
|
|
|
|
2008-02-21 11:26:40 +01:00
|
|
|
/**
|
|
|
|
* @internal scene event filter; used to manage applet dragging
|
|
|
|
*/
|
|
|
|
bool sceneEventFilter ( QGraphicsItem * watched, QEvent * event );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal manage the mouse movement to drag the applet around
|
|
|
|
*/
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
/**
|
|
|
|
* @internal manage the mouse movement to drag the applet around
|
|
|
|
*/
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
|
2008-04-14 23:07:25 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
*/
|
|
|
|
void focusInEvent(QFocusEvent * event);
|
|
|
|
|
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);
|
|
|
|
|
2008-04-29 22:31:18 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsLayoutItem
|
|
|
|
*/
|
|
|
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
private:
|
2007-07-20 05:34:20 +02:00
|
|
|
Q_DISABLE_COPY(Applet)
|
2008-04-28 17:41:18 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void checkImmutability())
|
2008-04-28 17:55:13 +02:00
|
|
|
Q_PRIVATE_SLOT(d, void themeChanged())
|
2007-07-20 05:34:20 +02:00
|
|
|
|
2007-07-20 10:12:20 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
2008-04-14 16:50:02 +02:00
|
|
|
void paint(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;
|
2008-04-18 18:05:20 +02:00
|
|
|
|
|
|
|
//Corona needs to access setFailedToLaunch and init
|
|
|
|
friend class Corona;
|
|
|
|
friend class Containment;
|
2008-04-29 05:05:31 +02:00
|
|
|
friend class AppletScript;
|
2005-12-29 22:55:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2008-04-26 11:13:57 +02:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
|
|
|
|
|
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
|