Ejemplo n.º 1
0
QMap<QString, QString> KConfig::entryMap(const QString &aGroup) const
{
    Q_D(const KConfig);
    QMap<QString, QString> theMap;
    const QByteArray theGroup(aGroup.isEmpty() ? "<default>" : aGroup.toUtf8());

    const KEntryMapConstIterator theEnd = d->entryMap.constEnd();
    KEntryMapConstIterator it = d->entryMap.findEntry(theGroup, 0, 0);
    if (it != theEnd) {
        ++it; // advance past the special group entry marker

        for (; it != theEnd && it.key().mGroup == theGroup; ++it) {
            // leave the default values and deleted entries out
            if (!it->bDeleted && !it.key().bDefault) {
                const QString key = QString::fromUtf8(it.key().mKey.constData());
                // the localized entry should come first, so don't overwrite it
                // with the non-localized entry
                if (!theMap.contains(key)) {
                    if (it->bExpand) {
                        theMap.insert(key, KConfigPrivate::expandString(QString::fromUtf8(it->mValue.constData())));
                    } else {
                        theMap.insert(key, QString::fromUtf8(it->mValue.constData()));
                    }
                }
            }
        }
    }

    return theMap;
}
Ejemplo n.º 2
0
QStringList KConfigPrivate::keyListImpl(const QByteArray &theGroup) const
{
    QStringList keys;

    const KEntryMapConstIterator theEnd = entryMap.constEnd();
    KEntryMapConstIterator it = entryMap.findEntry(theGroup);
    if (it != theEnd) {
        ++it; // advance past the special group entry marker

        QSet<QString> tmp;
        for (; it != theEnd && it.key().mGroup == theGroup; ++it) {
            const KEntryKey &key = it.key();
            if (!key.mKey.isNull() && !it->bDeleted) {
                tmp << QString::fromUtf8(key.mKey);
            }
        }
        keys = tmp.toList();
    }

    return keys;
}
Ejemplo n.º 3
0
static void writeEntries(FILE *pStream, const KEntryMap &entryMap, bool defaultGroup, bool &firstEntry, const QCString &localeString)
{
    // now write out all other groups.
    QCString currentGroup;
    for(KEntryMapConstIterator aIt = entryMap.begin(); aIt != entryMap.end(); ++aIt)
    {
        const KEntryKey &key = aIt.key();

        // Either proces the default group or all others
        if((key.mGroup != "<default>") == defaultGroup)
            continue; // Skip

        // Skip default values and group headers.
        if((key.bDefault) || key.mKey.isEmpty())
            continue; // Skip

        const KEntry &currentEntry = *aIt;

        KEntryMapConstIterator aTestIt = aIt;
        ++aTestIt;
        bool hasDefault = (aTestIt != entryMap.end());
        if(hasDefault)
        {
            const KEntryKey &defaultKey = aTestIt.key();
            if((!defaultKey.bDefault) || (defaultKey.mKey != key.mKey) || (defaultKey.mGroup != key.mGroup) || (defaultKey.bLocal != key.bLocal))
                hasDefault = false;
        }


        if(hasDefault)
        {
            // Entry had a default value
            if((currentEntry.mValue == (*aTestIt).mValue) && (currentEntry.bDeleted == (*aTestIt).bDeleted))
                continue; // Same as default, don't write.
        }
        else
        {
            // Entry had no default value.
            if(currentEntry.bDeleted)
                continue; // Don't write deleted entries if there is no default.
        }

        if(!defaultGroup && (currentGroup != key.mGroup))
        {
            if(!firstEntry)
                fprintf(pStream, "\n");
            currentGroup = key.mGroup;
            fprintf(pStream, "[%s]\n", encodeGroup(currentGroup).data());
        }

        firstEntry = false;
        // it is data for a group
        fputs(encodeKey(key.mKey.data()), pStream); // Key

        if(currentEntry.bNLS)
        {
            fputc('[', pStream);
            fputs(localeString.data(), pStream);
            fputc(']', pStream);
        }

        if(currentEntry.bDeleted)
        {
            fputs("[$d]\n", pStream); // Deleted
        }
        else
        {
            if(currentEntry.bImmutable || currentEntry.bExpand)
            {
                fputc('[', pStream);
                fputc('$', pStream);
                if(currentEntry.bImmutable)
                    fputc('i', pStream);
                if(currentEntry.bExpand)
                    fputc('e', pStream);

                fputc(']', pStream);
            }
            fputc('=', pStream);
            fputs(stringToPrintable(currentEntry.mValue).data(), pStream);
            fputc('\n', pStream);
        }
    } // for loop
}