70 QDir().mkpath(m_dbDir);
71 m_uniqueId = QHelpGlobal::uniquifyConnectionName(
"QHelpWriter"_L1,
this);
72 m_db = QSqlDatabase::addDatabase(
"QSQLITE"_L1, m_uniqueId);
73 const QString dbPath = m_dbDir + u'/' + QLatin1StringView(FTS_DB_NAME);
74 m_db.setDatabaseName(dbPath);
76 const QString &error = QHelpSearchIndexWriter::tr(
77 "Cannot open database \"%1\" using connection \"%2\": %3")
78 .arg(dbPath, m_uniqueId, m_db.lastError().text());
79 qWarning(
"%s", qUtf8Printable(error));
81 QSqlDatabase::removeDatabase(m_uniqueId);
341 QMutexLocker lock(&m_mutex);
346 const bool reindex(m_reindex);
347 const QString collectionFile(m_collectionFile);
348 const QString indexPath(m_indexFilesFolder);
353 if (!engine.setupData())
357 clearIndexMap(&engine);
359 emit indexingStarted();
366 const QStringList ®isteredDocs = engine.registeredDocumentations();
367 QMap<QString, QDateTime> indexMap = readIndexMap(engine);
370 for (
const QString &namespaceName : registeredDocs) {
371 const auto it = indexMap.constFind(namespaceName);
372 if (it != indexMap.constEnd()) {
373 const QString path = engine.documentationFileName(namespaceName);
374 if (*it < QFileInfo(path).lastModified()) {
377 writer.removeNamespace(namespaceName);
378 }
else if (!writer.hasNamespace(namespaceName)) {
390 writer.removeNamespace(namespaceName);
399 auto it = indexMap.begin();
400 while (it != indexMap.end()) {
401 if (!registeredDocs.contains(it.key())) {
403 it = indexMap.erase(it);
409 for (
const QString &namespaceName : registeredDocs) {
413 writeIndexMap(&engine, indexMap);
414 writer.endTransaction();
415 emit indexingFinished();
421 if (indexMap.contains(namespaceName))
424 const QString fileName = engine.documentationFileName(namespaceName);
425 QHelpDBReader reader(fileName, QHelpGlobal::uniquifyConnectionName(
426 fileName,
this),
nullptr);
430 const QString virtualFolder = reader.virtualFolder();
432 const QList<QStringList> &attributeSets =
433 engine.filterAttributeSets(namespaceName);
435 for (
const QStringList &attributes : attributeSets) {
436 const QString &attributesString = attributes.join(u'|');
438 const auto htmlFiles = reader.filesData(attributes,
"html"_L1);
439 const auto htmFiles = reader.filesData(attributes,
"htm"_L1);
440 const auto txtFiles = reader.filesData(attributes,
"txt"_L1);
442 auto files = htmlFiles;
443 files.unite(htmFiles);
444 files.unite(txtFiles);
446 for (
auto it = files.cbegin(), end = files.cend(); it != end ; ++it) {
450 writeIndexMap(&engine, indexMap);
451 writer.endTransaction();
452 emit indexingFinished();
457 const QString &file = it.key();
458 const QByteArray &data = it.value();
464 url.setScheme(
"qthelp"_L1);
465 url.setAuthority(namespaceName);
466 url.setPath(u'/' + virtualFolder + u'/' + file);
468 if (url.hasFragment())
471 const QString &fullFileName = url.toString();
472 if (!fullFileName.endsWith(
".html"_L1) && !fullFileName.endsWith(
".htm"_L1)
473 && !fullFileName.endsWith(
".txt"_L1)) {
478 auto encoding = QStringDecoder::encodingForHtml(data);
480 s.setEncoding(*encoding);
482 const QString &text = s.readAll();
488 if (fullFileName.endsWith(
".txt"_L1)) {
489 title = fullFileName.mid(fullFileName.lastIndexOf(u'/') + 1);
490 contents = text.toHtmlEscaped();
495 title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped();
496 contents = doc.toPlainText().toHtmlEscaped();
499 writer.insertDoc(namespaceName, attributesString, fullFileName, title, contents);
503 const QString &path = engine.documentationFileName(namespaceName);
504 indexMap.insert(namespaceName, QFileInfo(path).lastModified());
507 writeIndexMap(&engine, indexMap);
510 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)