Merge branch 'stardict' of ssh://drop.maemo.org/git/mdictionary into stardict
authorPrzemyslaw Wojtysiak <pwojtysiak88@gmail.com>
Tue, 5 Oct 2010 13:44:50 +0000 (15:44 +0200)
committerPrzemyslaw Wojtysiak <pwojtysiak88@gmail.com>
Tue, 5 Oct 2010 13:44:50 +0000 (15:44 +0200)
Conflicts:
src/plugins/stardict/stardict.pro

src/plugins/stardict/CompressedReader.cpp [new file with mode: 0644]
src/plugins/stardict/CompressedReader.h [new file with mode: 0644]
src/plugins/stardict/StarDialog.h
src/plugins/stardict/StarDictPlugin.cpp
src/plugins/stardict/StarDictReader.h [new file with mode: 0644]
src/plugins/stardict/StarDictReaderFactory.cpp [new file with mode: 0644]
src/plugins/stardict/StarDictReaderFactory.h [new file with mode: 0644]
src/plugins/stardict/UncompressedReader.cpp [new file with mode: 0644]
src/plugins/stardict/UncompressedReader.h [new file with mode: 0644]
src/plugins/stardict/stardict.pro

diff --git a/src/plugins/stardict/CompressedReader.cpp b/src/plugins/stardict/CompressedReader.cpp
new file mode 100644 (file)
index 0000000..c10c2fc
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "CompressedReader.h"
+#include <QtEndian>
+
+CompressedReader::CompressedReader(QObject *parent) :
+    StarDictReader(parent) {
+}
+
+CompressedReader::CompressedReader(QString filename, QObject *parent) :
+    StarDictReader(parent) {
+    open(filename);
+}
+
+CompressedReader::~CompressedReader() {
+    if(_file != NULL)
+        gzclose(_file);
+}
+
+bool CompressedReader::open(QString file) {
+    _file = gzopen(file.toStdString().c_str(), "rb");
+    if(_file == NULL)
+        return false;
+    return true;
+}
+
+void CompressedReader::close() {
+    gzclose(_file);
+    _file = NULL;
+}
+
+
+QChar CompressedReader::readChar() {
+    char c[1];
+    gzread(_file, c, 1);
+    return QChar(c[0]);
+}
+
+qint32 CompressedReader::readInt32BigEndian() {
+    qint32 value;
+    gzread(_file, (void*)(&value), 4);
+
+    return qFromBigEndian(value);
+}
+
+qint64 CompressedReader::readInt64BigEndian() {
+    qint64 value;
+    gzread(_file, (void*)(&value), 8);
+
+    return value;
+}
+
+QString CompressedReader::readKeyword() {
+    QString result;
+    QChar c;
+    c = readChar();
+
+    while(c != '\0') {
+        result += c;
+        c = readChar();
+    }
+
+    return result;
+}
+
+QString CompressedReader::readString(qint32 offset, qint32 len) {
+    char* buf;
+    buf = new char[len];
+
+    gzseek(_file, offset, SEEK_SET);
+    gzread(_file, buf, len);
+
+    QString result(buf);
+    delete [] buf;
+    return result;
+}
+
+QString CompressedReader::readString(qint64 offset, qint32 len) {
+    char* buf;
+    buf = new char[len];
+
+    gzseek(_file, offset, SEEK_SET);
+    gzread(_file, buf, len);
+
+    QString result(buf);
+    delete [] buf;
+    return result;
+}
+
diff --git a/src/plugins/stardict/CompressedReader.h b/src/plugins/stardict/CompressedReader.h
new file mode 100644 (file)
index 0000000..ab5caba
--- /dev/null
@@ -0,0 +1,107 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef COMPRESSEDREADER_H
+#define COMPRESSEDREADER_H
+
+#include <QObject>
+#include <zconf.h>
+#include <zlibdefs.h>
+#include <zlib.h>
+#include "StarDictReader.h"
+
+/*!
+  Class implementing StarDictReader interface and handling rading from compressed
+    files like .gz or .dz, using zlib
+  */
+class CompressedReader : public StarDictReader
+{
+    Q_OBJECT
+public:
+    CompressedReader(QObject *parent = 0);
+    /*!
+      Creates new compressed reader and open file with passed filename
+      */
+    CompressedReader(QString filename, QObject *parent = 0);
+    /*!
+      Destructs object and closing file
+    */
+    ~CompressedReader();
+
+    /*!
+      Reads translations text from compressed dict file.
+      \param offset 32-bit offset of translation in uncompressed file, readed
+             from idx file
+      \param len length of uncompressed translation, readed from idx file too
+      */
+    QString readString(qint32 offset, qint32 len);
+
+    /*!
+      Reads translations text from compressed dict file.
+      \param offset 64-bit offset of translation in uncompressed file, readed
+             from idx file
+      \param len length of uncompressed translation, readed from idx file too
+      */
+    QString readString(qint64 offset, qint32 len);
+
+    /*!
+      Reads 32-bits integer value from compressed file and convert it from
+      BigEndian to Little Endian
+      */
+    qint32 readInt32BigEndian();
+
+    /*!
+      Reads 64-bits integer value from compressed file and convert it from
+      BigEndian to Little Endian
+      */
+    qint64 readInt64BigEndian();
+
+    /*!
+      Reads single string from compressed file, end of string is marked as '\0'
+     in file.
+     */
+    QString readKeyword();
+
+
+    /*!
+      Closing file;
+      */
+    void close();
+
+protected:
+    /*!
+      Opens file
+      \returns true if file is opened or false otherwise
+      */
+    bool open(QString file);
+
+    /*!
+      Reads single char from compressed.
+     */
+    QChar readChar();
+
+private:
+    gzFile _file;
+};
+
+#endif // COMPRESSEDREADER_H
index 85a08cc..5348b17 100644 (file)
@@ -33,7 +33,7 @@
 #include "StarDictPlugin.h"
 
 
