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
qwinregistry_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:trivial-impl-only
4
5#ifndef QWINREGISTRY_H
6#define QWINREGISTRY_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qstring.h>
20#include <QtCore/qstringview.h>
21#include <QtCore/qt_windows.h>
22#include <QtCore/qvariant.h>
23#include <QtCore/qobject.h>
24#include <QtCore/private/quniquehandle_types_p.h>
25
27
29{
30public:
31 QWinRegistryKey() = default;
32 explicit QWinRegistryKey(HKEY parentHandle, const wchar_t *subKey,
33 REGSAM permissions = KEY_READ, REGSAM access = 0);
34 explicit QWinRegistryKey(HKEY parentHandle, const QString &subKey,
35 REGSAM permissions = KEY_READ, REGSAM access = 0);
36 ~QWinRegistryKey();
37
38 QWinRegistryKey(QWinRegistryKey &&other) noexcept
39 : m_key(std::exchange(other.m_key, nullptr)) {}
40 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QWinRegistryKey)
41 void swap(QWinRegistryKey &other) noexcept
42 {
43 qt_ptr_swap(m_key, other.m_key);
44 }
45
46 [[nodiscard]] bool isValid() const { return m_key != nullptr; }
47
48 [[nodiscard]] HKEY handle() const { return m_key; }
49
50 operator HKEY() const { return handle(); }
51
52 void close();
53
54 QString name() const;
55
56 [[nodiscard]] QVariant value(const wchar_t *subKey) const;
57 [[nodiscard]] QVariant value(const QString &subKey) const;
58
59 template<typename T>
60 [[nodiscard]] std::optional<T> value(const wchar_t *subKey) const
61 {
62 return to_optional<T>(value(subKey));
63 }
64
65 template<typename T>
66 [[nodiscard]] std::optional<T> value(const QString &subKey) const
67 {
68 return to_optional<T>(value(subKey));
69 }
70
71 QString stringValue(const wchar_t *subKey) const;
72 QString stringValue(const QString &subKey) const;
73
74#ifndef QT_NO_DEBUG_STREAM
75 friend Q_CORE_EXPORT QDebug operator<<(QDebug dbg, const QWinRegistryKey &);
76#endif
77
78private:
79 template<typename T>
80 static std::optional<T> to_optional(QVariant v)
81 {
82 if (v.isValid())
83 return qvariant_cast<T>(std::move(v));
84 return std::nullopt;
85 }
86
87 HKEY m_key = nullptr;
88};
89
91
92class Q_CORE_EXPORT QWinRegistryNotifier : public QObject
93{
94 Q_OBJECT
95 Q_DISABLE_COPY(QWinRegistryNotifier)
96
97public:
98 explicit QWinRegistryNotifier(QWinRegistryKey &&key, QObject *parent = nullptr);
99 explicit QWinRegistryNotifier(HKEY parentHandle, const wchar_t *subKey,
100 QObject *parent = nullptr);
101 explicit QWinRegistryNotifier(HKEY parentHandle, const QString &subKey,
102 QObject *parent = nullptr);
103
104 [[nodiscard]] bool isValid() const { return m_key.isValid(); }
105 [[nodiscard]] const QWinRegistryKey &key() const { return m_key; }
106
107Q_SIGNALS:
108 void valueChanged();
109
110private:
111 QWinRegistryKey m_key;
112 QUniqueWin32NullHandle m_keyChangedEvent;
113};
114
115QT_END_NAMESPACE
116
117#endif // QWINREGISTRY_H
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static const wchar_t * nullTerminate(const QString &s)