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"
|
2010-04-29 07:57:34 +02:00
|
|
|
|
|
|
|
#include "config-plasma.h"
|
|
|
|
|
2009-12-11 20:53:55 +01:00
|
|
|
#include <plasma/animations/animation.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#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 <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
|
|
|
|
2010-04-29 07:57:34 +02:00
|
|
|
#ifndef PLASMA_NO_SOLID
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <solid/powermanagement.h>
|
2010-04-29 07:57:34 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-01-27 00:35:32 +01:00
|
|
|
#include "abstracttoolbox.h"
|
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/applethandle_p.h"
|
2010-04-07 04:04:52 +02:00
|
|
|
#include "private/extenderitem_p.h"
|
|
|
|
#include "private/framesvg_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"
|
2010-04-03 21:10:32 +02:00
|
|
|
#include "abstractdialogmanager.h"
|
2010-07-15 23:06:21 +02:00
|
|
|
#include "pluginloader.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-11-25 02:09:17 +01:00
|
|
|
#include "private/plasmoidservice_p.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"
|
|
|
|
#include "ui_publish.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-09-09 15:40:16 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-08-03 01:56:02 +02:00
|
|
|
Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId)
|
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
d(new AppletPrivate(KService::Ptr(), &info, 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-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),
|
2010-08-03 01:56:02 +02:00
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
|
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();
|
|
|
|
}
|
|
|
|
|
2009-02-08 16:24:56 +01:00
|
|
|
Applet::Applet(QGraphicsItem *parent,
|
|
|
|
const QString &serviceID,
|
|
|
|
uint appletId,
|
|
|
|
const QVariantList &args)
|
|
|
|
: QGraphicsWidget(parent),
|
2010-08-03 01:56:02 +02:00
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
|
2009-02-08 16:24:56 +01:00
|
|
|
{
|
|
|
|
// 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(
|
2010-08-03 01:56:02 +02:00
|
|
|
KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0,
|
2008-11-04 00:08:39 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2010-03-23 23:41:57 +01:00
|
|
|
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
|
|
|
|
: QGraphicsWidget(0),
|
2010-08-03 01:56:02 +02:00
|
|
|
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
|
2010-03-23 23:41:57 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(args) // FIXME?
|
|
|
|
d->init(packagePath);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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-12-29 20:38:37 +01:00
|
|
|
d->extender.data()->saveState();
|
2009-01-16 19:49:54 +01:00
|
|
|
|
2009-12-29 20:38:37 +01:00
|
|
|
foreach (ExtenderItem *item, d->extender.data()->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()
|
|
|
|
{
|
2010-04-30 03:05:52 +02:00
|
|
|
setFlag(ItemIsMovable, true);
|
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
|
2011-04-25 16:43:15 +02:00
|
|
|
disconnect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
2009-01-07 21:34:34 +01:00
|
|
|
d->configLoader->writeConfig();
|
2011-04-25 16:43:15 +02:00
|
|
|
connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
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"
|
2009-11-25 02:09:17 +01:00
|
|
|
#include "private/plasmoidservice_p.h"
|
2009-09-02 04:27:16 +02:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 22:52:22 +01:00
|
|
|
|
|
|
|
d->messageOverlay = 0;
|
|
|
|
if (d->messageDialog) {
|
|
|
|
d->messageDialog.data()->deleteLater();
|
|
|
|
d->messageDialog.clear();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
setLayout(0);
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
2010-01-27 00:35:32 +01:00
|
|
|
|
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 {
|
2010-01-27 00:35:32 +01:00
|
|
|
Animation *zoomAnim = Plasma::Animator::create(Plasma::Animator::ZoomAnimation);
|
2010-11-03 21:52:13 +01:00
|
|
|
connect(zoomAnim, SIGNAL(finished()), this, SLOT(cleanUpAndDelete()));
|
2010-01-04 10:19:08 +01:00
|
|
|
zoomAnim->setTargetWidget(this);
|
2009-12-11 20:53:55 +01:00
|
|
|
zoomAnim->start();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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::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();
|
|
|
|
|
2010-11-03 21:52:13 +01:00
|
|
|
if (q->scene()) {
|
2010-11-03 21:55:23 +01:00
|
|
|
if (isContainment) {
|
2010-11-03 21:52:13 +01:00
|
|
|
// prematurely emit our destruction if we are a Containment,
|
|
|
|
// giving Corona a chance to remove this Containment from its collection
|
2010-11-03 21:55:23 +01:00
|
|
|
emit q->QObject::destroyed(q);
|
2010-11-03 21:52:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
q->scene()->removeItem(q);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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() &&
|
2009-12-29 20:38:37 +01:00
|
|
|
popup->graphicsWidget() != extender.data()) {
|
2009-08-24 19:27:24 +02:00
|
|
|
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-12-29 20:38:37 +01:00
|
|
|
} else if (usePopup && popup->graphicsWidget() && popup->graphicsWidget() != extender.data()) {
|
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) {
|
2011-02-09 20:35:15 +01:00
|
|
|
if (button == messageOkButton.data()) {
|
2009-02-02 20:39:41 +01:00
|
|
|
buttonCode = ButtonOk;
|
|
|
|
}
|
2011-02-09 20:35:15 +01:00
|
|
|
if (button == messageYesButton.data()) {
|
2009-02-02 20:39:41 +01:00
|
|
|
buttonCode = ButtonYes;
|
|
|
|
}
|
2011-02-09 20:35:15 +01:00
|
|
|
if (button == messageNoButton.data()) {
|
2009-02-02 20:39:41 +01:00
|
|
|
buttonCode = ButtonNo;
|
|
|
|
}
|
2011-02-09 20:35:15 +01:00
|
|
|
if (button == messageCancelButton.data()) {
|
2011-02-09 00:02:28 +01:00
|
|
|
buttonCode = ButtonCancel;
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit q->messageButtonPressed(buttonCode);
|
2011-02-09 00:02:28 +01:00
|
|
|
} else if (q->sender() == messageOverlay) {
|
|
|
|
emit q->messageButtonPressed(ButtonCancel);
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
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);
|
2010-08-04 02:59:09 +02:00
|
|
|
} else if (!package() || package()->metadata().remoteLocation().isEmpty()) {
|
2009-09-02 04:27:16 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2009-12-29 20:38:37 +01:00
|
|
|
return d->extender.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 19:22:55 +01:00
|
|
|
void Applet::setBusy(bool busy)
|
|
|
|
{
|
|
|
|
if (busy) {
|
2009-11-18 03:21:43 +01:00
|
|
|
if (!d->busyWidget && !d->busyWidgetTimer.isActive()) {
|
|
|
|
d->busyWidgetTimer.start(500, this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
d->busyWidgetTimer.stop();
|
|
|
|
if (d->busyWidget) {
|
|
|
|
d->busyWidget = 0;
|
|
|
|
d->destroyMessageOverlay();
|
2009-04-15 09:29:23 +02:00
|
|
|
}
|
2008-11-04 19:22:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isBusy() const
|
|
|
|
{
|
2009-11-18 03:21:43 +01:00
|
|
|
return d->busyWidgetTimer.isActive() || (d->busyWidget && d->busyWidget->isVisible());
|
2008-11-04 19:22:55 +01:00
|
|
|
}
|
|
|
|
|
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);
|
2010-05-21 03:07:31 +02:00
|
|
|
if (c && c->d->isPanelContainment()) {
|
|
|
|
return i18n("Panel");
|
|
|
|
} else if (!d->appletDescription.isValid()) {
|
|
|
|
return i18n("Unknown");
|
2009-10-07 20:31:14 +02:00
|
|
|
} else {
|
2010-05-21 03:07:31 +02:00
|
|
|
return d->appletDescription.name();
|
2009-10-07 20:31:14 +02:00
|
|
|
}
|
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
|
|
|
|
{
|
2010-04-29 07:57:34 +02:00
|
|
|
#ifndef PLASMA_NO_SOLID
|
2008-11-04 00:08:39 +01:00
|
|
|
return Solid::PowerManagement::appShouldConserveResources();
|
2010-04-29 07:57:34 +02:00
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
{
|
2010-11-12 23:48:31 +01:00
|
|
|
// if this object is itself system immutable, then just return that; it's the most
|
|
|
|
// restrictive setting possible and will override anything that might be happening above it
|
|
|
|
// in the Corona->Containment->Applet hierarchy
|
2010-12-26 11:42:57 +01:00
|
|
|
if (d->transient || (d->mainConfig && d->mainConfig->isImmutable())) {
|
2010-11-12 23:48:31 +01:00
|
|
|
return SystemImmutable;
|
2010-09-21 16:21:58 +02:00
|
|
|
}
|
|
|
|
|
2010-11-12 23:48:31 +01:00
|
|
|
//Returning the more strict immutability between the applet immutability, Containment and Corona
|
|
|
|
ImmutabilityType upperImmutability = Mutable;
|
|
|
|
Containment *cont = d->isContainment ? 0 : containment();
|
|
|
|
|
2010-09-21 16:21:58 +02:00
|
|
|
if (cont) {
|
2010-11-12 23:48:31 +01:00
|
|
|
upperImmutability = cont->immutability();
|
2010-09-21 16:21:58 +02:00
|
|
|
} else if (Corona *corona = qobject_cast<Corona*>(scene())) {
|
2010-11-12 23:48:31 +01:00
|
|
|
upperImmutability = corona->immutability();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 23:48:31 +01:00
|
|
|
if (upperImmutability != Mutable) {
|
|
|
|
// it's either system or user immutable, and we already check for local system immutability,
|
|
|
|
// so upperImmutability is guaranteed to be as or more severe as this object's immutability
|
|
|
|
return upperImmutability;
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
return d->immutability;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setImmutability(const ImmutabilityType immutable)
|
|
|
|
{
|
2010-11-12 23:48:31 +01:00
|
|
|
if (d->immutability == immutable || immutable == Plasma::SystemImmutable) {
|
|
|
|
// we do not store system immutability in d->immutability since that gets saved
|
|
|
|
// out to the config file; instead, we check with
|
|
|
|
// the config group itself for this information at all times. this differs from
|
|
|
|
// corona, where SystemImmutability is stored in d->immutability.
|
2008-11-04 00:08:39 +01:00
|
|
|
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);
|
2010-06-24 22:41:29 +02:00
|
|
|
QObject::connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(themeChanged()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
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-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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-06-08 18:20:15 +02:00
|
|
|
if (!qobject_cast<Plasma::PopupApplet *>(this) && (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical)) {
|
|
|
|
configWidget->setImage("widgets/configuration-icons", "configure");
|
|
|
|
configWidget->setMaximumSize(24,24);
|
|
|
|
configWidget->setMinimumSize(24,24);
|
|
|
|
} else {
|
|
|
|
configWidget->setText(i18n("Configure..."));
|
|
|
|
}
|
2009-03-03 23:23:42 +01:00
|
|
|
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) {
|
2011-02-09 20:35:15 +01:00
|
|
|
d->messageOkButton = new PushButton(mainWidget);
|
|
|
|
d->messageOkButton.data()->setText(i18n("&OK"));
|
|
|
|
d->messageOkButton.data()->setIcon(KIcon("dialog-ok"));
|
|
|
|
buttonLayout->addItem(d->messageOkButton.data());
|
|
|
|
connect(d->messageOkButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonYes) {
|
2011-02-09 20:35:15 +01:00
|
|
|
d->messageYesButton = new PushButton(mainWidget);
|
|
|
|
d->messageYesButton.data()->setText(i18n("&Yes"));
|
|
|
|
buttonLayout->addItem(d->messageYesButton.data());
|
|
|
|
connect(d->messageYesButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonNo) {
|
2011-02-09 20:35:15 +01:00
|
|
|
d->messageNoButton = new PushButton(mainWidget);
|
|
|
|
d->messageNoButton.data()->setText(i18n("&No"));
|
|
|
|
buttonLayout->addItem(d->messageNoButton.data());
|
|
|
|
connect(d->messageNoButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
2009-09-12 02:19:42 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
if (buttons & ButtonCancel) {
|
2011-02-09 20:35:15 +01:00
|
|
|
d->messageCancelButton = new PushButton(mainWidget);
|
|
|
|
d->messageCancelButton.data()->setText(i18n("&Cancel"));
|
|
|
|
d->messageCancelButton.data()->setIcon(KIcon("dialog-cancel"));
|
|
|
|
buttonLayout->addItem(d->messageCancelButton.data());
|
|
|
|
connect(d->messageCancelButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
2009-02-02 20:39:41 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 00:02:28 +01:00
|
|
|
d->messageCloseAction = new QAction(d->messageOverlay);
|
|
|
|
d->messageCloseAction.data()->setShortcut(Qt::Key_Escape);
|
|
|
|
mainWidget->addAction(d->messageCloseAction.data());
|
|
|
|
connect(d->messageCloseAction.data(), SIGNAL(triggered()), this, SLOT(destroyMessageOverlay()));
|
2010-08-17 23:46:00 +02:00
|
|
|
|
2009-02-02 20:39:41 +01:00
|
|
|
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()));
|
2010-03-09 04:07:29 +01:00
|
|
|
|
|
|
|
// if we are going to show it in a popup, then at least make sure it can be dismissed
|
|
|
|
if (buttonLayout->count() < 1) {
|
|
|
|
PushButton *ok = new PushButton(mainWidget);
|
|
|
|
ok->setText(i18n("OK"));
|
|
|
|
ok->setIcon(KIcon("dialog-ok"));
|
|
|
|
buttonLayout->addItem(ok);
|
|
|
|
connect(ok, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-18 03:21:43 +01:00
|
|
|
if (d->constraintsTimer.isActive()) {
|
|
|
|
d->constraintsTimer.stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "fushing constraints: " << d->pendingConstraints << "!!!!!!!!!!!!!!!!!!!!!!!!!!!";
|
|
|
|
Plasma::Constraints c = d->pendingConstraints;
|
|
|
|
d->pendingConstraints = NoConstraint;
|
|
|
|
|
|
|
|
if (c & Plasma::StartupCompletedConstraint) {
|
|
|
|
//common actions
|
|
|
|
bool unlocked = immutability() == Mutable;
|
2009-05-03 22:22:14 +02:00
|
|
|
QAction *closeApplet = d->actions->action("remove");
|
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setEnabled(unlocked);
|
|
|
|
closeApplet->setVisible(unlocked);
|
2010-03-09 06:11:37 +01:00
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(selectItemToDestroy()), Qt::UniqueConnection);
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QAction *configAction = d->actions->action("configure");
|
2010-03-09 06:15:13 +01:00
|
|
|
if (configAction) {
|
2009-05-03 22:22:14 +02:00
|
|
|
if (d->isContainment) {
|
2010-03-09 06:11:37 +01:00
|
|
|
connect(configAction, SIGNAL(triggered(bool)), this, SLOT(requestConfiguration()), Qt::UniqueConnection);
|
2009-05-03 22:22:14 +02:00
|
|
|
} else {
|
2010-03-09 06:11:37 +01:00
|
|
|
connect(configAction, SIGNAL(triggered(bool)), this, SLOT(showConfigurationInterface()), Qt::UniqueConnection);
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
2009-07-30 20:13:01 +02:00
|
|
|
|
2010-09-05 10:03:27 +02:00
|
|
|
if (d->hasConfigurationInterface) {
|
2010-03-09 06:15:13 +01:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize("plasma/allow_configure_when_locked");
|
|
|
|
configAction->setVisible(canConfig);
|
|
|
|
configAction->setEnabled(canConfig);
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
QAction *runAssociatedApplication = d->actions->action("run associated application");
|
|
|
|
if (runAssociatedApplication) {
|
2010-03-09 06:11:37 +01:00
|
|
|
connect(runAssociatedApplication, SIGNAL(triggered(bool)), this, SLOT(runAssociatedApplication()), Qt::UniqueConnection);
|
2009-09-16 19:08:45 +02:00
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
d->updateShortcuts();
|
|
|
|
Corona * corona = qobject_cast<Corona*>(scene());
|
|
|
|
if (corona) {
|
2010-03-09 06:11:37 +01:00
|
|
|
connect(corona, SIGNAL(shortcutsChanged()), this, SLOT(updateShortcuts()), Qt::UniqueConnection);
|
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");
|
2010-09-05 10:03:27 +02:00
|
|
|
if (action && d->hasConfigurationInterface) {
|
2010-01-21 07:00:24 +01:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize("plasma/allow_configure_when_locked");
|
2009-02-08 19:31:43 +01:00
|
|
|
action->setVisible(canConfig);
|
|
|
|
action->setEnabled(canConfig);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-04-07 04:04:52 +02:00
|
|
|
|
|
|
|
if (d->extender) {
|
|
|
|
foreach (ExtenderItem *item, d->extender.data()->attachedItems()) {
|
|
|
|
item->d->setMovable(unlocked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
QGraphicsLayoutItem *item = layout()->itemAt(1);
|
|
|
|
layout()->removeAt(1);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2010-05-17 14:40:37 +02:00
|
|
|
|
|
|
|
// avoid putting rotated applets in panels
|
|
|
|
if (f == Vertical || f == Horizontal) {
|
|
|
|
QTransform at;
|
|
|
|
at.rotateRadians(0);
|
|
|
|
setTransform(at);
|
|
|
|
}
|
2010-06-16 14:26:23 +02:00
|
|
|
|
|
|
|
//was a size saved for a particular form factor?
|
|
|
|
if (d->sizeForFormFactor.contains(f)) {
|
|
|
|
resize(d->sizeForFormFactor.value(f));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2010-06-16 14:26:23 +02:00
|
|
|
|
2010-08-27 21:27:19 +02:00
|
|
|
if (!size().isEmpty() &&
|
|
|
|
((c & Plasma::StartupCompletedConstraint) || (c & Plasma::SizeConstraint && !(c & Plasma::FormFactorConstraint)))) {
|
2010-06-16 14:26:23 +02:00
|
|
|
d->sizeForFormFactor[formFactor()] = size();
|
|
|
|
}
|
|
|
|
|
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
|
2010-04-21 14:16:06 +02:00
|
|
|
//save the old size policy. since ignored doesn't (yet) have a valid use case in containments, use it as special unset value
|
|
|
|
if (d->preferredSizePolicy == QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored)) {
|
|
|
|
d->preferredSizePolicy = sizePolicy();
|
|
|
|
}
|
2008-12-15 19:29:45 +01:00
|
|
|
if (formFactor() == Horizontal) {
|
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding));
|
|
|
|
} else if (formFactor() == Vertical) {
|
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
2010-04-21 14:16:06 +02:00
|
|
|
} else if (d->preferredSizePolicy != QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored)) {
|
|
|
|
setSizePolicy(d->preferredSizePolicy);
|
2008-12-15 19:29:45 +01:00
|
|
|
}
|
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
|
2009-11-18 03:21:43 +01:00
|
|
|
if (d->modificationsTimer) {
|
|
|
|
if (d->modificationsTimer->isActive()) {
|
|
|
|
d->modificationsTimer->stop();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
d->modificationsTimer = new QBasicTimer;
|
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
|
|
|
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
|
2010-04-13 18:21:12 +02:00
|
|
|
// the view must be assigned only if its containment is actually our own
|
2008-11-28 23:39:29 +01:00
|
|
|
Containment::StyleOption coption(*option);
|
2010-04-13 21:16:20 +02:00
|
|
|
if (v && v->containment() == containment()) {
|
2010-04-13 18:21:12 +02:00
|
|
|
coption.view = v;
|
|
|
|
}
|
2008-11-28 23:39:29 +01:00
|
|
|
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();
|
2010-04-14 14:05:15 +02:00
|
|
|
QGraphicsWidget *pw = qobject_cast<QGraphicsWidget *>(parent());
|
|
|
|
if (!pw) {
|
|
|
|
pw = dynamic_cast<QGraphicsWidget *>(parentItem());
|
|
|
|
}
|
|
|
|
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
|
|
|
//assumption: this loop is usually is -really- short or doesn't run at all
|
|
|
|
while (!parentApplet && pw && pw->parentWidget()) {
|
|
|
|
QGraphicsWidget *parentWidget = qobject_cast<QGraphicsWidget *>(pw->parent());
|
|
|
|
if (!parentWidget) {
|
|
|
|
parentWidget = dynamic_cast<QGraphicsWidget *>(pw->parentItem());
|
|
|
|
}
|
|
|
|
pw = parentWidget;
|
|
|
|
parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
|
|
|
}
|
2009-08-08 13:34:49 +02:00
|
|
|
|
|
|
|
|
2010-04-11 23:05:55 +02:00
|
|
|
const PopupApplet *pa = dynamic_cast<const PopupApplet *>(this);
|
|
|
|
|
2009-08-08 13:34:49 +02:00
|
|
|
//if the applet is in a widget that isn't a containment
|
|
|
|
//try to retrieve the formFactor from the parent size
|
2010-04-11 23:05:55 +02:00
|
|
|
//we can't use our own sizeHint here because it needs formFactor, so endless recursion.
|
|
|
|
// a popupapplet can always be constrained.
|
|
|
|
// a normal applet should to but
|
|
|
|
//FIXME: not always constrained to not break systemmonitor
|
2010-04-14 14:05:15 +02:00
|
|
|
if (parentApplet && parentApplet != c && c != this && (pa || layout())) {
|
|
|
|
if (pa || (parentApplet->size().height() < layout()->effectiveSizeHint(Qt::MinimumSize).height())) {
|
2009-08-08 13:34:49 +02:00
|
|
|
return Plasma::Horizontal;
|
2010-04-14 14:05:15 +02:00
|
|
|
} else if (pa || (parentApplet->size().width() < layout()->effectiveSizeHint(Qt::MinimumSize).width())) {
|
2010-04-11 23:05:55 +02:00
|
|
|
return Plasma::Vertical;
|
|
|
|
}
|
2010-04-14 14:05:15 +02:00
|
|
|
return parentApplet->formFactor();
|
2009-08-08 13:34:49 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-12-16 21:08:16 +01:00
|
|
|
if (!c) {
|
|
|
|
//if the applet is an offscreen widget its parentItem will be 0, while its parent
|
|
|
|
//will be its parentWidget, so here we check the QObject hierarchy.
|
|
|
|
QObject *objParent = this->parent();
|
|
|
|
while (objParent) {
|
|
|
|
Containment *possibleC = qobject_cast<Containment*>(objParent);
|
|
|
|
if (possibleC && possibleC->Applet::d->isContainment) {
|
|
|
|
c = possibleC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
objParent = objParent->parent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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()));
|
2010-05-07 22:57:03 +02:00
|
|
|
connect(d->activationAction, SIGNAL(globalShortcutChanged(QKeySequence)),
|
|
|
|
this, SLOT(globalShortcutChanged()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
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);
|
2010-05-07 22:57:03 +02:00
|
|
|
d->globalShortcutChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletPrivate::globalShortcutChanged()
|
|
|
|
{
|
|
|
|
if (!activationAction) {
|
|
|
|
return;
|
|
|
|
}
|
2009-03-24 03:07:20 +01:00
|
|
|
|
2010-05-07 22:57:03 +02:00
|
|
|
KConfigGroup shortcutConfig(mainConfigGroup(), "Shortcuts");
|
|
|
|
shortcutConfig.writeEntry("global", activationAction->globalShortcut().toString());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::AspectRatioMode Applet::aspectRatioMode() const
|
|
|
|
{
|
|
|
|
return d->aspectRatioMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode)
|
|
|
|
{
|
2009-11-18 21:11:03 +01:00
|
|
|
PopupApplet *popup = qobject_cast<PopupApplet *>(this);
|
|
|
|
if (popup && popup->d->dialogPtr) {
|
|
|
|
popup->d->dialogPtr.data()->setAspectRatioMode(mode);
|
2009-11-18 21:18:32 +01:00
|
|
|
popup->d->savedAspectRatio = mode;
|
2009-11-18 21:11:03 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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);
|
2010-10-04 23:10:48 +02:00
|
|
|
} else if (d->appletDescription.isValid()) {
|
2009-09-03 01:49:46 +02:00
|
|
|
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;
|
2010-10-04 23:10:48 +02:00
|
|
|
PackageMetadata pm;
|
|
|
|
pm.setName(d->appletDescription.name());
|
|
|
|
pm.setDescription(d->appletDescription.comment());
|
2011-04-28 23:48:55 +02:00
|
|
|
pm.setIcon(d->appletDescription.icon());
|
2010-10-04 23:10:48 +02:00
|
|
|
d->service->d->publish(methods, resourceName, pm);
|
|
|
|
} else {
|
|
|
|
kDebug() << "Can not publish invalid applets.";
|
2009-09-03 01:49:46 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
2010-03-06 02:10:53 +01:00
|
|
|
if (hasInterface == d->hasConfigurationInterface) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-06 02:10:53 +01:00
|
|
|
QAction *configAction = d->actions->action("configure");
|
|
|
|
if (configAction) {
|
|
|
|
bool enable = hasInterface;
|
|
|
|
if (enable) {
|
|
|
|
const bool unlocked = immutability() == Mutable;
|
|
|
|
enable = unlocked || KAuthorized::authorize("plasma/allow_configure_when_locked");
|
|
|
|
}
|
|
|
|
configAction->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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"));
|
2010-01-04 07:37:41 +01:00
|
|
|
configAction->setData(AbstractToolBox::ConfigureTool);
|
2009-05-03 22:22:14 +02:00
|
|
|
|
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"));
|
2010-01-04 07:37:41 +01:00
|
|
|
closeApplet->setData(AbstractToolBox::DestructiveTool);
|
2009-05-03 22:22:14 +02:00
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
KAction *runAssociatedApplication = actions->addAction("run associated application");
|
|
|
|
runAssociatedApplication->setAutoRepeat(false);
|
2010-05-09 13:03:13 +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);
|
2010-01-04 07:37:41 +01:00
|
|
|
runAssociatedApplication->setData(AbstractToolBox::ControlTool);
|
2009-09-16 19:08:45 +02:00
|
|
|
|
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:
|
2010-11-30 23:20:34 +01:00
|
|
|
case QEvent::GraphicsSceneMousePress:
|
|
|
|
case QEvent::GraphicsSceneMouseRelease:
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
// don't move when the containment is not mutable,
|
|
|
|
// in the rare case the containment doesn't exists consider it as mutable
|
2010-04-30 02:51:39 +02:00
|
|
|
if ((flags() & ItemIsMovable) && d->registeredAsDragHandle.contains(watched)) {
|
2008-12-11 04:10:36 +01:00
|
|
|
Containment *c = containment();
|
|
|
|
if (!c || c->immutability() == Mutable) {
|
2010-11-30 23:20:34 +01:00
|
|
|
scene()->sendEvent(this, event);
|
2010-12-04 21:58:52 +01:00
|
|
|
return false;
|
2008-12-11 04:10:36 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::sceneEventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2010-04-30 03:05:52 +02:00
|
|
|
if (immutability() == Mutable && formFactor() == Plasma::Planar && (flags() & ItemIsMovable)) {
|
2010-07-28 00:07:07 +02:00
|
|
|
QGraphicsWidget::mouseMoveEvent(event);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2010-01-29 22:21:16 +01:00
|
|
|
bool Applet::isUserConfiguring() const
|
|
|
|
{
|
|
|
|
return KConfigDialog::exists(d->configDialogId());
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::showConfigurationInterface()
|
|
|
|
{
|
|
|
|
if (!hasConfigurationInterface()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-21 07:00:24 +01:00
|
|
|
if (immutability() != Mutable && !KAuthorized::authorize("plasma/allow_configure_when_locked")) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-16 07:46:39 +01:00
|
|
|
d->publishUI.publishCheckbox = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
if (d->package && d->configLoader) {
|
2010-02-03 18:37:54 +01:00
|
|
|
KConfigDialog *dialog = 0;
|
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()) {
|
|
|
|
QFile f(uiFile);
|
2010-02-03 17:18:37 +01:00
|
|
|
QUiLoader loader;
|
|
|
|
QWidget *w = loader.load(&f);
|
2010-02-03 18:37:54 +01:00
|
|
|
if (w) {
|
2010-05-21 02:26:23 +02:00
|
|
|
dialog = new AppletConfigDialog(0, d->configDialogId(), d->configLoader);
|
2010-02-03 18:37:54 +01:00
|
|
|
dialog->setWindowTitle(d->configWindowTitle());
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
|
|
|
|
d->addGlobalShortcutsPage(dialog);
|
|
|
|
d->addPublishPage(dialog);
|
|
|
|
dialog->show();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2009-05-26 20:04:02 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-02-03 18:37:54 +01:00
|
|
|
if (!dialog && d->script) {
|
|
|
|
d->script->showConfigurationInterface();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
} else if (d->script) {
|
|
|
|
d->script->showConfigurationInterface();
|
|
|
|
} else {
|
2009-08-20 21:05:14 +02:00
|
|
|
KConfigDialog *dialog = d->generateGenericConfigDialog();
|
2009-10-23 15:48:29 +02:00
|
|
|
d->addStandardConfigurationPages(dialog);
|
2010-04-03 21:10:32 +02:00
|
|
|
showConfigurationInterface(dialog);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit releaseVisualFocus();
|
|
|
|
}
|
|
|
|
|
2010-04-03 21:10:32 +02:00
|
|
|
void Applet::showConfigurationInterface(QWidget *widget)
|
|
|
|
{
|
|
|
|
if (!containment() || !containment()->corona() ||
|
|
|
|
!containment()->corona()->dialogManager()) {
|
|
|
|
widget->show();
|
|
|
|
return;
|
|
|
|
}
|
2010-04-03 23:58:35 +02:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(containment()->corona()->dialogManager(), "showDialog", Q_ARG(QWidget *, widget), Q_ARG(Plasma::Applet *, this));
|
2010-04-03 21:10:32 +02:00
|
|
|
}
|
|
|
|
|
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()
|
2010-11-11 18:37:36 +01:00
|
|
|
<< QString(I18N_NOOP("Productivity")).toLower()
|
2009-05-01 20:03:13 +02:00
|
|
|
<< 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);
|
2010-05-21 02:26:23 +02:00
|
|
|
KConfigDialog *dialog = new AppletConfigDialog(0, configDialogId(), nullManager);
|
2009-01-20 03:11:01 +01:00
|
|
|
dialog->setFaceType(KPageDialog::Auto);
|
|
|
|
dialog->setWindowTitle(configWindowTitle());
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
2009-09-02 04:27:16 +02:00
|
|
|
q->createConfigurationInterface(dialog);
|
2010-05-26 09:55:37 +02:00
|
|
|
dialog->showButton(KDialog::Default, false);
|
2009-09-02 04:27:16 +02:00
|
|
|
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
|
|
|
|
2010-01-19 07:57:28 +01:00
|
|
|
QObject::connect(dialog, SIGNAL(applyClicked()), q, SLOT(configDialogFinished()), Qt::UniqueConnection);
|
|
|
|
QObject::connect(dialog, SIGNAL(okClicked()), q, SLOT(configDialogFinished()), Qt::UniqueConnection);
|
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
|
2010-02-16 07:46:39 +01:00
|
|
|
if (publishUI.publishCheckbox) {
|
|
|
|
q->config().writeEntry("Share", publishUI.publishCheckbox->isChecked());
|
|
|
|
|
|
|
|
if (publishUI.publishCheckbox->isChecked()) {
|
|
|
|
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-04 02:08:26 +02:00
|
|
|
}
|
|
|
|
} else {
|
2010-02-16 07:46:39 +01:00
|
|
|
q->unpublish();
|
2009-09-04 02:08:26 +02:00
|
|
|
}
|
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.
|
2011-04-25 16:43:15 +02:00
|
|
|
propagateConfigChanged();
|
2011-02-01 09:52:07 +01:00
|
|
|
if (KConfigDialog *dialog = qobject_cast<KConfigDialog *>(q->sender())) {
|
|
|
|
dialog->enableButton(KDialog::Apply, false);
|
|
|
|
}
|
2009-05-26 19:32:33 +02:00
|
|
|
}
|
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;
|
2010-01-27 00:35:32 +01:00
|
|
|
names << "add sibling containment" << "configure shortcuts" << "lock widgets";
|
2009-05-03 22:22:14 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-25 16:43:15 +02:00
|
|
|
void AppletPrivate::propagateConfigChanged()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2011-04-25 16:43:15 +02:00
|
|
|
if (script && configLoader) {
|
|
|
|
configLoader->readConfig();
|
|
|
|
script->configChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isContainment) {
|
|
|
|
Containment *c = qobject_cast<Containment *>(q);
|
|
|
|
if (c) {
|
|
|
|
c->d->configChanged();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
2011-04-25 16:43:15 +02:00
|
|
|
|
|
|
|
q->configChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::configChanged()
|
|
|
|
{
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-01-27 21:34:55 +01:00
|
|
|
valid = valid && hasAuthorization("LaunchApp"); //obey security!
|
2009-09-16 19:08:45 +02:00
|
|
|
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);
|
2010-01-27 21:34:55 +01:00
|
|
|
valid = valid && hasAuthorization("LaunchApp"); //obey security!
|
2009-09-16 19:08:45 +02:00
|
|
|
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()
|
|
|
|
{
|
2010-01-27 21:34:55 +01:00
|
|
|
if (hasAuthorization("LaunchApp")) {
|
|
|
|
AssociatedApplicationManager::self()->run(this);
|
|
|
|
}
|
2009-09-16 19:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-29 01:34:30 +02:00
|
|
|
QString AppletPrivate::parentAppConstraint(const QString &parentApp)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (parentApp.isEmpty()) {
|
2010-04-29 01:34:30 +02:00
|
|
|
return QString("((not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '') or [X-KDE-ParentApp] == '%1')")
|
|
|
|
.arg(KGlobal::mainComponent().aboutData()->appName());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-04-29 01:34:30 +02:00
|
|
|
return QString("[X-KDE-ParentApp] == '%1'").arg(parentApp);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List Applet::listAppletInfo(const QString &category, const QString &parentApp)
|
|
|
|
{
|
2010-09-03 20:09:18 +02:00
|
|
|
return PluginLoader::pluginLoader()->listAppletInfo(category, parentApp);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-05-06 12:12:47 +02:00
|
|
|
KPluginInfo::List Applet::listAppletInfoForMimeType(const QString &mimeType)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-04-29 01:34:30 +02:00
|
|
|
QString constraint = AppletPrivate::parentAppConstraint();
|
2011-05-06 12:12:47 +02:00
|
|
|
constraint.append(QString(" and '%1' in [X-Plasma-DropMimeTypes]").arg(mimeType));
|
|
|
|
//kDebug() << "listAppletInfoForMimetype with" << mimeType << constraint;
|
2008-11-04 00:08:39 +01:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", 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)
|
|
|
|
{
|
2010-04-29 01:34:30 +02:00
|
|
|
QString constraint = AppletPrivate::parentAppConstraint();
|
|
|
|
constraint.append(" and exist [X-Plasma-DropUrlPatterns]");
|
2009-10-29 10:09:01 +01:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", 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)
|
|
|
|
{
|
2010-04-29 01:34:30 +02:00
|
|
|
QString constraint = AppletPrivate::parentAppConstraint(parentApp);
|
|
|
|
constraint.append(" and exist [X-KDE-PluginInfo-Category]");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
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);
|
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::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)
|
|
|
|
{
|
2010-07-15 23:38:56 +02:00
|
|
|
return PluginLoader::pluginLoader()->loadApplet(appletName, appletId, args);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2010-11-12 23:48:31 +01:00
|
|
|
case ItemSceneHasChanged: {
|
|
|
|
Corona *newCorona = qobject_cast<Corona *>(qvariant_cast<QGraphicsScene*>(value));
|
|
|
|
if (newCorona && newCorona->immutability() != Mutable) {
|
|
|
|
updateConstraints(ImmutableConstraint);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
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-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);
|
2011-03-28 10:05:58 +02:00
|
|
|
const FormFactor ff = formFactor();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-03-28 10:05:58 +02:00
|
|
|
// in panels make sure that the contents won't exit from the panel
|
|
|
|
if (which == Qt::MinimumSize) {
|
|
|
|
if (ff == Horizontal) {
|
|
|
|
hint.setHeight(0);
|
|
|
|
} else if (ff == Vertical) {
|
|
|
|
hint.setWidth(0);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// enforce a square size in panels
|
|
|
|
if (d->aspectRatioMode == Plasma::Square) {
|
2011-03-28 10:05:58 +02:00
|
|
|
if (ff == Horizontal) {
|
2008-11-04 00:08:39 +01:00
|
|
|
hint.setWidth(size().height());
|
2011-03-28 10:05:58 +02:00
|
|
|
} else if (ff == Vertical) {
|
2008-11-04 00:08:39 +01:00
|
|
|
hint.setHeight(size().width());
|
|
|
|
}
|
|
|
|
} else if (d->aspectRatioMode == Plasma::ConstrainedSquare) {
|
|
|
|
//enforce a size not wider than tall
|
2011-03-28 10:05:58 +02:00
|
|
|
if (ff == Horizontal && (which == Qt::MaximumSize || size().height() <= KIconLoader::SizeLarge)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
hint.setWidth(size().height());
|
|
|
|
//enforce a size not taller than wide
|
2011-03-28 10:05:58 +02:00
|
|
|
} else if (ff == Vertical && (which == Qt::MaximumSize || size().width() <= KIconLoader::SizeLarge)) {
|
2008-11-04 00:08:39 +01:00
|
|
|
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) {
|
2009-11-18 03:21:43 +01:00
|
|
|
d->constraintsTimer.stop();
|
|
|
|
d->busyWidgetTimer.stop();
|
|
|
|
if (d->modificationsTimer) {
|
|
|
|
d->modificationsTimer->stop();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-18 03:21:43 +01:00
|
|
|
if (event->timerId() == d->constraintsTimer.timerId()) {
|
|
|
|
d->constraintsTimer.stop();
|
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();
|
|
|
|
}
|
2009-11-18 03:21:43 +01:00
|
|
|
} else if (d->modificationsTimer && event->timerId() == d->modificationsTimer->timerId()) {
|
|
|
|
d->modificationsTimer->stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
// 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();
|
2009-11-18 03:21:43 +01:00
|
|
|
} else if (event->timerId() == d->busyWidgetTimer.timerId()) {
|
|
|
|
if (!d->busyWidget) {
|
|
|
|
d->createMessageOverlay(false);
|
|
|
|
d->messageOverlay->opacity = 0;
|
|
|
|
|
|
|
|
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(d->messageOverlay);
|
|
|
|
d->busyWidget = new Plasma::BusyWidget(d->messageOverlay);
|
|
|
|
d->busyWidget->setAcceptHoverEvents(false);
|
|
|
|
d->busyWidget->setAcceptedMouseButtons(Qt::NoButton);
|
|
|
|
d->messageOverlay->setAcceptHoverEvents(false);
|
2011-02-07 10:48:28 +01:00
|
|
|
d->messageOverlay->setAcceptedMouseButtons(Qt::NoButton);
|
2009-11-18 03:21:43 +01:00
|
|
|
|
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->addItem(d->busyWidget);
|
|
|
|
mainLayout->addStretch();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-04-13 20:36:54 +02:00
|
|
|
|
|
|
|
Containment *c = q->containment();
|
|
|
|
if (c) {
|
|
|
|
c->d->checkContainmentFurniture();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isContainment() const
|
|
|
|
{
|
|
|
|
return d->isContainment;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PRIVATE CLASS IMPLEMENTATION
|
|
|
|
|
2010-08-03 01:56:02 +02:00
|
|
|
AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet)
|
2008-11-04 00:08:39 +01:00
|
|
|
: appletId(uniqueID),
|
|
|
|
q(applet),
|
2009-09-02 04:27:16 +02:00
|
|
|
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),
|
2010-08-03 01:56:02 +02:00
|
|
|
appletDescription(info ? *info : KPluginInfo(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),
|
2010-04-21 14:16:06 +02:00
|
|
|
preferredSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored),
|
2009-11-18 03:21:43 +01:00
|
|
|
modificationsTimer(0),
|
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()
|
|
|
|
{
|
|
|
|
if (activationAction && activationAction->isGlobalShortcutEnabled()) {
|
|
|
|
//kDebug() << "reseting global action for" << q->name() << activationAction->objectName();
|
|
|
|
activationAction->forgetGlobalShortcut();
|
|
|
|
}
|
|
|
|
|
2010-06-09 03:16:12 +02:00
|
|
|
delete extender.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
delete script;
|
|
|
|
script = 0;
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
delete configLoader;
|
|
|
|
configLoader = 0;
|
|
|
|
delete mainConfig;
|
|
|
|
mainConfig = 0;
|
2009-11-18 03:21:43 +01:00
|
|
|
delete modificationsTimer;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
2010-08-03 01:28:13 +02:00
|
|
|
//set a default size before any saved settings are read
|
|
|
|
QSize size(200, 200);
|
|
|
|
q->setBackgroundHints(Applet::DefaultBackground);
|
|
|
|
q->setHasConfigurationInterface(true); //FIXME why not default it to true in the constructor?
|
|
|
|
|
|
|
|
QAction *closeApplet = actions->action("remove");
|
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setText(i18nc("%1 is the name of the applet", "Remove this %1", q->name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *configAction = actions->action("configure");
|
|
|
|
if (configAction) {
|
|
|
|
configAction->setText(i18nc("%1 is the name of the applet", "%1 Settings", q->name()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject::connect(q, SIGNAL(activate()), q, SLOT(setFocus()));
|
2008-11-04 00:08:39 +01:00
|
|
|
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].";
|
2010-08-03 01:28:13 +02:00
|
|
|
q->resize(size);
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-17 23:54:40 +02:00
|
|
|
QVariant s = appletDescription.property("X-Plasma-DefaultSize");
|
|
|
|
if (s.isValid()) {
|
|
|
|
size = s.toSize();
|
|
|
|
}
|
2010-08-03 01:28:13 +02:00
|
|
|
//kDebug() << "size" << size;
|
|
|
|
q->resize(size);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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()) {
|
2010-05-04 05:19:09 +02:00
|
|
|
QString subPath = q->packageStructure()->defaultPackageRoot() + '/' + appletDescription.pluginName() + '/';
|
|
|
|
path = KStandardDirs::locate("data", subPath + "metadata.desktop");
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
path = KStandardDirs::locate("data", subPath);
|
|
|
|
} else {
|
|
|
|
path.remove(QString("metadata.desktop"));
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()) {
|
|
|
|
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);
|
2011-04-25 16:43:15 +02:00
|
|
|
QObject::connect(configLoader, SIGNAL(configChanged()), q, SLOT(propagateConfigChanged()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2009-11-18 03:21:43 +01:00
|
|
|
if (started && !constraintsTimer.isActive() && !(c & Plasma::StartupCompletedConstraint)) {
|
|
|
|
constraintsTimer.start(0, q);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2009-11-18 03:21:43 +01:00
|
|
|
// modificationsTimer is not allocated until we get our notice of being started
|
|
|
|
if (modificationsTimer) {
|
2008-12-15 18:41:37 +01:00
|
|
|
// schedule a save
|
2009-11-18 03:21:43 +01:00
|
|
|
if (modificationsTimer->isActive()) {
|
|
|
|
modificationsTimer->stop();
|
2008-12-15 18:41:37 +01:00
|
|
|
}
|
|
|
|
|
2009-11-18 03:21:43 +01:00
|
|
|
modificationsTimer->start(1000, q);
|
2008-12-15 18:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2010-01-08 03:13:52 +01:00
|
|
|
if (package && !containmentConfig.hasGroup(QString::number(appletId))) {
|
2009-09-02 04:27:16 +02:00
|
|
|
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
|
|
|
|
2010-01-08 03:02:43 +01:00
|
|
|
Containment *c = q->containment();
|
|
|
|
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();
|
|
|
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
|
|
|
} else if (c) {
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
|
2010-01-08 03:13:52 +01:00
|
|
|
if (package && !appletConfig.hasGroup(QString::number(appletId))) {
|
2009-09-02 04:27:16 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2010-01-08 03:13:52 +01:00
|
|
|
if (newGroup) {
|
2009-09-02 04:27:16 +02:00
|
|
|
//see if we have a default configuration in our package
|
2010-01-08 03:11:58 +01:00
|
|
|
const QString defaultConfigFile = q->package()->filePath("defaultconfig");
|
|
|
|
if (!defaultConfigFile.isEmpty()) {
|
|
|
|
kDebug() << "copying default config: " << q->package()->filePath("defaultconfig");
|
|
|
|
KConfigGroup defaultConfig(KSharedConfig::openConfig(defaultConfigFile)->group("Configuration"));
|
|
|
|
defaultConfig.copyTo(mainConfig);
|
|
|
|
}
|
2009-09-02 04:27:16 +02:00
|
|
|
}
|
|
|
|
|
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::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
|
|
|
}
|
|
|
|
|
|
|
|
void AppletOverlayWidget::destroy()
|
|
|
|
{
|
2010-04-28 19:42:12 +02:00
|
|
|
Animation *anim = Plasma::Animator::create(Plasma::Animator::DisappearAnimation);
|
|
|
|
if (anim) {
|
|
|
|
connect(anim, SIGNAL(finished()), this, SLOT(overlayAnimationComplete()));
|
|
|
|
anim->setTargetWidget(this);
|
|
|
|
anim->start();
|
|
|
|
} else {
|
|
|
|
overlayAnimationComplete();
|
|
|
|
}
|
2009-02-04 12:39:22 +01:00
|
|
|
}
|
|
|
|
|
2010-08-08 21:57:11 +02:00
|
|
|
void AppletOverlayWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2009-12-11 20:53:55 +01:00
|
|
|
void AppletOverlayWidget::overlayAnimationComplete()
|
2009-02-04 12:39:22 +01:00
|
|
|
{
|
2009-12-11 20:53:55 +01:00
|
|
|
if (scene()) {
|
|
|
|
scene()->removeItem(this);
|
2009-04-09 07:57:57 +02:00
|
|
|
}
|
2009-12-11 20:53:55 +01: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->setRenderHints(QPainter::Antialiasing);
|
2009-02-02 20:39:41 +01:00
|
|
|
painter->fillPath(backgroundShape, wash);
|
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"
|