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
This commit is contained in:
Rob Scheepmaker 2009-01-16 18:49:54 +00:00
parent 8a0159e10e
commit bfb771ddd8
4 changed files with 42 additions and 43 deletions

View File

@ -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();
}

View File

@ -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<QPair<int, QString> > 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<int, QString> 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;
}
}
}
}

View File

@ -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;

View File

@ -98,6 +98,7 @@ class ExtenderItemPrivate
bool mouseOver;
bool dragStarted;
bool destroyActionVisibility;
bool collapsed;
QTimer *expirationTimer;