Clean up QLibraryInfoPrivate::findConfiguration()

The QFile::exists() check in the end was redundant if one of the
!QFile::exists() had returned false before. By always doing the
positive check we can get rid of it and also avoid excessive
nesting.

Also, on OSX the isEmpty() clause probably never evaluated
to true, with the effect that qt.conf in an applicationDirPath was
never found.

Change-Id: I750735741b707d3e98c4bf6c6b9558618e1fcc59
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Ulf Hermann 2015-03-10 13:31:57 +01:00
parent 8eaddf8343
commit aad3c08902

View File

@ -158,35 +158,35 @@ void QLibrarySettings::load()
QSettings *QLibraryInfoPrivate::findConfiguration()
{
QString qtconfig = QStringLiteral(":/qt/etc/qt.conf");
if (QFile::exists(qtconfig))
return new QSettings(qtconfig, QSettings::IniFormat);
#ifdef QT_BUILD_QMAKE
if(!QFile::exists(qtconfig))
qtconfig = qmake_libraryInfoFile();
qtconfig = qmake_libraryInfoFile();
if (QFile::exists(qtconfig))
return new QSettings(qtconfig, QSettings::IniFormat);
#else
if (!QFile::exists(qtconfig)) {
#ifdef Q_OS_MAC
CFBundleRef bundleRef = CFBundleGetMainBundle();
if (bundleRef) {
QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef,
QCFString(QLatin1String("qt.conf")),
0,
0);
if (urlRef) {
QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
qtconfig = QDir::cleanPath(path);
}
}
if (qtconfig.isEmpty())
#endif
{
if (QCoreApplication::instance()) {
QDir pwd(QCoreApplication::applicationDirPath());
qtconfig = pwd.filePath(QLatin1String("qt.conf"));
}
CFBundleRef bundleRef = CFBundleGetMainBundle();
if (bundleRef) {
QCFType<CFURLRef> urlRef = CFBundleCopyResourceURL(bundleRef,
QCFString(QLatin1String("qt.conf")),
0,
0);
if (urlRef) {
QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
qtconfig = QDir::cleanPath(path);
if (QFile::exists(qtconfig))
return new QSettings(qtconfig, QSettings::IniFormat);
}
}
#endif
if (QFile::exists(qtconfig))
return new QSettings(qtconfig, QSettings::IniFormat);
if (QCoreApplication::instance()) {
QDir pwd(QCoreApplication::applicationDirPath());
qtconfig = pwd.filePath(QLatin1String("qt.conf"));
if (QFile::exists(qtconfig))
return new QSettings(qtconfig, QSettings::IniFormat);
}
#endif
return 0; //no luck
}