First pass at OS X port (Qt4->5; Carbon->Cocoa)

Application compiles and runs, with some caveats. Full list of changes:

- minor changes related to Qt4->Qt5 API differences

- Replaced calls to Carbon framework by Cocoa

- Removed registering of AE event handler. Seems to be done
automatically in Qt5.

- temporarily removed Podcast functionality, pending (presumably)
complete re-write due to Quicktime being obsolete in newer OS X
versions.

- Created OBCocoa namespace, and associated files src/core/OBCocoa.h/.mm, to
handle OS X - specific system calls. Currently used only by
UBApplication, but can in the future provide a useful interface between
the cocoa framework and OB, to avoid having too much OSX-specific code
in various files
preferencesAboutTextFull
Craig Watson 9 years ago
parent 7a4e9d2e83
commit 91cc74fbd7
  1. 34
      OpenBoard.pro
  2. 2
      src/adaptors/UBThumbnailAdaptor.cpp
  3. 3
      src/board/UBBoardView.cpp
  4. 11
      src/core/OBCocoa.h
  5. 24
      src/core/OBCocoa.mm
  6. 38
      src/core/UBApplication.cpp
  7. 9
      src/core/UBApplication.h
  8. 3
      src/core/UBApplicationController.cpp
  9. 4
      src/core/core.pri
  10. 3
      src/desktop/UBWindowCapture_mac.mm
  11. 12
      src/frameworks/UBPlatformUtils_mac.mm
  12. 2
      src/gui/UBFloatingPalette.cpp
  13. 6
      src/gui/UBKeyboardPalette_mac.mm
  14. 2
      src/gui/UBMagnifer.cpp
  15. 10
      src/gui/UBRubberBand.cpp
  16. 3
      src/gui/gui.pri
  17. 14
      src/podcast/UBPodcastController.cpp
  18. 16
      src/podcast/podcast.pri

