1 /*==================================================================
3 ! mardrone application AR-Drone for MeeGo
5 ! Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8 ! Author:Kate Alhola kate.alhola@nokia.com
10 ! GNU Lesser General Public License Usage
11 ! This file may be used under the terms of the GNU Lesser
12 ! General Public License version 2.1 as published by the Free Software
13 ! Foundation and appearing in the file LICENSE.LGPL included in the
14 ! packaging of this file. Please review the following information to
15 ! ensure the GNU Lesser General Public License version 2.1 requirements
16 ! will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
20 *===================================================================*/
21 #include <QtGui/QApplication>
22 #include "dronecontrol.h"
24 #include "gaugehorizon.h"
25 #include "gaugetape.h"
26 #include "gaugelabel.h"
27 #include <QDeclarativeView>
28 #include <QDeclarativeContext>
29 #include <QDeclarativeEngine>
30 #include <QtDeclarative>
33 #include "qdeclarativetoucharea.h"
35 QString selectQmlMain(QStringList inportPaths,QString cmdParam,QString activeUI);
37 // MacOSX sdl hack so that SDL won't hijack main
40 int main(int argc, char *argv[])
42 qmlRegisterType<DroneControl>("Drone", 1, 0, "DroneControl");
43 qmlRegisterType<DroneVideo>("Drone", 1, 0, "DroneVideo");
44 qmlRegisterType<GaugeTape>("Gauges", 1, 0, "GaugeTape");
45 qmlRegisterType<GaugeLabel>("Gauges", 1, 0, "GaugeLabel");
46 qmlRegisterType<GaugeHorizon>("Gauges", 1, 0, "GaugeHorizon");
47 qmlRegisterType<JoyStick>("JoyStick", 1, 0, "JoyStick");
48 qmlRegisterType<QDeclarativeTouchArea>("TouchArea", 1, 0, "TouchArea");
50 QApplication app(argc, argv);
54 QSettings *mardroneSettings=new QSettings("katix.org","mardrone");
55 QString activeUi=mardroneSettings->value("activeUI","ardrone_desktop.qml").toString();
56 qDebug() << "activeUI=" << activeUi;
57 QString qmlmainfile=app.arguments().size()>=2 ? app.arguments()[1]:"";
59 QDeclarativeView window;
60 window.rootContext()->setContextProperty("MArdrone",window.window());
61 QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
62 // Check available UI's
63 window.engine()->addImportPath("qrc:/gauges/");
64 window.engine()->addImportPath("qrc:");
65 window.engine()->addImportPath("gauges");
66 window.engine()->addImportPath(".");
67 qDebug() << "ImportPathList" << window.engine()->importPathList() << window.engine()->importPathList();;
68 QStringList importPath=window.engine()->importPathList();
69 QString qmlFile=QString("qrc:/")+selectQmlMain(importPath,qmlmainfile,activeUi);
70 qDebug() << "using:" << qmlFile;
72 if(qmlFile.contains("desktop")) { // We have desktop UI
73 QDeclarativeComponent component(window.engine(),QUrl(qmlFile));
74 if(component.isError()) qDebug() << component.errors(); else
75 QObject *myObject = component.create();
76 } else { // We have Mobile UI
77 window.setSource(QUrl(qmlFile));
78 QRect screenGeometry=QApplication::desktop()->screenGeometry();
79 window.setAttribute(Qt::WA_LockLandscapeOrientation, true);
80 if((screenGeometry.height()<=800) && (screenGeometry.width()<=1024)) window.window()->showFullScreen();
81 else window.window()->show();
86 QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI)
88 QString importPath=importPaths.last();
89 if(cmdParam.contains(".qml")) return cmdParam;
90 if(cmdParam.isEmpty() && !activeUI.isEmpty()) return activeUI;
91 if(cmdParam=="harmattan" || (cmdParam=="" && QFile(importPath+"/com/nokia/meego").exists())) return QString("ardrone_harmattan.qml");
92 if(cmdParam=="symbian" || (cmdParam=="" && QFile(importPath+"/MeeGo/Components").exists())) return QString("ardrone_symbian.qml");
93 if(cmdParam=="desktop" || (cmdParam=="" && QFile(importPath+"/QtDesktop").exists())) return QString("ardrone_desktop.qml");