From 49f277482e86d21edf9a055229100486aaf8b4c0 Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Tue, 9 Oct 2012 19:34:29 +0200 Subject: [PATCH] Blackberry: Populating the QCoreApplicationData Change-Id: I7adb2e207cab89fbad9458cd0bcb856ecd2288f0 Reviewed-by: Peter Hartmann Reviewed-by: Giuseppe D'Angelo --- src/corelib/kernel/qcoreapplication.cpp | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index fd423d4..1e4a6f4 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -264,6 +264,35 @@ struct QCoreApplicationData { data->deref(); // deletes the data and the adopted thread } } + +#ifdef Q_OS_BLACKBERRY + //The QCoreApplicationData struct is only populated on demand, because it is rarely needed and would + //affect startup time + void loadManifest() { + static bool manifestLoadAttempt = false; + if (manifestLoadAttempt) + return; + + manifestLoadAttempt = true; + + QFile metafile(QStringLiteral("app/META-INF/MANIFEST.MF")); + if (!metafile.open(QIODevice::ReadOnly)) { + qWarning() << Q_FUNC_INFO << "Could not open application metafile for reading"; + } else { + while (!metafile.atEnd() && (application.isEmpty() || applicationVersion.isEmpty() || orgName.isEmpty())) { + QByteArray line = metafile.readLine(); + if (line.startsWith("Application-Name:")) + application = QString::fromUtf8(line.mid(18).trimmed()); + else if (line.startsWith("Application-Version:")) + applicationVersion = QString::fromUtf8(line.mid(21).trimmed()); + else if (line.startsWith("Package-Author:")) + orgName = QString::fromUtf8(line.mid(16).trimmed()); + } + metafile.close(); + } + } +#endif + QString orgName, orgDomain, application; QString applicationVersion; @@ -1765,6 +1794,15 @@ QString QCoreApplication::applicationFilePath() #if defined(Q_OS_WIN) d->cachedApplicationFilePath = QFileInfo(qAppFileName()).filePath(); return d->cachedApplicationFilePath; +#elif defined(Q_OS_BLACKBERRY) + QDir dir(QStringLiteral("./app/native/")); + QStringList executables = dir.entryList(QDir::Executable | QDir::Files); + if (!executables.empty()) { + //We assume that there is only one executable in the folder + return dir.absoluteFilePath(executables.first()); + } else { + return QString(); + } #elif defined(Q_OS_MAC) QString qAppFileName_str = qAppFileName(); if(!qAppFileName_str.isEmpty()) { @@ -1930,6 +1968,9 @@ void QCoreApplication::setOrganizationName(const QString &orgName) QString QCoreApplication::organizationName() { +#ifdef Q_OS_BLACKBERRY + coreappdata()->loadManifest(); +#endif return coreappdata()->orgName; } @@ -1977,6 +2018,9 @@ void QCoreApplication::setApplicationName(const QString &application) QString QCoreApplication::applicationName() { +#ifdef Q_OS_BLACKBERRY + coreappdata()->loadManifest(); +#endif QString appname = coreappdata() ? coreappdata()->application : QString(); if (appname.isEmpty() && QCoreApplication::self) appname = QCoreApplication::self->d_func()->appName(); @@ -2003,6 +2047,9 @@ void QCoreApplication::setApplicationVersion(const QString &version) QString QCoreApplication::applicationVersion() { +#ifdef Q_OS_BLACKBERRY + coreappdata()->loadManifest(); +#endif return coreappdata()->applicationVersion; } -- 2.7.4