+/*==================================================================
+ !
+ ! mardrone application AR-Drone for MeeGo
+
+ ! Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ ! All rights reserved.
+ !
+ ! Author:Kate Alhola kate.alhola@nokia.com
+ !
+ ! GNU Lesser General Public License Usage
+ ! This file may be used under the terms of the GNU Lesser
+ ! General Public License version 2.1 as published by the Free Software
+ ! Foundation and appearing in the file LICENSE.LGPL included in the
+ ! packaging of this file. Please review the following information to
+ ! ensure the GNU Lesser General Public License version 2.1 requirements
+ ! will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ !
+ !
+ !
+ *===================================================================*/
#include <QtGui/QApplication>
#include "dronecontrol.h"
#include "video.h"
#include "gaugehorizon.h"
+#include "gaugetape.h"
+#include "gaugelabel.h"
+#include "uilistelement.h"
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QtDeclarative>
-#include <QtComponents/qdeclarativewindow.h>
+#include <gaugearc.h>
+#include <gaugehsi.h>
+#include <QSettings>
+#include "joystick.h"
+#include "qdeclarativetoucharea.h"
+#include <QList>
+
+QString selectQmlMain(QStringList inportPaths,QString cmdParam,QString activeUI);
+// MacOSX sdl hack so that SDL won't hijack main
+#undef main
+
+#ifdef QT_IOS
+int Qt_main(int argc, char *argv[])
+#else
int main(int argc, char *argv[])
+#endif
{
qmlRegisterType<DroneControl>("Drone", 1, 0, "DroneControl");
qmlRegisterType<DroneVideo>("Drone", 1, 0, "DroneVideo");
- qmlRegisterType<GaugeHorizon>("Drone", 1, 0, "GaugeHorizon");
+ qmlRegisterType<GaugeTape>("Gauges", 1, 0, "GaugeTape");
+ qmlRegisterType<GaugeLabel>("Gauges", 1, 0, "GaugeLabel");
+ qmlRegisterType<GaugeHorizon>("Gauges", 1, 0, "GaugeHorizon");
+ qmlRegisterType<GaugeArc>("Gauges", 1, 0, "GaugeArc");
+ qmlRegisterType<GaugeHSI>("Gauges", 1, 0, "GaugeHSI");
+ qmlRegisterType<JoyStick>("JoyStick", 1, 0, "JoyStick");
+ qmlRegisterType<QDeclarativeTouchArea>("TouchArea", 1, 0, "TouchArea");
+
QApplication app(argc, argv);
QUrl *url;
+ uiListModel uiList;
+ bool setDefault=false;
- qDebug() << "./ardrone.qml exists " << QFile("ardrone.qml").exists();
- qDebug() << ":/ardrone.qml exists " << QFile(":/ardrone.qml").exists();
+ uiList.addUI(new uiListElement("MeeGo","ardrone_harmattan.qml"));
+ uiList.addUI(new uiListElement("Symbian","ardrone_symbian.qml"));
+ uiList.addUI(new uiListElement("Desktop","ardrone_desktop.qml"));
+ uiList.addUI(new uiListElement("PlainQml","ardrone_plainqml.qml"));
- if(QFile("ardrone.qml").exists()) {
- QDir::setCurrent(app.applicationDirPath());
- url=new QUrl(QUrl::fromLocalFile("ardrone.qml"));
- }
- else {
- QDir::setCurrent(":/");
- url=new QUrl("qrc:/ardrone.qml");
- }
- QDeclarativeWindow window(*url);
- window.window()->show();
+ QSettings *mardroneSettings=new QSettings("katix.org","mardrone");
+#ifdef QT_IOS
+ QString activeUi=mardroneSettings->value("activeUI","ardrone_plainqml.qml").toString();
+#else
+ // QString activeUi=mardroneSettings->value("activeUI","ardrone_harmattan.qml").toString();
+ QString activeUi=mardroneSettings->value("activeUI","ardrone_desktop.qml").toString();
+#endif
+ qDebug() << "activeUI=" << activeUi;
+ QString qmlmainfile=app.arguments().size()>=2 ? app.arguments()[1]:"";
+ if(app.arguments().size()>=3 && qmlmainfile=="set") {
+ qmlmainfile=app.arguments()[2];
+ setDefault=true;
+ };
+
+ QDeclarativeView window;
+ window.rootContext()->setContextProperty("MArdrone",window.window());
+ QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
+ // Check available UI's
+ window.engine()->addImportPath("qrc:/gauges/");
+ window.engine()->addImportPath("qrc:");
+ window.engine()->addImportPath("gauges");
+ window.engine()->addImportPath(".");
+ qDebug() << "ImportPathList" << window.engine()->importPathList() ;
+ QStringList importPath=window.engine()->importPathList();
+ window.rootContext()->setContextProperty("uiList",&uiList);
+ QString qmlFile=selectQmlMain(importPath,qmlmainfile,activeUi);
+ if(setDefault) mardroneSettings->setValue("activeUI",qmlFile);
+#ifndef QT_IOS
+ qmlFile=QString("qrc:/")+qmlFile;
+#endif
+
+ qDebug() << "using:" << qmlFile;
+
+ if(qmlFile.contains("desktop")) { // We have desktop UI
+ QDeclarativeComponent component(window.engine(),QUrl(qmlFile));
+ if(component.isError()) qDebug() << component.errors(); else
+ QObject *myObject = component.create();
+ } else { // We have Mobile UI
+ window.setSource(QUrl(qmlFile));
+ QRect screenGeometry=QApplication::desktop()->screenGeometry();
+ window.setAttribute(Qt::WA_LockLandscapeOrientation, true);
+ if((screenGeometry.height()<=800) && (screenGeometry.width()<=1024)) window.window()->showFullScreen();
+ else window.window()->show();
+ }
return app.exec();
}
+
+QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI)
+{
+ QString importPath=importPaths.last();
+ if(cmdParam.contains(".qml")) return cmdParam;
+ if(cmdParam.isEmpty() && !activeUI.isEmpty()) return activeUI;
+ if(cmdParam=="harmattan" || (cmdParam=="" && QFile(importPath+"/com/nokia/meego").exists())) return QString("ardrone_harmattan.qml");
+ if(cmdParam=="symbian" || (cmdParam=="" && QFile(importPath+"/MeeGo/Components").exists())) return QString("ardrone_symbian.qml");
+ if(cmdParam=="desktop" || (cmdParam=="" && QFile(importPath+"/QtDesktop").exists())) return QString("ardrone_desktop.qml");
+ if(cmdParam=="plain") return QString("ardrone_plainqml.qml");
+ return(activeUI);
+}