X-Git-Url: http://git.maemo.org/git/?p=mverbiste;a=blobdiff_plain;f=mainwindow.cpp;h=35db3e562ed3927e23aa6c95610a4d20e696dc28;hp=31fed0cd617dd7993790e26f7ec1868635d1d4b8;hb=c592baecbda14091d59a1dc1ba0776de02e59f5d;hpb=3363c69bdbc38494b966567f4dbf8384402e5877 diff --git a/mainwindow.cpp b/mainwindow.cpp index 31fed0c..35db3e5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "gui/conjugation.h" #include @@ -44,6 +45,7 @@ void MainWindow::setupcodedUI() // Clear the word input when Clear button is tapped QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(clear())); QObject::connect(btnClear, SIGNAL(clicked()), labVerb, SLOT(clear())); + QObject::connect(btnClear, SIGNAL(clicked()), wordinput, SLOT(setFocus())); QObject::connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup())); QObject::connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup())); @@ -106,32 +108,58 @@ void MainWindow::showExpanded() #else show(); #endif + wordinput->setFocus(); } void MainWindow::startLookup() { - const std::set *templateSet = NULL; QString input = wordinput->text(); - labVerb->setText(input); + FrenchVerbDictionary::Language lang = FrenchVerbDictionary::parseLanguageCode(langCode); if (lang != FrenchVerbDictionary::FRENCH) { - //wordinput->setText(QString("Fr")); + // TODO: If lang code is not supported? } + + /* Create verb dictionary, accept non-accent input */ + freVerbDic = new FrenchVerbDictionary(true); + + /* Get input word to look up */ + const std::string word = input.toLower().toUtf8().constData(); + /* - std::string conjFileName, verbsFileName; - FrenchVerbDictionary::getXMLFilenames(conjFileName, verbsFileName, lang); - */ - freVerbDic = new FrenchVerbDictionary(false); - const std::string word = input.toUtf8().constData(); - templateSet = &freVerbDic->getVerbTemplateSet(word); - for (std::set::const_iterator it = templateSet->begin(); - it != templateSet->end(); ++it) - { - const std::string &tname = *it; - - FrenchVerbDictionary::getRadical(word, tname); - } + * For each possible deconjugation, take the infinitive form and + * obtain its complete conjugation. + */ + std::vector v; + bool includePronouns = FALSE; // TODO: Will get this value from external + + freVerbDic->deconjugate(word, v); + + std::string prevUTF8Infinitive, prevTemplateName; + for (std::vector::const_iterator it = v.begin(); + it != v.end(); it++) + { + const InflectionDesc &d = *it; + VVVS conjug; + getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns); + + if (conjug.size() == 0 // if no tenses + || conjug[0].size() == 0 // if no infinitive tense + || conjug[0][0].size() == 0 // if no person in inf. tense + || conjug[0][0][0].empty()) // if infinitive string empty + { + continue; + } + + std::string utf8Infinitive = conjug[0][0][0]; + if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName) + // This result is duplicated + continue; + + /* Show on GUI */ + labVerb->setText(QString::fromUtf8(utf8Infinitive.c_str())); + } } void MainWindow::initverbiste()