Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtdocinstaller.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3#include "tracer.h"
4
5#include <QtCore/QDir>
6#include <QtCore/QLibraryInfo>
7#include <QtCore/QDateTime>
8#include <QtCore/QFileSystemWatcher>
9#include <QtHelp/QHelpEngineCore>
11#include "qtdocinstaller.h"
12
14
15using namespace Qt::StringLiterals;
16
17QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos)
18 : m_abort(false), m_docInfos(docInfos)
19{
21}
22
24{
26 if (!isRunning())
27 return;
28 m_mutex.lock();
29 m_abort = true;
30 m_mutex.unlock();
31 wait();
32}
33
35{
37 start(LowPriority);
38}
39
41{
43 m_qchDir.setPath(QLibraryInfo::path(QLibraryInfo::DocumentationPath));
44 m_qchFiles = m_qchDir.entryList(QStringList() << "*.qch"_L1);
45
46 bool changes = false;
47 for (const DocInfo &docInfo : std::as_const(m_docInfos)) {
48 changes |= installDoc(docInfo);
49 m_mutex.lock();
50 if (m_abort) {
51 m_mutex.unlock();
52 return;
53 }
54 m_mutex.unlock();
55 }
56 emit docsInstalled(changes);
57}
58
59bool QtDocInstaller::installDoc(const DocInfo &docInfo)
60{
62 const QString &component = docInfo.first;
63 const QStringList &info = docInfo.second;
64 QDateTime dt;
65 if (!info.isEmpty() && !info.first().isEmpty())
66 dt = QDateTime::fromString(info.first(), Qt::ISODate);
67
68 QString qchFile;
69 if (info.size() == 2)
70 qchFile = info.last();
71
72 if (m_qchFiles.isEmpty()) {
73 emit qchFileNotFound(component);
74 return false;
75 }
76 for (const QString &f : std::as_const(m_qchFiles)) {
77 if (f.startsWith(component)) {
78 QFileInfo fi(m_qchDir.absolutePath() + QDir::separator() + f);
79 if (dt.isValid() && fi.lastModified().toSecsSinceEpoch() == dt.toSecsSinceEpoch()
80 && qchFile == fi.absoluteFilePath())
81 return false;
82 emit registerDocumentation(component, fi.absoluteFilePath());
83 return true;
84 }
85 }
86
87 emit qchFileNotFound(component);
88 return false;
89}
90
91QT_END_NAMESPACE
QtDocInstaller(const QList< DocInfo > &docInfos)
void run() override
~QtDocInstaller() override
Combined button and popup list for selecting options.
#define TRACE_OBJ
Definition tracer.h:34