Merge branch 'master' into qmake
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 2 Sep 2010 12:18:31 +0000 (14:18 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Thu, 2 Sep 2010 12:18:31 +0000 (14:18 +0200)
Conflicts:
mdictionary.pro
src/mdictionary/gui/WordListWidget.cpp
trunk/src/base/base.pro
trunk/src/plugins/xdxf/src/src.pro

17 files changed:
src/common/translation.h
src/mdictionary/backbone/BookmarkTranslations.h
src/mdictionary/backbone/Bookmarks.cpp
src/mdictionary/backbone/Bookmarks.h
src/mdictionary/backbone/backbone.cpp
src/mdictionary/gui/DictManagerWidget.cpp
src/mdictionary/gui/SearchBarWidget.cpp
src/mdictionary/gui/TranslationWidget.cpp
src/mdictionary/gui/WordListWidget.cpp
src/mdictionary/gui/WordListWidget.h
src/plugins/google/GooglePlugin.cpp
src/plugins/google/GoogleSettingsDialog.cpp
src/plugins/xdxf/TranslationXdxf.cpp
src/plugins/xdxf/XdxfLoadDialog.cpp
src/plugins/xdxf/XdxfSettingsDialog.cpp
src/plugins/xdxf/xdxfplugin.cpp
tests/XdxfPluginTests/test.cpp

index 6fca57c..a6a20a9 100644 (file)
@@ -30,6 +30,8 @@
 
 #include <QString>
 #include <QMetaType>
+#include <QDebug>
+
 class CommonDictInterface;
 
 
@@ -38,7 +40,7 @@ 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;
index b3c5345..0748d30 100644 (file)
 #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;
index 527a8a5..c39f868 100644 (file)
@@ -7,10 +7,21 @@ 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);
@@ -90,7 +101,8 @@ QList<Translation*> Bookmarks::list() {
     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;
 }
