Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / plugins / stardict / StarDictPlugin.cpp
index b12f843..67e2db3 100644 (file)
     Copyright 2010 Comarch S.A.
 
 *******************************************************************************/
+/*!
+     \file StarDictPlugin.cpp
+     \brief Implementation of stardict plugin's main class.
 
-/*! \file stardictplugin.cpp
+     \author Jakub Jaszczynski
 */
 
 #include "StarDictPlugin.h"
 
-
+/**/
 uint qHash(const TranslationStarDict &key) {
    return qHash(key.key());
 }
@@ -40,10 +43,12 @@ StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
 
     _settings->setValue("type","stardict");
     _icon = QIcon("/usr/share/mdictionary/stardict.png");
-    _wordsCount = -1;
     stopped = false;
 
+    _settings->setValue("strip_accents","true");
+
     initAccents();
+
 }
 
 
@@ -52,7 +57,7 @@ void StarDictPlugin::retranslate() {
     QTranslator *translator = new QTranslator(this);
 
     if(!translator->load(":/stardict/translations/" + locale)) {
-        translator->load(":/stardicts/translations/en_US");
+        translator->load(":/stardict/translations/en_US");
     }
     QCoreApplication::installTranslator(translator);
 }
@@ -99,17 +104,18 @@ QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
     QString idxPath = settings()->value("idxFileName");
     StarDictReader * reader = StarDictReaderFactory::createReader(idxPath);
     QString fkey;
-    qint64 offset = 0, len = 0;
-    QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
+    qint64 offset = 0,
+    len = 0;
 
     if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
         word.indexOf("_")==-1 && word.indexOf("%")==-1)
         word+="*";
-
+    QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
 
     if((settings()->value("idxoffsetbits") == "32") ||
                          (settings()->value("idxoffsetbits") == ""))
         is32b = true;
+
     if(!err)
         return QList<Translation*>();
 
@@ -123,9 +129,9 @@ QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
             offset = reader->readInt64BigEndian();
         len = reader->readInt32BigEndian();
 
-        if(keyword.exactMatch(fkey)) {
+        if(keyword.exactMatch(fkey) ) {
             TranslationStarDict tran(fkey, infoNote(), this);
-            qDebug() << "off/len" << offset << len;
+  //        qDebug() << "off/len" << offset << len;
             int id = translations.indexOf(tran);
             if(id == -1) {
                 tran.add(offset, len);
@@ -150,10 +156,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++)
@@ -163,22 +165,24 @@ QByteArray StarDictPlugin::read(QByteArray::iterator it,
 
 
 QString StarDictPlugin::interpret(QByteArray::iterator it,
-        QByteArray::iterator end, QChar mode,QString key, bool last) {
+        QByteArray::iterator end, QChar mode,QString key, bool) {
     QString result;
-    qDebug()<<"****** mode:     "<<mode;
-    if(mode == 'm'){
-        result += "<key>" + key + "</key>";
-        result += QString::fromUtf8(read(it++, end));
-    }
-    else if(mode == 'l'){
+//    qDebug()<<"****** mode:     "<<mode;
+    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 +191,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,29 +201,8 @@ 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
+// W & P 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)
  /*
     }
@@ -250,8 +229,6 @@ QString StarDictPlugin::interpret(QByteArray::iterator it,
         } else
             result += read(it++, end);
     } */
-
-    qDebug()<<"wynik  "<<result;
     return result;
 }
 
@@ -273,7 +250,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 +305,6 @@ Settings* StarDictPlugin::settings() {
 }
 
 
-bool StarDictPlugin::isCached() {
-    return false;
-}
-
-
 bool StarDictPlugin::setSettings(const Settings *sett) {
     if(sett) {
         foreach(QString key, sett->keys())
@@ -372,16 +343,4 @@ QIcon* StarDictPlugin::icon() {
     return &_icon;
 }
 
-
-int StarDictPlugin::countWords() {
-    return 0;
-}
-
-
-
-void StarDictPlugin::clean() {
-
-}
-
-
 Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)