change returned XML format in toHtml function, and add limit to search word List
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 7 Oct 2010 08:17:53 +0000 (10:17 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 7 Oct 2010 08:17:53 +0000 (10:17 +0200)
src/mdictionary/gui/TranslationWidget.cpp
src/plugins/stardict/StarDictPlugin.cpp
src/plugins/stardict/TranslationStarDict.cpp

index d9d9fb4..468087b 100644 (file)
@@ -83,7 +83,7 @@ void TranslationWidget::show(QStringList translations) {
     trans=QString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + QString("\n <ar>")
            + trans + QString("\n </ar>");
 
-
+    qDebug()<<trans;
     trans=XslConversion(trans);
 
     QString head = "<html><head>";
index d6b2f2d..3709ca4 100644 (file)
@@ -108,7 +108,7 @@ QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
     QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
 
     int counter = 0;
-    while(counter < wordcount) {
+    while(counter < wordcount && counter<limit) {
         counter++;
         fkey = reader->readKeyword();
         if(is32b)
@@ -227,7 +227,6 @@ QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
         return "";
 
     QByteArray raw = dictReader->readString(offset, len);
-
     return format(raw, settings()->value("sametypesequence"));
 }
 
index a95f285..65c60a0 100644 (file)
@@ -60,25 +60,35 @@ QString TranslationStarDict::key() const {
 }
 
 QString TranslationStarDict::toXml() const {
-    qDebug() << "asdf" << _dictionaryInfo;
+
     QString result("");
     if(!starDictPlugin)
         return result;
 
-    qDebug() << "asdf";
     for(int i = 0; i < offsets.size(); i++) {
         result=result + "<dict> <info path=\"/usr/share/mdictionary/stardict.png\" ";
         if(isBookmark())
             result+= " bookmark=\"true\" > \n";
         else
             result+= " bookmark=\"false\" > \n";
-    qDebug() << "!!asdf";
-        result+= _dictionaryInfo + "</info>" +
-                starDictPlugin->search(_key, offsets.at(i), lengths.at(i))
-                + "</dict>";
-    qDebug() << "!!!!asdf";
+            if(_dictionaryInfo.isEmpty())
+                result+= "starDict dictionary </info>";
+            else
+                result+= _dictionaryInfo +"</info>";
+
+            /*przeformatowanie zwracanego stringu na oczekiwany format*/
+            QString text =starDictPlugin->search(_key, offsets.at(i), lengths.at(i));
+            text.replace("</k>","</key><t>");
+            text.replace("<k>","</t><key>");
+            int pos=text.indexOf("</t>");
+            if(pos!=-1)
+                text.remove(pos,4);
+
+            result+= text;
+            result+= "</t> </dict>";
+            qDebug()<<"trans"<<result;
    }
-   return result.replace("&","&amp;");
+   return result;
 }
 
 void TranslationStarDict::setKey(QString _key) {