[PATCH]KConfigGroup::groupList() kind of broken

Oswald Buddenhagen ossi at kde.org
Tue Nov 20 08:36:14 GMT 2007


On Tue, Nov 20, 2007 at 01:38:33AM +0100, Andreas Pakulat wrote:
> Ok, while implementing this I've found a new problem :( 
> 
> KConfigGroup bargrp( &grp, "foo/bar" );
> 
> returns "foo/bar" as name,
>
that's good.

> though implementation wise that group is the same as bargrp here:
> 
> KConfigGroup middle(&grp, "foo");
> KConfigGroup bargrp(&middle, "bar");
> 
that's not good.
it's again the same ... separator quoting. i.e., a full group name in
an ini file is a list with a separator which should be opaque to the
caller.

> 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.
> 
yes, i've been pondering this myself. it's gonna be a bit hard to have
that in 4.0, though. ;)
i think for the moment we just need to forbid the slash in group names.

> Index: tests/kconfigtest.cpp
> ===================================================================
> --- tests/kconfigtest.cpp	(Revision 738799)
> +++ tests/kconfigtest.cpp	(Arbeitskopie)
> @@ -701,13 +704,29 @@
>      KConfigGroup subcg3( &cg, "SubGroup/3");
> -    QVERIFY(subcg3.readEntry( "sub3string", "") == QString("somevalue") );
> +    QCOMPARE(subcg3.readEntry( "sub3string", ""), QString("somevalue") );
> +    QCOMPARE(subcg3.name(), QString("3"));
> +
urgs. that's an expected failure, not a pass. if it is not possible to
express this with qtest, at least add a big fat comment here.

rest of test looks good.

> Index: config/kconfig.cpp
> ===================================================================
> --- config/kconfig.cpp	(Revision 738799)
> +++ config/kconfig.cpp	(Arbeitskopie)
>
still good. :)

> 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());
>  }
>  
ok, so no fullName() after all. fine with me. :=)

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.




More information about the kde-core-devel mailing list