mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
MigrateAwayFromDeprecatedMethods
MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods MigrateAwayFromDeprecatedMethods
This commit is contained in:
parent
fef6ac515c
commit
85530ee79b
5 changed files with 54 additions and 82 deletions
|
@ -193,72 +193,6 @@ void Utils::OS::shutdownComputer([[maybe_unused]] const ShutdownDialogAction &ac
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
#ifdef Q_OS_WIN
|
||||||
Path Utils::OS::windowsSystemPath()
|
Path Utils::OS::windowsSystemPath()
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,13 +48,6 @@ namespace Utils::OS
|
||||||
{
|
{
|
||||||
void shutdownComputer(const ShutdownDialogAction &action);
|
void shutdownComputer(const ShutdownDialogAction &action);
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
|
||||||
bool isTorrentFileAssocSet();
|
|
||||||
void setTorrentFileAssoc();
|
|
||||||
bool isMagnetLinkAssocSet();
|
|
||||||
void setMagnetLinkAssoc();
|
|
||||||
#endif // Q_OS_MACOS
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
Path windowsSystemPath();
|
Path windowsSystemPath();
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,11 @@ namespace MacUtils
|
||||||
void displayNotification(const QString &title, const QString &message);
|
void displayNotification(const QString &title, const QString &message);
|
||||||
void openFiles(const PathList &pathList);
|
void openFiles(const PathList &pathList);
|
||||||
|
|
||||||
|
bool isMagnetLinkAssocSet();
|
||||||
|
void setMagnetLinkAssoc();
|
||||||
|
bool isTorrentFileAssocSet();
|
||||||
|
void setTorrentFileAssoc();
|
||||||
|
|
||||||
QString badgeLabelText();
|
QString badgeLabelText();
|
||||||
void setBadgeLabelText(const QString &text);
|
void setBadgeLabelText(const QString &text);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,46 @@ namespace MacUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isMagnetLinkAssocSet()
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
const NSURL *magnetStandardURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"magnet:"]];
|
||||||
|
const NSURL *qbtURL = [[NSBundle mainBundle] bundleURL];
|
||||||
|
return [magnetStandardURL isEqual:qbtURL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMagnetLinkAssoc()
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
[[NSWorkspace sharedWorkspace] setDefaultApplicationAtURL:[[NSBundle mainBundle] bundleURL]
|
||||||
|
toOpenURLsWithScheme:@"magnet" completionHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTorrentFileAssocSet()
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
const NSURL *torrentStandardURL = [[NSWorkspace sharedWorkspace]
|
||||||
|
URLForApplicationToOpenContentType:[UTType typeWithFilenameExtension:@"torrent"]];
|
||||||
|
const NSURL *qbtURL = [[NSBundle mainBundle] bundleURL];
|
||||||
|
return [torrentStandardURL isEqual:qbtURL];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTorrentFileAssoc()
|
||||||
|
{
|
||||||
|
@autoreleasepool
|
||||||
|
{
|
||||||
|
[[NSWorkspace sharedWorkspace] setDefaultApplicationAtURL:[[NSBundle mainBundle] bundleURL]
|
||||||
|
toOpenContentType:[UTType typeWithFilenameExtension:@"torrent"]
|
||||||
|
completionHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString badgeLabelText()
|
QString badgeLabelText()
|
||||||
{
|
{
|
||||||
return QString::fromNSString(NSApp.dockTile.badgeLabel);
|
return QString::fromNSString(NSApp.dockTile.badgeLabel);
|
||||||
|
|
|
@ -88,9 +88,9 @@
|
||||||
#include "base/net/dnsupdater.h"
|
#include "base/net/dnsupdater.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined Q_OS_MACOS || defined Q_OS_WIN
|
#ifdef Q_OS_MACOS
|
||||||
#include "base/utils/os.h"
|
#include "macutilities.h"
|
||||||
#endif // defined Q_OS_MACOS || defined Q_OS_WIN
|
#endif
|
||||||
|
|
||||||
#define SETTINGS_KEY(name) u"OptionsDialog/" name
|
#define SETTINGS_KEY(name) u"OptionsDialog/" name
|
||||||
|
|
||||||
|
@ -329,9 +329,9 @@ void OptionsDialog::loadBehaviorTabOptions()
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
m_ui->checkShowSystray->setVisible(false);
|
m_ui->checkShowSystray->setVisible(false);
|
||||||
m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
|
m_ui->checkAssociateTorrents->setChecked(MacUtils::isTorrentFileAssocSet());
|
||||||
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
||||||
m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
|
m_ui->checkAssociateMagnetLinks->setChecked(MacUtils::isMagnetLinkAssocSet());
|
||||||
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -517,14 +517,14 @@ void OptionsDialog::saveBehaviorTabOptions() const
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
if (m_ui->checkAssociateTorrents->isChecked())
|
if (m_ui->checkAssociateTorrents->isChecked())
|
||||||
{
|
{
|
||||||
Utils::OS::setTorrentFileAssoc();
|
MacUtils::setTorrentFileAssoc();
|
||||||
m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
|
m_ui->checkAssociateTorrents->setChecked(MacUtils::isTorrentFileAssocSet());
|
||||||
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
|
||||||
}
|
}
|
||||||
if (m_ui->checkAssociateMagnetLinks->isChecked())
|
if (m_ui->checkAssociateMagnetLinks->isChecked())
|
||||||
{
|
{
|
||||||
Utils::OS::setMagnetLinkAssoc();
|
MacUtils::setMagnetLinkAssoc();
|
||||||
m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
|
m_ui->checkAssociateMagnetLinks->setChecked(MacUtils::isMagnetLinkAssocSet());
|
||||||
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue