diff --git a/.arclint b/.arclint index 3d9106143..2258bb04f 100644 --- a/.arclint +++ b/.arclint @@ -1,132 +1,132 @@ { "linters": { "generated": { "type": "generated" }, "clang-format": { "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)/)" ] }, "autopep8": { "type": "autopep8", "version": ">=1.3.4", "include": "(\\.py$)" }, "flake8": { "type": "flake8", "include": "(\\.py$)", "flags": [ "--select=E112,E113,E115,E116,E125,E131,E133,E223,E224,E271,E272,E273,E274,E275,E304,E306,E502,E702,E703,E714,E721,E741,E742,E743,F401,F402,F403,F404,F405,F406,F407,F601,F602,F621,F622,F631,F701,F702,F703,F704,F705,F706,F707,F811,F812,F822,F823,F831,W292,W601,W602,W603,W604,W605" ] }, "lint-format-strings": { "type": "lint-format-strings", "include": "(^src/.*\\.(h|c|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "check-doc": { "type": "check-doc", "include": "(^src/.*\\.(h|c|cpp)$)" }, "lint-tests": { "type": "lint-tests", "include": "(^src/(rpc/|wallet/)?test/.*\\.(cpp)$)" }, "lint-python-format": { "type": "lint-python-format", "include": "(\\.py$)", "exclude": [ "(^test/lint/lint-python-format\\.py$)" ] }, "phpcs": { "type": "phpcs", "include": "(\\.php$)", "exclude": [ "(^arcanist/__phutil_library_.+\\.php$)" ], "phpcs.standard": "arcanist/phpcs.xml" }, "lint-locale-dependence": { "type": "lint-locale-dependence", "include": "(^src/.*\\.(h|cpp)$)", "exclude": [ "(^src/(crypto/ctaes/|leveldb/|secp256k1/|seeder/|tinyformat.h|univalue/))" ] }, "lint-cheader": { "type": "lint-cheader", "include": "(^src/.*\\.(h|cpp)$)", "exclude": [ "(^src/(crypto/ctaes|secp256k1|univalue|leveldb)/)" ] }, "spelling": { "type": "spelling", "exclude": [ "(^build-aux/m4/)", "(^depends/)", "(^doc/release-notes/)", "(^src/(qt/locale|secp256k1|univalue|leveldb)/)", "(^test/lint/dictionary/)" ], "spelling.dictionaries": [ "test/lint/dictionary/english.json" ] }, "lint-assert-with-side-effects": { "type": "lint-assert-with-side-effects", "include": "(^src/.*\\.(h|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "lint-include-quotes": { "type": "lint-include-quotes", "include": "(^src/.*\\.(h|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "lint-include-guard": { "type": "lint-include-guard", "include": "(^src/.*\\.h$)", "exclude": [ "(^src/(crypto/ctaes|secp256k1|univalue|leveldb)/)", "(^src/tinyformat.h$)" ] }, "lint-include-source": { "type": "lint-include-source", "include": "(^src/.*\\.(h|c|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "lint-stdint": { "type": "lint-stdint", "include": "(^src/.*\\.(h|c|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "lint-source-filename": { "type": "lint-source-filename", "include": "(^src/.*\\.(h|c|cpp)$)", "exclude": [ "(^src/(secp256k1|univalue|leveldb)/)" ] }, "lint-boost-dependencies": { "type": "lint-boost-dependencies", "include": "(^src/.*\\.(h|cpp)$)" } } } diff --git a/src/.clang-format b/src/.clang-format index 1e71b84f3..6900bd0e5 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -1,18 +1,22 @@ -Language: Cpp -Standard: Cpp11 ColumnLimit: 80 IndentWidth: 4 TabWidth: 4 AccessModifierOffset: -4 UseTab: Never IndentCaseLabels: true NamespaceIndentation: Inner BreakBeforeBraces: Attach ReflowComments: true AlignEscapedNewlines: Right AllowShortBlocksOnASingleLine: false AllowShortIfStatementsOnASingleLine: true AllowShortFunctionsOnASingleLine: Inline 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 index a0b62ae00..169acd646 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -1,128 +1,123 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #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; } 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(); this->m_dummyWidget = new QWidget(); this->m_dockMenu = new QMenu(this->m_dummyWidget); this->setMainWindow(nullptr); #if QT_VERSION >= 0x050200 this->m_dockMenu->setAsDockMenu(); #endif [pool release]; } void MacDockIconHandler::setMainWindow(QMainWindow *window) { 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()) 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); // 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]; + 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]; } } [NSApp setApplicationIconImage:image]; [image release]; [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(); } Q_EMIT this->dockIconClicked(); } diff --git a/src/qt/macnotificationhandler.mm b/src/qt/macnotificationhandler.mm index 61f811c5b..98f260d14 100644 --- a/src/qt/macnotificationhandler.mm +++ b/src/qt/macnotificationhandler.mm @@ -1,77 +1,84 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #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 { return [self __bundleIdentifier]; } } @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(); cString = (char *)utf8.constData(); 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]; [userNotification release]; } } -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; }