mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
Put macOS specific functions to MacUtils namespace
This commit is contained in:
parent
d57bd62add
commit
d7fa5b6b6b
@ -33,9 +33,12 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <objc/objc.h>
|
#include <objc/objc.h>
|
||||||
|
|
||||||
QPixmap pixmapForExtension(const QString &ext, const QSize &size);
|
namespace MacUtils
|
||||||
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
|
{
|
||||||
void displayNotification(const QString &title, const QString &message);
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size);
|
||||||
void openFiles(const QSet<QString> &pathsList);
|
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...));
|
||||||
|
void displayNotification(const QString &title, const QString &message);
|
||||||
|
void openFiles(const QSet<QString> &pathsList);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // MACUTILITIES_H
|
#endif // MACUTILITIES_H
|
||||||
|
@ -33,64 +33,67 @@
|
|||||||
#include <objc/message.h>
|
#include <objc/message.h>
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
QPixmap pixmapForExtension(const QString &ext, const QSize &size)
|
namespace MacUtils
|
||||||
{
|
{
|
||||||
@autoreleasepool {
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size)
|
||||||
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()];
|
{
|
||||||
if (image) {
|
@autoreleasepool {
|
||||||
NSRect rect = NSMakeRect(0, 0, size.width(), size.height());
|
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()];
|
||||||
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
|
if (image) {
|
||||||
return QtMac::fromCGImageRef(cgImage);
|
NSRect rect = NSMakeRect(0, 0, size.width(), size.height());
|
||||||
|
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil];
|
||||||
|
return QtMac::fromCGImageRef(cgImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return QPixmap();
|
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...))
|
||||||
}
|
{
|
||||||
}
|
NSApplication *appInst = [NSApplication sharedApplication];
|
||||||
|
|
||||||
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...))
|
if (!appInst)
|
||||||
{
|
return;
|
||||||
NSApplication *appInst = [NSApplication sharedApplication];
|
|
||||||
|
Class delClass = [[appInst delegate] class];
|
||||||
if (!appInst)
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
||||||
return;
|
|
||||||
|
if (class_getInstanceMethod(delClass, shouldHandle)) {
|
||||||
Class delClass = [[appInst delegate] class];
|
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
|
||||||
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
|
qDebug("Registered dock click handler (replaced original method)");
|
||||||
|
else
|
||||||
if (class_getInstanceMethod(delClass, shouldHandle)) {
|
qWarning("Failed to replace method for dock click handler");
|
||||||
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
|
}
|
||||||
qDebug("Registered dock click handler (replaced original method)");
|
else {
|
||||||
else
|
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
|
||||||
qWarning("Failed to replace method for dock click handler");
|
qDebug("Registered dock click handler");
|
||||||
}
|
else
|
||||||
else {
|
qWarning("Failed to register dock click handler");
|
||||||
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"))
|
}
|
||||||
qDebug("Registered dock click handler");
|
}
|
||||||
else
|
|
||||||
qWarning("Failed to register dock click handler");
|
void displayNotification(const QString &title, const QString &message)
|
||||||
}
|
{
|
||||||
}
|
@autoreleasepool {
|
||||||
|
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
||||||
void displayNotification(const QString &title, const QString &message)
|
notification.title = title.toNSString();
|
||||||
{
|
notification.informativeText = message.toNSString();
|
||||||
@autoreleasepool {
|
notification.soundName = NSUserNotificationDefaultSoundName;
|
||||||
NSUserNotification *notification = [[NSUserNotification alloc] init];
|
|
||||||
notification.title = title.toNSString();
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
||||||
notification.informativeText = message.toNSString();
|
}
|
||||||
notification.soundName = NSUserNotificationDefaultSoundName;
|
}
|
||||||
|
|
||||||
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
|
void openFiles(const QSet<QString> &pathsList)
|
||||||
}
|
{
|
||||||
}
|
@autoreleasepool {
|
||||||
|
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
|
||||||
void openFiles(const QSet<QString> &pathsList)
|
|
||||||
{
|
for (const auto &path : pathsList)
|
||||||
@autoreleasepool {
|
[pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]];
|
||||||
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()];
|
|
||||||
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
|
||||||
for (const auto &path : pathsList)
|
}
|
||||||
[pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]];
|
|
||||||
|
|
||||||
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1298,7 +1298,7 @@ static bool dockClickHandler(id self, SEL cmd, ...)
|
|||||||
void MainWindow::setupDockClickHandler()
|
void MainWindow::setupDockClickHandler()
|
||||||
{
|
{
|
||||||
dockMainWindowHandle = this;
|
dockMainWindowHandle = this;
|
||||||
overrideDockClickHandler(dockClickHandler);
|
MacUtils::overrideDockClickHandler(dockClickHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -1557,7 +1557,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
|
|||||||
if (!reply.isError())
|
if (!reply.isError())
|
||||||
return;
|
return;
|
||||||
#elif defined(Q_OS_MAC)
|
#elif defined(Q_OS_MAC)
|
||||||
displayNotification(title, msg);
|
MacUtils::displayNotification(title, msg);
|
||||||
#else
|
#else
|
||||||
if (m_systrayIcon && QSystemTrayIcon::supportsMessages())
|
if (m_systrayIcon && QSystemTrayIcon::supportsMessages())
|
||||||
m_systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
m_systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON);
|
||||||
|
@ -150,7 +150,7 @@ namespace
|
|||||||
{
|
{
|
||||||
QPixmap pixmapForExtension(const QString &ext) const override
|
QPixmap pixmapForExtension(const QString &ext) const override
|
||||||
{
|
{
|
||||||
return ::pixmapForExtension(ext, QSize(32, 32));
|
return MacUtils::pixmapForExtension(ext, QSize(32, 32));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
|
@ -559,7 +559,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
|
|||||||
QString path = torrent->contentPath(true);
|
QString path = torrent->contentPath(true);
|
||||||
pathsList.insert(path);
|
pathsList.insert(path);
|
||||||
}
|
}
|
||||||
openFiles(pathsList);
|
MacUtils::openFiles(pathsList);
|
||||||
#else
|
#else
|
||||||
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
|
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
|
||||||
QString path = torrent->contentPath(true);
|
QString path = torrent->contentPath(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user