@@ -103,7 +115,6 @@ QList<Translation*> Bookmarks::searchWordList(QString word) {
         word+="%";
     word = word.replace("*", "%");
     word = word.replace("?", "_");
-    qDebug() << word;
 
     QList<Translation*> tr;
     QSqlDatabase db = getDbCnx(dbName);
@@ -128,7 +139,7 @@ QList<Translation*> Bookmarks::searchWordList(QString word) {
 
 
 QStringList Bookmarks::search(QString word, QString dbName) {
-    checkAndCreateDb();
+    //checkAndCreateDb();
     QStringList result;
     QSqlDatabase db = getDbCnx(dbName);
     if(!db.isOpen() && !db.open()) {
@@ -150,18 +161,15 @@ QStringList Bookmarks::search(QString word, QString dbName) {
 
 
 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;
 }
index 8fa5d66..d0fea98 100644 (file)
@@ -56,6 +56,7 @@ class BookmarkTranslation;
 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
@@ -103,6 +104,7 @@ private:
     QSqlDatabase getDbCnx(QString dbName);
     QMap<QChar, QRegExp> letters;
     QRegExp noLetter;
+    QSqlDatabase mdb;
 
 };
 
index 4bbbd78..16bb487 100644 (file)
@@ -263,7 +263,10 @@ void Backbone::addDictionary(CommonDictInterface *dict, bool active) {
 
  void Backbone::removeDictionary(CommonDictInterface *dict) {
      _dicts.remove(dict);
-     dict->clean();
+     if(dict)
+        dict->clean();
+     else
+        qDebug()<<"delete empty dict";
      delete dict;
      dictUpdated();
 
@@ -453,6 +456,7 @@ void Backbone::loadDicts(QString fileName) {
 
         set.endGroup();
         addInternalDictionary(plug->getNew(plugSet), active);
+        delete plugSet;
     }
 }
 
index f0cae5f..4794eb1 100644 (file)
@@ -181,6 +181,7 @@ void DictManagerWidget::addNewDictButtonClicked() {
 
        if(settings != NULL) {
            CommonDictInterface* newDict = selectedPlugin->getNew(settings);
+           delete settings;
            Q_EMIT addDictionary(newDict);
        }
    }
index 0652236..62ee99a 100644 (file)
@@ -120,7 +120,7 @@ void SearchBarWidget::initializeUI() {
 
 
 
-    completerModel = new QStringListModel;
+    completerModel = new QStringListModel(this);
 
 
     lineEditCompleter = new QCompleter(searchWordLineEdit);
index 5cea174..ab9f787 100644 (file)
@@ -220,6 +220,7 @@ void TranslationWidget::initializeUI() {
     if(!fac)
         fac++;
     webkit->setZoomFactor(fac);
+    delete set;
 
     QWidget*w = new QWidget(this);
     verticalLayout = new QVBoxLayout(w);
index 8085a05..7d6eaab 100644 (file)
@@ -39,7 +39,8 @@ WordListWidget::WordListWidget(QWidget *parent):
     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
@@ -49,6 +50,12 @@ WordListWidget::WordListWidget(QWidget *parent):
     #endif
 }
 
+
+WordListWidget::~WordListWidget() {
+    if(proxyStyle)
+        delete proxyStyle;
+}
+
 void WordListWidget::addWord(QString word, int row) {
     QStandardItem* item = new QStandardItem(word);
 
index cc6d72e..f06d889 100644 (file)
@@ -27,6 +27,7 @@
 #include <QtGui>
 #include <QStringListModel>
 #include "../backbone/backbone.h"
+#include "WordListProxyStyle.h"
 
 //! Displays list of words found in dictionaries
 /*!
@@ -40,6 +41,7 @@ class WordListWidget : public QTreeView {
     Q_OBJECT
 public:
     explicit WordListWidget(QWidget *parent = 0);
+    ~WordListWidget();
 
 
 Q_SIGNALS:
@@ -103,6 +105,7 @@ private:
 
     //! Association between words and their translations
     QHash<QString, QList<Translation*> > searchResult;
+    WordListProxyStyle* proxyStyle;
 };
 
 #endif // WORDLISTWIDGET_H
index 3fe8907..4e53601 100644 (file)
@@ -36,7 +36,6 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
     _settings->setValue("connection_accepted","true");
     _dictDialog = new GoogleDictDialog(this,this);
     _icon = QIcon(":/icons/drawing.png");
-    _hash=123456;
 
     stopped = false;
     languages=initLanguages();
@@ -48,6 +47,7 @@ GooglePlugin::GooglePlugin(QObject *parent): CommonDictInterface(parent),
 
 GooglePlugin::~GooglePlugin() {
     delete _settings;
+    delete _dictDialog;
 }
 
 
@@ -122,11 +122,13 @@ void GooglePlugin::setHash(uint _hash) {
 
 
 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;
 }
 
 
@@ -148,7 +150,8 @@ QIcon* GooglePlugin::icon() {
 
 CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const {
     GooglePlugin *plugin = new GooglePlugin();
-    plugin->setSettings(settings);
+    if(settings)
+        plugin->setSettings(settings);
     return plugin;
 }
 
index cdadfe2..91782ba 100644 (file)
@@ -182,6 +182,6 @@ void GoogleSettingsDialog::changeSettings(GooglePlugin* 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;
 }
index c214a7b..0bd9718 100644 (file)
@@ -28,6 +28,7 @@
 
 TranslationXdxf::TranslationXdxf():_key(""),_dictionaryInfo("") {
     xdxfPlugin=0;
+//   qDebug()<<"\n\n create translaton Xdxf\n\n";
 }
 
 TranslationXdxf::TranslationXdxf(QString _key, QString _dictionaryInfo,
@@ -36,10 +37,12 @@ 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 {
index 4bb5282..c3ce79e 100644 (file)
@@ -46,8 +46,8 @@ XdxfLoadDialog::XdxfLoadDialog(QWidget *parent) :
 
     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);
@@ -78,7 +78,6 @@ void XdxfLoadDialog::selectFile() {
                                      NULL);
 
     if (!fileName.isEmpty()) {
-        qDebug()<<fileName;
         browseLabel->setText(tr("Dictionary file: %1").arg(fileName));
         _dicitonaryFilePath = fileName;
     }repaint(rect());
index 9f2a3d6..7afb707 100644 (file)
@@ -30,7 +30,7 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
     QDialog(parent)
 {
     this->plugin = plugin;
-    verticalLayout = new QVBoxLayout(this);
+    verticalLayout = new QVBoxLayout();
        setLayout(verticalLayout);
 
     setWindowTitle(tr("XDXF Settings"));
@@ -45,18 +45,18 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
 
     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)"));
@@ -79,7 +79,7 @@ XdxfSettingsDialog::XdxfSettingsDialog(XdxfPlugin *plugin, QWidget *parent) :
 
     cacheLayout->addWidget(cacheCheckBox);
 
-    saveButton = new QPushButton(tr("Save settings"),this);
+    saveButton = new QPushButton(tr("Save settings"));
 
     verticalLayout->addWidget(saveButton);
 
@@ -146,6 +146,7 @@ Settings* XdxfSettingsDialog::getSettings(XdxfPlugin *plugin,
             settings->setValue("strip_accents", "false");
 
         plugin->setSettings(settings);
+        delete settings;
         return 0;
     }
 
index ba143b9..9a29f8a 100644 (file)
@@ -49,6 +49,7 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
 XdxfPlugin::~XdxfPlugin() {
     delete _settings;
     delete cachingDialog;
+    delete _dictDialog;
 }
 
 
@@ -93,7 +94,6 @@ QList<Translation*> XdxfPlugin::searchWordListCache(QString word, int limit) {
     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;
@@ -309,8 +309,12 @@ DictDialog* XdxfPlugin::dictDialog() {
 
 
 CommonDictInterface* XdxfPlugin::getNew(const Settings *settings) const {
+
+    qDebug()<<"tu";
     XdxfPlugin *plugin = new XdxfPlugin();
+    qDebug()<<"tu2";
     if(settings){
+            qDebug()<<"tu3";
         plugin->setSettings(settings);
     }
     return  plugin;
@@ -333,6 +337,13 @@ uint XdxfPlugin::hash() const {
 
 
 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;
 }
 
@@ -345,8 +356,9 @@ bool XdxfPlugin::isCached() {
 
 
 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")) {
@@ -362,12 +374,14 @@ void XdxfPlugin::setSettings(const Settings *settings) {
 
         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" ||
@@ -472,6 +486,12 @@ bool XdxfPlugin::makeCache(QString) {
         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"))
@@ -509,7 +529,7 @@ bool XdxfPlugin::makeCache(QString) {
     timer.start();
     countWords();
     int lastProg = -1;
-    settings()->setValue("strip_accents", "true");
+    _settings->setValue("strip_accents", "true");
     counter=0;
 
     /*add all words to db*/
@@ -583,8 +603,10 @@ bool XdxfPlugin::makeCache(QString) {
 
 
 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);
+    }
 }
 
 
index 429b135..f7bfed6 100644 (file)
@@ -28,6 +28,7 @@ void XdxfTest::getNew() {
     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);
@@ -42,6 +43,7 @@ void XdxfTest::searchFile() {
     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>"));
@@ -58,6 +60,8 @@ void XdxfTest::makeCache()
     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();
@@ -70,6 +74,7 @@ void XdxfTest::searchCache() {
     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>"));
@@ -86,6 +91,7 @@ void XdxfTest::searchWordListCache(){
     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)
@@ -130,6 +136,7 @@ void XdxfTest::searchWordListFile() {
     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)
@@ -174,6 +181,7 @@ void XdxfTest::stop() {
     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,
@@ -187,11 +195,11 @@ void XdxfTest::stop() {
 
 
 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"));
 
@@ -217,6 +225,7 @@ void XdxfTest::timeCache() {
     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>";
@@ -264,6 +273,7 @@ void XdxfTest::timeFile() {
     Settings *settings=new Settings;
     settings->setValue("path","../../../../../../dict.xdxf");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+    delete settings;
 
     timer.start();
     xdxfPlugin->search("Bantu");
@@ -309,6 +319,7 @@ void  XdxfTest::timeCacheNormalize() {
     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>";
@@ -342,6 +353,7 @@ void  XdxfTest::removeAccents() {
 
     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"));
@@ -372,6 +384,7 @@ void XdxfTest::timeFileNormalize(){
     settings->setValue("path","../../../../../../dict.xdxf");
     settings->setValue("strip_accents", "true");
     CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings);
+    delete settings;
 
     timer.start();
     xdxfPlugin->search("Bantu");
@@ -396,7 +409,6 @@ void XdxfTest::timeFileNormalize(){
     File.close();
     xdxfPlugin->clean();
     delete xdxfPlugin;
-
 }
 
 QTEST_MAIN(XdxfTest)