@ -128,32 +128,34 @@ win32 {
macx { macx {
LIBS += -framework Foundation LIBS += -framework Foundation
LIBS += -framework Cocoa
LIBS += -framework Carbon
LIBS += -lcrypto LIBS += -lcrypto
CONFIG(release, debug|release):CONFIG += x86 CONFIG(release, debug|release):CONFIG += x86_64
CONFIG(debug, debug|release):CONFIG += x86_64
# [03-02-2011] We must use the 32bit version for the moment # TODO Craig: switch to 64bit
# because the Quicktime components used by this application
# are not yet available in 64bits.
CONFIG(debug, debug|release):CONFIG += x86
QMAKE_MAC_SDK = "/Developer/SDKs/MacOSX10.6.sdk" QMAKE_MAC_SDK = macosx
QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.5" QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.10"
VERSION_RC_PATH = "$$BUILD_DIR/version_rc" QMAKE_CXXFLAGS += -Wno-overloaded-virtual
#VERSION_RC_PATH = "$$BUILD_DIR/version_rc"
# No references to breakpad in the code =>is this still used?
# Embed version into executable for breakpad # Embed version into executable for breakpad
QMAKE_LFLAGS += -sectcreate \ #QMAKE_LFLAGS += -sectcreate \
__DATA \ # __DATA \
__version \ # __version \
$$VERSION_RC_PATH # $$VERSION_RC_PATH
QMAKE_CXXFLAGS_RELEASE += -gdwarf-2 \ QMAKE_CXXFLAGS_RELEASE += -gdwarf-2 \
-mdynamic-no-pic -mdynamic-no-pic
QMAKE_CFLAGS += -fopenmp # QMAKE_CFLAGS += -fopenmp
QMAKE_CXXFLAGS += -fopenmp # QMAKE_CXXFLAGS += -fopenmp
QMAKE_LFLAGS += -fopenmp # QMAKE_LFLAGS += -fopenmp
CONTENTS_DIR = "Contents" CONTENTS_DIR = "Contents"
RESOURCES_DIR = "Contents/Resources" RESOURCES_DIR = "Contents/Resources"
@ -364,7 +366,7 @@ macx {
system(mkdir -p $$BUILD_DIR) system(mkdir -p $$BUILD_DIR)
system(printf \""$$OSX_VERSION"\" > $$BUILD_DIR/osx_version) system(printf \""$$OSX_VERSION"\" > $$BUILD_DIR/osx_version)
system(printf \""$$VERSION"\" > $$BUILD_DIR/version) system(printf \""$$VERSION"\" > $$BUILD_DIR/version)
system(printf "%02x%02x%02x%02x" `printf $$VERSION_RC | cut -d ',' -f 1` `printf $$VERSION_RC | cut -d ',' -f 2` `printf $$VERSION_RC | cut -d ',' -f 3` `printf $$VERSION_RC | cut -d ',' -f 4` | xxd -r -p > "$$VERSION_RC_PATH") # system(printf "%02x%02x%02x%02x" `printf $$VERSION_RC | cut -d ',' -f 1` `printf $$VERSION_RC | cut -d ',' -f 2` `printf $$VERSION_RC | cut -d ',' -f 3` `printf $$VERSION_RC | cut -d ',' -f 4` | xxd -r -p > "$$VERSION_RC_PATH")
} }
linux-g++* { linux-g++* {

@ -98,7 +98,7 @@ const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex)
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
pix->load(fileName, 0, Qt::AutoColor); pix->load(fileName, 0, Qt::AutoColor);
#else #else
pix->load(fileName, 0, Qt::AutoColor, false); pix->load(fileName, 0, Qt::AutoColor);
#endif #endif
} }
return pix; return pix;

@ -872,7 +872,6 @@ bool UBBoardView::directTabletEvent(QEvent *event)
tEvent = new QTabletEvent(tEvent->type() tEvent = new QTabletEvent(tEvent->type()
, mapFromGlobal(tEvent->pos()) , mapFromGlobal(tEvent->pos())
, tEvent->globalPos() , tEvent->globalPos()
, tEvent->hiResGlobalPos()
, tEvent->device() , tEvent->device()
, tEvent->pointerType() , tEvent->pointerType()
, tEvent->pressure() , tEvent->pressure()
@ -905,7 +904,7 @@ QWidget *UBBoardView::widgetForTabletEvent(QWidget *w, const QPoint &pos)
QWidget *childAtPos = NULL; QWidget *childAtPos = NULL;
QList<QObject *> childs = w->childItems(); QList<QObject *> childs = w->children();
foreach(QObject *child, childs) foreach(QObject *child, childs)
{ {
QWidget *childWidget = qobject_cast<QWidget *>(child); QWidget *childWidget = qobject_cast<QWidget *>(child);

@ -0,0 +1,11 @@
/*
OBCocoa.h
Header file permitting access to Mac OSX / Cocoa specific functions
*/
namespace OBCocoa {
void setFrontProcess();
}

@ -0,0 +1,24 @@
#include "OBCocoa.h"
#include "UBApplicationController.h"
#include <QDebug>
#import <Cocoa/Cocoa.h>
namespace OBCocoa {
/**
* @brief Activate the current application
*/
void setFrontProcess()
{
NSRunningApplication* app = [NSRunningApplication currentApplication];
// activate the application, forcing focus on it
[app activateWithOptions: NSApplicationActivateIgnoringOtherApps];
// other option:NSApplicationActivateAllWindows. This won't steal focus from another app, e.g
// if the user is doing something else while waiting for OpenBoard to load
}
} // namespace OBCocoa

@ -34,7 +34,7 @@
#include <QStyleFactory> #include <QStyleFactory>
#if defined(Q_OS_OSX) #if defined(Q_OS_OSX)
#include <Carbon/Carbon.h> #include "OBCocoa.h"
#endif #endif
#include "frameworks/UBPlatformUtils.h" #include "frameworks/UBPlatformUtils.h"
@ -91,27 +91,6 @@ bool bIsMinimized = false;
QObject* UBApplication::staticMemoryCleaner = 0; QObject* UBApplication::staticMemoryCleaner = 0;
#if defined(Q_OS_OSX)
static OSStatus ub_appleEventProcessor(const AppleEvent *ae, AppleEvent *event, long handlerRefCon)
{
Q_UNUSED(event);
OSType aeID = typeWildCard;
OSType aeClass = typeWildCard;
AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0);
AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0);
if (aeClass == kCoreEventClass && aeID == kAEReopenApplication)
{
// User clicked on Uniboard in the Dock
((UBApplicationController*)handlerRefCon)->hideDesktop();
return noErr;
}
return eventNotHandledErr;
}
#endif
UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv) UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv)
, mPreferencesController(NULL) , mPreferencesController(NULL)
@ -368,11 +347,6 @@ int UBApplication::exec(const QString& pFileToImport)
if (pFileToImport.length() > 0) if (pFileToImport.length() > 0)
UBApplication::applicationController->importFile(pFileToImport); UBApplication::applicationController->importFile(pFileToImport);
#if defined(Q_OS_OSX)
static AEEventHandlerUPP ub_proc_ae_handlerUPP = AEEventHandlerUPP(ub_appleEventProcessor);
AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, ub_proc_ae_handlerUPP, SRefCon(UBApplication::applicationController), true);
#endif
if (UBSettings::settings()->appStartMode->get().toInt()) if (UBSettings::settings()->appStartMode->get().toInt())
applicationController->showDesktop(); applicationController->showDesktop();
else else
@ -390,14 +364,14 @@ void UBApplication::onScreenCountChanged(int newCount)
mainWindow->actionMultiScreen->setEnabled(displayManager.numScreens() > 1); mainWindow->actionMultiScreen->setEnabled(displayManager.numScreens() > 1);
} }
#ifdef Q_OS_OSX
void UBApplication::showMinimized() void UBApplication::showMinimized()
{ {
#ifdef Q_OS_OSX
mainWindow->hide(); mainWindow->hide();
bIsMinimized = true; bIsMinimized = true;
#endif
} }
#endif
void UBApplication::startScript() void UBApplication::startScript()
{ {
@ -590,11 +564,7 @@ bool UBApplication::eventFilter(QObject *obj, QEvent *event)
{ {
QFileOpenEvent *fileToOpenEvent = static_cast<QFileOpenEvent *>(event); QFileOpenEvent *fileToOpenEvent = static_cast<QFileOpenEvent *>(event);
#if defined(Q_OS_OSX) OBCocoa::setFrontProcess();
ProcessSerialNumber psn;
GetCurrentProcess(&psn);
SetFrontProcess(&psn);
#endif
applicationController->importFile(fileToOpenEvent->file()); applicationController->importFile(fileToOpenEvent->file());
} }

@ -124,9 +124,9 @@ class UBApplication : public QtSingleApplication
private slots: private slots:
void closing(); void closing();
#ifdef Q_OS_OSX //#ifdef Q_OS_OSX // for some reason this is not compiled if the ifdef is uncommented
void showMinimized(); void showMinimized();
#endif //#endif
void onScreenCountChanged(int newCount); void onScreenCountChanged(int newCount);
private: private:
@ -136,10 +136,11 @@ class UBApplication : public QtSingleApplication
bool mIsVerbose; bool mIsVerbose;
QString checkLanguageAvailabilityForSankore(QString& language); QString checkLanguageAvailabilityForSankore(QString& language);
protected: protected:
/*
#if defined(Q_OS_OSX) && !defined(QT_MAC_USE_COCOA) #if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA)
bool macEventFilter(EventHandlerCallRef caller, EventRef event); bool macEventFilter(EventHandlerCallRef caller, EventRef event);
#endif #endif
*/
UBPreferencesController* mPreferencesController; UBPreferencesController* mPreferencesController;
QTranslator* mApplicationTranslator; QTranslator* mApplicationTranslator;

@ -67,9 +67,6 @@
#include "ui_mainWindow.h" #include "ui_mainWindow.h"
#ifdef Q_OS_OSX
#include <Carbon/Carbon.h>
#endif
#include "core/memcheck.h" #include "core/memcheck.h"

@ -36,3 +36,7 @@ SOURCES += src/core/main.cpp \
src/core/UBPersistenceWorker.cpp src/core/UBPersistenceWorker.cpp
macx {
HEADERS += src/core/OBCocoa.h
OBJECTIVE_SOURCES += src/core/OBCocoa.mm
}

@ -26,9 +26,10 @@
#include "UBWindowCapture.h" #include "UBWindowCapture.h"
#include "UBDesktopAnnotationController.h" #include "UBDesktopAnnotationController.h"
#include <QDialog>
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSAutoreleasePool.h>
#import <Carbon/Carbon.h> #import <Cocoa/Cocoa.h>
UBWindowCapture::UBWindowCapture(UBDesktopAnnotationController *parent) UBWindowCapture::UBWindowCapture(UBDesktopAnnotationController *parent)

@ -33,6 +33,7 @@
#include <QWidget> #include <QWidget>
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSAutoreleasePool.h>
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
#import <APELite.h> #import <APELite.h>
@ -51,7 +52,7 @@ OSStatus emptySetSystemUIMode (
return noErr; return noErr;
} }
void *originalSetSystemUIMode = 0; //void *originalSetSystemUIMode = 0;
void UBPlatformUtils::init() void UBPlatformUtils::init()
{ {
@ -62,7 +63,7 @@ void UBPlatformUtils::init()
// http://developer.apple.com/mac/library/documentation/Carbon/Reference/Dock_Manager/Reference/reference.html#//apple_ref/c/func/SetSystemUIMode // http://developer.apple.com/mac/library/documentation/Carbon/Reference/Dock_Manager/Reference/reference.html#//apple_ref/c/func/SetSystemUIMode
// //
originalSetSystemUIMode = APEPatchCreate((const void *)SetSystemUIMode, (const void *)emptySetSystemUIMode); //originalSetSystemUIMode = APEPatchCreate((const void *)SetSystemUIMode, (const void *)emptySetSystemUIMode);
setDesktopMode(false); setDesktopMode(false);
@ -92,9 +93,9 @@ void UBPlatformUtils::init()
void UBPlatformUtils::setDesktopMode(bool desktop) void UBPlatformUtils::setDesktopMode(bool desktop)
{ { /*
#ifndef OS_NEWER_THAN_OR_EQUAL_TO_1010 #ifndef OS_NEWER_THAN_OR_EQUAL_TO_1010
OSStatus (*functor)(SystemUIMode, SystemUIOptions) = (OSStatus (*)(SystemUIMode, SystemUIOptions))originalSetSystemUIMode; //OSStatus (*functor)(SystemUIMode, SystemUIOptions) = (OSStatus (*)(SystemUIMode, SystemUIOptions))originalSetSystemUIMode;
if (desktop) if (desktop)
{ {
@ -105,6 +106,7 @@ void UBPlatformUtils::setDesktopMode(bool desktop)
functor(kUIModeAllHidden, 0); functor(kUIModeAllHidden, 0);
} }
#endif #endif
*/
} }
@ -533,7 +535,7 @@ void UBPlatformUtils::SetMacLocaleByIdentifier(const QString& id)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const char * strName = id.toAscii().data(); const char * strName = id.toLatin1().data();
CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman );

@ -60,7 +60,7 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent)
#endif #endif
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
setAttribute(Qt::WA_MacAlwaysShowToolWindow); setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow); //setAttribute(Qt::WA_MacNonActivatingToolWindow); // no longer exists
setAttribute(Qt::WA_MacNoShadow); setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }

