diff options
author | Sergey Zolotarev <sryze@protonmail.com> | 2020-10-24 12:04:20 +0300 |
---|---|---|
committer | Sergey Zolotarev <sryze@protonmail.com> | 2020-10-24 12:53:52 +0300 |
commit | cc0e4140cbfee6180a3be2ce81cdda9c70452660 (patch) | |
tree | 39f7f9787b26c3e0cd881057db15b11ff0d3b8a4 | |
parent | 38205cab684325ef228c38bc08680a6b02bb5682 (diff) |
Misc fixes for Windows 7windows7-fixes
Signed-off-by: Sergey Zolotarev <sryze@protonmail.com>
-rw-r--r-- | src/common/utility.h | 1 | ||||
-rw-r--r-- | src/common/utility_win.cpp | 11 | ||||
-rw-r--r-- | src/gui/navigationpanehelper.cpp | 23 | ||||
-rw-r--r-- | src/gui/systray.cpp | 11 |
4 files changed, 31 insertions, 15 deletions
diff --git a/src/common/utility.h b/src/common/utility.h index 1058cf719..3913fd257 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -227,6 +227,7 @@ namespace Utility { OCSYNC_EXPORT QByteArray conflictFileBaseNameFromPattern(const QByteArray &conflictName); #ifdef Q_OS_WIN + OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey); OCSYNC_EXPORT QVariant registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName); OCSYNC_EXPORT bool registrySetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName, DWORD type, const QVariant &value); OCSYNC_EXPORT bool registryDeleteKeyTree(HKEY hRootKey, const QString &subKey); diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 13badf599..bfe9d7852 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -114,6 +114,17 @@ QRect Utility::getTaskbarDimensions() return QRect(barRect.left, barRect.top, (barRect.right - barRect.left), (barRect.bottom - barRect.top)); } +bool Utility::registryKeyExists(HKEY hRootKey, const QString &subKey) +{ + HKEY hKey; + + REGSAM sam = KEY_READ | KEY_WOW64_64KEY; + LONG result = RegOpenKeyEx(hRootKey, reinterpret_cast<LPCWSTR>(subKey.utf16()), 0, sam, &hKey); + + RegCloseKey(hKey); + return result != ERROR_FILE_NOT_FOUND; +} + QVariant Utility::registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName) { QVariant value; diff --git a/src/gui/navigationpanehelper.cpp b/src/gui/navigationpanehelper.cpp index a95830eee..ce2bad09c 100644 --- a/src/gui/navigationpanehelper.cpp +++ b/src/gui/navigationpanehelper.cpp @@ -66,17 +66,18 @@ void NavigationPaneHelper::updateCloudStorageRegistry() // that matches ours when we saved. QVector<QUuid> entriesToRemove; #ifdef Q_OS_WIN - Utility::registryWalkSubKeys( - HKEY_CURRENT_USER, - QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)"), - [&entriesToRemove](HKEY key, const QString &subKey) { - QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName")); - if (appName.toString() == QLatin1String(APPLICATION_NAME)) { - QUuid clsid{ subKey }; - Q_ASSERT(!clsid.isNull()); - entriesToRemove.append(clsid); - } - }); + QString nameSpaceKey = QStringLiteral(R"(Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace)"); + if (Utility::registryKeyExists(HKEY_CURRENT_USER, nameSpaceKey)) { + Utility::registryWalkSubKeys(HKEY_CURRENT_USER, nameSpaceKey, + [&entriesToRemove](HKEY key, const QString &subKey) { + QVariant appName = Utility::registryGetKeyValue(key, subKey, QStringLiteral("ApplicationName")); + if (appName.toString() == QLatin1String(APPLICATION_NAME)) { + QUuid clsid{ subKey }; + Q_ASSERT(!clsid.isNull()); + entriesToRemove.append(clsid); + } + }); + } #endif // Only save folder entries if the option is enabled. diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index 3309f54b3..d539c7061 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -241,6 +241,12 @@ Systray::TaskBarPosition Systray::taskbarOrientation() const auto taskbarPosition = Utility::registryGetKeyValue(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects3", "Settings"); + if (taskbarPosition.isNull()) { + // Windows 7 + taskbarPosition = Utility::registryGetKeyValue(HKEY_CURRENT_USER, + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects2", + "Settings"); + } switch (taskbarPosition.toInt()) { // Mapping windows binary value (0 = left, 1 = top, 2 = right, 3 = bottom) to qml logic (0 = bottom, 1 = left...) case 0: @@ -374,26 +380,23 @@ QPoint Systray::computeWindowPosition(int width, int height) const const auto windowRect = [=]() { const auto rect = QRect(topLeft, bottomRight); auto offset = QPoint(); - if (rect.left() < screenRect.left()) { offset.setX(screenRect.left() - rect.left() + 4); } else if (rect.right() > screenRect.right()) { offset.setX(screenRect.right() - rect.right() - 4); } - if (rect.top() < screenRect.top()) { offset.setY(screenRect.top() - rect.top() + 4); } else if (rect.bottom() > screenRect.bottom()) { offset.setY(screenRect.bottom() - rect.bottom() - 4); } - return rect.translated(offset); }(); qCDebug(lcSystray) << "taskbarScreenEdge:" << taskbarScreenEdge; qCDebug(lcSystray) << "screenRect:" << screenRect; qCDebug(lcSystray) << "windowRect (reference)" << QRect(topLeft, bottomRight); - qCDebug(lcSystray) << "windowRect (adjusted )" << windowRect; + qCDebug(lcSystray) << "windowRect (adjusted)" << windowRect; return windowRect.topLeft(); } |