#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>
+#include <QObject>
+#include "qmlappviewer.h"
+QString selectQmlMain(QStringList inportPaths,QString cmdParam,QString activeUI,uiListModel &uiList);
+
+
+
+
+// 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();
+ 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;
+ };
- 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();
+ // QDeclarativeView window;
+ QmlAppViewer window;
+ window.rootContext()->setContextProperty("MArdrone",window.window());
+ QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
+ // Check available UI's
+ window.engine()->addImportPath(":/gauges/");
+ window.engine()->addImportPath("qrc:");
+ window.engine()->addImportPath(":");
+ window.engine()->addImportPath("gauges");
+ window.engine()->addImportPath(".");
+#ifdef Q_OS_ANDROID
+ window.engine()->addImportPath("/");
+ window.engine()->addImportPath("/imports");
+ window.engine()->addImportPath("/assets");
+ window.engine()->addPluginPath(QDir::homePath()+"/../lib");
+#endif
+ qDebug() << "ImportPathList" << window.engine()->importPathList() ;
+ QStringList importPath=window.engine()->importPathList();
+ window.rootContext()->setContextProperty("uiList",&uiList);
+ QString qmlFile=selectQmlMain(importPath,qmlmainfile,activeUi,uiList);
+ 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();
+ }
+ QObject::connect(&window, SIGNAL(backKey()), window.rootObject(), SLOT(backKey()));
return app.exec();
}
+
+QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI,uiListModel &uiList)
+{
+ bool haveHarmattan=FALSE;
+ bool haveSymbian=FALSE;
+ bool haveDesktop=FALSE;
+ bool haveAndroid=FALSE;
+ QStringList appQmlFilesFilter;
+ QString uiName;
+ appQmlFilesFilter << "ardrone*.qml";
+ QStringList appQmlFiles;
+ qDebug() << "selectQmlMain importPath=" << importPaths << " ActiveUi=" << activeUI;
+ if(cmdParam.contains(".qml")) return cmdParam;
+ if(cmdParam=="plain") activeUI="ardrone_plainqml.qml";
+ if(cmdParam=="harmattan") activeUI="ardrone_harmattan.qml";
+ if(cmdParam=="symbian") activeUI="ardrone_symbian.qml";
+ if(cmdParam=="desktop") activeUI="ardrone_desktop.qml";
+ // Scan supported components
+ for(int i=0;i<importPaths.size();i++) {
+ QString importPath=importPaths[i];
+ QDir searchDir(importPath);
+ QStringList qmlFiles=searchDir.entryList();
+ qDebug() << importPath << qmlFiles;
+ haveHarmattan|=QFile(importPath+"/com/nokia/meego/qmldir").exists();
+ haveSymbian|=QFile(importPath+"/com/nokia/symbian.1.1/qmldir").exists();
+ haveAndroid|=QFile(importPath+"/com/nokia/android.1.1/qmldir").exists();
+ haveDesktop|=QFile(importPath+"/QtDesktop/qmldir").exists();
+ qDebug() << importPath << haveHarmattan << haveSymbian << haveDesktop << haveAndroid ;
+ }
+ // Scan UI .qml files
+ for(int i=0;i<importPaths.size();i++) {
+ QString importPath=importPaths[i];
+ QDir searchDir(importPath);
+ QStringList qmlFiles=searchDir.entryList(appQmlFilesFilter);
+ qDebug() << qmlFiles;
+ appQmlFiles+=qmlFiles;
+ for(int j=0;j<qmlFiles.size();j++) {
+ if((qmlFiles[j].contains("harmattan") && haveHarmattan)||
+ (qmlFiles[j].contains("symbian") && haveSymbian) ||
+ (qmlFiles[j].contains("android") && haveAndroid) ||
+ (qmlFiles[j].contains("desktop") && haveDesktop) ||
+ (qmlFiles[j].contains("plainqml")))
+ {
+ QFile qmlFile(importPath+"/"+qmlFiles[j]);
+ if(qmlFile.open(QFile::ReadOnly))
+ {
+ QString firstLine=QString(qmlFile.readLine(100));
+ if(firstLine.contains("// uiName:")) { uiName=firstLine.remove(0,10); }
+ else uiName=qmlFiles[j];
+ if(uiName.endsWith("\n")) uiName.chop(1);
+ qDebug() << importPath+"/"+qmlFiles[j] << uiName;
+ uiList.addUI(new uiListElement(uiName,qmlFiles[j]));
+ }
+ }
+ }
+ }
+ // Check validity of activeUi
+ bool validUi=false;
+ for(int j=0;j<uiList.count();j++) validUi|=(((uiListElement*)uiList.get(j))->file())==activeUI;
+ if(!validUi) activeUI=((uiListElement*)uiList.get(0))->file();
+ return(activeUI);
+}
+