@ -30,7 +30,8 @@
#include <stdio.h> #include <stdio.h>
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#include <Carbon/Carbon.h>
#import <Cocoa/Cocoa.h>
#include <QMap> #include <QMap>
#include <QString> #include <QString>
@ -74,6 +75,8 @@ void UBKeyboardPalette::createCtrlButtons()
void UBKeyboardPalette::checkLayout() void UBKeyboardPalette::checkLayout()
{ {
/*
* REMOVED FOR NOW -- check if is still needed in 10.9/10.10
TISInputSourceRef selectedLocale = TISCopyCurrentKeyboardInputSource(); TISInputSourceRef selectedLocale = TISCopyCurrentKeyboardInputSource();
CFStringRef sr = (CFStringRef) TISGetInputSourceProperty(selectedLocale, CFStringRef sr = (CFStringRef) TISGetInputSourceProperty(selectedLocale,
@ -96,6 +99,7 @@ void UBKeyboardPalette::checkLayout()
} }
} }
} }
*/
} }
void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onActivated(bool)

@ -85,7 +85,7 @@ UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive)
#endif #endif
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
setAttribute(Qt::WA_MacAlwaysShowToolWindow); setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setAttribute(Qt::WA_MacNonActivatingToolWindow); //setAttribute(Qt::WA_MacNonActivatingToolWindow);
setAttribute(Qt::WA_MacNoShadow); setAttribute(Qt::WA_MacNoShadow);
#endif #endif
} }

