minor changes in plugin
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 5 Aug 2010 09:56:39 +0000 (11:56 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 5 Aug 2010 09:56:39 +0000 (11:56 +0200)
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.h
trunk/src/plugins/xdxf/tests/test.cpp
trunk/src/plugins/xdxf/tests/test.h

index 293ad72..10fa126 100644 (file)
@@ -31,8 +31,10 @@ QString XdxfPlugin::infoNote() const {
 
 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     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";
@@ -62,7 +64,6 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int 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 +79,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 +95,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 +115,11 @@ QDialog* XdxfPlugin::loadDialog() {
 }
 
 QDialog* XdxfPlugin::settingsDialog() {
-    ;
+    path="dict.xdxf";
 }
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings*) const {
+  // CommonDictInterface *commonDictInterface= new
     ;
 }
 
@@ -123,7 +127,12 @@ bool XdxfPlugin::isAvailable() const {
     return true;
 }
 
+void XdxfPlugin::setHash(uint _hash)
+{
+    this->_hash=_hash;
+}
+
 uint XdxfPlugin::hash() const
 {
-    return 1;
+   return _hash;
 }
index 8a93749..fbc78f6 100644 (file)
@@ -6,6 +6,7 @@
 #include <QDialog>
 #include <QRegExp>
 #include "TranslationXdxf.h"
+#include <QTime>
 
 class XdxfPlugin : public CommonDictInterface
 {
@@ -48,6 +49,9 @@ public:
     //! returns a unique hash for a dictionary
     uint hash() const;
 
+    //! set unique value (unique for every dictionary not plugin)
+    void setHash(uint);
+
 public Q_SLOTS:
     /*! performs search in dictionary
       \param  word word to search in dictionary
@@ -71,6 +75,7 @@ private:
     QDialog *_loadDialog;
     QDialog *_settingsDialog;
     QString path;
+    uint _hash;
     bool stopped;   /*volatile*/
 };
 
index 3ba6b25..4bba1f5 100644 (file)
@@ -7,17 +7,24 @@ void Testowanie::search()
     xdxfPlugin.loadDialog();
     xdxfPlugin.searchWordList("Cain",10);
     xdxfPlugin.search("Cain");
-    QCOMPARE(xdxfPlugin.search("cain"), QString("lina"));
-    QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
-    //QCOMPARE(xdxfPlugin.search("boss"), QString(""));
+    QCOMPARE(xdxfPlugin.search("Apacz"), QString("Apachee"));
+ //   QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
+ //   QCOMPARE(xdxfPlugin.search("boss"), QString(""));
 }
 
 void Testowanie::langFrom()
 {
     XdxfPlugin xdxfPlugin(this);
     xdxfPlugin.loadDialog();
-  //  xdxfPlugin.searchWordList("rope",10);
-    //QCOMPARE(xdxfPlugin.langFrom(), QString("ENG"));
+    xdxfPlugin.searchWordList("rope",10);
+    QCOMPARE(xdxfPlugin.langFrom(), QString("ENG"));
+}
+
+void Testowanie::hash()
+{
+    XdxfPlugin xdxfPlugin(this);
+    xdxfPlugin.loadDialog();
+    xdxfPlugin.hash();
 }
 
 void Testowanie::sig()
@@ -25,12 +32,14 @@ void Testowanie::sig()
     XdxfPlugin xdxfPlugin(this);
     xdxfPlugin.loadDialog();
 
-    QSignalSpy spy(&xdxfPlugin, SIGNAL(finalTranslation(QList<Translation*>)));
+    QSignalSpy spy(&xdxfPlugin, SIGNAL(finalTranslation()));
 
-    xdxfPlugin.searchWordList("rope",10);
+    xdxfPlugin.searchWordList("Apacz",10);
 
     QCOMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
 }
 
 QTEST_MAIN(Testowanie)
 //#include "testqstring.moc"
+
+/*duze i małe litery*/
index 9096c6d..389c754 100644 (file)
@@ -7,6 +7,7 @@
 #include "../../../includes/translation.h"
 
 #include <QList>
+#include <QTime>
 
  class Testowanie: public QObject
  {
@@ -17,6 +18,7 @@
      void search();
      void langFrom();
      void sig();
+     void hash();
  };