2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
2011-01-11 21:45:24 +01:00
|
|
|
* Copyright 2007-2011 Aaron Seigo <aseigo@kde.org>
|
2008-11-04 00:08:39 +01:00
|
|
|
* Copyright 2007 Riccardo Iaconelli <riccardo@kde.org>
|
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 "corona.h"
|
2012-09-24 18:10:25 +02:00
|
|
|
#include "private/corona_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
2010-06-11 19:20:29 +02:00
|
|
|
#include <QDesktopWidget>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QGraphicsGridLayout>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2008-12-12 15:41:15 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2010-11-18 18:17:56 +01:00
|
|
|
#include <kaction.h>
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
2012-03-18 17:45:41 +01:00
|
|
|
#include <klocalizedstring.h>
|
2012-09-24 18:10:25 +02:00
|
|
|
#include <kshortcutsdialog.h>
|
|
|
|
#include <kwindowsystem.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "abstractdialogmanager.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "containment.h"
|
2009-10-05 22:50:57 +02:00
|
|
|
#include "containmentactionspluginsconfig.h"
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "pluginloader.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/applet_p.h"
|
2009-05-03 22:22:14 +02:00
|
|
|
#include "private/containment_p.h"
|
2011-07-19 22:04:22 +02:00
|
|
|
#include "view.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-02-24 15:24:52 +01:00
|
|
|
bool CoronaPrivate::s_positioningContainments = false;
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
Corona::Corona(QObject *parent)
|
2012-09-24 18:10:25 +02:00
|
|
|
: QObject(parent),
|
2008-11-04 00:08:39 +01:00
|
|
|
d(new CoronaPrivate(this))
|
|
|
|
{
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2010-01-31 20:45:48 +01:00
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Corona ctor start";
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2008-11-04 00:08:39 +01:00
|
|
|
d->init();
|
|
|
|
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Corona::~Corona()
|
|
|
|
{
|
2012-03-24 19:33:54 +01:00
|
|
|
KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig");
|
2009-01-22 01:00:16 +01:00
|
|
|
trans.deleteGroup();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::setAppletMimeType(const QString &type)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->mimetype = type;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::appletMimeType()
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->mimetype;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 01:05:13 +01:00
|
|
|
void Corona::setDefaultContainmentPlugin(const QString &name)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
// we could check if it is in:
|
|
|
|
// Containment::listContainments().contains(name) ||
|
|
|
|
// Containment::listContainments(QString(), QCoreApplication::instance()->applicationName()).contains(name)
|
|
|
|
// but that seems like overkill
|
|
|
|
d->defaultContainmentPlugin = name;
|
2011-01-12 01:05:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::defaultContainmentPlugin() const
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->defaultContainmentPlugin;
|
2011-01-12 01:05:13 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::saveLayout(const QString &configName) const
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
KSharedConfigPtr c;
|
|
|
|
|
|
|
|
if (configName.isEmpty() || configName == d->configName) {
|
|
|
|
c = config();
|
|
|
|
} else {
|
|
|
|
c = KSharedConfig::openConfig(configName, KConfig::SimpleConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->saveLayout(c);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-09-27 20:16:43 +02:00
|
|
|
void Corona::exportLayout(KConfigGroup &config, QList<Containment*> containments)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
foreach (const QString &group, config.groupList()) {
|
|
|
|
KConfigGroup cg(&config, group);
|
|
|
|
cg.deleteGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
//temporarily unlock so that removal works
|
|
|
|
ImmutabilityType oldImm = immutability();
|
|
|
|
d->immutability = Mutable;
|
|
|
|
|
|
|
|
KConfigGroup dest(&config, "Containments");
|
|
|
|
KConfigGroup dummy;
|
|
|
|
foreach (Plasma::Containment *c, containments) {
|
|
|
|
c->save(dummy);
|
|
|
|
c->config().reparent(&dest);
|
|
|
|
|
|
|
|
//ensure the containment is unlocked
|
|
|
|
//this is done directly because we have to bypass any SystemImmutable checks
|
|
|
|
c->Applet::d->immutability = Mutable;
|
|
|
|
foreach (Applet *a, c->applets()) {
|
|
|
|
a->d->immutability = Mutable;
|
|
|
|
}
|
|
|
|
|
|
|
|
c->destroy(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//restore immutability
|
|
|
|
d->immutability = oldImm;
|
|
|
|
|
|
|
|
config.sync();
|
2010-09-27 20:16:43 +02:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::requestConfigSync()
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
// constant controlling how long between requesting a configuration sync
|
|
|
|
// and one happening should occur. currently 10 seconds
|
|
|
|
static const int CONFIG_SYNC_TIMEOUT = 10000;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
// TODO: should we check into our immutability before doing this?
|
2008-12-18 23:12:49 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
//NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT
|
|
|
|
// after the first time this is called. not much of a heuristic for save points, but
|
|
|
|
// it should at least compress these activities a bit and provide a way for applet
|
|
|
|
// authors to ween themselves from the sync() disease. A more interesting/dynamic
|
|
|
|
// algorithm for determining when to actually sync() to disk might be better, though.
|
2012-12-20 10:47:51 +01:00
|
|
|
if (!d->configSyncTimer->isActive()) {
|
|
|
|
d->configSyncTimer->start(CONFIG_SYNC_TIMEOUT);
|
2012-09-24 18:10:25 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::requireConfigSync()
|
2010-02-24 15:24:52 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->syncConfig();
|
2010-02-24 15:24:52 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::initializeLayout(const QString &configName)
|
2010-02-24 15:24:52 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
clearContainments();
|
|
|
|
loadLayout(configName);
|
2010-02-24 15:24:52 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
if (d->containments.isEmpty()) {
|
|
|
|
loadDefaultLayout();
|
|
|
|
if (!d->containments.isEmpty()) {
|
|
|
|
requestConfigSync();
|
2010-02-24 15:24:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
if (config()->isImmutable()) {
|
|
|
|
setImmutability(SystemImmutable);
|
|
|
|
} else {
|
|
|
|
KConfigGroup coronaConfig(config(), "General");
|
|
|
|
setImmutability((ImmutabilityType)coronaConfig.readEntry("immutability", (int)Mutable));
|
2010-02-24 15:24:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void Corona::loadLayout(const QString &configName)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
if (!configName.isEmpty() && configName != d->configName) {
|
|
|
|
// if we have a new config name passed in, then use that as the config file for this Corona
|
|
|
|
d->config = 0;
|
|
|
|
d->configName = configName;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup conf(config(), QString());
|
|
|
|
d->importLayout(conf, false);
|
2010-05-14 19:00:54 +02:00
|
|
|
}
|
2009-10-11 19:06:26 +02:00
|
|
|
|
2010-09-27 20:16:43 +02:00
|
|
|
QList<Plasma::Containment *> Corona::importLayout(const KConfigGroup &conf)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->importLayout(conf, true);
|
2010-09-27 20:16:43 +02:00
|
|
|
}
|
|
|
|
|
2008-11-17 05:34:55 +01:00
|
|
|
Containment *Corona::containmentForScreen(int screen, int desktop) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
foreach (Containment *containment, d->containments) {
|
|
|
|
if (containment->screen() == screen &&
|
|
|
|
(desktop < 0 || containment->desktop() == desktop) &&
|
|
|
|
(containment->containmentType() == Containment::DesktopContainment ||
|
|
|
|
containment->containmentType() == Containment::CustomContainment)) {
|
|
|
|
return containment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-11-18 18:17:56 +01:00
|
|
|
Containment *Corona::containmentForScreen(int screen, int desktop,
|
|
|
|
const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
Containment *containment = containmentForScreen(screen, desktop);
|
|
|
|
if (!containment && !defaultPluginIfNonExistent.isEmpty()) {
|
|
|
|
// screen requests are allowed to bypass immutability
|
|
|
|
if (screen >= 0 && screen < numScreens() &&
|
|
|
|
desktop >= -1 && desktop < KWindowSystem::numberOfDesktops()) {
|
2012-12-20 10:47:51 +01:00
|
|
|
containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0);
|
2012-09-24 18:10:25 +02:00
|
|
|
if (containment) {
|
|
|
|
containment->setScreen(screen, desktop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return containment;
|
2010-11-18 18:17:56 +01:00
|
|
|
}
|
2011-01-11 21:45:24 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QList<Containment*> Corona::containments() const
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->containments;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::clearContainments()
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
foreach (Containment *containment, d->containments) {
|
|
|
|
containment->clearApplets();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
KSharedConfigPtr Corona::config() const
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
if (!d->config) {
|
|
|
|
d->config = KSharedConfig::openConfig(d->configName, KConfig::SimpleConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->config;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment *Corona::addContainment(const QString &name, const QVariantList &args)
|
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
if (d->immutability == Mutable) {
|
2012-12-20 10:47:51 +01:00
|
|
|
return d->addContainment(name, args, 0);
|
2009-11-05 02:12:22 +01:00
|
|
|
}
|
2008-12-10 01:57:42 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
return 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
int Corona::numScreens() const
|
2008-11-06 19:21:10 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return 1;
|
2008-11-06 19:21:10 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QRect Corona::screenGeometry(int id) const
|
2009-04-07 23:22:18 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return qApp->desktop()->screenGeometry(id);
|
2009-04-07 23:22:18 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QRegion Corona::availableScreenRegion(int id) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return QRegion(screenGeometry(id));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::loadDefaultLayout()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->toolBoxPlugins[type] = plugin;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QString Corona::preferredToolBoxPlugin(const Containment::Type type) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->toolBoxPlugins.value(type);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
ImmutabilityType Corona::immutability() const
|
2009-09-28 19:28:17 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->immutability;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::setImmutability(const ImmutabilityType immutable)
|
|
|
|
{
|
|
|
|
if (d->immutability == immutable || d->immutability == SystemImmutable) {
|
|
|
|
return;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:46:52 +02:00
|
|
|
#ifndef NDEBUG
|
2012-09-24 18:10:25 +02:00
|
|
|
kDebug() << "setting immutability to" << immutable;
|
2011-07-29 15:46:52 +02:00
|
|
|
#endif
|
2012-09-24 18:10:25 +02:00
|
|
|
d->immutability = immutable;
|
|
|
|
d->updateContainmentImmutability();
|
|
|
|
//tell non-containments that might care (like plasmaapp or a custom corona)
|
|
|
|
emit immutabilityChanged(immutable);
|
|
|
|
|
|
|
|
//update our actions
|
|
|
|
QAction *action = d->actions.action("lock widgets");
|
|
|
|
if (action) {
|
|
|
|
if (d->immutability == SystemImmutable) {
|
|
|
|
action->setEnabled(false);
|
|
|
|
action->setVisible(false);
|
2009-09-28 19:28:17 +02:00
|
|
|
} else {
|
2012-09-24 18:10:25 +02:00
|
|
|
bool unlocked = d->immutability == Mutable;
|
|
|
|
action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets"));
|
|
|
|
action->setIcon(KDE::icon(unlocked ? "object-locked" : "object-unlocked"));
|
|
|
|
action->setEnabled(true);
|
|
|
|
action->setVisible(true);
|
2009-09-28 19:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
if (d->immutability != SystemImmutable) {
|
|
|
|
KConfigGroup cg(config(), "General");
|
2008-12-12 15:41:15 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
// we call the dptr member directly for locked since isImmutable()
|
|
|
|
// also checks kiosk and parent containers
|
|
|
|
cg.writeEntry("immutability", (int)d->immutability);
|
|
|
|
requestConfigSync();
|
2008-12-12 15:41:15 +01:00
|
|
|
}
|
2012-09-24 18:10:25 +02:00
|
|
|
}
|
2008-12-12 15:41:15 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QList<Plasma::Location> Corona::freeEdges(int screen) const
|
|
|
|
{
|
|
|
|
QList<Plasma::Location> freeEdges;
|
|
|
|
freeEdges << Plasma::TopEdge << Plasma::BottomEdge
|
|
|
|
<< Plasma::LeftEdge << Plasma::RightEdge;
|
2011-07-28 18:53:21 +02:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
foreach (Containment *containment, containments()) {
|
|
|
|
if (containment->screen() == screen &&
|
|
|
|
freeEdges.contains(containment->location())) {
|
|
|
|
freeEdges.removeAll(containment->location());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
return freeEdges;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QAction *Corona::action(QString name) const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->actions.action(name);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::addAction(QString name, QAction *action)
|
2010-07-30 14:46:22 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->actions.addAction(name, action);
|
2010-07-30 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
KAction* Corona::addAction(QString name)
|
2010-07-30 14:46:22 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->actions.addAction(name);
|
2010-07-30 14:46:22 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QList<QAction*> Corona::actions() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->actions.actions();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::enableAction(const QString &name, bool enable)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
QAction *action = d->actions.action(name);
|
|
|
|
if (action) {
|
|
|
|
action->setEnabled(enable);
|
|
|
|
action->setVisible(enable);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::updateShortcuts()
|
2008-12-21 11:23:45 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
QMutableListIterator<QWeakPointer<KActionCollection> > it(d->actionCollections);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
KActionCollection *collection = it.value().data();
|
|
|
|
if (!collection) {
|
|
|
|
// get rid of KActionCollections that have been deleted behind our backs
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
collection->readSettings();
|
|
|
|
if (d->shortcutsDlg) {
|
|
|
|
d->shortcutsDlg.data()->addCollection(collection);
|
|
|
|
}
|
|
|
|
}
|
2008-12-21 11:23:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::addShortcuts(KActionCollection *newShortcuts)
|
2009-03-10 20:52:50 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->actionCollections << newShortcuts;
|
|
|
|
if (d->shortcutsDlg) {
|
|
|
|
d->shortcutsDlg.data()->addCollection(newShortcuts);
|
|
|
|
}
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config)
|
2009-03-10 20:52:50 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->containmentActionsDefaults.insert(containmentType, config);
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
ContainmentActionsPluginsConfig Corona::containmentActionsDefaults(Containment::Type containmentType)
|
2009-05-04 00:13:05 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->containmentActionsDefaults.value(containmentType);
|
2009-05-04 00:13:05 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void Corona::setDialogManager(AbstractDialogManager *dialogManager)
|
2009-03-10 20:52:50 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
d->dialogManager = dialogManager;
|
2009-03-10 20:52:50 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
AbstractDialogManager *Corona::dialogManager()
|
2009-03-11 19:37:12 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
return d->dialogManager.data();
|
2009-03-11 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
CoronaPrivate::CoronaPrivate(Corona *corona)
|
|
|
|
: q(corona),
|
|
|
|
immutability(Mutable),
|
|
|
|
mimetype("text/x-plasmoidservicename"),
|
|
|
|
defaultContainmentPlugin("desktop"),
|
|
|
|
config(0),
|
2012-12-20 10:47:51 +01:00
|
|
|
configSyncTimer(new QTimer(corona)),
|
|
|
|
delayedInitTimer(new QTimer(corona)),
|
2012-09-24 18:10:25 +02:00
|
|
|
actions(corona)
|
|
|
|
{
|
|
|
|
if (QCoreApplication::instance()) {
|
|
|
|
configName = QCoreApplication::instance()->applicationName() + "-appletsrc";
|
|
|
|
} else {
|
|
|
|
configName = "plasma-appletsrc";
|
|
|
|
}
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
CoronaPrivate::~CoronaPrivate()
|
2009-05-03 22:22:14 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
qDeleteAll(containments);
|
2009-05-03 22:22:14 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void CoronaPrivate::init()
|
2009-10-05 22:50:57 +02:00
|
|
|
{
|
2012-12-20 10:47:51 +01:00
|
|
|
delayedInitTimer->setInterval(100);
|
|
|
|
delayedInitTimer->setSingleShot(true);
|
|
|
|
QObject::connect(delayedInitTimer, SIGNAL(timeout()), q, SLOT(delayedContainmentInit()));
|
|
|
|
configSyncTimer->setSingleShot(true);
|
|
|
|
QObject::connect(configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig()));
|
2012-09-24 18:10:25 +02:00
|
|
|
|
|
|
|
//some common actions
|
|
|
|
actions.setConfigGroup("Shortcuts");
|
|
|
|
|
|
|
|
KAction *lockAction = actions.addAction("lock widgets");
|
|
|
|
QObject::connect(lockAction, SIGNAL(triggered(bool)), q, SLOT(toggleImmutability()));
|
|
|
|
lockAction->setText(i18n("Lock Widgets"));
|
|
|
|
lockAction->setAutoRepeat(true);
|
|
|
|
lockAction->setIcon(KDE::icon("object-locked"));
|
2012-09-25 20:21:37 +02:00
|
|
|
lockAction->setData(Containment::ControlTool);
|
2012-09-24 18:10:25 +02:00
|
|
|
lockAction->setShortcut(KShortcut("alt+d, l"));
|
|
|
|
lockAction->setShortcutContext(Qt::ApplicationShortcut);
|
|
|
|
|
|
|
|
//FIXME this doesn't really belong here. desktop KCM maybe?
|
|
|
|
//but should the shortcuts be per-app or really-global?
|
|
|
|
//I don't know how to make kactioncollections use plasmarc
|
|
|
|
KAction *action = actions.addAction("configure shortcuts");
|
|
|
|
QObject::connect(action, SIGNAL(triggered()), q, SLOT(showShortcutConfig()));
|
|
|
|
action->setText(i18n("Shortcut Settings"));
|
|
|
|
action->setIcon(KDE::icon("configure-shortcuts"));
|
|
|
|
action->setAutoRepeat(false);
|
2012-09-25 20:21:37 +02:00
|
|
|
action->setData(Containment::ConfigureTool);
|
2012-09-24 18:10:25 +02:00
|
|
|
//action->setShortcut(KShortcut("ctrl+h"));
|
|
|
|
action->setShortcutContext(Qt::ApplicationShortcut);
|
|
|
|
|
|
|
|
//fake containment/applet actions
|
|
|
|
KActionCollection *containmentActions = AppletPrivate::defaultActions(q); //containment has to start with applet stuff
|
|
|
|
ContainmentPrivate::addDefaultActions(containmentActions); //now it's really containment
|
|
|
|
actionCollections << &actions << AppletPrivate::defaultActions(q) << containmentActions;
|
|
|
|
q->updateShortcuts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaPrivate::showShortcutConfig()
|
|
|
|
{
|
|
|
|
//show a kshortcutsdialog with the actions
|
|
|
|
KShortcutsDialog *dlg = shortcutsDlg.data();
|
|
|
|
if (!dlg) {
|
|
|
|
dlg = new KShortcutsDialog();
|
|
|
|
dlg->setModal(false);
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
QObject::connect(dlg, SIGNAL(saved()), q, SIGNAL(shortcutsChanged()));
|
|
|
|
|
|
|
|
dlg->addCollection(&actions);
|
|
|
|
QMutableListIterator<QWeakPointer<KActionCollection> > it(actionCollections);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
KActionCollection *collection = it.value().data();
|
|
|
|
if (!collection) {
|
|
|
|
// get rid of KActionCollections that have been deleted behind our backs
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg->addCollection(collection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop());
|
|
|
|
dlg->configure();
|
|
|
|
dlg->raise();
|
2009-10-05 22:50:57 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void CoronaPrivate::toggleImmutability()
|
2009-10-05 22:50:57 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
if (immutability == Mutable) {
|
|
|
|
q->setImmutability(UserImmutable);
|
|
|
|
} else {
|
|
|
|
q->setImmutability(Mutable);
|
|
|
|
}
|
2009-10-05 22:50:57 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void CoronaPrivate::saveLayout(KSharedConfigPtr cg) const
|
2010-04-03 21:10:32 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
KConfigGroup containmentsGroup(cg, "Containments");
|
|
|
|
foreach (const Containment *containment, containments) {
|
|
|
|
QString cid = QString::number(containment->id());
|
|
|
|
KConfigGroup containmentConfig(&containmentsGroup, cid);
|
|
|
|
containment->save(containmentConfig);
|
|
|
|
}
|
2010-04-03 21:10:32 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void CoronaPrivate::updateContainmentImmutability()
|
2010-04-03 21:10:32 +02:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
foreach (Containment *c, containments) {
|
|
|
|
// we need to tell each containment that immutability has been altered
|
|
|
|
c->updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
2010-04-03 21:10:32 +02:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
void CoronaPrivate::containmentDestroyed(QObject *obj)
|
2011-01-11 21:45:24 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
// we do a static_cast here since it really isn't an Containment by this
|
|
|
|
// point anymore since we are in the qobject dtor. we don't actually
|
|
|
|
// try and do anything with it, we just need the value of the pointer
|
|
|
|
// so this unsafe looking code is actually just fine.
|
|
|
|
Containment* containment = static_cast<Plasma::Containment*>(obj);
|
|
|
|
int index = containments.indexOf(containment);
|
2011-01-11 21:45:24 +01:00
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
if (index > -1) {
|
|
|
|
containments.removeAt(index);
|
|
|
|
q->requestConfigSync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaPrivate::syncConfig()
|
2011-01-11 21:45:24 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
q->config()->sync();
|
|
|
|
emit q->configSynced();
|
2011-01-11 21:45:24 +01:00
|
|
|
}
|
|
|
|
|
2012-12-20 10:47:51 +01:00
|
|
|
Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id)
|
2011-01-11 21:45:24 +01:00
|
|
|
{
|
2012-09-24 18:10:25 +02:00
|
|
|
QString pluginName = name;
|
|
|
|
Containment *containment = 0;
|
|
|
|
Applet *applet = 0;
|
|
|
|
|
|
|
|
//kDebug() << "Loading" << name << args << id;
|
|
|
|
|
|
|
|
if (pluginName.isEmpty() || pluginName == "default") {
|
|
|
|
// default to the desktop containment
|
|
|
|
pluginName = defaultContainmentPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool loadingNull = pluginName == "null";
|
|
|
|
if (!loadingNull) {
|
|
|
|
applet = PluginLoader::self()->loadApplet(pluginName, id, args);
|
|
|
|
containment = dynamic_cast<Containment*>(applet);
|
2012-12-07 17:02:27 +01:00
|
|
|
if (containment) {
|
|
|
|
containment->setParent(q);
|
|
|
|
}
|
2012-09-24 18:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!containment) {
|
|
|
|
if (!loadingNull) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
kDebug() << "loading of containment" << name << "failed.";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case we got a non-Containment from Applet::loadApplet or
|
|
|
|
// a null containment was requested
|
|
|
|
if (applet) {
|
|
|
|
// the applet probably doesn't know what's hit it, so let's pretend it can be
|
|
|
|
// initialized to make assumptions in the applet's dtor safer
|
|
|
|
applet->init();
|
|
|
|
delete applet;
|
|
|
|
}
|
2012-12-07 17:02:27 +01:00
|
|
|
applet = containment = new Containment(q, 0, id);
|
2012-09-24 18:10:25 +02:00
|
|
|
|
|
|
|
if (loadingNull) {
|
|
|
|
containment->setDrawWallpaper(false);
|
|
|
|
} else {
|
|
|
|
containment->setFailedToLaunch(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we want to provide something and don't care about the failure to launch
|
|
|
|
containment->setFormFactor(Plasma::Planar);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this is a new containment, we need to ensure that there are no stale
|
|
|
|
// configuration data around
|
|
|
|
if (id == 0) {
|
|
|
|
KConfigGroup conf(q->config(), "Containments");
|
|
|
|
conf = KConfigGroup(&conf, QString::number(containment->id()));
|
|
|
|
conf.deleteGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
applet->d->isContainment = true;
|
|
|
|
applet->d->setIsContainment(true, true);
|
|
|
|
containments.append(containment);
|
2012-12-20 10:47:51 +01:00
|
|
|
containmentsNeedingInit.append(containment);
|
|
|
|
delayedInitTimer->start();
|
2012-09-24 18:10:25 +02:00
|
|
|
|
|
|
|
QObject::connect(containment, SIGNAL(destroyed(QObject*)),
|
|
|
|
q, SLOT(containmentDestroyed(QObject*)));
|
|
|
|
QObject::connect(containment, SIGNAL(configNeedsSaving()),
|
|
|
|
q, SLOT(requestConfigSync()));
|
|
|
|
QObject::connect(containment, SIGNAL(releaseVisualFocus()),
|
|
|
|
q, SIGNAL(releaseVisualFocus()));
|
|
|
|
QObject::connect(containment, SIGNAL(screenChanged(int,int,Plasma::Containment*)),
|
|
|
|
q, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*)));
|
|
|
|
|
2012-12-20 10:47:51 +01:00
|
|
|
return containment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoronaPrivate::delayedContainmentInit()
|
|
|
|
{
|
|
|
|
foreach (QWeakPointer<Containment> c, containmentsNeedingInit) {
|
|
|
|
Containment *containment = c.data();
|
|
|
|
if (!containment) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
containment->init();
|
|
|
|
KConfigGroup cg = containment->config();
|
|
|
|
containment->restore(cg);
|
|
|
|
containment->updateConstraints(Plasma::StartupCompletedConstraint);
|
|
|
|
containment->save(cg);
|
|
|
|
q->requestConfigSync();
|
|
|
|
containment->flushPendingConstraintsEvents();
|
2012-09-24 18:10:25 +02:00
|
|
|
emit q->containmentAdded(containment);
|
|
|
|
}
|
|
|
|
|
2012-12-20 10:47:51 +01:00
|
|
|
containmentsNeedingInit.clear();
|
2011-01-11 21:45:24 +01:00
|
|
|
}
|
|
|
|
|
2012-09-24 18:10:25 +02:00
|
|
|
QList<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig)
|
|
|
|
{
|
|
|
|
if (!conf.isValid()) {
|
|
|
|
return QList<Containment *>();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Plasma::Containment *> newContainments;
|
|
|
|
QSet<uint> containmentsIds;
|
|
|
|
|
|
|
|
foreach (Containment *containment, containments) {
|
|
|
|
containmentsIds.insert(containment->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup containmentsGroup(&conf, "Containments");
|
|
|
|
|
|
|
|
foreach (const QString &group, containmentsGroup.groupList()) {
|
|
|
|
KConfigGroup containmentConfig(&containmentsGroup, group);
|
|
|
|
|
|
|
|
if (containmentConfig.entryMap().isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint cid = group.toUInt();
|
|
|
|
if (containmentsIds.contains(cid)) {
|
|
|
|
cid = ++AppletPrivate::s_maxAppletId;
|
|
|
|
} else if (cid > AppletPrivate::s_maxAppletId) {
|
|
|
|
AppletPrivate::s_maxAppletId = cid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mergeConfig) {
|
|
|
|
KConfigGroup realConf(q->config(), "Containments");
|
|
|
|
realConf = KConfigGroup(&realConf, QString::number(cid));
|
|
|
|
// in case something was there before us
|
|
|
|
realConf.deleteGroup();
|
|
|
|
containmentConfig.copyTo(&realConf);
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString());
|
|
|
|
#endif
|
2012-12-20 10:47:51 +01:00
|
|
|
Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid);
|
2012-09-24 18:10:25 +02:00
|
|
|
if (!c) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
newContainments.append(c);
|
|
|
|
containmentsIds.insert(c->id());
|
|
|
|
|
|
|
|
c->init();
|
|
|
|
#ifndef NDEBUG
|
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Init Containment" << c->pluginName();
|
|
|
|
#endif
|
|
|
|
c->restore(containmentConfig);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Restored Containment" << c->pluginName();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Containment *containment, newContainments) {
|
|
|
|
containment->updateConstraints(Plasma::StartupCompletedConstraint);
|
|
|
|
containment->d->initApplets();
|
|
|
|
emit q->containmentAdded(containment);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Containment" << containment->name();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return newContainments;
|
|
|
|
}
|
2011-01-11 21:45:24 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
|
2012-02-08 23:33:03 +01:00
|
|
|
|
|
|
|
#include "moc_corona.cpp"
|