google translation can be added to bookmark
[mdictionary] / src / plugins / google / GooglePlugin.cpp
index 37eaf20..0d85f4c 100644 (file)
@@ -44,8 +44,11 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
     stopped = false;
     initLanguages();
 
-    http = new QHttp(this);
+    http = new QHttp();
     connect(http, SIGNAL(done(bool)), this, SLOT(done()));
+    threa=new QThread();
+    http->moveToThread(threa);
+    threa->start();
 }
 
 void GooglePlugin::retranslate() {
@@ -189,10 +192,22 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int ) {
 
         wait=true;      /* bool - change in slot done (initiate by http) */
         stopped=false;  /* bool - change in slot stop (initiate in gui)  */
+
+        int lastState=0;
+        //qDebug()<<"google3";
         http->request(head, data);
-        while(wait && (error=="" || error=="Unknown error") && !stopped)
+        while(wait && (error=="" || error=="Unknown error") && !stopped){
             error=http->errorString();
-
+            if(lastState!=http->state()) {
+                lastState=http->state();
+        //        qDebug()<<lastState;
+                if(lastState==0){
+                    done();
+        //            qDebug()<<"done2";
+                }
+            }
+        }
+        //qDebug()<<"google4";
         if(error!="" && error!="Unknown error") {
             if(!noNetworkErrorShowed) {
                 noNetworkErrorShowed = true;
@@ -213,7 +228,7 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int ) {
 
 
 QString GooglePlugin::jsonParse(QString result) {
-    qDebug()<<"Json"<<result;
+    //qDebug()<<"Json"<<result;
     int pos=0,pos2=0,index=0,size=0;
     QString returnLang;
     QString translation;
@@ -290,12 +305,13 @@ QString GooglePlugin::jsonParse(QString result) {
             result+=words.at(i)->at(j)+", ";
         result.remove(result.size()-2,2);
     }
-    qDebug()<<"PO"<<result;
+    //qDebug()<<"PO"<<result;
     return result;
 }
 
 
 void GooglePlugin::done() {
+//    qDebug()<<"done";
     wait=false;
 }