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 "uilistelement.h"
28 #include <QDeclarativeView>
29 #include <QDeclarativeContext>
30 #include <QDeclarativeEngine>
31 #include <QtDeclarative>
36 #include "qdeclarativetoucharea.h"
39 QString selectQmlMain(QStringList inportPaths,QString cmdParam,QString activeUI);
41 // MacOSX sdl hack so that SDL won't hijack main
45 int Qt_main(int argc, char *argv[])
47 int main(int argc, char *argv[])
50 qmlRegisterType<DroneControl>("Drone", 1, 0, "DroneControl");
51 qmlRegisterType<DroneVideo>("Drone", 1, 0, "DroneVideo");
52 qmlRegisterType<GaugeTape>("Gauges", 1, 0, "GaugeTape");
53 qmlRegisterType<GaugeLabel>("Gauges", 1, 0, "GaugeLabel");
54 qmlRegisterType<GaugeHorizon>("Gauges", 1, 0, "GaugeHorizon");
55 qmlRegisterType<GaugeArc>("Gauges", 1, 0, "GaugeArc");
56 qmlRegisterType<GaugeHSI>("Gauges", 1, 0, "GaugeHSI");
57 qmlRegisterType<JoyStick>("JoyStick", 1, 0, "JoyStick");
58 qmlRegisterType<QDeclarativeTouchArea>("TouchArea", 1, 0, "TouchArea");
60 QApplication app(argc, argv);
63 bool setDefault=false;
65 uiList.addUI(new uiListElement("MeeGo","ardrone_harmattan.qml"));
66 uiList.addUI(new uiListElement("Symbian","ardrone_symbian.qml"));
67 uiList.addUI(new uiListElement("Desktop","ardrone_desktop.qml"));
68 uiList.addUI(new uiListElement("PlainQml","ardrone_plainqml.qml"));
71 QSettings *mardroneSettings=new QSettings("katix.org","mardrone");
73 QString activeUi=mardroneSettings->value("activeUI","ardrone_plainqml.qml").toString();
75 // QString activeUi=mardroneSettings->value("activeUI","ardrone_harmattan.qml").toString();
76 QString activeUi=mardroneSettings->value("activeUI","ardrone_desktop.qml").toString();
78 qDebug() << "activeUI=" << activeUi;
79 QString qmlmainfile=app.arguments().size()>=2 ? app.arguments()[1]:"";
80 if(app.arguments().size()>=3 && qmlmainfile=="set") {
81 qmlmainfile=app.arguments()[2];
85 QDeclarativeView window;
86 window.rootContext()->setContextProperty("MArdrone",window.window());
87 QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
88 // Check available UI's
89 window.engine()->addImportPath("qrc:/gauges/");
90 window.engine()->addImportPath("qrc:");
91 window.engine()->addImportPath("gauges");
92 window.engine()->addImportPath(".");
93 qDebug() << "ImportPathList" << window.engine()->importPathList() ;
94 QStringList importPath=window.engine()->importPathList();
95 window.rootContext()->setContextProperty("uiList",&uiList);
96 QString qmlFile=selectQmlMain(importPath,qmlmainfile,activeUi);
97 if(setDefault) mardroneSettings->setValue("activeUI",qmlFile);
99 qmlFile=QString("qrc:/")+qmlFile;
102 qDebug() << "using:" << qmlFile;
104 if(qmlFile.contains("desktop")) { // We have desktop UI
105 QDeclarativeComponent component(window.engine(),QUrl(qmlFile));
106 if(component.isError()) qDebug() << component.errors(); else
107 QObject *myObject = component.create();
108 } else { // We have Mobile UI
109 window.setSource(QUrl(qmlFile));
110 QRect screenGeometry=QApplication::desktop()->screenGeometry();
111 window.setAttribute(Qt::WA_LockLandscapeOrientation, true);
112 if((screenGeometry.height()<=800) && (screenGeometry.width()<=1024)) window.window()->showFullScreen();
113 else window.window()->show();
118 QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI)
120 QString importPath=importPaths.last();
121 if(cmdParam.contains(".qml")) return cmdParam;
122 if(cmdParam.isEmpty() && !activeUI.isEmpty()) return activeUI;
123 if(cmdParam=="harmattan" || (cmdParam=="" && QFile(importPath+"/com/nokia/meego").exists())) return QString("ardrone_harmattan.qml");
124 if(cmdParam=="symbian" || (cmdParam=="" && QFile(importPath+"/MeeGo/Components").exists())) return QString("ardrone_symbian.qml");
125 if(cmdParam=="desktop" || (cmdParam=="" && QFile(importPath+"/QtDesktop").exists())) return QString("ardrone_desktop.qml");
126 if(cmdParam=="plain") return QString("ardrone_plainqml.qml");