fix autorelease pools not being set (
issue #209) and format code a little
--- a/QTfrontend/CocoaInitializer.h Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/CocoaInitializer.h Sun Apr 03 16:34:12 2011 +0200
@@ -1,7 +1,23 @@
/*
- * Copyright (C) 2008 Remko Troncon
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2005-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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; version 2 of the License
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+// see original example here http://el-tramo.be/blog/mixing-cocoa-and-qt
+
#ifndef COCOAINITIALIZER_H
#define COCOAINITIALIZER_H
@@ -13,8 +29,7 @@
private:
class Private;
- Private* d;
- Private* c;
+ Private* c;
};
#endif
--- a/QTfrontend/CocoaInitializer.mm Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/CocoaInitializer.mm Sun Apr 03 16:34:12 2011 +0200
@@ -1,7 +1,23 @@
/*
- * Copyright (C) 2008 Remko Troncon
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2005-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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; version 2 of the License
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+// see original example here http://el-tramo.be/blog/mixing-cocoa-and-qt
+
#include "CocoaInitializer.h"
#include <AppKit/AppKit.h>
@@ -10,23 +26,19 @@
class CocoaInitializer::Private
{
- public:
- NSAutoreleasePool* autoReleasePool_;
+ public:
+ NSAutoreleasePool* pool;
};
CocoaInitializer::CocoaInitializer()
{
- d = new CocoaInitializer::Private();
- c = new CocoaInitializer::Private();
- NSApplicationLoad();
- c->autoReleasePool_ = [[NSAutoreleasePool alloc] init];
- d->autoReleasePool_ = [[NSAutoreleasePool alloc] init];
+ c = new CocoaInitializer::Private();
+ NSApplicationLoad();
+ c->pool = [[NSAutoreleasePool alloc] init];
}
CocoaInitializer::~CocoaInitializer()
{
- [d->autoReleasePool_ release];
- [c->autoReleasePool_ release];
- delete c;
- delete d;
+ [c->pool release];
+ delete c;
}
--- a/QTfrontend/InstallController.h Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/InstallController.h Sun Apr 03 16:34:12 2011 +0200
@@ -20,11 +20,11 @@
#define INSTALLCONTROLLER_H
class InstallController
- {
+{
public:
virtual ~InstallController();
virtual void showInstallController() = 0;
- };
+};
#endif
--- a/QTfrontend/M3Panel.h Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/M3Panel.h Sun Apr 03 16:34:12 2011 +0200
@@ -22,7 +22,7 @@
#include "InstallController.h"
class M3Panel : public InstallController
- {
+{
public:
M3Panel(void);
~M3Panel();
@@ -32,6 +32,6 @@
private:
class Private;
Private* c;
- };
+};
#endif
--- a/QTfrontend/M3Panel.mm Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/M3Panel.mm Sun Apr 03 16:34:12 2011 +0200
@@ -23,26 +23,25 @@
class M3Panel::Private
{
-public:
+ public:
M3InstallController *install;
};
M3Panel::M3Panel(void)
{
- c = new Private;
+ c = new Private;
- c->install = [[M3InstallController alloc] init];
- [c->install retain];
-
+ c->install = [[M3InstallController alloc] init];
+ [c->install retain];
}
M3Panel::~M3Panel()
{
- [c->install release];
- delete c;
+ [c->install release];
+ delete c;
}
void M3Panel::showInstallController()
{
- [c->install displayInstaller];
+ [c->install displayInstaller];
}
--- a/QTfrontend/SparkleAutoUpdater.mm Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/SparkleAutoUpdater.mm Sun Apr 03 16:34:12 2011 +0200
@@ -1,7 +1,23 @@
/*
- * Copyright (C) 2008 Remko Troncon
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2005-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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; version 2 of the License
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+// see original example here http://el-tramo.be/blog/mixing-cocoa-and-qt
+
#include "SparkleAutoUpdater.h"
#include <Cocoa/Cocoa.h>
@@ -9,29 +25,28 @@
class SparkleAutoUpdater::Private
{
- public:
- SUUpdater* updater;
+ public:
+ SUUpdater* updater;
};
SparkleAutoUpdater::SparkleAutoUpdater(const QString& aUrl)
{
- d = new Private;
+ d = new Private;
- d->updater = [SUUpdater sharedUpdater];
- [d->updater retain];
+ d->updater = [SUUpdater sharedUpdater];
+ [d->updater retain];
- NSURL* url = [NSURL URLWithString:
- [NSString stringWithUTF8String: aUrl.toUtf8().data()]];
- [d->updater setFeedURL: url];
+ NSURL* url = [NSURL URLWithString:[NSString stringWithUTF8String:aUrl.toUtf8().data()]];
+ [d->updater setFeedURL:url];
}
SparkleAutoUpdater::~SparkleAutoUpdater()
{
- [d->updater release];
- delete d;
+ [d->updater release];
+ delete d;
}
void SparkleAutoUpdater::checkForUpdates()
{
- [d->updater checkForUpdatesInBackground];
+ [d->updater checkForUpdatesInBackground];
}
--- a/QTfrontend/hwform.cpp Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/hwform.cpp Sun Apr 03 16:34:12 2011 +0200
@@ -61,7 +61,6 @@
#include "drawmapwidget.h"
#ifdef __APPLE__
-#include "CocoaInitializer.h"
#include "M3Panel.h"
#ifdef SPARKLE_ENABLED
#define SPARKLE_APPCAST_URL "http://www.hedgewars.org/download/appcast.xml"
@@ -101,7 +100,7 @@
#ifdef SPARKLE_ENABLED
AutoUpdater* updater;
- CocoaInitializer initializer;
+
updater = new SparkleAutoUpdater(SPARKLE_APPCAST_URL);
if (updater && config->isAutoUpdateEnabled())
updater->checkForUpdates();
--- a/QTfrontend/main.cpp Sun Apr 03 16:31:48 2011 +0400
+++ b/QTfrontend/main.cpp Sun Apr 03 16:34:12 2011 +0200
@@ -31,6 +31,9 @@
#ifdef _WIN32
#include <Shlobj.h>
#endif
+#ifdef __APPLE__
+#include "CocoaInitializer.h"
+#endif
bool checkForDir(const QString & dir)
{
@@ -425,6 +428,10 @@
registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
}
#endif
+#ifdef __APPLE__
+ // this creates the autoreleasepool that prevents leaking
+ CocoaInitializer initializer;
+#endif
HWForm *Form = new HWForm();