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()) { foreach (Applet *applet, c->applets()) {
if (applet->d->extender) { if (applet->d->extender) {
foreach (ExtenderItem *item, applet->d->extender->attachedItems()) { foreach (ExtenderItem *item, applet->d->extender->attachedItems()) {
if (item->sourceAppletId() == d->applet->id()) { if (item->d->sourceApplet == d->applet) {
result.append(item); result.append(item);
} }
} }

View File

@ -66,30 +66,27 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
d->extenderItemId = ++ExtenderItemPrivate::s_maxExtenderItemId; 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 //create items's configgroup
KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems"); KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems");
KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId)); KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId));
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
//TODO: automatically load title and icon. //TODO: automatically load title and icon.
if (!dg.readEntry("sourceAppletId", 0)) { if (!sourceAppletId) {
//The item is new //The item is new
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName()); dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName());
dg.writeEntry("sourceAppletId", hostExtender->d->applet->id()); dg.writeEntry("sourceAppletId", hostExtender->d->applet->id());
d->sourceAppletId = hostExtender->d->applet->id();
d->sourceApplet = hostExtender->d->applet; d->sourceApplet = hostExtender->d->applet;
} else { } else {
//The item already exists. //The item already exists.
d->name = dg.readEntry("extenderItemName", ""); d->name = dg.readEntry("extenderItemName", "");
d->sourceAppletId = dg.readEntry("sourceAppletId", 0);
//Set the sourceapplet. //Find the sourceapplet.
Corona *corona = hostExtender->d->applet->containment()->corona(); Corona *corona = hostExtender->d->applet->containment()->corona();
foreach (Containment *containment, corona->containments()) { foreach (Containment *containment, corona->containments()) {
foreach (Applet *applet, containment->applets()) { foreach (Applet *applet, containment->applets()) {
if (applet->id() == d->sourceAppletId && if (applet->id() == sourceAppletId &&
applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) { applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) {
d->sourceApplet = applet; 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. //create the toolbox.
d->toolbox = new QGraphicsWidget(this); d->toolbox = new QGraphicsWidget(this);
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox); d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
@ -109,6 +110,9 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
//set the extender we want to move to. //set the extender we want to move to.
setExtender(hostExtender); setExtender(hostExtender);
//show or hide the return to source icon.
d->updateToolBox();
//set the image paths, image sizes and collapseIcon position. //set the image paths, image sizes and collapseIcon position.
d->themeChanged(); d->themeChanged();
@ -283,7 +287,7 @@ bool ExtenderItem::autoExpireDelay() const
bool ExtenderItem::isDetached() const bool ExtenderItem::isDetached() const
{ {
if (d->hostApplet()) { if (d->hostApplet()) {
return (sourceAppletId() != d->hostApplet()->id()); return (d->sourceApplet != d->hostApplet());
} else { } else {
return false; return false;
} }
@ -307,11 +311,6 @@ QAction *ExtenderItem::action(const QString &name) const
} }
} }
uint ExtenderItem::sourceAppletId() const
{
return d->sourceAppletId;
}
void ExtenderItem::destroy() void ExtenderItem::destroy()
{ {
if (d->mousePressed) { if (d->mousePressed) {
@ -725,11 +724,11 @@ ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *h
toplevel(0), toplevel(0),
previousTargetExtender(0), previousTargetExtender(0),
extender(hostExtender), extender(hostExtender),
sourceApplet(0),
dragger(new PanelSvg(extenderItem)), dragger(new PanelSvg(extenderItem)),
background(new PanelSvg(extenderItem)), background(new PanelSvg(extenderItem)),
collapseIcon(0), collapseIcon(0),
title(QString()), title(QString()),
sourceAppletId(hostExtender->d->applet->id()),
mousePressed(false), mousePressed(false),
mouseOver(false), mouseOver(false),
expirationTimer(0) expirationTimer(0)
@ -951,6 +950,14 @@ void ExtenderItemPrivate::themeChanged()
q->update(); 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; uint ExtenderItemPrivate::s_maxExtenderItemId = 0;
} // namespace Plasma } // namespace Plasma

View File

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

View File

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