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 #include "qmlappviewer.h"
41 QString selectQmlMain(QStringList inportPaths,QString cmdParam,QString activeUI,uiListModel &uiList);
46 // MacOSX sdl hack so that SDL won't hijack main
50 int Qt_main(int argc, char *argv[])
52 int main(int argc, char *argv[])
55 qmlRegisterType<DroneControl>("Drone", 1, 0, "DroneControl");
56 qmlRegisterType<DroneVideo>("Drone", 1, 0, "DroneVideo");
57 qmlRegisterType<GaugeTape>("Gauges", 1, 0, "GaugeTape");
58 qmlRegisterType<GaugeLabel>("Gauges", 1, 0, "GaugeLabel");
59 qmlRegisterType<GaugeHorizon>("Gauges", 1, 0, "GaugeHorizon");
60 qmlRegisterType<GaugeArc>("Gauges", 1, 0, "GaugeArc");
61 qmlRegisterType<GaugeHSI>("Gauges", 1, 0, "GaugeHSI");
62 qmlRegisterType<JoyStick>("JoyStick", 1, 0, "JoyStick");
63 qmlRegisterType<QDeclarativeTouchArea>("TouchArea", 1, 0, "TouchArea");
65 QApplication app(argc, argv);
68 bool setDefault=false;
70 QSettings *mardroneSettings=new QSettings("katix.org","mardrone");
72 QString activeUi=mardroneSettings->value("activeUI","ardrone_plainqml.qml").toString();
74 QString activeUi=mardroneSettings->value("activeUI","ardrone_harmattan.qml").toString();
75 // QString activeUi=mardroneSettings->value("activeUI","ardrone_desktop.qml").toString();
77 qDebug() << "activeUI=" << activeUi;
78 QString qmlmainfile=app.arguments().size()>=2 ? app.arguments()[1]:"";
79 if(app.arguments().size()>=3 && qmlmainfile=="set") {
80 qmlmainfile=app.arguments()[2];
84 // QDeclarativeView window;
86 window.rootContext()->setContextProperty("MArdrone",window.window());
87 QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
89 // Check available UI's
90 window.engine()->addImportPath(":/gauges/");
91 window.engine()->addImportPath("qrc:");
92 window.engine()->addImportPath(":");
93 window.engine()->addImportPath("gauges");
94 window.engine()->addImportPath(".");
96 window.engine()->addImportPath("/");
97 window.engine()->addImportPath("/imports");
98 window.engine()->addImportPath("/assets");
99 window.engine()->addPluginPath(QDir::homePath()+"/../lib");
101 qDebug() << "ImportPathList" << window.engine()->importPathList() ;
102 QStringList importPath=window.engine()->importPathList();
103 window.rootContext()->setContextProperty("uiList",&uiList);
104 QString qmlFile=selectQmlMain(importPath,qmlmainfile,activeUi,uiList);
105 if(setDefault) mardroneSettings->setValue("activeUI",qmlFile);
107 qmlFile=QString("qrc:/")+qmlFile;
110 qDebug() << "using:" << qmlFile;
112 if(qmlFile.contains("desktop")) { // We have desktop UI
113 QDeclarativeComponent component(window.engine(),QUrl(qmlFile));
114 if(component.isError()) qDebug() << component.errors(); else
115 QObject *myObject = component.create();
116 } else { // We have Mobile UI
117 window.setSource(QUrl(qmlFile));
118 QRect screenGeometry=QApplication::desktop()->screenGeometry();
119 window.setAttribute(Qt::WA_LockLandscapeOrientation, true);
120 if((screenGeometry.height()<=800) && (screenGeometry.width()<=1024)) window.window()->showFullScreen();
121 else window.window()->show();
123 QObject::connect(&window, SIGNAL(backKey()), window.rootObject(), SLOT(backKey()));
127 QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI,uiListModel &uiList)
129 bool haveHarmattan=FALSE;
130 bool haveSymbian=FALSE;
131 bool haveDesktop=FALSE;
132 bool haveAndroid=FALSE;
133 QStringList appQmlFilesFilter;
135 appQmlFilesFilter << "ardrone*.qml";
136 QStringList appQmlFiles;
137 qDebug() << "selectQmlMain importPath=" << importPaths << " ActiveUi=" << activeUI;
138 if(cmdParam.contains(".qml")) return cmdParam;
139 if(cmdParam=="plain") activeUI="ardrone_plainqml.qml";
140 if(cmdParam=="harmattan") activeUI="ardrone_harmattan.qml";
141 if(cmdParam=="symbian") activeUI="ardrone_symbian.qml";
142 if(cmdParam=="desktop") activeUI="ardrone_desktop.qml";
143 // Scan supported components
144 for(int i=0;i<importPaths.size();i++) {
145 QString importPath=importPaths[i];
146 QDir searchDir(importPath);
147 QStringList qmlFiles=searchDir.entryList();
148 qDebug() << importPath << qmlFiles;
149 haveHarmattan|=QFile(importPath+"/com/nokia/meego/qmldir").exists();
150 haveSymbian|=QFile(importPath+"/com/nokia/symbian.1.1/qmldir").exists();
151 haveAndroid|=QFile(importPath+"/com/nokia/android.1.1/qmldir").exists();
152 haveDesktop|=QFile(importPath+"/QtDesktop/qmldir").exists();
153 qDebug() << importPath << haveHarmattan << haveSymbian << haveDesktop << haveAndroid ;
155 // Scan UI .qml files
156 for(int i=0;i<importPaths.size();i++) {
157 QString importPath=importPaths[i];
158 QDir searchDir(importPath);
159 QStringList qmlFiles=searchDir.entryList(appQmlFilesFilter);
160 qDebug() << qmlFiles;
161 appQmlFiles+=qmlFiles;
162 for(int j=0;j<qmlFiles.size();j++) {
163 if((qmlFiles[j].contains("harmattan") && haveHarmattan)||
164 (qmlFiles[j].contains("symbian") && haveSymbian) ||
165 (qmlFiles[j].contains("android") && haveAndroid) ||
166 (qmlFiles[j].contains("desktop") && haveDesktop) ||
167 (qmlFiles[j].contains("plainqml")))
169 QFile qmlFile(importPath+"/"+qmlFiles[j]);
170 if(qmlFile.open(QFile::ReadOnly))
172 QString firstLine=QString(qmlFile.readLine(100));
173 if(firstLine.contains("// uiName:")) { uiName=firstLine.remove(0,10); }
174 else uiName=qmlFiles[j];
175 if(uiName.endsWith("\n")) uiName.chop(1);
176 qDebug() << importPath+"/"+qmlFiles[j] << uiName;
177 uiList.addUI(new uiListElement(uiName,qmlFiles[j]));
182 // Check validity of activeUi
184 for(int j=0;j<uiList.count();j++) validUi|=(((uiListElement*)uiList.get(j))->file())==activeUI;
185 if(!validUi) activeUI=((uiListElement*)uiList.get(0))->file();