[PATCH]KConfigGroup::groupList() kind of broken
Andreas Pakulat
apaku at gmx.de
Tue Nov 20 00:38:33 GMT 2007
On 20.11.07 00:56:34, Oswald Buddenhagen wrote:
> On Tue, Nov 20, 2007 at 12:13:01AM +0100, Andreas Pakulat wrote:
> > On 19.11.07 23:58:17, Oswald Buddenhagen wrote:
> > > On Mon, Nov 19, 2007 at 11:36:48PM +0100, Andreas Pakulat wrote:
> > > > I'm not sure wether name() should be changed now and then a new function
> > > > added to KConfigGroup in 4.1... Opinions?
> > > >
> > > good idea, also precludes silent failures.
> >
> > So are you saying we should change name() now to make sure we don't get
> > silent failures later on and introduce a new function for KDE 4.1?
> >
> yes. well, once everything is compiled and some time has passed, one can
> add the new function. it's just going to be 4.1 at that time, quite
> probably.
Ok, while implementing this I've found a new problem :(
KConfigGroup bargrp( &grp, "foo/bar" );
returns "foo/bar" as name, though implementation wise that group is the
same as bargrp here:
KConfigGroup middle(&grp, "foo");
KConfigGroup bargrp(&middle, "bar");
That made the implementation a bit more costly, though I guess we can't
fix this without creating a real parent-child relation ship between
KConfigGroups, instead of just handling group names in a special way.
Updated patch attached, unless I hear screams from anybody I'm going to
commit this tomorrow around this time.
> > If just kdevelop3 would be a bit better at working with kdelibs...
> >
> you mean, like not crashing every 10 minutes or eating 100% cpu? :-P
:)
Actually I just mean being a bit faster at opening and working with
kdelibs, though I didn't try kdelibs for a long time now. About the 100%
cpu, make sure you don't use 3.5.0 (but latest from KDE/3.5/kdevelop)
Andreas
--
Troubled day for virgins over 16 who are beautiful and wealthy and live
in eucalyptus trees.
-------------- next part --------------
Index: tests/kconfigtest.cpp
===================================================================
--- tests/kconfigtest.cpp (Revision 738799)
+++ tests/kconfigtest.cpp (Arbeitskopie)
@@ -65,6 +65,9 @@
#define VARIANTLISTENTRY2 (QVariantList() << POINTENTRY << SIZEENTRY)
#define HOMEPATH QDir::homePath()+"/foo"
#define HOMEPATHESCAPE QDir::homePath()+"/foo/$HOME"
+#define SUBGROUPLIST (QStringList() << "SubGroup1" << "SubGroup2" << "SubGroup")
+#define PARENTGROUPKEYS (QStringList() << "parentgrpstring")
+#define SUBGROUP3KEYS (QStringList() << "sub3string")
void KConfigTest::initTestCase()
{
@@ -701,13 +704,29 @@
{
KConfig sc( "kconfigtest" );
KConfigGroup cg( &sc, "ParentGroup" );
- QVERIFY(cg.readEntry( "parentgrpstring", "") == QString("somevalue") );
+ QCOMPARE(cg.readEntry( "parentgrpstring", ""), QString("somevalue") );
KConfigGroup subcg1( &cg, "SubGroup1");
- QVERIFY(subcg1.readEntry( "somestring", "") == QString("somevalue") );
+ QCOMPARE(subcg1.name(), QString("SubGroup1"));
+ QCOMPARE(subcg1.readEntry( "somestring", ""), QString("somevalue") );
KConfigGroup subcg2( &cg, "SubGroup2");
- QVERIFY(subcg2.readEntry( "substring", "") == QString("somevalue") );
+ QCOMPARE(subcg2.name(), QString("SubGroup2"));
+ QCOMPARE(subcg2.readEntry( "substring", ""), QString("somevalue") );
KConfigGroup subcg3( &cg, "SubGroup/3");
- QVERIFY(subcg3.readEntry( "sub3string", "") == QString("somevalue") );
+ QCOMPARE(subcg3.readEntry( "sub3string", ""), QString("somevalue") );
+ QCOMPARE(subcg3.name(), QString("3"));
+
+ KConfigGroup subcg( &cg, "SubGroup" );
+ KConfigGroup cg_sub3( &subcg, "3" );
+ QCOMPARE(cg_sub3.readEntry("sub3string", ""), subcg3.readEntry("sub3string", ""));
+
+ QCOMPARE(cg.groupList(), SUBGROUPLIST );
+
+ QCOMPARE(subcg3.keyList(), SUBGROUP3KEYS);
+ QCOMPARE(cg.keyList(), PARENTGROUPKEYS);
+
+ QCOMPARE(QStringList(cg.entryMap().keys()), PARENTGROUPKEYS);
+ QCOMPARE(QStringList(subcg3.entryMap().keys()), SUBGROUP3KEYS);
+
KConfigGroup subcg4( &subcg3, "3");
QVERIFY(!subcg4.exists());
}
Index: config/kconfig.cpp
===================================================================
--- config/kconfig.cpp (Revision 738799)
+++ config/kconfig.cpp (Arbeitskopie)
@@ -167,13 +167,16 @@
QStringList KConfigPrivate::groupList(const QByteArray& group) const
{
- QStringList groups;
+ QSet<QString> groups;
foreach (const KEntryKey& key, entryMap.keys())
if (key.mKey.isNull() && key.mGroup.startsWith(group) && key.mGroup != group)
- groups << QString::fromUtf8(key.mGroup);
+ {
+ QString groupname = QString::fromUtf8(key.mGroup.mid(group.length()+1));
+ groups << groupname.left(groupname.indexOf("/"));
+ }
- return groups;
+ return groups.toList();
}
QStringList KConfig::keyList(const QString& aGroup) const
Index: config/kconfiggroup.cpp
===================================================================
--- config/kconfiggroup.cpp (Revision 738799)
+++ config/kconfiggroup.cpp (Arbeitskopie)
@@ -83,13 +83,18 @@
QByteArray fullName() const
{
if (!mParent) {
- if (mName.isEmpty())
- return "<default>";
- return mName;
+ return name();
}
return mParent->fullName(mName);
}
+ QByteArray name() const
+ {
+ if (mName.isEmpty())
+ return "<default>";
+ return mName.mid(mName.lastIndexOf("/")+1);
+ }
+
QByteArray fullName(const QByteArray& aGroup) const
{
return fullName() + '/' + aGroup;
@@ -636,7 +641,7 @@
{
Q_ASSERT_X(isValid(), "KConfigGroup::name", "accessing an invalid group");
- return QString::fromUtf8(d->fullName());
+ return QString::fromUtf8(d->name());
}
bool KConfigGroup::exists() const
More information about the kde-core-devel
mailing list