From bfb771ddd878a521e9c600f71b60b05a1901cce9 Mon Sep 17 00:00:00 2001 From: Rob Scheepmaker Date: Fri, 16 Jan 2009 18:49:54 +0000 Subject: [PATCH] Make all items persistent by default, even if still attached. This allows us to restore their position and their collapsed state. svn path=/trunk/KDE/kdelibs/; revision=912127 --- applet.cpp | 11 +++++--- extender.cpp | 61 ++++++++++++++++++---------------------- extenderitem.cpp | 12 ++++---- private/extenderitem_p.h | 1 + 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/applet.cpp b/applet.cpp index 0d750376d..6bf33e925 100644 --- a/applet.cpp +++ b/applet.cpp @@ -143,15 +143,15 @@ Applet::~Applet() //problem with calling saveState(). Doing this in saveState() might be a possibility, but //that would require every extender savestate implementation to call it's parent function, //which isn't very nice. + d->extender->saveState(); + foreach (ExtenderItem *item, d->extender->attachedItems()) { - if (!item->isDetached() || item->autoExpireDelay()) { + if (item->autoExpireDelay()) { //destroy temporary extender items, or items that aren't detached, so their //configuration won't linger after a plasma restart. item->destroy(); } } - - d->extender->saveState(); } delete d; @@ -590,7 +590,10 @@ void Applet::constraintsEvent(Plasma::Constraints constraints) void Applet::initExtenderItem(ExtenderItem *item) { - Q_UNUSED(item) + kWarning() << "Missing implementation of initExtenderItem in the applet " + << item->config().readEntry("SourceAppletPluginName", "") + << "!\n Any applet that uses extenders should implement initExtenderItem to " + << "instantiate a widget. Destroying the item..."; item->destroy(); } diff --git a/extender.cpp b/extender.cpp index 6dda436e7..42a5d4278 100644 --- a/extender.cpp +++ b/extender.cpp @@ -386,8 +386,6 @@ void ExtenderPrivate::loadExtenderItems() //first create a list of extenderItems, and then sort them on their position, so the items get //recreated in the correct order. - //TODO: this restoring of the correct order should now be done in itemAddedEvent instead of - //here, to allow easy subclassing of Extender. QList > groupList; foreach (const QString &extenderItemId, cg.groupList()) { KConfigGroup dg = cg.group(extenderItemId); @@ -398,6 +396,7 @@ void ExtenderPrivate::loadExtenderItems() //iterate over the extender items for (int i = 0; i < groupList.count(); i++) { QPair pair = groupList[i]; + KConfigGroup dg = cg.group(pair.second); //load the relevant settings. @@ -411,43 +410,37 @@ void ExtenderPrivate::loadExtenderItems() kDebug() << "applet id = " << applet->id(); kDebug() << "sourceappletid = " << sourceAppletId; - if (sourceAppletId != applet->id()) { - //find the source applet. - Corona *corona = applet->containment()->corona(); - Applet *sourceApplet = 0; - foreach (Containment *containment, corona->containments()) { - foreach (Applet *applet, containment->applets()) { - if (applet->id() == sourceAppletId) { - sourceApplet = applet; - } + //find the source applet. + Corona *corona = applet->containment()->corona(); + Applet *sourceApplet = 0; + foreach (Containment *containment, corona->containments()) { + foreach (Applet *applet, containment->applets()) { + if (applet->id() == sourceAppletId) { + sourceApplet = applet; } } + } - //There is no source applet. We just instantiate one just for the sake of creating - //detachables. - if (!sourceApplet) { - kDebug() << "creating a temporary applet as factory"; - sourceApplet = Applet::load(appletName); - temporarySourceApplet = true; - //TODO: maybe add an option to applet to indicate that it shouldn't be deleted after - //having used it as factory. - } + //There is no source applet. We just instantiate one just for the sake of creating + //detachables. + if (!sourceApplet) { + kDebug() << "creating a temporary applet as factory"; + sourceApplet = Applet::load(appletName); + temporarySourceApplet = true; + //TODO: maybe add an option to applet to indicate that it shouldn't be deleted after + //having used it as factory. + } - if (!sourceApplet) { - kDebug() << "sourceApplet is null? appletName = " << appletName; - kDebug() << " extenderItemId = " << extenderItemId; - } else { - ExtenderItem *item = new ExtenderItem(q, extenderItemId.toInt()); - sourceApplet->initExtenderItem(item); - - if (temporarySourceApplet) { - delete sourceApplet; - } - } + if (!sourceApplet) { + kDebug() << "sourceApplet is null? appletName = " << appletName; + kDebug() << " extenderItemId = " << extenderItemId; } else { - //this entry is still here, probably because plasma crashed, but it isn't detached and - //should be reinstantiated. Just delete the entry. - cg.deleteGroup(pair.second); + ExtenderItem *item = new ExtenderItem(q, extenderItemId.toInt()); + sourceApplet->initExtenderItem(item); + + if (temporarySourceApplet) { + delete sourceApplet; + } } } } diff --git a/extenderitem.cpp b/extenderitem.cpp index 0bc1c5c15..5864bbe55 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -113,6 +113,8 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId) //The item already exists. d->name = dg.readEntry("extenderItemName", ""); d->title = dg.readEntry("extenderTitle", ""); + setCollapsed(dg.readEntry("isCollapsed", false)); + QString iconName = dg.readEntry("extenderIconName", "utilities-desktop-extra"); if (iconName.isEmpty()) { iconName = "utilities-desktop-extra"; @@ -279,11 +281,7 @@ Extender *ExtenderItem::extender() const bool ExtenderItem::isCollapsed() const { - if (!d->widget) { - return true; - } else { - return !d->widget->isVisible(); - } + return d->collapsed; } void ExtenderItem::setAutoExpireDelay(uint time) @@ -381,6 +379,9 @@ void ExtenderItem::destroy() void ExtenderItem::setCollapsed(bool collapsed) { + config().writeEntry("isCollapsed", collapsed); + d->collapsed = collapsed; + qreal marginWidth = d->bgLeft + d->bgRight + d->dragLeft + d->dragRight; qreal marginHeight = d->bgTop + d->bgBottom + 2 * d->dragTop + 2 * d->dragBottom; @@ -828,6 +829,7 @@ ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *h mouseOver(false), dragStarted(false), destroyActionVisibility(false), + collapsed(false), expirationTimer(0) { dragLeft = dragTop = dragRight = dragBottom = 0; diff --git a/private/extenderitem_p.h b/private/extenderitem_p.h index 2a04ed879..ef533dc17 100644 --- a/private/extenderitem_p.h +++ b/private/extenderitem_p.h @@ -98,6 +98,7 @@ class ExtenderItemPrivate bool mouseOver; bool dragStarted; bool destroyActionVisibility; + bool collapsed; QTimer *expirationTimer;