Copyright 2010 Comarch S.A.
*******************************************************************************/
+/*!
+ \file StarDictPlugin.cpp
+ \brief Implementation of stardict plugin's main class.
-/*! \file xdxfplugin.cpp
-\author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
+ \author Jakub Jaszczynski
*/
-#include "xdxfplugin.h"
-#include <QDebug>
-#include "../../include/Notify.h"
+#include "StarDictPlugin.h"
-XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
+/**/
+uint qHash(const TranslationStarDict &key) {
+ return qHash(key.key());
+}
+
+
+StarDictPlugin::StarDictPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(""), _langTo(""),_name(""), _infoNote("") {
_settings = new Settings();
- _dictDialog = new XdxfDictDialog(this, this);
+ _dictDialog = new StarDictDialog(this, this);
connect(_dictDialog, SIGNAL(notify(Notify::NotifyType,QString)),
this, SIGNAL(notify(Notify::NotifyType,QString)));
-
- _settings->setValue("type","xdxf");
- _icon = QIcon("/usr/share/mdictionary/xdxf.png");
- _wordsCount = -1;
+ _settings->setValue("type","stardict");
+ _icon = QIcon("/usr/share/mdictionary/stardict.png");
stopped = false;
+ _settings->setValue("strip_accents","true");
+
initAccents();
+
}
-void XdxfPlugin::retranslate() {
- QString locale = QLocale::system().name();
+void StarDictPlugin::retranslate() {
+ QString locale = QLocale::system().name();
QTranslator *translator = new QTranslator(this);
- if(!translator->load(":/xdxf/translations/" + locale)) {
- translator->load(":/xdxf/translations/en_US");
+ if(!translator->load(":/stardict/translations/" + locale)) {
+ translator->load(":/stardict/translations/en_US");
}
QCoreApplication::installTranslator(translator);
}
-XdxfPlugin::~XdxfPlugin() {
+StarDictPlugin::~StarDictPlugin() {
delete _settings;
delete _dictDialog;
}
-QString XdxfPlugin::langFrom() const {
+QString StarDictPlugin::langFrom() const {
return _langFrom;
}
-QString XdxfPlugin::langTo() const {
+QString StarDictPlugin::langTo() const {
return _langTo;
}
-QString XdxfPlugin::name() const {
+QString StarDictPlugin::name() const {
return _name;
}
-QString XdxfPlugin::type() const {
- return QString("xdxf");
+QString StarDictPlugin::type() const {
+ return QString("stardict");
}
-QString XdxfPlugin::infoNote() const {
- return _infoNote;
+QString StarDictPlugin::infoNote() const {
+ return _name;
}
-QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
+QList<Translation*> StarDictPlugin::searchWordList(QString word, int limit) {
+ QList<TranslationStarDict> translations;
+ bool is32b = false;
+ bool err = 0;
+ int wordcount = settings()->value("wordcount").toInt(&err);
+ int counter = 0;
+ int counterLimit = 0;
+ QString idxPath = settings()->value("idxFileName");
+ StarDictReader * reader = StarDictReaderFactory::createReader(idxPath);
+ QString fkey;
+ qint64 offset = 0,
+ len = 0;
+
if( word.indexOf("*")==-1 && word.indexOf("?")==-1 &&
word.indexOf("_")==-1 && word.indexOf("%")==-1)
word+="*";
+ QRegExp keyword(word, Qt::CaseInsensitive, QRegExp::Wildcard);
+
+ if((settings()->value("idxoffsetbits") == "32") ||
+ (settings()->value("idxoffsetbits") == ""))
+ is32b = true;
- if(isCached())
- return searchWordListCache(word,limit);
- return searchWordListFile(word, limit);
+ if(!err)
+ return QList<Translation*>();
+
+ stopped=false;
+ while(counter < wordcount && (counterLimit<limit || limit==0) && !stopped) {
+ counter++;
+ fkey = reader->readKeyword();
+ if(is32b)
+ offset = reader->readInt32BigEndian();
+ else
+ offset = reader->readInt64BigEndian();
+ len = reader->readInt32BigEndian();
+
+ if(keyword.exactMatch(fkey) ) {
+ TranslationStarDict tran(fkey, infoNote(), this);
+ // qDebug() << "off/len" << offset << len;
+ int id = translations.indexOf(tran);
+ if(id == -1) {
+ tran.add(offset, len);
+ translations.push_front(tran);
+ } else
+ translations[id].add(offset, len);
+ counterLimit++;
+ }
+ }
+ QList<Translation*> ret;
+ QListIterator<TranslationStarDict> it(translations);
+ while(it.hasNext())
+ ret.push_back(new TranslationStarDict(it.next()));
+ return ret;
}
-QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
- QSet<Translation*> translations;
- QString cacheFilePath = _settings->value("cache_path");
+QByteArray StarDictPlugin::read(QByteArray::iterator it,
+ QByteArray::iterator end, int bytes) {
+ QByteArray ret;
- db.setDatabaseName(cacheFilePath);
- if(!QFile::exists(cacheFilePath) || !db.open()) {
- qDebug() << "Database error" << db.lastError().text() << endl;
- Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
- "opened for %1 dictionary. Searching in XDXF file. "
- "You may want to recache.").arg(name())));
- _settings->setValue("cached","false");
- return searchWordListFile(word, limit);
+ if(bytes == 0 && it != end){
+ while(*it != '\0' && it != end)
+ ret.append(*it++);
}
- stopped = false;
- word = word.toLower();
- word = word.replace("*", "%");
- word = word.replace("?", "_");
-
- QSqlQuery cur(db);
- if(limit !=0)
- cur.prepare("select word from dict where word like ? or normalized "
- "like ? limit ?");
else
- cur.prepare("select word from dict where word like ? or normalized "
- "like ?");
- cur.addBindValue(word);
- cur.addBindValue(word);
- if(limit !=0)
- cur.addBindValue(limit);
- cur.exec();
-
- while(cur.next() && (translations.size()<limit || limit==0)) {
- translations.insert(new TranslationXdxf(
- cur.value(0).toString(),
- _dictionaryInfo, this));
- }
- db.close();
- return translations.toList();
+ for(int i = 0; i < bytes && it != end; i++)
+ ret.append(*it++);
+ return ret;
}
-QList<Translation*> XdxfPlugin::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();
+QString StarDictPlugin::interpret(QByteArray::iterator it,
+ QByteArray::iterator end, QChar mode,QString key, bool) {
+ QString result;
+// qDebug()<<"****** mode: "<<mode;
+ if(mode == 'm'
+ || mode == 'l'
+ || mode == 'g'
+ || mode == 't'
+ || mode == 'y'
+ || mode == 'k'
+ || mode == 'w'
+ || mode == 'h'
+ || mode == 'r'){
+ result += "<key>" + key + "</key>";
+ result += "<t>" + QString::fromUtf8(read(it++, end)) + "</t>";
}
- 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 TranslationXdxf(readKey.toLower(),
- _dictionaryInfo,this));
- if(translations.size()==limit && limit!=0)
- break;
- }
+ if(mode == 'g'){
+ /* delete "small" tag from g translation*/
+ int indexOfSmall=result.indexOf("<small>");
+ while(indexOfSmall!=-1){
+ int indexOfEndSmall= result.indexOf("</small>");
+ if(indexOfEndSmall!=-1)
+ result.remove(indexOfSmall,indexOfEndSmall-indexOfSmall+8);
+ indexOfSmall=result.indexOf("<small>");
}
- this->thread()->yieldCurrentThread();
}
- stopped=false;
- dictionaryFile.close();
- return translations.toList();
-}
-
+ if(mode == 'x'){
+ result += QString::fromUtf8(read(it++, end));
+ result.replace("</k>","</key><t>");
+ result.replace("<k>","</t><key>");
+ int pos=result.indexOf("</t>");
+ if(pos!=-1)
+ result.remove(pos,4);
+ if(result.contains("<t>"))
+ result+="</t>";
+ }
-QString XdxfPlugin::search(QString key) {
- if(isCached())
- return searchCache(key);
- return searchFile(key);
+// W & P 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)
+ /*
+ }
+ else if(mode == 'W') {
+ result += "<key>" + key + "</key>";
+ if(!last) {
+ QByteArray tmp ;
+ tmp.append(*(it++));
+ tmp.append(*(it++));
+ tmp.append(*(it++));
+ tmp.append(*(it));
+ result += read(it++, end, (qint32)qFromBigEndian(*(qint32*)tmp.data()));
+ } else
+ result += read(it++, end);
+ } else if(mode == 'P') {
+ result += "<key>" + key + "</key>";
+ if(!last) {
+ QByteArray tmp ;
+ tmp.append(*(it++));
+ tmp.append(*(it++));
+ tmp.append(*(it++));
+ tmp.append(*(it));
+ result += read(it++, end, (qint32)qFromBigEndian(*(qint32*)tmp.data()));
+ } else
+ result += read(it++, end);
+ } */
+ return result;
}
-QString XdxfPlugin::searchCache(QString key) {
- QString result("");
- QString cacheFilePath = _settings->value("cache_path");
- db.setDatabaseName(cacheFilePath);
- key = key.toLower();
-
- if(!QFile::exists(cacheFilePath) || !db.open()) {
- qDebug() << "Database error" << db.lastError().text() << endl;
- Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
- "opened for %1 dictionary. Searching in XDXF file. "
- "You may want to recache.").arg(name())));
- _settings->setValue("cached","false");
- return searchFile(key);
+QString StarDictPlugin::format(QByteArray raw, QString mode,QString key) {
+ QString result;
+ if(mode == "") {
+ for(QByteArray::iterator it = raw.begin(); it != raw.end(); it++) {
+ char tmp = *(++it);
+ result += interpret(--it, raw.end(), tmp, key);
+ }
+ } else {
+ QByteArray::iterator it = raw.begin();
+ foreach(QChar tmp, mode) {
+ result += interpret(it, raw.end(), tmp, key);
+ }
}
-
- QSqlQuery cur(db);
-
- cur.prepare("select translation from dict where word like ?");
- cur.addBindValue(key);
- cur.exec();
- while(cur.next())
- result += cur.value(0).toString();
-
- db.close();
-
return result;
-
}
-QString XdxfPlugin::searchFile(QString key) {
- QFile dictionaryFile(_settings->value("path"));
- QString resultString("");
- key = key.toLower();
+QString StarDictPlugin::search(QString key, qint64 offset, qint32 len) {
+ QString dictPath = settings()->value("dictFileName");
+ StarDictReader *reader = StarDictReaderFactory::createReader(dictPath);
+ QByteArray raw = reader->readString(offset, len);
+ QString result= format(raw, settings()->value("sametypesequence"),key);
- /*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("<","<").
- replace(">",">");
- 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;
+ delete reader;
+ return result;
}
-void XdxfPlugin::stop() {
- //qDebug()<<"stop";
+void StarDictPlugin::stop() {
stopped=true;
}
-DictDialog* XdxfPlugin::dictDialog() {
+DictDialog* StarDictPlugin::dictDialog() {
return _dictDialog;
}
-CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
- XdxfPlugin *plugin = new XdxfPlugin();
+CommonDictInterface* StarDictPlugin::getNew(const Settings *settings) const {
+ StarDictPlugin *plugin = new StarDictPlugin();
connect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
this, SIGNAL(notify(Notify::NotifyType,QString)));
- ((XdxfDictDialog*)plugin->dictDialog())->setLastDialogParent(_dictDialog->lastDialogParent());
-
-
+ ((StarDictDialog*)plugin->dictDialog())->
+ setLastDialogParent(_dictDialog->lastDialogParent());
if(settings && plugin->setSettings(settings)) {
-
- disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
- this, SIGNAL(notify(Notify::NotifyType,QString)));
+ disconnect( plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
+ plugin->getDictionaryInfo();
return plugin;
}
else {
- disconnect(plugin, SIGNAL(notify(Notify::NotifyType,QString)),
- this, SIGNAL(notify(Notify::NotifyType,QString)));
+ disconnect( plugin, SIGNAL(notify(Notify::NotifyType,QString)),
+ this, SIGNAL(notify(Notify::NotifyType,QString)));
delete plugin;
return 0;
}
}
-bool XdxfPlugin::isAvailable() const {
+bool StarDictPlugin::isAvailable() const {
return true;
}
-Settings* XdxfPlugin::settings() {
+Settings* StarDictPlugin::settings() {
return _settings;
}
-bool XdxfPlugin::isCached() {
- if(_settings->value("cached") == "true")
- return true;
- return false;
-}
-
-
-bool XdxfPlugin::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")=="true"
- && _settings->value("cache_path")!="") {
- db_name = _settings->value("type")
- + _settings->value("cache_path");
- db = QSqlDatabase::addDatabase("QSQLITE",db_name);
- }
- }
+bool StarDictPlugin::setSettings(const Settings *sett) {
+ if(sett) {
+ foreach(QString key, sett->keys())
+ _settings->setValue(key, sett->value(key));
- if((_settings->value("cached") == "false" ||
- _settings->value("cached").isEmpty()) &&
- settings->value("generateCache") == "true") {
- clean();
- makeCache("");
- }
-
- else if (settings->value("generateCache") == "false") {
- _settings->setValue("cached", "false");
- }
- }
- else
+ } else
return false;
Q_EMIT settingsChanged();
return true;
}
-bool XdxfPlugin::getDictionaryInfo() {
- 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 dictionary cannot be read from file")));
- qDebug()<<"Error: could not open 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;
-}
-
-
-QIcon* XdxfPlugin::icon() {
- return &_icon;
-}
-
-
-int XdxfPlugin::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;
-}
-
-
-bool XdxfPlugin::makeCache(QString) {
-
- XdxfCachingDialog d(_dictDialog->lastDialogParent());
-
-// qDebug()<<_dictDialog->lastDialogParent();
-
- connect(&d, SIGNAL(cancelCaching()),
- this, SLOT(stop()));
- connect(this, SIGNAL(updateCachingProgress(int,int)),
- &d, SLOT(updateCachingProgress(int,int)));
-
- d.show();
-
- QCoreApplication::processEvents();
- QFileInfo dictFileN(_settings->value("path"));
- QString cachePathN;
- stopped = false;
-
- /*create cache file name*/
- int i=0;
- do {
- cachePathN = QDir::homePath() + "/.mdictionary/"
- + dictFileN.completeBaseName()+"."
- +QString::number(i) + ".cache";
- i++;
- } while(QFile::exists(cachePathN));
-
- db_name = _settings->value("type") + cachePathN;
- db = QSqlDatabase::addDatabase("QSQLITE",db_name);
-
- /*checke errors (File open and db open)*/
- QFile dictionaryFile(dictFileN.filePath());
- if (!QFile::exists(_settings->value("path"))
- || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
- Q_EMIT updateCachingProgress(100, 0);
+bool StarDictPlugin::getDictionaryInfo() {
+ QFile file(settings()->value("ifoFileName"));
+ if(!QFile::exists(_settings->value("ifoFileName"))
+ || !file.open(QFile::ReadOnly | QFile::Text)) {
Q_EMIT notify(Notify::Warning,
- QString(tr("XDXF file cannot be read for %1 dictionary")
- .arg(name())));
- return 0;
- }
- QXmlStreamReader reader(&dictionaryFile);
- db.setDatabaseName(cachePathN);
- if(!db.open()) {
- qDebug() << "Database error" << db.lastError().text() << endl;
- Q_EMIT updateCachingProgress(100, 0);
- Q_EMIT notify(Notify::Warning, QString(tr("Cache database cannot be "
- "opened for %1 dictionary. Searching in XDXF file. "
- "You may want to recache.").arg(name())));
+ QString(tr("StarDict dictionary cannot be read from file")));
+ qDebug()<<"Error: could not open the file";
return false;
}
-
- /*inicial sqlQuery*/
- QCoreApplication::processEvents();
- QSqlQuery cur(db);
- cur.exec("PRAGMA synchronous = 0");
- cur.exec("drop table dict");
- QCoreApplication::processEvents();
- cur.exec("create table dict(word text, normalized text ,translation text)");
- int counter = 0;
- cur.exec("BEGIN;");
-
- QString readKey;
- bool match = false;
- QTime timer;
- timer.start();
- countWords();
- int lastProg = -1;
- _settings->setValue("strip_accents", "true");
- counter=0;
-
- /*add all words to db*/
- while (!reader.atEnd() && !stopped) {
-
- QCoreApplication::processEvents();
- reader.readNext();
- if(reader.tokenType() == QXmlStreamReader::StartElement) {
- if(reader.name()=="k"){
- readKey = reader.readElementText();
- 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("<","<").replace(">"
- ,">");
- reader.readNext();
- }
- if(temp.at(0)==QChar('\n'))
- temp.remove(0,1);
- temp="<key>" + readKey + "</key>" + "<t>" + temp+ "</t>";
- match=false;
- cur.prepare("insert into dict values(?,?,?)");
- cur.addBindValue(readKey.toLower());
- cur.addBindValue(removeAccents(readKey).toLower());
- cur.addBindValue(temp);
- cur.exec();
- counter++;
- int prog = counter*100/_wordsCount;
- if(prog % 2 == 0 && lastProg != prog) {
- Q_EMIT updateCachingProgress(prog,timer.restart());
- lastProg = prog;
- }
+ QTextStream in(&file);
+ while (!in.atEnd()) {
+ QString line = in.readLine();
+ QStringList list = line.split("=");
+ if(list.size() == 2) {
+ settings()->setValue(list.at(0),list.at(1));
}
}
- cur.exec("END;");
- cur.exec("select count(*) from dict");
-
- /*checke errors (wrong number of added words)*/
- countWords();
- if(!cur.next() || countWords() != cur.value(0).toInt()) {
- Q_EMIT updateCachingProgress(100, timer.restart());
- Q_EMIT notify(Notify::Warning,
- QString(tr("Database caching error, please try again.")));
- db.close();
- _settings->setValue("cache_path", cachePathN);
- if(stopped)
- clean();
- _settings->setValue("cache_path","");
- return false;
- }
-
- _settings->setValue("cache_path", cachePathN);
- _settings->setValue("cached", "true");
-
- disconnect(&d, SIGNAL(cancelCaching()),
- this, SLOT(stop()));
- disconnect(this, SIGNAL(updateCachingProgress(int,int)),
- &d, SLOT(updateCachingProgress(int,int)));
- db.close();
+ _name = settings()->value("bookname");
return true;
}
-void XdxfPlugin::clean() {
- if(QFile::exists(_settings->value("cache_path"))) {
- QFile(_settings->value("cache_path")).remove();
- QSqlDatabase::removeDatabase(db_name);
- }
-}
+QIcon* StarDictPlugin::icon() {
+ return &_icon;
+}
-Q_EXPORT_PLUGIN2(xdxf, XdxfPlugin)
+Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)