add google bookmark work correctly google
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 6 Oct 2010 06:27:05 +0000 (08:27 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 6 Oct 2010 06:27:05 +0000 (08:27 +0200)
src/mdictionary/backbone/Bookmarks.cpp
src/mdictionary/backbone/Bookmarks.h
src/mdictionary/backbone/ConfigGenerator.cpp
src/mdictionary/backbone/backbone.cpp
src/mdictionary/backbone/backbone.h
src/mdictionary/gui/HistoryListDialog.cpp
src/mdictionary/gui/MainWindow.cpp
src/plugins/google/GooglePlugin.cpp
src/plugins/xdxf/xdxfplugin.cpp

index 56d8020..42130cb 100644 (file)
@@ -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();
 }
index 1731499..3010bad 100644 (file)
@@ -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
index 704a6ba..c183aba 100644 (file)
@@ -30,6 +30,7 @@
 
 bool ConfigGenerator::generateCss(QString file) {
     generateFile(":/xsl/style.css", file);
+    return true;
 }
 
 
index 721decc..ad8147b 100644 (file)
@@ -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<Translation*> translations) {
+void Backbone::addBookmarkFuture(QList<Translation*> translations) {
     if(translations.size()>0) {
+        qDebug()<<"size"<<translations.size();
         Translation *tr = translations.at(0);
         foreach(CommonDictInterface* dict, activeDicts()) {
             Translation* trans = dict->getTranslationFor(tr->key());
@@ -530,20 +533,29 @@ void Backbone::addBookmark(QList<Translation*> translations) {
     foreach(translation,translations){
         translation->setBookmark(true);
         trans.insert(translation->toXml(),translation->key());
-
     }
 
+    _xmlResult.clear();
     foreach(QString value,trans.keys()){
+        qDebug()<<"dodaje"<<value;
         QString key= trans.value(value);
-        _bookmarks.add(key,key,value);
+        _bookmarks.add(key,value);
+        _xmlResult.append(value);
     }
+}
+
+void Backbone::addBookmark(QList<Translation*> 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<Translation *> translations) {
     _xmlResult.clear();
@@ -563,15 +575,12 @@ void Backbone::searchXml(QList<Translation *> translations) {
         }
     }
 
-   _innerXmlResult = QtConcurrent::mapped(dummy,
-                                            &TranslationPtr::toHtml);
+   _innerXmlResult = QtConcurrent::mapped(dummy, &TranslationPtr::toHtml);
    _xmlResultWatcher.setFuture(_innerXmlResult);
 }
 
 
-
 void Backbone::xmlTranslationReady() {
-
     QFutureIterator<QString> it(_innerXmlResult);
     QSet<QString> uniqe;
     while(it.hasNext())
@@ -595,15 +604,12 @@ QList<CommonDictInterface*> 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));
index e5c619d..d925b12 100644 (file)
@@ -140,7 +140,7 @@ public:
         what kind of function may be used there see Qt docs */
     static int _searchLimit;
 
-
+    void addBookmarkFuture(QList<Translation*> 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<QList<Translation*> > _innerBookmarks; //Res of search in bookmarks
     QFuture<QList<Translation*> > _innerListBookmarks; //Res of search in bookmarks
     QFuture<QStringList> _innerXmlBookmarks; //Xml result of bookmarks search
+    QFuture<void> _innerTranslationsList;
+
 
     QMultiHash<QString, Translation*> _result; //Final result of word search
     QStringList _xmlResult; // Final result of xml search
@@ -298,6 +299,7 @@ private:
     QFutureWatcher<QList<Translation*> > _bookmarkWatcher;
     QFutureWatcher<QList<Translation*> > _bookmarkSearchWatcher;
     QFutureWatcher<QString> _xmlResultWatcher;
+    QFutureWatcher<void> _translationsListWatcher;
 
 
     QString _pluginPath;
index 7e58372..19f0e80 100644 (file)
@@ -76,4 +76,5 @@ int HistoryListDialog::selectedRow() {
 int HistoryListDialog::exec() {
     historyListWidget->setFocus();
     QDialog::exec();
+    return 0;
 }
index 51384d6..ef791ed 100644 (file)
@@ -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<Translation*>)),
-    //       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<Translation*>)),
             this, SIGNAL(searchTranslations(QList<Translation*>)));
 
-
-
-
     connect(this, SIGNAL(setBusy()),
             wordListWidget, SLOT(lockList()));
 
@@ -521,6 +507,9 @@ void MainWindow::connectWordList() {
             wordListWidget, SLOT(unlockList()));
 
     connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
+           this, SIGNAL(setBusy()));
+
+    connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
             backbone, SLOT(addBookmark(QList<Translation*>)));
 
     connect(wordListWidget, SIGNAL(removeBookmark(QList<Translation*>)),
index 38aac6c..500c531 100644 (file)
@@ -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<Translation*> 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()<<error;
                 Q_EMIT notify(Notify::Warning,
                         tr("GooglePlugin: %1").arg(error));
             }
@@ -223,7 +223,6 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int ) {
 
 
 QString GooglePlugin::jsonParse(QString result) {
-    //qDebug()<<"Json"<<result;
     int pos=0,pos2=0,index=0,size=0;
     QString returnLang;
     QString translation;
@@ -300,7 +299,6 @@ QString GooglePlugin::jsonParse(QString result) {
             result+=words.at(i)->at(j)+", ";
         result.remove(result.size()-2,2);
     }
-    //qDebug()<<"PO"<<result;
     return result;
 }
 
index ee8ee03..56a038f 100644 (file)
@@ -173,7 +173,6 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
             if((regWord.exactMatch(readKey)
                     || regWord.exactMatch(removeAccents(readKey)))
                     && (i<limit || limit==0) && !reader.atEnd())  {
- //               qDebug()<<readKey;
                 translations<<(new TranslationXdxf(readKey.toLower(),
                                _dictionaryInfo,this));
                 if(translations.size()==limit && limit!=0)
@@ -288,7 +287,6 @@ QString XdxfPlugin::searchFile(QString key) {
 
 
 void XdxfPlugin::stop() {
-   //qDebug()<<"stop";
     stopped=true;
 }
 
@@ -423,12 +421,12 @@ bool XdxfPlugin::getDictionaryInfo() {
     if(reader.name()=="full_name")
         _name=reader.readElementText();
     else
-        qDebug()<<"no full_name";
+        qDebug()<<"Dictionary dont have full_name";
     reader.readNextStartElement();
     if(reader.name()=="description")
         _infoNote=reader.readElementText();
     else
-        qDebug()<<"no description";
+        qDebug()<<"Dictionary dont have description";
 
     _dictionaryInfo= _name + " [" + _langFrom + "-"
                 + _langTo + "]";
@@ -478,9 +476,6 @@ int XdxfPlugin::countWords() {
 bool XdxfPlugin::makeCache(QString) {
 
     XdxfCachingDialog d(_dictDialog->lastDialogParent());
-
-//    qDebug()<<_dictDialog->lastDialogParent();
-
     connect(&d, SIGNAL(cancelCaching()),
             this, SLOT(stop()));
     connect(this, SIGNAL(updateCachingProgress(int,int)),