当前位置: 首页>>代码示例>>C++>>正文


C++ KConfigBase::setLocale方法代码示例

本文整理汇总了C++中KConfigBase::setLocale方法的典型用法代码示例。如果您正苦于以下问题:C++ KConfigBase::setLocale方法的具体用法?C++ KConfigBase::setLocale怎么用?C++ KConfigBase::setLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KConfigBase的用法示例。


在下文中一共展示了KConfigBase::setLocale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readEntry

QString KConfigBase::readEntry(const char *pKey, const QString &aDefault) const
{
    // we need to access _locale instead of the method locale()
    // because calling locale() will create a locale object if it
    // doesn't exist, which requires KConfig, which will create a infinite
    // loop, and nobody likes those.
    if(!bLocaleInitialized && KGlobal::_locale)
    {
        // get around const'ness.
        KConfigBase *that = const_cast< KConfigBase * >(this);
        that->setLocale();
    }

    QString aValue;

    bool expand = false;
    // construct a localized version of the key
    // try the localized key first
    KEntry aEntryData;
    KEntryKey entryKey(mGroup, 0);
    entryKey.c_key = pKey;
    entryKey.bDefault = readDefaults();
    entryKey.bLocal = true;
    aEntryData = lookupData(entryKey);
    if(!aEntryData.mValue.isNull())
    {
        // for GNOME .desktop
        aValue = KStringHandler::from8Bit(aEntryData.mValue.data());
        expand = aEntryData.bExpand;
    }
    else
    {
        entryKey.bLocal = false;
        aEntryData = lookupData(entryKey);
        if(!aEntryData.mValue.isNull())
        {
            aValue = QString::fromUtf8(aEntryData.mValue.data());
            if(aValue.isNull())
            {
                static const QString &emptyString = KGlobal::staticQString("");
                aValue = emptyString;
            }
            expand = aEntryData.bExpand;
        }
        else
        {
            aValue = aDefault;
        }
    }

    // only do dollar expansion if so desired
    if(expand || bExpand)
    {
        // check for environment variables and make necessary translations
        int nDollarPos = aValue.find('$');

        while(nDollarPos != -1 && nDollarPos + 1 < static_cast< int >(aValue.length()))
        {
            // there is at least one $
            if((aValue)[nDollarPos + 1] == '(')
            {
                uint nEndPos = nDollarPos + 1;
                // the next character is no $
                while((nEndPos <= aValue.length()) && (aValue[nEndPos] != ')'))
                    nEndPos++;
                nEndPos++;
                QString cmd = aValue.mid(nDollarPos + 2, nEndPos - nDollarPos - 3);

                QString result;
                FILE *fs = popen(QFile::encodeName(cmd).data(), "r");
                if(fs)
                {
                    {
                        QTextStream ts(fs, IO_ReadOnly);
                        result = ts.read().stripWhiteSpace();
                    }
                    pclose(fs);
                }
                aValue.replace(nDollarPos, nEndPos - nDollarPos, result);
            }
            else if((aValue)[nDollarPos + 1] != '$')
            {
                uint nEndPos = nDollarPos + 1;
                // the next character is no $
                QString aVarName;
                if(aValue[nEndPos] == '{')
                {
                    while((nEndPos <= aValue.length()) && (aValue[nEndPos] != '}'))
                        nEndPos++;
                    nEndPos++;
                    aVarName = aValue.mid(nDollarPos + 2, nEndPos - nDollarPos - 3);
                }
                else
                {
                    while(nEndPos <= aValue.length() && (aValue[nEndPos].isNumber() || aValue[nEndPos].isLetter() || aValue[nEndPos] == '_'))
                        nEndPos++;
                    aVarName = aValue.mid(nDollarPos + 1, nEndPos - nDollarPos - 1);
                }
                const char *pEnv = 0;
                if(!aVarName.isEmpty())
//.........这里部分代码省略.........
开发者ID:serghei,项目名称:kde3-kdelibs,代码行数:101,代码来源:kconfigbase.cpp


注:本文中的KConfigBase::setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。