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"
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <cmath>
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
#include <QList>
|
2014-03-11 17:04:31 +01:00
|
|
|
#include <QAbstractButton>
|
2014-02-13 15:29:44 +01:00
|
|
|
#include <QMessageBox>
|
2019-12-04 16:24:47 +01:00
|
|
|
#include <QMetaEnum>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-15 22:23:56 +01:00
|
|
|
#include <kactioncollection.h>
|
2013-09-16 16:16:21 +02:00
|
|
|
#include <kauthorized.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kcolorscheme.h>
|
2011-10-31 17:54:39 +01:00
|
|
|
#include <kdesktopfile.h>
|
2013-07-29 19:05:59 +02:00
|
|
|
#include <QDebug>
|
2013-07-10 01:45:41 +02:00
|
|
|
#include <kglobalaccel.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kplugininfo.h>
|
2013-02-19 13:00:57 +01:00
|
|
|
#include <klocalizedstring.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kservice.h>
|
2014-04-26 14:29:54 +02:00
|
|
|
#include <KConfigLoader>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kwindowsystem.h>
|
2009-09-16 19:08:45 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "containment.h"
|
|
|
|
#include "corona.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
#include "scripting/appletscript.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"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/containment_p.h"
|
2014-11-11 16:44:48 +01:00
|
|
|
#include "private/package_p.h"
|
2015-12-15 22:56:40 +01:00
|
|
|
#include "debug_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2016-10-10 16:27:50 +02:00
|
|
|
static KPluginMetaData appletMetadataForDirectory(const QString &path)
|
|
|
|
{
|
|
|
|
return QFile::exists(path + QLatin1String("/metadata.json"))
|
|
|
|
? KPluginMetaData(path + QLatin1String("/metadata.json"))
|
|
|
|
: KPluginMetaData::fromDesktopFile(path + QLatin1String("/metadata.desktop"), { QStringLiteral("plasma-applet.desktop") });
|
|
|
|
}
|
|
|
|
|
2016-10-04 23:56:17 +02:00
|
|
|
Applet::Applet(const KPluginMetaData &info, QObject *parent, uint appletId)
|
2012-09-24 14:30:42 +02:00
|
|
|
: QObject(parent),
|
2016-10-04 23:56:17 +02:00
|
|
|
d(new AppletPrivate(info, appletId, this))
|
2010-08-03 01:56:02 +02:00
|
|
|
{
|
2016-10-04 23:56:17 +02:00
|
|
|
qCDebug(LOG_PLASMA) << " From KPluginMetaData, valid? " << info.isValid();
|
2010-08-03 01:56:02 +02:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
|
|
|
d->init();
|
2013-02-25 17:20:29 +01:00
|
|
|
d->setupPackage();
|
2010-08-03 01:56:02 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 23:56:17 +02:00
|
|
|
Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId)
|
|
|
|
: Applet(info.toMetaData(), parent, appletId)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-24 14:30:42 +02:00
|
|
|
Applet::Applet(QObject *parent, const QString &serviceID, uint appletId)
|
|
|
|
: QObject(parent),
|
2016-10-04 23:56:17 +02:00
|
|
|
d(new AppletPrivate(KPluginMetaData(serviceID), 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();
|
2013-02-25 17:20:29 +01:00
|
|
|
d->setupPackage();
|
2009-02-08 16:24:56 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet::Applet(QObject *parentObject, const QVariantList &args)
|
2018-04-13 13:58:44 +02:00
|
|
|
: QObject(nullptr),
|
2017-12-09 10:37:02 +01:00
|
|
|
d(new AppletPrivate(KPluginMetaData(), args.count() > 2 ? args[2].toInt() : 0, this))
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
setParent(parentObject);
|
2018-04-13 13:58:44 +02:00
|
|
|
if (!args.isEmpty()) {
|
2016-10-10 16:27:50 +02:00
|
|
|
const QVariant first = args.first();
|
2017-12-09 10:37:02 +01:00
|
|
|
if (first.canConvert<KPackage::Package>()) {
|
|
|
|
d->package = first.value<KPackage::Package>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (args.count() > 1) {
|
|
|
|
const QVariant second = args[1];
|
|
|
|
if (second.canConvert<QString>()) {
|
|
|
|
d->appletDescription = KPluginMetaData(second.toString());
|
|
|
|
} else if (second.canConvert<QVariantMap>()) {
|
|
|
|
auto metadata = second.toMap().value(QStringLiteral("MetaData")).toMap();
|
2016-10-10 16:27:50 +02:00
|
|
|
d->appletDescription = KPluginMetaData(QJsonObject::fromVariantMap(metadata), {});
|
|
|
|
}
|
2015-05-07 16:26:37 +02:00
|
|
|
}
|
2016-10-10 16:27:50 +02:00
|
|
|
d->icon = d->appletDescription.iconName();
|
2009-01-13 22:46:07 +01:00
|
|
|
|
2017-12-02 15:12:40 +01:00
|
|
|
if (args.contains(QVariant::fromValue(QStringLiteral("org.kde.plasma:force-create")))) {
|
2016-03-20 22:04:53 +01:00
|
|
|
setProperty("org.kde.plasma:force-create", true);
|
|
|
|
}
|
|
|
|
|
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
|
2017-12-09 10:37:02 +01:00
|
|
|
d->init(QString(), args.mid(3));
|
2013-02-25 17:20:29 +01:00
|
|
|
d->setupPackage();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-25 17:20:29 +01:00
|
|
|
Applet::Applet(const QString &packagePath, uint appletId)
|
2017-12-25 18:41:50 +01:00
|
|
|
: QObject(nullptr),
|
2016-10-10 16:27:50 +02:00
|
|
|
d(new AppletPrivate(appletMetadataForDirectory(packagePath), appletId, this))
|
2010-03-23 23:41:57 +01:00
|
|
|
{
|
|
|
|
d->init(packagePath);
|
2013-02-25 17:20:29 +01:00
|
|
|
d->setupPackage();
|
2010-03-23 23:41:57 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Applet::~Applet()
|
|
|
|
{
|
2014-10-30 17:56:04 +01:00
|
|
|
if (d->transient) {
|
2014-10-28 15:55:12 +01:00
|
|
|
d->resetConfigurationObject();
|
|
|
|
}
|
2009-01-28 08:58:17 +01:00
|
|
|
//let people know that i will die
|
2012-09-24 13:58:54 +02:00
|
|
|
emit appletDeleted(this);
|
2009-01-28 08:58:17 +01:00
|
|
|
|
2019-09-07 23:19:03 +02:00
|
|
|
// ConfigLoader is deleted when AppletPrivate closes not Applet
|
|
|
|
// It saves on closure and emits a signal.
|
|
|
|
// disconnect early to avoid a crash. See 411221
|
|
|
|
disconnect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::init()
|
|
|
|
{
|
2016-06-15 11:00:57 +02:00
|
|
|
//Don't implement anything here, it will be overridden by subclasses
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint Applet::id() const
|
|
|
|
{
|
|
|
|
return d->appletId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::save(KConfigGroup &g) const
|
|
|
|
{
|
2013-02-13 21:38:21 +01:00
|
|
|
if (d->transient || !d->appletDescription.isValid()) {
|
2008-12-18 23:14:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
KConfigGroup group = g;
|
|
|
|
if (!group.isValid()) {
|
|
|
|
group = *d->mainConfigGroup();
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:56:40 +01:00
|
|
|
//qCDebug(LOG_PLASMA) << "saving" << pluginName() << "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);
|
2016-10-04 23:56:17 +02:00
|
|
|
group.writeEntry("plugin", d->appletDescription.pluginId());
|
2008-12-12 02:05:00 +01:00
|
|
|
|
|
|
|
if (!d->started) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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()));
|
2015-02-11 14:52:41 +01:00
|
|
|
d->configLoader->save();
|
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)
|
|
|
|
{
|
|
|
|
|
2013-05-14 20:27:32 +02:00
|
|
|
setImmutability((Types::ImmutabilityType)group.readEntry("immutability", (int)Types::Mutable));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
KConfigGroup shortcutConfig(&group, "Shortcuts");
|
|
|
|
QString shortcutText = shortcutConfig.readEntryUntranslated("global", QString());
|
|
|
|
if (!shortcutText.isEmpty()) {
|
2013-07-10 02:33:28 +02:00
|
|
|
setGlobalShortcut(QKeySequence(shortcutText));
|
2009-03-24 03:07:20 +01:00
|
|
|
/*
|
2014-04-26 01:45:47 +02:00
|
|
|
#ifndef NDEBUG
|
2015-12-15 22:56:40 +01:00
|
|
|
// qCDebug(LOG_PLASMA) << "got global shortcut for" << name() << "of" << QKeySequence(shortcutText);
|
2014-04-26 01:45:47 +02:00
|
|
|
#endif
|
|
|
|
#ifndef NDEBUG
|
2015-12-15 22:56:40 +01:00
|
|
|
// qCDebug(LOG_PLASMA) << "set to" << d->activationAction->objectName()
|
2014-04-26 01:45:47 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
<< 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
|
|
|
|
/*
|
2014-04-26 01:45:47 +02:00
|
|
|
#include "accessmanager.h"
|
|
|
|
#include "private/plasmoidservice_p.h"
|
|
|
|
#include "authorizationmanager.h"
|
|
|
|
#include "authorizationmanager.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
shortcutText = shortcutConfig.readEntryUntranslated("local", QString());
|
|
|
|
if (!shortcutText.isEmpty()) {
|
|
|
|
//TODO: implement; the shortcut
|
|
|
|
}
|
|
|
|
*/
|
2019-12-04 16:24:47 +01:00
|
|
|
|
|
|
|
// User background hints
|
|
|
|
// TODO support flags in the config
|
|
|
|
QByteArray hintsString = config().readEntry("UserBackgroundHints", QString()).toUtf8();
|
|
|
|
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
|
|
|
bool ok;
|
|
|
|
int value = hintEnum.keyToValue(hintsString.constData(), &ok);
|
|
|
|
if (ok) {
|
|
|
|
d->userBackgroundHints = Plasma::Types::BackgroundHints(value);
|
|
|
|
d->userBackgroundHintsInitialized = true;
|
|
|
|
emit userBackgroundHintsChanged();
|
|
|
|
if (d->backgroundHints & Plasma::Types::ConfigurableBackground) {
|
|
|
|
emit effectiveBackgroundHintsChanged();
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-12 20:07:23 +01:00
|
|
|
void Applet::setLaunchErrorMessage(const QString &message)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-02-12 20:07:23 +01:00
|
|
|
if (message == d->launchErrorMessage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->failed = true;
|
|
|
|
d->launchErrorMessage = message;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2009-01-22 01:00:16 +01:00
|
|
|
if (d->transient) {
|
2012-03-24 19:33:54 +01:00
|
|
|
return KConfigGroup(KSharedConfig::openConfig(), "PlasmaTransientsConfig");
|
2009-01-22 01:00:16 +01:00
|
|
|
}
|
|
|
|
|
2013-12-11 13:41:22 +01:00
|
|
|
if (isContainment()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return *(d->mainConfigGroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
return KConfigGroup(d->mainConfigGroup(), "Configuration");
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::globalConfig() const
|
|
|
|
{
|
|
|
|
KConfigGroup globalAppletConfig;
|
2016-02-29 00:08:05 +01:00
|
|
|
QString group = isContainment() ? QStringLiteral("ContainmentGlobals") : QStringLiteral("AppletGlobals");
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2012-09-24 17:18:55 +02:00
|
|
|
Containment *cont = containment();
|
2018-04-13 13:58:44 +02:00
|
|
|
Corona *corona = nullptr;
|
2012-09-24 17:18:55 +02:00
|
|
|
if (cont) {
|
|
|
|
corona = cont->corona();
|
|
|
|
}
|
2008-12-18 23:14:06 +01:00
|
|
|
if (corona) {
|
|
|
|
KSharedConfig::Ptr coronaConfig = corona->config();
|
2008-11-04 00:08:39 +01:00
|
|
|
globalAppletConfig = KConfigGroup(coronaConfig, group);
|
|
|
|
} else {
|
2012-03-24 19:33:54 +01:00
|
|
|
globalAppletConfig = KConfigGroup(KSharedConfig::openConfig(), group);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return KConfigGroup(&globalAppletConfig, d->globalName());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::destroy()
|
|
|
|
{
|
2013-05-10 19:29:13 +02:00
|
|
|
if (immutability() != Types::Mutable || d->transient || !d->started) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return; //don't double delete
|
|
|
|
}
|
|
|
|
|
2016-08-25 16:55:18 +02:00
|
|
|
d->setDestroyed(true);
|
2011-11-17 14:40:53 +01:00
|
|
|
//FIXME: an animation on leave if !isContainment() would be good again .. which should be handled by the containment class
|
|
|
|
d->cleanUpAndDelete();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-01 02:04:58 +01:00
|
|
|
bool Applet::destroyed() const
|
|
|
|
{
|
|
|
|
return d->transient;
|
|
|
|
}
|
|
|
|
|
2014-04-26 14:29:54 +02:00
|
|
|
KConfigLoader *Applet::configScheme() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-02-26 14:48:39 +01:00
|
|
|
if (!d->configLoader) {
|
2017-12-09 10:37:02 +01:00
|
|
|
const QString xmlPath = d->package.isValid() ? d->package.filePath("mainconfigxml") : QString();
|
2013-02-26 14:48:39 +01:00
|
|
|
KConfigGroup cfg = config();
|
|
|
|
if (xmlPath.isEmpty()) {
|
2018-04-13 13:58:44 +02:00
|
|
|
d->configLoader = new KConfigLoader(cfg, nullptr);
|
2013-02-26 14:48:39 +01:00
|
|
|
} else {
|
|
|
|
QFile file(xmlPath);
|
2014-04-26 14:29:54 +02:00
|
|
|
d->configLoader = new KConfigLoader(cfg, &file);
|
2013-02-26 14:48:39 +01:00
|
|
|
QObject::connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
return d->configLoader;
|
|
|
|
}
|
|
|
|
|
2011-07-15 12:59:51 +02:00
|
|
|
Package Applet::package() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2014-11-11 16:44:48 +01:00
|
|
|
Package p;
|
2017-12-09 10:37:02 +01:00
|
|
|
p.d->internalPackage = new KPackage::Package(d->package);
|
2014-11-11 16:44:48 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
KPackage::Package Applet::kPackage() const
|
|
|
|
{
|
2017-12-09 10:37:02 +01:00
|
|
|
return d->package;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-05-14 18:08:58 +02:00
|
|
|
void Applet::updateConstraints(Plasma::Types::Constraints constraints)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
d->scheduleConstraintsUpdate(constraints);
|
|
|
|
}
|
|
|
|
|
2013-05-14 18:08:58 +02:00
|
|
|
void Applet::constraintsEvent(Plasma::Types::Constraints constraints)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
//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)
|
2015-12-15 22:56:40 +01:00
|
|
|
//qCDebug(LOG_PLASMA) << constraints << "constraints are FormFactor: " << formFactor()
|
2008-11-04 00:08:39 +01:00
|
|
|
// << ", Location: " << location();
|
|
|
|
if (d->script) {
|
|
|
|
d->script->constraintsEvent(constraints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:30:25 +01:00
|
|
|
QString Applet::title() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-02-12 11:30:25 +01:00
|
|
|
if (!d->customTitle.isEmpty()) {
|
|
|
|
return d->customTitle;
|
2012-11-07 02:14:18 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 12:49:38 +01:00
|
|
|
if (d->appletDescription.isValid()) {
|
|
|
|
return d->appletDescription.name();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-03-11 12:49:38 +01:00
|
|
|
return i18n("Unknown");
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 11:32:46 +01:00
|
|
|
void Applet::setTitle(const QString &title)
|
2012-11-07 02:14:18 +01:00
|
|
|
{
|
2016-03-09 11:32:46 +01:00
|
|
|
if (title == d->customTitle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:30:25 +01:00
|
|
|
d->customTitle = title;
|
2016-03-09 11:32:46 +01:00
|
|
|
emit titleChanged(title);
|
2012-11-07 02:14:18 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QString Applet::icon() const
|
|
|
|
{
|
2013-09-23 16:44:31 +02:00
|
|
|
return d->icon;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2013-09-23 16:44:31 +02:00
|
|
|
void Applet::setIcon(const QString &icon)
|
|
|
|
{
|
2016-03-09 11:32:46 +01:00
|
|
|
if (icon == d->icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-23 16:44:31 +02:00
|
|
|
d->icon = icon;
|
2016-03-09 11:32:46 +01:00
|
|
|
emit iconChanged(icon);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2016-03-17 18:27:06 +01:00
|
|
|
bool Applet::isBusy() const
|
|
|
|
{
|
|
|
|
return d->busy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setBusy(bool busy)
|
|
|
|
{
|
|
|
|
if (busy == d->busy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->busy = busy;
|
|
|
|
emit busyChanged(busy);
|
|
|
|
}
|
|
|
|
|
2019-12-04 16:24:47 +01:00
|
|
|
Plasma::Types::BackgroundHints Applet::backgroundHints() const
|
|
|
|
{
|
|
|
|
return d->backgroundHints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setBackgroundHints(Plasma::Types::BackgroundHints hint)
|
|
|
|
{
|
|
|
|
if (d->backgroundHints == hint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Types::BackgroundHints oldeffectiveHints = effectiveBackgroundHints();
|
|
|
|
|
|
|
|
d->backgroundHints = hint;
|
|
|
|
emit backgroundHintsChanged();
|
|
|
|
|
|
|
|
if (oldeffectiveHints != effectiveBackgroundHints()) {
|
|
|
|
emit effectiveBackgroundHintsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Types::BackgroundHints Applet::effectiveBackgroundHints() const
|
|
|
|
{
|
|
|
|
if (d->userBackgroundHintsInitialized
|
|
|
|
&& (d->backgroundHints & Plasma::Types::ConfigurableBackground)) {
|
|
|
|
return d->userBackgroundHints;
|
|
|
|
} else {
|
|
|
|
return d->backgroundHints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Types::BackgroundHints Applet::userBackgroundHints() const
|
|
|
|
{
|
|
|
|
return d->userBackgroundHints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setUserBackgroundHints(Plasma::Types::BackgroundHints hint)
|
|
|
|
{
|
|
|
|
if (d->userBackgroundHints == hint && d->userBackgroundHintsInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->userBackgroundHints = hint;
|
|
|
|
d->userBackgroundHintsInitialized = true;
|
|
|
|
QMetaEnum hintEnum = QMetaEnum::fromType<Plasma::Types::BackgroundHints>();
|
|
|
|
config().writeEntry("UserBackgroundHints", hintEnum.valueToKey(d->userBackgroundHints));
|
|
|
|
if (containment() && containment()->corona()) {
|
|
|
|
containment()->corona()->requestConfigSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit userBackgroundHintsChanged();
|
|
|
|
|
|
|
|
if (d->backgroundHints & Plasma::Types::ConfigurableBackground) {
|
|
|
|
emit effectiveBackgroundHintsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 11:46:26 +01:00
|
|
|
KPluginInfo Applet::pluginInfo() const
|
2016-10-04 23:56:17 +02:00
|
|
|
{
|
|
|
|
return KPluginInfo(d->appletDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginMetaData Applet::pluginMetaData() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-02-12 11:46:26 +01:00
|
|
|
return d->appletDescription;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2014-08-30 19:45:50 +02:00
|
|
|
Types::ImmutabilityType Applet::immutability() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
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())) {
|
2013-05-10 19:29:13 +02:00
|
|
|
return Types::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
|
2013-05-14 20:27:32 +02:00
|
|
|
Types::ImmutabilityType upperImmutability = Types::Mutable;
|
2010-11-12 23:48:31 +01:00
|
|
|
|
2014-02-17 12:00:24 +01:00
|
|
|
if (isContainment()) {
|
2014-04-26 01:45:47 +02:00
|
|
|
Corona *cor = static_cast<Containment *>(const_cast<Applet *>(this))->corona();
|
2014-02-17 12:00:24 +01:00
|
|
|
if (cor) {
|
|
|
|
upperImmutability = cor->immutability();
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-11 13:41:22 +01:00
|
|
|
const Containment *cont = containment();
|
|
|
|
if (cont) {
|
2014-02-17 12:00:24 +01:00
|
|
|
if (cont->corona()) {
|
|
|
|
upperImmutability = cont->corona()->immutability();
|
|
|
|
} else {
|
|
|
|
upperImmutability = cont->immutability();
|
|
|
|
}
|
2013-12-11 13:41:22 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
if (upperImmutability != Types::Mutable) {
|
2010-11-12 23:48:31 +01:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-30 19:45:50 +02:00
|
|
|
void Applet::setImmutability(const Types::ImmutabilityType immutable)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2013-05-10 19:29:13 +02:00
|
|
|
if (d->immutability == immutable || immutable == Types::SystemImmutable) {
|
2010-11-12 23:48:31 +01:00
|
|
|
// 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;
|
2013-05-10 19:29:13 +02:00
|
|
|
updateConstraints(Types::ImmutableConstraint);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-12 20:07:23 +01:00
|
|
|
QString Applet::launchErrorMessage() const
|
|
|
|
{
|
|
|
|
return d->launchErrorMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::failedToLaunch() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-29 14:25:18 +01:00
|
|
|
QString Applet::configurationRequiredReason() const
|
|
|
|
{
|
|
|
|
return d->configurationRequiredReason;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
|
|
|
{
|
2016-02-29 14:25:18 +01:00
|
|
|
if (d->needsConfig == needsConfig && reason == d->configurationRequiredReason) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-06 16:52:13 +01:00
|
|
|
d->needsConfig = needsConfig;
|
2016-02-29 14:25:18 +01:00
|
|
|
d->configurationRequiredReason = reason;
|
|
|
|
|
|
|
|
emit configurationRequiredChanged(needsConfig, reason);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-08-20 18:17:20 +02:00
|
|
|
bool Applet::isUserConfiguring() const
|
|
|
|
{
|
|
|
|
return d->userConfiguring;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setUserConfiguring(bool configuring)
|
|
|
|
{
|
|
|
|
if (configuring == d->userConfiguring) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->userConfiguring = configuring;
|
|
|
|
emit userConfiguringChanged(configuring);
|
|
|
|
}
|
|
|
|
|
2013-05-14 20:49:50 +02:00
|
|
|
Types::ItemStatus Applet::status() const
|
2009-07-09 19:19:00 +02:00
|
|
|
{
|
|
|
|
return d->itemStatus;
|
|
|
|
}
|
|
|
|
|
2013-05-14 20:49:50 +02:00
|
|
|
void Applet::setStatus(const Types::ItemStatus status)
|
2009-07-09 19:19:00 +02:00
|
|
|
{
|
2015-12-22 15:03:03 +01:00
|
|
|
if (status == d->itemStatus) {
|
|
|
|
return;
|
|
|
|
}
|
2009-07-09 19:19:00 +02:00
|
|
|
d->itemStatus = status;
|
2013-02-12 20:44:04 +01:00
|
|
|
emit statusChanged(status);
|
2009-07-09 19:19:00 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::flushPendingConstraintsEvents()
|
|
|
|
{
|
2013-05-10 19:29:13 +02:00
|
|
|
if (d->pendingConstraints == Types::NoConstraint) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-18 03:21:43 +01:00
|
|
|
if (d->constraintsTimer.isActive()) {
|
|
|
|
d->constraintsTimer.stop();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2018-10-22 20:05:29 +02:00
|
|
|
//qCDebug(LOG_PLASMA) << "flushing constraints: " << d->pendingConstraints << "!!!!!!!!!!!!!!!!!!!!!!!!!!!";
|
2013-05-14 18:08:58 +02:00
|
|
|
Plasma::Types::Constraints c = d->pendingConstraints;
|
2013-05-10 19:29:13 +02:00
|
|
|
d->pendingConstraints = Types::NoConstraint;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2013-08-09 21:51:13 +02:00
|
|
|
if (c & Plasma::Types::UiReadyConstraint) {
|
|
|
|
d->setUiReady();
|
|
|
|
}
|
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
if (c & Plasma::Types::StartupCompletedConstraint) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//common actions
|
2013-05-10 19:29:13 +02:00
|
|
|
bool unlocked = immutability() == Types::Mutable;
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *closeApplet = d->actions->action(QStringLiteral("remove"));
|
2009-05-03 22:22:14 +02:00
|
|
|
if (closeApplet) {
|
|
|
|
closeApplet->setEnabled(unlocked);
|
|
|
|
closeApplet->setVisible(unlocked);
|
2014-03-20 19:22:27 +01:00
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(askDestroy()), Qt::UniqueConnection);
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *configAction = d->actions->action(QStringLiteral("configure"));
|
2010-03-09 06:15:13 +01:00
|
|
|
if (configAction) {
|
2009-07-30 20:13:01 +02:00
|
|
|
|
2010-09-05 10:03:27 +02:00
|
|
|
if (d->hasConfigurationInterface) {
|
2016-02-29 00:08:05 +01:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize(QStringLiteral("plasma/allow_configure_when_locked"));
|
2010-03-09 06:15:13 +01:00
|
|
|
configAction->setVisible(canConfig);
|
|
|
|
configAction->setEnabled(canConfig);
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *runAssociatedApplication = d->actions->action(QStringLiteral("run associated application"));
|
2009-09-16 19:08:45 +02:00
|
|
|
if (runAssociatedApplication) {
|
2019-08-30 17:26:54 +02:00
|
|
|
connect(runAssociatedApplication, &QAction::triggered, this, &Applet::runAssociatedApplication, Qt::UniqueConnection);
|
2009-09-16 19:08:45 +02:00
|
|
|
}
|
|
|
|
|
2009-05-03 22:22:14 +02:00
|
|
|
d->updateShortcuts();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
if (c & Plasma::Types::ImmutableConstraint) {
|
|
|
|
bool unlocked = immutability() == Types::Mutable;
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *action = d->actions->action(QStringLiteral("remove"));
|
2008-11-04 00:08:39 +01:00
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}
|
2014-07-23 12:25:32 +02:00
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
action = d->actions->action(QStringLiteral("configure"));
|
2010-09-05 10:03:27 +02:00
|
|
|
if (action && d->hasConfigurationInterface) {
|
2016-02-29 00:08:05 +01:00
|
|
|
bool canConfig = unlocked || KAuthorized::authorize(QStringLiteral("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
|
|
|
|
2018-10-22 20:05:29 +02:00
|
|
|
//an immutable constraint will always happen at startup
|
2015-03-17 19:13:28 +01:00
|
|
|
//make sure don't emit a change signal for nothing
|
|
|
|
if (d->oldImmutability != immutability()) {
|
|
|
|
emit immutabilityChanged(immutability());
|
|
|
|
}
|
|
|
|
d->oldImmutability = immutability();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2018-10-22 20:05:29 +02:00
|
|
|
// now take care of constraints in special subclass: Containment
|
2014-04-26 01:45:47 +02:00
|
|
|
Containment *containment = qobject_cast<Plasma::Containment *>(this);
|
2013-12-11 13:41:22 +01:00
|
|
|
if (containment) {
|
2008-11-04 00:08:39 +01:00
|
|
|
containment->d->containmentConstraintsEvent(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);
|
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
if (c & Types::StartupCompletedConstraint) {
|
2008-12-15 18:41:37 +01:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
2014-03-04 18:13:19 +01:00
|
|
|
|
|
|
|
if (c & Plasma::Types::FormFactorConstraint) {
|
|
|
|
emit formFactorChanged(formFactor());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c & Plasma::Types::LocationConstraint) {
|
|
|
|
emit locationChanged(location());
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2014-04-26 01:45:47 +02:00
|
|
|
QList<QAction *> Applet::contextualActions()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2015-12-15 22:56:40 +01:00
|
|
|
//qCDebug(LOG_PLASMA) << "empty context actions";
|
2014-04-26 01:45:47 +02:00
|
|
|
return d->script ? d->script->contextualActions() : QList<QAction *>();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-25 16:31:26 +01:00
|
|
|
KActionCollection *Applet::actions() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2015-10-07 17:19:13 +02:00
|
|
|
return d->actions;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-05-14 18:19:33 +02:00
|
|
|
Types::FormFactor Applet::formFactor() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Containment *c = containment();
|
2012-09-24 14:30:42 +02:00
|
|
|
QObject *pw = qobject_cast<QObject *>(parent());
|
2010-04-14 14:05:15 +02:00
|
|
|
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
|
|
|
//assumption: this loop is usually is -really- short or doesn't run at all
|
2012-09-24 17:18:55 +02:00
|
|
|
while (!parentApplet && pw && pw->parent()) {
|
|
|
|
pw = pw->parent();
|
2010-04-14 14:05:15 +02:00
|
|
|
parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
|
|
|
}
|
2009-08-08 13:34:49 +02:00
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
return c ? c->d->formFactor : Plasma::Types::Planar;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment *Applet::containment() const
|
|
|
|
{
|
2014-04-26 01:45:47 +02:00
|
|
|
Containment *c = qobject_cast<Containment *>(const_cast<Applet *>(this));
|
2014-04-14 14:03:49 +02:00
|
|
|
if (c && c->isContainment()) {
|
2013-12-11 13:41:22 +01:00
|
|
|
return c;
|
2014-04-14 14:03:49 +02:00
|
|
|
} else {
|
2018-04-13 13:58:44 +02:00
|
|
|
c = nullptr;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 17:18:55 +02:00
|
|
|
QObject *parent = this->parent();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
while (parent) {
|
2014-04-26 01:45:47 +02:00
|
|
|
Containment *possibleC = qobject_cast<Containment *>(parent);
|
2014-04-14 14:03:49 +02:00
|
|
|
|
|
|
|
if (possibleC && possibleC->isContainment()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
c = possibleC;
|
|
|
|
break;
|
|
|
|
}
|
2012-09-24 17:18:55 +02:00
|
|
|
parent = parent->parent();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-07-10 02:33:28 +02:00
|
|
|
void Applet::setGlobalShortcut(const QKeySequence &shortcut)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (!d->activationAction) {
|
2013-07-10 01:45:41 +02:00
|
|
|
d->activationAction = new QAction(this);
|
2013-02-12 11:30:25 +01:00
|
|
|
d->activationAction->setText(i18n("Activate %1 Widget", title()));
|
2015-11-27 21:03:48 +01:00
|
|
|
d->activationAction->setObjectName(QStringLiteral("activate widget %1").arg(id())); // NO I18N
|
2019-08-30 17:26:54 +02:00
|
|
|
connect(d->activationAction, &QAction::triggered, this, &Applet::activated);
|
2014-04-12 20:09:08 +02:00
|
|
|
connect(d->activationAction, SIGNAL(changed()),
|
2010-05-07 22:57:03 +02:00
|
|
|
this, SLOT(globalShortcutChanged()));
|
2013-07-10 02:33:28 +02:00
|
|
|
} else if (d->activationAction->shortcut() == shortcut) {
|
2011-12-06 17:37:54 +01:00
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2014-05-16 10:02:56 +02:00
|
|
|
d->activationAction->setShortcut(shortcut);
|
2013-07-10 01:45:41 +02:00
|
|
|
d->globalShortcutEnabled = true;
|
|
|
|
QList<QKeySequence> seqs;
|
2013-07-10 02:33:28 +02:00
|
|
|
seqs << shortcut;
|
2014-01-27 18:52:12 +01:00
|
|
|
KGlobalAccel::self()->setShortcut(d->activationAction, seqs, KGlobalAccel::NoAutoloading);
|
2010-05-07 22:57:03 +02:00
|
|
|
d->globalShortcutChanged();
|
|
|
|
}
|
|
|
|
|
2013-07-10 02:33:28 +02:00
|
|
|
QKeySequence Applet::globalShortcut() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
if (d->activationAction) {
|
2014-01-27 18:52:12 +01:00
|
|
|
QList<QKeySequence> shortcuts = KGlobalAccel::self()->shortcut(d->activationAction);
|
|
|
|
if (!shortcuts.isEmpty()) {
|
|
|
|
return shortcuts.first();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-07-10 02:33:28 +02:00
|
|
|
return QKeySequence();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2013-05-14 18:27:27 +02:00
|
|
|
Types::Location Applet::location() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Containment *c = containment();
|
2013-05-10 19:29:13 +02:00
|
|
|
return c ? c->d->location : Plasma::Types::Desktop;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::hasConfigurationInterface() const
|
|
|
|
{
|
|
|
|
return d->hasConfigurationInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-11-27 21:03:48 +01:00
|
|
|
QAction *configAction = d->actions->action(QStringLiteral("configure"));
|
2010-03-06 02:10:53 +01:00
|
|
|
if (configAction) {
|
|
|
|
bool enable = hasInterface;
|
|
|
|
if (enable) {
|
2013-05-10 19:29:13 +02:00
|
|
|
const bool unlocked = immutability() == Types::Mutable;
|
2015-11-27 21:03:48 +01:00
|
|
|
enable = unlocked || KAuthorized::authorize(QStringLiteral("plasma/allow_configure_when_locked"));
|
2010-03-06 02:10:53 +01:00
|
|
|
}
|
|
|
|
configAction->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->hasConfigurationInterface = hasInterface;
|
|
|
|
}
|
|
|
|
|
2011-04-25 16:43:15 +02:00
|
|
|
void Applet::configChanged()
|
|
|
|
{
|
2011-12-05 00:16:53 +01:00
|
|
|
if (d->script) {
|
|
|
|
if (d->configLoader) {
|
2015-02-11 14:52:41 +01:00
|
|
|
d->configLoader->load();
|
2011-12-05 00:16:53 +01:00
|
|
|
}
|
|
|
|
d->script->configChanged();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-09-16 19:08:45 +02:00
|
|
|
void Applet::setAssociatedApplication(const QString &string)
|
|
|
|
{
|
|
|
|
AssociatedApplicationManager::self()->setApplication(this, string);
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *runAssociatedApplication = d->actions->action(QStringLiteral("run associated application"));
|
2009-09-16 19:08:45 +02:00
|
|
|
if (runAssociatedApplication) {
|
|
|
|
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
runAssociatedApplication->setVisible(valid);
|
|
|
|
runAssociatedApplication->setEnabled(valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-15 22:28:17 +02:00
|
|
|
void Applet::setAssociatedApplicationUrls(const QList<QUrl> &urls)
|
2009-09-16 19:08:45 +02:00
|
|
|
{
|
|
|
|
AssociatedApplicationManager::self()->setUrls(this, urls);
|
|
|
|
|
2016-02-29 00:08:05 +01:00
|
|
|
QAction *runAssociatedApplication = d->actions->action(QStringLiteral("run associated application"));
|
2009-09-16 19:08:45 +02:00
|
|
|
if (runAssociatedApplication) {
|
|
|
|
bool valid = AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
runAssociatedApplication->setVisible(valid);
|
|
|
|
runAssociatedApplication->setEnabled(valid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::associatedApplication() const
|
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->application(this);
|
|
|
|
}
|
|
|
|
|
2012-07-15 22:28:17 +02:00
|
|
|
QList<QUrl> Applet::associatedApplicationUrls() const
|
2009-09-16 19:08:45 +02:00
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->urls(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::runAssociatedApplication()
|
|
|
|
{
|
2013-02-12 12:18:42 +01:00
|
|
|
AssociatedApplicationManager::self()->run(this);
|
2009-09-16 19:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::hasValidAssociatedApplication() const
|
|
|
|
{
|
|
|
|
return AssociatedApplicationManager::self()->appletHasValidAssociatedApplication(this);
|
|
|
|
}
|
|
|
|
|
2013-02-25 17:20:29 +01:00
|
|
|
Applet *Applet::loadPlasmoid(const QString &path, uint appletId)
|
2009-04-26 02:43:20 +02:00
|
|
|
{
|
2016-10-10 16:27:50 +02:00
|
|
|
const KPluginMetaData md = appletMetadataForDirectory(path);
|
|
|
|
if (md.isValid()) {
|
|
|
|
QStringList types = md.serviceTypes();
|
2009-10-23 15:48:29 +02:00
|
|
|
|
2019-08-29 07:23:49 +02:00
|
|
|
if (types.contains(QLatin1String("Plasma/Containment"))) {
|
2016-10-10 16:27:50 +02:00
|
|
|
return new Containment(md, appletId);
|
2013-02-11 19:37:54 +01:00
|
|
|
} else {
|
2016-10-10 16:27:50 +02:00
|
|
|
return new Applet(md, nullptr, appletId);
|
2009-10-23 15:48:29 +02:00
|
|
|
}
|
2009-04-26 02:43:20 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 13:58:44 +02:00
|
|
|
return nullptr;
|
2009-04-26 02:43:20 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Applet::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (d->transient) {
|
2009-11-18 03:21:43 +01:00
|
|
|
d->constraintsTimer.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
|
2014-04-26 01:45:47 +02:00
|
|
|
if (!(d->pendingConstraints & Plasma::Types::StartupCompletedConstraint)) {
|
2008-11-04 18:51:11 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isContainment() const
|
|
|
|
{
|
2014-04-14 14:03:49 +02:00
|
|
|
//HACK: this is a special case for the systray
|
|
|
|
//containment in an applet that is not a containment
|
|
|
|
Applet *pa = qobject_cast<Applet *>(parent());
|
|
|
|
if (pa && !pa->isContainment()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//normal "acting as a containment" condition
|
2014-04-26 01:45:47 +02:00
|
|
|
return qobject_cast<const Containment *>(this) && qobject_cast<Corona *>(parent());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Plasma namespace
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
#include "moc_applet.cpp"
|