diff --git a/.arclint b/.arclint --- a/.arclint +++ b/.arclint @@ -7,7 +7,7 @@ "type": "clang-format", "version": "7.0", "bin": ["clang-format-7", "clang-format"], - "include": "(^src/.*\\.(h|c|cpp)$)", + "include": "(^src/.*\\.(h|c|cpp|mm)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] diff --git a/src/.clang-format b/src/.clang-format --- a/src/.clang-format +++ b/src/.clang-format @@ -1,5 +1,3 @@ -Language: Cpp -Standard: Cpp11 ColumnLimit: 80 IndentWidth: 4 TabWidth: 4 @@ -16,3 +14,9 @@ FixNamespaceComments: true ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, BOOST_REVERSE_FOREACH ] CommentPragmas: '@DISABLE FORMATING FOR THIS COMMENT@' +--- +Language: Cpp +Standard: Cpp11 +--- +Language: ObjC +ObjCBlockIndentWidth: 4 diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -4,24 +4,24 @@ #include "macdockiconhandler.h" +#include #include #include -#include #include #undef slots #include -#include #include +#include static MacDockIconHandler *s_instance = nullptr; -bool dockClickHandler(id self,SEL _cmd,...) { +bool dockClickHandler(id self, SEL _cmd, ...) { Q_UNUSED(self) Q_UNUSED(_cmd) - + s_instance->handleDockIconClickEvent(); - + // Return NO (false) to suppress the default OS X actions return false; } @@ -29,21 +29,23 @@ void setupDockClickHandler() { Class cls = objc_getClass("NSApplication"); id appInst = objc_msgSend((id)cls, sel_registerName("sharedApplication")); - + if (appInst != nullptr) { id delegate = objc_msgSend(appInst, sel_registerName("delegate")); - Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class")); - SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:"); + Class delClass = + (Class)objc_msgSend(delegate, sel_registerName("class")); + SEL shouldHandle = sel_registerName( + "applicationShouldHandleReopen:hasVisibleWindows:"); if (class_getInstanceMethod(delClass, shouldHandle)) - class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, "B@:"); + class_replaceMethod(delClass, shouldHandle, (IMP)dockClickHandler, + "B@:"); else - class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler,"B@:"); + class_addMethod(delClass, shouldHandle, (IMP)dockClickHandler, + "B@:"); } } - -MacDockIconHandler::MacDockIconHandler() : QObject() -{ +MacDockIconHandler::MacDockIconHandler() : QObject() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; setupDockClickHandler(); @@ -60,19 +62,16 @@ this->mainWindow = window; } -MacDockIconHandler::~MacDockIconHandler() -{ +MacDockIconHandler::~MacDockIconHandler() { delete this->m_dummyWidget; this->setMainWindow(nullptr); } -QMenu *MacDockIconHandler::dockMenu() -{ +QMenu *MacDockIconHandler::dockMenu() { return this->m_dockMenu; } -void MacDockIconHandler::setIcon(const QIcon &icon) -{ +void MacDockIconHandler::setIcon(const QIcon &icon) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSImage *image = nil; if (icon.isNull()) @@ -87,13 +86,14 @@ 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]; + NSData *macImgData = + [NSData dataWithBytes:notificationBuffer.buffer().data() + length:notificationBuffer.buffer().size()]; + image = [[NSImage alloc] initWithData:macImgData]; } } - if(!image) { + if (!image) { // if testnet image could not be created, load std. app icon image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; } @@ -104,22 +104,17 @@ [pool release]; } -MacDockIconHandler *MacDockIconHandler::instance() -{ - if (!s_instance) - s_instance = new MacDockIconHandler(); +MacDockIconHandler *MacDockIconHandler::instance() { + if (!s_instance) s_instance = new MacDockIconHandler(); return s_instance; } -void MacDockIconHandler::cleanup() -{ +void MacDockIconHandler::cleanup() { delete s_instance; } -void MacDockIconHandler::handleDockIconClickEvent() -{ - if (this->mainWindow) - { +void MacDockIconHandler::handleDockIconClickEvent() { + if (this->mainWindow) { this->mainWindow->activateWindow(); this->mainWindow->show(); } diff --git a/src/qt/macnotificationhandler.mm b/src/qt/macnotificationhandler.mm --- a/src/qt/macnotificationhandler.mm +++ b/src/qt/macnotificationhandler.mm @@ -5,13 +5,12 @@ #include "macnotificationhandler.h" #undef slots -#import #include +#import // Add an obj-c category (extension) to return the expected bundle identifier -@implementation NSBundle(returnCorrectIdentifier) -- (NSString *)__bundleIdentifier -{ +@implementation NSBundle (returnCorrectIdentifier) +- (NSString *)__bundleIdentifier { if (self == [NSBundle mainBundle]) { return @"org.bitcoinabc.BitcoinABC-Qt"; } else { @@ -20,13 +19,13 @@ } @end -void MacNotificationHandler::showNotification(const QString &title, const QString &text) -{ +void MacNotificationHandler::showNotification(const QString &title, + const QString &text) { // check if users OS has support for NSUserNotification - if(this->hasUserNotificationCenterSupport()) { + if (this->hasUserNotificationCenterSupport()) { // okay, seems like 10.8+ QByteArray utf8 = title.toUtf8(); - char* cString = (char *)utf8.constData(); + char *cString = (char *)utf8.constData(); NSString *titleMac = [[NSString alloc] initWithUTF8String:cString]; utf8 = text.toUtf8(); @@ -34,12 +33,19 @@ NSString *textMac = [[NSString alloc] initWithUTF8String:cString]; // do everything weak linked (because we will keep <10.8 compatibility) - id userNotification = [[NSClassFromString(@"NSUserNotification") alloc] init]; - [userNotification performSelector:@selector(setTitle:) withObject:titleMac]; - [userNotification performSelector:@selector(setInformativeText:) withObject:textMac]; + id userNotification = + [[NSClassFromString(@"NSUserNotification") alloc] init]; + [userNotification performSelector:@selector(setTitle:) + withObject:titleMac]; + [userNotification performSelector:@selector(setInformativeText:) + withObject:textMac]; - id notificationCenterInstance = [NSClassFromString(@"NSUserNotificationCenter") performSelector:@selector(defaultUserNotificationCenter)]; - [notificationCenterInstance performSelector:@selector(deliverNotification:) withObject:userNotification]; + id notificationCenterInstance = + [NSClassFromString(@"NSUserNotificationCenter") + performSelector:@selector(defaultUserNotificationCenter)]; + [notificationCenterInstance + performSelector:@selector(deliverNotification:) + withObject:userNotification]; [titleMac release]; [textMac release]; @@ -47,30 +53,31 @@ } } -bool MacNotificationHandler::hasUserNotificationCenterSupport() -{ +bool MacNotificationHandler::hasUserNotificationCenterSupport() { Class possibleClass = NSClassFromString(@"NSUserNotificationCenter"); // check if users OS has support for NSUserNotification - if(possibleClass!=nil) { + if (possibleClass != nil) { return true; } return false; } - -MacNotificationHandler *MacNotificationHandler::instance() -{ +MacNotificationHandler *MacNotificationHandler::instance() { static MacNotificationHandler *s_instance = nullptr; if (!s_instance) { s_instance = new MacNotificationHandler(); - + Class aPossibleClass = objc_getClass("NSBundle"); if (aPossibleClass) { - // change NSBundle -bundleIdentifier method to return a correct bundle identifier - // a bundle identifier is required to use OSXs User Notification Center - method_exchangeImplementations(class_getInstanceMethod(aPossibleClass, @selector(bundleIdentifier)), - class_getInstanceMethod(aPossibleClass, @selector(__bundleIdentifier))); + // change NSBundle -bundleIdentifier method to return a correct + // bundle identifier a bundle identifier is required to use OSXs + // User Notification Center + method_exchangeImplementations( + class_getInstanceMethod(aPossibleClass, + @selector(bundleIdentifier)), + class_getInstanceMethod(aPossibleClass, + @selector(__bundleIdentifier))); } } return s_instance;