#include <QString>
#include <QMetaType>
+#include <QDebug>
+
class CommonDictInterface;
as late as possible*/
class Translation {
public:
- Translation () { _bookmark = 0; }
+ Translation () { _bookmark = 0;}
virtual ~Translation () {}
//! \return word to be translated
virtual QString key() const = 0;
#include "../../common/settings.h"
#include "../../common/translation.h"
#include "Bookmarks.h"
+#include "QObject"
class BookmarkTranslation : public Translation
{
public:
- BookmarkTranslation(QString key, Bookmarks* bookmarks, QString dbName) {
+ BookmarkTranslation(QString key, Bookmarks* bookmarks, QString dbName){
_key = key;
_dictionaryInfo = dbName;
_bookmarks = bookmarks;
+ "bookmarks.db";
checkAndCreateDb();
initAccents();
+
+ mdb = QSqlDatabase::addDatabase("QSQLITE",
+ QString("%2").arg((int)QThread::currentThreadId()));
+ mdb.setDatabaseName(dbName);
+}
+
+
+Bookmarks::~Bookmarks() {
+ mdb.close();
}
QSqlDatabase Bookmarks::getDbCnx(QString dbName) {
+ QSqlDatabase::removeDatabase(
+ QString("%2").arg((int)QThread::currentThreadId()));
QSqlDatabase db =QSqlDatabase::addDatabase("QSQLITE",
QString("%2").arg((int)QThread::currentThreadId()));
db.setDatabaseName(dbName);
QSqlQuery cur(db);
cur.exec("select distinct key from bookmarks");
while(cur.next())
- res.append(new BookmarkTranslation(cur.value(0).toString(), this, dbName));
+ res.append(new BookmarkTranslation(cur.value(0).toString(),
+ this, dbName));
db.close();
return res;
}
word+="%";
word = word.replace("*", "%");
word = word.replace("?", "_");
- qDebug() << word;
QList<Translation*> tr;
QSqlDatabase db = getDbCnx(dbName);
QStringList Bookmarks::search(QString word, QString dbName) {
- checkAndCreateDb();
+ //checkAndCreateDb();
QStringList result;
QSqlDatabase db = getDbCnx(dbName);
if(!db.isOpen() && !db.open()) {
bool Bookmarks::inBookmarks(QString word) {
- checkAndCreateDb();
- QSqlDatabase db = getDbCnx(dbName);
- if(!db.isOpen() && !db.open()) {
- qDebug() << "Database error: " << db.lastError().text() << endl;
+ if(!mdb.isOpen() && !mdb.open()) {
+ qDebug() << "Database error: " << mdb.lastError().text() << endl;
return false;
}
- QSqlQuery cur(db);
+ QSqlQuery cur(mdb);
cur.prepare("select translation from bookmarks where key like ? limit 1");
cur.addBindValue(word);
cur.exec();
if(cur.next())
return true;
- db.close();
return false;
}
class Bookmarks : public AccentsNormalizer {
public:
Bookmarks();
+ ~Bookmarks();
/*! Adds new word and translation to bookmarks
\param translation new translation to be saved and cached as a bookmark
QSqlDatabase getDbCnx(QString dbName);
QMap<QChar, QRegExp> letters;
QRegExp noLetter;
+ QSqlDatabase mdb;
};
void Backbone::removeDictionary(CommonDictInterface *dict) {
_dicts.remove(dict);
- dict->clean();
+ if(dict)
+ dict->clean();
+ else
+ qDebug()<<"delete empty dict";
delete dict;
dictUpdated();
set.endGroup();
addInternalDictionary(plug->getNew(plugSet), active);
+ delete plugSet;
}
}
if(settings != NULL) {
CommonDictInterface* newDict = selectedPlugin->getNew(settings);
+ delete settings;
Q_EMIT addDictionary(newDict);
}
}
- completerModel = new QStringListModel;
+ completerModel = new QStringListModel(this);
lineEditCompleter = new QCompleter(searchWordLineEdit);
if(!fac)
fac++;
webkit->setZoomFactor(fac);
+ delete set;
QWidget*w = new QWidget(this);
verticalLayout = new QVBoxLayout(w);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//set our custom style to draw checkboxes as stars
- setStyle(new WordListProxyStyle);
+ proxyStyle = new WordListProxyStyle();
+ setStyle(proxyStyle);
//setting size of star in pixels, on maemo checboxes are much bigger
#ifdef Q_WS_MAEMO_5
#endif
}
+
+WordListWidget::~WordListWidget() {
+ if(proxyStyle)
+ delete proxyStyle;
+}
+
void WordListWidget::addWord(QString word, int row) {
QStandardItem* item = new QStandardItem(word);
#include <QtGui>
#include <QStringListModel>
#include "../backbone/backbone.h"
+#include "WordListProxyStyle.h"
//! Displays list of words found in dictionaries
/*!
Q_OBJECT
public:
explicit WordListWidget(QWidget *parent = 0);
+ ~WordListWidget();
Q_SIGNALS:
//! Association between words and their translations
QHash<QString, QList<Translation*> > searchResult;
+ WordListProxyStyle* proxyStyle;
};
#endif // WORDLISTWIDGET_H
_settings->setValue("connection_accepted","true");
_dictDialog = new GoogleDictDialog(this,this);
_icon = QIcon(":/icons/drawing.png");
- _hash=123456;
stopped = false;
languages=initLanguages();
GooglePlugin::~GooglePlugin() {
delete _settings;
+ delete _dictDialog;
}
Settings* GooglePlugin::settings() {
- Settings *returnSettings=new Settings;
+/* Settings *returnSettings=new Settings;
QStringList list = _settings->keys();
foreach(QString key, list)
returnSettings->setValue(key,_settings->value(key));
return returnSettings;
+*/
+ return _settings;
}
CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const {
GooglePlugin *plugin = new GooglePlugin();
- plugin->setSettings(settings);
+ if(settings)
+ plugin->setSettings(settings);
return plugin;
}
QWidget *parent) {
Settings *settings = new Settings();
settings=getSettings(parent,plugin->settings(),tr("Save changes"));
- if(settings)
- plugin->setSettings(settings);
+ plugin->setSettings(settings);
+ delete settings;
}
TranslationXdxf::TranslationXdxf():_key(""),_dictionaryInfo("") {
xdxfPlugin=0;
+// qDebug()<<"\n\n create translaton Xdxf\n\n";
}
TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo,
if(xdxfPlugin)
_dictHash = xdxfPlugin->hash();
_bookmark=0;
+
+// qDebug()<<"create translaton Xdxf";
}
TranslationXdxf::~TranslationXdxf() {
- // qDebug()<<"\n\n delete translation:: Xdxf\n\n";
+// qDebug()<<"delete translation:: Xdxf";
}
QString TranslationXdxf::key() const {
cacheLayout = new QHBoxLayout;
verticalLayout->addLayout(cacheLayout);
- accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more time, "
- "but spelling don't have to be exact)"));
+ accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more "
+ "time, but spelling don't have to be exact)"));
verticalLayout->addWidget(accentsCheckBox);
cacheCheckBox = new QCheckBox(tr("Optimize for quicker searches (may take some time)"),this);
NULL);
if (!fileName.isEmpty()) {
- qDebug()<<fileName;
browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
_dicitonaryFilePath = fileName;
}repaint(rect());
QDialog(parent)
{
this->plugin = plugin;
- verticalLayout = new QVBoxLayout(this);
+ verticalLayout = new QVBoxLayout();
setLayout(verticalLayout);
setWindowTitle(tr("XDXF Settings"));
verticalLayout->addWidget(infoLabel);
- browseLayout = new QHBoxLayout(this);
+ browseLayout = new QHBoxLayout();
verticalLayout->addLayout(browseLayout);
- browseButton = new QPushButton(tr("Browse"),this);
+ browseButton = new QPushButton(tr("Browse"));
browseLabel = new QLabel(tr("Dictionary file: ") +
- plugin->settings()->value("path"),this);
+ plugin->settings()->value("path"));
browseLayout->addWidget(browseLabel);
browseLayout->addWidget(browseButton,0, Qt::AlignRight);
- cacheLayout = new QHBoxLayout(this);
+ cacheLayout = new QHBoxLayout();
verticalLayout->insertLayout(-1,cacheLayout,0);
accentsCheckBox = new QCheckBox(tr("Strip accents \n(searching takes more time, "
"but spelling don't have to be exact)"));
cacheLayout->addWidget(cacheCheckBox);
- saveButton = new QPushButton(tr("Save settings"),this);
+ saveButton = new QPushButton(tr("Save settings"));
verticalLayout->addWidget(saveButton);
settings->setValue("strip_accents", "false");
plugin->setSettings(settings);
+ delete settings;
return 0;
}
XdxfPlugin::~XdxfPlugin() {
delete _settings;
delete cachingDialog;
+ delete _dictDialog;
}
QSet<Translation*> translations;
QString cacheFilePath = _settings->value("cache_path");
-// QSqlDatabase::removeDatabase(cacheFilePath);
db.setDatabaseName(cacheFilePath);
if(!QFile::exists(cacheFilePath) || !db.open()) {
qDebug() << "Database error" << db.lastError().text() << endl;
CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+
+ qDebug()<<"tu";
XdxfPlugin *plugin = new XdxfPlugin();
+ qDebug()<<"tu2";
if(settings){
+ qDebug()<<"tu3";
plugin->setSettings(settings);
}
return plugin;
Settings* XdxfPlugin::settings() {
+/*
+ Settings *returnSettings=new Settings;
+ QStringList list = _settings->keys();
+ foreach(QString key, list)
+ returnSettings->setValue(key,_settings->value(key));
+ return returnSettings;
+*/
return _settings;
}
void XdxfPlugin::setSettings(const Settings *settings) {
+ qDebug()<<"tu4";
if(settings) {
-
+ qDebug()<<"tu5";
bool isPathChange=false;
QString oldPath = _settings->value("path");
if(oldPath != settings->value("path")) {
if(isPathChange) {
_wordsCount=0;
- if(oldPath!="") {
+ if(oldPath!="")
_settings->setValue("cached","false");
- QSqlDatabase::removeDatabase(db_name);
+ if(_settings->value("cached")=="true"
+ && _settings->value("cache_path")!="") {
+ db_name = _settings->value("type")
+ + _settings->value("cache_path");
+ db = QSqlDatabase::addDatabase("QSQLITE",db_name);
}
- db_name = _settings->value("type") + _settings->value("path");
- db = QSqlDatabase::addDatabase("QSQLITE",db_name);
}
if((_settings->value("cached") == "false" ||
i++;
} while(QFile::exists(cachePathN));
+ db_name = _settings->value("type") + cachePathN;
+ db = QSqlDatabase::addDatabase("QSQLITE",db_name);
+
+ qDebug()<<QSqlDatabase::connectionNames().size();
+ foreach(QString name,QSqlDatabase::connectionNames())
+ qDebug()<<name;
/*checke errors (File open and db open)*/
QFile dictionaryFile(dictFileN.filePath());
if (!QFile::exists(_settings->value("path"))
timer.start();
countWords();
int lastProg = -1;
- settings()->setValue("strip_accents", "true");
+ _settings->setValue("strip_accents", "true");
counter=0;
/*add all words to db*/
void XdxfPlugin::clean() {
- if(QFile::exists(_settings->value("cache_path")))
+ if(QFile::exists(_settings->value("cache_path"))) {
QFile(_settings->value("cache_path")).remove();
+ QSqlDatabase::removeDatabase(db_name);
+ }
}
Settings *settings=new Settings;
settings->setValue("path","../tests/dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QList<Translation*> te6=xdxfPlugin->searchWordList("*",8);
QCOMPARE(te6.size(),8);
Settings *settings=new Settings;
settings->setValue("path","../tests/dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
QCOMPARE(xdxfPlugin->search("1"), QString("<key>1</key><t>one</t>"));
settings->setValue("path","../tests/dict.xdxf");
settings->setValue("generateCache", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
+
QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
xdxfPlugin->clean();
settings->setValue("path","../tests/dict.xdxf");
settings->setValue("generateCache", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QCOMPARE(xdxfPlugin->settings()->value("cached"),tr("true"));
QCOMPARE(xdxfPlugin->search("."), QString("<key>.</key><t>kropka</t>"));
settings->setValue("path","../tests/dict.xdxf");
settings->setValue("generateCache", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
if(te.size()>0)
Settings *settings=new Settings;
settings->setValue("path","../tests/dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
if(te.size()>0)
Settings *settings=new Settings;
settings->setValue("path","../tests/dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QString string("*");
QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin,
void XdxfTest::langFrom() {
-
XdxfPlugin xdxfPluginB(this);
Settings *settings=new Settings;
settings->setValue("path","../tests/dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
QCOMPARE(xdxfPlugin->langFrom(), QString("ENG"));
settings->setValue("path","../../../../../../dict.xdxf");
settings->setValue("generateCache", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
out<<"\n<date>" + date.currentDate().toString("dd.MM.yyyy") +" ";
out<<timer.currentTime().toString(Qt::TextDate) + "</date>";
Settings *settings=new Settings;
settings->setValue("path","../../../../../../dict.xdxf");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
timer.start();
xdxfPlugin->search("Bantu");
settings->setValue("generateCache", "true");
settings->setValue("strip_accents", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
out<<"\n<type> Cache with strip accent </type> <time>" << timer.elapsed();
out<<"</time>";
XdxfPluginSub xdxf;
xdxf.settings()->setValue(QString("strip_accents"), QString("true"));
+
QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
QCOMPARE(xdxf.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
settings->setValue("path","../../../../../../dict.xdxf");
settings->setValue("strip_accents", "true");
CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+ delete settings;
timer.start();
xdxfPlugin->search("Bantu");
File.close();
xdxfPlugin->clean();
delete xdxfPlugin;
-
}
QTEST_MAIN(XdxfTest)