summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowsservices.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-09-27 13:36:38 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-10-14 20:26:42 +0200
commit05a829f923a88e69b2ceaa372820a2dcb8c083cd (patch)
treee782463b2643f38a4ce478044a63820674c4a6e3 /src/plugins/platforms/windows/qwindowsservices.cpp
parent95ac2072bbbcb50ff1f8b2fd9ffbcfb4e1326b27 (diff)
Win32: Consolidate registry code
Add a RAII class for registry keys and use it throughout the code base. Change-Id: I666b2fbb790f83436443101d6bc1e3c0525e78df Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsservices.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowsservices.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp
index b2b1dee232..83b052bb49 100644
--- a/src/plugins/platforms/windows/qwindowsservices.cpp
+++ b/src/plugins/platforms/windows/qwindowsservices.cpp
@@ -45,6 +45,8 @@
#include <QtCore/qdebug.h>
#include <QtCore/qdir.h>
+#include <QtCore/private/qwinregistry_p.h>
+
#include <shlobj.h>
#include <intshcut.h>
@@ -78,35 +80,24 @@ static inline QString mailCommand()
const wchar_t mailUserKey[] = L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice";
- wchar_t command[MAX_PATH] = {0};
// Check if user has set preference, otherwise use default.
- HKEY handle;
- QString keyName;
- if (!RegOpenKeyEx(HKEY_CURRENT_USER, mailUserKey, 0, KEY_READ, &handle)) {
- DWORD bufferSize = BufferSize;
- if (!RegQueryValueEx(handle, L"Progid", nullptr, nullptr, reinterpret_cast<unsigned char*>(command), &bufferSize))
- keyName = QString::fromWCharArray(command);
- RegCloseKey(handle);
- }
+ QString keyName = QWinRegistryKey(HKEY_CURRENT_USER, mailUserKey)
+ .stringValue( L"Progid");
const QLatin1String mailto = keyName.isEmpty() ? QLatin1String("mailto") : QLatin1String();
keyName += mailto + QLatin1String("\\Shell\\Open\\Command");
if (debug)
qDebug() << __FUNCTION__ << "keyName=" << keyName;
- command[0] = 0;
- if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, reinterpret_cast<const wchar_t*>(keyName.utf16()), 0, KEY_READ, &handle)) {
- DWORD bufferSize = BufferSize;
- RegQueryValueEx(handle, L"", nullptr, nullptr, reinterpret_cast<unsigned char*>(command), &bufferSize);
- RegCloseKey(handle);
- }
+ const QString command = QWinRegistryKey(HKEY_CLASSES_ROOT, keyName).stringValue(L"");
// QTBUG-57816: As of Windows 10, if there is no mail client installed, an entry like
// "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it
// silently fails or brings up a broken dialog after a long time, so exclude it and
// fall back to ShellExecute() which brings up the URL assocation dialog.
- if (!command[0] || wcsstr(command, L",MailToProtocolHandler") != nullptr)
+ if (command.isEmpty() || command.contains(QLatin1String(",MailToProtocolHandler")))
return QString();
wchar_t expandedCommand[MAX_PATH] = {0};
- return ExpandEnvironmentStrings(command, expandedCommand, MAX_PATH) ?
- QString::fromWCharArray(expandedCommand) : QString::fromWCharArray(command);
+ return ExpandEnvironmentStrings(reinterpret_cast<const wchar_t *>(command.utf16()),
+ expandedCommand, MAX_PATH)
+ ? QString::fromWCharArray(expandedCommand) : command;
}
static inline bool launchMail(const QUrl &url)