From ec8802203db491821feb0b895ea04d46c5747255 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 18 Oct 2023 12:12:30 +0800 Subject: [PATCH] Improve .torrent associate handling * Use correct pointer type in NSIS scripts * Only remove qbt specific registry keys when uninstalling or disassociating * Set .torrent Content Type when associating .torrent format * Move ".torrent association" functions to Utils::OS class Original PR #19709. --- dist/windows/installer.nsi | 4 +- dist/windows/uninstaller.nsi | 11 +- src/app/application.cpp | 10 +- src/base/CMakeLists.txt | 2 + src/base/base.pri | 2 + src/base/preferences.cpp | 153 --------------------------- src/base/preferences.h | 11 +- src/base/utils/misc.cpp | 2 +- src/base/utils/os.cpp | 194 +++++++++++++++++++++++++++++++++++ src/base/utils/os.h | 50 +++++++++ src/gui/optionsdialog.cpp | 24 +++-- 11 files changed, 278 insertions(+), 185 deletions(-) create mode 100644 src/base/utils/os.cpp create mode 100644 src/base/utils/os.h diff --git a/dist/windows/installer.nsi b/dist/windows/installer.nsi index 14edd1f1f..a76e92609 100644 --- a/dist/windows/installer.nsi +++ b/dist/windows/installer.nsi @@ -109,7 +109,7 @@ Section $(inst_torrent) ;"Open .torrent files with qBittorrent" !insertmacro UAC_AsUser_Call Function inst_torrent_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)' + System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)' SectionEnd @@ -142,7 +142,7 @@ Section $(inst_magnet) ;"Open magnet links with qBittorrent" !insertmacro UAC_AsUser_Call Function inst_magnet_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)' + System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)' SectionEnd diff --git a/dist/windows/uninstaller.nsi b/dist/windows/uninstaller.nsi index 64dee7dea..72a13749d 100644 --- a/dist/windows/uninstaller.nsi +++ b/dist/windows/uninstaller.nsi @@ -26,17 +26,17 @@ Section "un.$(remove_associations)" ;"un.Remove file associations" DetailPrint "$(uninst_tor_warn) $0" DeleteRegValue HKLM "Software\Classes\.torrent" "" DeleteRegKey /ifempty HKLM "Software\Classes\.torrent" - torrent_end: + ReadRegStr $0 HKLM "Software\Classes\magnet\shell\open\command" "" StrCmp $0 '"$INSTDIR\qbittorrent.exe" "%1"' 0 magnet_end DetailPrint "$(uninst_mag_warn) $0" DeleteRegKey HKLM "Software\Classes\magnet" - magnet_end: + !insertmacro UAC_AsUser_Call Function un.remove_associations_user ${UAC_SYNCREGISTERS}|${UAC_SYNCOUTDIR}|${UAC_SYNCINSTDIR} - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)' + System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)' SectionEnd Function un.remove_associations_user @@ -45,13 +45,12 @@ Function un.remove_associations_user DetailPrint "$(uninst_tor_warn) $0" DeleteRegValue HKCU "Software\Classes\.torrent" "" DeleteRegKey /ifempty HKCU "Software\Classes\.torrent" - torrent_end: + ReadRegStr $0 HKCU "Software\Classes\magnet\shell\open\command" "" StrCmp $0 '"$INSTDIR\qbittorrent.exe" "%1"' 0 magnet_end DetailPrint "$(uninst_mag_warn) $0" DeleteRegKey HKCU "Software\Classes\magnet" - magnet_end: FunctionEnd @@ -62,7 +61,7 @@ Section "un.$(remove_registry)" ;"un.Remove registry keys" DeleteRegKey HKLM "Software\qBittorrent" DeleteRegKey HKLM "Software\Classes\qBittorrent" - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)' + System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p 0, p 0)' SectionEnd Section "un.$(remove_firewall)" ; diff --git a/src/app/application.cpp b/src/app/application.cpp index 4ff01741a..0fb60f83f 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -98,6 +98,10 @@ #include "gui/uithememanager.h" #include "gui/utils.h" #include "gui/windowstate.h" + +#ifdef Q_OS_WIN +#include "base/utils/os.h" +#endif // Q_OS_WIN #endif // DISABLE_GUI #ifndef DISABLE_WEBUI @@ -877,14 +881,14 @@ int Application::exec() delete m_startupProgressDialog; #ifdef Q_OS_WIN auto *pref = Preferences::instance(); - if (!pref->neverCheckFileAssoc() && (!Preferences::isTorrentFileAssocSet() || !Preferences::isMagnetLinkAssocSet())) + if (!pref->neverCheckFileAssoc() && (!Utils::OS::isTorrentFileAssocSet() || !Utils::OS::isMagnetLinkAssocSet())) { if (QMessageBox::question(m_window, tr("Torrent file association") , tr("qBittorrent is not the default application for opening torrent files or Magnet links.\nDo you want to make qBittorrent the default application for these?") , QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { - pref->setTorrentFileAssoc(true); - pref->setMagnetLinkAssoc(true); + Utils::OS::setTorrentFileAssoc(true); + Utils::OS::setMagnetLinkAssoc(true); } else { diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 2403c2e11..36825a283 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -99,6 +99,7 @@ add_library(qbt_base STATIC utils/io.h utils/misc.h utils/net.h + utils/os.h utils/password.h utils/random.h utils/string.h @@ -184,6 +185,7 @@ add_library(qbt_base STATIC utils/io.cpp utils/misc.cpp utils/net.cpp + utils/os.cpp utils/password.cpp utils/random.cpp utils/string.cpp diff --git a/src/base/base.pri b/src/base/base.pri index e6fd1ca3b..7c1d3af57 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -99,6 +99,7 @@ HEADERS += \ $$PWD/utils/io.h \ $$PWD/utils/misc.h \ $$PWD/utils/net.h \ + $$PWD/utils/os.h \ $$PWD/utils/password.h \ $$PWD/utils/random.h \ $$PWD/utils/string.h \ @@ -184,6 +185,7 @@ SOURCES += \ $$PWD/utils/io.cpp \ $$PWD/utils/misc.cpp \ $$PWD/utils/net.cpp \ + $$PWD/utils/os.cpp \ $$PWD/utils/password.cpp \ $$PWD/utils/random.cpp \ $$PWD/utils/string.cpp \ diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index b349f357c..ca2b101ab 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -31,13 +31,6 @@ #include -#ifdef Q_OS_MACOS -#include -#endif -#ifdef Q_OS_WIN -#include -#endif - #include #include #include @@ -47,10 +40,6 @@ #include #include -#ifdef Q_OS_WIN -#include -#endif - #include "algorithm.h" #include "global.h" #include "path.h" @@ -1316,150 +1305,8 @@ void Preferences::setNeverCheckFileAssoc(const bool check) setValue(u"Preferences/Win32/NeverCheckFileAssocation"_s, check); } - -bool Preferences::isTorrentFileAssocSet() -{ - const QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); - if (settings.value(u".torrent/Default"_s).toString() != u"qBittorrent") - { - qDebug(".torrent != qBittorrent"); - return false; - } - - return true; -} - -void Preferences::setTorrentFileAssoc(const bool set) -{ - QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); - - // .Torrent association - if (set) - { - const QString oldProgId = settings.value(u".torrent/Default"_s).toString(); - if (!oldProgId.isEmpty() && (oldProgId != u"qBittorrent")) - settings.setValue((u".torrent/OpenWithProgids/" + oldProgId), QString()); - settings.setValue(u".torrent/Default"_s, u"qBittorrent"_s); - } - else if (isTorrentFileAssocSet()) - { - settings.setValue(u".torrent/Default"_s, QString()); - } - - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); -} - -bool Preferences::isMagnetLinkAssocSet() -{ - const QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); - - // Check magnet link assoc - const QString shellCommand = settings.value(u"magnet/shell/open/command/Default"_s, QString()).toString(); - - const QRegularExpressionMatch exeRegMatch = QRegularExpression(u"\"([^\"]+)\".*"_s).match(shellCommand); - if (!exeRegMatch.hasMatch()) - return false; - - const Path assocExe {exeRegMatch.captured(1)}; - if (assocExe != Path(qApp->applicationFilePath())) - return false; - - return true; -} - -void Preferences::setMagnetLinkAssoc(const bool set) -{ - QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); - - // Magnet association - if (set) - { - const QString applicationFilePath = Path(qApp->applicationFilePath()).toString(); - const QString commandStr = u'"' + applicationFilePath + u"\" \"%1\""; - const QString iconStr = u'"' + applicationFilePath + u"\",1"; - - settings.setValue(u"magnet/Default"_s, u"URL:Magnet link"_s); - settings.setValue(u"magnet/Content Type"_s, u"application/x-magnet"_s); - settings.setValue(u"magnet/URL Protocol"_s, QString()); - settings.setValue(u"magnet/DefaultIcon/Default"_s, iconStr); - settings.setValue(u"magnet/shell/Default"_s, u"open"_s); - settings.setValue(u"magnet/shell/open/command/Default"_s, commandStr); - } - else if (isMagnetLinkAssocSet()) - { - settings.remove(u"magnet"_s); - } - - SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); -} #endif // Q_OS_WIN -#ifdef Q_OS_MACOS -namespace -{ - const CFStringRef torrentExtension = CFSTR("torrent"); - const CFStringRef magnetUrlScheme = CFSTR("magnet"); -} - -bool Preferences::isTorrentFileAssocSet() -{ - bool isSet = false; - const CFStringRef torrentId = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL); - if (torrentId != NULL) - { - const CFStringRef defaultHandlerId = LSCopyDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer); - if (defaultHandlerId != NULL) - { - const CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); - if (myBundleId != NULL) - isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; - CFRelease(defaultHandlerId); - } - CFRelease(torrentId); - } - return isSet; -} - -void Preferences::setTorrentFileAssoc() -{ - if (isTorrentFileAssocSet()) - return; - - const CFStringRef torrentId = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL); - if (torrentId != NULL) - { - const CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); - if (myBundleId != NULL) - LSSetDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer, myBundleId); - CFRelease(torrentId); - } -} - -bool Preferences::isMagnetLinkAssocSet() -{ - bool isSet = false; - const CFStringRef defaultHandlerId = LSCopyDefaultHandlerForURLScheme(magnetUrlScheme); - if (defaultHandlerId != NULL) - { - const CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); - if (myBundleId != NULL) - isSet = CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; - CFRelease(defaultHandlerId); - } - return isSet; -} - -void Preferences::setMagnetLinkAssoc() -{ - if (isMagnetLinkAssocSet()) - return; - - const CFStringRef myBundleId = CFBundleGetIdentifier(CFBundleGetMainBundle()); - if (myBundleId != NULL) - LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId); -} -#endif // Q_OS_MACOS - int Preferences::getTrackerPort() const { return value(u"Preferences/Advanced/trackerPort"_s, 9000); diff --git a/src/base/preferences.h b/src/base/preferences.h index 9f17eabb5..3cd35c8c6 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -290,17 +290,8 @@ public: #ifdef Q_OS_WIN bool neverCheckFileAssoc() const; void setNeverCheckFileAssoc(bool check = true); - static bool isTorrentFileAssocSet(); - static void setTorrentFileAssoc(bool set); - static bool isMagnetLinkAssocSet(); - static void setMagnetLinkAssoc(bool set); -#endif -#ifdef Q_OS_MACOS - static bool isTorrentFileAssocSet(); - static void setTorrentFileAssoc(); - static bool isMagnetLinkAssocSet(); - static void setMagnetLinkAssoc(); #endif + int getTrackerPort() const; void setTrackerPort(int port); bool isTrackerPortForwardingEnabled() const; diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index a39355e23..9ca0cdf24 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -611,4 +611,4 @@ Path Utils::Misc::windowsSystemPath() }(); return path; } -#endif +#endif // Q_OS_WIN diff --git a/src/base/utils/os.cpp b/src/base/utils/os.cpp new file mode 100644 index 000000000..8ee374e3d --- /dev/null +++ b/src/base/utils/os.cpp @@ -0,0 +1,194 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2023 Mike Tzou (Chocobo1) + * Copyright (C) 2014 sledgehammer999 + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "os.h" + +#ifdef Q_OS_MACOS +#include +#endif // Q_OS_MACOS + +#ifdef Q_OS_WIN +#include +#endif // Q_OS_WIN + +#include + +#ifdef Q_OS_WIN +#include +#include +#include +#endif // Q_OS_WIN + +#include "base/global.h" +#include "base/path.h" + +#ifdef Q_OS_MACOS +namespace +{ + const CFStringRef torrentExtension = CFSTR("torrent"); + const CFStringRef magnetUrlScheme = CFSTR("magnet"); +} + +bool Utils::OS::isTorrentFileAssocSet() +{ + bool isSet = false; + const CFStringRef torrentId = ::UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL); + if (torrentId != NULL) + { + const CFStringRef defaultHandlerId = ::LSCopyDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer); + if (defaultHandlerId != NULL) + { + const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); + if (myBundleId != NULL) + isSet = ::CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; + ::CFRelease(defaultHandlerId); + } + ::CFRelease(torrentId); + } + return isSet; +} + +void Utils::OS::setTorrentFileAssoc() +{ + if (isTorrentFileAssocSet()) + return; + + const CFStringRef torrentId = ::UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, torrentExtension, NULL); + if (torrentId != NULL) + { + const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); + if (myBundleId != NULL) + ::LSSetDefaultRoleHandlerForContentType(torrentId, kLSRolesViewer, myBundleId); + ::CFRelease(torrentId); + } +} + +bool Utils::OS::isMagnetLinkAssocSet() +{ + bool isSet = false; + const CFStringRef defaultHandlerId = ::LSCopyDefaultHandlerForURLScheme(magnetUrlScheme); + if (defaultHandlerId != NULL) + { + const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); + if (myBundleId != NULL) + isSet = ::CFStringCompare(myBundleId, defaultHandlerId, 0) == kCFCompareEqualTo; + ::CFRelease(defaultHandlerId); + } + return isSet; +} + +void Utils::OS::setMagnetLinkAssoc() +{ + if (isMagnetLinkAssocSet()) + return; + + const CFStringRef myBundleId = ::CFBundleGetIdentifier(::CFBundleGetMainBundle()); + if (myBundleId != NULL) + ::LSSetDefaultHandlerForURLScheme(magnetUrlScheme, myBundleId); +} +#endif // Q_OS_MACOS + +#ifdef Q_OS_WIN +bool Utils::OS::isTorrentFileAssocSet() +{ + const QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); + return settings.value(u".torrent/Default"_s).toString() == u"qBittorrent"; +} + +void Utils::OS::setTorrentFileAssoc(const bool set) +{ + if (set == isTorrentFileAssocSet()) + return; + + QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); + + if (set) + { + const QString oldProgId = settings.value(u".torrent/Default"_s).toString(); + if (!oldProgId.isEmpty() && (oldProgId != u"qBittorrent")) + settings.setValue((u".torrent/OpenWithProgids/" + oldProgId), QString()); + + settings.setValue(u".torrent/Default"_s, u"qBittorrent"_s); + settings.setValue(u".torrent/Content Type"_s, u"application/x-bittorrent"_s); + } + else + { + settings.setValue(u".torrent/Default"_s, QString()); + } + + ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr); +} + +bool Utils::OS::isMagnetLinkAssocSet() +{ + const QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); + const QString shellCommand = settings.value(u"magnet/shell/open/command/Default"_s).toString(); + + const QRegularExpressionMatch exeRegMatch = QRegularExpression(u"\"([^\"]+)\".*"_s).match(shellCommand); + if (!exeRegMatch.hasMatch()) + return false; + + const Path assocExe {exeRegMatch.captured(1)}; + if (assocExe != Path(qApp->applicationFilePath())) + return false; + + return true; +} + +void Utils::OS::setMagnetLinkAssoc(const bool set) +{ + if (set == isMagnetLinkAssocSet()) + return; + + QSettings settings(u"HKEY_CURRENT_USER\\Software\\Classes"_s, QSettings::NativeFormat); + + if (set) + { + const QString applicationFilePath = Path(qApp->applicationFilePath()).toString(); + const QString commandStr = u'"' + applicationFilePath + u"\" \"%1\""; + const QString iconStr = u'"' + applicationFilePath + u"\",1"; + + settings.setValue(u"magnet/Default"_s, u"URL:Magnet link"_s); + settings.setValue(u"magnet/Content Type"_s, u"application/x-magnet"_s); + settings.setValue(u"magnet/DefaultIcon/Default"_s, iconStr); + settings.setValue(u"magnet/shell/Default"_s, u"open"_s); + settings.setValue(u"magnet/shell/open/command/Default"_s, commandStr); + settings.setValue(u"magnet/URL Protocol"_s, QString()); + } + else + { + // only wipe values that are specific to qbt + settings.setValue(u"magnet/DefaultIcon/Default"_s, QString()); + settings.setValue(u"magnet/shell/open/command/Default"_s, QString()); + } + + ::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr); +} +#endif // Q_OS_WIN diff --git a/src/base/utils/os.h b/src/base/utils/os.h new file mode 100644 index 000000000..66b899977 --- /dev/null +++ b/src/base/utils/os.h @@ -0,0 +1,50 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2023 Mike Tzou (Chocobo1) + * Copyright (C) 2014 sledgehammer999 + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#pragma once + +#include + +namespace Utils::OS +{ +#ifdef Q_OS_MACOS + bool isTorrentFileAssocSet(); + void setTorrentFileAssoc(); + bool isMagnetLinkAssocSet(); + void setMagnetLinkAssoc(); +#endif // Q_OS_MACOS + +#ifdef Q_OS_WIN + bool isTorrentFileAssocSet(); + void setTorrentFileAssoc(bool set); + bool isMagnetLinkAssocSet(); + void setMagnetLinkAssoc(bool set); +#endif // Q_OS_WIN +} diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index d043dfbb6..4247c4e8d 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -74,6 +74,10 @@ #include "base/net/dnsupdater.h" #endif +#if defined Q_OS_MACOS || defined Q_OS_WIN +#include "base/utils/os.h" +#endif // defined Q_OS_MACOS || defined Q_OS_WIN + #define SETTINGS_KEY(name) u"OptionsDialog/" name namespace @@ -284,15 +288,15 @@ void OptionsDialog::loadBehaviorTabOptions() #ifdef Q_OS_WIN m_ui->checkStartup->setChecked(pref->WinStartup()); - m_ui->checkAssociateTorrents->setChecked(Preferences::isTorrentFileAssocSet()); - m_ui->checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet()); + m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet()); + m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet()); #endif #ifdef Q_OS_MACOS m_ui->checkShowSystray->setVisible(false); - m_ui->checkAssociateTorrents->setChecked(Preferences::isTorrentFileAssocSet()); + m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet()); m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked()); - m_ui->checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet()); + m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet()); m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked()); #endif @@ -433,8 +437,8 @@ void OptionsDialog::saveBehaviorTabOptions() const #ifdef Q_OS_WIN pref->setWinStartup(WinStartup()); - Preferences::setTorrentFileAssoc(m_ui->checkAssociateTorrents->isChecked()); - Preferences::setMagnetLinkAssoc(m_ui->checkAssociateMagnetLinks->isChecked()); + Utils::OS::setTorrentFileAssoc(m_ui->checkAssociateTorrents->isChecked()); + Utils::OS::setMagnetLinkAssoc(m_ui->checkAssociateMagnetLinks->isChecked()); #endif #ifndef Q_OS_MACOS @@ -447,14 +451,14 @@ void OptionsDialog::saveBehaviorTabOptions() const #ifdef Q_OS_MACOS if (m_ui->checkAssociateTorrents->isChecked()) { - Preferences::setTorrentFileAssoc(); - m_ui->checkAssociateTorrents->setChecked(Preferences::isTorrentFileAssocSet()); + Utils::OS::setTorrentFileAssoc(); + m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet()); m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked()); } if (m_ui->checkAssociateMagnetLinks->isChecked()) { - Preferences::setMagnetLinkAssoc(); - m_ui->checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet()); + Utils::OS::setMagnetLinkAssoc(); + m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet()); m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked()); } #endif