Пример #1
0
void FileListModel::loadFileList()
{
    beginResetModel();
    m_fileList.clear();
    FcitxStringHashSet* files = FcitxXDGGetFiles(dictDir().toAscii().constData(), NULL, ".txt");

    HASH_SORT(files, fcitx_utils_string_hash_set_compare);
    HASH_FOREACH(f, files, FcitxStringHashSet) {
        m_fileList.append(QString::fromLocal8Bit(f->name).prepend(dictDir() + "/"));
    }
Пример #2
0
const QStringList Configuration::getAllAvailableSpellCheckDictNames()
{
    QStringList dicts;
    QString dirPath = QString( "%1/%2" ).arg( defaultSpellCheckRootDir ).arg( SPELL_CHECK_DIC_DIRECTORY_NAME );
    QDir dictDir( dirPath );

    if ( !dictDir.exists() ) {
        return dicts;
    }

    QStringList filter;
    filter << "*.aff";
    QFileInfoList fileInfoList = dictDir.entryInfoList( filter, QDir::Files, QDir::Name );

    for ( int i = 0; i < fileInfoList.size(); i++ ) {
        QFileInfo fileInfo = fileInfoList.at( i );
        QString dictFilePath = QString( "%1/%2.dic" ).arg( fileInfo.absolutePath() ).arg( fileInfo.baseName() );

        if ( QFile::exists( dictFilePath ) ) {
            dicts << fileInfo.baseName();
        }
    }

    return dicts;
}
Пример #3
0
//! \brief SpellChecker::setLanguage switches to the given language if possible
//! \param language The new language use "en" or "en_US". If more than one
//! exists, the first one in the directory listing is used
//! \return true if switching the language succeded
bool SpellChecker::setLanguage(const QString &language)
{
    Q_D(SpellChecker);

    qDebug() << "spellechecker.cpp in setLanguage() lang=" << language << "dictPath=" << dictPath();

    QDir dictDir(dictPath());
    QStringList affMatches = dictDir.entryList(QStringList(language+"*.aff"));
    QStringList dicMatches = dictDir.entryList(QStringList(language+"*.dic"));

    if (affMatches.isEmpty() || dicMatches.isEmpty()) {
        QString lang = language;
        lang.truncate(2);
        qWarning() << "Did not find a dictionary for" << language << " - checking for " << lang;
        if (language.length() > 2) {
            return setLanguage(lang);
        }

        qWarning() << "No dictionary found for" << language << "turning off spellchecking";
        d->clear();
        return false;
    }

    d->aff_file = dictPath() + "/" + affMatches[0];
    d->dic_file = dictPath() + "/" + dicMatches[0];

    qDebug() << "spellechecker.cpp in setLanguage() aff_file=" << d->aff_file << "dic_file=" << d->dic_file;

    if (enabled()) {
        setEnabled(false);
        return setEnabled(true);
    } else {
        return true;
    }
}
Пример #4
0
QVariant FileListModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid() || index.row() >= m_fileList.size())
        return QVariant();

    switch (role) {
    case Qt::DisplayRole:
        {
            const int length = dictDir().size();
            return m_fileList[index.row()].mid(length + 1, m_fileList[index.row()].size() - length - strlen(".txt") - 1);
        }
    case Qt::UserRole:
        return m_fileList[index.row()];
    default:
        break;
    }
    return QVariant();
}
Пример #5
0
bool QDictWidget::ensureDictFile()
{
    if(dictFile.exists())
    {
        return true;
    }
    QDir baseDir("/media/card");
    if(!baseDir.exists())
    {
        baseDir = QDir::home();
    }
    QDir dictDir(baseDir.path() + "/.qgcide");
    if(!dictDir.exists())
    {
        if(!baseDir.mkdir(".qgcide"))
        {
            showErr(tr("Unable to create dictionary dir ") + dictDir.absolutePath());
            return false;
        }
    }
    dictFile.setFileName(dictDir.absolutePath() + "/gcide-entries.xml");
    if(dictFile.exists())
    {
        return true;
    }
    if(QMessageBox::question(this, tr("English dictionary"),
                          tr("Dictionary must be downloaded. Please make sure you have internet connection and press yes to confirm download (14MB)."),
                          QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
    {
        return false;
    }
    progress->setVisible(true);
    QString gzFile = dictFile.fileName() + ".gz";
    if(!download("http://dl.linuxphone.ru/openmoko/qtmoko/packages/gcide-entries.xml.gz", gzFile, "gcide-entries.xml.gz"))
    {
        return false;
    }
    if(!ungzip(gzFile))
    {
        return false;
    }
    progress->setVisible(false);
    return true;
}