74 QDir().mkpath(m_dbDir);
75 m_uniqueId = QHelpGlobal::uniquifyConnectionName(
"QHelpWriter"_L1,
this);
76 m_db = QSqlDatabase::addDatabase(
"QSQLITE"_L1, m_uniqueId);
77 const QString dbPath = m_dbDir + u'/' + QLatin1StringView(FTS_DB_NAME);
78 m_db.setDatabaseName(dbPath);
80 const QString &error = QHelpSearchIndexWriter::tr(
81 "Cannot open database \"%1\" using connection \"%2\": %3")
82 .arg(dbPath, m_uniqueId, m_db.lastError().text());
83 qWarning(
"%s", qUtf8Printable(error));
85 QSqlDatabase::removeDatabase(m_uniqueId);
345 QMutexLocker lock(&m_mutex);
350 const bool reindex(m_reindex);
351 const QString collectionFile(m_collectionFile);
352 const QString indexPath(m_indexFilesFolder);
357 if (!engine.setupData())
363 emit indexingStarted();
370 const QStringList ®isteredDocs = engine.registeredDocumentations();
371 QMap<QString, QDateTime> indexMap = readIndexMap(engine);
374 for (
const QString &namespaceName : registeredDocs) {
375 const auto it = indexMap.constFind(namespaceName);
376 if (it != indexMap.constEnd()) {
377 const QString path = engine.documentationFileName(namespaceName);
378 if (*it < QFileInfo(path).lastModified()) {
381 writer.removeNamespace(namespaceName);
382 }
else if (!writer.hasNamespace(namespaceName)) {
394 writer.removeNamespace(namespaceName);
403 auto it = indexMap.begin();
404 while (it != indexMap.end()) {
405 if (!registeredDocs.contains(it.key())) {
407 it = indexMap.erase(it);
413 for (
const QString &namespaceName : registeredDocs) {
417 writeIndexMap(&engine, indexMap);
418 writer.endTransaction();
419 emit indexingFinished();
425 if (indexMap.contains(namespaceName))
428 const QString fileName = engine.documentationFileName(namespaceName);
429 QHelpDBReader reader(fileName, QHelpGlobal::uniquifyConnectionName(
430 fileName,
this),
nullptr);
434 const QString virtualFolder = reader.virtualFolder();
436 const QList<QStringList> &attributeSets =
437 engine.filterAttributeSets(namespaceName);
439 for (
const QStringList &attributes : attributeSets) {
440 const QString &attributesString = attributes.join(u'|');
442 const auto htmlFiles = reader.filesData(attributes,
"html"_L1);
443 const auto htmFiles = reader.filesData(attributes,
"htm"_L1);
444 const auto txtFiles = reader.filesData(attributes,
"txt"_L1);
446 auto files = htmlFiles;
447 files.unite(htmFiles);
448 files.unite(txtFiles);
450 for (
auto it = files.cbegin(), end = files.cend(); it != end ; ++it) {
454 writeIndexMap(&engine, indexMap);
455 writer.endTransaction();
456 emit indexingFinished();
461 const QString &file = it.key();
462 const QByteArray &data = it.value();
468 url.setScheme(
"qthelp"_L1);
469 url.setAuthority(namespaceName);
470 url.setPath(u'/' + virtualFolder + u'/' + file);
472 if (url.hasFragment())
475 const QString &fullFileName = url.toString();
476 if (!fullFileName.endsWith(
".html"_L1) && !fullFileName.endsWith(
".htm"_L1)
477 && !fullFileName.endsWith(
".txt"_L1)) {
482 auto encoding = QStringDecoder::encodingForHtml(data);
484 s.setEncoding(*encoding);
486 const QString &text = s.readAll();
492 if (fullFileName.endsWith(
".txt"_L1)) {
493 title = fullFileName.mid(fullFileName.lastIndexOf(u'/') + 1);
494 contents = text.toHtmlEscaped();
495#if QT_CONFIG(fullqthelp)
500 title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped();
501 contents = doc.toPlainText().toHtmlEscaped();
505 writer.insertDoc(namespaceName, attributesString, fullFileName, title, contents);
509 const QString &path = engine.documentationFileName(namespaceName);
510 indexMap.insert(namespaceName, QFileInfo(path).lastModified());
516 emit indexingFinished();
void updateIndex(const QString &collectionFile, const QString &indexFilesFolder, bool reindex)
void removeNamespace(const QString &namespaceName)
void insertDoc(const QString &namespaceName, const QString &attributes, const QString &url, const QString &title, const QString &contents)
bool hasNamespace(const QString &namespaceName)
static bool writeIndexMap(QHelpEngineCore *engine, const QMap< QString, QDateTime > &indexMap)
static const char IndexedNamespacesKey[]
static bool clearIndexMap(QHelpEngineCore *engine)
static QMap< QString, QDateTime > readIndexMap(const QHelpEngineCore &engine)