Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/dict.xdxf
trunk/src/plugins/xdxf/tests/test.cpp

index 42312e4..807937e 100644 (file)
@@ -217,17 +217,45 @@ QString XdxfPlugin::searchFile(QString key) {
         }
         else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
             if(match) {
-                QString temp(dictionaryReader.text().toString());
+ /*             QString temp(dictionaryReader.text().toString());
+                if(temp=="\n")
+                    temp=dictionaryReader.readElementText();
                 temp.replace("\n","");
                 if(temp == ""){
+                    int i=0;
                     while(dictionaryReader.name()!="ar"&&
                                 !dictionaryReader.atEnd()){
                         dictionaryReader.readNext();
+                        if(dictionaryReader.name()!="" &&
+                                         dictionaryReader.name()!="ar") {
+                            if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement)
+                                temp+=tr("</");
+                            if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
+                                temp+=tr("<");
+                            qDebug()<<dictionaryReader.tokenType();
+                            temp=temp+dictionaryReader.name().toString() + tr(">");
+                            i++;
+                        }
                         temp+=dictionaryReader.text().toString();
                     }
                 }
                 resultString+=temp.replace("\n","")+"\n";
                 match=false;
+*/
+                QString temp("");
+                while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()) {
+                    if(dictionaryReader.name()!="") {
+                        if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement)
+                            temp+=tr("</");
+                        if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
+                            temp+=tr("<");
+                        temp=temp+dictionaryReader.name().toString() + tr(">");
+                    }
+                    temp+= dictionaryReader.text().toString();
+                    dictionaryReader.readNext();
+                }
+                resultString+=tr("<t>") + temp.replace("\n","") + tr("</t>");
+                match=false;
             }
         }
         this->thread()->yieldCurrentThread();
@@ -448,15 +476,19 @@ bool XdxfPlugin::makeCache(QString dir) {
         }
         else if(reader.tokenType() == QXmlStreamReader::Characters) {
              if(match) {
-                QString temp(reader.text().toString());
-                temp.replace("\n","");
-                if(temp == ""){
-                    while(reader.name()!="ar"&&
-                                !reader.atEnd()){
-                        reader.readNext();
-                        temp+=reader.text().toString();
+                QString temp("");
+                while(reader.name()!="ar" && !reader.atEnd()) {
+                    if(reader.name()!="") {
+                        if(reader.tokenType()==QXmlStreamReader::EndElement)
+                            temp+=tr("</");
+                        if(reader.tokenType()==QXmlStreamReader::StartElement)
+                            temp+=tr("<");
+                        temp=temp+reader.name().toString() + tr(">");
                     }
+                    temp+= reader.text().toString();
+                    reader.readNext();
                 }
+                temp=tr("<t>") + temp.replace("\n","") + tr("</t>");
                 match = false;
                 cur.prepare("insert into dict values(?,?)");
                 cur.addBindValue(a);
index d217c26..d1b7d73 100644 (file)
@@ -19,4 +19,6 @@ sto</ar>
 tysišc</ar>
 <ar><k>house</k>
 dom</ar>
+<ar><k>test</k>
+<pos>krowa</pos>test01</ar>
 </xdxf>
index b06adf7..77b7d9d 100644 (file)
@@ -43,8 +43,10 @@ void XdxfTest::search() {
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
 
     xdxfPlugin->search("wino");
-    QCOMPARE(xdxfPlugin->search("."), QString("kropka\n"));
-    QCOMPARE(xdxfPlugin->search("1"), QString("one\n"));
+    QCOMPARE(xdxfPlugin->search("."), QString("<t>kropka</t>"));
+    QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
+
+    QCOMPARE(xdxfPlugin->search("test"), QString("<t><pos>krowa</pos>test01</t>"));
 }
 
 void XdxfTest::searchWordList() {
@@ -56,7 +58,7 @@ void XdxfTest::searchWordList() {
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
     if(te.size()>0)
-        QCOMPARE(te.size(), 8);
+        QCOMPARE(te.size(), 9);
     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
     QCOMPARE(te2.size(), 5);
 
@@ -67,7 +69,7 @@ void XdxfTest::searchWordList() {
         QCOMPARE(te4.at(0)->key(), QString("house"));
 
     QList<Translation*> te5 = xdxfPlugin->searchWordList("*");
-        QCOMPARE(te5.size(), 8);
+        QCOMPARE(te5.size(), 9);
 
     QList<Translation*> te6 = xdxfPlugin->searchWordList("*", 8);
         QCOMPARE(te6.size(), 8);
@@ -103,7 +105,7 @@ void XdxfTest::stop() {
     QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
     QList<Translation*> te5 = future.result();
 
-    QCOMPARE(te5.size(), 8);
+    QCOMPARE(te5.size(), 9);
 }