Esempio n. 1
0
InputMatcher::InputMatcher(const QString &n) : mIndex(null_index), mReplaces(null_index), mLookup(TRUE), lowerdict(FALSE)
{
    int index = 0;
    QString tmpName = n;
    while(aliasLookup[index].name != 0) {
	if (tmpName == aliasLookup[index].name) {
	    tmpName = aliasLookup[index].lookup;
	    break;
	}
	index++;
    }
    index = 0;
    while(validNames[index].name != 0) {
	if (tmpName == validNames[index].name) {
	    mId = tmpName;
	    mIndex = index;
	    break;
	}
	index++;
    }

    QStringList cl = chosenLanguages();
    // named dictionary.  mIndex is still dict, but name isn't
    if (tmpName.left(5) == "dict-" && cl.indexOf(tmpName.mid(5)) >= 0) {
	mId = tmpName;
	mIndex = dict_index;
    }

    if (mId.isNull())
	mId = tmpName;
    // init will set mId to null if there is no valid mode of that name
    init();
}
Esempio n. 2
0
AcceptLanguageDialog::AcceptLanguageDialog(const QString &languages, QWidget *parent) : Dialog(parent),
	m_ui(new Ui::AcceptLanguageDialog)
{
	m_ui->setupUi(this);

	m_model = new QStandardItemModel(this);
	m_model->setHorizontalHeaderLabels(QStringList({tr("Name"), tr("Code")}));

	m_ui->languagesViewWidget->setModel(m_model);

	QStringList chosenLanguages(languages.split(QLatin1Char(','), QString::SkipEmptyParts));

	for (int i = 0; i < chosenLanguages.count(); ++i)
	{
		addLanguage(chosenLanguages.at(i).section(QLatin1Char(';'), 0, 0));
	}

	const QList<QLocale> locales(QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry));
	QVector<QPair<QString, QString> > entries;

	for (int i = 0; i < locales.count(); ++i)
	{
		const QLocale locale(locales.at(i));

		if (locale != QLocale::c())
		{
			if (locale.nativeCountryName().isEmpty() || locale.nativeLanguageName().isEmpty())
			{
				entries.append({tr("Unknown [%1]").arg(locale.bcp47Name()), locale.bcp47Name()});
			}
			else
			{
				entries.append({QStringLiteral("%1 - %2 [%3]").arg(locale.nativeLanguageName()).arg(locale.nativeCountryName()).arg(locale.bcp47Name()), locale.bcp47Name()});
			}
		}
	}

	QCollator collator;
	collator.setCaseSensitivity(Qt::CaseInsensitive);

	qSort(entries.begin(), entries.end(), [&](const QPair<QString, QString> &first, const QPair<QString, QString> &second)
	{
		return (collator.compare(first.first, second.first) < 0);
	});

	entries.prepend(QPair<QString, QString>(tr("Any other"), QLatin1String("*")));
	entries.prepend(QPair<QString, QString>(tr("System language (%1 - %2)").arg(QLocale::system().nativeLanguageName()).arg(QLocale::system().nativeCountryName()), QString("system")));

	for (int i = 0; i < entries.count(); ++i)
	{
		m_ui->languagesComboBox->addItem(entries.at(i).first, entries.at(i).second);
	}

	m_ui->moveDownButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-down")));
	m_ui->moveUpButton->setIcon(ThemesManager::createIcon(QLatin1String("arrow-up")));
	m_ui->languagesComboBox->installEventFilter(this);

	connect(m_ui->moveDownButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveDownRow);
	connect(m_ui->moveUpButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::moveUpRow);
	connect(m_ui->removeButton, &QToolButton::clicked, m_ui->languagesViewWidget, &ItemViewWidget::removeRow);
	connect(m_ui->addButton, &QToolButton::clicked, this, &AcceptLanguageDialog::addNewLanguage);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveDownChanged, m_ui->moveDownButton, &QToolButton::setEnabled);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::canMoveUpChanged, m_ui->moveUpButton, &QToolButton::setEnabled);
	connect(m_ui->languagesViewWidget, &ItemViewWidget::needsActionsUpdate, this, &AcceptLanguageDialog::updateActions);
}
Esempio n. 3
0
QStringList InputMatcher::searchDict(bool allowprefix,
	bool predict, const QString& language,
	const QStringList& extradict, int start, int end, uint *me) const
{
    // Search dictionaries. Return list of words matching
    // this->sets, with the most likely word first. If no
    // words match, prefixes of the most likely words are
    // returned.

    InputMatcherWordErrorList r;
    QString lang = language;
    QString lang2;
    if ( lang.isNull() )
	lang = chosenLanguages()[0];
    if ( lang[2] == '_' ) {
	// Non country-specific words
	lang2 = lang.left(2);
    }

    bool prefixequal=true; // XXX could be parameterized if needed

    uint minError = UINT_MAX;
    for (int prefix=0; (r.isEmpty() || prefixequal) && prefix<=1; ++prefix) {
	InputMatcherWordErrorList preferred, added, extra;
	InputMatcherWordErrorList common, fixed, common2, fixed2;

	if(!qualifiedSets)
	    preferred = findWords(Qtopia::dawg("preferred").root(),start,end,
		    "", 0, prefix, predict);
	added = findWords(Qtopia::addedDawg().root(),start,end,
		    "",0, prefix, predict);
	if(!qualifiedSets)
	    common = findWords(Qtopia::dawg("_common",lang).root(),start,end,
		    "",0, prefix, predict);
	fixed = findWords(Qtopia::dawg("_words",lang).root(),start,end,
		    "",0, prefix, predict);

	if ( !lang2.isEmpty() ) {
	    common2 = findWords(Qtopia::dawg("_common",lang2).root(),
		    start,end,"",0, prefix, predict);
	    fixed2 = findWords(Qtopia::dawg("_words",lang2).root(),
		    start,end,"",0, prefix, predict);
	}

	uint nerror;
	for (QStringList::ConstIterator xdit=extradict.begin(); xdit!=extradict.end(); ++xdit) {
	    extra = findWords(Qtopia::dawg(*xdit).root(),start,end,"",0, prefix, predict);
	    nerror = r.merge(extra);
	    if (nerror < minError)
		minError = nerror;
	}

	nerror = r.merge(preferred);
	if (nerror < minError)
	    minError = nerror;
	nerror = r.merge(common);
	if (nerror < minError)
	    minError = nerror;
	nerror = r.merge(fixed);
	if (nerror < minError)
	    minError = nerror;
	nerror = r.merge(added);
	if (nerror < minError)
	    minError = nerror;
	nerror = r.merge(common2);
	if (nerror < minError)
	    minError = nerror;
	nerror = r.merge(fixed2);
	if (nerror < minError)
	    minError = nerror;

        if ( !allowprefix )
            break;
    }
    QStringList deleted = findWords(Qtopia::dawg("deleted").root(),start,end,"",0, false, predict).asStringList();
    for ( QStringList::ConstIterator i=deleted.begin(); i!=deleted.end(); ++i) {
        r.remove(*i);
    };

    qLog(Input) << "searchDict" <<
        (allowprefix ? " with prefixes" : "") <<
        (predict ? " with prediction" : "") <<
        " in" << language << ": " << r;

    if (me)
	*me = minError;
    // if error larger than X add extra word? not here.
    return r.asStringList();
}