cacheLayout = new QHBoxLayout;
verticalLayout->addLayout(cacheLayout);
- cacheButton = new QPushButton(tr("Cache"));
- if(plugin->settings()->value("Cached") == "true") {
- cacheButton->setEnabled(false);
+ cacheCheckBox = new QCheckBox(tr("Cached"));
+ if(plugin->settings()->value("cached") == "true") {
+ cacheCheckBox->setChecked(true);
+ _generateCache = true;
+ }
+ else {
+ cacheCheckBox->setChecked(false);
+ _generateCache = false;
}
- cacheLayout->addWidget(cacheButton);
+ cacheLayout->addWidget(cacheCheckBox);
saveButton = new QPushButton(tr("Save settings"));
connect(saveButton, SIGNAL(clicked()),
this, SLOT(accept()));
+ connect(cacheCheckBox, SIGNAL(toggled(bool)),
+ SLOT(setGenerateCache(bool)));
+
_dicitonaryFilePath = plugin->settings()->value("path");
}
+void XdxfSettingsDialog::setGenerateCache(bool generate) {
+ _generateCache = generate;
+}
+
+bool XdxfSettingsDialog::generateCache() {
+ return _generateCache;
+}
+
void XdxfSettingsDialog::selectFile() {
QString fileName = QFileDialog::getOpenFileName(this,
tr("Select dictionary file"),
foreach(QString key, plugin->settings()->keys())
settings->setValue(key, plugin->settings()->value(key));
settings->setValue("path", settingsDialog.dicitonaryFilePath());
+
+ if(settingsDialog.generateCache()) {
+ settings->setValue("cached", "true");
+ }
+ else {
+ settings->setValue("cached", "false");
+ }
plugin->setSettings(settings);
return NULL;
}
QString dicitonaryFilePath();
//! Returns if user want to cache dictionary
- // bool generateCache();
+ bool generateCache();
private Q_SLOTS:
void selectFile();
+ void setGenerateCache(bool);
private:
QLabel* infoLabel;
QPushButton* saveButton;
QPushButton* browseButton;
QLabel* browseLabel;
- QPushButton* cacheButton;
+ QCheckBox* cacheCheckBox;
QVBoxLayout* verticalLayout;
QHBoxLayout* browseLayout;
QHBoxLayout* cacheLayout;
void XdxfPlugin::setPath(QString path){
this->path=path;
_settings->setValue("path",path);
- getDictionaryInfo();
+ //getDictionaryInfo();
}
XdxfPlugin *plugin = new XdxfPlugin();
if(settings){
plugin->setPath(settings->value("path"));
+
QStringList list = settings->keys();
foreach(QString key, list)
plugin->settings()->setValue(key, settings->value(key));
- //if(plugin->settings()->value("cached") != "true")
+
+//if(plugin->settings()->value("cached") != "true")
plugin->db_name = plugin->_settings->value("type")
+ plugin->_settings->value("path");
plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
plugin->makeCache("");
+ plugin->getDictionaryInfo();
+
}
return plugin;
}
}
void XdxfPlugin::setSettings(Settings *settings) {
- _settings = settings;
- setPath(_settings->value("path"));
+
+ QString oldPath = _settings->value("path");
+ if(oldPath != settings->value("path")) {
+ setPath(settings->value("path"));
+ }
+
+ if(_settings->value("cached") == "false" &&
+ settings->value("cached") == "true") {
+ makeCache("");
+ }
+ else {
+ _settings->setValue("cached", settings->value("cached"));
+ }
+
emit settingsChanged();
}
bool XdxfPlugin::makeCache(QString dir) {
cachingDialog->setVisible(true);
+ QCoreApplication::processEvents();
QFileInfo dictFileN(_settings->value("path"));
QString cachePathN;
cachePathN = QDir::homePath() + "/.mdictionary/"
qDebug() << "Database error" << endl;
return false;
}
+ QCoreApplication::processEvents();
QSqlQuery cur(db);
cur.exec("PRAGMA synchronous = 0");
cur.exec("drop table dict");
cur.exec("create table dict(word text ,transl text)");
+ QCoreApplication::processEvents();
int counter = 0;
cur.exec("BEGIN;");
}
}
- cachingDialog->setVisible(false);
qDebug()<<counter;
cur.exec("END;");
cur.exec("select count(*) from dict");
+
+ countWords();
+ cachingDialog->setVisible(false);
+
if(!cur.next() || countWords() != cur.value(0).toInt())
return false;
_settings->setValue("cache_path", cachePathN);
_settings->setValue("cached", "true");
+
return true;
}