Bug 693422 - Unify QApplication creation. r=tatiana

--HG--
rename : widget/src/qt/mozqwidget.h => widget/src/qt/moziqwidget.h
extra : rebase_source : b9dc6d5d2c2826aad68a145413886f518ab388fa
This commit is contained in:
Oleg Romashin 2011-10-17 17:53:37 -07:00
parent da61ec4e86
commit 54132854c7
3 changed files with 60 additions and 35 deletions

View File

@ -50,13 +50,9 @@
#if defined(MOZ_WIDGET_QT) #if defined(MOZ_WIDGET_QT)
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtCore/QScopedPointer> #include "nsQAppInstance.h"
#include <QtGui/QInputContextFactory> #include <QtGui/QInputContextFactory>
#include <QtGui/QInputContext> #include <QtGui/QInputContext>
#ifdef MOZ_ENABLE_MEEGOTOUCH
#include <MComponentData>
#include <MozMeegoAppService.h>
#endif // MOZ_ENABLE_MEEGOTOUCH
#endif // MOZ_WIDGET_QT #endif // MOZ_WIDGET_QT
#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentParent.h"
@ -3022,31 +3018,21 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#endif #endif
#if defined(MOZ_WIDGET_QT) #if defined(MOZ_WIDGET_QT)
const char* qgraphicssystemARG = NULL; nsQAppInstance::AddRef(gArgc, gArgv, true);
ar = CheckArg("graphicssystem", true, &qgraphicssystemARG, false);
if (ar == ARG_FOUND)
PR_SetEnv(PR_smprintf("MOZ_QT_GRAPHICSSYSTEM=%s", qgraphicssystemARG));
QScopedPointer<QApplication> app(new QApplication(gArgc, gArgv));
#ifdef MOZ_ENABLE_MEEGOTOUCH
gArgv[gArgc] = strdup("-software");
gArgc++;
QScopedPointer<MComponentData> meegotouch(new MComponentData(gArgc, gArgv,"", new MApplicationService("")));
#endif
#if MOZ_PLATFORM_MAEMO > 5 #if MOZ_PLATFORM_MAEMO > 5
if (XRE_GetProcessType() == GeckoProcessType_Default) { if (XRE_GetProcessType() == GeckoProcessType_Default) {
// try to get the MInputContext if possible to support the MeeGo VKB // try to get the MInputContext if possible to support the MeeGo VKB
QInputContext* inputContext = app->inputContext(); QInputContext* inputContext = qApp->inputContext();
if (inputContext && inputContext->identifierName() != "MInputContext") { if (inputContext && inputContext->identifierName() != "MInputContext") {
QInputContext* context = QInputContextFactory::create("MInputContext", QInputContext* context = QInputContextFactory::create("MInputContext",
app.data()); qApp);
if (context) if (context)
app->setInputContext(context); qApp->setInputContext(context);
} }
} }
#endif #endif
QStringList nonQtArguments = app->arguments(); QStringList nonQtArguments = qApp->arguments();
gQtOnlyArgc = 1; gQtOnlyArgc = 1;
gQtOnlyArgv = (char**) malloc(sizeof(char*) gQtOnlyArgv = (char**) malloc(sizeof(char*)
* (gRestartArgc - nonQtArguments.size() + 2)); * (gRestartArgc - nonQtArguments.size() + 2));
@ -3618,6 +3604,10 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
// has gone out of scope. see bug #386739 for more details // has gone out of scope. see bug #386739 for more details
profileLock->Unlock(); profileLock->Unlock();
#if defined(MOZ_WIDGET_QT)
nsQAppInstance::Release();
#endif
// Restart the app after XPCOM has been shut down cleanly. // Restart the app after XPCOM has been shut down cleanly.
if (appInitiatedRestart) { if (appInitiatedRestart) {
RestoreStateForAppInitiatedRestart(); RestoreStateForAppInitiatedRestart();

View File

@ -38,35 +38,63 @@
#include "nsQAppInstance.h" #include "nsQAppInstance.h"
#include <QApplication> #include <QApplication>
#ifdef MOZ_ENABLE_MEEGOTOUCH
#include <MComponentData>
#include <MApplicationService>
#endif
#include "prenv.h" #include "prenv.h"
#include <stdlib.h>
// declared in nsAppRunner.cpp
extern int gArgc;
extern char **gArgv;
QApplication *nsQAppInstance::sQAppInstance = NULL; QApplication *nsQAppInstance::sQAppInstance = NULL;
#ifdef MOZ_ENABLE_MEEGOTOUCH
MComponentData* nsQAppInstance::sMComponentData = NULL;
#endif
int nsQAppInstance::sQAppRefCount = 0; int nsQAppInstance::sQAppRefCount = 0;
void nsQAppInstance::AddRef(void) { void nsQAppInstance::AddRef(int& aArgc, char** aArgv, bool aDefaultProcess) {
if (qApp) return; if (qApp)
return;
if (!sQAppInstance) { if (!sQAppInstance) {
const char *graphicsSystem = PR_GetEnv("MOZ_QT_GRAPHICSSYSTEM"); const char *graphicsSystem = getenv("MOZ_QT_GRAPHICSSYSTEM");
if (graphicsSystem) if (graphicsSystem) {
QApplication::setGraphicsSystem(QString(graphicsSystem)); QApplication::setGraphicsSystem(QString(graphicsSystem));
}
#if (MOZ_PLATFORM_MAEMO == 6) #if (MOZ_PLATFORM_MAEMO == 6)
// Should create simple windows style for non chrome process
// otherwise meegotouch style initialize and crash happen
// because we don't initialize MComponent for child process
if (!aDefaultProcess) {
QApplication::setStyle(QLatin1String("windows")); QApplication::setStyle(QLatin1String("windows"));
if (!gArgc) { }
gArgv[gArgc] = strdup("nsQAppInstance"); if (!aArgc) {
gArgc++; aArgv[aArgc] = strdup("nsQAppInstance");
aArgc++;
}
#endif
sQAppInstance = new QApplication(aArgc, aArgv);
#ifdef MOZ_ENABLE_MEEGOTOUCH
if (aDefaultProcess) {
// GLContext created by meegotouch will be under meego graphics
// system control, and will drop GL context automatically in background mode
// In order to use that GLContext we need to implement
// LayerManager switch in runtime from SW<->HW
// That not yet implemented so we need to control GL context,
// force software mode for, and create our own QGLWidget
gArgv[gArgc] = strdup("-software");
gArgc++;
sMComponentData = new MComponentData(aArgc, aArgv, "", new MApplicationService(""));
} }
#endif #endif
sQAppInstance = new QApplication(gArgc, gArgv);
} }
sQAppRefCount++; sQAppRefCount++;
} }
void nsQAppInstance::Release(void) { void nsQAppInstance::Release(void) {
if (sQAppInstance && !--sQAppRefCount) { if (sQAppInstance && !--sQAppRefCount) {
#ifdef MOZ_ENABLE_MEEGOTOUCH
delete sMComponentData;
sMComponentData = NULL;
#endif
delete sQAppInstance; delete sQAppInstance;
sQAppInstance = NULL; sQAppInstance = NULL;
} }

View File

@ -39,16 +39,23 @@
#ifndef nsQAppInstance_h #ifndef nsQAppInstance_h
#define nsQAppInstance_h #define nsQAppInstance_h
#include <QApplication> // declared in nsAppRunner.cpp
extern int gArgc;
extern char **gArgv;
class QApplication;
class MComponentData;
class nsQAppInstance class nsQAppInstance
{ {
public: public:
static void AddRef(void); static void AddRef(int& aArgc = gArgc,
char** aArgv = gArgv,
bool aDefaultProcess = false);
static void Release(void); static void Release(void);
private: private:
static QApplication *sQAppInstance; static QApplication *sQAppInstance;
static MComponentData* sMComponentData;
static int sQAppRefCount; static int sQAppRefCount;
}; };