|
|
@ -28,56 +28,72 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "macutilities.h" |
|
|
|
#include "macutilities.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QSet> |
|
|
|
#include <QtMac> |
|
|
|
#include <QtMac> |
|
|
|
#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, ...)) |
|
|
|
void overrideDockClickHandler(bool (*dockClickHandler)(id, SEL, ...)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
NSApplication *appInst = [NSApplication sharedApplication]; |
|
|
|
NSApplication *appInst = [NSApplication sharedApplication]; |
|
|
|
|
|
|
|
|
|
|
|
if (!appInst) |
|
|
|
if (!appInst) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
Class delClass = [[appInst delegate] class]; |
|
|
|
Class delClass = [[appInst delegate] class]; |
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); |
|
|
|
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); |
|
|
|
|
|
|
|
|
|
|
|
if (class_getInstanceMethod(delClass, shouldHandle)) { |
|
|
|
if (class_getInstanceMethod(delClass, shouldHandle)) { |
|
|
|
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
if (class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
qDebug("Registered dock click handler (replaced original method)"); |
|
|
|
qDebug("Registered dock click handler (replaced original method)"); |
|
|
|
else |
|
|
|
else |
|
|
|
qWarning("Failed to replace method for dock click handler"); |
|
|
|
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@:")) |
|
|
|
void displayNotification(const QString &title, const QString &message) |
|
|
|
qDebug("Registered dock click handler"); |
|
|
|
{ |
|
|
|
else |
|
|
|
@autoreleasepool { |
|
|
|
qWarning("Failed to register dock click handler"); |
|
|
|
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) |
|
|
|
void openFiles(const QSet<QString> &pathsList) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@autoreleasepool { |
|
|
|
@autoreleasepool { |
|
|
|
NSUserNotification *notification = [[NSUserNotification alloc] init]; |
|
|
|
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; |
|
|
|
notification.title = title.toNSString(); |
|
|
|
|
|
|
|
notification.informativeText = message.toNSString(); |
|
|
|
for (const auto &path : pathsList) |
|
|
|
notification.soundName = NSUserNotificationDefaultSoundName; |
|
|
|
[pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]]; |
|
|
|
|
|
|
|
|
|
|
|
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification]; |
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|