Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
authorMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
committerMateusz Półrola <mateusz.polrola@comarch.pl>
Wed, 18 Aug 2010 13:37:07 +0000 (15:37 +0200)
1  2 
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

@@@ -89,7 -89,6 +89,7 @@@ QList<Translation*> XdxfPlugin::searchW
          stopped = false;
          if(word.indexOf("*")==-1 && word.indexOf("?")== 0)
              word+="%";
 +        word = word.toLower();
          word = word.replace("*", "%");
          word = word.replace("?", "_");
          word = removeAccents(word);
          cur.addBindValue(limit);
          cur.exec();
          while(cur.next())
 -            translations.insert(new TranslationXdxf(cur.value(0).toString(),
 -                                                    _infoNote, this));
 +            translations.insert(new TranslationXdxf(
 +                        cur.value(0).toString().toLower(),
 +                        _infoNote, this));
          return translations.toList();
  }
  
@@@ -113,7 -111,6 +113,7 @@@ QList<Translation*> XdxfPlugin::searchW
      QSet<Translation*> translations;
      QFile dictionaryFile(path);
  
 +    word = word.toLower();
      word = removeAccents(word);
  
      stopped = false;
                          ok=false;  /*if key word is in the dictionary more that one */
                  }
                  if(ok)  /*add key word to list*/
 -                    translations<<(new TranslationXdxf(a,_infoNote,this));
 +                    translations<<(new TranslationXdxf(a.toLower(),
 +                                _infoNote,this));
                  i++;
                  if(i>=limit && limit!=0)
                      break;
@@@ -171,7 -167,6 +171,7 @@@ QString XdxfPlugin::searchCache(QStrin
      QString result;
      QString cacheFilePath = _settings->value("cache_path");
      db.setDatabaseName(cacheFilePath);
 +    key = key.toLower();
  
      if(!db.open()) {
          qDebug() << "Database error" << db.lastError().text() << endl;
  
  
  QString XdxfPlugin::searchFile(QString key) {
 +    key = key.toLower();
      QFile dictionaryFile(path);
      QString resultString("");
      if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
          }
          else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
              if(match) {
-                 QString temp(dictionaryReader.text().toString());
+  /*             QString temp(dictionaryReader.text().toString());
+                 if(temp=="\n")
+                     temp=dictionaryReader.readElementText();
                  temp.replace("\n","");
                  if(temp == ""){
+                     int i=0;
                      while(dictionaryReader.name()!="ar"&&
                                  !dictionaryReader.atEnd()){
                          dictionaryReader.readNext();
+                         if(dictionaryReader.name()!="" &&
+                                          dictionaryReader.name()!="ar") {
+                             if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement)
+                                 temp+=tr("</");
+                             if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
+                                 temp+=tr("<");
+                             qDebug()<<dictionaryReader.tokenType();
+                             temp=temp+dictionaryReader.name().toString() + tr(">");
+                             i++;
+                         }
                          temp+=dictionaryReader.text().toString();
                      }
                  }
                  resultString+=temp.replace("\n","")+"\n";
                  match=false;
+ */
+                 QString temp("");
+                 while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()) {
+                     if(dictionaryReader.name()!="") {
+                         if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement)
+                             temp+=tr("</");
+                         if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
+                             temp+=tr("<");
+                         temp=temp+dictionaryReader.name().toString() + tr(">");
+                     }
+                     temp+= dictionaryReader.text().toString();
+                     dictionaryReader.readNext();
+                 }
+                 resultString+=tr("<t>") + temp.replace("\n","") + tr("</t>");
+                 match=false;
              }
          }
          this->thread()->yieldCurrentThread();
@@@ -344,6 -366,7 +372,6 @@@ void XdxfPlugin::getDictionaryInfo() 
  }
  
  QString XdxfPlugin::removeAccents(QString string) {
 -
      string = string.replace(QString::fromUtf8("ł"), "l", Qt::CaseInsensitive);
      QString normalized = string.normalized(QString::NormalizationForm_D);
      normalized = normalized;
@@@ -448,15 -471,19 +476,19 @@@ bool XdxfPlugin::makeCache(QString dir
          }
          else if(reader.tokenType() == QXmlStreamReader::Characters) {
               if(match) {
-                 QString temp(reader.text().toString());
-                 temp.replace("\n","");
-                 if(temp == ""){
-                     while(reader.name()!="ar"&&
-                                 !reader.atEnd()){
-                         reader.readNext();
-                         temp+=reader.text().toString();
+                 QString temp("");
+                 while(reader.name()!="ar" && !reader.atEnd()) {
+                     if(reader.name()!="") {
+                         if(reader.tokenType()==QXmlStreamReader::EndElement)
+                             temp+=tr("</");
+                         if(reader.tokenType()==QXmlStreamReader::StartElement)
+                             temp+=tr("<");
+                         temp=temp+reader.name().toString() + tr(">");
                      }
+                     temp+= reader.text().toString();
+                     reader.readNext();
                  }
+                 temp=tr("<t>") + temp.replace("\n","") + tr("</t>");
                  match = false;
                  cur.prepare("insert into dict values(?,?)");
                  cur.addBindValue(a);