From e12dbeb00001141aba10d92283993a661e2f2d5d Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 1 Jan 2008 22:44:56 +0000 Subject: [PATCH] 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 --- applet.h | 10 ++++++++++ containment.cpp | 5 +++++ corona.cpp | 29 +++++++++++++++++++++++++++-- corona.h | 7 +++++++ 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/applet.h b/applet.h index ae19f1f4d..2a5a2f0f9 100644 --- a/applet.h +++ b/applet.h @@ -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. diff --git a/containment.cpp b/containment.cpp index 525fcd4d8..2708cebbe 100644 --- a/containment.cpp +++ b/containment.cpp @@ -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; } diff --git a/corona.cpp b/corona.cpp index c0f188a75..7b8d5afef 100644 --- a/corona.cpp +++ b/corona.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -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 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; diff --git a/corona.h b/corona.h index b952af5e6..a783207a6 100644 --- a/corona.h +++ b/corona.h @@ -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;