* simplify the public API for addApplet, move the more complex version to the pimpl
* move applet loading to Containmnet * rename loadConstraints to loadContainment since it does constraints, applets, etc in one go svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800822
This commit is contained in:
parent
84aa9fb8b0
commit
902d57ffcd
@ -106,6 +106,9 @@ public:
|
||||
}
|
||||
|
||||
void setLockToolText();
|
||||
Applet* addApplet(const QString& name, const QVariantList& args = QVariantList(),
|
||||
const QRectF &geometry = QRectF(-1, -1, -1, -1), uint id = 0,
|
||||
bool delayedInit = false);
|
||||
|
||||
Containment *q;
|
||||
FormFactor formFactor;
|
||||
@ -200,7 +203,18 @@ void Containment::init()
|
||||
Applet::init();
|
||||
}
|
||||
|
||||
void Containment::loadConstraints(KConfigGroup* group)
|
||||
// helper function for sorting the list of applets
|
||||
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();
|
||||
}
|
||||
|
||||
void Containment::loadContainment(KConfigGroup* group)
|
||||
{
|
||||
/*kDebug() << "!!!!!!!!!!!!initConstraints" << group->name() << containmentType();
|
||||
kDebug() << " location:" << group->readEntry("location", (int)d->location);
|
||||
@ -221,9 +235,36 @@ void Containment::loadConstraints(KConfigGroup* group)
|
||||
setLocation((Plasma::Location)group->readEntry("location", (int)d->location));
|
||||
setFormFactor((Plasma::FormFactor)group->readEntry("formfactor", (int)d->formFactor));
|
||||
setScreen(group->readEntry("screen", d->screen));
|
||||
|
||||
flushUpdatedConstraints();
|
||||
//kDebug() << "Containment" << id() << "geometry is" << geometry() << "config'd with" << appletConfig.name();
|
||||
KConfigGroup applets(group, "Applets");
|
||||
|
||||
// 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;
|
||||
foreach (const QString &appletGroup, applets.groupList()) {
|
||||
//kDebug() << "reading from applet group" << appletGroup;
|
||||
KConfigGroup appletConfig(&applets, appletGroup);
|
||||
appletConfigs.append(appletConfig);
|
||||
}
|
||||
qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
||||
|
||||
foreach (KConfigGroup appletConfig, appletConfigs) {
|
||||
int appId = appletConfig.name().toUInt();
|
||||
//kDebug() << "the name is" << appletConfig.name();
|
||||
QString plugin = appletConfig.readEntry("plugin", QString());
|
||||
|
||||
if (plugin.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Applet *applet = d->addApplet(plugin, QVariantList(), appletConfig.readEntry("geometry", QRectF()), appId, true);
|
||||
applet->restore(&appletConfig);
|
||||
}
|
||||
}
|
||||
|
||||
void Containment::saveConstraints(KConfigGroup* group) const
|
||||
void Containment::saveContainment(KConfigGroup* group) const
|
||||
{
|
||||
// locking is saved in Applet::save
|
||||
group->writeEntry("screen", d->screen);
|
||||
@ -626,14 +667,20 @@ void Containment::clearApplets()
|
||||
d->applets.clear();
|
||||
}
|
||||
|
||||
Applet* Containment::addApplet(const QString& name, const QVariantList& args, uint id, const QRectF& appletGeometry, bool delayInit)
|
||||
Applet* Containment::addApplet(const QString& name, const QVariantList& args, const QRectF &appletGeometry)
|
||||
{
|
||||
if (!delayInit && immutability() != NotImmutable) {
|
||||
return d->addApplet(name, args, appletGeometry);
|
||||
}
|
||||
|
||||
Applet* Containment::Private::addApplet(const QString& name, const QVariantList& args,
|
||||
const QRectF& appletGeometry, uint id, bool delayInit)
|
||||
{
|
||||
if (!delayInit && q->immutability() != NotImmutable) {
|
||||
kDebug() << "addApplet for" << name << "requested, but we're currently immutable!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGraphicsView *v = view();
|
||||
QGraphicsView *v = q->view();
|
||||
if (v) {
|
||||
v->setCursor(Qt::BusyCursor);
|
||||
}
|
||||
@ -648,8 +695,9 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
|
||||
applet = new Applet;
|
||||
}
|
||||
|
||||
addApplet(applet, appletGeometry.topLeft(), delayInit);
|
||||
q->addApplet(applet, appletGeometry.topLeft(), delayInit);
|
||||
|
||||
/*
|
||||
if (containmentType() != PanelContainment) {
|
||||
//kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid();
|
||||
if (appletGeometry.isValid()) {
|
||||
@ -658,19 +706,20 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
|
||||
// yes, this means we can't have items start -1, -1
|
||||
//applet->setGeometry(QRectF(appletGeometry.topLeft(),
|
||||
// applet->sizeHint()));
|
||||
} else if (geometry().isValid()) {
|
||||
} else if (q->geometry().isValid()) {
|
||||
//applet->setGeometry(geometryForApplet(applet));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
||||
|
||||
Corona *c = corona();
|
||||
Corona *c = q->corona();
|
||||
if (c) {
|
||||
connect(applet, SIGNAL(configNeedsSaving()), corona(), SLOT(scheduleConfigSync()));
|
||||
connect(applet, SIGNAL(configNeedsSaving()), q->corona(), SLOT(scheduleConfigSync()));
|
||||
}
|
||||
|
||||
emit appletAdded(applet);
|
||||
emit q->appletAdded(applet);
|
||||
return applet;
|
||||
}
|
||||
|
||||
@ -1163,7 +1212,7 @@ void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
QString plasmoidName;
|
||||
plasmoidName = event->mimeData()->data(mimetype);
|
||||
QRectF geom(mapFromScene(event->scenePos()), QSize(0, 0));
|
||||
addApplet(plasmoidName, QVariantList(), 0, geom);
|
||||
addApplet(plasmoidName, QVariantList(), geom);
|
||||
event->acceptProposedAction();
|
||||
} else if (KUrl::List::canDecode(event->mimeData())) {
|
||||
//TODO: collect the mimetypes of available script engines and offer
|
||||
@ -1180,11 +1229,11 @@ void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
||||
|
||||
if (appletList.isEmpty()) {
|
||||
// no special applet associated with this mimetype, let's
|
||||
addApplet("icon", args, 0, geom);
|
||||
addApplet("icon", args, geom);
|
||||
} else {
|
||||
//TODO: should we show a dialog here to choose which plasmoid load if
|
||||
//!appletList.isEmpty()
|
||||
addApplet(appletList.first().pluginName(), args, 0, geom);
|
||||
addApplet(appletList.first().pluginName(), args, geom);
|
||||
}
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
|
@ -184,8 +184,15 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
* @return a pointer to the applet on success, or 0 on failure
|
||||
*/
|
||||
Applet* addApplet(const QString& name, const QVariantList& args = QVariantList(),
|
||||
uint id = 0, const QRectF &geometry = QRectF(-1, -1, -1, -1),
|
||||
bool delayedInit = false);
|
||||
const QRectF &geometry = QRectF(-1, -1, -1, -1));
|
||||
|
||||
/**
|
||||
* add existing applet to this containment at pos
|
||||
* @param applet the applet that should be added
|
||||
* @param pos the containment-relative position
|
||||
* @param dontInit if true, init() will not be called on the applet
|
||||
*/
|
||||
void addApplet(Applet *applet, const QPointF &pos = QPointF(-1, -1), bool dontInit = true);
|
||||
|
||||
/**
|
||||
* @return the applets currently in this Containment
|
||||
@ -197,14 +204,6 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
*/
|
||||
void clearApplets();
|
||||
|
||||
/**
|
||||
* add existing applet to this containment at pos
|
||||
* @param applet the applet that should be added
|
||||
* @param pos the containment-relative position
|
||||
* @param dontInit if true, init() will not be called on the applet
|
||||
*/
|
||||
void addApplet(Applet *applet, const QPointF &pos = QPointF(-1, -1), bool dontInit = true);
|
||||
|
||||
/**
|
||||
* @return the index to insert an applet at if you want it near the point pos.
|
||||
* @param pos the containment-relative position
|
||||
@ -234,12 +233,12 @@ class PLASMA_EXPORT Containment : public Applet
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void saveConstraints(KConfigGroup* group) const;
|
||||
void saveContainment(KConfigGroup* group) const;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
void loadConstraints(KConfigGroup* group);
|
||||
void loadContainment(KConfigGroup* group);
|
||||
|
||||
/**
|
||||
* Emits the launchActivated() signal
|
||||
|
40
corona.cpp
40
corona.cpp
@ -89,7 +89,7 @@ public:
|
||||
foreach (const Containment *containment, containments) {
|
||||
QString cid = QString::number(containment->id());
|
||||
KConfigGroup containmentConfig(&containmentsGroup, cid);
|
||||
containment->saveConstraints(&containmentConfig);
|
||||
containment->saveContainment(&containmentConfig);
|
||||
containment->save(&containmentConfig);
|
||||
KConfigGroup applets(&containmentConfig, "Applets");
|
||||
foreach (const Applet* applet, containment->applets()) {
|
||||
@ -188,16 +188,6 @@ void Corona::scheduleConfigSync() const
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void Corona::loadLayout(const QString& configName)
|
||||
{
|
||||
clearContainments();
|
||||
@ -228,33 +218,7 @@ void Corona::loadLayout(const QString& configName)
|
||||
|
||||
addItem(c);
|
||||
c->init();
|
||||
c->loadConstraints(&containmentConfig);
|
||||
c->flushUpdatedConstraints();
|
||||
//kDebug() << "Containment" << c->id() << "geometry is" << c->geometry().toRect() << "config'd with" << appletConfig.name();
|
||||
KConfigGroup applets(&containmentConfig, "Applets");
|
||||
|
||||
// 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;
|
||||
foreach (const QString &appletGroup, applets.groupList()) {
|
||||
//kDebug() << "reading from applet group" << appletGroup;
|
||||
KConfigGroup appletConfig(&applets, appletGroup);
|
||||
appletConfigs.append(appletConfig);
|
||||
}
|
||||
qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
||||
|
||||
foreach (KConfigGroup appletConfig, appletConfigs) {
|
||||
int appId = appletConfig.name().toUInt();
|
||||
//kDebug() << "the name is" << appletConfig.name();
|
||||
QString plugin = appletConfig.readEntry("plugin", QString());
|
||||
|
||||
if (plugin.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Applet *applet = c->addApplet(plugin, QVariantList(), appId, appletConfig.readEntry("geometry", QRectF()), true);
|
||||
applet->restore(&appletConfig);
|
||||
}
|
||||
c->loadContainment(&containmentConfig);
|
||||
}
|
||||
|
||||
if (d->containments.count() < 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user