Fixed mac specific compiler errors and cleaned up Objective C code

Created new file src/gui/macutilities.mm, moved code from mainwindow.cpp and torrentcontentmodel.cpp that used the Objective C runtime into it and converted it to actual Objective C. Rewrote pixmapForExtension() so that it doesn't call into private Qt functions.
This commit is contained in:
Brian Kendall 2017-08-11 01:37:06 -04:00
parent 6f0d16bca5
commit 62b956946f
8 changed files with 144 additions and 56 deletions

View file

@ -31,8 +31,6 @@
#include "mainwindow.h"
#ifdef Q_OS_MAC
#include <objc/objc.h>
#include <objc/message.h>
#include <QtMacExtras>
#include <QtMac>
#endif
@ -107,7 +105,11 @@
#include "hidabletabwidget.h"
#include "ui_mainwindow.h"
#ifdef Q_OS_MAC
#if defined (Q_OS_MAC)
#include "macutilities.h"
#endif
#if defined (Q_OS_MAC)
void qt_mac_set_dock_menu(QMenu *menu);
#endif
@ -1294,29 +1296,9 @@ static bool dockClickHandler(id self, SEL cmd, ...)
}
void MainWindow::setupDockClickHandler()
{
Class cls = objc_getClass("NSApplication");
objc_object *appInst = objc_msgSend(reinterpret_cast<objc_object *>(cls), sel_registerName("sharedApplication"));
if (!appInst)
return;
{
dockMainWindowHandle = this;
objc_object* delegate = objc_msgSend(appInst, sel_registerName("delegate"));
Class delClass = reinterpret_cast<Class>(objc_msgSend(delegate, sel_registerName("class")));
SEL shouldHandle = sel_registerName("applicationShouldHandleReopen:hasVisibleWindows:");
if (class_getInstanceMethod(delClass, shouldHandle)) {
if (class_replaceMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
qDebug("Registered dock click handler (replaced original method)");
else
qWarning("Failed to replace method for dock click handler");
}
else {
if (class_addMethod(delClass, shouldHandle, reinterpret_cast<IMP>(dockClickHandler), "B@:"))
qDebug("Registered dock click handler");
else
qWarning("Failed to register dock click handler");
}
overrideDockClickHandler(dockClickHandler);
}
#endif