aboutsummaryrefslogtreecommitdiff
path: root/src/qt/macdockiconhandler.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/macdockiconhandler.mm')
-rw-r--r--src/qt/macdockiconhandler.mm30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm
index b6ea8e1d03..53b49c42e6 100644
--- a/src/qt/macdockiconhandler.mm
+++ b/src/qt/macdockiconhandler.mm
@@ -2,8 +2,8 @@
#include <QMenu>
#include <QWidget>
-
-extern void qt_mac_set_dock_menu(QMenu*);
+#include <QTemporaryFile>
+#include <QImageWriter>
#undef slots
#include <Cocoa/Cocoa.h>
@@ -47,11 +47,11 @@ extern void qt_mac_set_dock_menu(QMenu*);
MacDockIconHandler::MacDockIconHandler() : QObject()
{
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_dockMenu = new QMenu(this->m_dummyWidget);
- qt_mac_set_dock_menu(this->m_dockMenu);
+
[pool release];
}
@@ -74,15 +74,29 @@ QMenu *MacDockIconHandler::dockMenu()
void MacDockIconHandler::setIcon(const QIcon &icon)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSImage *image;
+ NSImage *image = nil;
if (icon.isNull())
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
else {
+ // generate NSImage from QIcon and use this as dock icon.
QSize size = icon.actualSize(QSize(128, 128));
QPixmap pixmap = icon.pixmap(size);
- CGImageRef cgImage = pixmap.toMacCGImageRef();
- image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
- CFRelease(cgImage);
+
+ // write temp file hack (could also be done through QIODevice [memory])
+ QTemporaryFile notificationIconFile;
+ if (!pixmap.isNull() && notificationIconFile.open()) {
+ QImageWriter writer(&notificationIconFile, "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];