X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fmacdockiconhandler.mm;h=32701137c9ac8ed4f99c9a22b05c435dc6b98e7d;hb=c6fb5920250cfb05d056639772a0f642d3a1e0c9;hp=75684403eb48d260724c3deaa4901b2bd0b6ef5f;hpb=02a236f2f7ea2113015a647006ec1dfb6f99bea9;p=novacoin.git diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index 7568440..3270113 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -1,7 +1,12 @@ +// Copyright (c) 2011-2013 The Bitcoin Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "macdockiconhandler.h" +#include #include +#include #include extern void qt_mac_set_dock_menu(QMenu*); @@ -9,6 +14,10 @@ extern void qt_mac_set_dock_menu(QMenu*); #undef slots #include +#if QT_VERSION < 0x050000 +extern void qt_mac_set_dock_menu(QMenu *); +#endif + @interface DockIconClickEventHandler : NSObject { MacDockIconHandler* dockIconHandler; @@ -38,8 +47,9 @@ extern void qt_mac_set_dock_menu(QMenu*); Q_UNUSED(event) Q_UNUSED(replyEvent) - if (dockIconHandler) + if (dockIconHandler) { dockIconHandler->handleDockIconClickEvent(); + } } @end @@ -47,18 +57,28 @@ 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); + this->setMainWindow(NULL); +#if QT_VERSION < 0x050000 qt_mac_set_dock_menu(this->m_dockMenu); +#elif QT_VERSION >= 0x050200 + this->m_dockMenu->setAsDockMenu(); +#endif [pool release]; } +void MacDockIconHandler::setMainWindow(QMainWindow *window) { + this->mainWindow = window; +} + MacDockIconHandler::~MacDockIconHandler() { [this->m_dockIconClickEventHandler release]; delete this->m_dummyWidget; + this->setMainWindow(NULL); } QMenu *MacDockIconHandler::dockMenu() @@ -69,15 +89,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 image into a R/W buffer from raw pixmap, then save the image. + QBuffer notificationBuffer; + if (!pixmap.isNull() && notificationBuffer.open(QIODevice::ReadWrite)) { + QImageWriter writer(¬ificationBuffer, "PNG"); + if (writer.write(pixmap.toImage())) { + NSData* macImgData = [NSData dataWithBytes:notificationBuffer.buffer().data() + length:notificationBuffer.buffer().size()]; + image = [[NSImage alloc] initWithData:macImgData]; + } + } + + if(!image) { + // if testnet image could not be created, load std. app icon + image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; + } } [NSApp setApplicationIconImage:image]; @@ -95,5 +129,11 @@ MacDockIconHandler *MacDockIconHandler::instance() void MacDockIconHandler::handleDockIconClickEvent() { + if (this->mainWindow) + { + this->mainWindow->activateWindow(); + this->mainWindow->show(); + } + emit this->dockIconClicked(); }