-//! Implementation of xdxf plugin's dialogs.
+//! Implementation of stardict plugin's dialogs.
 /*!
     This class can create dialogs for adding a new dictionary or changing settings
      of an existing one, based on dialog type passed to contructor.
index 88acba9..9879e12 100644 (file)
@@ -19,8 +19,7 @@
 
 *******************************************************************************/
 
-/*! \file xdxfplugin.cpp
-\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+/*! \file stardictplugin.cpp
 */
 
 #include "StarDictPlugin.h"
@@ -39,7 +38,7 @@ StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
             this, SIGNAL(notify(Notify::NotifyType,QString)));
 
 
-    _settings->setValue("type","xdxf");
+    _settings->setValue("type","stardict");
     _icon = QIcon("/usr/share/mdictionary/xdxf.png");
     _wordsCount = -1;
     stopped = false;
@@ -91,136 +90,19 @@ QString StarDictPlugin::infoNote() const {
 
 
 QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
-    if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
-        word.indexOf("_")==-1 && word.indexOf("%")==-1)
-        word+="*";
-
-    if(isCached())
-        return searchWordListCache(word,limit);
-    return searchWordListFile(word, limit);
-}
-
-
-
-QList<Translation*> StarDictPlugin::searchWordListFile(QString word, int limit) {
     QSet<Translation*> translations;
-    QFile dictionaryFile(_settings->value("path"));
-    word = word.toLower();
-    stopped = false;
-
-    QRegExp regWord(word);
-    regWord.setCaseSensitivity(Qt::CaseInsensitive);
-    regWord.setPatternSyntax(QRegExp::Wildcard);
-
-    /*check xdxf file exist*/
-    if(!QFile::exists(_settings->value("path"))
-                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        qDebug()<<"Error: could not open file";
-        Q_EMIT notify(Notify::Warning,
-                QString(tr("XDXF file cannot be read for %1").arg(name())));
-        return translations.toList();
-    }
-
-    QXmlStreamReader reader(&dictionaryFile);
-    QString readKey;
-    int i=0;
-
-    /*search words list*/
-    while(!reader.atEnd() && !stopped){
-        reader.readNextStartElement();
-        if(reader.name()=="ar") {
-            while(reader.name()!="k" && !reader.atEnd())
-                reader.readNextStartElement();
-            if(!reader.atEnd())
-                readKey = reader.readElementText();
-            if((regWord.exactMatch(readKey)
-                    || regWord.exactMatch(removeAccents(readKey)))
-                    && (i<limit || limit==0) && !reader.atEnd())  {
- //               qDebug()<<readKey;
-                translations<<(new TranslationStarDict(readKey.toLower(),
-                               _dictionaryInfo,this));
-                if(translations.size()==limit && limit!=0)
-                    break;
-            }
-        }
-        this->thread()->yieldCurrentThread();
-    }
-    stopped=false;
-    dictionaryFile.close();
     return translations.toList();
 }
 
 
