示例#1
0
EngineError KadmosDialog::findClassifiers()
{
    findClassifierPath();

    KLocale *locale = KGlobal::locale();
    QStringList allCountries = locale->allLanguagesTwoAlpha ();
    for ( QStringList::Iterator it = allCountries.begin();
          it != allCountries.end(); ++it )
    {
        m_longCountry2short[locale->twoAlphaToCountryName(*it)] = *it;
    }
    m_longCountry2short[i18n("European Countries")] = "eu";
    m_longCountry2short[ CNTRY_CZ ] = "cz";
    m_longCountry2short[ CNTRY_GB ] = "us";

    QStringList lst;

    /* custom Path */
    if( ! m_customClassifierPath.isEmpty() )
    {
        QDir dir( m_customClassifierPath );

        QStringList lst1 = dir.entryList( "ttf*.rec" );

        for ( QStringList::Iterator it = lst1.begin(); it != lst1.end(); ++it )
        {
            lst << m_customClassifierPath + *it;
        }

        lst1 = dir.entryList( "hand*.rec" );

        for ( QStringList::Iterator it = lst1.begin(); it != lst1.end(); ++it )
        {
            lst << m_customClassifierPath + *it;
        }

        lst1 = dir.entryList( "norm*.rec" );

        for ( QStringList::Iterator it = lst1.begin(); it != lst1.end(); ++it )
        {
            lst << m_customClassifierPath + *it;
        }
    }
    else
    {
        /* standard location */
        KStandardDirs stdDir;
        kdDebug(28000) << "Starting to read resource" << endl;

        lst = stdDir.findAllResources( "data",
                                       "kooka/classifiers/*.rec",
                                       true,   /* recursive */
                                       true ); /* uniqu */
    }


    /* no go through lst and sort out hand-, ttf- and norm classifier */
    for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )
    {
        QFileInfo fi( *it);
        QString name = fi.fileName().lower();

        kdDebug(28000) << "Checking file " << *it << endl;

        if( name.startsWith( "ttf" ) )
        {
            QString lang = name.mid(3,2);
            if( allCountries.contains(lang) )
            {
                QString lngCountry = locale->twoAlphaToCountryName(lang);
                if( lngCountry.isEmpty() )
                    lngCountry = name;
                m_ttfClassifier << lngCountry;
                kdDebug(28000) << "ttf: Insert country " << lngCountry << endl;
            }
            else if( lang == "cz" )
            {
                m_ttfClassifier << CNTRY_CZ;
            }
            else if( lang == "us" )
            {
                m_ttfClassifier << CNTRY_GB;
            }
            else
            {
                m_ttfClassifier << name;
                kdDebug(28000) << "ttf: Unknown country" << endl;
            }
        }
        else if( name.startsWith( "hand" ) )
        {
            QString lang = name.mid(4,2);
            if( allCountries.contains(lang) )
            {
                QString lngCountry = locale->twoAlphaToCountryName(lang);
                if( lngCountry.isEmpty() )
                    lngCountry = name;
                m_handClassifier << lngCountry;
            }
            else if( lang == "cz" )
            {
                m_handClassifier << i18n( "Czech Republic, Slovakia");
            }
            else if( lang == "us" )
            {
                m_handClassifier << i18n( "Great Britain, USA" );
            }
            else
            {
                kdDebug(28000) << "Hand: Unknown country " << lang << endl;
                m_handClassifier << name;
            }
        }
        else if( name.startsWith( "norm" ))
        {
            m_haveNorm = true;
        }

        kdDebug(28000) << "Found classifier: " << *it << endl;
        m_classifierPath << *it;
    }

    if( m_handClassifier.count()+m_ttfClassifier.count()>0 )
    {
        /* There are classifiers */
        return ENG_OK;
    }
    else
    {
        /* Classifier are missing */
        return ENG_DATA_MISSING;
    }
}