summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2011-01-11 10:48:38 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2011-01-11 14:22:53 (GMT)
commita601a45f7fbff6df2b39990d0e1dbd00542b9819 (patch)
tree4ccef6d0bc78b9ed03209f99e873e5ba37209351 /src/corelib/kernel/qcoreapplication.cpp
parentb58eb0419f9f724af5d9baf8bbce4e0f1e2f3f8b (diff)
downloadQt-a601a45f7fbff6df2b39990d0e1dbd00542b9819.zip
Qt-a601a45f7fbff6df2b39990d0e1dbd00542b9819.tar.gz
Qt-a601a45f7fbff6df2b39990d0e1dbd00542b9819.tar.bz2
Allow use of command line parameters with RApaLsSession::StartApp.
When a Symbian application is launched using RApaLsSession::StartApp, command line parameters can be given with CApaCommandLine::SetTailEndL and will now be correctly interpreted by Qt applications as command line parameters. There are a couple of limitations: 1) The parameters given with CApaCommandLine::SetTailEndL will not be available in main method's argv array; they can be accessed via QCoreApplication::arguments function. 2) CApaCommandLine::SetTailEndL does support any arbitrary binary data as parameter, but only 8-bit string data gets parsed properly into QCoreApplication::arguments. For other kind of tail data, you need to subclass QS60MainAppUi and implement ProcessCommandParametersL callback. Task-number: QTBUG-15987 Reviewed-by: axis
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index b445a50..381be34 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -71,6 +71,7 @@
# include <e32ldr.h>
# include "qeventdispatcher_symbian_p.h"
# include "private/qcore_symbian_p.h"
+# include <apacmdln.h>
#elif defined(Q_OS_UNIX)
# if !defined(QT_NO_GLIB)
# include "qeventdispatcher_glib_p.h"
@@ -115,7 +116,58 @@ private:
#ifdef Q_OS_SYMBIAN
typedef TDriveNumber (*SystemDriveFunc)(RFs&);
-static SystemDriveFunc PtrGetSystemDrive=0;
+static SystemDriveFunc PtrGetSystemDrive = 0;
+static CApaCommandLine* apaCommandLine = 0;
+static char *apaTail = 0;
+static QVector<char *> *apaArgv = 0;
+
+static void qt_cleanup_apa_cmd_line()
+{
+ delete apaCommandLine;
+ apaCommandLine = 0;
+ delete apaArgv;
+ apaArgv = 0;
+ delete apaTail;
+ apaTail = 0;
+}
+
+static inline void qt_init_symbian_apa_arguments(int &argc, char **&argv)
+{
+ // If app is launched via CApaCommandLine::StartApp(), normal arguments only contain
+ // application name.
+ if (argc == 1) {
+ CApaCommandLine* commandLine = QCoreApplicationPrivate::symbianCommandLine();
+ if(commandLine) {
+ TPtrC8 apaCmdLine = commandLine->TailEnd();
+ int tailLen = apaCmdLine.Length();
+ if (tailLen) {
+ apaTail = reinterpret_cast<char *>(qMalloc(tailLen + 1));
+ qMemCopy(apaTail, reinterpret_cast<const char *>(apaCmdLine.Ptr()), tailLen);
+ apaTail[tailLen] = '\0';
+ apaArgv = new QVector<char *>(8);
+ // Reuse windows command line parsing
+ *apaArgv = qWinCmdLine<char>(apaTail, tailLen, argc);
+ apaArgv->insert(0, argv[0]);
+ argc++;
+ argv = apaArgv->data();
+ }
+ }
+ }
+}
+
+CApaCommandLine* QCoreApplicationPrivate::symbianCommandLine()
+{
+ // Getting of Apa command line needs to be static as it can only be called successfully
+ // once per process.
+ if (!apaCommandLine) {
+ TInt err = CApaCommandLine::GetCommandLineFromProcessEnvironment(apaCommandLine);
+ if (err == KErrNone) {
+ qAddPostRoutine(qt_cleanup_apa_cmd_line);
+ }
+ }
+ return apaCommandLine;
+}
+
#endif
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
@@ -274,6 +326,10 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv)
}
QCoreApplicationPrivate::is_app_closing = false;
+#ifdef Q_OS_SYMBIAN
+ qt_init_symbian_apa_arguments(argc, argv);
+#endif
+
#ifdef Q_OS_UNIX
qt_application_thread_id = QThread::currentThreadId();
#endif
@@ -2056,6 +2112,12 @@ char **QCoreApplication::argv()
As a result of this, the string given by arguments().at(0) might not be
the program name on Windows, depending on how the application was started.
+ For Symbian applications started with \c RApaLsSession::StartApp one can specify
+ arguments using \c CApaCommandLine::SetTailEndL function. Such arguments are only
+ available via this method; they will not be passed to \c main function. Also note
+ that only 8-bit string data set with \c CApaCommandLine::SetTailEndL is supported
+ by this function.
+
\sa applicationFilePath()
*/