--- /dev/null
+/*******************************************************************************
+
+ 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;
+}
+
--- /dev/null
+/*******************************************************************************
+
+ 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 CompressedReader : public StarDictReader
+{
+ Q_OBJECT
+public:
+ CompressedReader(QObject *parent = 0);
+ CompressedReader(QString filename, QObject *parent = 0);
+ ~CompressedReader();
+
+ QString readString(qint32 offset, qint32 len);
+ QString readString(qint64 offset, qint32 len);
+ QChar readChar();
+ qint32 readInt32BigEndian();
+ qint64 readInt64BigEndian();
+ QString readKeyword();
+ bool open(QString file);
+ void close();
+private:
+ gzFile _file;
+};
+
+#endif // COMPRESSEDREADER_H
--- /dev/null
+/*******************************************************************************
+
+ 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 STARDICTREADER_H
+#define STARDICTREADER_H
+
+#include <QObject>
+
+class StarDictReader : public QObject {
+ Q_OBJECT
+public:
+ StarDictReader(QObject *parent = 0) : QObject(parent) {}
+ virtual ~StarDictReader() {}
+
+ virtual QString readString(qint32 offset, qint32 len)=0;
+ virtual QString readString(qint64 offset, qint32 len)=0;
+ virtual QChar readChar()=0;
+ virtual qint32 readInt32BigEndian()=0;
+ virtual qint64 readInt64BigEndian()=0;
+ virtual QString readKeyword()=0;
+ virtual bool open(QString file)=0;
+ virtual void close()=0;
+};
+
+#endif // STARDICTREADER_H
--- /dev/null
+/*******************************************************************************
+
+ 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) {
+ StarDictReader* reader;
+ if(filename.endsWith(".gz", Qt::CaseInsensitive) ||
+ filename.endsWith(".dz", Qt::CaseInsensitive)) {
+ reader = new CompressedReader();
+ }
+ else {
+ reader = new UncompressedReader();
+ }
+
+ reader->open(filename);
+ return reader;
+}
+
--- /dev/null
+/*******************************************************************************
+
+ 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 StarDictReaderFactory
+{
+public:
+ static StarDictReader* createReader(QString file);
+};
+
+#endif // STARDICTREADERFACTORY_H
--- /dev/null
+#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;
+}
--- /dev/null
+/*******************************************************************************
+
+ 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 UncompressedReader : public StarDictReader
+{
+ Q_OBJECT
+public:
+ UncompressedReader(QObject *parent = 0);
+ UncompressedReader(QString filename, QObject *parent = 0);
+ ~UncompressedReader();
+
+ QString readString(qint32 offset, qint32 len);
+ QString readString(qint64 offset, qint32 len);
+ QChar readChar();
+ qint32 readInt32BigEndian();
+ qint64 readInt64BigEndian();
+ QString readKeyword();
+ bool open(QString file);
+ void close();
+
+private:
+ QFile _file;
+ QDataStream _stream;
+};
+
+#endif // UNCOMPRESSEDREADER_H
maemo5:QT += maemo5
+LIBS += -lz
+
SOURCES += \
StarDictPlugin.cpp \
TranslationStarDict.cpp \
StarDictDialog.cpp \
- StarDialog.cpp
+ StarDialog.cpp \
+ CompressedReader.cpp \
+ UncompressedReader.cpp \
+ StarDictReaderFactory.cpp
HEADERS += \
../../include/translation.h \
../../include/settings.h \
../../include/CommonDictInterface.h \
- StarDialog.h
+ StarDialog.h \
+ CompressedReader.h \
+ UncompressedReader.h \
+ StarDictReaderFactory.h \
+ StarDictReader.h
RESOURCES += \
StarDict.qrc