X-Git-Url: http://git.maemo.org/git/?p=mverbiste;a=blobdiff_plain;f=mainwindow.cpp;h=2496c75e1372d4c1d1be428fa1b64cc6b3dc4f5f;hp=f5a38aa633734d886d9f50cd67f2a519d242676a;hb=5193e53ba89b72f9760af7c8a02aab2f645d9c08;hpb=cc80761bdb1c9e1dd83d7713ec77e215051dc534 diff --git a/mainwindow.cpp b/mainwindow.cpp index f5a38aa..2496c75 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,9 +3,6 @@ #include "gui/conjugation.h" #include -#ifdef DEBUG -#include -#endif MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -16,7 +13,6 @@ MainWindow::MainWindow(QWidget *parent) #endif ui->setupUi(this); setupcodedUI(); - initverbiste(); } void MainWindow::setupcodedUI() @@ -46,12 +42,28 @@ void MainWindow::setupcodedUI() connect(wordinput, SIGNAL(returnPressed()), this, SLOT(startLookup())); connect(btnLookup, SIGNAL(clicked()), this, SLOT(startLookup())); + + /* Icon */ + QIcon *icon = new QIcon(); + icon->addFile(ICONFILE); + setWindowIcon(*icon); + + /* About Dialog */ + aboutDialog = new AboutDialog(ICONFILE, QString("MVerbiste v%1").arg(VERSTR)); + aboutDialog->setIntro(trUtf8("A French conjugation utility for Maemo and MeeGo")); + aboutDialog->addAuthor(QString::fromUtf8("Nguyễn Hồng Quân \nPierre Sarrazin ")); + + /* Menu */ + QMenu *menu = ui->menuBar->addMenu(tr("Top menu")); + QAction *act_about = menu->addAction(tr("About")); + connect(act_about, SIGNAL(triggered()), aboutDialog, SLOT(show())); } MainWindow::~MainWindow() { delete ui; delete freVerbDic; + delete aboutDialog; } void MainWindow::setOrientation(ScreenOrientation orientation) @@ -106,6 +118,7 @@ void MainWindow::showExpanded() #else show(); #endif + initverbiste(); wordinput->setFocus(); } @@ -125,12 +138,16 @@ void MainWindow::initverbiste() void MainWindow::startLookup() { + QString input = wordinput->text().trimmed(); + if (input.isEmpty()) { + return; + } + btnLookup->setText(tr("Please wait...")); btnLookup->setEnabled(false); clearResults(); /* Pending the lookup job to the next event loop (redraw the button right now) */ QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - QString input = wordinput->text(); /* Get input word to look up */ const std::string word = input.toLower().toUtf8().constData(); @@ -143,16 +160,49 @@ void MainWindow::startLookup() bool includePronouns = FALSE; // TODO: Will get this value from external bool isItalian = FALSE; // TODO: Will get this value from external +#ifndef QT_NO_DEBUG + timer.start(); + qDebug() << "Start " << timer.elapsed(); +#endif freVerbDic->deconjugate(word, infles); resultPages->setUpdatesEnabled(false); - std::string prevUTF8Infinitive, prevTemplateName; + std::string prevUTF8Infinitive, prevTemplateName; /* Remember found word + to avoid conjugating again */ + for (std::vector::const_iterator it = infles.begin(); it != infles.end(); it++) { const InflectionDesc &d = *it; + +#ifndef QT_NO_DEBUG + qDebug() << ">> Infinitive " << d.infinitive.c_str(); + qDebug() << " Template " << d.templateName.c_str(); +#endif + /* If this infinitive has been conjugated, we skip to the next infinitive */ + if (d.infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName) { + continue; + } + /* FIXME: + * In original source (Verbiste), this checking is done later, + * after getConjugation(). I place it here to avoid calling again + * multitimes getConjugation(), which is very slow. + * We need to test more to see which place is more correct. + */ + VVVS conjug; - getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, includePronouns); +#ifndef QT_NO_DEBUG + qDebug() << " START getConjugation " << timer.elapsed(); +#endif + getConjugation(freVerbDic, d.infinitive, d.templateName, conjug, + #ifndef QT_NO_DEBUG + timer, + #endif + includePronouns); + +#ifndef QT_NO_DEBUG + qDebug() << " getConjugation() returns: " << timer.elapsed(); +#endif if (conjug.size() == 0 // if no tenses || conjug[0].size() == 0 // if no infinitive tense @@ -163,11 +213,12 @@ void MainWindow::startLookup() } std::string utf8Infinitive = conjug[0][0][0]; - if (utf8Infinitive == prevUTF8Infinitive && d.templateName == prevTemplateName) - // This result is duplicated - continue; +#ifndef QT_NO_DEBUG + qDebug() << " Infinitive " << utf8Infinitive.c_str(); + qDebug() << " Template " << d.templateName.c_str(); +#endif - /* Show on GUI */ + /* Add result to GUI (not show yet) */ ResultPage *rsp = addResultPage(utf8Infinitive); /* Get modes and tenses of the verb */ @@ -190,10 +241,13 @@ void MainWindow::startLookup() QVBoxLayout *cell = makeResultCell(*t, utf8TenseName, word, freVerbDic); rsp->grid->addLayout(cell, row, col); } + + /* Show the result on GUI */ rsp->packContent(); prevUTF8Infinitive = utf8Infinitive; prevTemplateName = d.templateName; } + /* Enable the button again */ btnLookup->setEnabled(true); btnLookup->setText("");