Merge branch 'xdxf'
[mdictionary] / trunk / src / plugins / xdxf / src / XdxfPlugin / xdxfplugin.cpp
index 4e42a97..be0e716 100644 (file)
@@ -2,12 +2,14 @@
 #include <QDebug>
 #include <QFile>
 #include <QXmlStreamReader>
+#include <QtPlugin>
 #include "TranslationXdxf.h"
 
 XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _langFrom(tr("")), _langTo(tr("")),_name(tr("")),
                     _type(tr("xdxf")), _infoNote(tr("")) {
     path="dict.xdxf";
+    stopped = false;
 }
 
 QString XdxfPlugin::langFrom() const {
@@ -31,9 +33,12 @@ QString XdxfPlugin::infoNote() const {
 }
 
 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+    stopped = false;
     QRegExp regWord(word);
-    QList<Translation*> translations;
+    regWord.setCaseSensitivity(Qt::CaseInsensitive);
     regWord.setPatternSyntax(QRegExp::Wildcard);
+
+    QList<Translation*> translations;
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
@@ -60,10 +65,9 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
         if(dictionaryReader.name()=="ar"){
             while(dictionaryReader.name()!="k" && !dictionaryReader.atEnd())
                 dictionaryReader.readNextStartElement();
-            a = dictionaryReader.readElementText();
-            if(regWord.exactMatch(a) && i<limit) {
+           a = dictionaryReader.readElementText();
+           if(regWord.exactMatch(a) && i<limit) {
                 translations.append(new TranslationXdxf(a,_infoNote,this));
-                qDebug()<<a;
                 i++;
                 if(i>=limit)
                     break;
@@ -78,7 +82,8 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
 QString XdxfPlugin::search(QString key) {
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        return ""; //blad otwarcia pliku
+        qDebug()<<"Error: could not open file";
+        return "";
     }
     QXmlStreamReader dictionaryReader(&dictionaryFile);
 
@@ -93,12 +98,13 @@ QString XdxfPlugin::search(QString key) {
                     match = true;
             }
         }
-        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)
+        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
             if(match) {
-                dictionaryFile.close();
-                qDebug()<<dictionaryReader.text().toString().replace("\n","");
-                return dictionaryReader.text().toString().replace("\n","");
+              QString temp(dictionaryReader.text().toString().replace("\n",""));
+              dictionaryFile.close();
+              return temp;
             }
+        }
     }
     return "";
 }
@@ -112,10 +118,11 @@ QDialog* XdxfPlugin::loadDialog() {
 }
 
 QDialog* XdxfPlugin::settingsDialog() {
-    ;
+    path="dict.xdxf";
 }
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
+  // CommonDictInterface *commonDictInterface= new
     ;
 }
 
@@ -123,7 +130,14 @@ bool XdxfPlugin::isAvailable() const {
     return true;
 }
 
+void XdxfPlugin::setHash(uint _hash)
+{
+    this->_hash=_hash;
+}
+
 uint XdxfPlugin::hash() const
 {
-    return 1;
+   return _hash;
 }
+
+Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)