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)
#include <QtGui/QApplication>
#include <QtCore/QScopedPointer>
#include "nsQAppInstance.h"
#include <QtGui/QInputContextFactory>
#include <QtGui/QInputContext>
#ifdef MOZ_ENABLE_MEEGOTOUCH
#include <MComponentData>
#include <MozMeegoAppService.h>
#endif // MOZ_ENABLE_MEEGOTOUCH
#endif // MOZ_WIDGET_QT
#include "mozilla/dom/ContentParent.h"
@ -3022,31 +3018,21 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#endif
#if defined(MOZ_WIDGET_QT)
const char* qgraphicssystemARG = NULL;
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
nsQAppInstance::AddRef(gArgc, gArgv, true);
#if MOZ_PLATFORM_MAEMO > 5
if (XRE_GetProcessType() == GeckoProcessType_Default) {
// 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") {
QInputContext* context = QInputContextFactory::create("MInputContext",
app.data());
qApp);
if (context)
app->setInputContext(context);
qApp->setInputContext(context);
}
}
#endif
QStringList nonQtArguments = app->arguments();
QStringList nonQtArguments = qApp->arguments();
gQtOnlyArgc = 1;
gQtOnlyArgv = (char**) malloc(sizeof(char*)
* (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
profileLock->Unlock();
#if defined(MOZ_WIDGET_QT)
nsQAppInstance::Release();
#endif
// Restart the app after XPCOM has been shut down cleanly.
if (appInitiatedRestart) {
RestoreStateForAppInitiatedRestart();

View File

@ -38,35 +38,63 @@
#include "nsQAppInstance.h"
#include <QApplication>
#ifdef MOZ_ENABLE_MEEGOTOUCH
#include <MComponentData>
#include <MApplicationService>
#endif
#include "prenv.h"
// declared in nsAppRunner.cpp
extern int gArgc;
extern char **gArgv;
#include <stdlib.h>
QApplication *nsQAppInstance::sQAppInstance = NULL;
#ifdef MOZ_ENABLE_MEEGOTOUCH
MComponentData* nsQAppInstance::sMComponentData = NULL;
#endif
int nsQAppInstance::sQAppRefCount = 0;
void nsQAppInstance::AddRef(void) {
if (qApp) return;
void nsQAppInstance::AddRef(int& aArgc, char** aArgv, bool aDefaultProcess) {
if (qApp)
return;
if (!sQAppInstance) {
const char *graphicsSystem = PR_GetEnv("MOZ_QT_GRAPHICSSYSTEM");
if (graphicsSystem)
const char *graphicsSystem = getenv("MOZ_QT_GRAPHICSSYSTEM");
if (graphicsSystem) {
QApplication::setGraphicsSystem(QString(graphicsSystem));
}
#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"));
if (!gArgc) {
gArgv[gArgc] = strdup("nsQAppInstance");
gArgc++;
}
if (!aArgc) {
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
sQAppInstance = new QApplication(gArgc, gArgv);
}
sQAppRefCount++;
}
void nsQAppInstance::Release(void) {
if (sQAppInstance && !--sQAppRefCount) {
#ifdef MOZ_ENABLE_MEEGOTOUCH
delete sMComponentData;
sMComponentData = NULL;
#endif
delete sQAppInstance;
sQAppInstance = NULL;
}

View File

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