+
 QString StarDictPlugin::search(QString key) {
-    return searchFile(key);
+    return "";
 }
 
 
 
-QString StarDictPlugin::searchFile(QString key) {
-    QFile dictionaryFile(_settings->value("path"));
-    QString resultString("");
-    key = key.toLower();
-
-    /*check xdxf file exist*/
-    if(!QFile::exists(_settings->value("path"))
-                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        Q_EMIT notify(Notify::Warning,
-                QString(tr("XDXF file cannot be read for %1").arg(name())));
-        qDebug()<<"Error: could not open file";
-        return "";
-    }
-
-    QXmlStreamReader reader(&dictionaryFile);
-    QString readKey;
-    bool match =false;
-    stopped = false;
-
-    /*search translations for word*/
-    while (!reader.atEnd()&& !stopped) {
-        reader.readNext();
-        if(reader.tokenType() == QXmlStreamReader::StartElement) {
-            if(reader.name()=="k") {
-                readKey = reader.readElementText();
-                if(readKey.toLower()==key.toLower())
-                    match = true;
-            }
-        }
-        if(match) {
-            QString temp("");
-            while(reader.name()!="ar" && !reader.atEnd()) {
-                if(reader.name()!="" && reader.name()!="k") {
-                    if(reader.tokenType()==QXmlStreamReader::EndElement)
-                        temp+="</";
-                    if(reader.tokenType()==QXmlStreamReader::StartElement)
-                        temp+="<";
-                    temp+=reader.name().toString();
-                    if(reader.name().toString()=="c" &&
-                            reader.tokenType()==QXmlStreamReader::StartElement)
-                       temp= temp + " c=\"" + reader.attributes().
-                               value("c").toString() + "\"";
-                    temp+=">";
-                }
-                temp+= reader.text().toString().replace("<","&lt;").
-                        replace(">","&gt;");
-                reader.readNext();
-            }
-            if(temp.at(0)==QChar('\n'))
-                temp.remove(0,1);
-            resultString+="<key>" + readKey +"</key>";
-            resultString+="<t>" + temp + "</t>";
-            match=false;
-        }
-        this->thread()->yieldCurrentThread();
-    }
-    stopped=false;
-    dictionaryFile.close();
-    return resultString;
-}
-
-
 void StarDictPlugin::stop() {
-   //qDebug()<<"stop";
     stopped=true;
 }
 
