diff options
author | Andy Shaw <andy.shaw@digia.com> | 2013-07-07 20:23:07 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-08 17:40:26 (GMT) |
commit | 7b7c321d5f35b6ee70db5a72d5d37e19e125d7cf (patch) | |
tree | 5179429387fb9aae22e33401bb2fc57c86615f2d /src/gui | |
parent | b12e459ea17f083b01ad0676ee552b96aff14b59 (diff) | |
download | Qt-7b7c321d5f35b6ee70db5a72d5d37e19e125d7cf.zip Qt-7b7c321d5f35b6ee70db5a72d5d37e19e125d7cf.tar.gz Qt-7b7c321d5f35b6ee70db5a72d5d37e19e125d7cf.tar.bz2 |
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 <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 41 | ||||
-rw-r--r-- | 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<const NSString *>(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 @@ <qresource prefix="/trolltech/mac/style"> <file>images/leopard-unified-toolbar-on.png</file> </qresource> +<qresource prefix="/trolltech/mac/"> +<file>qt_menu.nib/classes.nib</file> +<file>qt_menu.nib/info.nib</file> +<file>qt_menu.nib/keyedobjects.nib</file> +</qresource> </RCC> |