2007-06-01 00:27:33 +02:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
|
|
|
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 Riccardo Iaconelli <riccardo@kde.org>
|
2007-06-01 00:27:33 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2007-06-01 00:27:33 +02:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QMimeData>
|
2008-01-01 23:44:56 +01:00
|
|
|
#include <QTimer>
|
2007-06-01 00:27:33 +02:00
|
|
|
|
2007-06-21 20:25:09 +02:00
|
|
|
#include <KDebug>
|
2008-02-11 22:43:09 +01:00
|
|
|
#include <KGlobal>
|
2007-06-01 00:27:33 +02:00
|
|
|
#include <KLocale>
|
2007-06-21 20:25:09 +02:00
|
|
|
#include <KMimeType>
|
2007-06-01 00:27:33 +02:00
|
|
|
#include <KWindowSystem>
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
#include "containment.h"
|
2007-06-01 00:27:33 +02:00
|
|
|
#include "dataengine.h"
|
2007-06-10 08:24:42 +02:00
|
|
|
#include "phase.h"
|
2007-11-19 23:42:56 +01:00
|
|
|
#include "layouts/layout.h"
|
2007-06-06 05:25:04 +02:00
|
|
|
#include "widgets/icon.h"
|
2007-06-01 00:27:33 +02:00
|
|
|
|
|
|
|
using namespace Plasma;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-01-01 23:44:56 +01:00
|
|
|
// constant controling how long between requesting a configuration sync
|
|
|
|
// and one happening should occur. currently 2 minutes.
|
|
|
|
const int CONFIG_SYNC_TIMEOUT = 120000;
|
|
|
|
|
2007-06-01 00:27:33 +02:00
|
|
|
class Corona::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
2007-07-17 19:55:05 +02:00
|
|
|
: immutable(false),
|
2007-12-20 00:59:59 +01:00
|
|
|
kioskImmutable(false),
|
2007-11-25 00:38:37 +01:00
|
|
|
mimetype("text/x-plasmoidservicename"),
|
|
|
|
config(0)
|
2007-06-01 00:27:33 +02:00
|
|
|
{
|
2008-02-11 22:43:09 +01:00
|
|
|
if (KGlobal::hasMainComponent()) {
|
|
|
|
configName = KGlobal::mainComponent().componentName() + "-appletsrc";
|
|
|
|
} else {
|
|
|
|
configName = "plasma-appletsrc";
|
|
|
|
}
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
2007-06-07 22:57:18 +02:00
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
2007-12-02 01:54:20 +01:00
|
|
|
qDeleteAll(containments);
|
2007-06-07 22:57:18 +02:00
|
|
|
}
|
|
|
|
|
2007-11-09 01:44:35 +01:00
|
|
|
void init(Corona* q)
|
|
|
|
{
|
2008-01-01 23:44:56 +01:00
|
|
|
configSyncTimer.setSingleShot(true);
|
|
|
|
connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig()));
|
2007-11-09 01:44:35 +01:00
|
|
|
QObject::connect(QApplication::desktop(), SIGNAL(resized(int)), q, SLOT(screenResized(int)));
|
|
|
|
}
|
|
|
|
|
2008-01-02 00:41:59 +01:00
|
|
|
void saveApplets(KSharedConfigPtr cg) const
|
|
|
|
{
|
|
|
|
KConfigGroup containmentsGroup(cg, "Containments");
|
|
|
|
foreach (const Containment *containment, containments) {
|
|
|
|
QString cid = QString::number(containment->id());
|
|
|
|
KConfigGroup containmentConfig(&containmentsGroup, cid);
|
|
|
|
containment->saveConstraints(&containmentConfig);
|
|
|
|
containment->save(&containmentConfig);
|
|
|
|
KConfigGroup applets(&containmentConfig, "Applets");
|
|
|
|
foreach (const Applet* applet, containment->applets()) {
|
|
|
|
KConfigGroup appletConfig(&applets, QString::number(applet->id()));
|
|
|
|
applet->save(&appletConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 05:00:39 +01:00
|
|
|
void updateContainmentImmutability()
|
|
|
|
{
|
|
|
|
foreach (Containment *c, containments) {
|
|
|
|
// we need to tell each containment that immutability has been altered
|
|
|
|
// TODO: should we tell the applets too?
|
|
|
|
c->updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-04 02:25:44 +02:00
|
|
|
bool immutable;
|
2007-12-04 05:15:21 +01:00
|
|
|
bool kioskImmutable;
|
2007-07-17 23:13:41 +02:00
|
|
|
QString mimetype;
|
2007-11-25 00:38:37 +01:00
|
|
|
QString configName;
|
|
|
|
KSharedConfigPtr config;
|
2008-01-01 23:44:56 +01:00
|
|
|
QTimer configSyncTimer;
|
2007-09-18 23:25:15 +02:00
|
|
|
QList<Containment*> containments;
|
2007-06-01 00:27:33 +02:00
|
|
|
};
|
|
|
|
|
2007-08-05 15:03:54 +02:00
|
|
|
Corona::Corona(QObject *parent)
|
2007-06-01 00:27:33 +02:00
|
|
|
: QGraphicsScene(parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
2007-11-09 01:44:35 +01:00
|
|
|
d->init(this);
|
2007-07-17 19:55:05 +02:00
|
|
|
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Corona::Corona(const QRectF & sceneRect, QObject * parent )
|
|
|
|
: QGraphicsScene(sceneRect, parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
2007-11-09 01:44:35 +01:00
|
|
|
d->init(this);
|
2007-07-17 19:55:05 +02:00
|
|
|
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Corona::Corona(qreal x, qreal y, qreal width, qreal height, QObject * parent)
|
|
|
|
: QGraphicsScene(x, y, width, height, parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
2007-11-09 01:44:35 +01:00
|
|
|
d->init(this);
|
2007-07-17 19:55:05 +02:00
|
|
|
//setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel)));
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Corona::~Corona()
|
|
|
|
{
|
2007-12-07 06:02:54 +01:00
|
|
|
KConfigGroup cg(config(), "General");
|
|
|
|
|
|
|
|
// we call the dptr member directly for locked since isImmutable()
|
|
|
|
// also checks kiosk and parent containers
|
|
|
|
cg.writeEntry("locked", d->immutable);
|
2007-06-07 22:57:18 +02:00
|
|
|
delete d;
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
2007-06-02 06:47:09 +02:00
|
|
|
QRectF Corona::maxSizeHint() const
|
|
|
|
{
|
|
|
|
//FIXME: this is a bit of a naive implementation, do you think? =)
|
|
|
|
// we should factor in how much space we actually have left!
|
|
|
|
return sceneRect();
|
|
|
|
}
|
2007-06-01 00:27:33 +02:00
|
|
|
|
2007-07-17 23:13:41 +02:00
|
|
|
void Corona::setAppletMimeType(const QString& type)
|
|
|
|
{
|
|
|
|
d->mimetype = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Corona::appletMimeType()
|
|
|
|
{
|
|
|
|
return d->mimetype;
|
|
|
|
}
|
|
|
|
|
2008-02-11 22:43:09 +01:00
|
|
|
void Corona::saveApplets(const QString &configName) const
|
2007-06-01 00:27:33 +02:00
|
|
|
{
|
2008-02-11 22:43:09 +01:00
|
|
|
KSharedConfigPtr c;
|
2007-08-05 15:03:54 +02:00
|
|
|
|
2008-02-11 22:43:09 +01:00
|
|
|
if (configName.isEmpty() || configName == d->configName) {
|
|
|
|
c = config();
|
|
|
|
} else {
|
|
|
|
c = KSharedConfig::openConfig(configName);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->saveApplets(c);
|
2007-08-05 15:03:54 +02:00
|
|
|
}
|
|
|
|
|
2008-01-02 00:41:59 +01:00
|
|
|
void Corona::scheduleConfigSync() const
|
2008-01-01 23:44:56 +01: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.
|
|
|
|
if (!d->configSyncTimer.isActive()) {
|
|
|
|
d->configSyncTimer.start(CONFIG_SYNC_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-03 09:44:14 +01:00
|
|
|
bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2)
|
|
|
|
{
|
|
|
|
QPointF p1 = c1.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
QPointF p2 = c2.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
if (p1.x() != p2.x()) {
|
|
|
|
return p1.x() < p2.x();
|
|
|
|
}
|
|
|
|
return p1.y() < p2.y();
|
|
|
|
}
|
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
void Corona::loadApplets(const QString& configName)
|
2007-08-05 15:03:54 +02:00
|
|
|
{
|
2007-08-08 19:32:32 +02:00
|
|
|
clearApplets();
|
2008-02-11 22:43:09 +01:00
|
|
|
KSharedConfigPtr c;
|
|
|
|
|
|
|
|
if (configName.isEmpty() || configName == d->configName) {
|
|
|
|
c = config();
|
|
|
|
} else {
|
|
|
|
c = KSharedConfig::openConfig(configName);
|
2008-01-02 00:41:59 +01:00
|
|
|
}
|
2007-08-29 04:33:22 +02:00
|
|
|
|
2007-12-07 06:02:54 +01:00
|
|
|
KConfigGroup containments(config(), "Containments");
|
2007-09-18 23:25:15 +02:00
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
foreach (const QString& group, containments.groupList()) {
|
|
|
|
KConfigGroup containmentConfig(&containments, group);
|
2007-11-27 08:47:23 +01:00
|
|
|
|
|
|
|
if (containmentConfig.entryMap().isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
int cid = group.toUInt();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group;
|
2007-11-25 00:38:37 +01:00
|
|
|
Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(),
|
|
|
|
cid, true);
|
2007-09-18 23:25:15 +02:00
|
|
|
if (!c) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
addItem(c);
|
2007-11-29 02:02:33 +01:00
|
|
|
c->init();
|
2007-11-25 00:38:37 +01:00
|
|
|
c->loadConstraints(&containmentConfig);
|
2008-01-06 08:17:53 +01:00
|
|
|
c->flushUpdatedConstraints();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "Containment" << c->id() << "geometry is" << c->geometry().toRect() << "config'd with" << appletConfig.name();
|
2007-11-25 00:38:37 +01:00
|
|
|
KConfigGroup applets(&containmentConfig, "Applets");
|
|
|
|
|
2008-01-03 09:44:14 +01:00
|
|
|
// Sort the applet configs in order of geometry to ensure that applets
|
|
|
|
// are added from left to right or top to bottom for a panel containment
|
|
|
|
QList<KConfigGroup> appletConfigs;
|
2007-11-25 00:38:37 +01:00
|
|
|
foreach (const QString &appletGroup, applets.groupList()) {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "reading from applet group" << appletGroup;
|
2007-11-25 00:38:37 +01:00
|
|
|
KConfigGroup appletConfig(&applets, appletGroup);
|
2008-01-03 09:44:14 +01:00
|
|
|
appletConfigs.append(appletConfig);
|
|
|
|
}
|
|
|
|
qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
|
|
|
|
|
|
|
foreach (KConfigGroup appletConfig, appletConfigs) {
|
|
|
|
int appId = appletConfig.name().toUInt();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "the name is" << appletConfig.name();
|
2007-11-27 07:35:26 +01:00
|
|
|
QString plugin = appletConfig.readEntry("plugin", QString());
|
|
|
|
|
|
|
|
if (plugin.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = c->addApplet(plugin, QVariantList(), appId, appletConfig.readEntry("geometry", QRectF()), true);
|
2008-02-13 02:52:45 +01:00
|
|
|
applet->restore(&appletConfig);
|
2007-12-28 19:04:00 +01:00
|
|
|
}
|
2007-09-13 19:03:13 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
if (d->containments.count() < 1) {
|
|
|
|
loadDefaultSetup();
|
2007-10-09 18:32:34 +02:00
|
|
|
} else {
|
|
|
|
foreach (Containment* containment, d->containments) {
|
2007-11-25 00:38:37 +01:00
|
|
|
QString cid = QString::number(containment->id());
|
|
|
|
KConfigGroup containmentConfig(&containments, cid);
|
2007-09-18 23:25:15 +02:00
|
|
|
|
2007-10-09 18:32:34 +02:00
|
|
|
foreach(Applet* applet, containment->applets()) {
|
|
|
|
applet->init();
|
|
|
|
}
|
2007-09-18 23:25:15 +02:00
|
|
|
|
2008-01-06 21:38:35 +01:00
|
|
|
containment->updateConstraints(Plasma::StartupCompletedConstraint);
|
2007-11-25 00:38:37 +01:00
|
|
|
containment->flushUpdatedConstraints();
|
|
|
|
}
|
2007-11-29 01:19:03 +01:00
|
|
|
|
|
|
|
// quick sanity check to ensure we have containments for each screen!
|
|
|
|
int numScreens = QApplication::desktop()->numScreens();
|
|
|
|
for (int i = 0; i < numScreens; ++i) {
|
|
|
|
if (!containmentForScreen(i)) {
|
|
|
|
//TODO: should we look for containments that aren't asigned but already exist?
|
|
|
|
Containment* c = addContainment("desktop");
|
|
|
|
c->setScreen(i);
|
|
|
|
c->setFormFactor(Plasma::Planar);
|
2008-01-05 11:35:32 +01:00
|
|
|
c->flushUpdatedConstraints();
|
2007-11-29 01:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 03:08:19 +02:00
|
|
|
}
|
|
|
|
|
2007-12-07 06:02:54 +01:00
|
|
|
d->kioskImmutable = config()->isImmutable();
|
2008-01-07 05:00:39 +01:00
|
|
|
if (d->kioskImmutable) {
|
|
|
|
d->updateContainmentImmutability();
|
|
|
|
}
|
|
|
|
|
2007-12-07 06:02:54 +01:00
|
|
|
KConfigGroup coronaConfig(config(), "General");
|
|
|
|
setImmutable(coronaConfig.readEntry("locked", false));
|
2007-08-05 15:03:54 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
void Corona::loadDefaultSetup()
|
2007-08-08 19:32:32 +02:00
|
|
|
{
|
2007-09-18 23:25:15 +02:00
|
|
|
//FIXME: implement support for system-wide defaults
|
2007-11-09 01:44:35 +01:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
int numScreens = desktop->numScreens();
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "number of screens is" << numScreens;
|
2007-11-02 03:21:13 +01:00
|
|
|
int topLeftScreen = 0;
|
2007-11-09 01:44:35 +01:00
|
|
|
QPoint topLeftCorner = desktop->screenGeometry(0).topLeft();
|
2007-11-02 03:21:13 +01:00
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
// create a containment for each screen
|
|
|
|
for (int i = 0; i < numScreens; ++i) {
|
2007-11-09 01:44:35 +01:00
|
|
|
QRect g = desktop->screenGeometry(i);
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << " screen " << i << "geometry is" << g;
|
2007-10-03 17:45:31 +02:00
|
|
|
Containment* c = addContainment("desktop");
|
2007-09-18 23:25:15 +02:00
|
|
|
c->setScreen(i);
|
|
|
|
c->setFormFactor(Plasma::Planar);
|
2008-01-05 11:35:32 +01:00
|
|
|
c->flushUpdatedConstraints();
|
2007-11-02 03:21:13 +01:00
|
|
|
|
2007-11-02 03:31:58 +01:00
|
|
|
if (g.x() <= topLeftCorner.x() && g.y() >= topLeftCorner.y()) {
|
2007-11-02 03:21:13 +01:00
|
|
|
topLeftCorner = g.topLeft();
|
|
|
|
topLeftScreen = i;
|
|
|
|
}
|
2007-09-18 23:25:15 +02:00
|
|
|
}
|
2007-09-30 20:06:08 +02:00
|
|
|
|
|
|
|
// make a panel at the bottom
|
2007-10-26 03:08:19 +02:00
|
|
|
Containment* panel = addContainment("panel");
|
2007-11-02 03:21:13 +01:00
|
|
|
panel->setScreen(topLeftScreen);
|
2007-10-26 03:08:19 +02:00
|
|
|
panel->setLocation(Plasma::BottomEdge);
|
2007-09-30 20:06:08 +02:00
|
|
|
|
|
|
|
// some default applets to get a usable UI
|
2007-10-24 04:04:02 +02:00
|
|
|
panel->addApplet("launcher");
|
|
|
|
panel->addApplet("tasks");
|
2008-01-01 20:37:05 +01:00
|
|
|
panel->addApplet("pager");
|
2007-10-24 04:04:02 +02:00
|
|
|
panel->addApplet("systemtray");
|
2007-11-28 00:22:07 +01:00
|
|
|
panel->addApplet("notifier");
|
2007-10-24 04:04:02 +02:00
|
|
|
panel->addApplet("digital-clock");
|
2007-11-09 01:44:35 +01:00
|
|
|
|
|
|
|
// trigger an instant layout so we immediately have a proper geometry rather than waiting around
|
|
|
|
// for the event loop
|
|
|
|
panel->flushUpdatedConstraints();
|
|
|
|
if (panel->layout()) {
|
|
|
|
panel->layout()->invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* a little snip that adds another panel, this time to the left
|
|
|
|
*
|
|
|
|
panel = addContainment("panel");
|
|
|
|
panel->setScreen(topLeftScreen);
|
|
|
|
//TODO: but .. *where* on the left edge?
|
|
|
|
panel->setLocation(Plasma::LeftEdge);
|
|
|
|
*/
|
2007-11-27 08:47:23 +01:00
|
|
|
|
2008-01-01 23:44:56 +01:00
|
|
|
// in case something goes bad during runtime, let's at least save this to disk soonish
|
|
|
|
scheduleConfigSync();
|
2007-08-08 19:32:32 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
Containment* Corona::containmentForScreen(int screen) const
|
2007-08-05 15:03:54 +02:00
|
|
|
{
|
2007-09-18 23:25:15 +02:00
|
|
|
foreach (Containment* containment, d->containments) {
|
2007-10-26 03:08:19 +02:00
|
|
|
if (containment->screen() == screen &&
|
2007-11-19 03:14:18 +01:00
|
|
|
containment->containmentType() == Containment::DesktopContainment) {
|
2007-09-18 23:25:15 +02:00
|
|
|
return containment;
|
|
|
|
}
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
2007-06-20 10:11:59 +02:00
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2007-09-01 14:34:22 +02:00
|
|
|
|
2007-09-30 20:06:08 +02:00
|
|
|
QList<Containment*> Corona::containments() const
|
|
|
|
{
|
|
|
|
return d->containments;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
void Corona::clearApplets()
|
|
|
|
{
|
|
|
|
foreach (Containment* containment, d->containments) {
|
|
|
|
containment->clearApplets();
|
2007-09-01 14:34:22 +02:00
|
|
|
}
|
2007-09-18 23:25:15 +02:00
|
|
|
}
|
|
|
|
|
2008-01-02 00:41:59 +01:00
|
|
|
KSharedConfigPtr Corona::config() const
|
2007-11-25 00:38:37 +01:00
|
|
|
{
|
|
|
|
if (!d->config) {
|
|
|
|
d->config = KSharedConfig::openConfig(d->configName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->config;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
Containment* Corona::addContainment(const QString& name, const QVariantList& args, uint id, bool delayedInit)
|
|
|
|
{
|
2007-10-07 23:53:47 +02:00
|
|
|
QString pluginName = name;
|
2007-09-18 23:25:15 +02:00
|
|
|
Containment* containment = 0;
|
|
|
|
Applet* applet = 0;
|
2007-09-01 14:34:22 +02:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "Loading" << name << args << id;
|
2007-09-30 20:06:08 +02:00
|
|
|
|
2007-10-07 23:53:47 +02:00
|
|
|
if (pluginName.isEmpty()) {
|
|
|
|
// default to the desktop containment
|
|
|
|
pluginName = "desktop";
|
2007-11-15 12:06:33 +01:00
|
|
|
} else if (pluginName != "null") {
|
2007-10-28 21:04:38 +01:00
|
|
|
applet = Applet::loadApplet(pluginName, id, args);
|
|
|
|
containment = dynamic_cast<Containment*>(applet);
|
2007-09-01 14:34:22 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
if (!containment) {
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "loading of containment" << name << "failed.";
|
2007-10-28 21:04:38 +01:00
|
|
|
|
|
|
|
// in case we got a non-Containment from Applet::loadApplet or a null containment was requested
|
|
|
|
delete applet;
|
2007-09-18 23:25:15 +02:00
|
|
|
containment = new Containment;
|
2007-10-28 21:04:38 +01:00
|
|
|
|
|
|
|
// we want to provide something and don't care about the failure to launch
|
|
|
|
containment->setFailedToLaunch(false);
|
2007-11-03 02:36:53 +01:00
|
|
|
containment->setFormFactor(Plasma::Planar);
|
2007-08-05 15:03:54 +02:00
|
|
|
}
|
2007-09-01 14:34:22 +02:00
|
|
|
|
2007-11-15 10:41:55 +01:00
|
|
|
containment->setIsContainment(true);
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
if (!delayedInit) {
|
2007-10-12 01:18:33 +02:00
|
|
|
addItem(containment);
|
2007-11-09 01:44:35 +01:00
|
|
|
containment->init();
|
2008-01-06 21:38:35 +01:00
|
|
|
containment->updateConstraints(Plasma::StartupCompletedConstraint);
|
2007-09-13 19:03:13 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
d->containments.append(containment);
|
|
|
|
connect(containment, SIGNAL(destroyed(QObject*)),
|
|
|
|
this, SLOT(containmentDestroyed(QObject*)));
|
2007-11-15 12:06:33 +01:00
|
|
|
connect(containment, SIGNAL(launchActivated()),
|
|
|
|
SIGNAL(launchActivated()));
|
2008-01-05 00:14:06 +01:00
|
|
|
connect(containment, SIGNAL(configNeedsSaving()),
|
2008-01-05 11:50:12 +01:00
|
|
|
SLOT(scheduleConfigSync()));
|
2007-09-18 23:25:15 +02:00
|
|
|
|
|
|
|
return containment;
|
|
|
|
}
|
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
void Corona::destroyContainment(Containment *c)
|
|
|
|
{
|
|
|
|
if (!d->containments.contains(c)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->containments.removeAll(c);
|
|
|
|
c->config().deleteGroup();
|
|
|
|
c->deleteLater();
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:27:33 +02:00
|
|
|
void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)";
|
2007-08-06 00:04:26 +02:00
|
|
|
if (event->mimeData()->hasFormat(d->mimetype) ||
|
2007-06-14 00:11:49 +02:00
|
|
|
KUrl::List::canDecode(event->mimeData())) {
|
2007-06-01 00:27:33 +02:00
|
|
|
event->acceptProposedAction();
|
2007-10-03 17:45:31 +02:00
|
|
|
//TODO Create the applet, move to mouse position then send the
|
2007-06-01 00:27:33 +02:00
|
|
|
// following event to lock it to the mouse
|
|
|
|
//QMouseEvent event(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, event->mouseButtons(), 0);
|
|
|
|
//QApplication::sendEvent(this, &event);
|
|
|
|
}
|
2007-08-05 10:41:55 +02:00
|
|
|
|
2007-08-01 09:09:27 +02:00
|
|
|
event->accept();
|
2007-06-01 00:27:33 +02:00
|
|
|
//TODO Allow dragging an applet from another Corona into this one while
|
|
|
|
// keeping its settings etc.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << "Corona::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)";
|
2007-06-01 00:27:33 +02:00
|
|
|
//TODO If an established Applet is dragged out of the Corona, remove it and
|
|
|
|
// create a QDrag type thing to keep the Applet's settings
|
2007-08-16 07:32:54 +02:00
|
|
|
|
|
|
|
QGraphicsScene::dragLeaveEvent(event);
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Corona::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2007-08-01 09:09:27 +02:00
|
|
|
QGraphicsScene::dragMoveEvent(event);
|
|
|
|
|
|
|
|
event->accept();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "Corona::dragMoveEvent(QDragMoveEvent* event)";
|
2007-06-01 00:27:33 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:25:15 +02:00
|
|
|
void Corona::containmentDestroyed(QObject* obj)
|
2007-06-02 09:51:11 +02:00
|
|
|
{
|
2007-09-18 23:25:15 +02:00
|
|
|
// we do a static_cast here since it really isn't an Containment by this
|
2007-06-02 09:51:11 +02:00
|
|
|
// 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.
|
2007-09-18 23:25:15 +02:00
|
|
|
Containment* containment = static_cast<Plasma::Containment*>(obj);
|
|
|
|
int index = d->containments.indexOf(containment);
|
2007-06-02 09:51:11 +02:00
|
|
|
|
|
|
|
if (index > -1) {
|
2007-09-18 23:25:15 +02:00
|
|
|
d->containments.removeAt(index);
|
2007-06-02 09:51:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-09 01:44:35 +01:00
|
|
|
void Corona::screenResized(int screen)
|
|
|
|
{
|
2007-12-17 19:26:38 +01:00
|
|
|
bool desktopFound = false;
|
2007-11-09 01:44:35 +01:00
|
|
|
foreach (Containment *c, d->containments) {
|
|
|
|
if (c->screen() == screen) {
|
|
|
|
// trigger a relayout
|
|
|
|
c->setScreen(screen);
|
2007-12-17 19:26:38 +01:00
|
|
|
desktopFound = desktopFound || c->containmentType() == Containment::DesktopContainment;
|
2007-11-09 01:44:35 +01:00
|
|
|
}
|
|
|
|
}
|
2007-11-27 23:55:09 +01:00
|
|
|
|
2007-12-17 19:26:38 +01:00
|
|
|
if (desktopFound) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-27 23:55:09 +01:00
|
|
|
// a new screen appeared. neat.
|
|
|
|
// FIXME: apparently QDesktopWidget doesn't do the Right Thing when a new screen is plugged in
|
|
|
|
// at runtime. seems it gets confused and thinks it's all one big screen? need to
|
|
|
|
// fix this upstream
|
|
|
|
Containment* c = addContainment("desktop");
|
|
|
|
c->setScreen(screen);
|
|
|
|
c->setFormFactor(Plasma::Planar);
|
|
|
|
emit newScreen(screen);
|
2007-11-09 01:44:35 +01:00
|
|
|
}
|
|
|
|
|
2008-01-01 23:44:56 +01:00
|
|
|
void Corona::syncConfig()
|
|
|
|
{
|
|
|
|
config()->sync();
|
|
|
|
}
|
|
|
|
|
2007-07-23 02:24:36 +02:00
|
|
|
bool Corona::isImmutable() const
|
2007-06-04 02:25:44 +02:00
|
|
|
{
|
2007-12-04 05:15:21 +01:00
|
|
|
return d->kioskImmutable || d->immutable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Corona::isKioskImmutable() const
|
|
|
|
{
|
|
|
|
return d->kioskImmutable;
|
2007-06-04 02:25:44 +02:00
|
|
|
}
|
|
|
|
|
2007-06-07 21:40:16 +02:00
|
|
|
void Corona::setImmutable(bool immutable)
|
2007-06-04 02:25:44 +02:00
|
|
|
{
|
2008-01-07 05:00:39 +01:00
|
|
|
if (d->immutable == immutable ||
|
|
|
|
(!immutable && d->kioskImmutable)) {
|
2007-06-07 21:40:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "setting immutability to" << immutable;
|
2007-06-07 21:40:16 +02:00
|
|
|
d->immutable = immutable;
|
2008-01-07 05:00:39 +01:00
|
|
|
d->updateContainmentImmutability();
|
2007-06-04 02:25:44 +02:00
|
|
|
}
|
|
|
|
|
2007-06-01 00:27:33 +02:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "corona.moc"
|
|
|
|
|