72 QDir().mkpath(m_dbDir);
73 m_uniqueId = QHelpGlobal::uniquifyConnectionName(
"QHelpWriter"_L1,
this);
74 m_db = QSqlDatabase::addDatabase(
"QSQLITE"_L1, m_uniqueId);
75 const QString dbPath = m_dbDir + u'/' + QLatin1StringView(FTS_DB_NAME);
76 m_db.setDatabaseName(dbPath);
78 const QString &error = QHelpSearchIndexWriter::tr(
79 "Cannot open database \"%1\" using connection \"%2\": %3")
80 .arg(dbPath, m_uniqueId, m_db.lastError().text());
81 qWarning(
"%s", qUtf8Printable(error));
83 QSqlDatabase::removeDatabase(m_uniqueId);
327 QMutexLocker lock(&m_mutex);
332 const bool reindex(m_reindex);
333 const QString collectionFile(m_collectionFile);
334 const QString indexPath(m_indexFilesFolder);
339 if (!engine.setupData())
345 emit indexingStarted();
352 emit indexingFinished();
359 const QStringList ®isteredDocs = engine.registeredDocumentations();
360 QMap<QString, QDateTime> indexMap = readIndexMap(engine);
363 for (
const QString &namespaceName : registeredDocs) {
364 const auto it = indexMap.constFind(namespaceName);
365 if (it != indexMap.constEnd()) {
366 const QString path = engine.documentationFileName(namespaceName);
367 if (*it < QFileInfo(path).lastModified()) {
370 writer.removeNamespace(namespaceName);
371 }
else if (!writer.hasNamespace(namespaceName)) {
383 writer.removeNamespace(namespaceName);
392 auto it = indexMap.begin();
393 while (it != indexMap.end()) {
394 if (!registeredDocs.contains(it.key())) {
396 it = indexMap.erase(it);
402 for (
const QString &namespaceName : registeredDocs) {
406 writeIndexMap(&engine, indexMap);
407 writer.endTransaction();
408 emit indexingFinished();
414 if (indexMap.contains(namespaceName))
417 const QString fileName = engine.documentationFileName(namespaceName);
418 QHelpDBReader reader(fileName, QHelpGlobal::uniquifyConnectionName(
419 fileName,
this),
nullptr);
423 const QString virtualFolder = reader.virtualFolder();
425 const QList<QStringList> &attributeSets =
426 engine.filterAttributeSets(namespaceName);
428 for (
const QStringList &attributes : attributeSets) {
429 const QString &attributesString = attributes.join(u'|');
431 bool canceled =
false;
432 reader.filesData(attributes, {
"html"_L1,
"htm"_L1,
"txt"_L1},
433 [&](
const QString &file,
const QByteArray &data) {
445 url.setScheme(
"qthelp"_L1);
446 url.setAuthority(namespaceName);
447 url.setPath(u'/' + virtualFolder + u'/' + file);
449 if (url.hasFragment())
452 const QString &fullFileName = url.toString();
453 if (!fullFileName.endsWith(
".html"_L1) && !fullFileName.endsWith(
".htm"_L1)
454 && !fullFileName.endsWith(
".txt"_L1)) {
459 auto encoding = QStringDecoder::encodingForHtml(data);
461 s.setEncoding(*encoding);
463 const QString &text = s.readAll();
469 if (fullFileName.endsWith(
".txt"_L1)) {
470 title = fullFileName.mid(fullFileName.lastIndexOf(u'/') + 1);
471 contents = text.toHtmlEscaped();
473#if QT_CONFIG(fullqthelp) && QT_CONFIG(texthtmlparser)
477 title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped();
478 contents = doc.toPlainText().toHtmlEscaped();
484 writer.insertDoc(namespaceName, attributesString, fullFileName, title, contents);
490 writeIndexMap(&engine, indexMap);
491 writer.endTransaction();
492 emit indexingFinished();
497 const QString &path = engine.documentationFileName(namespaceName);
498 indexMap.insert(namespaceName, QFileInfo(path).lastModified());
504 emit indexingFinished();
void updateIndex(const QString &collectionFile, const QString &indexFilesFolder, bool reindex)
Writer(const QString &path)
bool tryInit(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)