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
|
|
|
*/
|
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "applet.h"
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QApplication>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QList>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QPainter>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QSize>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <KDialog>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KPluginInfo>
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KStandardDirs>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KService>
|
2007-05-24 22:01:12 +02:00
|
|
|
#include <KServiceTypeTrader>
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/dataenginemanager.h"
|
2007-07-20 05:28:34 +02:00
|
|
|
#include "plasma/package.h"
|
|
|
|
#include "plasma/packages_p.h"
|
2007-06-22 22:28:42 +02:00
|
|
|
#include "plasma/plasma.h"
|
|
|
|
#include "plasma/svg.h"
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
#include "plasma/widgets/widget.h"
|
|
|
|
#include "plasma/widgets/lineedit.h"
|
|
|
|
#include "plasma/widgets/vboxlayout.h"
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Applet::Private
|
|
|
|
{
|
2007-07-20 05:28:34 +02:00
|
|
|
public:
|
|
|
|
Private(KService::Ptr service, int uniqueID)
|
|
|
|
: appletId(uniqueID),
|
|
|
|
globalConfig(0),
|
|
|
|
appletConfig(0),
|
2007-07-23 01:10:53 +02:00
|
|
|
appletDescription(service),
|
2007-07-20 05:28:34 +02:00
|
|
|
package(0),
|
|
|
|
background(0),
|
|
|
|
failureText(0),
|
|
|
|
immutable(false),
|
|
|
|
hasConfigurationInterface(false),
|
|
|
|
failed(false)
|
|
|
|
{
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = nextId();
|
|
|
|
}
|
2007-07-12 20:34:53 +02:00
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
if (appletId > s_maxAppletId) {
|
|
|
|
s_maxAppletId = appletId;
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
if (appletDescription.isValid() &&
|
|
|
|
!appletDescription.property("X-Plasma-Language").toString().isEmpty()) {
|
2007-07-20 05:28:34 +02:00
|
|
|
QString path = KStandardDirs::locate("appdata",
|
|
|
|
"plasmoids/" +
|
2007-07-23 01:10:53 +02:00
|
|
|
appletDescription.pluginName());
|
2007-07-20 05:28:34 +02:00
|
|
|
if (!path.isEmpty()) {
|
|
|
|
package = new Package(path,
|
2007-07-23 01:10:53 +02:00
|
|
|
appletDescription.pluginName(),
|
2007-07-20 05:28:34 +02:00
|
|
|
PlasmoidStructure());
|
|
|
|
if (!package->isValid()) {
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-20 05:28:34 +02:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
foreach ( const QString& engine, loadedEngines ) {
|
|
|
|
DataEngineManager::self()->unloadDataEngine( engine );
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
2007-07-20 05:28:34 +02:00
|
|
|
delete background;
|
|
|
|
delete package;
|
|
|
|
}
|
|
|
|
|
2007-07-20 10:12:20 +02:00
|
|
|
void init(Applet* applet)
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!appletDescription.isValid()) {
|
2007-07-20 10:12:20 +02:00
|
|
|
applet->setFailedToLaunch(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
applet->setImmutable(applet->globalConfig().isImmutable() ||
|
|
|
|
applet->config().isImmutable());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
static uint nextId()
|
|
|
|
{
|
|
|
|
++s_maxAppletId;
|
|
|
|
return s_maxAppletId;
|
|
|
|
}
|
2007-05-24 22:01:12 +02:00
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
//TODO: examine the usage of memory here; there's a pretty large
|
|
|
|
// number of members at this point.
|
|
|
|
uint appletId;
|
|
|
|
KSharedConfig::Ptr globalConfig;
|
|
|
|
KSharedConfig::Ptr appletConfig;
|
2007-07-23 01:10:53 +02:00
|
|
|
KPluginInfo appletDescription;
|
2007-07-20 05:28:34 +02:00
|
|
|
Package* package;
|
|
|
|
QList<QObject*> watchedForFocus;
|
|
|
|
QStringList loadedEngines;
|
|
|
|
static uint s_maxAppletId;
|
|
|
|
Plasma::Svg *background;
|
|
|
|
Plasma::LineEdit *failureText;
|
|
|
|
bool immutable : 1;
|
|
|
|
bool hasConfigurationInterface : 1;
|
|
|
|
bool failed : 1;
|
2005-12-29 22:55:22 +01:00
|
|
|
};
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
uint Applet::Private::s_maxAppletId = 0;
|
|
|
|
|
|
|
|
Applet::Applet(QGraphicsItem *parent,
|
|
|
|
const QString& serviceID,
|
2007-07-12 20:34:53 +02:00
|
|
|
uint appletId)
|
2007-07-20 05:28:34 +02:00
|
|
|
: QObject(0),
|
|
|
|
Widget(parent),
|
|
|
|
d(new Private(KService::serviceByStorageId(serviceID), appletId))
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-07-20 10:12:20 +02:00
|
|
|
d->init(this);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
Applet::Applet(QObject* parent, const QStringList& args)
|
|
|
|
: QObject(parent),
|
2007-07-12 20:34:53 +02:00
|
|
|
Widget(0),
|
|
|
|
d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0] : QString()),
|
|
|
|
args.count() > 1 ? args[1].toInt() : 0))
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2007-07-20 10:12:20 +02:00
|
|
|
d->init(this);
|
2007-05-24 22:01:12 +02:00
|
|
|
// the brain damage seen in the initialization list is due to the
|
2007-06-20 08:45:08 +02:00
|
|
|
// inflexibility of KService::createInstance
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
Applet::~Applet()
|
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
needsFocus( false );
|
2005-12-29 22:55:22 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup Applet::config() const
|
2006-04-13 02:11:16 +02:00
|
|
|
{
|
2007-07-18 00:26:18 +02:00
|
|
|
if (!d->appletConfig) {
|
2007-03-03 02:41:27 +01:00
|
|
|
QString file = KStandardDirs::locateLocal( "appdata",
|
2006-12-17 00:04:44 +01:00
|
|
|
"applets/" + instanceName() + "rc",
|
2007-03-03 02:41:27 +01:00
|
|
|
true );
|
|
|
|
d->appletConfig = KSharedConfig::openConfig( file );
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-05-25 04:36:22 +02:00
|
|
|
return KConfigGroup(d->appletConfig, "General");
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup Applet::config(const QString& group) const
|
|
|
|
{
|
|
|
|
KConfigGroup cg = config();
|
2007-07-20 10:06:27 +02:00
|
|
|
cg.changeGroup(instanceName() + '-' + group);
|
2007-07-12 21:14:23 +02:00
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::globalConfig() const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !d->globalConfig ) {
|
|
|
|
QString file = KStandardDirs::locateLocal( "config", "plasma_" + globalName() + "rc" );
|
|
|
|
d->globalConfig = KSharedConfig::openConfig( file );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-05-25 04:36:22 +02:00
|
|
|
return KConfigGroup(d->globalConfig, "General");
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
DataEngine* Applet::dataEngine(const QString& name) const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-06-02 19:29:39 +02:00
|
|
|
int index = d->loadedEngines.indexOf(name);
|
|
|
|
if (index != -1) {
|
|
|
|
return DataEngineManager::self()->dataEngine(name);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
DataEngine* engine = DataEngineManager::self()->loadDataEngine(name);
|
2007-07-11 03:24:43 +02:00
|
|
|
if (engine->isValid()) {
|
2007-06-02 19:29:39 +02:00
|
|
|
d->loadedEngines.append(name);
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-11 03:24:43 +02:00
|
|
|
return engine;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
const Package* Applet::package() const
|
|
|
|
{
|
|
|
|
return d->package;
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
void Applet::constraintsUpdated()
|
|
|
|
{
|
2007-06-02 00:58:48 +02:00
|
|
|
kDebug() << "Applet::constraintsUpdate(): constraints are FormFactor: " << formFactor() << ", Location: " << location() << endl;
|
2007-06-01 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
QString Applet::name() const
|
2007-06-05 21:31:48 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return i18n("Unknown Applet");
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.name();
|
2007-06-05 21:31:48 +02:00
|
|
|
}
|
|
|
|
|
2007-07-12 15:24:35 +02:00
|
|
|
QString Applet::category() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return i18n("Misc");
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
QString Applet::category(const KPluginInfo& applet)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
return applet.property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category(const QString& appletName)
|
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
return offers.first()->property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 02:24:36 +02:00
|
|
|
bool Applet::isImmutable() const
|
2007-06-21 20:24:05 +02:00
|
|
|
{
|
|
|
|
return d->immutable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setImmutable(bool immutable)
|
|
|
|
{
|
|
|
|
d->immutable = immutable;
|
2007-06-23 00:08:04 +02:00
|
|
|
QGraphicsItem::GraphicsItemFlags f = flags();
|
|
|
|
if (immutable) {
|
|
|
|
f ^= QGraphicsItem::ItemIsMovable;
|
2007-07-23 02:24:36 +02:00
|
|
|
} else if (!scene() || !static_cast<Corona*>(scene())->isImmutable()) {
|
2007-06-23 00:08:04 +02:00
|
|
|
f |= QGraphicsItem::ItemIsMovable;
|
|
|
|
}
|
|
|
|
setFlags(f);
|
2007-06-21 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
bool Applet::drawStandardBackground()
|
|
|
|
{
|
|
|
|
return d->background != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setDrawStandardBackground(bool drawBackground)
|
|
|
|
{
|
|
|
|
if (drawBackground) {
|
|
|
|
if (!d->background) {
|
|
|
|
d->background = new Plasma::Svg("widgets/background");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete d->background;
|
|
|
|
d->background = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
bool Applet::failedToLaunch() const
|
|
|
|
{
|
|
|
|
return d->failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString visibleFailureText(const QString& reason)
|
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
if (reason.isEmpty()) {
|
|
|
|
text = i18n("This object could not be created.");
|
|
|
|
} else {
|
2007-07-20 10:06:27 +02:00
|
|
|
text = i18n("This object could not be created for the following reason:<p>%1</p>", reason);
|
2007-07-12 20:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
|
|
|
{
|
|
|
|
if (d->failed == failed) {
|
|
|
|
if (d->failureText) {
|
|
|
|
d->failureText->setHtml(visibleFailureText(reason));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->failed = failed;
|
|
|
|
|
|
|
|
qDeleteAll(QGraphicsItem::children());
|
|
|
|
delete layout();
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
setDrawStandardBackground(failed || d->background != 0);
|
|
|
|
Layout* failureLayout = new VBoxLayout(this);
|
|
|
|
d->failureText = new LineEdit(this, scene());
|
|
|
|
d->failureText->setFlags(0);
|
|
|
|
d->failureText->setHtml(visibleFailureText(reason));
|
|
|
|
failureLayout->addItem(d->failureText);
|
|
|
|
} else {
|
|
|
|
d->failureText = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-07-23 00:01:10 +02:00
|
|
|
int Applet::type() const
|
|
|
|
{
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
QRectF Applet::boundingRect () const
|
|
|
|
{
|
|
|
|
//FIXME: this should be big enough to allow for the failure text?
|
|
|
|
return QRectF(300, 300, 300, 300);
|
|
|
|
}
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2007-06-20 08:45:08 +02:00
|
|
|
void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-06-22 22:28:42 +02:00
|
|
|
{
|
|
|
|
if (d->background) {
|
|
|
|
d->background->resize(boundingRect().size());
|
|
|
|
d->background->paint(painter, boundingRect());
|
|
|
|
}
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
if (d->failed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
paintInterface(painter, option, widget);
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
//TODO: interface overlays on hover
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-06-20 08:45:08 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(painter)
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
FormFactor Applet::formFactor() const
|
|
|
|
{
|
2007-06-02 00:58:48 +02:00
|
|
|
if (!scene()) {
|
|
|
|
return Plasma::Planar;
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
return static_cast<Corona*>(scene())->formFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
Location Applet::location() const
|
|
|
|
{
|
2007-06-02 00:58:48 +02:00
|
|
|
if (!scene()) {
|
|
|
|
return Plasma::Desktop;
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
return static_cast<Corona*>(scene())->location();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::globalName() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.service()->library();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::instanceName() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.service()->library() + QString::number( d->appletId );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 02:09:20 +01:00
|
|
|
void Applet::watchForFocus(QObject *widget, bool watch)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !widget ) {
|
2005-12-29 22:55:22 +01:00
|
|
|
return;
|
2007-03-03 02:41:27 +01:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
int index = d->watchedForFocus.indexOf(widget);
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( watch ) {
|
|
|
|
if ( index == -1 ) {
|
|
|
|
d->watchedForFocus.append( widget );
|
|
|
|
widget->installEventFilter( this );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
2007-03-03 02:41:27 +01:00
|
|
|
} else if ( index != -1 ) {
|
|
|
|
d->watchedForFocus.removeAt( index );
|
|
|
|
widget->removeEventFilter( this );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
void Applet::needsFocus(bool focus)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-05-24 22:01:12 +02:00
|
|
|
if (focus == QGraphicsItem::hasFocus()) {
|
2005-12-29 22:55:22 +01:00
|
|
|
return;
|
2007-03-03 02:41:27 +01:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
emit requestFocus(focus);
|
|
|
|
}
|
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
bool Applet::hasConfigurationInterface()
|
|
|
|
{
|
|
|
|
return d->hasConfigurationInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
|
|
|
d->hasConfigurationInterface = hasInterface;
|
|
|
|
}
|
|
|
|
|
2007-03-03 02:41:27 +01:00
|
|
|
bool Applet::eventFilter( QObject *o, QEvent * e )
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !d->watchedForFocus.contains( o ) )
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( e->type() == QEvent::MouseButtonRelease ||
|
|
|
|
e->type() == QEvent::FocusIn ) {
|
|
|
|
needsFocus( true );
|
|
|
|
} else if ( e->type() == QEvent::FocusOut ) {
|
|
|
|
needsFocus( false );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
return QObject::eventFilter(o, e);
|
|
|
|
}
|
|
|
|
|
2007-07-02 12:58:03 +02:00
|
|
|
void Applet::showConfigurationInterface()
|
2007-07-02 12:47:34 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
KPluginInfo::List Applet::knownApplets(const QString &category,
|
|
|
|
const QString &parentApp)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
|
|
|
}
|
|
|
|
|
2007-07-18 00:26:18 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
|
|
|
if (category == "Misc") {
|
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2007-07-17 23:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2007-07-18 00:26:18 +02:00
|
|
|
//kDebug() << "Applet::knownApplets constraint was '" << constraint << "' which got us " << offers.count() << " matches" << endl;
|
2007-05-24 22:01:12 +02:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
QStringList Applet::knownCategories(const QString &parentApp)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint = "exist [X-KDE-PluginInfo-Category]";
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append(" and not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2007-07-12 15:24:35 +02:00
|
|
|
QStringList categories;
|
|
|
|
foreach (KService::Ptr applet, offers) {
|
2007-07-17 23:30:27 +02:00
|
|
|
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
|
|
|
|
kDebug() << " and we have " << appletCategory << endl;
|
|
|
|
if (appletCategory.isEmpty()) {
|
|
|
|
if (!categories.contains(i18n("Misc"))) {
|
|
|
|
categories << i18n("Misc");
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
} else if (!categories.contains(appletCategory)) {
|
|
|
|
categories << appletCategory;
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
|
|
|
|
categories.sort();
|
2007-07-12 15:24:35 +02:00
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2007-06-20 10:11:59 +02:00
|
|
|
Applet* Applet::loadApplet(const QString& appletName, uint appletId, const QStringList& args)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
//TODO: what would be -really- cool is offer to try and download the applet
|
|
|
|
// from the network at this point
|
|
|
|
kDebug() << "Applet::loadApplet: offers is empty for \"" << appletName << "\"" << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = Private::nextId();
|
|
|
|
}
|
|
|
|
|
2007-06-20 10:11:59 +02:00
|
|
|
QStringList allArgs;
|
2007-05-24 22:01:12 +02:00
|
|
|
QString id;
|
|
|
|
id.setNum(appletId);
|
2007-06-20 10:11:59 +02:00
|
|
|
allArgs << offers.first()->storageId() << id << args;
|
|
|
|
Applet* applet = KService::createInstance<Plasma::Applet>(offers.first(), 0, allArgs);
|
2007-05-24 22:01:12 +02:00
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "Couldn't load applet \"" << appletName << "\"!" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return applet;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
Applet* Applet::loadApplet(const KPluginInfo& info, uint appletId, const QStringList& args)
|
2007-05-24 22:51:59 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!info.isValid()) {
|
2007-05-24 22:51:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return loadApplet(info.pluginName(), appletId, args);
|
2007-05-24 22:51:59 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "applet.moc"
|