[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Idea: SkipDirtyOnIdenticalValues WriteConfigFlag for KConfigBase /
From:       Eduardo Robles Elvira <edulix () gmail ! com>
Date:       2008-05-23 13:00:47
Message-ID: 200805231500.52227.edulix () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hello everybody!

The usual behaviour of KConfigGroup::writeEntry() (which in turns calls to 
KConfigPrivate::putData() ) is to automatically set the dirty flag. It 
doesn't matter if we're overwritting the entry with the same data.

I'm using KConfig to autosave konqueror sessions. Someone [1] has suggested 
that in order to not save power in notebooks, I shouldn't be writting to disk 
the session if it hasn't changed. The idea is to create my KConfig file with 
SkipDirtyOnIdenticalValues set as WriteConfigFlag, and the problem would be 
solved. This way others with similar needs will benefit from this change too 
=)

I attach a proof of concept patch to see what I mean. Of course in no way 
could this be added to KDE 4.1.

Greetings, 
        Eduardo Robles Elvira.
--
[1] See http://bugs.kde.org/show_bug.cgi?id=162498#c2
-- 
"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man." (George Bernard Shaw)

["kconfig-save-power.patch" (text/x-diff)]

Index: kconfig.cpp
===================================================================
--- kconfig.cpp	(revision 811382)
+++ kconfig.cpp	(working copy)
@@ -712,12 +712,15 @@
 void KConfigPrivate::putData( const QByteArray& group, const char* key,
                       const QByteArray& value, KConfigBase::WriteConfigFlags flags, bool expand)
 {
+    bool identicalValues = (value == lookupData(group, key, KEntryMap::SearchDefaults));
+    
     // the KConfig object is dirty now
     // set this before any IO takes place so that if any derivative
     // classes do caching, they won't try and flush the cache out
     // from under us before we read. A race condition is still
     // possible but minimized.
-    if( flags &  KConfigBase::Persistent )
+    if( flags &  KConfigBase::Persistent &&
+        (!(flags &  KConfigBase::SkipDirtyOnIdenticalValues) || identicalValues) )
         setDirty(true);
 
     KEntryMap::EntryOptions options = convertToOptions(flags);
Index: kconfigbase.h
===================================================================
--- kconfigbase.h	(revision 811382)
+++ kconfigbase.h	(working copy)
@@ -56,6 +56,11 @@
         /**<
          * Add the locale tag to the key when writing it.
          */
+        SkipDirtyOnIdenticalValues = 0x08,
+        /**<
+         * Do not save this entry when the new value is identical to the old
+         * value.
+         */
         Normal=Persistent
         /**<
          * Save the entry to the application specific config file without

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic