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

List:       kde-commits
Subject:    [kdelibs/frameworks] /: Make some KConfig classes return a bool when saving
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2013-06-25 17:12:27
Message-ID: E1UrWn5-0007tw-IV () scm ! kde ! org
[Download RAW message or body]

Git commit 131ea56cdbe336ab5f9d454db7c7877f88a06aab by Albert Astals Cid.
Committed on 25/06/2013 at 17:11.
Pushed by aacid into branch 'frameworks'.

Make some KConfig classes return a bool when saving

Acked by Kevin
REVIEW: 109667

M  +3    -0    KDE5PORTING.html
M  +4    -2    tier2/kconfig/autotests/kconfig_compiler/test_signal.cpp.ref
M  +1    -1    tier2/kconfig/autotests/kconfig_compiler/test_signal.h.ref
M  +10   -9    tier2/kconfig/autotests/kconfigguitest.cpp
M  +55   -36   tier2/kconfig/autotests/kconfigtest.cpp
M  +1    -0    tier2/kconfig/autotests/kconfigtest.h
M  +1    -1    tier2/kconfig/autotests/ksharedconfigtest.cpp
M  +5    -9    tier2/kconfig/src/core/kconfig.cpp
M  +1    -1    tier2/kconfig/src/core/kconfig.h
M  +1    -1    tier2/kconfig/src/core/kconfigbase.h
M  +4    -2    tier2/kconfig/src/core/kconfiggroup.cpp
M  +1    -1    tier2/kconfig/src/core/kconfiggroup.h
M  +9    -4    tier2/kconfig/src/core/kcoreconfigskeleton.cpp
M  +2    -2    tier2/kconfig/src/core/kcoreconfigskeleton.h
M  +5    -3    tier2/kconfig/src/kconfig_compiler/kconfig_compiler.cpp

http://commits.kde.org/kdelibs/131ea56cdbe336ab5f9d454db7c7877f88a06aab

diff --git a/KDE5PORTING.html b/KDE5PORTING.html
index ba67bdc..11a7955 100644
--- a/KDE5PORTING.html
+++ b/KDE5PORTING.html
@@ -193,6 +193,9 @@ A script is available in kdesdk/kde-dev-scripts/kf5/convert-kstandarddirs.pl to
 </li>
 <li>KConfig and KDesktopFile have been ported to QStandardPaths. This changes the "const char* \
resourceType" in the API into QStandardPaths::StandardLocation, and means that modifying the "config" \
resource before using KConfig has no effect on KConfig anymore.  </li>
+<li>KConfigBase::sync now returns a bool</li>
+<li>KCoreConfigSkeleton::writeConfig now returns a bool</li>
+<li>KCoreConfigSkeleton::usrWriteConfig now returns a bool</li>
 <li>KTemporaryFile is deprecated, port to QTemporaryFile instead, see KTemporaryFile API documentation \
for details.</li>  <li>KTempDir is deprecated, port to QTemporaryDir instead, see KTempDir API \
documentation for details.</li>  <li>KToolInvocation::invokeHelp is now KHelpClient::invokeHelp, in the \
                kwidgets framework.</li>
diff --git a/tier2/kconfig/autotests/kconfig_compiler/test_signal.cpp.ref \
b/tier2/kconfig/autotests/kconfig_compiler/test_signal.cpp.ref index fc04701..1dad37b 100644
--- a/tier2/kconfig/autotests/kconfig_compiler/test_signal.cpp.ref
+++ b/tier2/kconfig/autotests/kconfig_compiler/test_signal.cpp.ref
@@ -54,9 +54,10 @@ TestSignal::~TestSignal()
   s_globalTestSignal()->q = 0;
 }
 
-void TestSignal::usrWriteConfig()
+bool TestSignal::usrWriteConfig()
 {
-  KConfigSkeleton::usrWriteConfig();
+  const bool res = KConfigSkeleton::usrWriteConfig();
+  if (!res) return false;
 
   if ( mSettingsChanged & signalEmoticonSettingsChanged ) 
     emit emoticonSettingsChanged();
@@ -65,6 +66,7 @@ void TestSignal::usrWriteConfig()
     emit styleChanged(mStylePath, mStyleCSSVariant);
 
   mSettingsChanged = 0;
+  return true;
 }
 
 #include "test_signal.moc"
