On 03/05/2011 11:32 AM, Andriy Rysin wrote:
There seems to be plenty info on saving/restoring sessions for
applications (i.e. the features in KApplication and KMainWindow
classes) but I'd like to save/restore some information in KDED module
(keyboard layouts to be exact) but only if restore session on login is
set to true (I'd like not to introduce another option in keyboard kcm
but rather reuse system-wide session handing option).
So far the solution I've found is this:
save/restore session in module dtor/ctor checking if in "ksmserverrc"
the "loginMode" parameter is set to "restoreSavedSession".
This is not very nice as I have to read some other module's config and
compare some string values, though I could not find an exposed native
or DBUS API from ksmserver. Also I noticed that at least two plasma
applets in kde-workspace do exactly that.
So I've ended up doing something like the code below, but I was
wandering if we should do this at KDEDModule level, i.e.
KDEDModule::saveSession()
KDEDModule::restoreSession()
which would be overridden if necessary and called if session is to be
restored so that kded daemons can easily save/restore state, and
something like
KDEDModule::getSessionStoreDir()
to return base directory to store kded module session info so that
there's some standard location for this and modules don't have to invent
things.
Regards,
Andriy
bool LayoutMemoryPersister::save(const QString& moduleName)
{
KConfigGroup c(KSharedConfig::openConfig("ksmserverrc",
KConfig::NoGlobals), "General");
kDebug() << "loginMode:" << c.readEntry("loginMode");
QString loginMode = c.readEntry("loginMode");
if ( loginMode != "default" && loginMode != "restoreSavedSession" )
{ // we don't know how to restore saved session - only previous one
QString relPath = moduleName + "/keyboard/layout_memory.xml";
QFile file(KStandardDirs::locateLocal("data", relPath));
return saveToFile(file);
}
return false;
}
bool LayoutMemoryPersister::restore(const QString& moduleName)
{
KConfigGroup c(KSharedConfig::openConfig("ksmserverrc",
KConfig::NoGlobals), "General");
kDebug() << "loginMode:" << c.readEntry("loginMode");
QString loginMode = c.readEntry("loginMode");
if ( loginMode != "default" && loginMode != "restoreSavedSession" )
{ // we don't know how to restore saved session - only previous one
QString relPath = moduleName + "/keyboard/layout_memory.xml";
QFile file(KStandardDirs::locateLocal("data", relPath));
return restoreFromFile(file);
}
return false;
}