Blackberry: Populating the QCoreApplicationData
authorFabian Bumberger <fbumberger@rim.com>
Tue, 9 Oct 2012 17:34:29 +0000 (19:34 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Sat, 13 Oct 2012 03:51:19 +0000 (05:51 +0200)
Change-Id: I7adb2e207cab89fbad9458cd0bcb856ecd2288f0
Reviewed-by: Peter Hartmann <phartmann@rim.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
src/corelib/kernel/qcoreapplication.cpp

index fd423d4..1e4a6f4 100644 (file)
@@ -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;
 }