From 5d4fe75dc58654312c9ea72f6fdfe3a47dcb8965 Mon Sep 17 00:00:00 2001 From: Daniel Kettle Date: Thu, 5 Mar 2020 00:41:57 -0800 Subject: [PATCH] Adding in cocoainitializer class to prevent mem leaks on Cocoa-based Macs - Ignore .DS_Store folder setting files, src/qmake when building in tree - added name to about contributors Signed-off-by: Daniel Kettle --- .gitignore | 2 ++ src/cocoainitializer.h | 31 ++++++++++++++++++++++++++++++ src/cocoainitializer.mm | 42 +++++++++++++++++++++++++++++++++++++++++ src/mainimpl.cpp | 3 ++- src/qgit.cpp | 9 ++++++++- src/src.pro | 5 +++++ 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/cocoainitializer.h create mode 100644 src/cocoainitializer.mm diff --git a/.gitignore b/.gitignore index 63698fb9..33ca9c96 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ qgit.pro.* qgit.qbs.* src/release .qmake.stash +.DS_Store +src/qmake* diff --git a/src/cocoainitializer.h b/src/cocoainitializer.h new file mode 100644 index 00000000..5079779c --- /dev/null +++ b/src/cocoainitializer.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Copyright (C) 2015 Ivan Romanov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +class CocoaInitializer +{ +public: + CocoaInitializer(); + ~CocoaInitializer(); + +private: + class Private; + Private *d; +}; diff --git a/src/cocoainitializer.mm b/src/cocoainitializer.mm new file mode 100644 index 00000000..af37fce0 --- /dev/null +++ b/src/cocoainitializer.mm @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Copyright (C) 2015 Ivan Romanov + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include +#include + +#include "cocoainitializer.h" + +class CocoaInitializer::Private +{ +public: + NSAutoreleasePool *autoReleasePool_; +}; + +CocoaInitializer::CocoaInitializer() +{ + d = new CocoaInitializer::Private(); + NSApplicationLoad(); + d->autoReleasePool_ = [[NSAutoreleasePool alloc] init]; +} + +CocoaInitializer::~CocoaInitializer() +{ + [d->autoReleasePool_ release]; + delete d; +} diff --git a/src/mainimpl.cpp b/src/mainimpl.cpp index 4fd40c0c..d3ab070f 100644 --- a/src/mainimpl.cpp +++ b/src/mainimpl.cpp @@ -2200,7 +2200,8 @@ void MainImpl::ActAbout_activated() { "2018 Mateusz Balbus, " "2019 Sebastian Pipping, " "2019 Matthias von Faber, " - "2019 Kevin Kofler " + "2019 Kevin Kofler, " + "2020 Daniel Kettle " "

" diff --git a/src/qgit.cpp b/src/qgit.cpp index b01c49e9..37839472 100644 --- a/src/qgit.cpp +++ b/src/qgit.cpp @@ -13,10 +13,17 @@ #pragma comment(linker,"/subsystem:windows") #endif + +#ifdef Q_OS_MAC +#include "cocoainitializer.h" +#endif + using namespace QGit; int main(int argc, char* argv[]) { - +#ifdef Q_OS_MAC + CocoaInitializer initializer; +#endif QApplication app(argc, argv); #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); diff --git a/src/src.pro b/src/src.pro index d3ba9c2e..795ab340 100644 --- a/src/src.pro +++ b/src/src.pro @@ -51,6 +51,11 @@ macx { target.path = ~/bin #CONFIG += x86 ppc RC_FILE = resources/qgit.icns + # Import the CocoaInitializer class + QT += macextras # widgets-private gui-private core-private + LIBS += -framework Cocoa + OBJECTIVE_SOURCES += \ + cocoainitializer.mm } HAVE_GCC {