From 7b7c321d5f35b6ee70db5a72d5d37e19e125d7cf Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Sun, 7 Jul 2013 22:23:07 +0200 Subject: Fix Mac static builds so they get the qt_menu.nib from the resource file Instead of loading the file from the bundle (if it existed) then we create the qt_menu.nib from the resources instead. This ensures that static builds no longer have to have the qt_menu.nib file manually copied to be in the Resources folder for every application. Change-Id: I7abb6fad6395d466e22e7a3b7ffb63b50ae82f65 Reviewed-by: Gabriel de Dietrich --- src/gui/kernel/qapplication_mac.mm | 41 ++++++++++++++++++++++++++++++++------ src/gui/mac/macresources.qrc | 5 +++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index 5a256ff..e50e7b5 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -226,6 +226,40 @@ extern void qt_mac_update_cursor(); // qcursor_mac.mm void onApplicationWindowChangedActivation( QWidget*widget, bool activated ); void onApplicationChangedActivation( bool activated ); +void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader) +{ + // Create qt_menu.nib dir in temp. + QDir temp = QDir::temp(); + temp.mkdir("qt_menu.nib"); + QString nibDir = temp.canonicalPath() + QLatin1String("/") + QLatin1String("qt_menu.nib/"); + if (!QDir(nibDir).exists()) { + qWarning("qt_mac_loadMenuNib: could not create nib directory in temp"); + return; + } + + // Copy nib files from resources to temp. + QDir nibResource(":/trolltech/mac/qt_menu.nib/"); + if (!nibResource.exists()) { + qWarning("qt_mac_loadMenuNib: could not load nib from resources"); + return; + } + foreach (const QFileInfo &file, nibResource.entryInfoList()) + QFile::copy(file.absoluteFilePath(), nibDir + QLatin1String("/") + file.fileName()); + + // Load and instantiate nib file from temp + NSURL *nibUrl = [NSURL fileURLWithPath : reinterpret_cast(QCFString::toCFStringRef(nibDir))]; + NSNib *nib = [[NSNib alloc] initWithContentsOfURL : nibUrl]; + [nib autorelease]; + if (!nib) { + qWarning("qt_mac_loadMenuNib: could not load nib from temp"); + return; + } + bool ok = [nib instantiateNibWithOwner : qtMenuLoader topLevelObjects : nil]; + if (!ok) + qWarning("qt_mac_loadMenuNib: could not instantiate nib"); +} + + static void qt_mac_read_fontsmoothing_settings() { qt_applefontsmoothing_enabled = true; @@ -1258,15 +1292,10 @@ void qt_init(QApplicationPrivate *priv, int) [cocoaApp setDelegate:newDelegate]; QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init]; - if ([NSBundle loadNibNamed:@"qt_menu" owner:qtMenuLoader] == false) { - qFatal("Qt internal error: qt_menu.nib could not be loaded. The .nib file" - " should be placed in QtGui.framework/Versions/Current/Resources/ " - " or in the resources directory of your application bundle."); - } + qt_mac_loadMenuNib(qtMenuLoader); [cocoaApp setMenu:[qtMenuLoader menu]]; [newDelegate setMenuLoader:qtMenuLoader]; - [qtMenuLoader release]; } #endif // Register for Carbon tablet proximity events on the event monitor target. diff --git a/src/gui/mac/macresources.qrc b/src/gui/mac/macresources.qrc index 9696002..de50d39 100644 --- a/src/gui/mac/macresources.qrc +++ b/src/gui/mac/macresources.qrc @@ -9,4 +9,9 @@ images/leopard-unified-toolbar-on.png + +qt_menu.nib/classes.nib +qt_menu.nib/info.nib +qt_menu.nib/keyedobjects.nib + -- cgit v0.12