+ trans + QString("\n </ar>");
trans=checkTranslation(trans);
- trans=XslConversion(trans);
-
qDebug()<<"\n\n trans"<<trans;
+ trans=XslConversion(trans);
QString head = "<html><head>";
head += "<link rel=\"stylesheet\" type=\"text/css\" " ;
trans+= "</body></html>";
trans.replace("$STAR$", "/usr/share/mdictionary/staron.png");
+ // qDebug()<<"\n\n trans"<<trans;
webkit->setHtml(trans, QUrl().fromLocalFile("/"));
//webkit->repaint(this->rect());
//update(this->rect());
<location filename="GoogleDialog.cpp" line="91"/>
<source>Plugin: GoogleTranslator
</source>
- <translation type="unfinished"></translation>
+ <translation>Plugin: GoogleTranslator
+</translation>
</message>
<message>
<location filename="GoogleDialog.cpp" line="92"/>
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 true;
}
+
void CompressedReader::close() {
gzclose(_file);
_file = NULL;
QString cha;
gzread(_file, c, 1);
+ if(((unsigned char)c[0])>240)
+ gzread(_file, c+1, 3);
+ else if(((unsigned char)c[0])>224)
+ gzread(_file, c+1, 2);
+ else if(((unsigned char)c[0])>192)
+ gzread(_file, c+1, 1);
+ else if(((unsigned char)c[0])>127){
+ qDebug()<<"error - starDict - read wordList from UTF-8";
+ c[0]=0;
+ }
+
+
+ /* gzread(_file, c, 1);
if(((unsigned char)c[0])>127){
gzread(_file, c+1, 1);
if(((unsigned char)c[1])>127 && ((unsigned char)c[1])<192){
gzread(_file, c+3, 1);
}
}
+*/
cha=QString::fromUtf8(c);
return cha.at(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;
return result;
}
+
QByteArray CompressedReader::readString(qint64 offset, qint32 len) {
char* buf;
buf = new char[len];
#include "StarDictReader.h"
/*!
- Class implementing StarDictReader interface and handling rading from compressed
+ 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
- */
+ Creates new compressed reader and open file with passed filename
+ */
CompressedReader(QString filename, QObject *parent = 0);
/*!
- Destructs object and closing file
+ Destructs object and closing file
*/
~CompressedReader();
/*!
- Reads translations text from compressed dict file.
- \param offset 64-bit offset of translation in uncompressed file, readed
+ 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
- */
+ \param len length of uncompressed translation, readed from idx file too
+ */
QByteArray readString(qint64 offset, qint32 len);
/*!
- Reads 32-bits integer value from compressed file and convert it from
- BigEndian to Little Endian
- */
+ 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
- */
+ 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.
- */
+ Reads single string from compressed file, end of string is marked as '\0'
+ in file.
+ */
QString readKeyword();
/*!
- Closing file;
- */
+ Closing file;
+ */
void close();
protected:
/*!
- Opens file
- \returns true if file is opened or false otherwise
- */
+ Opens file
+ \returns true if file is opened or false otherwise
+ */
bool open(QString file);
/*!
- Reads single char from compressed.
- */
+ Reads single char from compressed.
+ */
QChar readChar();
private:
#include <QDebug>
#include <QFile>
-StarDialog::StarDialog(StarDictPlugin *plugin,
- StarDialogType type,
- QWidget *parent) :
- QDialog(parent) {
- this->plugin = plugin;
- this->type = type;
-
- accentsToolTip = tr("Strip accents (searching takes more time, but spelling doesn't have to be exact)");
-
- initializeUI();
-
-
- connect(accentsCheckBox, SIGNAL(toggled(bool)),
- this, SLOT(setAccents(bool)));
-
- #ifdef Q_WS_MAEMO_5
- connect(accentsInfoToolButton, SIGNAL(clicked()),
-
- #endif
-
- if(type == New) {
- connect(browseButton, SIGNAL(clicked()),
- this, SLOT(selectFile()));
- }
-
- connect(confirmButton, SIGNAL(clicked()),
- this, SLOT(accept()));
-
+StarDialog::StarDialog(StarDictPlugin *plugin, StarDialogType type,
+ QWidget *parent) : QDialog(parent) {
+ this->plugin = plugin;
+ this->type = type;
+ initializeUI();
+ if(type == New)
+ connect(browseButton, SIGNAL(clicked()),this, SLOT(selectFile()));
+ connect(confirmButton, SIGNAL(clicked()),this, SLOT(accept()));
}
mainVerticalLayout = new QVBoxLayout;
widget = new QWidget;
widget->setLayout(mainVerticalLayout);
-
infoLabel = new QLabel;
infoLabel->setWordWrap(true);
if(type == New) {
- setWindowTitle(tr("Add new StarDict dictionary"));
-
browseLayout = new QHBoxLayout;
browseButton = new QPushButton(tr("Browse"));
- infoLabel->setText(tr("Dictionary file: not selected"));
+ setWindowTitle(tr("Add new StarDict dictionary"));
+ infoLabel->setText(tr("Dictionary file: not selected"));
browseLayout->addWidget(infoLabel, 0, Qt::AlignLeft);
browseLayout->addWidget(browseButton, 0, Qt::AlignRight);
-
mainVerticalLayout->addLayout(browseLayout);
}
else {
setWindowTitle(tr("StarDict Settings"));
-
infoLabel->setText(tr("Plugin: ") + plugin->type().toUpper() +"\n" +
tr("Book name: ") + plugin->settings()->value("bookname")
+ "\n" +
mainVerticalLayout->addWidget(infoLabel);
}
- accentsLayout = new QHBoxLayout;
- accentsCheckBox = new QCheckBox(tr("Strip accents"));
- accentsCheckBox->setToolTip(accentsToolTip);
- accentsLayout->addWidget(accentsCheckBox);
- #ifdef Q_WS_MAEMO_5
- accentsInfoToolButton = new QToolButton;
- accentsInfoToolButton->setIcon(QIcon::fromTheme("general_information"));
- accentsLayout->addWidget(accentsInfoToolButton);
- #endif
-
-
- mainVerticalLayout->addLayout(accentsLayout);
-
-
- //load old setting if exists
- if(!plugin) {
- accentsCheckBox->setChecked(true);
- accentsCheckBox->setEnabled(false);
- _accents = true;
+ if(!plugin)
_dictionaryFilePath = "";
- }
- else if(plugin && plugin->settings()->value("cached") == "true") {
- accentsCheckBox->setChecked(true);
- accentsCheckBox->setEnabled(false);
- _accents = true;
- }
- else {
- if(plugin->settings()->value("strip_accents") == "true") {
- accentsCheckBox->setChecked(true);
- _accents = true;
- }
- else {
- accentsCheckBox->setChecked(false);
- _accents = false;
- }
- }
confirmButton = new QPushButton;
mainVerticalLayout->addWidget(confirmButton);
- if(type == New) {
+ if(type == New)
confirmButton->setText(tr("Add"));
- }
- else {
+ else
confirmButton->setText(tr("Save settings"));
- }
scrollArea = new QScrollArea;
scrollArea->setWidget(widget);
scrollArea->setLineWidth(0);
scrollArea->setMidLineWidth(0);
scrollArea->setFrameStyle(QFrame::NoFrame);
-
-
-}
-
-
-void StarDialog::setAccents(bool accents) {
- _accents = accents;
}
void StarDialog::selectFile() {
QString fileName = QFileDialog::getOpenFileName(this,
- tr("Select dictionary file"),
- _dictionaryFilePath,
- tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
- NULL,
- NULL);
-
+ tr("Select dictionary file"),
+ _dictionaryFilePath,
+ tr("StarDict Files (*.dict *dict.dz *.idx *idx.gz *.ifo)"),
+ NULL,
+ NULL);
if (!fileName.isEmpty()) {
infoLabel->setText(tr("Dictionary file: %1").arg(fileName));
_dictionaryFilePath = fileName;
- if (_dictionaryFilePath.endsWith(".tar.bz2")){
- _isCompressed = true;
- }
- else {
- _isCompressed = false;
- }
+ if (_dictionaryFilePath.endsWith(".tar.bz2"))
+ _isCompressed = true;
+ else
+ _isCompressed = false;
updateGeometry();
}
}
+
void StarDialog::saveSettings() {
_settings = new Settings;
- if(plugin) {
+
+ if(plugin)
foreach(QString key, plugin->settings()->keys())
_settings->setValue(key, plugin->settings()->value(key));
- }
- _settings->setValue("path", _dictionaryFilePath);
- _settings->setValue("ifoFileName", _dictName + ".ifo");
- _settings->setValue("idxFileName", _dictName + ".idx");
- if (QFile::exists(_dictName + ".dict.dz") == true) {
+ if(_settings->value("path")=="")
+ _settings->setValue("path", _dictionaryFilePath);
+
+ if(_settings->value("ifoFileName")=="")
+ _settings->setValue("ifoFileName", _dictName + ".ifo");
+
+ if(_settings->value("idxFileName")=="")
+ _settings->setValue("idxFileName", _dictName + ".idx");
+
+ if(_settings->value("dictFileName")==""){
+ if (QFile::exists(_dictName + ".dict.dz") == true)
_settings->setValue("dictFileName", _dictName + ".dict.dz");
- }
- else {
+ else
_settings->setValue("dictFileName", _dictName + ".dict");
}
- if (QFile::exists(_dictName + ".syn") == true) {
+ if(_settings->value("synFileName")=="")
+ if (QFile::exists(_dictName + ".syn") == true)
_settings->setValue("synFileName", _dictName + ".syn");
- }
-
- if(_accents)
- _settings->setValue("strip_accents", "true");
- else
- _settings->setValue("strip_accents", "false");
}
+
void StarDialog::accept() {
if(type == New && _dictionaryFilePath.isEmpty()) {
Q_EMIT notify(Notify::Warning, tr("File path is not set"));
-
return;
}
QDialog::accept();
}
+
bool StarDialog::checkFiles() {
- if (!_isCompressed) {
-
- if (_dictionaryFilePath.right(2) == "dz") {
- _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
- _dictName = _dictName.left(_dictName.lastIndexOf("."));
- }
- else {
- _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
- }
-
- if (QFile::exists(_dictName + ".idx") == false && QFile::exists(_dictName + ".idx.gz") == false) {
- return false;
- }
- if (QFile::exists(_dictName + ".dict") == false && QFile::exists(_dictName + ".dict.dz") == false) {
- return false;
- }
- return true;
+ if (!_isCompressed) {
+ if (_dictionaryFilePath.right(2) == "dz") {
+ _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
+ _dictName = _dictName.left(_dictName.lastIndexOf("."));
}
- else {
- //TODO: untar files (?)
+ else{
+ _dictName = _dictionaryFilePath.left(_dictionaryFilePath.lastIndexOf("."));
+ }
+
+
+ if (QFile::exists(_dictName + ".idx") == false
+ && QFile::exists(_dictName + ".idx.gz") == false) {
+ return false;
+ }
+ if (QFile::exists(_dictName + ".dict") == false
+ && QFile::exists(_dictName + ".dict.dz") == false) {
return false;
}
+ return true;
+ }
+ else
+ return false;
}
+
Settings* StarDialog::getSettings() {
return _settings;
}
-#ifdef Q_WS_MAEMO_5
- void StarDialog::showAccentsInfo() {
- Q_EMIT notify(Notify::Warning, accentsToolTip);
- }
-#endif
-
//! 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.
+ of an existing one, based on dialog type passed to contructor.
When adding a new dictionary dialog contains a button to browse file system and
select a dictionary file. When changing settings dialog displays basic
information about dictionary i. e. name, languages and license info.
In both types of dialogs there are comboboxes with "cache" and "remove accents"
- options. On maemo right next to comboboxes are tool buttons which allow to
- see more information about these options, on desktop the same information is
- displayed as a tool tip.
+ options. On maemo right next to comboboxes are tool buttons which allow to
+ see more information about these options, on desktop the same information is
+ displayed as a tool tip.
All contents of a dialog are in a scroll area.
*/
class StarDialog : public QDialog
Q_OBJECT
public:
/*!
- Describes type of dialog. New means that dialog contains widgets to browse
+ Describes type of dialog. New means that dialog contains widgets to browse
file system and select dictionary file. Change means that dialog displays
- information about dictionary.
- In both types dialog provides widgets to create or delete cache and remove
- or keep accents.
+ information about dictionary.
+ In both types dialog provides widgets to create or delete cache and remove
+ or keep accents.
*/
enum StarDialogType {New, Change};
StarDialogType type = New,
QWidget* parent = 0);
- //! \returns settings of plugin
/*!
After acceptance of dialog this method returns plugin's settings based on
- user's choices in dialog.
+ user's choices in dialog.
+ \returns settings of plugin
*/
Settings* getSettings();
private Q_SLOTS:
//! displays dialog to browse and select file
void selectFile();
- void setAccents(bool);
-
- #ifdef Q_WS_MAEMO_5
- //! on maemo shows information about checkboxes
- void showAccentsInfo();
- #endif
-
private:
void initializeUI();
QPushButton* browseButton;
QHBoxLayout* browseLayout;
-
- QCheckBox* accentsCheckBox;
- QHBoxLayout* accentsLayout;
-
- QString accentsToolTip;
-
- #ifdef Q_WS_MAEMO_5
- QToolButton* accentsInfoToolButton;
- #endif
-
-
QPushButton* confirmButton;
-
QString _dictionaryFilePath;
-
QScrollArea* scrollArea;
-
QWidget* widget;
QHBoxLayout* layout;
-
QVBoxLayout* mainVerticalLayout;
- bool _accents;
- bool _lastAccents;
-
bool _isCompressed;
QString _dictName;
#include "StarDialog.h"
#include <QDebug>
+
StarDictDialog::StarDictDialog(StarDictPlugin *plugin, QObject *parent) :
DictDialog(parent) {
this->plugin = plugin;
_lastDialogParent=0;
}
+
QWidget* StarDictDialog::lastDialogParent() {
return _lastDialogParent;
}
+
void StarDictDialog::setLastDialogParent(QWidget *w) {
_lastDialogParent = w;
}
+
Settings* StarDictDialog::addNewDictionary(QWidget *parent) {
StarDialog d(0, StarDialog::New, parent);
setLastDialogParent(parent);
return 0;
}
+
void StarDictDialog::changeSettings(QWidget * parent) {
StarDialog d(plugin, StarDialog::Change, parent);
setLastDialogParent(parent);
public:
explicit StarDictDialog(StarDictPlugin* plugin, QObject *parent = 0);
/*!
- Shows "add new xdxf dictionary" dialog and returns settings of a new dict
- \param parent parent widget on which dialog will be displayed
- */
+ Shows "add new xdxf dictionary" dialog and returns settings of a new dict
+ \param parent parent widget on which dialog will be displayed
+ */
Settings* addNewDictionary(QWidget *parent);
/*!
- Shows settings dialog and saves new settings in plugin
- \param parent parent widget on which dialog will be displayed
- */
+ Shows settings dialog and saves new settings in plugin
+ \param parent parent widget on which dialog will be displayed
+ */
void changeSettings(QWidget *parent);
QWidget* lastDialogParent();
#include "StarDictPlugin.h"
-
+/**/
uint qHash(const TranslationStarDict &key) {
return qHash(key.key());
}
_settings->setValue("type","stardict");
_icon = QIcon("/usr/share/mdictionary/stardict.png");
- _wordsCount = -1;
stopped = false;
initAccents();
word.indexOf("_")==-1 && word.indexOf("%")==-1)
word+="*";
-
if((settings()->value("idxoffsetbits") == "32") ||
(settings()->value("idxoffsetbits") == ""))
is32b = true;
+
if(!err)
return QList<Translation*>();
if(bytes == 0 && it != end){
while(*it != '\0' && it != end)
ret.append(*it++);
- if(it == end)
- qDebug()<<"end";
- else
- qDebug()<<"000";
}
else
for(int i = 0; i < bytes && it != end; i++)
QByteArray::iterator end, QChar mode,QString key, bool last) {
QString result;
qDebug()<<"****** mode: "<<mode;
- if(mode == 'm'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'l'){
+
+ if(mode == 'm' ||
+ mode == 'l' ||
+ mode == 'g' ||
+ mode == 't' ||
+ mode == 'y' ||
+ mode == 'k' ||
+ mode == 'w' ||
+ mode == 'h' ||
+ mode == 'r' ){
result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
+ result += "<t>" + QString::fromUtf8(read(it++, end)) + "</t>";
}
- else if(mode == 'g'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- /* delete "small" tag from translation*/
+ if(mode == 'g'){
+ /* delete "small" tag from g translation*/
int indexOfSmall=result.indexOf("<small>");
while(indexOfSmall!=-1){
int indexOfEndSmall= result.indexOf("</small>");
indexOfSmall=result.indexOf("<small>");
}
}
- else if(mode == 't'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'x'){
+ if(mode == 'x'){
result += QString::fromUtf8(read(it++, end));
result.replace("</k>","</key><t>");
result.replace("<k>","</t><key>");
if(result.contains("<t>"))
result+="</t>";
}
- else if(mode == 'y') {
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'k'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'w'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'h'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
- else if(mode == 'r'){
- result += "<key>" + key + "</key>";
- result += QString::fromUtf8(read(it++, end));
- }
-
// Dont know whether mDictionary would ever handle binary stardict format
// to be honest dont see any kind of adventages (can't find any binary dict)
}
-
QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
QString dictPath = settings()->value("dictFileName");
StarDictReader *reader = StarDictReaderFactory::createReader(dictPath);
}
-bool StarDictPlugin::isCached() {
- return false;
-}
-
-
bool StarDictPlugin::setSettings(const Settings *sett) {
if(sett) {
foreach(QString key, sett->keys())
}
-
void StarDictPlugin::clean() {
}
/*! \returns DictDialog object that creates dialogs
for adding a new dictionary and changing plugin settings
- */
+ */
DictDialog* dictDialog();
//! \returns new, clean copy of plugin with settings set as in Settings*
/*! \return a description of a word given by a QString
\param offset offset of translation to be cut out
\param len lenght of translation to be cut out
- */
+ */
QString search(QString key, qint64 offset, qint32 len);
//! \returns current plugin settings
/*! plugin should delete any files (eg. cache) that have been created and are ready
to be deleted
- */
+ */
void clean();
public Q_SLOTS:
- /*! performs search in a dictionary
- \param word word to search for in a dictionary
- \param limit limit on number of results
+ /*!
+ performs search in a dictionary
+ \param word word to search for in a dictionary
+ \param limit limit on number of results
- After finishing search it has to emit
- \see CommonDictInterface:finalTranslation finalTranslation
+ After finishing search it has to emit
+ \see CommonDictInterface:finalTranslation finalTranslation
*/
QList<Translation*> searchWordList(QString word, int limit=0);
private:
- /*! \returns true or false depending on whether the dictionary is cached
- or not
- */
- bool isCached();
- /*! searches for a list of words similar to a word in a database file
- \param word key compared with keys in a database
- \param limit limits the number of translations in returned list,
- 0 means unlimited
- \returns list of translations
+ /*!
+ searches for a list of words similar to a word in a database file
+ \param word key compared with keys in a database
+ \param limit limits the number of translations in returned list,
+ 0 means unlimited
+ \returns list of translations
*/
QList<Translation*> searchWordListCache(QString word, int limit=0);
- /*! searches for a list of words similar to a word in a xdxf file
- \param word key compared with keys in a xdxf file
- \param limit limits the number of translations in returned list,
- 0 means unlimited
- \returns list of translations
+ /*!
+ searches for a list of words similar to a word in a xdxf file
+ \param word key compared with keys in a xdxf file
+ \param limit limits the number of translations in returned list,
+ 0 means unlimited
+ \returns list of translations
*/
QList<Translation*> searchWordListFile(QString word, int limit=0);
- /*! searches for a translation of a word which is exactly like a key
- in a xdxf file */
+ /*!
+ searches for a translation of a word which is exactly like a key
+ in a xdxf file
+ */
QString searchFile(QString key);
//! scans dictionary file to get information about it
//! information about dictionary
QString _infoNote;
- QString _dictionaryInfo;
-
//! icon displayed during translations and when a dictionary is chosen
QIcon _icon;
- //! number of words in a dictionary
- long _wordsCount;
//! indicates if search is stopped
volatile bool stopped;
Settings *_settings;
StarDictDialog* _dictDialog;
Settings* _ifoFileSettings;
- /*! Reads and process (converting to qstring) data from StarDict dictionary
+ /*!
+ Reads and process (converting to qstring) data from StarDict dictionary
file (*.dict[.dz])
\return converted translation
\param QByteArray raw data to process
- \param mode StarDict parametr "sametypesequence" */
+ \param mode StarDict parametr "sametypesequence"
+ */
QString format(QByteArray, QString mode,QString key);
- /*! Reads bytes bytes of data or reads until \0
+ /*!
+ Reads bytes bytes of data or reads until \0
\param it iterator to given data
\param end end of data
\param bytes to read
- \return readed data chunk*/
+ \return readed data chunk
+ */
QByteArray read(QByteArray::iterator it, QByteArray::iterator end,
int bytes = 0);
- /*! Interpret data basis on mode (StarDict dict data type)
+ /*!
+ Interpret data basis on mode (StarDict dict data type)
\param it iterator on given data set
\param end iterator pointing to the data end
\param mode stardict dict data type
\param last used to interpret sametypesequence field last letter (see
- StarDict format description)
- \return QSting containing interpreted data chunk */
+ StarDict format description)
+ \return QSting containing interpreted data chunk
+ */
QString interpret(QByteArray::iterator it, QByteArray::iterator end,
QChar mode,QString key, bool last = false);
#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.
- */
+ 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:
virtual ~StarDictReader() {}
/*!
- 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
- */
+ 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 QByteArray readString(qint64 offset, qint32 len)=0;
/*!
- Reads 32-bits integer value from file and convert it from BigEndian
+ 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
+ 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.
- */
+ Reads single string from file, end of string is marked as '\0' in file.
+ */
virtual QString readKeyword()=0;
/*!
- Closing file;
- */
+ Closing file;
+ */
virtual void close()=0;
protected:
/*!
- Opens file
- \returns true if file is opened or false otherwise
- */
+ Opens file
+ \returns true if file is opened or false otherwise
+ */
virtual bool open(QString file)=0;
/*!
- Reads single char from file.
- */
+ Reads single char from file.
+ */
virtual QChar readChar()=0;
};
#include "StarDictReader.h"
/*!
- Class used to creating StarDictReader objects, based on filename it creates
- compressed or uncompressed reader.
- */
+ Class used to creating StarDictReader objects, based on filename it creates
+ compressed or uncompressed reader.
+*/
class StarDictReaderFactory
{
public:
Copyright 2010 Comarch S.A.
*******************************************************************************/
-/*! \file TranslationXdxf.cpp
+/*! \file TranslationStarDict.cpp
\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
*/
-
#include "TranslationStarDict.h"
#include <QDebug>
+
TranslationStarDict::TranslationStarDict():_key(""),_dictionaryInfo("") {
starDictPlugin=0;
}
+
TranslationStarDict::TranslationStarDict(QString _key, QString _dictionaryInfo,
StarDictPlugin *starDictPlugin): _key(_key),_dictionaryInfo(_dictionaryInfo) {
this->starDictPlugin=starDictPlugin;
return _key;
}
-QString TranslationStarDict::toXml() const {
+QString TranslationStarDict::toXml() const {
QString result("");
if(!starDictPlugin)
return result;
return result;
}
+
void TranslationStarDict::setKey(QString _key) {
this->_key=_key;
}
+
void TranslationStarDict::setDictionaryInfo(QString _dictionaryInfo) {
this->_dictionaryInfo=_dictionaryInfo;
}
//! \return parsed raw format into xml
QString toXml() const;
- /*! sets the word for which we want to find a translation
- \param word for which we want to find a translation */
+ /*!
+ sets the word for which we want to find a translation
+ \param word for which we want to find a translation
+ */
void setKey(QString);
//! sets information about dictionary
//! returns corresponding dict object
uint dict() const {return _dictHash;}
- /*! Add another hit in *.id(x) file
+ /*!
+ Add another hit in *.id(x) file
\param offset offset from begining of file to searched keyword
\param len lenght of searched keyword
*/
#include "UncompressedReader.h"
#include "QDebug"
+
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[4]={0};
QString cha;
_stream.readRawData(c,1);
- if(((unsigned char)c[0])>127){
+ if(((unsigned char)c[0])>240)
+ _stream.readRawData(c+1,3);
+ else if(((unsigned char)c[0])>224)
+ _stream.readRawData(c+1,2);
+ else if(((unsigned char)c[0])>192)
+ _stream.readRawData(c+1,1);
+ else if(((unsigned char)c[0])>127)
+ qDebug()<<"error - starDict - read wordList from UTF-8";
+
+
+ /* if(((unsigned char)c[0])>127){
_stream.readRawData(c+1,1);
if(((unsigned char)c[1])>127 && ((unsigned char)c[1])<192){
_stream.readRawData(c+2,1);
_stream.readRawData(c+3,1);
}
}
-
+ */
cha=QString::fromUtf8(c);
+
return cha.at(0);
}
+
QString UncompressedReader::readKeyword() {
QString result;
QChar c;
result += c;
c = readChar();
}
-
return result;
}
return result;
}
+
qint32 UncompressedReader::readInt32BigEndian() {
_stream.setByteOrder(QDataStream::BigEndian);
qint32 value;
return value;
}
+
qint64 UncompressedReader::readInt64BigEndian() {
_stream.setByteOrder(QDataStream::BigEndian);
qint64 value;
_stream>>value;
_stream.setByteOrder(QDataStream::LittleEndian);
-
return value;
}
/*!
Class implementing StarDictReader interface and handling rading from uncompressed files
- */
+*/
class UncompressedReader : public StarDictReader
{
Q_OBJECT
UncompressedReader(QObject *parent = 0);
/*!
- Creates new reader and open file with passed filename
- */
+ Creates new reader and open file with passed filename
+ */
UncompressedReader(QString filename, QObject *parent = 0);
/*!
- Destructs object and closing file
+ Destructs object and closing file
*/
~UncompressedReader();
/*!
- 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
- */
+ 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
+ */
QByteArray readString(qint64 offset, qint32 len);
/*!
- Reads 32-bits integer value from file and convert it from
- BigEndian to Little Endian
- */
+ 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
- */
+ 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.
- */
+ Reads single string from file, end of string is marked as '\0'
+ in file.
+ */
QString readKeyword();
/*!
- Closing file;
- */
+ Closing file;
+ */
void close();
protected:
/*!
- Opens file
- \returns true if file is opened or false otherwise
- */
+ Opens file
+ \returns true if file is opened or false otherwise
+ */
bool open(QString file);
/*!
- Reads single char from compressed.
- */
+ Reads single char from compressed.
+ */
QChar readChar();
private:
<!DOCTYPE TS>
<TS version="2.0" language="en_US">
<context>
- <name>XdxfCachingDialog</name>
- <message>
- <location filename="XdxfCachingDialog.cpp" line="35"/>
- <location filename="XdxfCachingDialog.cpp" line="49"/>
- <source>Caching dictionary, please wait</source>
- <translation type="unfinished"></translation>
- </message>
+ <name>StarDialog</name>
<message>
- <location filename="XdxfCachingDialog.cpp" line="41"/>
- <source>Cancel</source>
+ <location filename="StarDialog.cpp" line="33"/>
+ <source>Strip accents (searching takes more time, but spelling doesn't have to be exact)</source>
<translation type="unfinished"></translation>
</message>
+</context>
+<context>
+ <name>StarDictPlugin</name>
<message>
- <location filename="XdxfCachingDialog.cpp" line="79"/>
- <source>Estimated time left: </source>
+ <location filename="StarDictPlugin.cpp" line="353"/>
+ <source>StarDict dictionary cannot be read from file</source>
<translation type="unfinished"></translation>
</message>
+</context>
+<context>
+ <name>XdxfCachingDialog</name>
<message numerus="yes">
- <location filename="XdxfCachingDialog.cpp" line="80"/>
<source>%n second(s)</source>
- <translation>
+ <translation type="obsolete">
<numerusform>%n second</numerusform>
<numerusform>%n seconds</numerusform>
</translation>
</message>
</context>
-<context>
- <name>XdxfDialog</name>
- <message>
- <location filename="XdxfDialog.cpp" line="35"/>
- <source>Optimize for quicker searches (may take some time)</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="36"/>
- <source>Strip accents (searching takes more time, but spelling doesn't have to be exact)</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="74"/>
- <source>Add new XDXF dictionary</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="77"/>
- <source>Browse</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="78"/>
- <source>Dictionary file: not selected</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="86"/>
- <source>XDXF Settings</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="88"/>
- <source>Plugin: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="89"/>
- <source>From: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="90"/>
- <source>To: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="91"/>
- <source>Description: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="97"/>
- <source>Strip accents</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="107"/>
- <source>Optimize</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="153"/>
- <source>Add</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="156"/>
- <source>Save settings</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="210"/>
- <source>Select dictionary file</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="212"/>
- <source>XDXF Files (*.xdxf)</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="217"/>
- <source>Dictionary file: %1</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="246"/>
- <source>File path is not set</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
-<context>
- <name>XdxfPlugin</name>
- <message>
- <location filename="xdxfplugin.cpp" line="108"/>
- <location filename="xdxfplugin.cpp" line="206"/>
- <location filename="xdxfplugin.cpp" line="523"/>
- <source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="xdxfplugin.cpp" line="157"/>
- <location filename="xdxfplugin.cpp" line="237"/>
- <source>XDXF file cannot be read for %1</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="xdxfplugin.cpp" line="365"/>
- <source>XDXF file is in wrong format</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="xdxfplugin.cpp" line="407"/>
- <source>XDXF dictionary cannot be read from file</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="xdxfplugin.cpp" line="455"/>
- <location filename="xdxfplugin.cpp" line="514"/>
- <source>XDXF file cannot be read for %1 dictionary</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="xdxfplugin.cpp" line="605"/>
- <source>Database caching error, please try again.</source>
- <translation type="unfinished"></translation>
- </message>
-</context>
</TS>
<!DOCTYPE TS>
<TS version="2.0" language="pl_PL">
<context>
+ <name>StarDialog</name>
+ <message>
+ <location filename="StarDialog.cpp" line="33"/>
+ <source>Strip accents (searching takes more time, but spelling doesn't have to be exact)</source>
+ <translation type="unfinished">Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie)</translation>
+ </message>
+</context>
+<context>
+ <name>StarDictPlugin</name>
+ <message>
+ <location filename="StarDictPlugin.cpp" line="353"/>
+ <source>StarDict dictionary cannot be read from file</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>XdxfCachingDialog</name>
<message>
- <location filename="XdxfCachingDialog.cpp" line="35"/>
- <location filename="XdxfCachingDialog.cpp" line="49"/>
<source>Caching dictionary, please wait</source>
- <translation>Optymalizacja słownika, proszę czekać</translation>
+ <translation type="obsolete">Optymalizacja słownika, proszę czekać</translation>
</message>
<message>
- <location filename="XdxfCachingDialog.cpp" line="41"/>
<source>Cancel</source>
- <translation>Anuluj</translation>
+ <translation type="obsolete">Anuluj</translation>
</message>
<message>
- <location filename="XdxfCachingDialog.cpp" line="79"/>
<source>Estimated time left: </source>
- <translation>Pozostały czas: </translation>
+ <translation type="obsolete">Pozostały czas: </translation>
</message>
<message numerus="yes">
- <location filename="XdxfCachingDialog.cpp" line="80"/>
<source>%n second(s)</source>
- <translation>
+ <translation type="obsolete">
<numerusform>%n sekunda</numerusform>
<numerusform>%n sekundy</numerusform>
<numerusform>%n sekund</numerusform>
<context>
<name>XdxfDialog</name>
<message>
- <location filename="XdxfDialog.cpp" line="35"/>
<source>Optimize for quicker searches (may take some time)</source>
- <translation>Optymalizuj dla szybszego wyszukiwania (może zająć trochę czasu)</translation>
+ <translation type="obsolete">Optymalizuj dla szybszego wyszukiwania (może zająć trochę czasu)</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="36"/>
<source>Strip accents (searching takes more time, but spelling doesn't have to be exact)</source>
- <translation>Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie)</translation>
+ <translation type="obsolete">Usuń akcenty (wyszukiwanie trwa dłużej, ale szukane słowo nie musi być wpisane dokładnie)</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="74"/>
<source>Add new XDXF dictionary</source>
- <translation>Dodaj nowy słownik XDXF</translation>
+ <translation type="obsolete">Dodaj nowy słownik XDXF</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="77"/>
<source>Browse</source>
- <translation>Przeglądaj</translation>
+ <translation type="obsolete">Przeglądaj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="78"/>
<source>Dictionary file: not selected</source>
- <translation>Plik ze słownikiem nie został wybrany</translation>
+ <translation type="obsolete">Plik ze słownikiem nie został wybrany</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="86"/>
<source>XDXF Settings</source>
- <translation>Ustawienia XDXF</translation>
- </message>
- <message>
- <location filename="XdxfDialog.cpp" line="88"/>
- <source>Plugin: </source>
- <translation type="unfinished"></translation>
+ <translation type="obsolete">Ustawienia XDXF</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="89"/>
<source>From: </source>
- <translation>Z: </translation>
+ <translation type="obsolete">Z: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="90"/>
<source>To: </source>
- <translation>Na: </translation>
+ <translation type="obsolete">Na: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="91"/>
<source>Description: </source>
- <translation>Opis: </translation>
+ <translation type="obsolete">Opis: </translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="97"/>
<source>Strip accents</source>
- <translation>Usuń akcenty</translation>
+ <translation type="obsolete">Usuń akcenty</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="107"/>
<source>Optimize</source>
- <translation>Optymalizuj</translation>
+ <translation type="obsolete">Optymalizuj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="153"/>
<source>Add</source>
- <translation>Dodaj</translation>
+ <translation type="obsolete">Dodaj</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="156"/>
<source>Save settings</source>
- <translation>Zapisz ustawienia</translation>
+ <translation type="obsolete">Zapisz ustawienia</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="210"/>
<source>Select dictionary file</source>
- <translation>Wybierz plik ze słownikiem</translation>
+ <translation type="obsolete">Wybierz plik ze słownikiem</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="212"/>
<source>XDXF Files (*.xdxf)</source>
- <translation>Pliki XDXF (*.xdxf)</translation>
+ <translation type="obsolete">Pliki XDXF (*.xdxf)</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="217"/>
<source>Dictionary file: %1</source>
- <translation>Plik ze słownikiem: %1</translation>
+ <translation type="obsolete">Plik ze słownikiem: %1</translation>
</message>
<message>
- <location filename="XdxfDialog.cpp" line="246"/>
<source>File path is not set</source>
- <translation>Ścieżka do pliku nie jest ustawiona</translation>
+ <translation type="obsolete">Ścieżka do pliku nie jest ustawiona</translation>
</message>
</context>
<context>
<name>XdxfPlugin</name>
<message>
- <location filename="xdxfplugin.cpp" line="108"/>
- <location filename="xdxfplugin.cpp" line="206"/>
- <location filename="xdxfplugin.cpp" line="523"/>
<source>Cache database cannot be opened for %1 dictionary. Searching in XDXF file. You may want to recache.</source>
- <translation>Nie można otworzyć bazy danych dla słownika %1. Szukanie w pliku XDXF. Możesz spróbować ponownie włączyć optymalizację.</translation>
+ <translation type="obsolete">Nie można otworzyć bazy danych dla słownika %1. Szukanie w pliku XDXF. Możesz spróbować ponownie włączyć optymalizację.</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="157"/>
- <location filename="xdxfplugin.cpp" line="237"/>
<source>XDXF file cannot be read for %1</source>
- <translation>Nie można odczytać pliku XDXF dla %1</translation>
+ <translation type="obsolete">Nie można odczytać pliku XDXF dla %1</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="365"/>
<source>XDXF file is in wrong format</source>
- <translation>Niewłaściwy format pliku XDXF</translation>
+ <translation type="obsolete">Niewłaściwy format pliku XDXF</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="407"/>
<source>XDXF dictionary cannot be read from file</source>
- <translation>Nie można odczytać słownika XDXF z pliku</translation>
+ <translation type="obsolete">Nie można odczytać słownika XDXF z pliku</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="455"/>
- <location filename="xdxfplugin.cpp" line="514"/>
<source>XDXF file cannot be read for %1 dictionary</source>
- <translation>Nie mozna odczytać pliku XDXF dla słownika %1</translation>
+ <translation type="obsolete">Nie mozna odczytać pliku XDXF dla słownika %1</translation>
</message>
<message>
- <location filename="xdxfplugin.cpp" line="605"/>
<source>Database caching error, please try again.</source>
- <translation>Błąd optymalizacji, proszę spróbować ponownie.</translation>
+ <translation type="obsolete">Błąd optymalizacji, proszę spróbować ponownie.</translation>
</message>
</context>
</TS>