diff --git a/tier2/kconfig/autotests/kconfig_compiler/test_signal.h.ref \
b/tier2/kconfig/autotests/kconfig_compiler/test_signal.h.ref index f43f7dd..1c0d443 100644
--- a/tier2/kconfig/autotests/kconfig_compiler/test_signal.h.ref
+++ b/tier2/kconfig/autotests/kconfig_compiler/test_signal.h.ref
@@ -135,7 +135,7 @@ class TestSignal : public KConfigSkeleton
     TestSignal();
     friend class TestSignalHelper;
 
-    virtual void usrWriteConfig();
+    virtual bool usrWriteConfig();
 
     // Appearance
     QString mEmoticonTheme;
diff --git a/tier2/kconfig/autotests/kconfigguitest.cpp b/tier2/kconfig/autotests/kconfigguitest.cpp
index e6b4c17..e28701e 100644
--- a/tier2/kconfig/autotests/kconfigguitest.cpp
+++ b/tier2/kconfig/autotests/kconfigguitest.cpp
@@ -47,14 +47,14 @@ void KConfigTest::initTestCase()
   cg.writeEntry( "colorEntry3", (QList<int>() << 234 << 234 << 127));
   cg.writeEntry( "colorEntry4",  (QList<int>() << 235 << 235 << 100 << 125));
   cg.writeEntry( "fontEntry", FONTENTRY );
-  sc.sync();
+  QVERIFY(sc.sync());
 
   KConfig sc1("kdebugrc");
   KConfigGroup sg0(&sc1, "0");
   sg0.writeEntry("AbortFatal", false);
   sg0.writeEntry("WarnOutput", 0);
   sg0.writeEntry("FatalOutput", 0);
-  sc1.sync();
+  QVERIFY(sc1.sync());
 }
 
 void KConfigTest::cleanupTestCase()
@@ -98,47 +98,48 @@ void KConfigTest::testInvalid()
   // 1 element list
   list << 1;
   sc3.writeEntry( QString("badList"), list);
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() );
 
   // 2 element list
   list << 2;
   sc3.writeEntry( "badList", list);
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() );
 
   // 3 element list
   list << 303;
   sc3.writeEntry( "badList", list);
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() ); // out of bounds
 
   // 4 element list
   list << 4;
   sc3.writeEntry( "badList", list );
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() ); // out of bounds
 
   list[2] = -3;
-  sc3.writeEntry( "badList", list ); sc.sync();
+  sc3.writeEntry( "badList", list );
+  QVERIFY(sc.sync());
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() ); // out of bounds
 
   // 5 element list
   list[2] = 3;
   list << 5;
   sc3.writeEntry( "badList", list);
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() );
 
   // 6 element list
   list << 6;
   sc3.writeEntry( "badList", list);
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY( sc3.readEntry( "badList", QColor() ) == QColor() );
 }
diff --git a/tier2/kconfig/autotests/kconfigtest.cpp b/tier2/kconfig/autotests/kconfigtest.cpp
index 00ffc2a..7b03ade 100644
--- a/tier2/kconfig/autotests/kconfigtest.cpp
+++ b/tier2/kconfig/autotests/kconfigtest.cpp
@@ -174,7 +174,7 @@ void KConfigTest::initTestCase()
   KConfigGroup cg3(&cg, "SubGroup/3");
   cg3.writeEntry( "sub3string", "somevalue" );
 
-  sc.sync();
+  QVERIFY(sc.sync());
 
   QVERIFY(QFile::exists(kdehome + "/kconfigtestdir/kconfigtest"));
   QVERIFY(QFile::exists(kdehome + "/kconfigtestdir/kdeglobals"));
@@ -184,7 +184,7 @@ void KConfigTest::initTestCase()
   sg0.writeEntry("AbortFatal", false);
   sg0.writeEntry("WarnOutput", 0);
   sg0.writeEntry("FatalOutput", 0);
-  sc1.sync();
+  QVERIFY(sc1.sync());
 
   //Setup stuff to test KConfig::addConfigSources()
   KConfig devcfg("specificrc");
@@ -193,14 +193,14 @@ void KConfigTest::initTestCase()
   KConfigGroup devandbasegrp(&devcfg, "Shared Group");
   devandbasegrp.writeEntry("SomeSharedEntry", "DevValue");
   devandbasegrp.writeEntry("SomeSpecificOnlyEntry", "DevValue");
-  devcfg.sync();
+  QVERIFY(devcfg.sync());
   KConfig basecfg("baserc");
   KConfigGroup basegrp(&basecfg, "Base Only Group");
   basegrp.writeEntry("ExistingEntry", "BaseValue");
   KConfigGroup baseanddevgrp(&basecfg, "Shared Group");
   baseanddevgrp.writeEntry("SomeSharedEntry", "BaseValue");
   baseanddevgrp.writeEntry("SomeBaseOnlyEntry", "BaseValue");
-  basecfg.sync();
+  QVERIFY(basecfg.sync());
 
   KConfig gecfg("groupescapetest", KConfig::SimpleConfig);
   cg = KConfigGroup(&gecfg, DOLLARGROUP);
@@ -257,7 +257,7 @@ void KConfigTest::revertEntries()
   cg.revertToDefault( "stringEntry3" );
   cg.revertToDefault( "stringEntry4" );
   cg.revertToDefault( "stringEntry5" );
-  sc.sync();
+  QVERIFY(sc.sync());
 }
 
 void KConfigTest::testRevertAllEntries()
@@ -346,12 +346,12 @@ void KConfigTest::testDefaults()
 
     KConfigGroup group = defaults.group("any group");
     group.writeEntry("entry1", Default);
-    group.sync();
+    QVERIFY(group.sync());
 
     group = config.group("any group");
     group.writeEntry("entry1", Value1);
     group.writeEntry("entry2", Value2);
-    group.sync();
+    QVERIFY(group.sync());
 
     config.addConfigSources(QStringList() << \
QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + '/' + defaultsFile);  
@@ -379,14 +379,14 @@ void KConfigTest::testLocale()
     group.writeEntry("stringEntry1", Untranslated);
     config.setLocale("fr");
     group.writeEntry("stringEntry1", Translated, KConfig::Localized|KConfig::Persistent);
-    config.sync();
+    QVERIFY(config.sync());
 
     QCOMPARE(group.readEntry("stringEntry1", QString()), Translated);
     QCOMPARE(group.readEntryUntranslated("stringEntry1"), Untranslated);
 
     config.setLocale("C"); // strings written in the "C" locale are written as nonlocalized
     group.writeEntry("stringEntry1", Untranslated, KConfig::Localized|KConfig::Persistent);
-    config.sync();
+    QVERIFY(config.sync());
 
     QCOMPARE(group.readEntry("stringEntry1", QString()), Untranslated);
 }
@@ -398,7 +398,7 @@ void KConfigTest::testEncoding()
     KConfig c( "kconfigtestencodings" );
     KConfigGroup cg(&c, groupstr);
     cg.writeEntry("key", "value");
-    c.sync();
+    QVERIFY(c.sync());
 
     QList<QByteArray> lines = readLines("kconfigtestencodings");
     QCOMPARE(lines.count(), 2);
@@ -502,7 +502,7 @@ void KConfigTest::testPersistenceOfExpandFlagForPath()
   KConfig sc2( "kconfigtest" );
   KConfigGroup sc3(&sc2, "Path Type");
   sc3.writeEntry( "dummy", "dummy" );
-  sc2.sync();
+  QVERIFY(sc2.sync());
   }
 
   // 2nd step: Call testPath() again. Rewriting the config must not break
@@ -684,7 +684,7 @@ void KConfigTest::testDeleteEntry()
     group.deleteEntry("DelKey");
     QCOMPARE( group.readEntry("DelKey", QString("Fietsbel")), QString("Fietsbel") );
 
-    group.sync();
+    QVERIFY(group.sync());
     Q_ASSERT(!readLines(configFile).contains("DelKey=ToBeDeleted\n"));
     QCOMPARE( group.readEntry("DelKey", QString("still deleted")), QString("still deleted") );
 }
@@ -724,7 +724,7 @@ void KConfigTest::testDelete()
   QVERIFY( !sc.entryMap("Hello").isEmpty() ); //not deleted group
   QVERIFY( sc.entryMap("FooBar").isEmpty() ); //inexistant group
 
-  cg.sync();
+  QVERIFY(cg.sync());
   // Check what happens on disk
   const QList<QByteArray> lines = readLines();
   //qDebug() << lines;
@@ -740,7 +740,7 @@ void KConfigTest::testDelete()
   cg = cf.group("Portable Devices");
   cg.writeEntry("devices|manual|(null)", "whatever");
   cg.writeEntry("devices|manual|/mnt/ipod", "/mnt/ipod");
-  cf.sync();
+  QVERIFY(cf.sync());
 
   int count=0;
   Q_FOREACH(const QByteArray& item, readLines())
@@ -748,7 +748,7 @@ void KConfigTest::testDelete()
           count++;
   QCOMPARE(count, 2);
   cg.deleteEntry("devices|manual|/mnt/ipod");
-  cf.sync();
+  QVERIFY(cf.sync());
   Q_FOREACH(const QByteArray& item, readLines())
       QVERIFY(!item.contains("ipod"));
 }
@@ -762,7 +762,7 @@ void KConfigTest::testDefaultGroup()
     defaultGroup.writeEntry("TestKey", "defaultGroup");
     QVERIFY(defaultGroup.exists());
     QCOMPARE(defaultGroup.readEntry("TestKey", QString()), QString("defaultGroup"));
-    sc.sync();
+    QVERIFY(sc.sync());
 
     {
         // Test reading it
@@ -791,7 +791,7 @@ void KConfigTest::testDefaultGroup()
     }
 
     defaultGroup.deleteGroup();
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Test if deleteGroup worked
     lines = readLines();
@@ -807,7 +807,7 @@ void KConfigTest::testEmptyGroup()
     emptyGroup.writeEntry("TestKey", "emptyGroup");
     QVERIFY(emptyGroup.exists());
     QCOMPARE(emptyGroup.readEntry("TestKey", QString()), QString("emptyGroup"));
-    sc.sync();
+    QVERIFY(sc.sync());
 
     {
         // Test reading it
@@ -835,7 +835,7 @@ void KConfigTest::testEmptyGroup()
         QVERIFY(!group.isEmpty() && group != "<default>");
     }
     emptyGroup.deleteGroup();
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Test if deleteGroup worked
     lines = readLines();
@@ -863,7 +863,7 @@ void KConfigTest::testMerge()
                 << "entry[es]=Spanish" << endl
                 << "entry[de]=German" << endl;
     }
-    config.sync();
+    QVERIFY(config.sync());
 
     {
         QList<QByteArray> lines;
@@ -932,7 +932,7 @@ void KConfigTest::testOptionOrder()
     QCOMPARE(cg3.readEntry("entry2",""), QString("unlocalized"));
     QVERIFY(!cg3.isEntryImmutable("entry2"));
     cg3.writeEntry("entry2","modified");
-    config.sync();
+    QVERIFY(config.sync());
 
     {
         QList<QByteArray> lines;
@@ -1030,7 +1030,7 @@ void KConfigTest::testSubGroup()
       QVERIFY(!group.contains("SubGroup"));
     }
 
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Check that the empty groups are not written out.
     const QList<QByteArray> lines = readLines();
@@ -1063,7 +1063,7 @@ void KConfigTest::testAddConfigSources()
     KConfigGroup newgrp(&cf, "New Group");
     newgrp.writeEntry("New Entry", "SomeValue");
 
-    cf.sync();
+    QVERIFY(cf.sync());
 
     KConfig plaincfg("specificrc");
 
@@ -1100,7 +1100,7 @@ void KConfigTest::testConfigCopyToSync()
     // Prepare source file
     KConfigGroup group(&cf1, "CopyToTest");
     group.writeEntry("Type", "Test");
-    cf1.sync();
+    QVERIFY(cf1.sync());
 
     // Copy to "destination"
     const QString destination = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + \
"/kconfigcopytotest"; @@ -1114,7 +1114,7 @@ void KConfigTest::testConfigCopyToSync()
     QString testVal = group2.readEntry("Type");
     QCOMPARE(testVal, QString("Test"));
     // should write to disk the copied data from group
-    cf2.sync();
+    QVERIFY(cf2.sync());
     QVERIFY(QFile::exists(destination));
 }
 
@@ -1125,7 +1125,7 @@ void KConfigTest::testConfigCopyTo()
         // Prepare source file
         KConfigGroup group(&cf1, "CopyToTest");
         group.writeEntry("Type", "Test");
-        cf1.sync();
+        QVERIFY(cf1.sync());
     }
 
     {
@@ -1137,7 +1137,7 @@ void KConfigTest::testConfigCopyTo()
         KConfigGroup group2(&cf2, "CopyToTest");
         QString testVal = group2.readEntry("Type");
         QCOMPARE(testVal, QString("Test"));
-        cf2.sync();
+        QVERIFY(cf2.sync());
         QVERIFY(QFile::exists(destination));
     }
 
@@ -1196,7 +1196,7 @@ void KConfigTest::testWriteOnSync()
     // Should not rewrite the global config file.
     KConfigGroup cgLocal(&sc, "Locals");
     cgLocal.writeEntry("someLocalString", "whatever");
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Verify that the timestamp of global config file didn't change.
     newStamp = QFileInfo(globFile).lastModified();
@@ -1212,13 +1212,32 @@ void KConfigTest::testWriteOnSync()
     KConfigGroup cgGlobal(&sc, "Globals");
     cgGlobal.writeEntry("someGlobalString", "whatever",
                         KConfig::Persistent|KConfig::Global);
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Verify that the timestamp of local config file didn't change.
     newStamp = QFileInfo(locFile).lastModified();
     QCOMPARE(newStamp, oldStamp);
 }
 
+void KConfigTest::testFailOnReadOnlyFileSync()
+{
+    KConfig sc("kconfigfailonreadonlytest");
+    KConfigGroup cgLocal(&sc, "Locals");
+
+    cgLocal.writeEntry("someLocalString", "whatever");
+    QVERIFY(cgLocal.sync());
+
+    QFile f(m_xdgConfigHome + "/" + sc.name());
+    QVERIFY(f.exists());
+    QVERIFY(f.setPermissions(QFileDevice::ReadOwner));
+
+    cgLocal.writeEntry("someLocalString", "whatever2");
+    QVERIFY(!cgLocal.sync());
+
+    QVERIFY(f.setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner));
+    QVERIFY(f.remove());
+}
+
 void KConfigTest::testDirtyOnEqual()
 {
     QDateTime oldStamp, newStamp;
@@ -1227,7 +1246,7 @@ void KConfigTest::testDirtyOnEqual()
     // Initialize value
     KConfigGroup cgLocal(&sc, "random");
     cgLocal.writeEntry("theKey", "whatever");
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Age the timestamp of local config file a few sec, and collect it.
     QString locFile = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/kconfigtest";
@@ -1237,7 +1256,7 @@ void KConfigTest::testDirtyOnEqual()
     // Write exactly the same again
     cgLocal.writeEntry("theKey", "whatever");
     // This should be a no-op
-    sc.sync();
+    QVERIFY(sc.sync());
 
     // Verify that the timestamp of local config file didn't change.
     newStamp = QFileInfo(locFile).lastModified();
@@ -1270,7 +1289,7 @@ void KConfigTest::testCreateDir()
     QVERIFY(!QDir().exists(subdir));
     KDesktopFile desktopFile(file);
     desktopFile.desktopGroup().writeEntry("key", "value");
-    desktopFile.sync();
+    QVERIFY(desktopFile.sync());
     QVERIFY(QFile::exists(file));
 
     // Cleanup
@@ -1383,7 +1402,7 @@ void KConfigTest::testDeleteWhenLocalized()
     // Delete a value. Once with localized, once with Normal
     cg.deleteEntry("foostring", KConfigBase::Persistent | KConfigBase::Localized);
     cg.deleteEntry("foobool");
-    config.sync();
+    QVERIFY(config.sync());
 
     // The value is now gone. The others are still there. Everything correct
     // here.
@@ -1431,7 +1450,7 @@ void KConfigTest::testDeleteWhenLocalized()
 
     // Now test the deletion of a group.
     cg.deleteGroup();
-    config.sync();
+    QVERIFY(config.sync());
 
     // Current state: [ca] and [de] entries left... oops.
     //qDebug() << readLinesFrom(file);
@@ -1486,7 +1505,7 @@ void KConfigTest::testKdeGlobals()
         KConfig glob("kdeglobals");
         KConfigGroup general(&glob, "General");
         general.writeEntry("testKG", "1");
-        glob.sync();
+        QVERIFY(glob.sync());
     }
 
     KConfig globRead("kdeglobals");
@@ -1503,7 +1522,7 @@ void KConfigTest::testKdeGlobals()
         KConfig glob("kdeglobals", KConfig::NoGlobals);
         KConfigGroup general(&glob, "General");
         general.writeEntry("testKG", "2");
-        glob.sync();
+        QVERIFY(glob.sync());
     }
     globRead.reparseConfiguration();
     QCOMPARE(general.readEntry("testKG"), QString("2"));
diff --git a/tier2/kconfig/autotests/kconfigtest.h b/tier2/kconfig/autotests/kconfigtest.h
index 17a5294..69a2719 100644
--- a/tier2/kconfig/autotests/kconfigtest.h
+++ b/tier2/kconfig/autotests/kconfigtest.h
@@ -65,6 +65,7 @@ private Q_SLOTS:
     void testSubGroup();
     void testAddConfigSources();
     void testWriteOnSync();
+    void testFailOnReadOnlyFileSync();
     void testDirtyOnEqual();
     void testDirtyOnEqualOverdo();
     void testCreateDir();
diff --git a/tier2/kconfig/autotests/ksharedconfigtest.cpp \
b/tier2/kconfig/autotests/ksharedconfigtest.cpp index 2bb612f..7b23f89 100644
--- a/tier2/kconfig/autotests/ksharedconfigtest.cpp
+++ b/tier2/kconfig/autotests/ksharedconfigtest.cpp
@@ -70,7 +70,7 @@ void KSharedConfigTest::testReadWriteSync()
         cg.writeEntry("NumKey", value);
     }
     QVERIFY(!QFile::exists(m_path));
-    KSharedConfig::openConfig()->sync();
+    QVERIFY(KSharedConfig::openConfig()->sync());
     QVERIFY(QFile::exists(m_path));
     {
         KConfigGroup cg(KSharedConfig::openConfig(), "KSharedConfigTest");
diff --git a/tier2/kconfig/src/core/kconfig.cpp b/tier2/kconfig/src/core/kconfig.cpp
index d26f941..f849053 100644
--- a/tier2/kconfig/src/core/kconfig.cpp
+++ b/tier2/kconfig/src/core/kconfig.cpp
@@ -392,14 +392,13 @@ QMap<QString,QString> KConfig::entryMap(const QString& aGroup) const
     return theMap;
 }
 
