display code afrer JsonParse
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 25 Aug 2010 08:35:48 +0000 (10:35 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 25 Aug 2010 08:35:48 +0000 (10:35 +0200)
trunk/src/base/gui/SearchBarWidget.cpp
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/xsl.xsl
trunk/src/plugins/google/src/GooglePlugin.cpp
trunk/src/plugins/google/src/GooglePlugin.h
trunk/src/plugins/google/src/TranslationGoogle.cpp
trunk/src/plugins/google/tests/test.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

index 43519dc..29368e3 100644 (file)
@@ -185,7 +185,7 @@ void SearchBarWidget::initializeUI() {
                 fullScreenToolButton->sizeHint().height()*2);
     #endif*/
 
-    searchingProgressBar = new QProgressBar();
+    searchingProgressBar = new QProgressBar(this);
     //progress bar has minimum and maximum values set to 0, which will effect
     //with "I'm alive" bar
     searchingProgressBar->setMinimum(0);
index cacfebf..5111918 100644 (file)
@@ -80,9 +80,14 @@ void TranslationWidget::show(QStringList translations) {
     QTextDocument *document = textEdit->document();
     document->addResource(QTextDocument::ImageResource, QUrl("mydata://image.png"), QVariant(image));
 
+
+    qDebug()<<trans;
+
     trans=tr("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
     trans=XslConversion(trans);
 
+
+
     textEdit->insertHtml(trans);
 
 //  textEdit->setPlainText(trans);
index a3dd6e1..1fefc09 100644 (file)
 </xsl:template> 
 
 <xsl:template match="info">
-<<<<<<< HEAD
        <!-- <xsl:variable name="path" select="info/@path"/>-->
-       <tr bgcolor="#99FF99">
-               <th>            
+       <tr>
+               <th class="info">               
                <xsl:if test="@bookmark = 'true'">
                        <img src="mydata://image.png"/>   
                </xsl:if>
                <xsl:value-of select="."/> <!-- <img src="{$path}"/> -->
                </th>
-=======
-       <tr>
-       <th class="info"><xsl:value-of select="."/></th>
->>>>>>> 3e7118bfec64f44b11205ca836cb1a82c725d123
        </tr>
 </xsl:template>
 
 <xsl:template match="key">
-<<<<<<< HEAD
-       <tr bgcolor="#99CCFF">
-       <th><xsl:value-of select="."/></th>                     
-       </tr>
-=======
        <tr>
-       <th class="key"><xsl:value-of select="."/></th>         
-        </tr>
->>>>>>> 3e7118bfec64f44b11205ca836cb1a82c725d123
+       <th class="key"><xsl:value-of select="."/></th>                 
+       </tr>
 </xsl:template> 
 
 <xsl:template match="t">
        [<p><xsl:apply-templates/></p>]
 </xsl:template> 
 
+<xsl:template match="pos">
+       (<p><xsl:apply-templates/></p>)
+</xsl:template>
+
 <xsl:template match="pot">
        ,<p><xsl:apply-templates/></p>
 </xsl:template>
        <xsl:variable name="atr" select="@c"/>
        <font color="{$atr}"> <xsl:apply-templates/></font>
 </xsl:template>
+<!--
+<xsl:template match="table">
+       <table>
+       <xsl:apply-templates/>
+       </table>
+</xsl:template>
+
+<xsl:template match="tr">
+       <tr>
+       <xsl:apply-templates/>
+       </tr>
+</xsl:template>
+
+<xsl:template match="td">
+       <td>
+       <xsl:apply-templates/>
+       </td>
+</xsl:template>        -->
 
 </xsl:stylesheet> 
index bb1acf0..6c4baa6 100644 (file)
@@ -115,6 +115,7 @@ CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const
             plugin->settings()->setValue(key, settings->value(key));
     }
     delete settings;
+    plugin->getDictionaryInfo();
     return plugin;
 }
 
@@ -137,8 +138,8 @@ Translation* GooglePlugin::getTranslationFor(QString key) {
 
 QList<Translation*> GooglePlugin::searchWordList(QString word, int limit) {
     QList<Translation*> translations;
-    QString url = QString("/translate_a/t?client=t&sl=%1+&tl=%2").arg(_langFrom,_langTo);
-    qDebug()<<url;
+    QString url = QString("/translate_a/t?client=t&sl=%1&tl=%2").arg(_langFrom,
+                                                                     _langTo);
     QHttpRequestHeader head = QHttpRequestHeader("POST", url, 1,1);
     head.setValue("Host", "www.google.pl");
     head.setValue("User-Agent", "Mozilla/5.0");
@@ -154,9 +155,9 @@ QList<Translation*> GooglePlugin::searchWordList(QString word, int limit) {
     while(wait);
 
     QString text = QString::fromUtf8(http->readAll());
-
     text=jsonParse(text);
-    if(text!=""){
+
+    if(text!="") {
         text=tr("<key>") + word + tr("</key>") + tr("<t>") + text + tr("</t>");
         translations<<(new TranslationGoogle(word,text,_infoNote,this));
     }
@@ -167,7 +168,6 @@ QString GooglePlugin::jsonParse(QString result) {
     int pos=0,pos2=0;
     int index=0;
     int size=0;
-
     QString returnLang;
     QString translation;
     QString original;
@@ -193,28 +193,40 @@ QString GooglePlugin::jsonParse(QString result) {
         pos=result.indexOf("\"",pos+1);
         pos=result.indexOf("\"",pos+1);
         pos=result.indexOf("\"",pos+1);
+        QList<QString> *list=new QList<QString>;
         while(pos2>pos && pos2!=-1 && pos!= -1) {
             index++;
             if(size==index)
                 return QString("");
-            QList<QString> *list=new QList<QString>;
             list->append(list1.at(index*2+1));
-            words.append(list);
             pos=result.indexOf("\"",pos+1);
             pos=result.indexOf("\"",pos+1);
         }
+        words.append(list);
         index++;
         if(size==index)
             return QString("");
         pos=pos2+2;
     }
-    returnLang=list1.at(index*2+1);
-
-    if(returnLang!=_langFrom)
+    if(words.size()!=partOfSpeach.size()) {
+        qDebug()<<"Error in Google Plugin (JsonParse)";
         return QString("");
-
-    //result=translation;
-
+    }
+    returnLang=list1.at(index*2+1);
+    if(partOfSpeach.size()==0){
+        if(translation==original){
+            qDebug()<<"This word don't exist";
+            return QString("");
+        }
+        else
+            return "\""+translation+"\"";
+    }
+    result=translation;
+    for(int i=0; i<words.size();i++) {
+        result+="<pos>"+partOfSpeach.at(i)+"</pos>:";
+        for(int j=0; j<words.at(i)->size();j++)
+            result+=words.at(i)->at(j)+" ";
+    }
     return result;
 }
 
@@ -222,10 +234,6 @@ void GooglePlugin::done() {
     wait=false;
 }
 
-void GooglePlugin::started(int a) {
-    qDebug()<<"test";
-}
-
 void GooglePlugin::stop() {
     stopped=true;
 }
@@ -341,4 +349,12 @@ void GooglePlugin::initLanguages() {
     languages["UNKNOWN"] = "";
 }
 
+void GooglePlugin::getDictionaryInfo() {
+    QString fullLangFrom=languages.key(_langFrom);
+    QString fullLangTo=languages.key(_langTo);
+    _infoNote=" [" + fullLangFrom + "-";
+    _infoNote+= fullLangTo + "] (" + _type + ")";
+}
+
+
 Q_EXPORT_PLUGIN2(google, GooglePlugin)
index 632b04d..499e415 100644 (file)
@@ -112,11 +112,11 @@ public slots:
     void stop();
 
     void done();
-    void started(int);
 
 private:
     void initLanguages();
     QString jsonParse(QString result);
+    void getDictionaryInfo();
     QMap<QString, QString> languages;
 
     //! language from which we translate
index 9db6069..d8c33dc 100644 (file)
@@ -23,12 +23,14 @@ QString TranslationGoogle::dictionaryInfo() const {
 
 QString TranslationGoogle::toHtml() const {
     QString result("");
-    if(googlePlugin) {
-        result+="<dict> <info bookmark=\"false\">GOOGLE TRANSLATOR </info>";
-        result+=_trans +"</dict>";
-    }
-    qDebug()<<"test"+result;
-    return result;
+    if(!googlePlugin)
+        return result;
+    result="<dict> <info path=\"\" ";
+    if(isBookmark())
+        result+="bookmark=\"true\" >";
+    else
+        result+="bookmark=\"false\" >";
+    result+=_dictionaryInfo+ "</info>"+_trans +"</dict>";
 }
 
 void TranslationGoogle::setKey(QString) {
index be9d2e2..09924e0 100644 (file)
@@ -28,14 +28,6 @@ void GoogleTest::getNew() {
     Settings *settings=new Settings;
     settings->setValue("langFrom","pl");
     settings->setValue("langTo","en");
-
-
-jsonParse(QString result)
-
-
-
-    while(1)
-        qDebug()<<signa.count();
 }
 
 QTEST_MAIN(GoogleTest)
index 15eb1e7..450d209 100644 (file)
@@ -364,7 +364,7 @@ void XdxfPlugin::getDictionaryInfo() {
 //  qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
 //  qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
 
-    _infoNote="path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom + "-" + _langTo + "] "+ "(" + _type + ")";
+    _infoNote="path=\""+initialPath+"\"> \n" + _name + " [" + _langFrom + "-" + _langTo + "] (" + _type + ")";
 
     dictionaryFile.close();
 }