2005-12-29 22:55:22 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* 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-06-02 19:29:39 +02:00
|
|
|
#include <plasma/plasma.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2007-06-02 19:29:39 +02:00
|
|
|
|
|
|
|
class DataEngine;
|
|
|
|
|
2007-05-22 20:29:12 +02:00
|
|
|
/**
|
2007-05-24 00:45:21 +02:00
|
|
|
* @short The base Applet (Plasmoid) class
|
2007-05-22 20:29:12 +02:00
|
|
|
*
|
2007-05-23 17:47:27 +02:00
|
|
|
*
|
2007-05-22 20:29:12 +02:00
|
|
|
*/
|
2007-06-20 08:45:08 +02:00
|
|
|
class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
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-05-24 22:01:12 +02:00
|
|
|
Applet(QGraphicsItem* parent,
|
|
|
|
const QString& serviceId,
|
|
|
|
int appletId);
|
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
|
|
|
|
*/
|
|
|
|
Applet(QObject* parent, const QStringList& args);
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
~Applet();
|
|
|
|
|
|
|
|
/**
|
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-05-25 04:36:22 +02:00
|
|
|
KConfigGroup appletConfig() const;
|
2005-12-29 22:55:22 +01:00
|
|
|
|
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-05-25 04:36:22 +02:00
|
|
|
KConfigGroup globalAppletConfig() const;
|
2006-04-13 02:11:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the DataEngine named name is loaded and ready to be used
|
|
|
|
*
|
|
|
|
* @return returns true on success, false on failure
|
|
|
|
*/
|
2007-06-02 19:29:39 +02:00
|
|
|
DataEngine* dataEngine(const QString& name);
|
2006-04-13 02:11:16 +02:00
|
|
|
|
|
|
|
/**
|
2005-12-29 22:55:22 +01: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.
|
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.
|
|
|
|
*
|
2005-12-29 22:55:22 +01:00
|
|
|
* @property constraint
|
|
|
|
*/
|
|
|
|
virtual void constraintsUpdated();
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
/**
|
|
|
|
* Returns the current form factor the applet is being displayed in.
|
|
|
|
* @see Plasma::FormFactor
|
|
|
|
*/
|
|
|
|
FormFactor formFactor() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the location of the scene which is displaying applet.
|
|
|
|
* @see Plasma::Location
|
|
|
|
*/
|
|
|
|
Location location() const;
|
|
|
|
|
2007-06-02 06:47:09 +02:00
|
|
|
/**
|
|
|
|
* Returns a maximum size hint based on the Corona's space availability
|
|
|
|
* An applet may choose to violate this size hint, but should try and
|
|
|
|
* respect it as much as possible.
|
|
|
|
*/
|
|
|
|
QRectF maxSizeHint() const;
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of all known applets in a hash keyed by a unique
|
|
|
|
* identifier for each applet
|
|
|
|
*
|
|
|
|
* @return list of applets
|
|
|
|
**/
|
|
|
|
static KPluginInfo::List knownApplets();
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
/**
|
|
|
|
* @return true if this plasmoid provides a GUI configuration
|
|
|
|
**/
|
|
|
|
bool hasConfigurationInterface();
|
|
|
|
|
2007-05-26 21:01:32 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2007-07-02 12:47:34 +02:00
|
|
|
* from the context menu.
|
2007-05-26 21:01:32 +02:00
|
|
|
*/
|
2007-07-02 12:58:03 +02:00
|
|
|
virtual void showConfigurationInterface();
|
2007-05-24 22:01:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to load an applet, returning a pointer to the applet if
|
|
|
|
* successful. The caller takes responsibility for the applet, including
|
|
|
|
* 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,
|
|
|
|
const QStringList& args = QStringList());
|
2007-05-23 17:47:27 +02:00
|
|
|
|
2007-05-24 22:51:59 +02:00
|
|
|
/**
|
|
|
|
* Attempts to load an applet, returning a pointer to the applet if
|
|
|
|
* successful. The caller takes responsibility for the applet, including
|
|
|
|
* 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-06-20 10:11:59 +02:00
|
|
|
static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0,
|
|
|
|
const QStringList& args = QStringList());
|
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.
|
|
|
|
* @see QGraphicsItem::paint
|
|
|
|
**/
|
|
|
|
virtual void paintInterface(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget = 0);
|
|
|
|
|
2007-06-05 21:31:48 +02:00
|
|
|
/**
|
|
|
|
* Returns the user-visible name for the applet, as specified in the
|
|
|
|
* .desktop file.
|
|
|
|
* @return the user-visible name for the applet.
|
|
|
|
**/
|
2007-06-21 20:24:05 +02:00
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if this applet is immutable
|
|
|
|
**/
|
|
|
|
bool immutable() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether or not this applet is immutable or not
|
|
|
|
*
|
|
|
|
* @arg immutable true if this applet should not be changable
|
|
|
|
**/
|
|
|
|
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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets whether or not the applet should automatically draw the standard
|
|
|
|
* background or not. Defaults to false
|
|
|
|
**/
|
|
|
|
void setDrawStandardBackground(bool drawBackground);
|
2007-06-20 08:45:08 +02:00
|
|
|
|
2007-06-21 20:07:39 +02:00
|
|
|
/**
|
|
|
|
* Reimplented from QGraphicsItem
|
|
|
|
**/
|
|
|
|
enum { Type = Plasma::AppletType };
|
|
|
|
int type() const { return Type; }
|
|
|
|
|
2006-01-20 12:09:06 +01:00
|
|
|
Q_SIGNALS:
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
|
|
|
* Emit this signal when your applet needs to take (or lose) keyboard
|
|
|
|
* focus. This ensures that autohiding elements stay unhidden and other
|
|
|
|
* bits of bookkeeping are performed to ensure proper function.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
protected:
|
2007-05-27 10:01:31 +02:00
|
|
|
/**
|
|
|
|
* Returns the name of the applet. This will be the same for all
|
|
|
|
* instances of this applet.
|
|
|
|
**/
|
2005-12-29 22:55:22 +01:00
|
|
|
QString globalName() const;
|
2007-05-27 10:01:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a name unique to the insane of this applet. Useful for
|
|
|
|
* being able to refer directly to a particular applet. Combines the
|
|
|
|
* global name with the applet id
|
|
|
|
**/
|
2005-12-29 22:55:22 +01:00
|
|
|
QString instanceName() const;
|
|
|
|
|
|
|
|
/**
|
2007-05-27 10:01:31 +02:00
|
|
|
* Register widgets that can receive keyboard focus with this method
|
2005-12-29 22:55:22 +01:00
|
|
|
* This call results in an eventFilter being places on the widget.
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @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
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
private:
|
2007-06-22 22:28:42 +02:00
|
|
|
/**
|
|
|
|
* Reimplemented from QGraphicsItem
|
|
|
|
**/
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
void init();
|
|
|
|
|
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-05-24 22:01:12 +02:00
|
|
|
#define K_EXPORT_PLASMA_APPLET(libname, classname) \
|
|
|
|
K_EXPORT_COMPONENT_FACTORY( \
|
|
|
|
plasma_applet_##libname, \
|
|
|
|
KGenericFactory<classname>("plasma_applet_" #libname))
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
#endif // multiple inclusion guard
|
2007-05-24 22:01:12 +02:00
|
|
|
|