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-04-22 11:35:04 +02:00
|
|
|
#include <QtGui/QGraphicsItemGroup>
|
|
|
|
#include <QtGui/QWidget>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-02-20 08:00:30 +01:00
|
|
|
#include <ksharedconfig.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-05-23 19:25:30 +02:00
|
|
|
#include <plasma.h>
|
|
|
|
#include <dataengine.h>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
2007-05-22 20:29:12 +02:00
|
|
|
/**
|
|
|
|
* @short the base Applet class
|
|
|
|
*
|
2007-05-23 17:47:27 +02:00
|
|
|
*
|
2007-05-22 20:29:12 +02:00
|
|
|
*/
|
2007-05-20 22:13:46 +02:00
|
|
|
class PLASMA_EXPORT Applet : public QWidget, public QGraphicsItemGroup
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef QList<Applet*> List;
|
|
|
|
|
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-03-03 02:41:27 +01:00
|
|
|
Applet( QGraphicsItem* parent,
|
2007-05-21 16:28:03 +02:00
|
|
|
const QString& serviceId,
|
2007-03-05 01:07:21 +01:00
|
|
|
int appletId );
|
2005-12-29 22:55:22 +01:00
|
|
|
~Applet();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the KConfig object to access the applets configuration.
|
|
|
|
*
|
|
|
|
* For unique applets this config object will write to a config file
|
|
|
|
* named \<appletname\>rc in the user's local %KDE directory.
|
|
|
|
*
|
|
|
|
* For normal applets this config object will write to an instance
|
2006-04-13 02:11:16 +02:00
|
|
|
* specific config file named \<appletname\>\<instanceid\>rc
|
2005-12-29 22:55:22 +01:00
|
|
|
* in the user's local %KDE directory.
|
|
|
|
**/
|
|
|
|
KSharedConfig::Ptr appletConfig() const;
|
|
|
|
|
2006-04-13 02:11:16 +02:00
|
|
|
/**
|
|
|
|
* Returns a KConfig object to be shared by all applets of this type
|
|
|
|
* For unique applets, this will return the same config object as
|
|
|
|
* appletConfig()
|
|
|
|
*/
|
|
|
|
KSharedConfig::Ptr globalAppletConfig() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the DataEngine named name is loaded and ready to be used
|
|
|
|
*
|
|
|
|
* @return returns true on success, false on failure
|
|
|
|
*/
|
2007-03-03 02:41:27 +01:00
|
|
|
bool loadDataEngine( 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.
|
|
|
|
* @property constraint
|
|
|
|
*/
|
|
|
|
virtual void constraintsUpdated();
|
|
|
|
|
2007-05-23 17:47:27 +02:00
|
|
|
public Q_SLOTS:
|
|
|
|
virtual void updated(const QString& source, const Plasma::DataEngine::Data&) = 0;
|
|
|
|
|
2006-01-20 12:09:06 +01:00
|
|
|
Q_SIGNALS:
|
2007-03-03 02:41:27 +01:00
|
|
|
void requestFocus( bool focus );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
QString globalName() const;
|
|
|
|
QString instanceName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register widgets that can receive keyboard focus with this this method
|
|
|
|
* 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-03-03 02:41:27 +01:00
|
|
|
void needsFocus( bool focus );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
|
2007-03-03 02:41:27 +01:00
|
|
|
bool eventFilter( QObject *o, QEvent *e );
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
class Private;
|
2007-05-21 16:28:03 +02:00
|
|
|
Private* const d;
|
2005-12-29 22:55:22 +01:00
|
|
|
};
|
|
|
|
|
2007-03-13 04:00:09 +01:00
|
|
|
#define K_EXPORT_PLASMA_APPLET(libname, classname) \
|
|
|
|
K_EXPORT_COMPONENT_FACTORY( \
|
|
|
|
plasmaapplet_##libname, \
|
|
|
|
KGenericFactory<classname>("libplasmaapplet_" #libname))
|
|
|
|
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|