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> |
10 | #include "helpenginewrapper.h" |
11 | #include "qtdocinstaller.h" |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos) |
16 | : m_abort(false), m_docInfos(docInfos) |
17 | { |
18 | TRACE_OBJ |
19 | } |
20 | |
21 | QtDocInstaller::~QtDocInstaller() |
22 | { |
23 | TRACE_OBJ |
24 | if (!isRunning()) |
25 | return; |
26 | m_mutex.lock(); |
27 | m_abort = true; |
28 | m_mutex.unlock(); |
29 | wait(); |
30 | } |
31 | |
32 | void QtDocInstaller::installDocs() |
33 | { |
34 | TRACE_OBJ |
35 | start(LowPriority); |
36 | } |
37 | |
38 | void QtDocInstaller::run() |
39 | { |
40 | TRACE_OBJ |
41 | m_qchDir.setPath(QLibraryInfo::path(p: QLibraryInfo::DocumentationPath)); |
42 | m_qchFiles = m_qchDir.entryList(nameFilters: QStringList() << QLatin1String("*.qch")); |
43 | |
44 | bool changes = false; |
45 | for (const DocInfo &docInfo : std::as_const(t&: m_docInfos)) { |
46 | changes |= installDoc(docInfo); |
47 | m_mutex.lock(); |
48 | if (m_abort) { |
49 | m_mutex.unlock(); |
50 | return; |
51 | } |
52 | m_mutex.unlock(); |
53 | } |
54 | emit docsInstalled(newDocsInstalled: changes); |
55 | } |
56 | |
57 | bool QtDocInstaller::installDoc(const DocInfo &docInfo) |
58 | { |
59 | TRACE_OBJ |
60 | const QString &component = docInfo.first; |
61 | const QStringList &info = docInfo.second; |
62 | QDateTime dt; |
63 | if (!info.isEmpty() && !info.first().isEmpty()) |
64 | dt = QDateTime::fromString(string: info.first(), format: Qt::ISODate); |
65 | |
66 | QString qchFile; |
67 | if (info.size() == 2) |
68 | qchFile = info.last(); |
69 | |
70 | if (m_qchFiles.isEmpty()) { |
71 | emit qchFileNotFound(component); |
72 | return false; |
73 | } |
74 | for (const QString &f : std::as_const(t&: m_qchFiles)) { |
75 | if (f.startsWith(s: component)) { |
76 | QFileInfo fi(m_qchDir.absolutePath() + QDir::separator() + f); |
77 | if (dt.isValid() && fi.lastModified().toSecsSinceEpoch() == dt.toSecsSinceEpoch() |
78 | && qchFile == fi.absoluteFilePath()) |
79 | return false; |
80 | emit registerDocumentation(component, absFileName: fi.absoluteFilePath()); |
81 | return true; |
82 | } |
83 | } |
84 | |
85 | emit qchFileNotFound(component); |
86 | return false; |
87 | } |
88 | |
89 | QT_END_NAMESPACE |
90 |