@ -2,8 +2,8 @@
#include <QMenu>
#include <QMenu>
#include <QWidget>
#include <QWidget>
#include <QTemporaryFile>
extern void qt_mac_set_dock_menu(QMenu*);
#include <QImageWriter>
#undef slots
#undef slots
#include <Cocoa/Cocoa.h>
#include <Cocoa/Cocoa.h>
@ -47,11 +47,11 @@ extern void qt_mac_set_dock_menu(QMenu*);
MacDockIconHandler::MacDockIconHandler() : QObject()
MacDockIconHandler::MacDockIconHandler() : QObject()
{
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
this->m_dummyWidget = new QWidget();
this->m_dummyWidget = new QWidget();
this->m_dockMenu = new QMenu(this->m_dummyWidget);
this->m_dockMenu = new QMenu(this->m_dummyWidget);
qt_mac_set_dock_menu(this->m_dockMenu);
[pool release];
[pool release];
}
}
@ -74,15 +74,29 @@ QMenu *MacDockIconHandler::dockMenu()
void MacDockIconHandler::setIcon(const QIcon &icon)
void MacDockIconHandler::setIcon(const QIcon &icon)
{
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *image;
NSImage *image = nil ;
if (icon.isNull())
if (icon.isNull())
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
else {
else {
// generate NSImage from QIcon and use this as dock icon.
QSize size = icon.actualSize(QSize(128, 128));
QSize size = icon.actualSize(QSize(128, 128));
QPixmap pixmap = icon.pixmap(size);
QPixmap pixmap = icon.pixmap(size);
CGImageRef cgImage = pixmap.toMacCGImageRef();
image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
// write temp file hack (could also be done through QIODevice [memory])
CFRelease(cgImage);
QTemporaryFile notificationIconFile;
if (!pixmap.isNull() && notificationIconFile.open()) {
QImageWriter writer(¬ificationIconFile, "PNG");
if (writer.write(pixmap.toImage())) {
const char *cString = notificationIconFile.fileName().toUtf8().data();
NSString *macString = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding];
image = [[NSImage alloc] initWithContentsOfFile:macString];
}
}
if(!image) {
// if testnet image could not be created, load std. app icon
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
}
}
}
[NSApp setApplicationIconImage:image];
[NSApp setApplicationIconImage:image];