|
|
@ -35,18 +35,21 @@ |
|
|
|
#include <QSet> |
|
|
|
#include <QSet> |
|
|
|
#include <QSize> |
|
|
|
#include <QSize> |
|
|
|
#include <QString> |
|
|
|
#include <QString> |
|
|
|
#include <QtMac> |
|
|
|
|
|
|
|
|
|
|
|
QImage qt_mac_toQImage(CGImageRef image); |
|
|
|
|
|
|
|
|
|
|
|
namespace MacUtils |
|
|
|
namespace MacUtils |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size) |
|
|
|
QPixmap pixmapForExtension(const QString &ext, const QSize &size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@autoreleasepool { |
|
|
|
@autoreleasepool |
|
|
|
|
|
|
|
{ |
|
|
|
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; |
|
|
|
NSImage *image = [[NSWorkspace sharedWorkspace] iconForFileType:ext.toNSString()]; |
|
|
|
if (image) { |
|
|
|
if (image) |
|
|
|
|
|
|
|
{ |
|
|
|
NSRect rect = NSMakeRect(0, 0, size.width(), size.height()); |
|
|
|
NSRect rect = NSMakeRect(0, 0, size.width(), size.height()); |
|
|
|
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil]; |
|
|
|
CGImageRef cgImage = [image CGImageForProposedRect:&rect context:nil hints:nil]; |
|
|
|
return QtMac::fromCGImageRef(cgImage); |
|
|
|
return QPixmap::fromImage(qt_mac_toQImage(cgImage)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return QPixmap(); |
|
|
|
return QPixmap(); |
|
|
@ -63,13 +66,15 @@ namespace MacUtils |
|
|
|
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 { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
if (class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:")) |
|
|
|
qDebug("Registered dock click handler"); |
|
|
|
qDebug("Registered dock click handler"); |
|
|
|
else |
|
|
|
else |
|
|
@ -79,7 +84,8 @@ namespace MacUtils |
|
|
|
|
|
|
|
|
|
|
|
void displayNotification(const QString &title, const QString &message) |
|
|
|
void displayNotification(const QString &title, const QString &message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@autoreleasepool { |
|
|
|
@autoreleasepool |
|
|
|
|
|
|
|
{ |
|
|
|
NSUserNotification *notification = [[NSUserNotification alloc] init]; |
|
|
|
NSUserNotification *notification = [[NSUserNotification alloc] init]; |
|
|
|
notification.title = title.toNSString(); |
|
|
|
notification.title = title.toNSString(); |
|
|
|
notification.informativeText = message.toNSString(); |
|
|
|
notification.informativeText = message.toNSString(); |
|
|
@ -91,7 +97,8 @@ namespace MacUtils |
|
|
|
|
|
|
|
|
|
|
|
void openFiles(const QSet<QString> &pathsList) |
|
|
|
void openFiles(const QSet<QString> &pathsList) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@autoreleasepool { |
|
|
|
@autoreleasepool |
|
|
|
|
|
|
|
{ |
|
|
|
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; |
|
|
|
NSMutableArray *pathURLs = [NSMutableArray arrayWithCapacity:pathsList.size()]; |
|
|
|
|
|
|
|
|
|
|
|
for (const auto &path : pathsList) |
|
|
|
for (const auto &path : pathsList) |
|
|
@ -100,4 +107,14 @@ namespace MacUtils |
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; |
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString badgeLabelText() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return QString::fromNSString(NSApp.dockTile.badgeLabel); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setBadgeLabelText(const QString &text) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
NSApp.dockTile.badgeLabel = text.toNSString(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|