provide a way for applets to signal that they'd like their config saved out to disk, please.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=755616
This commit is contained in:
Aaron J. Seigo 2008-01-01 22:44:56 +00:00
parent b6030dd8b3
commit e12dbeb000
4 changed files with 49 additions and 2 deletions

View File

@ -581,6 +581,16 @@ class PLASMA_EXPORT Applet : public Widget
*/
void geometryChanged();
/**
* Emitted when an applet has changed values in its configuration
* and wishes for them to be saved at the next save point. As this implies
* disk activity, this signal should be used with care.
*
* @note This does not need to be emitted from saveState by individual
* applets.
*/
void configurationChanged();
public Q_SLOTS:
/**
* Sets whether or not this applet is immutable or not.

View File

@ -473,6 +473,11 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
Corona *c = corona();
if (c) {
connect(applet, SIGNAL(configurationChanged()), corona(), SLOT(scheduleConfigSync()));
}
emit appletAdded(applet);
return applet;
}

View File

@ -28,6 +28,7 @@
#include <QUrl>
#include <QGraphicsView>
#include <QStringList>
#include <QTimer>
#include <KDebug>
#include <KLocale>
@ -45,6 +46,10 @@ using namespace Plasma;
namespace Plasma
{
// constant controling how long between requesting a configuration sync
// and one happening should occur. currently 2 minutes.
const int CONFIG_SYNC_TIMEOUT = 120000;
class Corona::Private
{
public:
@ -64,6 +69,8 @@ public:
void init(Corona* q)
{
configSyncTimer.setSingleShot(true);
connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig()));
QObject::connect(QApplication::desktop(), SIGNAL(resized(int)), q, SLOT(screenResized(int)));
}
@ -72,6 +79,7 @@ public:
QString mimetype;
QString configName;
KSharedConfigPtr config;
QTimer configSyncTimer;
QList<Containment*> containments;
};
@ -151,6 +159,18 @@ void Corona::saveApplets() const
saveApplets(d->configName);
}
void Corona::scheduleConfigSync()
{
//NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT
// after the first time this is called. not much of a heuristic for save points, but
// it should at least compress these activities a bit and provide a way for applet
// authors to ween themselves from the sync() disease. A more interesting/dynamic
// algorithm for determining when to actually sync() to disk might be better, though.
if (!d->configSyncTimer.isActive()) {
d->configSyncTimer.start(CONFIG_SYNC_TIMEOUT);
}
}
void Corona::loadApplets(const QString& configName)
{
clearApplets();
@ -292,8 +312,8 @@ void Corona::loadDefaultSetup()
panel->setLocation(Plasma::LeftEdge);
*/
// in case something goes bad during runtime, let's at least save this to disk right away
config()->sync();
// in case something goes bad during runtime, let's at least save this to disk soonish
scheduleConfigSync();
}
Containment* Corona::containmentForScreen(int screen) const
@ -457,6 +477,11 @@ void Corona::screenResized(int screen)
emit newScreen(screen);
}
void Corona::syncConfig()
{
config()->sync();
}
bool Corona::isImmutable() const
{
return d->kioskImmutable || d->immutable;

View File

@ -114,6 +114,12 @@ public Q_SLOTS:
*/
void saveApplets() const;
/**
* Called when there have been changes made to configuration that should be saved
* to disk at the next convenient moment
*/
void scheduleConfigSync();
/**
* Adds a Containment to the Corona
*
@ -177,6 +183,7 @@ protected:
protected Q_SLOTS:
void containmentDestroyed(QObject*);
void screenResized(int);
void syncConfig();
private:
class Private;