fig delete settings
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 2 Sep 2010 09:28:24 +0000 (11:28 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 2 Sep 2010 09:28:24 +0000 (11:28 +0200)
trunk/src/base/backbone/backbone.cpp
trunk/src/base/gui/DictManagerWidget.cpp
trunk/src/includes/translation.h
trunk/src/plugins/google/src/GooglePlugin.cpp
trunk/src/plugins/google/src/GoogleSettingsDialog.cpp
trunk/src/plugins/xdxf/src/TranslationXdxf.cpp
trunk/src/plugins/xdxf/src/XdxfLoadDialog.cpp
trunk/src/plugins/xdxf/src/XdxfSettingsDialog.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp

index b2c5fb4..a206bb6 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 aee710e..2a54b9a 100644 (file)
@@ -181,6 +181,7 @@ void DictManagerWidget::addNewDictButtonClicked() {
 
        if(settings != NULL) {
            CommonDictInterface* newDict = selectedPlugin->getNew(settings);
+           delete settings;
            Q_EMIT addDictionary(newDict);
        }
    }
@@ -198,8 +199,8 @@ void DictManagerWidget::removeButtonClicked() {
             QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
         QList<QListWidgetItem*> selected = dictListWidget->selectedItems();
         if(selected.count() > 0) {
-            refreshDictsList();
             emit removeDictionary(dictsHash[selected[0]]);
+            refreshDictsList();
         }
    }
 }
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 3fe8907..a93a37c 100644 (file)
@@ -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..d505d7a 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..03829c5 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);
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 d94ea20..812bf2c 100644 (file)
@@ -333,6 +333,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;
 }
 
@@ -509,7 +516,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*/
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)