1 | // Copyright (C) 2019 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qcompressedhelpinfo.h" |
5 | |
6 | #include "qhelpdbreader_p.h" |
7 | |
8 | #include <QtCore/qversionnumber.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | using namespace Qt::StringLiterals; |
13 | |
14 | class QCompressedHelpInfoPrivate : public QSharedData |
15 | { |
16 | public: |
17 | QCompressedHelpInfoPrivate() = default; |
18 | QCompressedHelpInfoPrivate(const QCompressedHelpInfoPrivate &other) |
19 | : QSharedData(other) |
20 | , m_namespaceName(other.m_namespaceName) |
21 | , m_component(other.m_component) |
22 | , m_version(other.m_version) |
23 | , m_isNull(other.m_isNull) |
24 | { } |
25 | |
26 | QString m_namespaceName; |
27 | QString m_component; |
28 | QVersionNumber m_version; |
29 | bool m_isNull = true; |
30 | }; |
31 | |
32 | /*! |
33 | \class QCompressedHelpInfo |
34 | \since 5.13 |
35 | \inmodule QtHelp |
36 | \brief The QCompressedHelpInfo class provides access to |
37 | the details about a compressed help file. |
38 | |
39 | The detailed information about the compressed |
40 | help file can be fetched by calling the fromCompressedHelpFile() |
41 | static method, providing the path to the compressed |
42 | help file. |
43 | |
44 | The class provides access to various information about a compressed help file. |
45 | The namespace associated with the given compressed help file is |
46 | namespaceName(), the associated component name is component() |
47 | and version() provides version information. |
48 | |
49 | \sa QHelpFilterEngine |
50 | */ |
51 | |
52 | /*! |
53 | Constructs empty information about a compressed help file. |
54 | */ |
55 | QCompressedHelpInfo::QCompressedHelpInfo() |
56 | : d(new QCompressedHelpInfoPrivate) |
57 | {} |
58 | |
59 | /*! |
60 | Constructs a copy of \a other. |
61 | */ |
62 | QCompressedHelpInfo::QCompressedHelpInfo(const QCompressedHelpInfo &) = default; |
63 | |
64 | /*! |
65 | Move-constructs a QCompressedHelpInfo instance, |
66 | making it point to the same object that \a other was pointing to, |
67 | so that it contains the information the \a other used to contain. |
68 | */ |
69 | QCompressedHelpInfo::QCompressedHelpInfo(QCompressedHelpInfo &&) = default; |
70 | |
71 | /*! |
72 | Destroys the QCompressedHelpInfo. |
73 | */ |
74 | QCompressedHelpInfo::~QCompressedHelpInfo() = default; |
75 | |
76 | /*! |
77 | Makes this QHelpCollectionDetails into a copy of \a other, so the two |
78 | are identical, and returns a reference to this QHelpCollectionDetails. |
79 | */ |
80 | QCompressedHelpInfo &QCompressedHelpInfo::operator=(const QCompressedHelpInfo &) = default; |
81 | |
82 | /*! |
83 | Move-assigns \a other to this QCompressedHelpInfo instance. |
84 | */ |
85 | QCompressedHelpInfo &QCompressedHelpInfo::operator=(QCompressedHelpInfo &&) = default; |
86 | |
87 | /*! |
88 | \fn void QCompressedHelpInfo::swap(QCompressedHelpInfo &other) |
89 | |
90 | Swaps the compressed help file \a other with this compressed help file. This |
91 | operation is very fast and never fails. |
92 | */ |
93 | |
94 | /*! |
95 | Returns the namespace name of the compressed help file. |
96 | */ |
97 | QString QCompressedHelpInfo::namespaceName() const |
98 | { |
99 | return d->m_namespaceName; |
100 | } |
101 | |
102 | /*! |
103 | Returns the component of the compressed help file. |
104 | */ |
105 | QString QCompressedHelpInfo::component() const |
106 | { |
107 | return d->m_component; |
108 | } |
109 | |
110 | /*! |
111 | Returns the version of the compressed help file. |
112 | */ |
113 | QVersionNumber QCompressedHelpInfo::version() const |
114 | { |
115 | return d->m_version; |
116 | } |
117 | |
118 | /*! |
119 | Returns \c true if the info is invalid, otherwise returns |
120 | \c false. |
121 | */ |
122 | bool QCompressedHelpInfo::isNull() const |
123 | { |
124 | return d->m_isNull; |
125 | } |
126 | |
127 | /*! |
128 | Returns the QCompressedHelpInfo instance for the |
129 | \a documentationFileName of the existing qch file. |
130 | */ |
131 | QCompressedHelpInfo QCompressedHelpInfo::fromCompressedHelpFile(const QString &documentationFileName) |
132 | { |
133 | void *pointer = const_cast<QString *>(&documentationFileName); |
134 | QHelpDBReader reader(documentationFileName, QHelpGlobal::uniquifyConnectionName( |
135 | name: "GetCompressedHelpInfo"_L1 , pointer), nullptr); |
136 | if (reader.init()) { |
137 | QCompressedHelpInfo info; |
138 | info.d->m_namespaceName = reader.namespaceName(); |
139 | info.d->m_component = reader.virtualFolder(); |
140 | info.d->m_version = QVersionNumber::fromString(string: reader.version()); |
141 | info.d->m_isNull = false; |
142 | return info; |
143 | } |
144 | return {}; |
145 | } |
146 | |
147 | QT_END_NAMESPACE |
148 | |