@@ -266,58 +148,14 @@ Settings* StarDictPlugin::settings() {
 
 
 bool StarDictPlugin::isCached() {
-    if(_settings->value("cached") == "true")
-        return true;
     return false;
 }
 
 
 bool StarDictPlugin::setSettings(const Settings *settings) {
     if(settings) {
-        bool isPathChange=false;
-        QString oldPath = _settings->value("path");
-        Settings *oldSettings =  new Settings ;
-
-        if(oldPath != settings->value("path")) {
-            if(oldPath!="" && _settings->value("cache_path")!="")
-                clean();
-            isPathChange=true;
-        }
-
-        foreach(QString key, _settings->keys())
-            oldSettings->setValue(key, _settings->value(key));
-
-        foreach(QString key, settings->keys()) {
-           if(key != "generateCache")
-               _settings->setValue(key, settings->value(key));
-        }
-
-        if(!getDictionaryInfo()) {
-            Q_EMIT notify(Notify::Warning,
-                QString(tr("XDXF file is in wrong format")));
-            qDebug()<<"Error: xdxf file is in wrong format";
-            delete _settings;
-            _settings=oldSettings;
-            return false;
-        }
-
-        if(isPathChange) {
-            _wordsCount=0;
-            if(oldPath!="")
-                _settings->setValue("cached","false");
-        }
-
-        if((_settings->value("cached") == "false" ||
-            _settings->value("cached").isEmpty()) &&
-            settings->value("generateCache") == "true") {
-            clean();
-        }
-
-        else if (settings->value("generateCache") == "false") {
-            _settings->setValue("cached", "false");
-        }
-    }
-    else
+
+    } else
         return false;
     Q_EMIT settingsChanged();
     return true;
@@ -329,38 +167,11 @@ bool StarDictPlugin::getDictionaryInfo() {
     if(!QFile::exists(_settings->value("path"))
                 || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
        Q_EMIT notify(Notify::Warning,
-               QString(tr("XDXF dictionary cannot be read from file")));
-        qDebug()<<"Error: could not open file";
+               QString(tr("StarDict dictionary cannot be read from file")));
+        qDebug()<<"Error: could not open the file";
         return false;
     }
 
-    bool okFormat=false;
-    QXmlStreamReader reader(&dictionaryFile);
-    reader.readNextStartElement();
-    if(reader.name()=="xdxf") {
-        okFormat=true;
-        if(reader.attributes().hasAttribute("lang_from"))
-            _langFrom = reader.attributes().value("lang_from").toString();
-        if(reader.attributes().hasAttribute("lang_to"))
-            _langTo = reader.attributes().value("lang_to").toString();
-    }
-    reader.readNextStartElement();
-    if(reader.name()=="full_name")
-        _name=reader.readElementText();
-    else
-        qDebug()<<"no full_name";
-    reader.readNextStartElement();
-    if(reader.name()=="description")
-        _infoNote=reader.readElementText();
-    else
-        qDebug()<<"no description";
-
-    _dictionaryInfo= _name + " [" + _langFrom + "-"
-                + _langTo + "]";
-
-    dictionaryFile.close();
-    if(okFormat)
-        return true;
     return false;
 }
 
@@ -371,32 +182,7 @@ QIcon* StarDictPlugin::icon() {
 
 
 int StarDictPlugin::countWords() {
-    if(_wordsCount>0)
-        return _wordsCount;
-    QFile dictionaryFile(_settings->value("path"));
-    if(!QFile::exists(_settings->value("path"))
-                || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
-        Q_EMIT notify(Notify::Warning,
-                QString(tr("XDXF file cannot be read for %1 dictionary")
-                .arg(name())));
-        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("<k>")) {
-            wordsCount++;
-        }
-    }
-    _wordsCount = wordsCount;
-    dictionaryFile.close();
-    return wordsCount;
+    return 0;
 }
 
 