@ -31,15 +31,11 @@
#include <QStyleFactory> #include <QStyleFactory>
#include <QStyle> #include <QStyle>
#ifdef Q_OS_OSX
#include <QtGui/QMacStyle>
#endif
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBBoardView.h" #include "board/UBBoardView.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
UBRubberBand::UBRubberBand(Shape s, QWidget * p) UBRubberBand::UBRubberBand(Shape s, QWidget * p)
: QRubberBand(s, p) : QRubberBand(s, p)
@ -53,7 +49,7 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p)
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
customStyle = new QWindowsXPStyle(); customStyle = new QWindowsXPStyle();
#elif defined(Q_OS_OSX) #elif defined(Q_OS_OSX)
customStyle = new QMacStyle(); customStyle = QStyleFactory::create("macintosh");
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
customStyle = QStyleFactory::create("oxygen"); customStyle = QStyleFactory::create("oxygen");
#endif #endif

@ -85,7 +85,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \
src/gui/UBOpenSankoreImporterWidget.cpp \ src/gui/UBOpenSankoreImporterWidget.cpp \
src/gui/UBStartupHintsPalette.cpp src/gui/UBStartupHintsPalette.cpp
win32:SOURCES += src/gui/UBKeyboardPalette_win.cpp win32:SOURCES += src/gui/UBKeyboardPalette_win.cpp
macx:SOURCES += src/gui/UBKeyboardPalette_mac.cpp macx:OBJECTIVE_SOURCES += src/gui/UBKeyboardPalette_mac.mm
linux-g++:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++:SOURCES += src/gui/UBKeyboardPalette_linux.cpp
linux-g++-32:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++-32:SOURCES += src/gui/UBKeyboardPalette_linux.cpp
linux-g++-64:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++-64:SOURCES += src/gui/UBKeyboardPalette_linux.cpp

