forked from github_mirror/framelesshelper
registrykey: rename
RegistryKey is a better name than Registry. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
0535276f55
commit
a49756ee45
|
@ -34,14 +34,14 @@ QT_END_NAMESPACE
|
|||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
class FRAMELESSHELPER_CORE_API Registry : public QObject
|
||||
class FRAMELESSHELPER_CORE_API RegistryKey : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY_MOVE(Registry)
|
||||
Q_DISABLE_COPY_MOVE(RegistryKey)
|
||||
|
||||
public:
|
||||
explicit Registry(const Global::RegistryRootKey root, const QString &key, QObject *parent = nullptr);
|
||||
~Registry() override;
|
||||
explicit RegistryKey(const Global::RegistryRootKey root, const QString &key, QObject *parent = nullptr);
|
||||
~RegistryKey() override;
|
||||
|
||||
Q_NODISCARD Global::RegistryRootKey rootKey() const;
|
||||
Q_NODISCARD QString subKey() const;
|
||||
|
@ -54,13 +54,12 @@ private:
|
|||
Global::RegistryRootKey m_rootKey = Global::RegistryRootKey::CurrentUser;
|
||||
QString m_subKey = {};
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QScopedPointer<QWinRegistryKey> m_registry;
|
||||
QScopedPointer<QWinRegistryKey> m_registryKey;
|
||||
#else
|
||||
QScopedPointer<QSettings> m_settings;
|
||||
bool m_valid = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
FRAMELESSHELPER_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(Registry))
|
||||
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(RegistryKey))
|
|
@ -86,10 +86,10 @@ if(WIN32)
|
|||
${INCLUDE_PREFIX}/FramelessHelper_Win
|
||||
)
|
||||
list(APPEND PRIVATE_HEADERS
|
||||
${INCLUDE_PREFIX}/private/registry_p.h
|
||||
${INCLUDE_PREFIX}/private/registrykey_p.h
|
||||
)
|
||||
list(APPEND SOURCES
|
||||
registry.cpp
|
||||
registrykey.cpp
|
||||
utils_win.cpp
|
||||
framelesshelper_win.cpp
|
||||
)
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "chromepalette_p.h"
|
||||
#include "micamaterial_p.h"
|
||||
#ifdef Q_OS_WINDOWS
|
||||
# include "registry_p.h"
|
||||
# include "registrykey_p.h"
|
||||
#endif
|
||||
#include <QtGui/qguiapplication.h>
|
||||
|
||||
|
@ -176,7 +176,7 @@ void initialize()
|
|||
qRegisterMetaType<MicaMaterial>();
|
||||
qRegisterMetaType<MicaMaterialPrivate>();
|
||||
# ifdef Q_OS_WINDOWS
|
||||
qRegisterMetaType<Registry>();
|
||||
qRegisterMetaType<RegistryKey>();
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../../include/FramelessHelper/Core/private/registry_p.h"
|
|
@ -22,7 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "registry_p.h"
|
||||
#include "registrykey_p.h"
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
|
@ -33,11 +33,11 @@
|
|||
|
||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||
|
||||
Q_LOGGING_CATEGORY(lcCoreRegistry, "wangwenx190.framelesshelper.core.registry")
|
||||
#define INFO qCInfo(lcCoreRegistry)
|
||||
#define DEBUG qCDebug(lcCoreRegistry)
|
||||
#define WARNING qCWarning(lcCoreRegistry)
|
||||
#define CRITICAL qCCritical(lcCoreRegistry)
|
||||
Q_LOGGING_CATEGORY(lcCoreRegistryKey, "wangwenx190.framelesshelper.core.registrykey")
|
||||
#define INFO qCInfo(lcCoreRegistryKey)
|
||||
#define DEBUG qCDebug(lcCoreRegistryKey)
|
||||
#define WARNING qCWarning(lcCoreRegistryKey)
|
||||
#define CRITICAL qCCritical(lcCoreRegistryKey)
|
||||
|
||||
using namespace Global;
|
||||
|
||||
|
@ -69,7 +69,7 @@ static const QString g_strMap[] = {
|
|||
};
|
||||
static_assert(std::size(g_strMap) == std::size(g_keyMap));
|
||||
|
||||
Registry::Registry(const RegistryRootKey root, const QString &key, QObject *parent) : QObject(parent)
|
||||
RegistryKey::RegistryKey(const RegistryRootKey root, const QString &key, QObject *parent) : QObject(parent)
|
||||
{
|
||||
Q_ASSERT(!key.isEmpty());
|
||||
if (key.isEmpty()) {
|
||||
|
@ -78,39 +78,43 @@ Registry::Registry(const RegistryRootKey root, const QString &key, QObject *pare
|
|||
m_rootKey = root;
|
||||
m_subKey = key;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
m_registry.reset(new QWinRegistryKey(g_keyMap[static_cast<int>(m_rootKey)], m_subKey));
|
||||
m_registryKey.reset(new QWinRegistryKey(g_keyMap[static_cast<int>(m_rootKey)], m_subKey));
|
||||
if (!m_registryKey->isValid()) {
|
||||
m_registryKey.reset();
|
||||
}
|
||||
#else
|
||||
const QString rootKey = g_strMap[static_cast<int>(m_rootKey)];
|
||||
m_settings.reset(new QSettings(rootKey, QSettings::NativeFormat));
|
||||
if (m_settings->contains(m_subKey)) {
|
||||
m_settings.reset(new QSettings(rootKey + u'\\' + m_subKey, QSettings::NativeFormat));
|
||||
m_valid = true;
|
||||
} else {
|
||||
m_settings.reset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Registry::~Registry() = default;
|
||||
RegistryKey::~RegistryKey() = default;
|
||||
|
||||
RegistryRootKey Registry::rootKey() const
|
||||
RegistryRootKey RegistryKey::rootKey() const
|
||||
{
|
||||
return m_rootKey;
|
||||
}
|
||||
|
||||
QString Registry::subKey() const
|
||||
QString RegistryKey::subKey() const
|
||||
{
|
||||
return m_subKey;
|
||||
}
|
||||
|
||||
bool Registry::isValid() const
|
||||
bool RegistryKey::isValid() const
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
return m_registry->isValid();
|
||||
return (!m_registryKey.isNull() && m_registryKey->isValid());
|
||||
#else
|
||||
return m_valid;
|
||||
return !m_settings.isNull();
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariant Registry::value(const QString &name) const
|
||||
QVariant RegistryKey::value(const QString &name) const
|
||||
{
|
||||
Q_ASSERT(!name.isEmpty());
|
||||
Q_ASSERT(isValid());
|
||||
|
@ -118,11 +122,15 @@ QVariant Registry::value(const QString &name) const
|
|||
return {};
|
||||
}
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
const QPair<DWORD, bool> dwValue = m_registry->dwordValue(name);
|
||||
if (dwValue.second) {
|
||||
return qulonglong(dwValue.first);
|
||||
const QPair<DWORD, bool> dwVal = m_registryKey->dwordValue(name);
|
||||
if (dwVal.second) {
|
||||
return qulonglong(dwVal.first);
|
||||
}
|
||||
return m_registry->stringValue(name);
|
||||
const QString strVal = m_registryKey->stringValue(name);
|
||||
if (!strVal.isEmpty()) {
|
||||
return strVal;
|
||||
}
|
||||
return {};
|
||||
#else
|
||||
return m_settings->value(name);
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
#include "../../include/FramelessHelper/Core/private/registrykey_p.h"
|
|
@ -41,7 +41,7 @@
|
|||
#include "framelesshelper_windows.h"
|
||||
#include "framelessconfig_p.h"
|
||||
#include "sysapiloader_p.h"
|
||||
#include "registry_p.h"
|
||||
#include "registrykey_p.h"
|
||||
#include <uxtheme.h>
|
||||
#include <d2d1.h>
|
||||
|
||||
|
@ -375,7 +375,7 @@ private:
|
|||
if (code == ERROR_SUCCESS) {
|
||||
return kSuccessMessageText;
|
||||
}
|
||||
#if 0
|
||||
#if 0 // The following code works well, we commented it out just because we want to use as many Qt functionalities as possible.
|
||||
LPWSTR buf = nullptr;
|
||||
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&buf), 0, nullptr) == 0) {
|
||||
|
@ -607,7 +607,7 @@ bool Utils::isDwmCompositionEnabled()
|
|||
return true;
|
||||
}
|
||||
const auto resultFromRegistry = []() -> bool {
|
||||
const Registry registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
const RegistryKey registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
if (!registry.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ QString Utils::getSystemErrorMessage(const QString &function)
|
|||
QColor Utils::getDwmColorizationColor()
|
||||
{
|
||||
const auto resultFromRegistry = []() -> QColor {
|
||||
const Registry registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
const RegistryKey registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
if (!registry.isValid()) {
|
||||
return kDefaultDarkGrayColor;
|
||||
}
|
||||
|
@ -761,10 +761,10 @@ DwmColorizationArea Utils::getDwmColorizationArea()
|
|||
if (!isWin10OrGreater) {
|
||||
return DwmColorizationArea::None_;
|
||||
}
|
||||
const Registry themeRegistry(RegistryRootKey::CurrentUser, personalizeRegistryKey());
|
||||
const RegistryKey themeRegistry(RegistryRootKey::CurrentUser, personalizeRegistryKey());
|
||||
bool themeOk = false;
|
||||
const DWORD themeValue = themeRegistry.isValid() ? themeRegistry.value(qDwmColorKeyName).toULongLong(&themeOk) : 0;
|
||||
const Registry dwmRegistry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
const RegistryKey dwmRegistry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
bool dwmOk = false;
|
||||
const DWORD dwmValue = dwmRegistry.isValid() ? dwmRegistry.value(qDwmColorKeyName).toULongLong(&dwmOk) : 0;
|
||||
const bool theme = (themeOk && (themeValue != 0));
|
||||
|
@ -1573,9 +1573,12 @@ bool Utils::shouldAppsUseDarkMode_windows()
|
|||
} else {
|
||||
WARNING << "Failed to retrieve the platform native interface.";
|
||||
}
|
||||
#else
|
||||
// Qt gained the ability to detect the system dark mode setting only since 5.15.
|
||||
// We should detect it ourself on versions below that.
|
||||
#endif
|
||||
const auto resultFromRegistry = []() -> bool {
|
||||
const Registry registry(RegistryRootKey::CurrentUser, personalizeRegistryKey());
|
||||
const RegistryKey registry(RegistryRootKey::CurrentUser, personalizeRegistryKey());
|
||||
if (!registry.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1809,7 +1812,7 @@ QColor Utils::getDwmAccentColor()
|
|||
// so we'd better also do the same thing.
|
||||
// There's no Windows API to get this value, so we can only read it
|
||||
// directly from the registry.
|
||||
const Registry registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
const RegistryKey registry(RegistryRootKey::CurrentUser, dwmRegistryKey());
|
||||
if (!registry.isValid()) {
|
||||
return kDefaultDarkGrayColor;
|
||||
}
|
||||
|
@ -1837,7 +1840,7 @@ QString Utils::getWallpaperFilePath()
|
|||
WallpaperAspectStyle Utils::getWallpaperAspectStyle()
|
||||
{
|
||||
static constexpr const auto defaultStyle = WallpaperAspectStyle::Fill;
|
||||
const Registry registry(RegistryRootKey::CurrentUser, desktopRegistryKey());
|
||||
const RegistryKey registry(RegistryRootKey::CurrentUser, desktopRegistryKey());
|
||||
if (!registry.isValid()) {
|
||||
return defaultStyle;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue