Skip to content

Commit

Permalink
Fix Mac static builds so they get the qt_menu.nib from the resource file
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andy Shaw authored and The Qt Project committed Jul 8, 2013
1 parent b12e459 commit 7b7c321
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/gui/kernel/qapplication_mac.mm
Expand Up @@ -226,6 +226,40 @@
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;
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/gui/mac/macresources.qrc
Expand Up @@ -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>

0 comments on commit 7b7c321

Please sign in to comment.