@ -59,9 +59,9 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "windowsmedia/UBWindowsMediaVideoEncoder.h" #include "windowsmedia/UBWindowsMediaVideoEncoder.h"
#include "windowsmedia/UBWaveRecorder.h" #include "windowsmedia/UBWaveRecorder.h"
#elif defined(Q_OS_OSX) //#elif defined(Q_OS_OSX)
#include "quicktime/UBQuickTimeVideoEncoder.h" // #include "quicktime/UBQuickTimeVideoEncoder.h"
#include "quicktime/UBAudioQueueRecorder.h" // #include "quicktime/UBAudioQueueRecorder.h"
#endif #endif
#include "core/memcheck.h" #include "core/memcheck.h"
@ -305,8 +305,8 @@ void UBPodcastController::start()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
mVideoEncoder = new UBWindowsMediaVideoEncoder(this); //deleted on stop mVideoEncoder = new UBWindowsMediaVideoEncoder(this); //deleted on stop
#elif defined(Q_OS_OSX) //#elif defined(Q_OS_OSX)
mVideoEncoder = new UBQuickTimeVideoEncoder(this); //deleted on stop // mVideoEncoder = new UBQuickTimeVideoEncoder(this); //deleted on stop
#endif #endif
if (mVideoEncoder) if (mVideoEncoder)
@ -795,8 +795,8 @@ QStringList UBPodcastController::audioRecordingDevices()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
devices = UBWaveRecorder::waveInDevices(); devices = UBWaveRecorder::waveInDevices();
#elif defined(Q_OS_OSX) //#elif defined(Q_OS_OSX)
devices = UBAudioQueueRecorder::waveInDevices(); // devices = UBAudioQueueRecorder::waveInDevices();
#endif #endif
return devices; return devices;

@ -22,13 +22,13 @@ win32 {
src/podcast/windowsmedia/UBWaveRecorder.h src/podcast/windowsmedia/UBWaveRecorder.h
} }
macx { #macx {
SOURCES += src/podcast/quicktime/UBQuickTimeVideoEncoder.cpp \ # SOURCES += src/podcast/quicktime/UBQuickTimeVideoEncoder.cpp \
src/podcast/quicktime/UBQuickTimeFile.cpp \ # src/podcast/quicktime/UBQuickTimeFile.cpp \
src/podcast/quicktime/UBAudioQueueRecorder.cpp # src/podcast/quicktime/UBAudioQueueRecorder.cpp
HEADERS += src/podcast/quicktime/UBQuickTimeVideoEncoder.h \ # HEADERS += src/podcast/quicktime/UBQuickTimeVideoEncoder.h \
src/podcast/quicktime/UBQuickTimeFile.h \ # src/podcast/quicktime/UBQuickTimeFile.h \
src/podcast/quicktime/UBAudioQueueRecorder.h # src/podcast/quicktime/UBAudioQueueRecorder.h
} #}

Loading…
Cancel
Save