2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2009-08-18 00:31:18 +02:00
|
|
|
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "applet.h"
|
|
|
|
#include "private/applet_p.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QGraphicsGridLayout>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsView>
|
2009-09-03 01:49:58 +02:00
|
|
|
#include <QHostInfo>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QList>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QPainter>
|
2009-10-29 10:09:01 +01:00
|
|
|
#include <QRegExp>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QSize>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QUiLoader>
|
2008-11-15 22:23:56 +01:00
|
|
|
#include <QVBoxLayout>
|
2008-11-06 16:52:13 +01:00
|
|
|
#include <QWidget>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kaction.h>
|
2008-11-15 22:23:56 +01:00
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kauthorized.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kcolorscheme.h>
|
|
|
|
#include <kconfigdialog.h>
|
|
|
|
#include <kdialog.h>
|
2008-11-15 22:23:56 +01:00
|
|
|
#include <kicon.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kiconloader.h>
|
2008-11-15 22:23:56 +01:00
|
|
|
#include <kkeysequencewidget.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kplugininfo.h>
|
|
|
|
#include <kstandarddirs.h>
|
|
|
|
#include <kservice.h>
|
|
|
|
#include <kservicetypetrader.h>
|
|
|
|
#include <kshortcut.h>
|
|
|
|
#include <kwindowsystem.h>
|
2008-11-23 15:09:45 +01:00
|
|
|
#include <kpushbutton.h>
|
2009-09-16 19:08:45 +02:00
|
|
|
#include <krun.h>
|
|
|
|
#include "kio/jobclasses.h" // for KIO::JobFlags
|
|
|
|
#include "kio/job.h"
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <solid/powermanagement.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "authorizationmanager.h"
|
2009-09-04 02:08:26 +02:00
|
|
|
#include "authorizationrule.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "configloader.h"
|
|
|
|
#include "containment.h"
|
|
|
|
#include "corona.h"
|
|
|
|
#include "dataenginemanager.h"
|
2009-09-12 02:19:42 +02:00
|
|
|
#include "dialog.h"
|
2009-09-03 23:53:56 +02:00
|
|
|
#include "extenders/extender.h"
|
|
|
|
#include "extenders/extenderitem.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "package.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
#include "scripting/appletscript.h"
|
|
|
|
#include "svg.h"
|
|
|
|
#include "framesvg.h"
|
|
|
|
#include "popupapplet.h"
|
2009-10-28 19:06:56 +01:00
|
|
|
#include "private/framesvg_p.h"
|
|
|
|
#include "private/applethandle_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "theme.h"
|
|
|
|
#include "view.h"
|
|
|
|
#include "widgets/iconwidget.h"
|
|
|
|
#include "widgets/label.h"
|
|
|
|
#include "widgets/pushbutton.h"
|
2008-11-04 19:22:55 +01:00
|
|
|
#include "widgets/busywidget.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "tooltipmanager.h"
|
|
|
|
#include "wallpaper.h"
|
2009-02-02 20:39:41 +01:00
|
|
|
#include "paintutils.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-10-20 21:15:32 +02:00
|
|
|
#include "private/associatedapplicationmanager_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/authorizationmanager_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/containment_p.h"
|
|
|
|
#include "private/extenderapplet_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/package_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/packages_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/plasmoidservice.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/popupapplet_p.h"
|
2009-10-20 21:15:32 +02:00
|
|
|
#include "private/remotedataengine_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "private/service_p.h"
|
2009-10-20 16:14:53 +02:00
|
|
|
#include "private/internaltoolbox_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "ui_publish.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-09 17:37:03 +02:00
|
|
|
#include "config-plasma.h"
|
2009-09-09 15:40:16 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2009-04-26 02:43:20 +02:00
|
|
|
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
|
2008-11-04 00:08:39 +01:00
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(serviceID), appletId, this))
|
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
d->init();
|
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
Applet::Applet(QGraphicsItem *parent,
|
|
|
|
const QString &serviceID,
|
|
|
|
uint appletId,
|
|
|
|
const QVariantList &args)
|
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(serviceID), appletId, this))
|
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
|
|
|
|
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
d->args = mutableArgs;
|
|
|
|
|
|
|
|
d->init();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet::Applet(QObject *parentObject, const QVariantList &args)
|
|
|
|
: QGraphicsWidget(0),
|
|
|
|
d(new AppletPrivate(
|
|
|
|
KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()),
|
|
|
|
args.count() > 1 ? args[1].toInt() : 0, this))
|
|
|
|
{
|
|
|
|
// now remove those first two items since those are managed by Applet and subclasses shouldn't
|
|
|
|
// need to worry about them. yes, it violates the constness of this var, but it lets us add
|
|
|
|
// or remove items later while applets can just pretend that their args always start at 0
|
|
|
|
QVariantList &mutableArgs = const_cast<QVariantList &>(args);
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
d->args = mutableArgs;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
setParent(parentObject);
|
2009-01-13 22:46:07 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
d->init();
|
|
|
|
|
|
|
|
// the brain damage seen in the initialization list is due to the
|
|
|
|
// inflexibility of KService::createInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::~Applet()
|
|
|
|
{
|
2009-01-28 08:58:17 +01:00
|
|
|
//let people know that i will die
|
|
|
|
emit appletDestroyed(this);
|
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
if (!d->transient && d->extender) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//This would probably be nicer if it was located in extender. But in it's dtor, this won't
|
|
|
|
//work since when that get's called, the applet's config() isn't accessible anymore. (same
|
|
|
|
//problem with calling saveState(). Doing this in saveState() might be a possibility, but
|
|
|
|
//that would require every extender savestate implementation to call it's parent function,
|
|
|
|
//which isn't very nice.
|
2009-01-16 19:49:54 +01:00
|
|
|
d->extender->saveState();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (ExtenderItem *item, d->extender->attachedItems()) {
|
2009-01-16 19:49:54 +01:00
|
|
|
if (item->autoExpireDelay()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//destroy temporary extender items, or items that aren't detached, so their
|
|
|
|
//configuration won't linger after a plasma restart.
|
|
|
|
item->destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 03:32:48 +01:00
|
|
|
// clean up our config dialog, if any
|
2009-02-24 03:34:57 +01:00
|
|
|
delete KConfigDialog::exists(d->configDialogId());
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageStructure::Ptr Applet::packageStructure()
|
|
|
|
{
|
|
|
|
if (!AppletPrivate::packageStructure) {
|
|
|
|
AppletPrivate::packageStructure = new PlasmoidPackage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppletPrivate::packageStructure;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::init()
|
|
|
|
{
|
2009-06-12 17:20:54 +02:00
|
|
|
if (d->script) {
|
2009-11-11 20:26:05 +01:00
|
|
|
d->setupScriptSupport();
|
2009-11-11 02:54:00 +01:00
|
|
|
|
|
|
|
if (!d->script->init() && !d->failed) {
|
2009-06-12 17:20:54 +02:00
|
|
|
setFailedToLaunch(true, i18n("Script initialization failed"));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint Applet::id() const
|
|
|
|
{
|
|
|
|
return d->appletId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::save(KConfigGroup &g) const
|
|
|
|
{
|
2008-12-18 23:14:06 +01:00
|
|
|
if (d->transient) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup group = g;
|
|
|
|
if (!group.isValid()) {
|
|
|
|
group = *d->mainConfigGroup();
|
|
|
|
}
|
|
|
|
|
2008-12-12 02:05:00 +01:00
|
|
|
//kDebug() << "saving to" << group.name();
|
2008-11-04 00:08:39 +01:00
|
|
|
// we call the dptr member directly for locked since isImmutable()
|
|
|
|
// also checks kiosk and parent containers
|
|
|
|
group.writeEntry("immutability", (int)d->immutability);
|
|
|
|
group.writeEntry("plugin", pluginName());
|
2008-12-12 02:05:00 +01:00
|
|
|
|
|
|
|
group.writeEntry("geometry", geometry());
|
|
|
|
group.writeEntry("zvalue", zValue());
|
|
|
|
|
|
|
|
if (!d->started) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//FIXME: for containments, we need to have some special values here w/regards to
|
|
|
|
// screen affinity (e.g. "bottom of screen 0")
|
|
|
|
//kDebug() << pluginName() << "geometry is" << geometry()
|
|
|
|
// << "pos is" << pos() << "bounding rect is" << boundingRect();
|
|
|
|
if (transform() == QTransform()) {
|
|
|
|
group.deleteEntry("transform");
|
|
|
|
} else {
|
|
|
|
QList<qreal> m;
|
|
|
|
QTransform t = transform();
|
|
|
|
m << t.m11() << t.m12() << t.m13() << t.m21() << t.m22() << t.m23() << t.m31() << t.m32() << t.m33();
|
|
|
|
group.writeEntry("transform", m);
|
|
|
|
//group.writeEntry("transform", transformToString(transform()));
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup appletConfigGroup(&group, "Configuration");
|
|
|
|
saveState(appletConfigGroup);
|
|
|
|
|
2009-01-07 21:34:34 +01:00
|
|
|
if (d->configLoader) {
|
2009-05-26 19:32:33 +02:00
|
|
|
// we're saving so we know its changed, we don't need or want the configChanged
|
|
|
|
// signal bubbling up at this point due to that
|
|
|
|
disconnect(d->configLoader, SIGNAL(configChanged()), this, SLOT(configChanged()));
|
2009-01-07 21:34:34 +01:00
|
|
|
d->configLoader->writeConfig();
|
2009-05-26 19:32:33 +02:00
|
|
|
connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(configChanged()));
|
2009-01-07 21:34:34 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::restore(KConfigGroup &group)
|
|
|
|
{
|
|
|
|
QList<qreal> m = group.readEntry("transform", QList<qreal>());
|
|
|
|
if (m.count() == 9) {
|
|
|
|
QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
|
|
|
setTransform(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal z = group.readEntry("zvalue", 0);
|
|
|
|
|
|
|
|
if (z >= AppletPrivate::s_maxZValue) {
|
|
|
|
AppletPrivate::s_maxZValue = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (z > 0) {
|
|
|
|
setZValue(z);
|
|
|
|
}
|
|
|
|
|
|
|
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
|
|
|
|
|
|
|
QRectF geom = group.readEntry("geometry", QRectF());
|
|
|
|
if (geom.isValid()) {
|
|
|
|
setGeometry(geom);
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup shortcutConfig(&group, "Shortcuts");
|
|
|
|
QString shortcutText = shortcutConfig.readEntryUntranslated("global", QString());
|
|
|
|
if (!shortcutText.isEmpty()) {
|
|
|
|
setGlobalShortcut(KShortcut(shortcutText));
|
2009-03-24 03:07:20 +01:00
|
|
|
/*
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "got global shortcut for" << name() << "of" << QKeySequence(shortcutText);
|
|
|
|
kDebug() << "set to" << d->activationAction->objectName()
|
|
|
|
<< d->activationAction->globalShortcut().primary();
|
2009-03-24 03:07:20 +01:00
|
|
|
*/
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// local shortcut, if any
|
|
|
|
//TODO: implement; the shortcut will need to be registered with the containment
|
|
|
|
/*
|
2009-09-02 04:27:16 +02:00
|
|
|
#include "accessmanager.h"
|
|
|
|
#include "private/plasmoidservice.h"
|
|
|
|
#include "authorizationmanager.h"
|
|
|
|
#include "authorizationmanager.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
shortcutText = shortcutConfig.readEntryUntranslated("local", QString());
|
|
|
|
if (!shortcutText.isEmpty()) {
|
|
|
|
//TODO: implement; the shortcut
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::setFocus()
|
|
|
|
{
|
2009-01-04 08:59:10 +01:00
|
|
|
//kDebug() << "setting focus";
|
2008-11-04 00:08:39 +01:00
|
|
|
q->setFocus(Qt::ShortcutFocusReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setFailedToLaunch(bool failed, const QString &reason)
|
|
|
|
{
|
|
|
|
if (d->failed == failed) {
|
2008-12-30 02:00:13 +01:00
|
|
|
if (failed && !reason.isEmpty()) {
|
|
|
|
foreach (QGraphicsItem *item, QGraphicsItem::children()) {
|
|
|
|
Label *l = dynamic_cast<Label *>(item);
|
|
|
|
if (l) {
|
|
|
|
l->setText(d->visibleFailureText(reason));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->failed = failed;
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
2009-10-28 19:06:56 +01:00
|
|
|
foreach (QGraphicsItem *item, childItems()) {
|
|
|
|
if (!dynamic_cast<AppletHandle *>(item)) {
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
setLayout(0);
|
|
|
|
|
|
|
|
if (failed) {
|
2009-11-11 02:54:32 +01:00
|
|
|
d->destroyMessageOverlay();
|
2008-11-04 00:08:39 +01:00
|
|
|
setBackgroundHints(d->backgroundHints|StandardBackground);
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(this);
|
|
|
|
failureLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
IconWidget *failureIcon = new IconWidget(this);
|
|
|
|
failureIcon->setIcon(KIcon("dialog-error"));
|
|
|
|
failureLayout->addItem(failureIcon);
|
|
|
|
|
|
|
|
Label *failureWidget = new Plasma::Label(this);
|
|
|
|
failureWidget->setText(d->visibleFailureText(reason));
|
|
|
|
QLabel *label = failureWidget->nativeWidget();
|
|
|
|
label->setWordWrap(true);
|
|
|
|
failureLayout->addItem(failureWidget);
|
|
|
|
|
|
|
|
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
|
|
|
|
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
|
2008-11-11 22:36:28 +01:00
|
|
|
KIcon("dialog-error"));
|
2008-11-04 00:08:39 +01:00
|
|
|
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
|
|
|
|
|
|
|
|
setLayout(failureLayout);
|
|
|
|
resize(300, 250);
|
|
|
|
setMinimumSize(failureLayout->minimumSize());
|
|
|
|
d->background->resizeFrame(geometry().size());
|
|
|
|
}
|
2008-11-28 23:01:39 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::saveState(KConfigGroup &group) const
|
|
|
|
{
|
2009-11-05 19:43:39 +01:00
|
|
|
if (d->script) {
|
|
|
|
emit d->script->saveState(group);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
if (group.config()->name() != config().config()->name()) {
|
|
|
|
// we're being saved to a different file!
|
|
|
|
// let's just copy the current values in our configuration over
|
|
|
|
KConfigGroup c = config();
|
|
|
|
c.copyTo(&group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::config(const QString &group) const
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->transient) {
|
|
|
|
return KConfigGroup(KGlobal::config(), "PlasmaTransientsConfig");
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup cg = config();
|
|
|
|
return KConfigGroup(&cg, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::config() const
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->transient) {
|
|
|
|
return KConfigGroup(KGlobal::config(), "PlasmaTransientsConfig");
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->isContainment) {
|
|
|
|
return *(d->mainConfigGroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
return KConfigGroup(d->mainConfigGroup(), "Configuration");
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::globalConfig() const
|
|
|
|
{
|
|
|
|
KConfigGroup globalAppletConfig;
|
|
|
|
QString group = isContainment() ? "ContainmentGlobals" : "AppletGlobals";
|
|
|
|
|
2008-12-18 23:14:06 +01:00
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
|
|
|
if (corona) {
|
|
|
|
KSharedConfig::Ptr coronaConfig = corona->config();
|
2008-11-04 00:08:39 +01:00
|
|
|
globalAppletConfig = KConfigGroup(coronaConfig, group);
|
|
|
|
} else {
|
|
|
|
globalAppletConfig = KConfigGroup(KGlobal::config(), group);
|
|
|
|
}
|
|
|
|
|
|
|
|
return KConfigGroup(&globalAppletConfig, d->globalName());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::destroy()
|
|
|
|
{
|
2009-06-20 04:14:43 +02:00
|
|
|
if (immutability() != Mutable || d->transient || !d->started) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return; //don't double delete
|
|
|
|
}
|
|
|
|
|
|
|
|
d->transient = true;
|
|
|
|
|
|
|
|
if (isContainment()) {
|
|
|
|
d->cleanUpAndDelete();
|
|
|
|
} else {
|
|
|
|
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
|
|
|
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
|
|
|
Animator::self()->animateItem(this, Animator::DisappearAnimation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 02:04:58 +01:00
|
|
|
bool Applet::destroyed() const
|
|
|
|
{
|
|
|
|
return d->transient;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void AppletPrivate::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
|
|
|
{
|
2009-08-18 03:05:37 +02:00
|
|
|
if (anim == Animator::DisappearAnimation && item == q) {
|
|
|
|
cleanUpAndDelete();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::selectItemToDestroy()
|
|
|
|
{
|
|
|
|
//FIXME: this will not work nicely with multiple screens and being zoomed out!
|
2009-01-22 01:00:16 +01:00
|
|
|
if (isContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QGraphicsView *view = q->view();
|
|
|
|
if (view && view->transform().isScaling() &&
|
|
|
|
q->scene()->focusItem() != q) {
|
|
|
|
QGraphicsItem *focus = q->scene()->focusItem();
|
|
|
|
|
|
|
|
if (focus) {
|
|
|
|
Containment *toDestroy = dynamic_cast<Containment*>(focus->topLevelItem());
|
|
|
|
|
|
|
|
if (toDestroy) {
|
|
|
|
toDestroy->destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::updateRect(const QRectF &rect)
|
|
|
|
{
|
|
|
|
q->update(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::cleanUpAndDelete()
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
//kDebug() << "???????????????? DESTROYING APPLET" << q->name() << q->scene() << " ???????????????????????????";
|
2008-11-04 00:08:39 +01:00
|
|
|
QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>(q->parentItem());
|
|
|
|
//it probably won't matter, but right now if there are applethandles, *they* are the parent.
|
|
|
|
//not the containment.
|
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
//is the applet in a containment and does the containment have a layout?
|
2008-11-04 00:08:39 +01:00
|
|
|
//if yes, we remove the applet in the layout
|
|
|
|
if (parent && parent->layout()) {
|
|
|
|
QGraphicsLayout *l = parent->layout();
|
|
|
|
for (int i = 0; i < l->count(); ++i) {
|
|
|
|
if (q == l->itemAt(i)) {
|
|
|
|
l->removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (configLoader) {
|
|
|
|
configLoader->setDefaults();
|
|
|
|
}
|
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
resetConfigurationObject();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
q->scene()->removeItem(q);
|
|
|
|
q->deleteLater();
|
|
|
|
}
|
|
|
|
|
2009-03-06 19:21:59 +01:00
|
|
|
void AppletPrivate::createMessageOverlay(bool usePopup)
|
2008-11-06 16:52:13 +01:00
|
|
|
{
|
2009-03-03 23:23:42 +01:00
|
|
|
if (messageOverlay) {
|
2008-11-06 16:52:13 +01:00
|
|
|
qDeleteAll(messageOverlay->children());
|
|
|
|
messageOverlay->setLayout(0);
|
|
|
|
}
|
|
|
|
|
2009-03-03 23:23:42 +01:00
|
|
|
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
|
2008-11-06 16:52:13 +01:00
|
|
|
|
2009-03-03 23:23:42 +01:00
|
|
|
if (!messageOverlay) {
|
2009-08-24 19:27:24 +02:00
|
|
|
if (usePopup && popup) {
|
|
|
|
if (popup->widget()) {
|
|
|
|
messageOverlayProxy = new QGraphicsProxyWidget(q);
|
|
|
|
messageOverlayProxy->setWidget(popup->widget());
|
|
|
|
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
|
|
|
|
} else if (popup->graphicsWidget() &&
|
|
|
|
popup->graphicsWidget() != extender) {
|
|
|
|
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!messageOverlay) {
|
2009-03-03 23:23:42 +01:00
|
|
|
messageOverlay = new AppletOverlayWidget(q);
|
2008-11-06 16:52:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-24 19:27:24 +02:00
|
|
|
positionMessageOverlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::positionMessageOverlay()
|
|
|
|
{
|
|
|
|
if (!messageOverlay) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
|
2009-09-21 08:58:24 +02:00
|
|
|
const bool usePopup = popup && (messageOverlay->parentItem() != q);
|
2009-08-24 19:27:24 +02:00
|
|
|
QGraphicsItem *topItem = q;
|
|
|
|
|
|
|
|
if (usePopup && popup->widget()) {
|
2009-03-03 23:23:42 +01:00
|
|
|
// popupapplet with widget()
|
2009-10-15 18:42:41 +02:00
|
|
|
topItem = popup->d->proxy.data();
|
2009-03-03 23:23:42 +01:00
|
|
|
messageOverlay->setGeometry(popup->widget()->contentsRect());
|
2009-08-24 19:27:24 +02:00
|
|
|
} else if (usePopup && popup->graphicsWidget() && popup->graphicsWidget() != extender) {
|
2009-03-03 23:23:42 +01:00
|
|
|
// popupapplet with graphicsWidget()
|
2009-08-24 19:27:24 +02:00
|
|
|
topItem = popup->graphicsWidget();
|
|
|
|
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
|
|
|
|
messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect());
|
2009-03-03 23:23:42 +01:00
|
|
|
} else {
|
|
|
|
// normal applet
|
|
|
|
messageOverlay->setGeometry(q->contentsRect());
|
2009-08-24 19:27:24 +02:00
|
|
|
}
|
2009-03-03 23:23:42 +01:00
|
|
|
|
2009-08-24 19:27:24 +02:00
|
|
|
// raise the overlay above all the other children!
|
|
|
|
int zValue = 100;
|
|
|
|
foreach (QGraphicsItem *child, topItem->children()) {
|
|
|
|
if (child->zValue() > zValue) {
|
|
|
|
zValue = child->zValue() + 1;
|
2009-03-03 23:23:42 +01:00
|
|
|
}
|
|
|
|
}
|
2009-08-24 19:27:24 +02:00
|
|
|
messageOverlay->setZValue(zValue);
|
2008-11-06 16:52:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::destroyMessageOverlay()
|
|
|
|
{
|
2009-09-12 02:19:42 +02:00
|
|
|
if (messageDialog) {
|
2009-10-13 23:43:35 +02:00
|
|
|
messageDialog.data()->animatedHide(Plasma::locationToInverseDirection(q->location()));
|
|
|
|
//messageDialog.data()->deleteLater();
|
|
|
|
messageDialog.clear();
|
2009-09-12 02:19:42 +02:00
|
|
|
}
|
|
|
|
|
2009-03-05 14:05:12 +01:00
|
|
|
if (!messageOverlay) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-10 04:12:29 +02:00
|
|
|
|
2009-02-04 12:39:22 +01:00
|
|
|
messageOverlay->destroy();
|
2009-06-10 04:16:19 +02:00
|
|
|
messageOverlay = 0;
|
2009-02-04 12:39:22 +01:00
|
|
|
|
2009-06-10 04:12:29 +02:00
|
|
|
if (messageOverlayProxy) {
|
|
|
|
messageOverlayProxy->setWidget(0);
|
|
|
|
delete messageOverlayProxy;
|
|
|
|
messageOverlayProxy = 0;
|
|
|
|
}
|
2009-02-02 20:39:41 +01:00
|
|
|
|
|
|
|
MessageButton buttonCode = ButtonNo;
|
|
|
|
//find out if we're disappearing because of a button press
|
|
|
|
PushButton *button = qobject_cast<PushButton *>(q->sender());
|
|
|
|
if (button) {
|
|
|
|
if (button->text() == i18n("Ok")) {
|
|
|
|
buttonCode = ButtonOk;
|
|
|
|
}
|
|
|
|
if (button->text() == i18n("Yes")) {
|
|
|
|
buttonCode = ButtonYes;
|
|
|
|
}
|
|
|
|
if (button->text() == i18n("No")) {
|
|
|
|
buttonCode = ButtonNo;
|
|
|
|
}
|
|
|
|
if (button->text() == i18n("Cancel")) {
|
|
|
|
}
|
|
|
|
|
|
|
|
emit q->messageButtonPressed(buttonCode);
|
|
|
|
}
|
2008-11-06 16:52:13 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
ConfigLoader *Applet::configScheme() const
|
|
|
|
{
|
|
|
|
return d->configLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataEngine *Applet::dataEngine(const QString &name) const
|
|
|
|
{
|
2009-09-02 04:27:16 +02:00
|
|
|
if (!d->remoteLocation.isEmpty()) {
|
|
|
|
return d->remoteDataEngine(KUrl(d->remoteLocation), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!package() || package()->metadata().remoteLocation().isEmpty()) {
|
|
|
|
return d->dataEngine(name);
|
|
|
|
} else {
|
|
|
|
return d->remoteDataEngine(KUrl(package()->metadata().remoteLocation()), name);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const Package *Applet::package() const
|
|
|
|
{
|
|
|
|
return d->package;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *Applet::view() const
|
|
|
|
{
|
|
|
|
// It's assumed that we won't be visible on more than one view here.
|
|
|
|
// Anything that actually needs view() should only really care about
|
|
|
|
// one of them anyway though.
|
|
|
|
if (!scene()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *found = 0;
|
|
|
|
QGraphicsView *possibleFind = 0;
|
|
|
|
//kDebug() << "looking through" << scene()->views().count() << "views";
|
|
|
|
foreach (QGraphicsView *view, scene()->views()) {
|
|
|
|
//kDebug() << " checking" << view << view->sceneRect()
|
|
|
|
// << "against" << sceneBoundingRect() << scenePos();
|
|
|
|
if (view->sceneRect().intersects(sceneBoundingRect()) ||
|
|
|
|
view->sceneRect().contains(scenePos())) {
|
|
|
|
//kDebug() << " found something!" << view->isActiveWindow();
|
|
|
|
if (view->isActiveWindow()) {
|
|
|
|
found = view;
|
|
|
|
} else {
|
|
|
|
possibleFind = view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found ? found : possibleFind;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Applet::mapFromView(const QGraphicsView *view, const QRect &rect) const
|
|
|
|
{
|
|
|
|
// Why is this adjustment needed? Qt calculation error?
|
|
|
|
return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Applet::mapToView(const QGraphicsView *view, const QRectF &rect) const
|
|
|
|
{
|
|
|
|
// Why is this adjustment needed? Qt calculation error?
|
|
|
|
return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Applet::popupPosition(const QSize &s) const
|
2009-09-28 19:28:17 +02:00
|
|
|
{
|
|
|
|
return popupPosition(s, Qt::AlignLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Applet::popupPosition(const QSize &s, Qt::AlignmentFlag alignment) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-12-18 23:14:06 +01:00
|
|
|
Corona * corona = qobject_cast<Corona*>(scene());
|
|
|
|
Q_ASSERT(corona);
|
2009-09-28 19:28:17 +02:00
|
|
|
|
|
|
|
return corona->popupPosition(this, s, alignment);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::updateConstraints(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
d->scheduleConstraintsUpdate(constraints);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::constraintsEvent(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
//NOTE: do NOT put any code in here that reacts to constraints updates
|
|
|
|
// as it will not get called for any applet that reimplements constraintsEvent
|
|
|
|
// without calling the Applet:: version as well, which it shouldn't need to.
|
|
|
|
// INSTEAD put such code into flushPendingConstraintsEvents
|
|
|
|
Q_UNUSED(constraints)
|
|
|
|
//kDebug() << constraints << "constraints are FormFactor: " << formFactor()
|
|
|
|
// << ", Location: " << location();
|
|
|
|
if (d->script) {
|
|
|
|
d->script->constraintsEvent(constraints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::initExtenderItem(ExtenderItem *item)
|
|
|
|
{
|
2009-07-17 14:31:08 +02:00
|
|
|
if (d->script) {
|
2009-07-19 16:25:00 +02:00
|
|
|
emit extenderItemRestored(item);
|
2009-07-17 14:31:08 +02:00
|
|
|
} else {
|
|
|
|
kWarning() << "Missing implementation of initExtenderItem in the applet "
|
|
|
|
<< item->config().readEntry("SourceAppletPluginName", "")
|
|
|
|
<< "!\n Any applet that uses extenders should implement initExtenderItem to "
|
|
|
|
<< "instantiate a widget. Destroying the item...";
|
|
|
|
item->destroy();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Extender *Applet::extender() const
|
|
|
|
{
|
|
|
|
if (!d->extender) {
|
|
|
|
new Extender(const_cast<Applet*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->extender;
|
|
|
|
}
|
|
|
|
|
2008-11-04 19:22:55 +01:00
|
|
|
void Applet::setBusy(bool busy)
|
|
|
|
{
|
|
|
|
if (busy) {
|
2009-04-15 09:29:23 +02:00
|
|
|
if (!d->busyWidget) {
|
|
|
|
d->createMessageOverlay(false);
|
|
|
|
d->messageOverlay->opacity = 0;
|
2009-02-28 23:52:17 +01:00
|
|
|
|
2009-04-15 09:29:23 +02:00
|
|
|
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(d->messageOverlay);
|
|
|
|
d->busyWidget = new Plasma::BusyWidget(d->messageOverlay);
|
2009-05-07 19:13:17 +02:00
|
|
|
d->busyWidget->setAcceptHoverEvents(false);
|
|
|
|
d->busyWidget->setAcceptedMouseButtons(Qt::NoButton);
|
|
|
|
d->messageOverlay->setAcceptHoverEvents(false);
|
2009-02-28 23:52:17 +01:00
|
|
|
|
2009-04-15 09:29:23 +02:00
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->addItem(d->busyWidget);
|
|
|
|
mainLayout->addStretch();
|
|
|
|
}
|
|
|
|
} else if (d->busyWidget) {
|
2009-03-05 15:07:24 +01:00
|
|
|
//will be deleted by its parent
|
|
|
|
d->busyWidget = 0;
|
2009-03-05 14:05:12 +01:00
|
|
|
d->destroyMessageOverlay();
|
2008-11-04 19:22:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isBusy() const
|
|
|
|
{
|
|
|
|
return d->busyWidget && d->busyWidget->isVisible();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString Applet::name() const
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->isContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
const Containment *c = qobject_cast<const Containment*>(this);
|
|
|
|
if (c && !c->activity().isNull()) {
|
|
|
|
return i18n("%1 Activity", c->activity());
|
|
|
|
}
|
2009-10-07 20:31:14 +02:00
|
|
|
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return i18n("Unknown Activity");
|
2009-10-15 20:37:59 +02:00
|
|
|
} else if (c && (c->d->type == Containment::PanelContainment ||
|
|
|
|
c->d->type == Containment::CustomPanelContainment)) {
|
2009-10-14 01:07:35 +02:00
|
|
|
return d->appletDescription.name();
|
2009-10-07 20:31:14 +02:00
|
|
|
} else {
|
|
|
|
return i18n("%1 Activity", d->appletDescription.name());
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (!d->appletDescription.isValid()) {
|
|
|
|
return i18n("Unknown Widget");
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
QFont Applet::font() const
|
|
|
|
{
|
|
|
|
return QApplication::font();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::icon() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::pluginName() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.pluginName();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::shouldConserveResources() const
|
|
|
|
{
|
|
|
|
return Solid::PowerManagement::appShouldConserveResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
2008-11-04 13:54:19 +01:00
|
|
|
return i18nc("misc category", "Miscellaneous");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.category();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category(const KPluginInfo &applet)
|
|
|
|
{
|
2009-05-01 20:03:13 +02:00
|
|
|
return applet.property("X-KDE-PluginInfo-Category").toString();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category(const QString &appletName)
|
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-07-06 13:49:01 +02:00
|
|
|
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
2009-07-26 16:20:31 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
offers = KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2009-05-01 20:03:13 +02:00
|
|
|
return offers.first()->property("X-KDE-PluginInfo-Category").toString();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ImmutabilityType Applet::immutability() const
|
|
|
|
{
|
|
|
|
//Returning the more strict immutability between the applet immutability and Corona one
|
|
|
|
ImmutabilityType coronaImmutability = Mutable;
|
|
|
|
|
2008-12-18 23:14:06 +01:00
|
|
|
if (qobject_cast<Corona*>(scene())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
coronaImmutability = static_cast<Corona*>(scene())->immutability();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coronaImmutability == SystemImmutable) {
|
|
|
|
return SystemImmutable;
|
|
|
|
} else if (coronaImmutability == UserImmutable && d->immutability != SystemImmutable) {
|
|
|
|
return UserImmutable;
|
|
|
|
} else {
|
|
|
|
return d->immutability;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setImmutability(const ImmutabilityType immutable)
|
|
|
|
{
|
|
|
|
if (d->immutability == immutable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->immutability = immutable;
|
|
|
|
updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::BackgroundHints Applet::backgroundHints() const
|
|
|
|
{
|
|
|
|
return d->backgroundHints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setBackgroundHints(const BackgroundHints hints)
|
|
|
|
{
|
2009-06-15 00:12:40 +02:00
|
|
|
if (d->backgroundHints == hints) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->backgroundHints = hints;
|
2009-07-27 22:14:38 +02:00
|
|
|
d->preferredBackgroundHints = hints;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//Draw the standard background?
|
|
|
|
if ((hints & StandardBackground) || (hints & TranslucentBackground)) {
|
|
|
|
if (!d->background) {
|
|
|
|
d->background = new Plasma::FrameSvg(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hints & TranslucentBackground) &&
|
|
|
|
Plasma::Theme::defaultTheme()->currentThemeHasImage("widgets/translucentbackground")) {
|
|
|
|
d->background->setImagePath("widgets/translucentbackground");
|
|
|
|
} else {
|
|
|
|
d->background->setImagePath("widgets/background");
|
|
|
|
}
|
|
|
|
|
|
|
|
d->background->setEnabledBorders(Plasma::FrameSvg::AllBorders);
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
setContentsMargins(left, right, top, bottom);
|
|
|
|
QSizeF fitSize(left + right, top + bottom);
|
|
|
|
if (minimumSize().expandedTo(fitSize) != minimumSize()) {
|
|
|
|
setMinimumSize(minimumSize().expandedTo(fitSize));
|
|
|
|
}
|
|
|
|
d->background->resizeFrame(boundingRect().size());
|
2009-01-13 22:46:07 +01:00
|
|
|
|
|
|
|
//if the background has an "overlay" element decide a random position for it and then save it so it's consistent across plasma starts
|
2009-02-17 23:06:30 +01:00
|
|
|
|
2009-02-18 20:47:32 +01:00
|
|
|
if (d->background->hasElement("overlay")) {
|
2009-01-13 22:46:07 +01:00
|
|
|
QSize overlaySize = d->background->elementSize("overlay");
|
|
|
|
|
2009-02-18 20:47:32 +01:00
|
|
|
//position is in the boundaries overlaySize.width()*2, overlaySize.height()
|
|
|
|
qsrand(id());
|
2009-02-23 23:10:30 +01:00
|
|
|
d->background->d->overlayPos.rx() = - (overlaySize.width() /2) + (overlaySize.width() /4) * (qrand() % (4 + 1));
|
|
|
|
d->background->d->overlayPos.ry() = (- (overlaySize.height() /2) + (overlaySize.height() /4) * (qrand() % (4 + 1)))/2;
|
2009-01-13 22:46:07 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (d->background) {
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
//Setting a minimum size of 0,0 would result in the panel to be only
|
|
|
|
//on the first virtual desktop
|
|
|
|
setMinimumSize(qMax(minimumSize().width() - left - right, qreal(1.0)),
|
|
|
|
qMax(minimumSize().height() - top - bottom, qreal(1.0)));
|
|
|
|
|
|
|
|
delete d->background;
|
|
|
|
d->background = 0;
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
|
|
|
}
|
2009-06-15 00:12:40 +02:00
|
|
|
|
|
|
|
update();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::hasFailedToLaunch() const
|
|
|
|
{
|
|
|
|
return d->failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::paintWindowFrame(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(painter)
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
//Here come the code for the window frame
|
|
|
|
//kDebug() << windowFrameGeometry();
|
|
|
|
//painter->drawRoundedRect(windowFrameGeometry(), 5, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::configurationRequired() const
|
|
|
|
{
|
2008-11-06 16:52:13 +01:00
|
|
|
return d->needsConfig;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
|
|
|
{
|
2008-11-06 16:52:13 +01:00
|
|
|
if (d->needsConfig == needsConfig) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-06 16:52:13 +01:00
|
|
|
d->needsConfig = needsConfig;
|
|
|
|
|
|
|
|
if (!needsConfig) {
|
|
|
|
d->destroyMessageOverlay();
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-07 13:59:09 +02:00
|
|
|
d->createMessageOverlay(true);
|
2009-03-05 14:05:12 +01:00
|
|
|
d->messageOverlay->opacity = 0.4;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-06 16:52:13 +01:00
|
|
|
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(d->messageOverlay);
|
2008-11-04 00:08:39 +01:00
|
|
|
configLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
// configLayout->addStretch();
|
2009-03-05 17:14:34 +01:00
|
|
|
configLayout->setColumnStretchFactor(0, 5);
|
|
|
|
configLayout->setColumnStretchFactor(2, 5);
|
|
|
|
configLayout->setRowStretchFactor(0, 5);
|
|
|
|
configLayout->setRowStretchFactor(3, 5);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
int row = 1;
|
|
|
|
if (!reason.isEmpty()) {
|
2008-11-06 16:52:13 +01:00
|
|
|
Label *explanation = new Label(d->messageOverlay);
|
2008-11-04 00:08:39 +01:00
|
|
|
explanation->setText(reason);
|
|
|
|
configLayout->addItem(explanation, row, 1);
|
2009-03-05 17:14:34 +01:00
|
|
|
configLayout->setColumnStretchFactor(1, 5);
|
2008-11-04 00:08:39 +01:00
|
|
|
++row;
|
2009-03-05 17:14:34 +01:00
|
|
|
configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-03-03 23:23:42 +01:00
|
|
|
PushButton *configWidget = new PushButton(d->messageOverlay);
|
|
|
|
configWidget->setText(i18n("Configure..."));
|
|
|
|
connect(configWidget, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
|
|
|
|
configLayout->addItem(configWidget, row, 1);
|
2008-11-23 15:09:45 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
|
|
|
|
//configLayout->addStretch();
|
|
|
|
|
2008-11-06 16:52:13 +01:00
|
|
|
d->messageOverlay->show();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
void Applet::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
|
|
|
|
{
|
|
|
|
if (message.isEmpty()) {
|
|
|
|
d->destroyMessageOverlay();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-12 02:19:42 +02:00
|
|
|
Corona *corona = qobject_cast<Corona *>(scene());
|
2009-09-12 02:37:32 +02:00
|
|
|
QGraphicsWidget *mainWidget = new QGraphicsWidget;
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-09-12 02:37:32 +02:00
|
|
|
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
mainLayout->setOrientation(Qt::Vertical);
|
|
|
|
mainLayout->addStretch();
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *messageLayout = new QGraphicsLinearLayout();
|
|
|
|
messageLayout->setOrientation(Qt::Horizontal);
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *buttonLayout = new QGraphicsLinearLayout();
|
|
|
|
buttonLayout->setOrientation(Qt::Horizontal);
|
|
|
|
|
|
|
|
mainLayout->addItem(messageLayout);
|
|
|
|
mainLayout->addItem(buttonLayout);
|
|
|
|
mainLayout->addStretch();
|
|
|
|
|
2009-09-12 02:37:32 +02:00
|
|
|
IconWidget *messageIcon = new IconWidget(mainWidget);
|
|
|
|
Label *messageText = new Label(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
messageText->nativeWidget()->setWordWrap(true);
|
|
|
|
|
|
|
|
messageLayout->addStretch();
|
|
|
|
messageLayout->addItem(messageIcon);
|
|
|
|
messageLayout->addItem(messageText);
|
|
|
|
messageLayout->addStretch();
|
|
|
|
|
|
|
|
messageIcon->setIcon(icon);
|
|
|
|
messageText->setText(message);
|
|
|
|
|
|
|
|
buttonLayout->addStretch();
|
|
|
|
|
|
|
|
if (buttons & ButtonOk) {
|
2009-09-12 02:37:32 +02:00
|
|
|
PushButton *ok = new PushButton(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
ok->setText(i18n("Ok"));
|
|
|
|
buttonLayout->addItem(ok);
|
|
|
|
connect(ok, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonYes) {
|
2009-09-12 02:37:32 +02:00
|
|
|
PushButton *yes = new PushButton(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
yes->setText(i18n("Yes"));
|
|
|
|
buttonLayout->addItem(yes);
|
|
|
|
connect(yes, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonNo) {
|
2009-09-12 02:37:32 +02:00
|
|
|
PushButton *no = new PushButton(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
no->setText(i18n("No"));
|
|
|
|
buttonLayout->addItem(no);
|
|
|
|
connect(no, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonCancel) {
|
2009-09-12 02:37:32 +02:00
|
|
|
PushButton *cancel = new PushButton(mainWidget);
|
2009-02-02 20:39:41 +01:00
|
|
|
cancel->setText(i18n("Cancel"));
|
|
|
|
buttonLayout->addItem(cancel);
|
|
|
|
connect(cancel, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonLayout->addStretch();
|
|
|
|
|
2009-09-12 02:37:32 +02:00
|
|
|
mainWidget->adjustSize();
|
|
|
|
QSizeF hint = mainWidget->preferredSize();
|
|
|
|
if (hint.height() > size().height() || hint.width() > size().width()) {
|
|
|
|
// either a collapsed popup in h/v form factor or just too small,
|
|
|
|
// so show it in a dialog associated with ourselves
|
|
|
|
if (corona) {
|
|
|
|
corona->addOffscreenWidget(mainWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->messageDialog) {
|
2009-10-13 23:43:35 +02:00
|
|
|
delete d->messageDialog.data()->graphicsWidget();
|
2009-09-12 02:37:32 +02:00
|
|
|
} else {
|
|
|
|
d->messageDialog = new Plasma::Dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTipManager::self()->hide(this);
|
2009-10-13 23:43:35 +02:00
|
|
|
KWindowSystem::setOnAllDesktops(d->messageDialog.data()->winId(), true);
|
|
|
|
KWindowSystem::setState(d->messageDialog.data()->winId(), NET::SkipTaskbar | NET::SkipPager);
|
|
|
|
d->messageDialog.data()->setGraphicsWidget(mainWidget);
|
|
|
|
connect(d->messageDialog.data(), SIGNAL(destroyed(QObject*)), mainWidget, SLOT(deleteLater()));
|
2009-09-12 02:37:32 +02:00
|
|
|
} else {
|
2009-10-13 23:43:35 +02:00
|
|
|
delete d->messageDialog.data();
|
2009-09-12 02:37:32 +02:00
|
|
|
d->createMessageOverlay();
|
|
|
|
d->messageOverlay->opacity = 0.8;
|
2009-11-11 02:55:11 +01:00
|
|
|
mainWidget->setParentItem(d->messageOverlay);
|
2009-09-12 02:37:32 +02:00
|
|
|
QGraphicsLinearLayout *l = new QGraphicsLinearLayout(d->messageOverlay);
|
|
|
|
l->addItem(mainWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->messageDialog) {
|
2009-09-12 02:19:42 +02:00
|
|
|
QPoint pos = geometry().topLeft().toPoint();
|
|
|
|
if (corona) {
|
2009-10-13 23:43:35 +02:00
|
|
|
pos = corona->popupPosition(this, d->messageDialog.data()->size());
|
2009-09-12 02:19:42 +02:00
|
|
|
}
|
2009-02-02 20:39:41 +01:00
|
|
|
|
2009-10-13 23:43:35 +02:00
|
|
|
d->messageDialog.data()->move(pos);
|
|
|
|
d->messageDialog.data()->animatedShow(locationToDirection(location()));
|
2009-09-12 02:19:42 +02:00
|
|
|
} else {
|
|
|
|
d->messageOverlay->show();
|
|
|
|
}
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
QVariantList Applet::startupArguments() const
|
|
|
|
{
|
|
|
|
return d->args;
|
|
|
|
}
|
|
|
|
|
2009-07-09 19:19:00 +02:00
|
|
|
ItemStatus Applet::status() const
|
|
|
|
{
|
|
|
|
return d->itemStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setStatus(const ItemStatus status)
|
|
|
|
{
|
|
|
|
d->itemStatus = status;
|
|
|
|
emit newStatus(status);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::flushPendingConstraintsEvents()
|
|
|
|
{
|
|
|
|
if (d->pendingConstraints == NoConstraint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->constraintsTimerId) {
|
|
|
|
killTimer(d->constraintsTimerId);
|
|
|
|
d->constraintsTimerId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "fushing constraints: " << d->pendingConstraints << "!!!!!!!!!!!!!!!!!!!!!!!!!!!";
|
|
|
|
Plasma::Constraints c = d->pendingConstraints;
|
|
|
|
d->pendingConstraints = NoConstraint;
|
|
|
|
|
|
|
|
if (c & Plasma::StartupCompletedConstraint) {
|
|
|
|
//common actions
|
|
|
|
bool unlocked = immutability() == Mutable;
|
|
|
|
//FIXME desktop containments can't be removed while in use.
|
|
|
|
//it's kinda silly to have a keyboard shortcut for something that can only be used when the
|
|
|
|
//shortcut isn't active.
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *closeApplet = d->actions->action("remove");
|
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setEnabled(unlocked);
|
|
|
|
closeApplet->setVisible(unlocked);
|
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(selectItemToDestroy()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *configAction = d->actions->action("configure");
|
|
|
|
if (configAction) {
|
|
|
|
if (d->isContainment) {
|
|
|
|
connect(configAction, SIGNAL(triggered()), this, SLOT(requestConfiguration()));
|
|
|
|
} else {
|
|
|
|
connect(configAction, SIGNAL(triggered(bool)), this, SLOT(showConfigurationInterface()));
|
|
|
|
}
|
2009-07-30 20:13:01 +02:00
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize("PlasmaAllowConfigureWhenLocked");
|
|
|
|
configAction->setVisible(canConfig);
|
|
|
|
configAction->setEnabled(canConfig);
|
|
|
|
}
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
QAction *runAssociatedApplication = d->actions->action("run associated application");
|
|
|
|
if (runAssociatedApplication) {
|
|
|
|
connect(runAssociatedApplication, SIGNAL(triggered(bool)), this, SLOT(runAssociatedApplication()));
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
d->updateShortcuts();
|
|
|
|
Corona * corona = qobject_cast<Corona*>(scene());
|
|
|
|
if (corona) {
|
|
|
|
connect(corona, SIGNAL(shortcutsChanged()), this, SLOT(updateShortcuts()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c & Plasma::ImmutableConstraint) {
|
|
|
|
bool unlocked = immutability() == Mutable;
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *action = d->actions->action("remove");
|
2008-11-04 00:08:39 +01:00
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}
|
2009-01-16 01:39:07 +01:00
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
action = d->actions->action("configure");
|
2009-02-08 19:31:43 +01:00
|
|
|
if (action) {
|
2009-07-30 20:13:01 +02:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize("PlasmaAllowConfigureWhenLocked");
|
2009-02-08 19:31:43 +01:00
|
|
|
action->setVisible(canConfig);
|
|
|
|
action->setEnabled(canConfig);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-08-18 00:30:46 +02:00
|
|
|
emit immutabilityChanged(immutability());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-15 19:29:45 +01:00
|
|
|
if (c & Plasma::SizeConstraint) {
|
2009-08-24 19:27:24 +02:00
|
|
|
d->positionMessageOverlay();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-15 19:29:45 +01:00
|
|
|
if (d->started && layout()) {
|
|
|
|
layout()->updateGeometry();
|
|
|
|
}
|
2008-11-04 19:22:55 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (c & Plasma::FormFactorConstraint) {
|
|
|
|
FormFactor f = formFactor();
|
2009-01-22 01:00:16 +01:00
|
|
|
if (!d->isContainment && f != Vertical && f != Horizontal) {
|
2009-07-27 22:14:38 +02:00
|
|
|
setBackgroundHints(d->preferredBackgroundHints);
|
|
|
|
} else {
|
|
|
|
BackgroundHints hints = d->preferredBackgroundHints;
|
|
|
|
setBackgroundHints(NoBackground);
|
|
|
|
d->preferredBackgroundHints = hints;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->failed) {
|
|
|
|
if (f == Vertical || f == Horizontal) {
|
|
|
|
setMinimumSize(0, 0);
|
|
|
|
QGraphicsLayoutItem *item = layout()->itemAt(1);
|
|
|
|
layout()->removeAt(1);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-15 19:29:45 +01:00
|
|
|
if (c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) {
|
2009-01-22 17:49:45 +01:00
|
|
|
if (aspectRatioMode() == Plasma::Square || aspectRatioMode() == Plasma::ConstrainedSquare) {
|
2008-12-15 19:29:45 +01:00
|
|
|
// enforce square size in panels
|
|
|
|
if (formFactor() == Horizontal) {
|
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
|
|
|
|
} else if (formFactor() == Vertical) {
|
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-01-22 17:49:45 +01:00
|
|
|
updateGeometry();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-15 19:29:45 +01:00
|
|
|
// now take care of constraints in special subclasses: Contaiment and PopupApplet
|
2008-11-04 00:08:39 +01:00
|
|
|
Containment* containment = qobject_cast<Plasma::Containment*>(this);
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->isContainment && containment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
containment->d->containmentConstraintsEvent(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupApplet* popup = qobject_cast<Plasma::PopupApplet*>(this);
|
|
|
|
if (popup) {
|
|
|
|
popup->d->popupConstraintsEvent(c);
|
|
|
|
}
|
|
|
|
|
2008-12-15 19:29:45 +01:00
|
|
|
// pass the constraint on to the actual subclass
|
2008-11-04 00:08:39 +01:00
|
|
|
constraintsEvent(c);
|
|
|
|
|
2008-12-15 18:41:37 +01:00
|
|
|
if (c & StartupCompletedConstraint) {
|
|
|
|
// start up is done, we can now go do a mod timer
|
|
|
|
if (d->modificationsTimerId > 0) {
|
|
|
|
killTimer(d->modificationsTimerId);
|
|
|
|
}
|
2008-12-17 04:55:26 +01:00
|
|
|
|
2009-01-19 22:24:55 +01:00
|
|
|
d->modificationsTimerId = 0;
|
2008-12-15 18:41:37 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Applet::type() const
|
|
|
|
{
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction*> Applet::contextualActions()
|
|
|
|
{
|
|
|
|
//kDebug() << "empty context actions";
|
|
|
|
return d->script ? d->script->contextualActions() : QList<QAction*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *Applet::action(QString name) const
|
|
|
|
{
|
2009-05-03 22:22:14 +02:00
|
|
|
return d->actions->action(name);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::addAction(QString name, QAction *action)
|
|
|
|
{
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions->addAction(name, action);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2008-11-17 02:27:14 +01:00
|
|
|
if (!d->started) {
|
2009-01-22 01:00:16 +01:00
|
|
|
//kDebug() << "not started";
|
2008-11-17 02:27:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (transform().isRotating()) {
|
2008-11-28 23:39:29 +01:00
|
|
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->background &&
|
|
|
|
formFactor() != Plasma::Vertical &&
|
|
|
|
formFactor() != Plasma::Horizontal) {
|
|
|
|
//kDebug() << "option rect is" << option->rect;
|
2008-11-28 23:39:29 +01:00
|
|
|
d->background->paintFrame(painter);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
if (d->failed) {
|
2009-01-22 01:00:16 +01:00
|
|
|
//kDebug() << "failed!";
|
2008-11-28 23:39:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
getContentsMargins(&left, &top, &right, &bottom);
|
|
|
|
QRect contentsRect = QRectF(QPointF(0, 0),
|
|
|
|
boundingRect().size()).adjusted(left, top, -right, -bottom).toRect();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
if (widget && d->isContainment) {
|
2008-11-28 23:39:29 +01:00
|
|
|
// note that the widget we get is actually the viewport of the view, not the view itself
|
|
|
|
View* v = qobject_cast<Plasma::View*>(widget->parent());
|
|
|
|
Containment* c = qobject_cast<Plasma::Containment*>(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
//update the view transform of the toolbox, since it ignores transforms
|
2009-06-20 15:00:48 +02:00
|
|
|
if (v && c && c->d->toolBox) {
|
2009-10-20 16:14:53 +02:00
|
|
|
InternalToolBox *toolBox = qobject_cast<InternalToolBox *>(c->d->toolBox);
|
|
|
|
if (toolBox && toolBox->viewTransform().isScaling() && !v->transform().isScaling()) {
|
2008-12-18 12:03:35 +01:00
|
|
|
c->d->positionToolBox();
|
|
|
|
}
|
2009-10-20 16:14:53 +02:00
|
|
|
if (toolBox && v) {
|
|
|
|
toolBox->setViewTransform(v->transform());
|
2008-12-21 19:59:46 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
if (!v || v->isWallpaperEnabled()) {
|
|
|
|
|
|
|
|
// paint the wallpaper
|
|
|
|
if (c && c->drawWallpaper() && c->wallpaper()) {
|
|
|
|
Wallpaper *w = c->wallpaper();
|
|
|
|
if (!w->isInitialized()) {
|
|
|
|
// delayed paper initialization
|
|
|
|
KConfigGroup wallpaperConfig = c->config();
|
|
|
|
wallpaperConfig = KConfigGroup(&wallpaperConfig, "Wallpaper");
|
|
|
|
wallpaperConfig = KConfigGroup(&wallpaperConfig, w->pluginName());
|
|
|
|
w->restore(wallpaperConfig);
|
2009-11-03 23:27:05 +01:00
|
|
|
disconnect(w, SIGNAL(update(const QRectF&)), this, SLOT(updateRect(const QRectF&)));
|
|
|
|
connect(w, SIGNAL(update(const QRectF&)), this, SLOT(updateRect(const QRectF&)));
|
2008-11-28 23:39:29 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
painter->save();
|
|
|
|
c->wallpaper()->paint(painter, option->exposedRect);
|
|
|
|
painter->restore();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
// .. and now paint the actual containment interface, but with
|
|
|
|
// a Containment style option based on the one we get
|
|
|
|
Containment::StyleOption coption(*option);
|
|
|
|
coption.view = v;
|
|
|
|
paintInterface(painter, &coption, contentsRect);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//kDebug() << "paint interface of" << (QObject*) this;
|
|
|
|
// paint the applet's interface
|
|
|
|
paintInterface(painter, option, contentsRect);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-28 23:39:29 +01:00
|
|
|
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (d->script) {
|
|
|
|
d->script->paintInterface(painter, option, contentsRect);
|
|
|
|
} else {
|
|
|
|
//kDebug() << "Applet::paintInterface() default impl";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFactor Applet::formFactor() const
|
|
|
|
{
|
|
|
|
Containment *c = containment();
|
2009-08-08 13:34:49 +02:00
|
|
|
QGraphicsWidget *p = dynamic_cast<QGraphicsWidget *>(parentItem());
|
|
|
|
|
|
|
|
|
|
|
|
//if the applet is in a widget that isn't a containment
|
|
|
|
//try to retrieve the formFactor from the parent size
|
|
|
|
//we can't use our own sizeHint here because it needs formFactor, so endless recursion
|
|
|
|
if (p && p != c && c != this && layout()) {
|
|
|
|
if (p->size().width() < layout()->effectiveSizeHint(Qt::MinimumSize).width()) {
|
|
|
|
return Plasma::Vertical;
|
|
|
|
} else if (p->size().height() < layout()->effectiveSizeHint(Qt::MinimumSize).height()) {
|
|
|
|
return Plasma::Horizontal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return c ? c->d->formFactor : Plasma::Planar;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment *Applet::containment() const
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->isContainment) {
|
2008-12-18 23:14:06 +01:00
|
|
|
Containment *c = qobject_cast<Containment*>(const_cast<Applet*>(this));
|
2008-11-04 00:08:39 +01:00
|
|
|
if (c) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsItem *parent = parentItem();
|
|
|
|
Containment *c = 0;
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
Containment *possibleC = dynamic_cast<Containment*>(parent);
|
2009-01-22 01:00:16 +01:00
|
|
|
if (possibleC && possibleC->Applet::d->isContainment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
c = possibleC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent = parent->parentItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setGlobalShortcut(const KShortcut &shortcut)
|
|
|
|
{
|
|
|
|
if (!d->activationAction) {
|
|
|
|
d->activationAction = new KAction(this);
|
|
|
|
d->activationAction->setText(i18n("Activate %1 Widget", name()));
|
|
|
|
d->activationAction->setObjectName(QString("activate widget %1").arg(id())); // NO I18N
|
|
|
|
connect(d->activationAction, SIGNAL(triggered()), this, SIGNAL(activate()));
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
QList<QWidget *> widgets = d->actions->associatedWidgets();
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
w->addAction(d->activationAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "before" << shortcut.primary() << d->activationAction->globalShortcut().primary();
|
|
|
|
d->activationAction->setGlobalShortcut(
|
|
|
|
shortcut,
|
|
|
|
KAction::ShortcutTypes(KAction::ActiveShortcut | KAction::DefaultShortcut),
|
|
|
|
KAction::NoAutoloading);
|
2009-03-24 03:07:20 +01:00
|
|
|
|
|
|
|
KConfigGroup shortcutConfig(d->mainConfigGroup(), "Shortcuts");
|
|
|
|
shortcutConfig.writeEntry("global", d->activationAction->globalShortcut().toString());
|
|
|
|
d->scheduleModificationNotification();
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << "after" << shortcut.primary() << d->activationAction->globalShortcut().primary();
|
|
|
|
}
|
|
|
|
|
|
|
|
KShortcut Applet::globalShortcut() const
|
|
|
|
{
|
|
|
|
if (d->activationAction) {
|
|
|
|
return d->activationAction->globalShortcut();
|
|
|
|
}
|
|
|
|
|
|
|
|
return KShortcut();
|
|
|
|
}
|
|
|
|
|
2008-12-29 07:03:43 +01:00
|
|
|
bool Applet::isPopupShowing() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::addAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions->addAssociatedWidget(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::removeAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
2009-05-03 22:22:14 +02:00
|
|
|
d->actions->removeAssociatedWidget(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Location Applet::location() const
|
|
|
|
{
|
|
|
|
Containment *c = containment();
|
|
|
|
return c ? c->d->location : Plasma::Desktop;
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *Applet::context() const
|
|
|
|
{
|
|
|
|
Containment *c = containment();
|
|
|
|
Q_ASSERT(c);
|
|
|
|
return c->d->context();
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::AspectRatioMode Applet::aspectRatioMode() const
|
|
|
|
{
|
|
|
|
return d->aspectRatioMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode)
|
|
|
|
{
|
|
|
|
d->aspectRatioMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::registerAsDragHandle(QGraphicsItem *item)
|
|
|
|
{
|
2008-12-11 04:10:36 +01:00
|
|
|
if (!item || d->registeredAsDragHandle.contains(item)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-11 04:10:36 +01:00
|
|
|
d->registeredAsDragHandle.insert(item);
|
|
|
|
item->installSceneEventFilter(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::unregisterAsDragHandle(QGraphicsItem *item)
|
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-11 04:10:36 +01:00
|
|
|
if (d->registeredAsDragHandle.remove(item)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
item->removeSceneEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isRegisteredAsDragHandle(QGraphicsItem *item)
|
|
|
|
{
|
2008-12-11 04:10:36 +01:00
|
|
|
return d->registeredAsDragHandle.contains(item);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::hasConfigurationInterface() const
|
|
|
|
{
|
|
|
|
return d->hasConfigurationInterface;
|
|
|
|
}
|
|
|
|
|
2009-09-04 02:08:26 +02:00
|
|
|
void Applet::publish(AnnouncementMethods methods, const QString &resourceName)
|
2009-09-02 04:27:16 +02:00
|
|
|
{
|
2009-09-03 01:49:46 +02:00
|
|
|
if (d->package) {
|
|
|
|
d->package->d->publish(methods);
|
|
|
|
} else {
|
|
|
|
if (!d->service) {
|
|
|
|
d->service = new PlasmoidService(this);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2009-09-03 01:49:46 +02:00
|
|
|
kDebug() << "publishing package under name " << resourceName;
|
|
|
|
d->service->d->publish(methods, resourceName);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::unpublish()
|
|
|
|
{
|
2009-09-03 01:49:46 +02:00
|
|
|
if (d->package) {
|
|
|
|
d->package->d->unpublish();
|
|
|
|
} else {
|
|
|
|
if (d->service) {
|
|
|
|
d->service->d->unpublish();
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isPublished() const
|
|
|
|
{
|
2009-09-03 01:49:46 +02:00
|
|
|
if (d->package) {
|
2009-09-03 01:49:58 +02:00
|
|
|
return d->package->d->isPublished();
|
2009-09-02 04:27:16 +02:00
|
|
|
} else {
|
2009-09-03 01:49:46 +02:00
|
|
|
if (d->service) {
|
|
|
|
return d->service->d->isPublished();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//it bugs me that this can get turned on and off at will. I don't see it being useful and it just
|
|
|
|
//makes more work for me and more code duplication.
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
|
|
|
if (d->hasConfigurationInterface == hasInterface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->hasConfigurationInterface = hasInterface;
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
KActionCollection* AppletPrivate::defaultActions(QObject *parent)
|
|
|
|
{
|
|
|
|
KActionCollection *actions = new KActionCollection(parent);
|
|
|
|
actions->setConfigGroup("Shortcuts-Applet");
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction *configAction = actions->addAction("configure");
|
2009-06-29 03:22:58 +02:00
|
|
|
configAction->setAutoRepeat(false);
|
2009-05-04 00:13:05 +02:00
|
|
|
configAction->setText(i18n("Widget Settings"));
|
2009-05-03 22:22:14 +02:00
|
|
|
configAction->setIcon(KIcon("configure"));
|
|
|
|
configAction->setShortcut(KShortcut("alt+d, s"));
|
|
|
|
|
2009-05-04 00:13:05 +02:00
|
|
|
KAction *closeApplet = actions->addAction("remove");
|
2009-06-29 03:22:58 +02:00
|
|
|
closeApplet->setAutoRepeat(false);
|
2009-10-09 09:08:48 +02:00
|
|
|
closeApplet->setText(i18n("Remove this Widget"));
|
2009-05-03 22:22:14 +02:00
|
|
|
closeApplet->setIcon(KIcon("edit-delete"));
|
|
|
|
closeApplet->setShortcut(KShortcut("alt+d, r"));
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
KAction *runAssociatedApplication = actions->addAction("run associated application");
|
|
|
|
runAssociatedApplication->setAutoRepeat(false);
|
2009-10-01 11:57:01 +02:00
|
|
|
runAssociatedApplication->setText(i18n("Run the associated application"));
|
2009-09-16 19:08:45 +02:00
|
|
|
runAssociatedApplication->setIcon(KIcon("system-run"));
|
|
|
|
runAssociatedApplication->setShortcut(KShortcut("alt+d, t"));
|
|
|
|
runAssociatedApplication->setVisible(false);
|
|
|
|
runAssociatedApplication->setEnabled(false);
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
bool Applet::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
return QObject::eventFilter(o, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::GraphicsSceneMouseMove:
|
|
|
|
{
|
|
|
|
// don't move when the containment is not mutable,
|
|
|
|
// in the rare case the containment doesn't exists consider it as mutable
|
2008-12-11 04:10:36 +01:00
|
|
|
if (d->registeredAsDragHandle.contains(watched)) {
|
|
|
|
Containment *c = containment();
|
|
|
|
if (!c || c->immutability() == Mutable) {
|
|
|
|
mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
|
|
|
|
return true;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::sceneEventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (immutability() == Mutable && formFactor() == Plasma::Planar) {
|
|
|
|
QGraphicsItem *parent = parentItem();
|
|
|
|
Plasma::Applet *applet = qgraphicsitem_cast<Plasma::Applet*>(parent);
|
|
|
|
|
|
|
|
if (applet && applet->isContainment()) {
|
|
|
|
// our direct parent is a containment. just move ourselves.
|
|
|
|
QPointF curPos = event->pos();
|
|
|
|
QPointF lastPos = event->lastPos();
|
2009-09-10 13:46:21 +02:00
|
|
|
|
2009-09-10 13:45:19 +02:00
|
|
|
QTransform appletTransform = transform();
|
|
|
|
//we need to discard translation from the transform
|
|
|
|
QTransform t(appletTransform.m11(), appletTransform.m12(), appletTransform.m21(), appletTransform.m22(), 0, 0);
|
|
|
|
QPointF delta = t.map(curPos - lastPos);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
moveBy(delta.x(), delta.y());
|
|
|
|
} else if (parent) {
|
|
|
|
//don't move the icon as well because our parent
|
|
|
|
//(usually an appletHandle) will do it for us
|
|
|
|
//parent->moveBy(delta.x(),delta.y());
|
|
|
|
QPointF curPos = parent->transform().map(event->pos());
|
|
|
|
QPointF lastPos = parent->transform().map(event->lastPos());
|
|
|
|
QPointF delta = curPos - lastPos;
|
|
|
|
|
|
|
|
parent->setPos(parent->pos() + delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::focusInEvent(QFocusEvent *event)
|
|
|
|
{
|
|
|
|
if (!isContainment() && containment()) {
|
|
|
|
//focusing an applet may trigger this event again, but we won't be here more than twice
|
|
|
|
containment()->d->focusApplet(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsWidget::focusInEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsWidget::resizeEvent(event);
|
|
|
|
|
|
|
|
if (d->background) {
|
|
|
|
d->background->resizeFrame(boundingRect().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConstraints(Plasma::SizeConstraint);
|
|
|
|
|
2008-12-15 18:41:37 +01:00
|
|
|
d->scheduleModificationNotification();
|
2008-11-04 00:08:39 +01:00
|
|
|
emit geometryChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::showConfigurationInterface()
|
|
|
|
{
|
|
|
|
if (!hasConfigurationInterface()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (immutability() != Mutable && !KAuthorized::authorize("PlasmaAllowConfigureWhenLocked")) {
|
2008-11-25 01:06:00 +01:00
|
|
|
//FIXME: in 4.3 add an explanatory dialog
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-20 03:11:01 +01:00
|
|
|
KConfigDialog *dlg = KConfigDialog::exists(d->configDialogId());
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (dlg) {
|
|
|
|
KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop());
|
|
|
|
dlg->show();
|
|
|
|
KWindowSystem::activateWindow(dlg->winId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->package && d->configLoader) {
|
2009-01-22 01:00:16 +01:00
|
|
|
KConfigDialog *dialog = new KConfigDialog(0, d->configDialogId(), d->configLoader);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-26 20:04:02 +02:00
|
|
|
QString uiFile = d->package->filePath("mainconfigui");
|
|
|
|
if (!uiFile.isEmpty()) {
|
|
|
|
dialog->setWindowTitle(d->configWindowTitle());
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
QUiLoader loader;
|
|
|
|
QFile f(uiFile);
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) {
|
|
|
|
delete dialog;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-05-26 20:04:02 +02:00
|
|
|
if (d->script) {
|
|
|
|
d->script->showConfigurationInterface();
|
|
|
|
}
|
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-05-26 20:04:02 +02:00
|
|
|
QWidget *w = loader.load(&f);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-15 22:23:56 +01:00
|
|
|
d->addGlobalShortcutsPage(dialog);
|
2009-09-02 04:27:16 +02:00
|
|
|
d->addPublishPage(dialog);
|
2008-11-04 00:08:39 +01:00
|
|
|
dialog->show();
|
|
|
|
} else if (d->script) {
|
|
|
|
d->script->showConfigurationInterface();
|
|
|
|
} else {
|
2009-08-20 21:05:14 +02:00
|
|
|
KConfigDialog *dialog = d->generateGenericConfigDialog();
|
2009-09-03 01:49:46 +02:00
|
|
|
//createConfigurationInterface(dialog);
|
2009-10-23 15:48:29 +02:00
|
|
|
d->addStandardConfigurationPages(dialog);
|
2009-08-20 21:05:14 +02:00
|
|
|
dialog->show();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit releaseVisualFocus();
|
|
|
|
}
|
|
|
|
|
2009-01-20 03:11:01 +01:00
|
|
|
QString AppletPrivate::configDialogId() const
|
|
|
|
{
|
|
|
|
return QString("%1settings%2").arg(appletId).arg(q->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletPrivate::configWindowTitle() const
|
|
|
|
{
|
|
|
|
return i18nc("@title:window", "%1 Settings", q->name());
|
|
|
|
}
|
|
|
|
|
2009-05-01 20:03:13 +02:00
|
|
|
QSet<QString> AppletPrivate::knownCategories()
|
|
|
|
{
|
|
|
|
// this is to trick the tranlsation tools into making the correct
|
|
|
|
// strings for translation
|
2009-05-18 13:15:00 +02:00
|
|
|
QSet<QString> categories = s_customCategories;
|
2009-05-01 20:03:13 +02:00
|
|
|
categories << QString(I18N_NOOP("Accessibility")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Application Launchers")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Astronomy")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Date and Time")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Development Tools")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Education")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Environment and Weather")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Examples")).toLower()
|
|
|
|
<< QString(I18N_NOOP("File System")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Fun and Games")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Graphics")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Language")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Mapping")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Miscellaneous")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Multimedia")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Online Services")).toLower()
|
|
|
|
<< QString(I18N_NOOP("System Information")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Utilities")).toLower()
|
|
|
|
<< QString(I18N_NOOP("Windows and Tasks")).toLower();
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2009-02-24 03:32:48 +01:00
|
|
|
KConfigDialog *AppletPrivate::generateGenericConfigDialog()
|
2009-01-20 03:11:01 +01:00
|
|
|
{
|
|
|
|
KConfigSkeleton *nullManager = new KConfigSkeleton(0);
|
|
|
|
KConfigDialog *dialog = new KConfigDialog(0, configDialogId(), nullManager);
|
|
|
|
dialog->setFaceType(KPageDialog::Auto);
|
|
|
|
dialog->setWindowTitle(configWindowTitle());
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
2009-09-02 04:27:16 +02:00
|
|
|
q->createConfigurationInterface(dialog);
|
|
|
|
//TODO: Apply button does not correctly work for now, so do not show it
|
|
|
|
dialog->showButton(KDialog::Apply, false);
|
|
|
|
QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished()));
|
|
|
|
QObject::connect(dialog, SIGNAL(okClicked()), q, SLOT(configDialogFinished()));
|
2009-08-20 21:05:14 +02:00
|
|
|
QObject::connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
|
2009-02-24 03:32:48 +01:00
|
|
|
return dialog;
|
2009-01-20 03:11:01 +01:00
|
|
|
}
|
|
|
|
|
2009-10-23 15:48:29 +02:00
|
|
|
void AppletPrivate::addStandardConfigurationPages(KConfigDialog *dialog)
|
|
|
|
{
|
|
|
|
addGlobalShortcutsPage(dialog);
|
|
|
|
addPublishPage(dialog);
|
|
|
|
}
|
|
|
|
|
2008-11-15 22:23:56 +01:00
|
|
|
void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog)
|
|
|
|
{
|
2008-11-17 22:06:09 +01:00
|
|
|
if (isContainment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-15 22:23:56 +01:00
|
|
|
QWidget *page = new QWidget;
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(page);
|
|
|
|
|
|
|
|
if (!shortcutEditor) {
|
|
|
|
shortcutEditor = new KKeySequenceWidget(page);
|
2008-11-21 04:43:45 +01:00
|
|
|
QObject::connect(shortcutEditor, SIGNAL(destroyed(QObject*)), q, SLOT(clearShortcutEditorPtr()));
|
2008-11-15 22:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
shortcutEditor->setKeySequence(q->globalShortcut().primary());
|
|
|
|
layout->addWidget(shortcutEditor);
|
|
|
|
layout->addStretch();
|
|
|
|
dialog->addPage(page, i18n("Keyboard Shortcut"), "preferences-desktop-keyboard");
|
2009-08-20 20:19:44 +02:00
|
|
|
|
|
|
|
//TODO: Apply button does not correctly work for now, so do not show it
|
|
|
|
dialog->showButton(KDialog::Apply, false);
|
|
|
|
QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished()));
|
|
|
|
QObject::connect(dialog, SIGNAL(okClicked()), q, SLOT(configDialogFinished()));
|
2008-11-15 22:23:56 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
void AppletPrivate::addPublishPage(KConfigDialog *dialog)
|
|
|
|
{
|
2009-09-12 02:19:42 +02:00
|
|
|
#ifdef ENABLE_REMOTE_WIDGETS
|
2009-09-02 04:27:16 +02:00
|
|
|
QWidget *page = new QWidget;
|
|
|
|
publishUI.setupUi(page);
|
2009-09-04 02:08:26 +02:00
|
|
|
publishUI.publishCheckbox->setChecked(q->isPublished());
|
|
|
|
publishUI.allUsersCheckbox->setEnabled(q->isPublished());
|
|
|
|
|
|
|
|
QString resourceName =
|
|
|
|
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
|
|
|
|
"%1 on %2", q->name(), QHostInfo::localHostName());
|
|
|
|
if (AuthorizationManager::self()->d->matchingRule(resourceName, Credentials())) {
|
|
|
|
publishUI.allUsersCheckbox->setChecked(true);
|
|
|
|
} else {
|
|
|
|
publishUI.allUsersCheckbox->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
q->connect(publishUI.publishCheckbox, SIGNAL(stateChanged(int)),
|
|
|
|
q, SLOT(publishCheckboxStateChanged(int)));
|
2009-10-19 15:29:29 +02:00
|
|
|
dialog->addPage(page, i18n("Share"), "applications-internet");
|
2009-09-12 02:19:42 +02:00
|
|
|
#endif
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 02:08:26 +02:00
|
|
|
void AppletPrivate::publishCheckboxStateChanged(int state)
|
|
|
|
{
|
|
|
|
if (state == Qt::Checked) {
|
|
|
|
publishUI.allUsersCheckbox->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
publishUI.allUsersCheckbox->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-21 04:43:45 +01:00
|
|
|
void AppletPrivate::clearShortcutEditorPtr()
|
|
|
|
{
|
|
|
|
shortcutEditor = 0;
|
|
|
|
}
|
|
|
|
|
2009-01-05 19:08:14 +01:00
|
|
|
void AppletPrivate::configDialogFinished()
|
|
|
|
{
|
|
|
|
if (shortcutEditor) {
|
|
|
|
QKeySequence sequence = shortcutEditor->keySequence();
|
|
|
|
if (sequence != q->globalShortcut().primary()) {
|
|
|
|
q->setGlobalShortcut(KShortcut(sequence));
|
|
|
|
emit q->configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-12 13:07:11 +02:00
|
|
|
#ifdef ENABLE_REMOTE_WIDGETS
|
2009-10-19 15:29:29 +02:00
|
|
|
q->config().writeEntry("Share", publishUI.publishCheckbox->isChecked());
|
2009-09-03 01:49:46 +02:00
|
|
|
|
|
|
|
if (publishUI.publishCheckbox->isChecked()) {
|
2009-09-04 02:08:26 +02:00
|
|
|
QString resourceName =
|
|
|
|
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
|
|
|
|
"%1 on %2", q->name(), QHostInfo::localHostName());
|
|
|
|
q->publish(Plasma::ZeroconfAnnouncement, resourceName);
|
|
|
|
if (publishUI.allUsersCheckbox->isChecked()) {
|
|
|
|
if (!AuthorizationManager::self()->d->matchingRule(resourceName, Credentials())) {
|
|
|
|
AuthorizationRule *rule = new AuthorizationRule(resourceName, "");
|
|
|
|
rule->setPolicy(AuthorizationRule::Allow);
|
|
|
|
rule->setTargets(AuthorizationRule::AllUsers);
|
|
|
|
AuthorizationManager::self()->d->rules.append(rule);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
AuthorizationRule *matchingRule =
|
|
|
|
AuthorizationManager::self()->d->matchingRule(resourceName, Credentials());
|
|
|
|
if (matchingRule) {
|
|
|
|
AuthorizationManager::self()->d->rules.removeAll(matchingRule);
|
|
|
|
}
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
} else {
|
2009-09-03 01:49:46 +02:00
|
|
|
q->unpublish();
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
#endif
|
2009-09-02 04:27:16 +02:00
|
|
|
|
2009-05-26 19:32:33 +02:00
|
|
|
if (!configLoader) {
|
|
|
|
// the config loader will trigger this for us, so we don't need to.
|
|
|
|
q->configChanged();
|
|
|
|
}
|
2009-01-05 19:08:14 +01:00
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
void AppletPrivate::updateShortcuts()
|
|
|
|
{
|
|
|
|
if (isContainment) {
|
|
|
|
//a horrible hack to avoid clobbering corona settings
|
|
|
|
//we pull them out, then read, then put them back
|
|
|
|
QList<QString> names;
|
|
|
|
QList<QAction*> qactions;
|
|
|
|
names << "zoom out" << "add sibling containment" << "configure shortcuts" << "lock widgets";
|
|
|
|
foreach (const QString &name, names) {
|
|
|
|
QAction *a = actions->action(name);
|
|
|
|
actions->takeAction(a); //FIXME this is stupid, KActionCollection needs a takeAction(QString) method
|
|
|
|
qactions << a;
|
|
|
|
}
|
|
|
|
|
|
|
|
actions->readSettings();
|
|
|
|
|
2009-07-30 20:13:01 +02:00
|
|
|
for (int i = 0; i < names.size(); ++i) {
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *a = qactions.at(i);
|
|
|
|
if (a) {
|
|
|
|
actions->addAction(names.at(i), a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actions->readSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::configChanged()
|
|
|
|
{
|
|
|
|
if (d->script) {
|
|
|
|
d->script->configChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::createConfigurationInterface(KConfigDialog *parent)
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
// virtual method reimplemented by subclasses.
|
|
|
|
// do not put anything here ...
|
|
|
|
}
|
|
|
|
|
2009-06-03 03:10:57 +02:00
|
|
|
bool Applet::hasAuthorization(const QString &constraint) const
|
2009-03-04 18:05:51 +01:00
|
|
|
{
|
|
|
|
KConfigGroup constraintGroup(KGlobal::config(), "Constraints");
|
|
|
|
return constraintGroup.readEntry(constraint, true);
|
|
|
|
}
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
void Applet::setAssociatedApplication(const QString &string)
|
|
|
|
{
|
|
|
|
AssociatedApplicationManager::self()->setApplication(this, string);
|
|
|
|
|
|
|
|
QAction *runAssociatedApplication = d->actions->action("run associated application");
|
|
|
|
if (runAssociatedApplication) {
|
|
|
|
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
runAssociatedApplication->setVisible(valid);
|
|
|
|
runAssociatedApplication->setEnabled(valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setAssociatedApplicationUrls(const KUrl::List &urls)
|
|
|
|
{
|
|
|
|
AssociatedApplicationManager::self()->setUrls(this, urls);
|
|
|
|
|
|
|
|
QAction *runAssociatedApplication = d->actions->action("run associated application");
|
|
|
|
if (runAssociatedApplication) {
|
|
|
|
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
runAssociatedApplication->setVisible(valid);
|
|
|
|
runAssociatedApplication->setEnabled(valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::associatedApplication() const
|
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->application(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
KUrl::List Applet::associatedApplicationUrls() const
|
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->urls(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::runAssociatedApplication()
|
|
|
|
{
|
|
|
|
AssociatedApplicationManager::self()->run(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::hasValidAssociatedApplication() const
|
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
}
|
|
|
|
|
2009-11-11 01:24:49 +01:00
|
|
|
void AppletPrivate::filterOffers(QList<KService::Ptr> &offers)
|
|
|
|
{
|
|
|
|
KConfigGroup constraintGroup(KGlobal::config(), "Constraints");
|
|
|
|
foreach (const QString &key, constraintGroup.keyList()) {
|
|
|
|
//kDebug() << "security constraint" << key;
|
|
|
|
if (constraintGroup.readEntry(key, true)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//ugh. a qlist of ksharedptr<kservice>
|
|
|
|
QMutableListIterator<KService::Ptr> it(offers);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
KService::Ptr p = it.next();
|
|
|
|
QString prop = QString("X-Plasma-Requires-").append(key);
|
|
|
|
QVariant req = p->property(prop, QVariant::String);
|
|
|
|
//valid values: Required/Optional/Unused
|
|
|
|
QString reqValue;
|
|
|
|
if (req.isValid()) {
|
|
|
|
reqValue = req.toString();
|
|
|
|
} else if (p->property("X-Plasma-API").toString().toLower() == "javascript") {
|
|
|
|
//TODO: be able to check whether or not a script engine provides "controled"
|
|
|
|
//bindings; for now we just give a pass to the qscript ones
|
|
|
|
reqValue = "Unused";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(reqValue == "Optional" || reqValue == "Unused")) {
|
|
|
|
//if (reqValue == "Required") {
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KPluginInfo::List Applet::listAppletInfo(const QString &category,
|
|
|
|
const QString &parentApp)
|
|
|
|
{
|
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
2009-07-25 07:00:27 +02:00
|
|
|
constraint.append("(not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
2009-02-14 14:28:25 +01:00
|
|
|
//note: constraint guaranteed non-empty from here down
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-02-14 14:28:25 +01:00
|
|
|
if (category.isEmpty()) { //use all but the excluded categories
|
|
|
|
KConfigGroup group(KGlobal::config(), "General");
|
|
|
|
QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
|
|
|
|
foreach (const QString &category, excluded) {
|
2009-05-01 20:03:13 +02:00
|
|
|
constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-02-14 14:28:25 +01:00
|
|
|
} else { //specific category (this could be an excluded one - is that bad?)
|
2009-05-01 20:03:13 +02:00
|
|
|
constraint.append(" and ");
|
|
|
|
|
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
2008-11-04 00:08:39 +01:00
|
|
|
if (category == "Miscellaneous") {
|
2009-05-01 20:03:13 +02:00
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2009-07-26 16:20:31 +02:00
|
|
|
offers << KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
2009-03-04 18:05:51 +01:00
|
|
|
|
|
|
|
//now we have to do some manual filtering because the constraint can't handle everything
|
2009-11-11 01:24:49 +01:00
|
|
|
AppletPrivate::filterOffers(offers);
|
2009-03-04 18:05:51 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//kDebug() << "Applet::listAppletInfo constraint was '" << constraint
|
|
|
|
// << "' which got us " << offers.count() << " matches";
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List Applet::listAppletInfoForMimetype(const QString &mimetype)
|
|
|
|
{
|
|
|
|
QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimetype);
|
|
|
|
//kDebug() << "listAppletInfoForMimetype with" << mimetype << constraint;
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2009-07-26 16:20:31 +02:00
|
|
|
offers << KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
2009-11-11 01:24:49 +01:00
|
|
|
AppletPrivate::filterOffers(offers);
|
2008-11-04 00:08:39 +01:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2009-10-29 10:09:01 +01:00
|
|
|
|
|
|
|
KPluginInfo::List Applet::listAppletInfoForUrl(const QUrl &url)
|
|
|
|
{
|
|
|
|
QString constraint = "exist [X-Plasma-DropUrlPatterns]";
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
offers << KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
2009-11-11 01:24:49 +01:00
|
|
|
AppletPrivate::filterOffers(offers);
|
2009-10-29 10:09:01 +01:00
|
|
|
|
|
|
|
KPluginInfo::List allApplets = KPluginInfo::fromServices(offers);
|
|
|
|
KPluginInfo::List filtered;
|
|
|
|
foreach (const KPluginInfo &info, allApplets) {
|
|
|
|
QStringList urlPatterns = info.property("X-Plasma-DropUrlPatterns").toStringList();
|
|
|
|
foreach (const QString &glob, urlPatterns) {
|
|
|
|
QRegExp rx(glob);
|
|
|
|
rx.setPatternSyntax(QRegExp::Wildcard);
|
|
|
|
if (rx.exactMatch(url.toString())) {
|
|
|
|
kDebug() << info.name() << "matches" << glob << url;
|
|
|
|
filtered << info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-11 01:24:49 +01:00
|
|
|
|
2009-10-29 10:09:01 +01:00
|
|
|
return filtered;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
|
|
|
|
{
|
2009-05-01 20:03:13 +02:00
|
|
|
QString constraint = "exist [X-KDE-PluginInfo-Category]";
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
2009-07-25 07:00:27 +02:00
|
|
|
constraint.append("and (not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '')");
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
2009-02-14 14:28:25 +01:00
|
|
|
KConfigGroup group(KGlobal::config(), "General");
|
2009-07-06 13:49:01 +02:00
|
|
|
const QStringList excluded = group.readEntry("ExcludeCategories", QStringList());
|
2009-02-14 14:28:25 +01:00
|
|
|
foreach (const QString &category, excluded) {
|
2009-05-01 20:03:13 +02:00
|
|
|
constraint.append(" and [X-KDE-PluginInfo-Category] != '").append(category).append("'");
|
2009-02-14 14:28:25 +01:00
|
|
|
}
|
|
|
|
|
2009-07-26 16:20:31 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
offers << KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
2009-11-11 01:24:49 +01:00
|
|
|
AppletPrivate::filterOffers(offers);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QStringList categories;
|
2009-05-01 20:03:13 +02:00
|
|
|
QSet<QString> known = AppletPrivate::knownCategories();
|
2008-11-04 00:08:39 +01:00
|
|
|
foreach (const KService::Ptr &applet, offers) {
|
2009-05-01 20:03:13 +02:00
|
|
|
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
|
2008-11-04 00:08:39 +01:00
|
|
|
if (visibleOnly && applet->noDisplay()) {
|
|
|
|
// we don't want to show the hidden category
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << " and we have " << appletCategory;
|
2009-05-01 20:03:13 +02:00
|
|
|
if (!appletCategory.isEmpty() && !known.contains(appletCategory.toLower())) {
|
|
|
|
kDebug() << "Unknown category: " << applet->name() << "says it is in the"
|
|
|
|
<< appletCategory << "category which is unknown to us";
|
|
|
|
appletCategory.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (appletCategory.isEmpty()) {
|
2008-11-04 13:54:19 +01:00
|
|
|
if (!categories.contains(i18nc("misc category", "Miscellaneous"))) {
|
|
|
|
categories << i18nc("misc category", "Miscellaneous");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-05-01 20:03:13 +02:00
|
|
|
} else if (!categories.contains(appletCategory)) {
|
|
|
|
categories << appletCategory;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
categories.sort();
|
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2009-05-18 13:15:00 +02:00
|
|
|
void Applet::setCustomCategories(const QStringList &categories)
|
|
|
|
{
|
|
|
|
AppletPrivate::s_customCategories = QSet<QString>::fromList(categories);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList Applet::customCategories()
|
|
|
|
{
|
|
|
|
return AppletPrivate::s_customCategories.toList();
|
|
|
|
}
|
|
|
|
|
2009-04-26 02:43:20 +02:00
|
|
|
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
|
|
|
|
: QGraphicsWidget(0),
|
|
|
|
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), appletId, this))
|
|
|
|
{
|
|
|
|
Q_UNUSED(args) // FIXME?
|
|
|
|
d->init(packagePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantList &args)
|
|
|
|
{
|
|
|
|
if (QFile::exists(path + "/metadata.desktop")) {
|
2009-10-23 15:48:29 +02:00
|
|
|
KService service(path + "/metadata.desktop");
|
|
|
|
const QStringList& types = service.serviceTypes();
|
|
|
|
|
|
|
|
if (types.contains("Plasma/Containment")) {
|
|
|
|
return new Containment(path, appletId, args);
|
|
|
|
} else if (types.contains("Plasma/PopupApplet")) {
|
|
|
|
return new PopupApplet(path, appletId, args);
|
|
|
|
} else {
|
|
|
|
return new Applet(path, appletId, args);
|
|
|
|
}
|
2009-04-26 02:43:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet *Applet::load(const QString &appletName, uint appletId, const QVariantList &args)
|
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-06 13:49:01 +02:00
|
|
|
const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
2008-11-04 00:08:39 +01:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
bool isContainment = false;
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
//TODO: what would be -really- cool is offer to try and download the applet
|
|
|
|
// from the network at this point
|
|
|
|
offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
2009-04-23 12:54:45 +02:00
|
|
|
if (offers.count() > 0) {
|
|
|
|
isContainment = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-04-23 12:54:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPopupApplet = false;
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
offers = KServiceTypeTrader::self()->query("Plasma/PopupApplet", constraint);
|
|
|
|
if (offers.count() > 0) {
|
|
|
|
isPopupApplet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if (offers.count() > 1) {
|
2008-11-04 00:08:39 +01:00
|
|
|
kDebug() << "hey! we got more than one! let's blindly take the first one";
|
|
|
|
} */
|
2009-05-29 18:41:06 +02:00
|
|
|
|
2009-11-11 02:56:59 +01:00
|
|
|
AppletPrivate::filterOffers(offers);
|
2009-04-23 12:54:45 +02:00
|
|
|
if (offers.isEmpty()) {
|
|
|
|
kDebug() << "offers is empty for " << appletName;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
KService::Ptr offer = offers.first();
|
|
|
|
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = ++AppletPrivate::s_maxAppletId;
|
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << offer->storageId() << appletId << args;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!offer->property("X-Plasma-API").toString().isEmpty()) {
|
|
|
|
kDebug() << "we have a script using the"
|
|
|
|
<< offer->property("X-Plasma-API").toString() << "API";
|
|
|
|
if (isContainment) {
|
2009-04-23 12:54:45 +02:00
|
|
|
return new Containment(0, allArgs);
|
|
|
|
} else if (isPopupApplet) {
|
|
|
|
return new PopupApplet(0, allArgs);
|
|
|
|
} else {
|
|
|
|
return new Applet(0, allArgs);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginLoader plugin(*offer);
|
|
|
|
|
|
|
|
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion()) &&
|
|
|
|
(appletName != "internal:extender")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString error;
|
|
|
|
Applet *applet;
|
|
|
|
|
|
|
|
if (appletName == "internal:extender") {
|
|
|
|
applet = new ExtenderApplet(0, allArgs);
|
|
|
|
} else {
|
|
|
|
applet = offer->createInstance<Plasma::Applet>(0, allArgs, &error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "Couldn't load applet \"" << appletName << "\"! reason given: " << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *Applet::load(const KPluginInfo &info, uint appletId, const QVariantList &args)
|
|
|
|
{
|
|
|
|
if (!info.isValid()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return load(info.pluginName(), appletId, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
QVariant ret = QGraphicsWidget::itemChange(change, value);
|
|
|
|
|
|
|
|
//kDebug() << change;
|
|
|
|
switch (change) {
|
|
|
|
case ItemSceneHasChanged:
|
|
|
|
{
|
|
|
|
QGraphicsScene *newScene = qvariant_cast<QGraphicsScene*>(value);
|
|
|
|
if (newScene) {
|
|
|
|
d->checkImmutability();
|
|
|
|
}
|
|
|
|
}
|
2008-12-15 18:41:37 +01:00
|
|
|
break;
|
2009-06-10 20:28:17 +02:00
|
|
|
case ItemParentChange:
|
2009-06-30 20:09:27 +02:00
|
|
|
if (!d->isContainment) {
|
|
|
|
Containment *c = containment();
|
|
|
|
if (d->mainConfig && !c) {
|
|
|
|
kWarning() << "Configuration object was requested prior to init(), which is too early. "
|
|
|
|
"Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
|
|
|
|
<< name();
|
|
|
|
|
|
|
|
Applet *newC = dynamic_cast<Applet*>(value.value<QGraphicsItem *>());
|
|
|
|
if (newC) {
|
|
|
|
// if this is an applet, and we've just been assigned to our first containment,
|
|
|
|
// but the applet did something stupid like ask for the config() object prior to
|
|
|
|
// this happening (e.g. inits ctor) then let's repair that situation for them.
|
|
|
|
KConfigGroup *old = d->mainConfig;
|
|
|
|
KConfigGroup appletConfig = newC->config();
|
|
|
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
|
|
|
d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
|
|
|
|
old->copyTo(d->mainConfig);
|
|
|
|
old->deleteGroup();
|
|
|
|
delete old;
|
|
|
|
}
|
2009-06-25 16:13:14 +02:00
|
|
|
}
|
2009-06-10 20:28:17 +02:00
|
|
|
}
|
2009-06-30 20:09:27 +02:00
|
|
|
break;
|
2008-12-16 04:33:09 +01:00
|
|
|
case ItemPositionChange:
|
2009-02-23 14:48:04 +01:00
|
|
|
return (immutability() == Mutable || isContainment() || formFactor() == Horizontal || formFactor() == Vertical) ? value : pos();
|
2008-12-16 04:33:09 +01:00
|
|
|
break;
|
|
|
|
case ItemTransformChange:
|
|
|
|
return immutability() == Mutable ? value : transform();
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
case ItemPositionHasChanged:
|
|
|
|
emit geometryChanged();
|
|
|
|
// fall through!
|
|
|
|
case ItemTransformHasChanged:
|
2008-12-15 18:41:37 +01:00
|
|
|
d->scheduleModificationNotification();
|
|
|
|
break;
|
2008-11-04 00:08:39 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath Applet::shape() const
|
|
|
|
{
|
|
|
|
if (d->script) {
|
|
|
|
return d->script->shape();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsWidget::shape();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
|
{
|
|
|
|
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
|
|
|
|
|
|
|
//in panels make sure that the contents won't exit from the panel
|
|
|
|
if (formFactor() == Horizontal && which == Qt::MinimumSize) {
|
|
|
|
hint.setHeight(0);
|
|
|
|
} else if (formFactor() == Vertical && which == Qt::MinimumSize) {
|
|
|
|
hint.setWidth(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// enforce a square size in panels
|
|
|
|
if (d->aspectRatioMode == Plasma::Square) {
|
|
|
|
if (formFactor() == Horizontal) {
|
|
|
|
hint.setWidth(size().height());
|
|
|
|
} else if (formFactor() == Vertical) {
|
|
|
|
hint.setHeight(size().width());
|
|
|
|
}
|
|
|
|
} else if (d->aspectRatioMode == Plasma::ConstrainedSquare) {
|
|
|
|
//enforce a size not wider than tall
|
|
|
|
if (formFactor() == Horizontal &&
|
|
|
|
(which == Qt::MaximumSize || size().height() <= KIconLoader::SizeLarge)) {
|
|
|
|
hint.setWidth(size().height());
|
|
|
|
//enforce a size not taller than wide
|
|
|
|
} else if (formFactor() == Vertical &&
|
|
|
|
(which == Qt::MaximumSize || size().width() <= KIconLoader::SizeLarge)) {
|
|
|
|
hint.setHeight(size().width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (d->transient) {
|
|
|
|
killTimer(d->constraintsTimerId);
|
|
|
|
killTimer(d->modificationsTimerId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->timerId() == d->constraintsTimerId) {
|
|
|
|
killTimer(d->constraintsTimerId);
|
|
|
|
d->constraintsTimerId = 0;
|
2008-11-04 18:51:11 +01:00
|
|
|
|
|
|
|
// Don't flushPendingConstraints if we're just starting up
|
|
|
|
// flushPendingConstraints will be called by Corona
|
|
|
|
if(!(d->pendingConstraints & Plasma::StartupCompletedConstraint)) {
|
|
|
|
flushPendingConstraintsEvents();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (event->timerId() == d->modificationsTimerId) {
|
|
|
|
killTimer(d->modificationsTimerId);
|
|
|
|
d->modificationsTimerId = 0;
|
|
|
|
// invalid group, will result in save using the default group
|
|
|
|
KConfigGroup cg;
|
2009-06-30 15:32:40 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
save(cg);
|
|
|
|
emit configNeedsSaving();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect Applet::screenRect() const
|
|
|
|
{
|
|
|
|
QGraphicsView *v = view();
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
QPointF bottomRight = pos();
|
|
|
|
bottomRight.rx() += size().width();
|
|
|
|
bottomRight.ry() += size().height();
|
|
|
|
|
|
|
|
QPoint tL = v->mapToGlobal(v->mapFromScene(pos()));
|
|
|
|
QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight));
|
|
|
|
return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//The applet doesn't have a view on it.
|
|
|
|
//So a screenRect isn't relevant.
|
|
|
|
return QRect(QPoint(0, 0), QSize(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::raise()
|
|
|
|
{
|
|
|
|
setZValue(++AppletPrivate::s_maxZValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::lower()
|
|
|
|
{
|
|
|
|
setZValue(--AppletPrivate::s_minZValue);
|
|
|
|
}
|
|
|
|
|
2009-02-18 14:55:18 +01:00
|
|
|
void AppletPrivate::setIsContainment(bool nowIsContainment, bool forceUpdate)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-02-18 14:55:18 +01:00
|
|
|
if (isContainment == nowIsContainment && !forceUpdate) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isContainment = nowIsContainment;
|
2009-05-03 22:22:14 +02:00
|
|
|
//FIXME I do not like this function.
|
|
|
|
//currently it's only called before ctmt/applet init, with (true,true), and I'm going to assume it stays that way.
|
|
|
|
//if someone calls it at some other time it'll cause headaches. :P
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-01-22 01:00:16 +01:00
|
|
|
delete mainConfig;
|
|
|
|
mainConfig = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isContainment() const
|
|
|
|
{
|
|
|
|
return d->isContainment;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PRIVATE CLASS IMPLEMENTATION
|
|
|
|
|
|
|
|
AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet)
|
|
|
|
: appletId(uniqueID),
|
|
|
|
q(applet),
|
2009-09-02 04:27:16 +02:00
|
|
|
extender(0),
|
|
|
|
service(0),
|
2009-07-27 22:14:38 +02:00
|
|
|
preferredBackgroundHints(Applet::StandardBackground),
|
2009-09-05 01:45:44 +02:00
|
|
|
backgroundHints(Applet::NoBackground),
|
2009-06-10 20:28:17 +02:00
|
|
|
aspectRatioMode(Plasma::KeepAspectRatio),
|
|
|
|
immutability(Mutable),
|
2008-11-04 00:08:39 +01:00
|
|
|
appletDescription(service),
|
2009-06-10 20:28:17 +02:00
|
|
|
background(0),
|
|
|
|
mainConfig(0),
|
|
|
|
pendingConstraints(NoConstraint),
|
2008-11-06 16:52:13 +01:00
|
|
|
messageOverlay(0),
|
2009-06-10 20:28:17 +02:00
|
|
|
messageOverlayProxy(0),
|
2008-11-04 19:22:55 +01:00
|
|
|
busyWidget(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
script(0),
|
|
|
|
package(0),
|
|
|
|
configLoader(0),
|
2009-05-03 22:22:14 +02:00
|
|
|
actions(AppletPrivate::defaultActions(applet)),
|
2008-11-04 00:08:39 +01:00
|
|
|
activationAction(0),
|
2008-11-15 22:23:56 +01:00
|
|
|
shortcutEditor(0),
|
2009-07-09 19:19:00 +02:00
|
|
|
itemStatus(UnknownStatus),
|
2008-11-04 00:08:39 +01:00
|
|
|
constraintsTimerId(0),
|
|
|
|
modificationsTimerId(-1),
|
2009-01-20 04:12:08 +01:00
|
|
|
hasConfigurationInterface(false),
|
2008-11-04 00:08:39 +01:00
|
|
|
failed(false),
|
|
|
|
isContainment(false),
|
|
|
|
transient(false),
|
2008-11-14 05:34:52 +01:00
|
|
|
needsConfig(false),
|
|
|
|
started(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = ++s_maxAppletId;
|
|
|
|
} else if (appletId > s_maxAppletId) {
|
|
|
|
s_maxAppletId = appletId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AppletPrivate::~AppletPrivate()
|
|
|
|
{
|
|
|
|
modificationsTimerId = -1;
|
|
|
|
|
|
|
|
if (activationAction && activationAction->isGlobalShortcutEnabled()) {
|
|
|
|
//kDebug() << "reseting global action for" << q->name() << activationAction->objectName();
|
|
|
|
activationAction->forgetGlobalShortcut();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extender) {
|
|
|
|
delete extender;
|
|
|
|
extender = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete script;
|
|
|
|
script = 0;
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
delete configLoader;
|
|
|
|
configLoader = 0;
|
|
|
|
delete mainConfig;
|
|
|
|
mainConfig = 0;
|
|
|
|
}
|
|
|
|
|
2009-04-26 02:43:20 +02:00
|
|
|
void AppletPrivate::init(const QString &packagePath)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
q->setCacheMode(Applet::DeviceCoordinateCache);
|
|
|
|
q->setAcceptsHoverEvents(true);
|
|
|
|
q->setFlag(QGraphicsItem::ItemIsFocusable, true);
|
2008-11-26 17:38:42 +01:00
|
|
|
q->setFocusPolicy(Qt::ClickFocus);
|
2008-11-04 00:08:39 +01:00
|
|
|
// FIXME: adding here because nothing seems to be doing it in QGraphicsView,
|
|
|
|
// but it doesn't actually work anyways =/
|
|
|
|
q->setLayoutDirection(qApp->layoutDirection());
|
|
|
|
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
kDebug() << "Check your constructor! "
|
|
|
|
<< "You probably want to be passing in a Service::Ptr "
|
|
|
|
<< "or a QVariantList with a valid storageid as arg[0].";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString api = appletDescription.property("X-Plasma-API").toString();
|
|
|
|
|
|
|
|
// we have a scripted plasmoid
|
|
|
|
if (!api.isEmpty()) {
|
|
|
|
// find where the Package is
|
2009-04-26 02:43:20 +02:00
|
|
|
QString path = packagePath;
|
|
|
|
if (path.isEmpty()) {
|
2009-04-28 04:21:49 +02:00
|
|
|
path = KStandardDirs::locate("data", "plasma/plasmoids/" + appletDescription.pluginName() + '/');
|
2009-04-26 05:15:25 +02:00
|
|
|
} else if (!path.endsWith('/')) {
|
|
|
|
path.append('/');
|
2009-04-26 02:43:20 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
q->setFailedToLaunch(
|
|
|
|
true,
|
|
|
|
i18nc("Package file, name of the widget",
|
2008-11-04 13:49:28 +01:00
|
|
|
"Could not locate the %1 package required for the %2 widget.",
|
|
|
|
appletDescription.pluginName(), appletDescription.name()));
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
// create the package and see if we have something real
|
|
|
|
//kDebug() << "trying for" << path;
|
2009-04-26 02:43:20 +02:00
|
|
|
PackageStructure::Ptr structure = Plasma::packageStructure(api, Plasma::AppletComponent);
|
2008-11-04 00:08:39 +01:00
|
|
|
structure->setPath(path);
|
|
|
|
package = new Package(path, structure);
|
|
|
|
|
|
|
|
if (package->isValid()) {
|
|
|
|
// now we try and set up the script engine.
|
|
|
|
// it will be parented to this applet and so will get
|
|
|
|
// deleted when the applet does
|
|
|
|
|
|
|
|
script = Plasma::loadScriptEngine(api, q);
|
|
|
|
if (!script) {
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
q->setFailedToLaunch(true,
|
|
|
|
i18nc("API or programming language the widget was written in, name of the widget",
|
2008-11-04 13:49:28 +01:00
|
|
|
"Could not create a %1 ScriptEngine for the %2 widget.",
|
|
|
|
api, appletDescription.name()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
q->setFailedToLaunch(true, i18nc("Package file, name of the widget",
|
2008-11-04 13:49:28 +01:00
|
|
|
"Could not open the %1 package required for the %2 widget.",
|
|
|
|
appletDescription.pluginName(), appletDescription.name()));
|
2008-11-04 00:08:39 +01:00
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-20 17:58:59 +02:00
|
|
|
//set a default size before any saved settings are read
|
|
|
|
QSize size = appletDescription.property("X-Plasma-DefaultSize").toSize();
|
|
|
|
if (size.isEmpty()) {
|
|
|
|
size = QSize(200, 200);
|
|
|
|
}
|
|
|
|
//kDebug() << "size" << size;
|
|
|
|
q->resize(size);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
q->setBackgroundHints(Applet::DefaultBackground);
|
2009-05-03 22:22:14 +02:00
|
|
|
q->setHasConfigurationInterface(true); //FIXME why not default it to true in the constructor?
|
|
|
|
|
|
|
|
QAction *closeApplet = actions->action("remove");
|
2009-07-30 20:13:01 +02:00
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setText(i18nc("%1 is the name of the applet", "Remove this %1", q->name()));
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *configAction = actions->action("configure");
|
2009-07-30 20:13:01 +02:00
|
|
|
if (configAction) {
|
|
|
|
configAction->setText(i18nc("%1 is the name of the applet", "%1 Settings", q->name()));
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QObject::connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
|
2009-04-27 17:23:53 +02:00
|
|
|
QObject::connect(q, SIGNAL(activate()), q, SLOT(setFocus()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// put all setup routines for script here. at this point we can assume that
|
|
|
|
// package exists and that we have a script engine
|
|
|
|
void AppletPrivate::setupScriptSupport()
|
|
|
|
{
|
2009-11-11 20:26:05 +01:00
|
|
|
if (!package) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-11 23:35:51 +01:00
|
|
|
kDebug() << "setting up script support, package is in" << package->path()
|
|
|
|
<< "which is a" << package->structure()->type() << "package"
|
|
|
|
<< ", main script is" << package->filePath("mainscript");
|
|
|
|
|
2009-05-01 20:31:14 +02:00
|
|
|
QString translationsPath = package->filePath("translations");
|
|
|
|
if (!translationsPath.isEmpty()) {
|
|
|
|
//FIXME: we should _probably_ use a KComponentData to segregate the applets
|
|
|
|
// from each other; but I want to get the basics working first :)
|
|
|
|
KGlobal::dirs()->addResourceDir("locale", translationsPath);
|
2009-05-29 18:41:06 +02:00
|
|
|
KGlobal::locale()->insertCatalog(package->metadata().pluginName());
|
2009-05-01 20:31:14 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString xmlPath = package->filePath("mainconfigxml");
|
|
|
|
if (!xmlPath.isEmpty()) {
|
|
|
|
QFile file(xmlPath);
|
|
|
|
KConfigGroup config = q->config();
|
|
|
|
configLoader = new ConfigLoader(&config, &file);
|
|
|
|
QObject::connect(configLoader, SIGNAL(configChanged()), q, SLOT(configChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!package->filePath("mainconfigui").isEmpty()) {
|
|
|
|
q->setHasConfigurationInterface(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletPrivate::globalName() const
|
|
|
|
{
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletDescription.service()->library();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletPrivate::instanceName()
|
|
|
|
{
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletDescription.service()->library() + QString::number(appletId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::scheduleConstraintsUpdate(Plasma::Constraints c)
|
|
|
|
{
|
|
|
|
// Don't start up a timer if we're just starting up
|
|
|
|
// flushPendingConstraints will be called by Corona
|
2008-11-14 05:34:52 +01:00
|
|
|
if (started && !constraintsTimerId && !(c & Plasma::StartupCompletedConstraint)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
constraintsTimerId = q->startTimer(0);
|
|
|
|
}
|
|
|
|
|
2008-11-14 05:34:52 +01:00
|
|
|
if (c & Plasma::StartupCompletedConstraint) {
|
|
|
|
started = true;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
pendingConstraints |= c;
|
|
|
|
}
|
|
|
|
|
2008-12-15 18:41:37 +01:00
|
|
|
void AppletPrivate::scheduleModificationNotification()
|
|
|
|
{
|
|
|
|
// modificationsTimerId is -1 until we get our notice of being started
|
|
|
|
if (modificationsTimerId != -1) {
|
|
|
|
// schedule a save
|
|
|
|
if (modificationsTimerId) {
|
|
|
|
q->killTimer(modificationsTimerId);
|
|
|
|
}
|
|
|
|
|
|
|
|
modificationsTimerId = q->startTimer(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup *AppletPrivate::mainConfigGroup()
|
|
|
|
{
|
|
|
|
if (mainConfig) {
|
|
|
|
return mainConfig;
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
bool newGroup = false;
|
2008-11-04 00:08:39 +01:00
|
|
|
if (isContainment) {
|
2008-12-18 23:14:06 +01:00
|
|
|
Corona *corona = qobject_cast<Corona*>(q->scene());
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup containmentConfig;
|
2009-01-22 01:00:16 +01:00
|
|
|
//kDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q;
|
2008-12-18 23:14:06 +01:00
|
|
|
|
|
|
|
if (corona) {
|
|
|
|
containmentConfig = KConfigGroup(corona->config(), "Containments");
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
containmentConfig = KConfigGroup(KGlobal::config(), "Containments");
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
if (!containmentConfig.hasGroup(QString::number(appletId))) {
|
|
|
|
newGroup = true;
|
|
|
|
}
|
2009-10-05 20:21:24 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
mainConfig = new KConfigGroup(&containmentConfig, QString::number(appletId));
|
|
|
|
} else {
|
|
|
|
KConfigGroup appletConfig;
|
2009-06-30 20:09:27 +02:00
|
|
|
|
|
|
|
if (Containment *c = q->containment()) {
|
|
|
|
Plasma::Applet *parentApplet = qobject_cast<Applet *>(q->parent());
|
|
|
|
if (parentApplet && parentApplet != static_cast<Applet *>(c)) {
|
|
|
|
// this applet is nested inside another applet! use it's config
|
|
|
|
// as the parent group in the config
|
|
|
|
appletConfig = parentApplet->config();
|
|
|
|
} else {
|
|
|
|
// applet directly in a Containment, as usual
|
|
|
|
appletConfig = c->config();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
|
|
|
} else {
|
|
|
|
kWarning() << "requesting config for" << q->name() << "without a containment!";
|
|
|
|
appletConfig = KConfigGroup(KGlobal::config(), "Applets");
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
if (!appletConfig.hasGroup(QString::number(appletId))) {
|
|
|
|
newGroup = true;
|
|
|
|
}
|
2009-10-05 20:21:24 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
mainConfig = new KConfigGroup(&appletConfig, QString::number(appletId));
|
|
|
|
}
|
|
|
|
|
2009-09-02 04:27:16 +02:00
|
|
|
if (newGroup && q->package()) {
|
|
|
|
//see if we have a default configuration in our package
|
|
|
|
kDebug() << "copying default config: " << q->package()->filePath("defaultconfig");
|
|
|
|
KConfigGroup defaultConfig(KSharedConfig::openConfig(q->package()->filePath("config",
|
|
|
|
"default-configrc"))->group("Configuration"));
|
|
|
|
defaultConfig.copyTo(mainConfig);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return mainConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletPrivate::visibleFailureText(const QString &reason)
|
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
if (reason.isEmpty()) {
|
|
|
|
text = i18n("This object could not be created.");
|
|
|
|
} else {
|
|
|
|
text = i18n("This object could not be created for the following reason:<p><b>%1</b></p>", reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::checkImmutability()
|
|
|
|
{
|
|
|
|
const bool systemImmutable = q->globalConfig().isImmutable() || q->config().isImmutable() ||
|
|
|
|
((!isContainment && q->containment()) &&
|
|
|
|
q->containment()->immutability() == SystemImmutable) ||
|
2008-12-18 23:14:06 +01:00
|
|
|
(qobject_cast<Corona*>(q->scene()) && static_cast<Corona*>(q->scene())->immutability() == SystemImmutable);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
if (systemImmutable) {
|
|
|
|
q->updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::themeChanged()
|
|
|
|
{
|
|
|
|
if (background) {
|
|
|
|
//do again the translucent background fallback
|
|
|
|
q->setBackgroundHints(backgroundHints);
|
|
|
|
|
|
|
|
qreal left;
|
|
|
|
qreal right;
|
|
|
|
qreal top;
|
|
|
|
qreal bottom;
|
|
|
|
background->getMargins(left, top, right, bottom);
|
|
|
|
q->setContentsMargins(left, right, top, bottom);
|
|
|
|
}
|
|
|
|
q->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::resetConfigurationObject()
|
|
|
|
{
|
2008-12-01 07:27:07 +01:00
|
|
|
// make sure mainConfigGroup exists in all cases
|
|
|
|
mainConfigGroup();
|
|
|
|
|
|
|
|
mainConfig->deleteGroup();
|
|
|
|
delete mainConfig;
|
|
|
|
mainConfig = 0;
|
2009-01-22 01:00:16 +01:00
|
|
|
|
|
|
|
Corona * corona = qobject_cast<Corona*>(q->scene());
|
|
|
|
if (corona) {
|
|
|
|
corona->requireConfigSync();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint AppletPrivate::s_maxAppletId = 0;
|
2009-01-23 19:07:20 +01:00
|
|
|
int AppletPrivate::s_maxZValue = 0;
|
|
|
|
int AppletPrivate::s_minZValue = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
PackageStructure::Ptr AppletPrivate::packageStructure(0);
|
2009-05-18 13:15:00 +02:00
|
|
|
QSet<QString> AppletPrivate::s_customCategories;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
|
2009-03-05 14:05:12 +01:00
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
opacity(0.4)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
resize(parent->size());
|
2009-02-04 12:39:22 +01:00
|
|
|
Animator::self()->animateItem(this, Animator::AppearAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletOverlayWidget::destroy()
|
|
|
|
{
|
|
|
|
connect(Animator::self(),
|
|
|
|
SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
|
|
|
this,
|
2009-04-09 07:57:57 +02:00
|
|
|
SLOT(overlayAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
2009-02-04 12:39:22 +01:00
|
|
|
Animator::self()->animateItem(this, Animator::DisappearAnimation);
|
|
|
|
}
|
|
|
|
|
2009-04-09 07:57:57 +02:00
|
|
|
void AppletOverlayWidget::overlayAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation)
|
2009-02-04 12:39:22 +01:00
|
|
|
{
|
2009-04-09 07:57:57 +02:00
|
|
|
if (item == this) {
|
2009-08-18 03:05:37 +02:00
|
|
|
if (scene()) {
|
|
|
|
scene()->removeItem(this);
|
|
|
|
}
|
2009-04-09 07:57:57 +02:00
|
|
|
deleteLater();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppletOverlayWidget::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
2009-03-06 19:21:59 +01:00
|
|
|
|
|
|
|
if (qFuzzyCompare(1, 1+opacity)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
|
2009-03-05 14:05:12 +01:00
|
|
|
wash.setAlphaF(opacity);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Applet *applet = qobject_cast<Applet *>(parentWidget());
|
|
|
|
|
2009-03-03 23:23:42 +01:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
QPainterPath backgroundShape;
|
2009-03-03 23:23:42 +01:00
|
|
|
if (!applet || applet->backgroundHints() & Applet::StandardBackground) {
|
|
|
|
//FIXME: a resize here is nasty, but perhaps still better than an eventfilter just for that..
|
2009-09-07 13:24:35 +02:00
|
|
|
if (parentWidget()->contentsRect().size() != size()) {
|
|
|
|
resize(parentWidget()->contentsRect().size());
|
2009-03-03 23:23:42 +01:00
|
|
|
}
|
2009-03-11 23:06:12 +01:00
|
|
|
backgroundShape = PaintUtils::roundedRectangle(contentsRect(), 5);
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
2009-03-11 23:06:12 +01:00
|
|
|
backgroundShape = shape();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-02-02 20:39:41 +01:00
|
|
|
|
2009-02-17 20:07:47 +01:00
|
|
|
painter->save();
|
|
|
|
painter->setRenderHints(QPainter::Antialiasing);
|
2009-02-02 20:39:41 +01:00
|
|
|
painter->fillPath(backgroundShape, wash);
|
2009-02-17 20:07:47 +01:00
|
|
|
painter->restore();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "applet.moc"
|
2009-04-09 08:07:33 +02:00
|
|
|
#include "private/applet_p.moc"
|