diff --git a/src/plugins/stardict/StarDictReader.h b/src/plugins/stardict/StarDictReader.h
new file mode 100644 (file)
index 0000000..035d5e5
--- /dev/null
@@ -0,0 +1,92 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*!
+    \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+ */
+
+#ifndef STARDICTREADER_H
+#define STARDICTREADER_H
+
+#include <QObject>
+
+/*!
+  Abstract class used for reading stardict dict and idx files.
+  It allows to read all necessary data types used in parsing stardict files.
+  */
+class StarDictReader : public QObject {
+    Q_OBJECT
+public:
+    StarDictReader(QObject *parent = 0) : QObject(parent) {}
+    virtual ~StarDictReader() {}
+
+    /*!
+      Reads translations text from dict file.
+      \param offset 32-bit offset of translation in file, readed from idx file
+      \param len length of translation, readed from idx file too
+      */
+    virtual QString readString(qint32 offset, qint32 len)=0;
+
+    /*!
+      Reads translations text from dict file.
+      \param offset 64-bit offset of translation in file, readed from idx file
+      \param len length of translation, readed from idx file too
+      */
+    virtual QString readString(qint64 offset, qint32 len)=0;
+
+    /*!
+      Reads 32-bits integer value from file and convert it from BigEndian
+        to Little Endian
+      */
+    virtual qint32 readInt32BigEndian()=0;
+
+    /*!
+      Reads 64-bits integer value from file and convert it from BigEndian
+        to Little Endian
+      */
+    virtual qint64 readInt64BigEndian()=0;
+
+    /*!
+      Reads single string from file, end of string is marked as '\0' in file.
+     */
+    virtual QString readKeyword()=0;
+
+
+    /*!
+      Closing file;
+      */
+    virtual void close()=0;
+
+protected:
+    /*!
+      Opens file
+      \returns true if file is opened or false otherwise
+      */
+    virtual bool open(QString file)=0;
+
+    /*!
+      Reads single char from file.
+     */
+    virtual QChar readChar()=0;
+
+};
+
+#endif // STARDICTREADER_H
diff --git a/src/plugins/stardict/StarDictReaderFactory.cpp b/src/plugins/stardict/StarDictReaderFactory.cpp
new file mode 100644 (file)
index 0000000..498bdfc
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "StarDictReaderFactory.h"
+#include "CompressedReader.h"
+#include "UncompressedReader.h"
+
+
+StarDictReader* StarDictReaderFactory::createReader(QString filename) {
+    if(filename.endsWith(".gz", Qt::CaseInsensitive) ||
+       filename.endsWith(".dz", Qt::CaseInsensitive)) {
+        return new CompressedReader(filename);
+    }
+    else {
+        return new UncompressedReader(filename);
+    }
+}
+
diff --git a/src/plugins/stardict/StarDictReaderFactory.h b/src/plugins/stardict/StarDictReaderFactory.h
new file mode 100644 (file)
index 0000000..a6e12e3
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef STARDICTREADERFACTORY_H
+#define STARDICTREADERFACTORY_H
+#include "StarDictReader.h"
+
+/*!
+  Class used to creating StarDictReader objects, based on filename it creates
+  compressed or uncompressed reader.
+  */
+class StarDictReaderFactory
+{
+public:
+    //! Creates new StarDictReader suitable for passed file
+    static StarDictReader* createReader(QString file);
+};
+
+#endif // STARDICTREADERFACTORY_H
diff --git a/src/plugins/stardict/UncompressedReader.cpp b/src/plugins/stardict/UncompressedReader.cpp
new file mode 100644 (file)
index 0000000..15102ef
--- /dev/null
@@ -0,0 +1,89 @@
+#include "UncompressedReader.h"
+
+
+UncompressedReader::UncompressedReader(QObject *parent) :
+        StarDictReader(parent) {
+
+}
+
+UncompressedReader::UncompressedReader(QString filename, QObject *parent) :
+StarDictReader(parent) {
+    open(filename);
+}
+
+UncompressedReader::~UncompressedReader() {
+    if(_file.isOpen())
+        _file.close();
+}
+
+bool UncompressedReader::open(QString file) {
+    _file.setFileName(file);
+    _stream.setDevice(&_file);
+    return _file.open(QFile::ReadOnly);
+}
+
+void UncompressedReader::close() {
+    _file.close();
+}
+
+QChar UncompressedReader::readChar() {
+    char c[1];
+
+    _stream.readRawData(c, 1);
+    return QChar(c[0]);
+}
+
+QString UncompressedReader::readKeyword() {
+    QString result;
+    QChar c;
+    c = readChar();
+
+    while(c != '\0') {
+        result += c;
+        c = readChar();
+    }
+
+    return result;
+}
+
+QString UncompressedReader::readString(qint32 offset, qint32 len) {
+    char* buf;
+    buf = new char[len];
+
+    _file.seek(offset);
+    _stream.readRawData(buf, len);
+
+    QString result(buf);
+    delete [] buf;
+    return result;
+}
+
+QString UncompressedReader::readString(qint64 offset, qint32 len) {
+    char* buf;
+    buf = new char[len];
+
+    _file.seek(offset);
+    _stream.readRawData(buf, len);
+
+    QString result(buf);
+    delete [] buf;
+    return result;
+}
+
+qint32 UncompressedReader::readInt32BigEndian() {
+    _stream.setByteOrder(QDataStream::BigEndian);
+    qint32 value;
+    _stream>>value;
+    _stream.setByteOrder(QDataStream::LittleEndian);
+
+    return value;
+}
+
+qint64 UncompressedReader::readInt64BigEndian() {
+    _stream.setByteOrder(QDataStream::BigEndian);
+    qint64 value;
+    _stream>>value;
+    _stream.setByteOrder(QDataStream::LittleEndian);
+
+    return value;
+}
diff --git a/src/plugins/stardict/UncompressedReader.h b/src/plugins/stardict/UncompressedReader.h
new file mode 100644 (file)
index 0000000..462e08d
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#ifndef UNCOMPRESSEDREADER_H
+#define UNCOMPRESSEDREADER_H
+
+#include <QObject>
+#include <QFile>
+#include <QDataStream>
+#include <QString>
+#include "StarDictReader.h"
+
+
+/*!
+  Class implementing StarDictReader interface and handling rading from uncompressed files
+  */
+class UncompressedReader : public StarDictReader
+{
+    Q_OBJECT
+public:
+    UncompressedReader(QObject *parent = 0);
+
+    /*!
+      Creates new reader and open file with passed filename
+      */
+    UncompressedReader(QString filename, QObject *parent = 0);
+
+    /*!
+      Destructs object and closing file
+    */
+    ~UncompressedReader();
+
+    /*!
+      Reads translations text from file
+      \param offset 32-bit offset of translation in file, readed
+             from idx file
+      \param len length of translation, readed from idx file too
+      */
+    QString readString(qint32 offset, qint32 len);
+
+    /*!
+      Reads translations text from file
+      \param offset 64-bit offset of translation in file, readed
+             from idx file
+      \param len length of translation, readed from idx file too
+      */
+    QString readString(qint64 offset, qint32 len);
+
+    /*!
+      Reads 32-bits integer value from file and convert it from
+      BigEndian to Little Endian
+      */
+    qint32 readInt32BigEndian();
+
+    /*!
+      Reads 64-bits integer value from file and convert it from
+      BigEndian to Little Endian
+      */
+    qint64 readInt64BigEndian();
+
+    /*!
+      Reads single string from file, end of string is marked as '\0'
+     in file.
+     */
+    QString readKeyword();
+
+
+    /*!
+      Closing file;
+      */
+    void close();
+
+protected:
+    /*!
+      Opens file
+      \returns true if file is opened or false otherwise
+      */
+    bool open(QString file);
+
+    /*!
+      Reads single char from compressed.
+     */
+    QChar readChar();
+
+private:
+    QFile _file;
+    QDataStream _stream;
+};
+
+#endif // UNCOMPRESSEDREADER_H
index c1cd23e..93c4f12 100644 (file)
@@ -9,12 +9,17 @@ QT = core \
 
 maemo5:QT += maemo5
 
+LIBS += -lz
+
 SOURCES +=  \
     StarDictPlugin.cpp \
     TranslationStarDict.cpp \
     StarDictDialog.cpp \
     StarDialog.cpp \
     StarDictSettings.cpp
+    CompressedReader.cpp \
+    UncompressedReader.cpp \
+    StarDictReaderFactory.cpp
 
 
 HEADERS += \
@@ -27,6 +32,10 @@ HEADERS += \
     ../../include/CommonDictInterface.h \
     StarDialog.h \
     StarDictSettings.h
+    CompressedReader.h \
+    UncompressedReader.h \
+    StarDictReaderFactory.h \
+    StarDictReader.h
 
 RESOURCES += \
     StarDict.qrc