tools/qml/main.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    54 
    54 
    55 QT_USE_NAMESPACE
    55 QT_USE_NAMESPACE
    56 
    56 
    57 QtMsgHandler systemMsgOutput = 0;
    57 QtMsgHandler systemMsgOutput = 0;
    58 
    58 
    59 
    59 static QDeclarativeViewer *openFile(const QString &fileName);
       
    60 static void showViewer(QDeclarativeViewer *viewer);
    60 
    61 
    61 #if defined (Q_OS_SYMBIAN)
    62 #if defined (Q_OS_SYMBIAN)
    62 #include <unistd.h>
    63 #include <unistd.h>
    63 #include <sys/types.h>
    64 #include <sys/types.h>
    64 #include <sys/stat.h>
    65 #include <sys/stat.h>
   114         fflush(stderr);
   115         fflush(stderr);
   115     }
   116     }
   116 }
   117 }
   117 
   118 
   118 #endif
   119 #endif
       
   120 
       
   121 static QDeclarativeViewer* globalViewer = 0;
       
   122 
       
   123 // The qml file that is shown if the user didn't specify a QML file
       
   124 QString initialFile = "qrc:/startup/startup.qml";
   119 
   125 
   120 void usage()
   126 void usage()
   121 {
   127 {
   122     qWarning("Usage: qmlviewer [options] <filename>");
   128     qWarning("Usage: qmlviewer [options] <filename>");
   123     qWarning(" ");
   129     qWarning(" ");
   173     exit(1);
   179     exit(1);
   174 }
   180 }
   175 
   181 
   176 enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings };
   182 enum WarningsConfig { ShowWarnings, HideWarnings, DefaultWarnings };
   177 
   183 
   178 int main(int argc, char ** argv)
   184 struct ViewerOptions
   179 {
   185 {
   180 #if defined (Q_OS_SYMBIAN)
   186     ViewerOptions()
   181     qInstallMsgHandler(myMessageOutput);
   187         : frameless(false),
   182 #else
   188           fps(0.0),
   183     systemMsgOutput = qInstallMsgHandler(myMessageOutput);
   189           autorecord_from(0),
   184 #endif
   190           autorecord_to(0),
   185 
   191           dither("none"),
   186 #if defined (Q_OS_WIN)
   192           runScript(false),
   187     // Debugging output is not visible by default on Windows -
   193           devkeys(false),
   188     // therefore show modal dialog with errors instad.
   194           cache(0),
   189     atexit(showWarnings);
   195           useGL(false),
   190 #endif
   196           fullScreen(false),
   191 
   197           stayOnTop(false),
   192 #if defined (Q_WS_X11) || defined (Q_WS_MAC)
   198           maximized(false),
   193     //### default to using raster graphics backend for now
   199           useNativeFileBrowser(true),
   194     bool gsSpecified = false;
   200           experimentalGestures(false),
   195     for (int i = 0; i < argc; ++i) {
   201           warningsConfig(DefaultWarnings),
   196         QString arg = argv[i];
   202           sizeToView(true)
   197         if (arg == "-graphicssystem") {
   203     {
   198             gsSpecified = true;
   204 #if defined(Q_OS_SYMBIAN)
   199             break;
   205         maximized = true;
   200         }
   206         useNativeFileBrowser = false;
   201     }
   207 #endif
   202 
   208 
   203     if (!gsSpecified)
   209 #if defined(Q_WS_MAC)
   204         QApplication::setGraphicsSystem("raster");
   210         useGL = true;
   205 #endif
   211 #endif
   206 
   212     }
   207     QApplication app(argc, argv);
   213 
   208     app.setApplicationName("QtQmlViewer");
   214     bool frameless;
   209     app.setOrganizationName("Nokia");
   215     double fps;
   210     app.setOrganizationDomain("nokia.com");
   216     int autorecord_from;
   211 
   217     int autorecord_to;
   212 
   218     QString dither;
   213     
       
   214     QDeclarativeViewer::registerTypes();
       
   215     QDeclarativeTester::registerTypes();
       
   216 
       
   217     bool frameless = false;
       
   218     QString fileName;
       
   219     double fps = 0;
       
   220     int autorecord_from = 0;
       
   221     int autorecord_to = 0;
       
   222     QString dither = "none";
       
   223     QString recordfile;
   219     QString recordfile;
   224     QStringList recordargs;
   220     QStringList recordargs;
   225     QStringList imports;
   221     QStringList imports;
   226     QStringList plugins;
   222     QStringList plugins;
   227     QString script;
   223     QString script;
   228     QString scriptopts;
   224     QString scriptopts;
   229     bool runScript = false;
   225     bool runScript;
   230     bool devkeys = false;
   226     bool devkeys;
   231     int cache = 0;
   227     int cache;
   232     QString translationFile;
   228     QString translationFile;
   233     bool useGL = false;
   229     bool useGL;
   234     bool fullScreen = false;
   230     bool fullScreen;
   235     bool stayOnTop = false;
   231     bool stayOnTop;
   236     bool maximized = false;
   232     bool maximized;
   237     bool useNativeFileBrowser = true;
   233     bool useNativeFileBrowser;
   238     bool experimentalGestures = false;
   234     bool experimentalGestures;
   239 
   235 
   240     WarningsConfig warningsConfig = DefaultWarnings;
   236     WarningsConfig warningsConfig;
   241     bool sizeToView = true;
   237     bool sizeToView;
   242 
   238 
   243 #if defined(Q_OS_SYMBIAN)
   239     QDeclarativeViewer::ScriptOptions scriptOptions;
   244     maximized = true;
   240 };
   245     useNativeFileBrowser = false;
   241 
   246 #endif
   242 static ViewerOptions opts;
   247 
   243 static QStringList fileNames;
   248 #if defined(Q_WS_MAC)
   244 
   249     useGL = true;
   245 class Application : public QApplication
   250 #endif
   246 {
   251 
   247     Q_OBJECT
   252     for (int i = 1; i < argc; ++i) {
   248 public:
   253         bool lastArg = (i == argc - 1);
   249     Application(int &argc, char **&argv)
   254         QString arg = argv[i];
   250         : QApplication(argc, argv)
       
   251     {}
       
   252 
       
   253 protected:
       
   254     bool event(QEvent *ev)
       
   255     {
       
   256         if (ev->type() != QEvent::FileOpen)
       
   257             return QApplication::event(ev);
       
   258 
       
   259         QFileOpenEvent *fev = static_cast<QFileOpenEvent *>(ev);
       
   260 
       
   261         globalViewer->open(fev->file());
       
   262         if (!globalViewer->isVisible())
       
   263             showViewer(globalViewer);
       
   264 
       
   265         return true;
       
   266     }
       
   267 
       
   268 private Q_SLOTS:
       
   269     void showInitialViewer()
       
   270     {
       
   271         QApplication::processEvents();
       
   272 
       
   273         QDeclarativeViewer *viewer = globalViewer;
       
   274         if (!viewer)
       
   275             return;
       
   276         if (viewer->currentFile().isEmpty()) {
       
   277             if(opts.useNativeFileBrowser)
       
   278                 viewer->open(initialFile);
       
   279             else
       
   280                 viewer->openFile();
       
   281         }
       
   282         if (!viewer->isVisible())
       
   283             showViewer(viewer);
       
   284     }
       
   285 };
       
   286 
       
   287 static void parseScriptOptions()
       
   288 {
       
   289     QStringList options =
       
   290         opts.scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
       
   291 
       
   292     QDeclarativeViewer::ScriptOptions scriptOptions = 0;
       
   293     for (int i = 0; i < options.count(); ++i) {
       
   294         const QString &option = options.at(i);
       
   295         if (option == QLatin1String("help")) {
       
   296             scriptOptsUsage();
       
   297         } else if (option == QLatin1String("play")) {
       
   298             scriptOptions |= QDeclarativeViewer::Play;
       
   299         } else if (option == QLatin1String("record")) {
       
   300             scriptOptions |= QDeclarativeViewer::Record;
       
   301         } else if (option == QLatin1String("testimages")) {
       
   302             scriptOptions |= QDeclarativeViewer::TestImages;
       
   303         } else if (option == QLatin1String("testerror")) {
       
   304             scriptOptions |= QDeclarativeViewer::TestErrorProperty;
       
   305         } else if (option == QLatin1String("exitoncomplete")) {
       
   306             scriptOptions |= QDeclarativeViewer::ExitOnComplete;
       
   307         } else if (option == QLatin1String("exitonfailure")) {
       
   308             scriptOptions |= QDeclarativeViewer::ExitOnFailure;
       
   309         } else if (option == QLatin1String("saveonexit")) {
       
   310             scriptOptions |= QDeclarativeViewer::SaveOnExit;
       
   311         } else if (option == QLatin1String("snapshot")) {
       
   312             scriptOptions |= QDeclarativeViewer::Snapshot;
       
   313         } else {
       
   314             scriptOptsUsage();
       
   315         }
       
   316     }
       
   317 
       
   318     opts.scriptOptions = scriptOptions;
       
   319 }
       
   320 
       
   321 static void parseCommandLineOptions(const QStringList &arguments)
       
   322 {
       
   323     for (int i = 1; i < arguments.count(); ++i) {
       
   324         bool lastArg = (i == arguments.count() - 1);
       
   325         QString arg = arguments.at(i);
   255         if (arg == "-frameless") {
   326         if (arg == "-frameless") {
   256             frameless = true;
   327             opts.frameless = true;
   257         } else if (arg == "-maximized") {
   328         } else if (arg == "-maximized") {
   258             maximized = true;
   329             opts.maximized = true;
   259         } else if (arg == "-fullscreen") {
   330         } else if (arg == "-fullscreen") {
   260             fullScreen = true;
   331             opts.fullScreen = true;
   261         } else if (arg == "-stayontop") {
   332         } else if (arg == "-stayontop") {
   262             stayOnTop = true;
   333             opts.stayOnTop = true;
   263         } else if (arg == "-netcache") {
   334         } else if (arg == "-netcache") {
   264             if (lastArg) usage();
   335             if (lastArg) usage();
   265             cache = QString(argv[++i]).toInt();
   336             opts.cache = arguments.at(++i).toInt();
   266         } else if (arg == "-recordrate") {
   337         } else if (arg == "-recordrate") {
   267             if (lastArg) usage();
   338             if (lastArg) usage();
   268             fps = QString(argv[++i]).toDouble();
   339             opts.fps = arguments.at(++i).toDouble();
   269         } else if (arg == "-recordfile") {
   340         } else if (arg == "-recordfile") {
   270             if (lastArg) usage();
   341             if (lastArg) usage();
   271             recordfile = QString(argv[++i]);
   342             opts.recordfile = arguments.at(++i);
   272         } else if (arg == "-record") {
   343         } else if (arg == "-record") {
   273             if (lastArg) usage();
   344             if (lastArg) usage();
   274             recordargs << QString(argv[++i]);
   345             opts.recordargs << arguments.at(++i);
   275         } else if (arg == "-recorddither") {
   346         } else if (arg == "-recorddither") {
   276             if (lastArg) usage();
   347             if (lastArg) usage();
   277             dither = QString(argv[++i]);
   348             opts.dither = arguments.at(++i);
   278         } else if (arg == "-autorecord") {
   349         } else if (arg == "-autorecord") {
   279             if (lastArg) usage();
   350             if (lastArg) usage();
   280             QString range = QString(argv[++i]);
   351             QString range = arguments.at(++i);
   281             int dash = range.indexOf('-');
   352             int dash = range.indexOf('-');
   282             if (dash > 0)
   353             if (dash > 0)
   283                 autorecord_from = range.left(dash).toInt();
   354                 opts.autorecord_from = range.left(dash).toInt();
   284             autorecord_to = range.mid(dash+1).toInt();
   355             opts.autorecord_to = range.mid(dash+1).toInt();
   285         } else if (arg == "-devicekeys") {
   356         } else if (arg == "-devicekeys") {
   286             devkeys = true;
   357             opts.devkeys = true;
   287         } else if (arg == "-dragthreshold") {
   358         } else if (arg == "-dragthreshold") {
   288             if (lastArg) usage();
   359             if (lastArg) usage();
   289             app.setStartDragDistance(QString(argv[++i]).toInt());
   360             qApp->setStartDragDistance(arguments.at(++i).toInt());
   290         } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) {
   361         } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) {
   291             qWarning("Qt QML Viewer version %s", QT_VERSION_STR);
   362             qWarning("Qt QML Viewer version %s", QT_VERSION_STR);
   292             exit(0);
   363             exit(0);
   293         } else if (arg == "-translation") {
   364         } else if (arg == "-translation") {
   294             if (lastArg) usage();
   365             if (lastArg) usage();
   295             translationFile = argv[++i];
   366             opts.translationFile = arguments.at(++i);
   296         } else if (arg == "-opengl") {
   367         } else if (arg == "-opengl") {
   297             useGL = true;
   368             opts.useGL = true;
   298         } else if (arg == "-qmlbrowser") {
   369         } else if (arg == "-qmlbrowser") {
   299             useNativeFileBrowser = false;
   370             opts.useNativeFileBrowser = false;
   300         } else if (arg == "-warnings") {
   371         } else if (arg == "-warnings") {
   301             if (lastArg) usage();
   372             if (lastArg) usage();
   302             QString warningsStr = QString(argv[++i]);
   373             QString warningsStr = arguments.at(++i);
   303             if (warningsStr == QLatin1String("show")) {
   374             if (warningsStr == QLatin1String("show")) {
   304                 warningsConfig = ShowWarnings;
   375                 opts.warningsConfig = ShowWarnings;
   305             } else if (warningsStr == QLatin1String("hide")) {
   376             } else if (warningsStr == QLatin1String("hide")) {
   306                 warningsConfig = HideWarnings;
   377                 opts.warningsConfig = HideWarnings;
   307             } else {
   378             } else {
   308                 usage();
   379                 usage();
   309             }
   380             }
   310         } else if (arg == "-I" || arg == "-L") {
   381         } else if (arg == "-I" || arg == "-L") {
   311             if (arg == "-L")
   382             if (arg == "-L")
   314                 QDeclarativeEngine tmpEngine;
   385                 QDeclarativeEngine tmpEngine;
   315                 QString paths = tmpEngine.importPathList().join(QLatin1String(":"));
   386                 QString paths = tmpEngine.importPathList().join(QLatin1String(":"));
   316                 qWarning("Current search path: %s", paths.toLocal8Bit().constData());
   387                 qWarning("Current search path: %s", paths.toLocal8Bit().constData());
   317                 exit(0);
   388                 exit(0);
   318             }
   389             }
   319             imports << QString(argv[++i]);
   390             opts.imports << arguments.at(++i);
   320         } else if (arg == "-P") {
   391         } else if (arg == "-P") {
   321             if (lastArg) usage();
   392             if (lastArg) usage();
   322             plugins << QString(argv[++i]);
   393             opts.plugins << arguments.at(++i);
   323         } else if (arg == "-script") {
   394         } else if (arg == "-script") {
   324             if (lastArg) usage();
   395             if (lastArg) usage();
   325             script = QString(argv[++i]);
   396             opts.script = arguments.at(++i);
   326         } else if (arg == "-scriptopts") {
   397         } else if (arg == "-scriptopts") {
   327             if (lastArg) usage();
   398             if (lastArg) usage();
   328             scriptopts = QString(argv[++i]);
   399             opts.scriptopts = arguments.at(++i);
   329         } else if (arg == "-savescript") {
   400         } else if (arg == "-savescript") {
   330             if (lastArg) usage();
   401             if (lastArg) usage();
   331             script = QString(argv[++i]);
   402             opts.script = arguments.at(++i);
   332             runScript = false;
   403             opts.runScript = false;
   333         } else if (arg == "-playscript") {
   404         } else if (arg == "-playscript") {
   334             if (lastArg) usage();
   405             if (lastArg) usage();
   335             script = QString(argv[++i]);
   406             opts.script = arguments.at(++i);
   336             runScript = true;
   407             opts.runScript = true;
   337         } else if (arg == "-sizeviewtorootobject") {
   408         } else if (arg == "-sizeviewtorootobject") {
   338             sizeToView = false;
   409             opts.sizeToView = false;
   339         } else if (arg == "-sizerootobjecttoview") {
   410         } else if (arg == "-sizerootobjecttoview") {
   340             sizeToView = true;
   411             opts.sizeToView = true;
   341         } else if (arg == "-experimentalgestures") {
   412         } else if (arg == "-experimentalgestures") {
   342             experimentalGestures = true;
   413             opts.experimentalGestures = true;
   343         } else if (arg[0] != '-') {
   414         } else if (!arg.startsWith('-')) {
   344             fileName = arg;
   415             fileNames.append(arg);
   345         } else if (1 || arg == "-help") {
   416         } else if (true || arg == "-help") {
   346             usage();
   417             usage();
   347         }
   418         }
   348     }
   419     }
   349 
   420 
   350     QTranslator qmlTranslator;
   421     if (!opts.scriptopts.isEmpty()) {
   351     if (!translationFile.isEmpty()) {
   422 
   352         qmlTranslator.load(translationFile);
   423         parseScriptOptions();
   353         app.installTranslator(&qmlTranslator);
   424 
   354     }
   425         if (opts.script.isEmpty())
   355 
   426             usage();
   356     Qt::WFlags wflags = (frameless ? Qt::FramelessWindowHint : Qt::Widget);
   427 
   357     if (stayOnTop)
   428         if (!(opts.scriptOptions & QDeclarativeViewer::Record) && !(opts.scriptOptions & QDeclarativeViewer::Play))
       
   429             scriptOptsUsage();
       
   430     }  else if (!opts.script.isEmpty()) {
       
   431         usage();
       
   432     }
       
   433 
       
   434 }
       
   435 
       
   436 static QDeclarativeViewer *createViewer()
       
   437 {
       
   438     Qt::WFlags wflags = (opts.frameless ? Qt::FramelessWindowHint : Qt::Widget);
       
   439     if (opts.stayOnTop)
   358         wflags |= Qt::WindowStaysOnTopHint;
   440         wflags |= Qt::WindowStaysOnTopHint;
   359 
   441 
   360     QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
   442     QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags);
   361     viewer->setAttribute(Qt::WA_DeleteOnClose, true);
   443     viewer->setAttribute(Qt::WA_DeleteOnClose, true);
   362     if (!scriptopts.isEmpty()) {
   444     viewer->setUseGL(opts.useGL);
   363         QStringList options =
   445 
   364             scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts);
   446     if (!opts.scriptopts.isEmpty()) {
   365 
   447         viewer->setScriptOptions(opts.scriptOptions);
   366         QDeclarativeViewer::ScriptOptions scriptOptions = 0;
   448         viewer->setScript(opts.script);
   367         for (int i = 0; i < options.count(); ++i) {
       
   368             const QString &option = options.at(i);
       
   369             if (option == QLatin1String("help")) {
       
   370                 scriptOptsUsage();
       
   371             } else if (option == QLatin1String("play")) {
       
   372                 scriptOptions |= QDeclarativeViewer::Play;
       
   373             } else if (option == QLatin1String("record")) {
       
   374                 scriptOptions |= QDeclarativeViewer::Record;
       
   375             } else if (option == QLatin1String("testimages")) {
       
   376                 scriptOptions |= QDeclarativeViewer::TestImages;
       
   377             } else if (option == QLatin1String("testerror")) {
       
   378                 scriptOptions |= QDeclarativeViewer::TestErrorProperty;
       
   379             } else if (option == QLatin1String("exitoncomplete")) {
       
   380                 scriptOptions |= QDeclarativeViewer::ExitOnComplete;
       
   381             } else if (option == QLatin1String("exitonfailure")) {
       
   382                 scriptOptions |= QDeclarativeViewer::ExitOnFailure;
       
   383             } else if (option == QLatin1String("saveonexit")) {
       
   384                 scriptOptions |= QDeclarativeViewer::SaveOnExit;
       
   385             } else if (option == QLatin1String("snapshot")) {
       
   386                 scriptOptions |= QDeclarativeViewer::Snapshot;
       
   387             } else {
       
   388                 scriptOptsUsage();
       
   389             }
       
   390         }
       
   391 
       
   392         if (script.isEmpty())
       
   393             usage();
       
   394 
       
   395         if (!(scriptOptions & QDeclarativeViewer::Record) && !(scriptOptions & QDeclarativeViewer::Play))
       
   396             scriptOptsUsage();
       
   397         viewer->setScriptOptions(scriptOptions);
       
   398         viewer->setScript(script);
       
   399     }  else if (!script.isEmpty()) {
       
   400         usage();
       
   401     }
   449     }
   402 
   450 
   403 #if !defined(Q_OS_SYMBIAN)
   451 #if !defined(Q_OS_SYMBIAN)
   404     logger = viewer->warningsWidget();
   452     logger = viewer->warningsWidget();
   405     if (warningsConfig == ShowWarnings) {
   453     if (opts.warningsConfig == ShowWarnings) {
   406         logger.data()->setDefaultVisibility(LoggerWidget::ShowWarnings);
   454         logger.data()->setDefaultVisibility(LoggerWidget::ShowWarnings);
   407         logger.data()->show();
   455         logger.data()->show();
   408     } else if (warningsConfig == HideWarnings){
   456     } else if (opts.warningsConfig == HideWarnings){
   409         logger.data()->setDefaultVisibility(LoggerWidget::HideWarnings);
   457         logger.data()->setDefaultVisibility(LoggerWidget::HideWarnings);
   410     }
   458     }
   411 #endif
   459 #endif
   412 
   460 
   413     if (experimentalGestures)
   461     if (opts.experimentalGestures)
   414         viewer->enableExperimentalGestures();
   462         viewer->enableExperimentalGestures();
   415 
   463 
   416     foreach (QString lib, imports)
   464     foreach (QString lib, opts.imports)
   417         viewer->addLibraryPath(lib);
   465         viewer->addLibraryPath(lib);
   418 
   466 
   419     foreach (QString plugin, plugins)
   467     foreach (QString plugin, opts.plugins)
   420         viewer->addPluginPath(plugin);
   468         viewer->addPluginPath(plugin);
   421 
   469 
   422     viewer->setNetworkCacheSize(cache);
   470     viewer->setNetworkCacheSize(opts.cache);
   423     viewer->setRecordFile(recordfile);
   471     viewer->setRecordFile(opts.recordfile);
   424     viewer->setSizeToView(sizeToView);
   472     viewer->setSizeToView(opts.sizeToView);
   425     if (fps>0)
   473     if (opts.fps > 0)
   426         viewer->setRecordRate(fps);
   474         viewer->setRecordRate(opts.fps);
   427     if (autorecord_to)
   475     if (opts.autorecord_to)
   428         viewer->setAutoRecord(autorecord_from,autorecord_to);
   476         viewer->setAutoRecord(opts.autorecord_from, opts.autorecord_to);
   429     if (devkeys)
   477     if (opts.devkeys)
   430         viewer->setDeviceKeys(true);
   478         viewer->setDeviceKeys(true);
   431     viewer->setRecordDither(dither);
   479     viewer->setRecordDither(opts.dither);
   432     if (recordargs.count())
   480     if (opts.recordargs.count())
   433         viewer->setRecordArgs(recordargs);
   481         viewer->setRecordArgs(opts.recordargs);
   434 
   482 
   435     viewer->setUseNativeFileBrowser(useNativeFileBrowser);
   483     viewer->setUseNativeFileBrowser(opts.useNativeFileBrowser);
   436     if (fullScreen && maximized)
   484 
       
   485     return viewer;
       
   486 }
       
   487 
       
   488 void showViewer(QDeclarativeViewer *viewer)
       
   489 {
       
   490     if (opts.fullScreen)
       
   491         viewer->showFullScreen();
       
   492     else if (opts.maximized)
       
   493         viewer->showMaximized();
       
   494     else
       
   495         viewer->show();
       
   496     viewer->raise();
       
   497 }
       
   498 
       
   499 QDeclarativeViewer *openFile(const QString &fileName)
       
   500 {
       
   501     QDeclarativeViewer *viewer = globalViewer;
       
   502 
       
   503     viewer->open(fileName);
       
   504     showViewer(viewer);
       
   505 
       
   506     return viewer;
       
   507 }
       
   508 
       
   509 int main(int argc, char ** argv)
       
   510 {
       
   511 #if defined (Q_OS_SYMBIAN)
       
   512     qInstallMsgHandler(myMessageOutput);
       
   513 #else
       
   514     systemMsgOutput = qInstallMsgHandler(myMessageOutput);
       
   515 #endif
       
   516 
       
   517 #if defined (Q_OS_WIN)
       
   518     // Debugging output is not visible by default on Windows -
       
   519     // therefore show modal dialog with errors instad.
       
   520     atexit(showWarnings);
       
   521 #endif
       
   522 
       
   523 #if defined (Q_WS_X11) || defined (Q_WS_MAC)
       
   524     //### default to using raster graphics backend for now
       
   525     bool gsSpecified = false;
       
   526     for (int i = 0; i < argc; ++i) {
       
   527         QString arg = argv[i];
       
   528         if (arg == "-graphicssystem") {
       
   529             gsSpecified = true;
       
   530             break;
       
   531         }
       
   532     }
       
   533 
       
   534     if (!gsSpecified)
       
   535         QApplication::setGraphicsSystem("raster");
       
   536 #endif
       
   537 
       
   538     Application app(argc, argv);
       
   539     app.setApplicationName("QtQmlViewer");
       
   540     app.setOrganizationName("Nokia");
       
   541     app.setOrganizationDomain("nokia.com");
       
   542 
       
   543     QDeclarativeViewer::registerTypes();
       
   544     QDeclarativeTester::registerTypes();
       
   545 
       
   546     parseCommandLineOptions(app.arguments());
       
   547 
       
   548     QTranslator qmlTranslator;
       
   549     if (!opts.translationFile.isEmpty()) {
       
   550         qmlTranslator.load(opts.translationFile);
       
   551         app.installTranslator(&qmlTranslator);
       
   552     }
       
   553 
       
   554     if (opts.fullScreen && opts.maximized)
   437         qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen.";
   555         qWarning() << "Both -fullscreen and -maximized specified. Using -fullscreen.";
   438 
   556 
   439     if (fileName.isEmpty()) {
   557     if (fileNames.isEmpty()) {
   440         QFile qmlapp(QLatin1String("qmlapp"));
   558         QFile qmlapp(QLatin1String("qmlapp"));
   441         if (qmlapp.exists() && qmlapp.open(QFile::ReadOnly)) {
   559         if (qmlapp.exists() && qmlapp.open(QFile::ReadOnly)) {
   442                 QString content = QString::fromUtf8(qmlapp.readAll());
   560             QString content = QString::fromUtf8(qmlapp.readAll());
   443                 qmlapp.close();
   561             qmlapp.close();
   444 
   562 
   445                 int newline = content.indexOf(QLatin1Char('\n'));
   563             int newline = content.indexOf(QLatin1Char('\n'));
   446                 if (newline >= 0)
   564             if (newline >= 0)
   447                     fileName = content.left(newline);
   565                 fileNames += content.left(newline);
   448                 else
   566             else
   449                     fileName = content;
   567                 fileNames += content;
   450             }
   568         }
   451     }
   569     }
   452 
   570 
   453     if (!fileName.isEmpty()) {
   571     globalViewer = createViewer();
   454         viewer->open(fileName);
   572 
   455         fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
   573     if (fileNames.isEmpty()) {
       
   574         // show the initial viewer delayed.
       
   575         // This prevents an initial viewer popping up while there
       
   576         // are FileOpen events coming through the event queue
       
   577         QTimer::singleShot(1, &app, SLOT(showInitialViewer()));
   456     } else {
   578     } else {
   457         if (!useNativeFileBrowser)
   579         foreach (const QString &fileName, fileNames)
   458             viewer->openFile();
   580             openFile(fileName);
   459         fullScreen ? viewer->showFullScreen() : maximized ? viewer->showMaximized() : viewer->show();
   581     }
   460         if (useNativeFileBrowser)
   582 
   461             viewer->openFile();
   583     QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
   462     }
       
   463     viewer->setUseGL(useGL);
       
   464     viewer->raise();
       
   465 
   584 
   466     return app.exec();
   585     return app.exec();
   467 }
   586 }
       
   587 
       
   588 #include "main.moc"