|
|
|
@ -28,56 +28,72 @@
@@ -28,56 +28,72 @@
|
|
|
|
|
|
|
|
|
|
#include "macutilities.h" |
|
|
|
|
|
|
|
|
|
#include <QSet> |
|
|
|
|
#include <QtMac> |
|
|
|
|
#include <objc/message.h> |
|
|
|
|
#import <Cocoa/Cocoa.h> |
|
|
|
|
|
|
|
|
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size) |
|
|
|
|
namespace MacUtils |
|
|
|
|
{ |
|
|
|
|
@autoreleasepool { |
|
|
|
|
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; |
|
|
|
|
if (image) { |
|
|
|
|
NSRect rect = NSMakeRect(0, 0, size.width(), size.height()); |
|
|
|
|
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil]; |
|
|
|
|
return QtMac::fromCGImageRef(cgImage); |
|
|
|
|
} |
|
|
|
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size) |
|
|
|
|
{ |
|
|
|
|
@autoreleasepool { |
|
|
|
|
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; |
|
|
|
|
if (image) { |
|
|
|
|
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, ...)) |
|
|
|
|
{ |
|
|
|
|
NSApplication *appInst = [NSApplication sharedApplication]; |
|
|
|
|
|
|
|
|
|
if (!appInst) |
|
|
|
|
return; |
|
|
|
|
if (!appInst) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Class delClass = [[appInst delegate] class]; |
|
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); |
|
|
|
|
Class delClass = [[appInst delegate] class]; |
|
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); |
|
|
|
|
|
|
|
|
|
if (class_getInstanceMethod(delClass, shouldHandle)) { |
|
|
|
|
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
|
qDebug("Registered dock click handler (replaced original method)"); |
|
|
|
|
else |
|
|
|
|
qWarning("Failed to replace method for dock click handler"); |
|
|
|
|
if (class_getInstanceMethod(delClass, shouldHandle)) { |
|
|
|
|
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
|
qDebug("Registered dock click handler (replaced original method)"); |
|
|
|
|
else |
|
|
|
|
qWarning("Failed to replace method for dock click handler"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
|
qDebug("Registered dock click handler"); |
|
|
|
|
else |
|
|
|
|
qWarning("Failed to register dock click handler"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
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]; |
|
|
|
|
notification.title = title.toNSString(); |
|
|
|
|
notification.informativeText = message.toNSString(); |
|
|
|
|
notification.soundName = NSUserNotificationDefaultSoundName; |
|
|
|
|
|
|
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void displayNotification(const QString &title, const QString &message) |
|
|
|
|
{ |
|
|
|
|
@autoreleasepool { |
|
|
|
|
NSUserNotification *notification = [[NSUserNotification alloc] init]; |
|
|
|
|
notification.title = title.toNSString(); |
|
|
|
|
notification.informativeText = message.toNSString(); |
|
|
|
|
notification.soundName = NSUserNotificationDefaultSoundName; |
|
|
|
|
void openFiles(const QSet<QString> &pathsList) |
|
|
|
|
{ |
|
|
|
|
@autoreleasepool { |
|
|
|
|
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; |
|
|
|
|
|
|
|
|
|
for (const auto &path : pathsList) |
|
|
|
|
[pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]]; |
|
|
|
|
|
|
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; |
|
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|