-// TODO KDE5: return a bool value
-void KConfig::sync()
+bool KConfig::sync()
 {
     Q_D(KConfig);
 
     if (isImmutable() || name().isEmpty()) {
         // can't write to an immutable or anonymous file.
-        return;
+        return false;
     }
 
     if (d->bDirty && d->mBackend) {
@@ -411,7 +410,7 @@ void KConfig::sync()
         // lock the local file
         if (d->configState == ReadWrite && !d->lockLocal()) {
             qWarning() << "couldn't lock local file";
-            return;
+            return false;
         }
 
         // Rewrite global/local config only if there is a dirty entry in it.
@@ -438,12 +437,10 @@ void KConfig::sync()
             if (d->configState == ReadWrite && !tmp->lock()) {
                 qWarning() << "couldn't lock global file";
                 d->bDirty = true;
-                return;
+                return false;
             }
             if (!tmp->writeConfig(utf8Locale, d->entryMap, KConfigBackend::WriteGlobal)) {
                 d->bDirty = true;
-                // TODO KDE5: return false? (to tell the app that writing wasn't possible, e.g.
-                // config file is immutable or disk full)
             }
             if (tmp->isLocked()) {
                 tmp->unlock();
@@ -453,14 +450,13 @@ void KConfig::sync()
         if (writeLocals) {
             if (!d->mBackend->writeConfig(utf8Locale, d->entryMap, KConfigBackend::WriteOptions())) {
                 d->bDirty = true;
-                // TODO KDE5: return false? (to tell the app that writing wasn't possible, e.g.
-                // config file is immutable or disk full)
             }
         }
         if (d->mBackend->isLocked()) {
             d->mBackend->unlock();
         }
     }
+    return !d->bDirty;
 }
 
 void KConfig::markAsClean()
diff --git a/tier2/kconfig/src/core/kconfig.h b/tier2/kconfig/src/core/kconfig.h
index 597330f..ca09320 100644
--- a/tier2/kconfig/src/core/kconfig.h
+++ b/tier2/kconfig/src/core/kconfig.h
@@ -159,7 +159,7 @@ public:
     QString name() const;
 
     /// @reimp
-    void sync();
+    Q_DECL_OVERRIDE bool sync();
 
     /// @reimp
     void markAsClean();
diff --git a/tier2/kconfig/src/core/kconfigbase.h b/tier2/kconfig/src/core/kconfigbase.h
index ce190f3..782ff4b 100644
--- a/tier2/kconfig/src/core/kconfigbase.h
+++ b/tier2/kconfig/src/core/kconfigbase.h
@@ -119,7 +119,7 @@ public:
      * not overwritten. Note however, that this object is @em not automatically
      * updated with those changes.
      */
-    virtual void sync() = 0;
+    virtual bool sync() = 0;
 
     /**
      * Reset the dirty flags of all entries in the entry map, so the
diff --git a/tier2/kconfig/src/core/kconfiggroup.cpp b/tier2/kconfig/src/core/kconfiggroup.cpp
index 53cac13..79f3b86 100644
--- a/tier2/kconfig/src/core/kconfiggroup.cpp
+++ b/tier2/kconfig/src/core/kconfiggroup.cpp
@@ -589,12 +589,14 @@ bool KConfigGroup::exists() const
     return config()->hasGroup( d->fullName() );
 }
 
-void KConfigGroup::sync()
+bool KConfigGroup::sync()
 {
     Q_ASSERT_X(isValid(), "KConfigGroup::sync", "accessing an invalid group");
 
     if (!d->bConst)
-        config()->sync();
+        return config()->sync();
+
+    return false;
 }
 
 QMap<QString, QString> KConfigGroup::entryMap() const
diff --git a/tier2/kconfig/src/core/kconfiggroup.h b/tier2/kconfig/src/core/kconfiggroup.h
index ff63afa..aa661ec 100644
--- a/tier2/kconfig/src/core/kconfiggroup.h
+++ b/tier2/kconfig/src/core/kconfiggroup.h
@@ -126,7 +126,7 @@ public:
      *
      * Syncs the parent config.
      */
-    void sync();
+    Q_DECL_OVERRIDE bool sync();
 
     /// @reimp
     void markAsClean();
diff --git a/tier2/kconfig/src/core/kcoreconfigskeleton.cpp \
b/tier2/kconfig/src/core/kcoreconfigskeleton.cpp index c0ad044..1852d08 100644
--- a/tier2/kconfig/src/core/kcoreconfigskeleton.cpp
+++ b/tier2/kconfig/src/core/kcoreconfigskeleton.cpp
@@ -1072,7 +1072,7 @@ void KCoreConfigSkeleton::readConfig()
   usrReadConfig();
 }
 
-void KCoreConfigSkeleton::writeConfig()
+bool KCoreConfigSkeleton::writeConfig()
 {
     //kDebug(kCoreConfigSkeletionDebugArea());
   KConfigSkeletonItem::List::ConstIterator it;
@@ -1080,13 +1080,17 @@ void KCoreConfigSkeleton::writeConfig()
   {
     (*it)->writeConfig( d->mConfig.data() );
   }
-  usrWriteConfig();
+  if (!usrWriteConfig())
+    return false;
 
-  d->mConfig->sync();
+  if (!d->mConfig->sync())
+    return false;
 
   readConfig();
 
   Q_EMIT configChanged();
+
+  return true;
 }
 
 bool KCoreConfigSkeleton::usrUseDefaults(bool)
@@ -1102,8 +1106,9 @@ void KCoreConfigSkeleton::usrReadConfig()
 {
 }
 
-void KCoreConfigSkeleton::usrWriteConfig()
+bool KCoreConfigSkeleton::usrWriteConfig()
 {
+  return true;
 }
 
 void KCoreConfigSkeleton::addItem( KConfigSkeletonItem *item, const QString &name )
diff --git a/tier2/kconfig/src/core/kcoreconfigskeleton.h b/tier2/kconfig/src/core/kcoreconfigskeleton.h
index 3e4971b..75f6fa2 100644
--- a/tier2/kconfig/src/core/kcoreconfigskeleton.h
+++ b/tier2/kconfig/src/core/kcoreconfigskeleton.h
@@ -1357,7 +1357,7 @@ public Q_SLOTS:
    * If you need more fine-grained control of storing the settings from
    * the registered items you can override writeConfig() in a derived class.
    */
-  virtual void writeConfig();
+  virtual bool writeConfig();
 
 Q_SIGNALS:
   /**
@@ -1395,7 +1395,7 @@ protected:
    * Override in derived classes to write special config values.
    * Called from @ref writeConfig()
    */
-  virtual void usrWriteConfig();
+  virtual bool usrWriteConfig();
 
 private:
   class Private;
diff --git a/tier2/kconfig/src/kconfig_compiler/kconfig_compiler.cpp \
b/tier2/kconfig/src/kconfig_compiler/kconfig_compiler.cpp index 47963a5..f37a7e9 100644
--- a/tier2/kconfig/src/kconfig_compiler/kconfig_compiler.cpp
+++ b/tier2/kconfig/src/kconfig_compiler/kconfig_compiler.cpp
@@ -1842,7 +1842,7 @@ int main( int argc, char **argv )
   }
 
   if ( hasSignals ) {
-    h << "    virtual void usrWriteConfig();" << endl;
+    h << "    virtual bool usrWriteConfig();" << endl;
   }
 
   // Member variables
@@ -2289,9 +2289,10 @@ int main( int argc, char **argv )
   cpp << "}" << endl << endl;
 
   if ( hasSignals ) {
-    cpp << "void " << cfg.className << "::" << "usrWriteConfig()" << endl;
+    cpp << "bool " << cfg.className << "::" << "usrWriteConfig()" << endl;
     cpp << "{" << endl;
-    cpp << "  " << cfg.inherits << "::usrWriteConfig();" << endl << endl;
+    cpp << "  const bool res = " << cfg.inherits << "::usrWriteConfig();" << endl;
+    cpp << "  if (!res) return false;" << endl << endl;
     foreach(const Signal &signal, signalList) {
       cpp << "  if ( " << varPath("settingsChanged", cfg) << " & " << signalEnumName(signal.name) << " ) \
" << endl;  cpp << "    emit " << signal.name << "(";
@@ -2317,6 +2318,7 @@ int main( int argc, char **argv )
       cpp << ");" << endl << endl;
     }
     cpp << "  " << varPath("settingsChanged", cfg) << " = 0;" << endl;
+    cpp << "  return true;" << endl;
     cpp << "}" << endl;
   }
 


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

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