Added word counting function in xdxf plugin
authorBartosz Szatkowski <bulislaw@linux.com>
Thu, 12 Aug 2010 14:51:34 +0000 (16:51 +0200)
committerBartosz Szatkowski <bulislaw@linux.com>
Thu, 12 Aug 2010 14:51:34 +0000 (16:51 +0200)
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h

index 8dcff29..1e753d0 100644 (file)
@@ -252,18 +252,6 @@ void XdxfPlugin::getDictionaryInfo() {
     if(dictionaryReader.name()=="description")
         _infoNote=dictionaryReader.readElementText();
 
-    /*dictionaryFile.seek(0);
-
-    long wordsCount = 0;
-
-    QString line;
-    while(!dictionaryFile.atEnd()) {
-        line = dictionaryFile.readLine();
-        if(line.contains("<ar>")) {
-            wordsCount++;
-        }
-    }*/
-
     dictionaryFile.close();
 }
 
@@ -286,4 +274,28 @@ QIcon* XdxfPlugin::icon() {
     return &_icon;
 }
 
+int XdxfPlugin::countWords() {
+
+    QFile dictionaryFile(path);
+    if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+        qDebug()<<"Error: could not open file";
+        return -1;
+    }
+
+    dictionaryFile.seek(0);
+
+    long wordsCount = 0;
+
+    QString line;
+    while(!dictionaryFile.atEnd()) {
+        line = dictionaryFile.readLine();
+        if(line.contains("<ar>")) {
+            wordsCount++;
+        }
+    }
+    _wordsCount = wordsCount;
+    dictionaryFile.close();
+    return wordsCount;
+}
+
 Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
index ca1cb4a..b0722cb 100644 (file)
@@ -114,6 +114,7 @@ private:
 
     QList<Translation*> searchWordListCache(QString word, int limit=0);
     QList<Translation*> searchWordListFile(QString word, int limit=0);
+    int countWords();
 
     //! language from which we translate
     QString _langFrom;