tools/assistant/lib/qhelpsearchindexwriter_default.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
   102     QFile docFile(documentFile);
   102     QFile docFile(documentFile);
   103     if (!(status = docFile.open(QFile::WriteOnly)))
   103     if (!(status = docFile.open(QFile::WriteOnly)))
   104         return status;
   104         return status;
   105 
   105 
   106     QDataStream docStream(&docFile);
   106     QDataStream docStream(&docFile);
   107     foreach(const QStringList list, documentList) {
   107     foreach(const QStringList &list, documentList) {
   108         docStream << list.at(0);
   108         docStream << list.at(0);
   109         docStream << list.at(1);
   109         docStream << list.at(1);
   110     }
   110     }
   111     docFile.close();
   111     docFile.close();
   112 
   112 
   124         docFile.remove();
   124         docFile.remove();
   125 }
   125 }
   126 
   126 
   127 void Writer::setIndexFile(const QString &namespaceName, const QString &attributes)
   127 void Writer::setIndexFile(const QString &namespaceName, const QString &attributes)
   128 {
   128 {
   129     QString extention = namespaceName + QLatin1String("@") + attributes;
   129     QString extension = namespaceName + QLatin1String("@") + attributes;
   130     indexFile = indexPath + QLatin1String("/indexdb40.") + extention;
   130     indexFile = indexPath + QLatin1String("/indexdb40.") + extension;
   131     documentFile = indexPath + QLatin1String("/indexdoc40.") + extention;
   131     documentFile = indexPath + QLatin1String("/indexdoc40.") + extension;
   132 }
   132 }
   133 
   133 
   134 void Writer::insertInIndex(const QString &string, int docNum)
   134 void Writer::insertInIndex(const QString &string, int docNum)
   135 {
   135 {
   136     if (string == QLatin1String("amp") || string == QLatin1String("nbsp"))
   136     if (string == QLatin1String("amp") || string == QLatin1String("nbsp"))
   224 
   224 
   225     emit indexingStarted();
   225     emit indexingStarted();
   226 
   226 
   227     QStringList namespaces;
   227     QStringList namespaces;
   228     Writer writer(indexPath);
   228     Writer writer(indexPath);
   229     foreach(const QString namespaceName, registeredDocs) {
   229     foreach(const QString &namespaceName, registeredDocs) {
   230         mutex.lock();
   230         mutex.lock();
   231         if (m_cancel) {
   231         if (m_cancel) {
   232             mutex.unlock();
   232             mutex.unlock();
   233             return;
   233             return;
   234         }
   234         }
   240             continue;
   240             continue;
   241 
   241 
   242         const QList<QStringList> attributeSets =
   242         const QList<QStringList> attributeSets =
   243             engine.filterAttributeSets(namespaceName);
   243             engine.filterAttributeSets(namespaceName);
   244 
   244 
   245         foreach (QStringList attributes, attributeSets) {
   245         foreach (const QStringList &attributes, attributeSets) {
   246             // cleanup maybe old or unfinished files
   246             // cleanup maybe old or unfinished files
   247             writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@")));
   247             writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@")));
   248             writer.removeIndex();
   248             writer.removeIndex();
   249 
   249 
   250             QSet<QString> documentsSet;
   250             QSet<QString> documentsSet;
   264                     documentsSet.insert(s);
   264                     documentsSet.insert(s);
   265             }
   265             }
   266 
   266 
   267             int docNum = 0;
   267             int docNum = 0;
   268             const QStringList documentsList(documentsSet.toList());
   268             const QStringList documentsList(documentsSet.toList());
   269             foreach(const QString url, documentsList) {
   269             foreach(const QString &url, documentsList) {
   270                 if (m_cancel)
   270                 if (m_cancel)
   271                     return;
   271                     return;
   272 
   272 
   273                 QByteArray data(engine.fileData(url));
   273                 QByteArray data(engine.fileData(url));
   274                 if (data.isEmpty())
   274                 if (data.isEmpty())
   345             continue;
   345             continue;
   346 
   346 
   347         const QList<QStringList> attributeSets =
   347         const QList<QStringList> attributeSets =
   348             engine.filterAttributeSets(namespaceName);
   348             engine.filterAttributeSets(namespaceName);
   349 
   349 
   350         foreach (QStringList attributes, attributeSets) {
   350         foreach (const QStringList &attributes, attributeSets) {
   351             writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@")));
   351             writer.setIndexFile(namespaceName, attributes.join(QLatin1String("@")));
   352             writer.removeIndex();
   352             writer.removeIndex();
   353         }
   353         }
   354 
   354 
   355         engine.setCustomValue(key, removeNamespace(
   355         engine.setCustomValue(key, removeNamespace(