73 QDir().mkpath(m_dbDir);
74 m_uniqueId = QHelpGlobal::uniquifyConnectionName(
"QHelpWriter"_L1,
this);
75 m_db = QSqlDatabase::addDatabase(
"QSQLITE"_L1, m_uniqueId);
76 const QString dbPath = m_dbDir + u'/' + QLatin1StringView(FTS_DB_NAME);
77 m_db.setDatabaseName(dbPath);
79 const QString &error = QHelpSearchIndexWriter::tr(
80 "Cannot open database \"%1\" using connection \"%2\": %3")
81 .arg(dbPath, m_uniqueId, m_db.lastError().text());
82 qWarning(
"%s", qUtf8Printable(error));
84 QSqlDatabase::removeDatabase(m_uniqueId);
344 QMutexLocker lock(&m_mutex);
349 const bool reindex(m_reindex);
350 const QString collectionFile(m_collectionFile);
351 const QString indexPath(m_indexFilesFolder);
356 if (!engine.setupData())
360 clearIndexMap(&engine);
362 emit indexingStarted();
369 const QStringList ®isteredDocs = engine.registeredDocumentations();
370 QMap<QString, QDateTime> indexMap = readIndexMap(engine);
373 for (
const QString &namespaceName : registeredDocs) {
374 const auto it = indexMap.constFind(namespaceName);
375 if (it != indexMap.constEnd()) {
376 const QString path = engine.documentationFileName(namespaceName);
377 if (*it < QFileInfo(path).lastModified()) {
380 writer.removeNamespace(namespaceName);
381 }
else if (!writer.hasNamespace(namespaceName)) {
393 writer.removeNamespace(namespaceName);
402 auto it = indexMap.begin();
403 while (it != indexMap.end()) {
404 if (!registeredDocs.contains(it.key())) {
406 it = indexMap.erase(it);
412 for (
const QString &namespaceName : registeredDocs) {
416 writeIndexMap(&engine, indexMap);
417 writer.endTransaction();
418 emit indexingFinished();
424 if (indexMap.contains(namespaceName))
427 const QString fileName = engine.documentationFileName(namespaceName);
428 QHelpDBReader reader(fileName, QHelpGlobal::uniquifyConnectionName(
429 fileName,
this),
nullptr);
433 const QString virtualFolder = reader.virtualFolder();
435 const QList<QStringList> &attributeSets =
436 engine.filterAttributeSets(namespaceName);
438 for (
const QStringList &attributes : attributeSets) {
439 const QString &attributesString = attributes.join(u'|');
441 const auto htmlFiles = reader.filesData(attributes,
"html"_L1);
442 const auto htmFiles = reader.filesData(attributes,
"htm"_L1);
443 const auto txtFiles = reader.filesData(attributes,
"txt"_L1);
445 auto files = htmlFiles;
446 files.unite(htmFiles);
447 files.unite(txtFiles);
449 for (
auto it = files.cbegin(), end = files.cend(); it != end ; ++it) {
453 writeIndexMap(&engine, indexMap);
454 writer.endTransaction();
455 emit indexingFinished();
460 const QString &file = it.key();
461 const QByteArray &data = it.value();
467 url.setScheme(
"qthelp"_L1);
468 url.setAuthority(namespaceName);
469 url.setPath(u'/' + virtualFolder + u'/' + file);
471 if (url.hasFragment())
474 const QString &fullFileName = url.toString();
475 if (!fullFileName.endsWith(
".html"_L1) && !fullFileName.endsWith(
".htm"_L1)
476 && !fullFileName.endsWith(
".txt"_L1)) {
481 auto encoding = QStringDecoder::encodingForHtml(data);
483 s.setEncoding(*encoding);
485 const QString &text = s.readAll();
491 if (fullFileName.endsWith(
".txt"_L1)) {
492 title = fullFileName.mid(fullFileName.lastIndexOf(u'/') + 1);
493 contents = text.toHtmlEscaped();
494#if QT_CONFIG(fullqthelp)
499 title = doc.metaInformation(QTextDocument::DocumentTitle).toHtmlEscaped();
500 contents = doc.toPlainText().toHtmlEscaped();
504 writer.insertDoc(namespaceName, attributesString, fullFileName, title, contents);
508 const QString &path = engine.documentationFileName(namespaceName);
509 indexMap.insert(namespaceName, QFileInfo(path).lastModified());
512 writeIndexMap(&engine, indexMap);
515 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)