From d158533e8d78cc85e919dfb7e6fb5d08dd59c1dc Mon Sep 17 00:00:00 2001 From: Jakub Jaszczynski Date: Wed, 6 Oct 2010 08:27:05 +0200 Subject: [PATCH] add google bookmark work correctly --- src/mdictionary/backbone/Bookmarks.cpp | 4 +-- src/mdictionary/backbone/Bookmarks.h | 2 +- src/mdictionary/backbone/ConfigGenerator.cpp | 1 + src/mdictionary/backbone/backbone.cpp | 36 ++++++++++++++------------ src/mdictionary/backbone/backbone.h | 8 +++--- src/mdictionary/gui/HistoryListDialog.cpp | 1 + src/mdictionary/gui/MainWindow.cpp | 17 +++--------- src/plugins/google/GooglePlugin.cpp | 8 +++--- src/plugins/xdxf/xdxfplugin.cpp | 9 ++----- 9 files changed, 38 insertions(+), 48 deletions(-) diff --git a/src/mdictionary/backbone/Bookmarks.cpp b/src/mdictionary/backbone/Bookmarks.cpp index 56d8020..42130cb 100644 --- a/src/mdictionary/backbone/Bookmarks.cpp +++ b/src/mdictionary/backbone/Bookmarks.cpp @@ -70,7 +70,7 @@ void Bookmarks::add(Translation* translation) { cur.exec(); } -void Bookmarks::add(QString key,QString removeAccentKey,QString value){ +void Bookmarks::add(QString key,QString value){ checkAndCreateDb(); QSqlDatabase db = getDbCnx(); if(!db.isOpen() && !db.open()) { @@ -80,7 +80,7 @@ void Bookmarks::add(QString key,QString removeAccentKey,QString value){ QSqlQuery cur(db); cur.prepare("insert into bookmarks values (?,?,?)"); cur.addBindValue(key); - cur.addBindValue(removeAccentKey); + cur.addBindValue(removeAccents(key)); cur.addBindValue(value); cur.exec(); } diff --git a/src/mdictionary/backbone/Bookmarks.h b/src/mdictionary/backbone/Bookmarks.h index 1731499..3010bad 100644 --- a/src/mdictionary/backbone/Bookmarks.h +++ b/src/mdictionary/backbone/Bookmarks.h @@ -63,7 +63,7 @@ public: */ void add(Translation* translation); - void add(QString key,QString removeAccentKey,QString value); + void add(QString key,QString value); /*! Removes word and corresponding translation cache from bookmarks list \param translation translation to be removed diff --git a/src/mdictionary/backbone/ConfigGenerator.cpp b/src/mdictionary/backbone/ConfigGenerator.cpp index 704a6ba..c183aba 100644 --- a/src/mdictionary/backbone/ConfigGenerator.cpp +++ b/src/mdictionary/backbone/ConfigGenerator.cpp @@ -30,6 +30,7 @@ bool ConfigGenerator::generateCss(QString file) { generateFile(":/xsl/style.css", file); + return true; } diff --git a/src/mdictionary/backbone/backbone.cpp b/src/mdictionary/backbone/backbone.cpp index 721decc..ad8147b 100644 --- a/src/mdictionary/backbone/backbone.cpp +++ b/src/mdictionary/backbone/backbone.cpp @@ -96,6 +96,8 @@ void Backbone::init() { SLOT(bookmarksListReady())); connect(&_bookmarkSearchWatcher, SIGNAL(finished()), this, SLOT(translationReady())); + connect(&_translationsListWatcher, SIGNAL(finished()), + this, SLOT(bookmarkReadyFuture())); // In common opinion perfect thread count is cores_number+1 (in qt perfect // thread count is set to cores number) so iam changin it @@ -514,8 +516,9 @@ QStringList Backbone::xmls() { return _xmlResult; } -void Backbone::addBookmark(QList translations) { +void Backbone::addBookmarkFuture(QList translations) { if(translations.size()>0) { + qDebug()<<"size"<getTranslationFor(tr->key()); @@ -530,20 +533,29 @@ void Backbone::addBookmark(QList translations) { foreach(translation,translations){ translation->setBookmark(true); trans.insert(translation->toXml(),translation->key()); - } + _xmlResult.clear(); foreach(QString value,trans.keys()){ + qDebug()<<"dodaje"< translations) { + _translationsListWatcher.setFuture(QtConcurrent::run(this , + &Backbone::addBookmarkFuture,translations)); + /* foreach(Translation *trans,translations){ + _bookmarks.add(trans); */ - // Translation* translation; - // foreach(translation, translations) - // _bookmarks.add(translation); - // emit bookmarkReady(); } +void Backbone::bookmarkReadyFuture(){ + qDebug()<<"zaraz stop"; + emit xmlReady(); +} void Backbone::searchXml(QList translations) { _xmlResult.clear(); @@ -563,15 +575,12 @@ void Backbone::searchXml(QList translations) { } } - _innerXmlResult = QtConcurrent::mapped(dummy, - &TranslationPtr::toHtml); + _innerXmlResult = QtConcurrent::mapped(dummy, &TranslationPtr::toHtml); _xmlResultWatcher.setFuture(_innerXmlResult); } - void Backbone::xmlTranslationReady() { - QFutureIterator it(_innerXmlResult); QSet uniqe; while(it.hasNext()) @@ -595,15 +604,12 @@ QList Backbone::activeDicts() { } - void Backbone::bookmarksListReady() { _bookmarksResult = _innerBookmarks.result(); Q_EMIT bookmarksReady(); } - - void Backbone::setSettings(Settings *settings) { _historyLen = settings->value("history_size").toInt(); _searchLimit = settings->value("search_limit").toInt(); @@ -625,8 +631,6 @@ void Backbone::setSettings(Settings *settings) { } - - Settings* Backbone::settings() { Settings * settings = new Settings(); settings->setValue("history_size", QString("%1").arg(_historyLen)); diff --git a/src/mdictionary/backbone/backbone.h b/src/mdictionary/backbone/backbone.h index e5c619d..d925b12 100644 --- a/src/mdictionary/backbone/backbone.h +++ b/src/mdictionary/backbone/backbone.h @@ -140,7 +140,7 @@ public: what kind of function may be used there see Qt docs */ static int _searchLimit; - + void addBookmarkFuture(QList translations); public Q_SLOTS: //! stops all current searches and emits searchCanceled signal @@ -242,8 +242,7 @@ public Q_SLOTS: */ Settings* settings(); - - + void bookmarkReadyFuture(); @@ -287,6 +286,8 @@ private: QFuture > _innerBookmarks; //Res of search in bookmarks QFuture > _innerListBookmarks; //Res of search in bookmarks QFuture _innerXmlBookmarks; //Xml result of bookmarks search + QFuture _innerTranslationsList; + QMultiHash _result; //Final result of word search QStringList _xmlResult; // Final result of xml search @@ -298,6 +299,7 @@ private: QFutureWatcher > _bookmarkWatcher; QFutureWatcher > _bookmarkSearchWatcher; QFutureWatcher _xmlResultWatcher; + QFutureWatcher _translationsListWatcher; QString _pluginPath; diff --git a/src/mdictionary/gui/HistoryListDialog.cpp b/src/mdictionary/gui/HistoryListDialog.cpp index 7e58372..19f0e80 100644 --- a/src/mdictionary/gui/HistoryListDialog.cpp +++ b/src/mdictionary/gui/HistoryListDialog.cpp @@ -76,4 +76,5 @@ int HistoryListDialog::selectedRow() { int HistoryListDialog::exec() { historyListWidget->setFocus(); QDialog::exec(); + return 0; } diff --git a/src/mdictionary/gui/MainWindow.cpp b/src/mdictionary/gui/MainWindow.cpp index 51384d6..ef791ed 100644 --- a/src/mdictionary/gui/MainWindow.cpp +++ b/src/mdictionary/gui/MainWindow.cpp @@ -255,7 +255,6 @@ void MainWindow::translationsReady() { #ifndef Q_WS_MAEMO_5 hideWelcomeScreen(); #endif - Q_EMIT showTranslation(backbone->xmls()); wordListWidget->setFocus(); #ifdef Q_WS_MAEMO_5 @@ -313,9 +312,6 @@ void MainWindow::searchDelay(QString word) { } - - - void MainWindow::searchingInterrupted() { //make sure to unset exact search mode setExactSearch(false); @@ -464,13 +460,6 @@ void MainWindow::connectBackbone() { connect(backbone, SIGNAL(closeOk()), this, SLOT(close())); - - - //connect(wordListWidget, SIGNAL(addBookmark(QList)), - // this, SIGNAL(setBusy())); - - //connect(backbone, SIGNAL(bookmarkReady()), - // this, SIGNAL(setIdle())); } void MainWindow::connectSearchBar() { @@ -511,9 +500,6 @@ void MainWindow::connectWordList() { connect(wordListWidget, SIGNAL(showTranslation(QList)), this, SIGNAL(searchTranslations(QList))); - - - connect(this, SIGNAL(setBusy()), wordListWidget, SLOT(lockList())); @@ -521,6 +507,9 @@ void MainWindow::connectWordList() { wordListWidget, SLOT(unlockList())); connect(wordListWidget, SIGNAL(addBookmark(QList)), + this, SIGNAL(setBusy())); + + connect(wordListWidget, SIGNAL(addBookmark(QList)), backbone, SLOT(addBookmark(QList))); connect(wordListWidget, SIGNAL(removeBookmark(QList)), diff --git a/src/plugins/google/GooglePlugin.cpp b/src/plugins/google/GooglePlugin.cpp index 38aac6c..500c531 100644 --- a/src/plugins/google/GooglePlugin.cpp +++ b/src/plugins/google/GooglePlugin.cpp @@ -45,7 +45,7 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent), initLanguages(); http = new QHttp(); - connect(http, SIGNAL(done(bool)), this, SLOT(done())); + //connect(http, SIGNAL(done(bool)), this, SLOT(done())); threa=new QThread(); http->moveToThread(threa); threa->start(); @@ -198,14 +198,14 @@ QList GooglePlugin::searchWordList(QString word, int ) { error=http->errorString(); if(lastState!=http->state()) { lastState=http->state(); - if(lastState==0){ + if(lastState==0) done(); - } } } if(error!="" && error!="Unknown error") { if(!noNetworkErrorShowed) { noNetworkErrorShowed = true; + qDebug()< GooglePlugin::searchWordList(QString word, int ) { QString GooglePlugin::jsonParse(QString result) { - //qDebug()<<"Json"<at(j)+", "; result.remove(result.size()-2,2); } - //qDebug()<<"PO"< XdxfPlugin::searchWordListFile(QString word, int limit) { if((regWord.exactMatch(readKey) || regWord.exactMatch(removeAccents(readKey))) && (ilastDialogParent()); - -// qDebug()<<_dictDialog->lastDialogParent(); - connect(&d, SIGNAL(cancelCaching()), this, SLOT(stop())); connect(this, SIGNAL(updateCachingProgress(int,int)), -- 1.7.9.5