A bit more sourceApplet correctness:

* Removed sourceApplet() function, it has no place in public api. That was also discussed in the api review, but I forgot to actually remove it.
* Update sourceApplet's pointer and remove the "return to source" button when the source applet is removed.


svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=875290
This commit is contained in:
Rob Scheepmaker 2008-10-23 22:42:58 +00:00
parent 3488fd23c7
commit 241d38ad65
4 changed files with 26 additions and 23 deletions

View File

@ -101,7 +101,7 @@ QList<ExtenderItem*> Extender::items() const
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
foreach (ExtenderItem *item, applet->d->extender->attachedItems()) {
if (item->sourceAppletId() == d->applet->id()) {
if (item->d->sourceApplet == d->applet) {
result.append(item);
}
}

View File

@ -66,30 +66,27 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
d->extenderItemId = ++ExtenderItemPrivate::s_maxExtenderItemId;
}
//TODO: make sourceApplet a function so stuff doesn't break when the source applet has been
//removed.
d->sourceApplet = hostExtender->d->applet;
//create items's configgroup
KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems");
KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId));
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
//TODO: automatically load title and icon.
if (!dg.readEntry("sourceAppletId", 0)) {
if (!sourceAppletId) {
//The item is new
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName());
dg.writeEntry("sourceAppletId", hostExtender->d->applet->id());
d->sourceAppletId = hostExtender->d->applet->id();
d->sourceApplet = hostExtender->d->applet;
} else {
//The item already exists.
d->name = dg.readEntry("extenderItemName", "");
d->sourceAppletId = dg.readEntry("sourceAppletId", 0);
//Set the sourceapplet.
//Find the sourceapplet.
Corona *corona = hostExtender->d->applet->containment()->corona();
foreach (Containment *containment, corona->containments()) {
foreach (Applet *applet, containment->applets()) {
if (applet->id() == d->sourceAppletId &&
if (applet->id() == sourceAppletId &&
applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) {
d->sourceApplet = applet;
}
@ -97,6 +94,10 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
}
}
//make sure we keep monitoring if the source applet still exists, so the return to source icon
//can be hidden if it is removed.
connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved()));
//create the toolbox.
d->toolbox = new QGraphicsWidget(this);
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
@ -109,6 +110,9 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
//set the extender we want to move to.
setExtender(hostExtender);
//show or hide the return to source icon.
d->updateToolBox();
//set the image paths, image sizes and collapseIcon position.
d->themeChanged();
@ -283,7 +287,7 @@ bool ExtenderItem::autoExpireDelay() const
bool ExtenderItem::isDetached() const
{
if (d->hostApplet()) {
return (sourceAppletId() != d->hostApplet()->id());
return (d->sourceApplet != d->hostApplet());
} else {
return false;
}
@ -307,11 +311,6 @@ QAction *ExtenderItem::action(const QString &name) const
}
}
uint ExtenderItem::sourceAppletId() const
{
return d->sourceAppletId;
}
void ExtenderItem::destroy()
{
if (d->mousePressed) {
@ -725,11 +724,11 @@ ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *h
toplevel(0),
previousTargetExtender(0),
extender(hostExtender),
sourceApplet(0),
dragger(new PanelSvg(extenderItem)),
background(new PanelSvg(extenderItem)),
collapseIcon(0),
title(QString()),
sourceAppletId(hostExtender->d->applet->id()),
mousePressed(false),
mouseOver(false),
expirationTimer(0)
@ -951,6 +950,14 @@ void ExtenderItemPrivate::themeChanged()
q->update();
}
void ExtenderItemPrivate::sourceAppletRemoved()
{
//the original source applet is removed, set the pointer to 0 and no longer show the return to
//source icon.
sourceApplet = 0;
updateToolBox();
}
uint ExtenderItemPrivate::s_maxExtenderItemId = 0;
} // namespace Plasma

View File

@ -171,11 +171,6 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
*/
QAction *action(const QString &name) const;
/**
* @return the id of the applet this item is created by.
*/
uint sourceAppletId() const;
public Q_SLOTS:
/**
* Destroys the extender item. As opposed to calling delete on this class, destroy also
@ -210,6 +205,7 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
Q_PRIVATE_SLOT(d, void toggleCollapse())
Q_PRIVATE_SLOT(d, void updateToolBox())
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void sourceAppletRemoved())
ExtenderItemPrivate * const d;

View File

@ -55,6 +55,7 @@ class ExtenderItemPrivate
QPointF scenePosFromScreenPos(const QPoint &pos) const;
Applet *hostApplet() const;
void themeChanged();
void sourceAppletRemoved();
ExtenderItem *q;
@ -79,7 +80,6 @@ class ExtenderItemPrivate
QString title;
QString name;
uint sourceAppletId;
uint extenderItemId;
qreal dragLeft, dragTop, dragRight, dragBottom;