fix bug's (translation color in stardict and kept settings after leave)
[mdictionary] / src / plugins / stardict / StarDictPlugin.cpp
index b12f843..f30dbc8 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "StarDictPlugin.h"
 
-
+/**/
 uint qHash(const TranslationStarDict &key) {
    return qHash(key.key());
 }
@@ -40,7 +40,6 @@ StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
 
     _settings->setValue("type","stardict");
     _icon = QIcon("/usr/share/mdictionary/stardict.png");
-    _wordsCount = -1;
     stopped = false;
 
     initAccents();
@@ -106,10 +105,10 @@ QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
         word.indexOf("_")==-1 && word.indexOf("%")==-1)
         word+="*";
 
-
     if((settings()->value("idxoffsetbits") == "32") ||
                          (settings()->value("idxoffsetbits") == ""))
         is32b = true;
+
     if(!err)
         return QList<Translation*>();
 
@@ -150,10 +149,6 @@ QByteArray StarDictPlugin::read(QByteArray::iterator it,
     if(bytes == 0 && it != end){
         while(*it != '\0' && it != end)
             ret.append(*it++);
-        if(it == end)
-            qDebug()<<"end";
-        else
-            qDebug()<<"000";
     }
     else
         for(int i = 0; i < bytes && it != end; i++)
@@ -166,19 +161,22 @@ QString StarDictPlugin::interpret(QByteArray::iterator it,
         QByteArray::iterator end, QChar mode,QString key, bool last) {
     QString result;
     qDebug()<<"****** mode:     "<<mode;
-    if(mode == 'm'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'l'){
+
+    if(mode == 'm' ||
+            mode == 'l' ||
+            mode == 'g' ||
+            mode == 't' ||
+            mode == 'y' ||
+            mode == 'k' ||
+            mode == 'w' ||
+            mode == 'h' ||
+            mode == 'r' ){
         result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
+        result += "<t>" + QString::fromUtf8(read(it++, end)) + "</t>";
     }
-    else if(mode ==  'g'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
 
-        /* delete "small" tag  from translation*/
+    if(mode ==  'g'){
+        /* delete "small" tag  from g translation*/
         int indexOfSmall=result.indexOf("<small>");
         while(indexOfSmall!=-1){
             int indexOfEndSmall= result.indexOf("</small>");
@@ -187,11 +185,7 @@ QString StarDictPlugin::interpret(QByteArray::iterator it,
             indexOfSmall=result.indexOf("<small>");
         }
     }
-    else if(mode == 't'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'x'){
+    if(mode == 'x'){
         result += QString::fromUtf8(read(it++, end));
         result.replace("</k>","</key><t>");
         result.replace("<k>","</t><key>");
@@ -201,27 +195,6 @@ QString StarDictPlugin::interpret(QByteArray::iterator it,
         if(result.contains("<t>"))
             result+="</t>";
     }
-    else if(mode == 'y') {
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'k'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'w'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'h'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'r'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-
 
 // Dont know whether mDictionary would ever handle binary stardict format
 // to be honest dont see any kind of adventages (can't find any binary dict)
@@ -273,7 +246,6 @@ QString StarDictPlugin::format(QByteArray raw, QString mode,QString key) {
 }
 
 
-
 QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
     QString dictPath = settings()->value("dictFileName");
     StarDictReader *reader = StarDictReaderFactory::createReader(dictPath);
@@ -329,11 +301,6 @@ Settings* StarDictPlugin::settings() {
 }
 
 
-bool StarDictPlugin::isCached() {
-    return false;
-}
-
-
 bool StarDictPlugin::setSettings(const Settings *sett) {
     if(sett) {
         foreach(QString key, sett->keys())
@@ -378,7 +345,6 @@ int StarDictPlugin::countWords() {
 }
 
 
-
 void StarDictPlugin::clean() {
 
 }