[Panel-devel] [PATCH] Package and PackageStructure cleanup
Paolo Capriotti
p.capriotti at gmail.com
Sun Nov 25 12:01:03 CET 2007
Aaron J. Seigo wrote:
> On Saturday 24 November 2007, Paolo Capriotti wrote:
>> Hi,
>> while working on background selection with ruphy, I've found some
>> oddities in the existing Package code. Here is a cleanup patch that:
>> 1) replaces all const char* with QString in the API;
>
> the reason they are const char*, just as in KConfig, is to communicate that
> these are non-translated, abstract keys to the actual data. what benefit is
> there to having them as QStrings? these are, after all, literals.
A big problem with const char* is that PackageStructure uses pointers as
QHash keys, hence comparison is done by address, and not by value.
So for example pkg.filePath("metadata") will never work, because the
internalized "metadata" literal string in the plasma library is
considered different from the literal in the call place.
At first I was surprised to see the tests pass, but then I noticed that
nasty #include "packages.cpp" :) Since the package structure literals
are internalized in the test itself, they magically match in assertions.
But of course all of that blows up when you try to use package
structures defined in a different library, or simply don't use a literal.
Since QHash does not seem to be parameterizable on the hash function it
uses, the only solutions are:
1) use QString everywhere
2) store keys as QString and convert back and forth to ascii.
I don't think there are real reasons to prefer the latter.
Paolo Capriotti
More information about the Panel-devel
mailing list