#include "xdxfplugin.h"
#include <QDebug>
+#include "../../../includes/Notify.h"
XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
_langFrom(tr("")), _langTo(tr("")),_name(tr("")),
}
QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
- //if(_settings->value("cached") == "true")
if(word.indexOf("*")==-1 && word.indexOf("?")==-1 && word.indexOf("_")==-1
&& word.indexOf("%")==-1)
word+="*";
db.setDatabaseName(cacheFilePath);
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return searchWordListFile(word, limit);
}
word = word.replace("*", "%");
word = word.replace("?", "_");
word = removeAccents(word);
- //qDebug() << word;
QSqlQuery cur(db);
if(limit !=0)
regWord.setPatternSyntax(QRegExp::Wildcard);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1").arg(name()));
return translations.toList();
}
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return searchFile(key);
}
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
- qDebug()<<"Error: could not open file when search";
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1").arg(name()));
+ qDebug()<<"Error: could not open file";
return "";
}
QXmlStreamReader reader(&dictionaryFile);
void XdxfPlugin::getDictionaryInfo() {
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read dictionary"));
qDebug()<<"Error: could not open file";
return;
}
QString format = "png";
QString initialPath = QDir::currentPath() + tr("/xdxf.") + format;
-// qDebug()<<initialPath;
-// QPixmap test(":/icons/xdxf.png");
-// qDebug()<<QPixmap(test).save(initialPath,format.toAscii());
-// qDebug()<<QPixmap("/home/jakub/star.jpg").save(initialPath,format.toAscii());
_infoNote="path=\""+initialPath+"\">"+"\n" + _name + " [" + _langFrom + "-" + _langTo + "] "+ "(" + _type + ")";
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1 dictionary")
+ .arg(name()));
qDebug()<<"Error: could not open file";
return -1;
}
if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ Q_EMIT updateCachingProgress(100, 0);
+ Q_EMIT notify(Notify::Warning,
+ QString("Xdxf file cannot be read for %1 dictionary")
+ .arg(name()));
return 0;
}
db.setDatabaseName(cachePathN);
if(!db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
+ Q_EMIT updateCachingProgress(100, 0);
+ Q_EMIT notify(Notify::Warning, QString("Cache database cannot be "
+ "opened for %1 dictionary. Searching in xdxf file. "
+ "You may want to recache.").arg(name()));
return false;
}
QCoreApplication::processEvents();
if(!cur.next() || countWords() != cur.value(0).toInt())
{
+ Q_EMIT updateCachingProgress(100, timer.restart());
+ Q_EMIT notify(Notify::Warning,
+ QString("Database caching error, please try againg."));
db.close();
return false;
}