This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Watching for changes in KConfigXT settings

Tags: kdeui, kconfigxt kdeui, kconfigxt kdeui, kconfigxt
(comma "," separated)
B4700011
Registered Member
Posts
16
Karma
0
This is the scenario:

I have an application 'App' which reads/writes some settings (let's call them 'AppSettings') via KConfigXT.

There exists a KCModule 'KCM_App_Config' which also reads/writes 'AppSettings'.

Assuming that both App and KCM_APP_Config are running concurrently, is there a way via KConfigXT or a similar framework for them to "watch" AppSettings for changes?

Please note that the obvious approach of listening for the KCoreConfigSkeleton::configChanged() signal will not work, as App and KCM_App_Config are different processes.

Although I could use a custom DBus signal/slot pair, I suspect there is an out-of-the-box solution which I have been unable to spot. Any suggestions in this regard will be greatly appreciated.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
I would recommend that both use file monitoring to watch the file(s) in question, and reload the configuration whenever it changes.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
B4700011
Registered Member
Posts
16
Karma
0
Thank you for your answer. Indeed, that's what I have done in the end.

For reference, this is how it can be implemented:

Code: Select all
KDirWatch::self()->addFile(KStandardDirs::locate("config",
                                                 AppSettings::self()->config()->name()));
connect(KDirWatch::self(), SIGNAL(created(const QString&)),
        this, SLOT(reconfigure()));

[ reconfigure() is the slot in my application which re-reads the configuration. ]

Curiously, config writes appear to be dealt with by unlinking the config file and creating it anew, so KDirWatch::dirty() is never emitted, and if I connected to KDirWatch::deleted() my reconfigure() slot would be called twice: once on unlink, once on create.

One way or the other, the above seems to work so far.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient