1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Assistant of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | #include "tracer.h" |
29 | |
30 | #include <QtCore/QDir> |
31 | #include <QtCore/QLibraryInfo> |
32 | #include <QtCore/QDateTime> |
33 | #include <QtCore/QFileSystemWatcher> |
34 | #include <QtHelp/QHelpEngineCore> |
35 | #include "helpenginewrapper.h" |
36 | #include "qtdocinstaller.h" |
37 | |
38 | QT_BEGIN_NAMESPACE |
39 | |
40 | QtDocInstaller::QtDocInstaller(const QList<DocInfo> &docInfos) |
41 | : m_abort(false), m_docInfos(docInfos) |
42 | { |
43 | TRACE_OBJ |
44 | } |
45 | |
46 | QtDocInstaller::~QtDocInstaller() |
47 | { |
48 | TRACE_OBJ |
49 | if (!isRunning()) |
50 | return; |
51 | m_mutex.lock(); |
52 | m_abort = true; |
53 | m_mutex.unlock(); |
54 | wait(); |
55 | } |
56 | |
57 | void QtDocInstaller::installDocs() |
58 | { |
59 | TRACE_OBJ |
60 | start(LowPriority); |
61 | } |
62 | |
63 | void QtDocInstaller::run() |
64 | { |
65 | TRACE_OBJ |
66 | m_qchDir.setPath(QLibraryInfo::location(QLibraryInfo::DocumentationPath)); |
67 | m_qchFiles = m_qchDir.entryList(nameFilters: QStringList() << QLatin1String("*.qch")); |
68 | |
69 | bool changes = false; |
70 | for (const DocInfo &docInfo : qAsConst(t&: m_docInfos)) { |
71 | changes |= installDoc(docInfo); |
72 | m_mutex.lock(); |
73 | if (m_abort) { |
74 | m_mutex.unlock(); |
75 | return; |
76 | } |
77 | m_mutex.unlock(); |
78 | } |
79 | emit docsInstalled(newDocsInstalled: changes); |
80 | } |
81 | |
82 | bool QtDocInstaller::installDoc(const DocInfo &docInfo) |
83 | { |
84 | TRACE_OBJ |
85 | const QString &component = docInfo.first; |
86 | const QStringList &info = docInfo.second; |
87 | QDateTime dt; |
88 | if (!info.isEmpty() && !info.first().isEmpty()) |
89 | dt = QDateTime::fromString(s: info.first(), f: Qt::ISODate); |
90 | |
91 | QString qchFile; |
92 | if (info.count() == 2) |
93 | qchFile = info.last(); |
94 | |
95 | if (m_qchFiles.isEmpty()) { |
96 | emit qchFileNotFound(component); |
97 | return false; |
98 | } |
99 | for (const QString &f : qAsConst(t&: m_qchFiles)) { |
100 | if (f.startsWith(s: component)) { |
101 | QFileInfo fi(m_qchDir.absolutePath() + QDir::separator() + f); |
102 | if (dt.isValid() && fi.lastModified().toSecsSinceEpoch() == dt.toSecsSinceEpoch() |
103 | && qchFile == fi.absoluteFilePath()) |
104 | return false; |
105 | emit registerDocumentation(component, absFileName: fi.absoluteFilePath()); |
106 | return true; |
107 | } |
108 | } |
109 | |
110 | emit qchFileNotFound(component); |
111 | return false; |
112 | } |
113 | |
114 | QT_END_NAMESPACE |
115 |