Merge branch 'cache' of ssh://drop.maemo.org/git/mdictionary into cache
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 18 Aug 2010 09:57:13 +0000 (11:57 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Wed, 18 Aug 2010 09:57:13 +0000 (11:57 +0200)
1  2 
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

@@@ -102,6 -102,7 +102,7 @@@ QList<Translation*> XdxfPlugin::searchW
          while(cur.next())
              translations.insert(new TranslationXdxf(cur.value(0).toString(),
                                                      _infoNote, this));
+         db.close();
          return translations.toList();
  }
  
@@@ -136,7 -137,8 +137,7 @@@ QList<Translation*> XdxfPlugin::searchW
              if(regWord.exactMatch(removeAccents(a)) && (i<limit || limit==0)) {
                  bool ok=true;
                  Translation *tran;
 -                foreach(tran,translations)
 -                {
 +                foreach(tran,translations) {
                      if(tran->key()==a)
                          ok=false;  /*if key word is in the dictionary more that one */
                  }
@@@ -179,6 -181,7 +180,7 @@@ QString XdxfPlugin::searchCache(QStrin
      cur.exec();
      if(cur.next())
          result = cur.value(0).toString();
+     db.close();
      return result;
  
  }
@@@ -262,6 -265,7 +264,7 @@@ CommonDictInterface* XdxfPlugin::getNew
  
          plugin->db_name = plugin->_settings->value("type")
                 + plugin->_settings->value("path");
+         if(!plugin->db.connectionName().isEmpty())
          plugin->db = QSqlDatabase::addDatabase("QSQLITE", plugin->db_name);
  
          if(settings->value("cached").isEmpty() &&
@@@ -278,11 -282,13 +281,11 @@@ bool XdxfPlugin::isAvailable() const 
      return true;
  }
  
 -void XdxfPlugin::setHash(uint _hash)
 -{
 +void XdxfPlugin::setHash(uint _hash) {
      this->_hash=_hash;
  }
  
 -uint XdxfPlugin::hash() const
 -{
 +uint XdxfPlugin::hash() const {
     return _hash;
  }
  
@@@ -290,7 -296,8 +293,7 @@@ Settings* XdxfPlugin::settings() 
      return _settings;
  }
  
 -bool XdxfPlugin::isCached()
 -{
 +bool XdxfPlugin::isCached() {
      if(_settings->value("cached") == "true")
          return true;
      return false;
@@@ -410,9 -417,10 +413,9 @@@ bool XdxfPlugin::makeCache(QString dir
  
      QXmlStreamReader reader(&dictionaryFile);
  
 -
      db.setDatabaseName(cachePathN);
      if(!db.open()) {
 -        qDebug() << "Database error" << endl;
 +        qDebug() << "Database error" << db.lastError().text() << endl;
          return false;
      }
      QCoreApplication::processEvents();
      while (!reader.atEnd() && !stopped) {
  
          QCoreApplication::processEvents();
 -       // usleep(50);
          reader.readNext();
  
          if(reader.tokenType() == QXmlStreamReader::StartElement) {
      cachingDialog->setVisible(false);
  
      if(!cur.next() || countWords() != cur.value(0).toInt())
+     {
+         db.close();
          return false;
+     }
      _settings->setValue("cache_path", cachePathN);
      _settings->setValue("cached", "true");
  
+     db.close();
      return true;
  }