QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
int i=0;
QSet<Translation*> translations;
-
QString cacheFilePath = _settings->value("cache_path");
+
+// QSqlDatabase::removeDatabase(cacheFilePath);
db.setDatabaseName(cacheFilePath);
- if(!db.open()) {
+ 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. "
+ "opened for %1 dictionary. Searching in XDXF file. "
"You may want to recache.").arg(name())));
+ _settings->setValue("cached","false");
return searchWordListFile(word, limit);
}
-
stopped = false;
word = word.toLower();
word = word.replace("*", "%");
QRegExp regWord(word);
regWord.setCaseSensitivity(Qt::CaseInsensitive);
regWord.setPatternSyntax(QRegExp::Wildcard);
- if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+
+ /*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())));
+ QString(tr("XDXF file cannot be read for %1").arg(name())));
return translations.toList();
}
db.setDatabaseName(cacheFilePath);
key = key.toLower();
- if(!db.open()) {
+ 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. "
+ "opened for %1 dictionary. Searching in XDXF file. "
"You may want to recache.").arg(name())));
+ _settings->setValue("cached","false");
return searchFile(key);
}
}
+
QString XdxfPlugin::searchFile(QString key) {
- key = key.toLower();
- QFile dictionaryFile(path);
+ QFile dictionaryFile(_settings->value("path"));
QString resultString("");
- if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ 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())));
+ QString(tr("XDXF file cannot be read for %1").arg(name())));
qDebug()<<"Error: could not open file";
return "";
}
}
-
void XdxfPlugin::getDictionaryInfo() {
- QFile dictionaryFile(path);
- if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ 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 dictionary")));
+ QString(tr("XDXF dictionary cannot be read from file")));
qDebug()<<"Error: could not open file";
return;
}
return &_icon;
}
+
int XdxfPlugin::countWords() {
- if(_wordsCount > 0)
+ if(_wordsCount>0)
return _wordsCount;
-
- QFile dictionaryFile(path);
- if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ 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")
+ QString(tr("XDXF file cannot be read for %1 dictionary")
.arg(name())));
qDebug()<<"Error: could not open file";
return -1;
bool XdxfPlugin::makeCache(QString) {
cachingDialog->setVisible(true);
QCoreApplication::processEvents();
- stopped = false;
QFileInfo dictFileN(_settings->value("path"));
QString cachePathN;
- cachePathN = QDir::homePath() + "/.mdictionary/"
- + dictFileN.completeBaseName() + ".cache";
+ 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));
+
+ /*checke errors (File open and db open)*/
QFile dictionaryFile(dictFileN.filePath());
-
- if (!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
+ if (!QFile::exists(_settings->value("path"))
+ || !dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
Q_EMIT updateCachingProgress(100, 0);
Q_EMIT notify(Notify::Warning,
- QString(tr("Xdxf file cannot be read for %1 dictionary")
+ QString(tr("XDXF file cannot be read for %1 dictionary")
.arg(name())));
return 0;
}