| 1 |
#include "osx_helper.h" |
| 2 |
#include <Cocoa/Cocoa.h> |
| 3 |
#include <ApplicationServices/ApplicationServices.h> |
| 4 |
|
| 5 |
QIcon osxGetIcon(const QString& extension) |
| 6 |
{ |
| 7 |
QIcon icon; |
| 8 |
@autoreleasepool |
| 9 |
{ |
| 10 |
NSImage* image = [[NSWorkspace sharedWorkspace] iconForFileType:extension.toNSString()]; |
| 11 |
NSRect rect = NSMakeRect(0, 0, image.size.width, image.size.height); |
| 12 |
CGImageRef imageRef = [image CGImageForProposedRect:&rect context:NULL hints:nil]; |
| 13 |
if (imageRef) |
| 14 |
{ |
| 15 |
icon = QtMac::fromCGImageRef(imageRef); |
| 16 |
} |
| 17 |
} |
| 18 |
return icon; |
| 19 |
} |
| 20 |
|
| 21 |
void osxShowDockIcon() |
| 22 |
{ |
| 23 |
ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 24 |
TransformProcessType(&psn, kProcessTransformToForegroundApplication); |
| 25 |
} |
| 26 |
|
| 27 |
void osxHideDockIcon() |
| 28 |
{ |
| 29 |
ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 30 |
TransformProcessType(&psn, kProcessTransformToUIElementApplication); |
| 31 |
} |