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,uiListModel &uiList,QStringList &uiNames,QStringList &uiFiles);
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;
64 QStringList uiNames,uiFiles;
66 QSettings *mardroneSettings=new QSettings("katix.org","mardrone");
68 QString activeUi=mardroneSettings->value("activeUI","ardrone_plainqml.qml").toString();
70 QString activeUi=mardroneSettings->value("activeUI","ardrone_harmattan.qml").toString();
71 // QString activeUi=mardroneSettings->value("activeUI","ardrone_desktop.qml").toString();
73 qDebug() << "activeUI=" << activeUi;
74 QString qmlmainfile=app.arguments().size()>=2 ? app.arguments()[1]:"";
75 if(app.arguments().size()>=3 && qmlmainfile=="set") {
76 qmlmainfile=app.arguments()[2];
80 QDeclarativeView window;
81 window.rootContext()->setContextProperty("MArdrone",window.window());
82 QObject::connect((QObject*)window.engine(), SIGNAL(quit()), &app, SLOT(quit()));
83 // Check available UI's
84 window.engine()->addImportPath("qrc:/gauges/");
85 window.engine()->addImportPath("qrc:");
86 window.engine()->addImportPath(":");
87 window.engine()->addImportPath("gauges");
88 window.engine()->addImportPath(".");
90 window.engine()->addImportPath("/imports/");
91 window.engine()->addPluginPath(QDir::homePath()+"/../lib");
93 qDebug() << "ImportPathList" << window.engine()->importPathList() ;
94 QStringList importPath=window.engine()->importPathList();
95 window.rootContext()->setContextProperty("uiList",&uiList);
96 window.rootContext()->setContextProperty("uiNames",uiNames);
97 window.rootContext()->setContextProperty("uiFiles",uiFiles);
98 QString qmlFile=selectQmlMain(importPath,qmlmainfile,activeUi,uiList,uiNames,uiFiles);
99 if(setDefault) mardroneSettings->setValue("activeUI",qmlFile);
101 qmlFile=QString("qrc:/")+qmlFile;
104 qDebug() << "using:" << qmlFile;
106 if(qmlFile.contains("desktop")) { // We have desktop UI
107 QDeclarativeComponent component(window.engine(),QUrl(qmlFile));
108 if(component.isError()) qDebug() << component.errors(); else
109 QObject *myObject = component.create();
110 } else { // We have Mobile UI
111 window.setSource(QUrl(qmlFile));
112 QRect screenGeometry=QApplication::desktop()->screenGeometry();
113 window.setAttribute(Qt::WA_LockLandscapeOrientation, true);
114 if((screenGeometry.height()<=800) && (screenGeometry.width()<=1024)) window.window()->showFullScreen();
115 else window.window()->show();
120 QString selectQmlMain(QStringList importPaths,QString cmdParam,QString activeUI,uiListModel &uiList,QStringList &uiNames,QStringList &uiFiles)
122 bool haveHarmattan=FALSE;
123 bool haveSymbian=FALSE;
124 bool haveDesktop=FALSE;
125 QStringList appQmlFilesFilter;
127 appQmlFilesFilter << "ardrone*.qml";
128 QStringList appQmlFiles;
129 qDebug() << "selectQmlMain importPath=" << importPaths << " ActiveUi=" << activeUI;
130 if(cmdParam.contains(".qml")) return cmdParam;
131 if(cmdParam=="plain") activeUI="ardrone_plainqml.qml";
132 if(cmdParam=="harmattan") activeUI="ardrone_harmattan.qml";
133 if(cmdParam=="symbian") activeUI="ardrone_symbian.qml";
134 if(cmdParam=="desktop") activeUI="ardrone_desktop.qml";
135 // Scan supported components
136 for(int i=0;i<importPaths.size();i++) {
137 QString importPath=importPaths[i];
138 haveHarmattan|=QFile(importPath+"/com/nokia/meego").exists();
139 haveSymbian|=QFile(importPath+"/com/nokia/symbian.1.1").exists();
140 haveDesktop|=QFile(importPath+"/QtDesktop").exists();
141 qDebug() << importPath << haveHarmattan << haveSymbian << haveDesktop;
143 // Scan UI .qml files
144 for(int i=0;i<importPaths.size();i++) {
145 QString importPath=importPaths[i];
146 QDir searchDir(importPath);
147 QStringList qmlFiles=searchDir.entryList(appQmlFilesFilter);
148 qDebug() << qmlFiles;
149 appQmlFiles+=qmlFiles;
150 for(int j=0;j<qmlFiles.size();j++) {
151 if((qmlFiles[j].contains("harmattan") && haveHarmattan)||
152 (qmlFiles[j].contains("symbian") && haveSymbian) ||
153 (qmlFiles[j].contains("desktop") && haveDesktop) ||
154 (qmlFiles[j].contains("plainqml")))
156 QFile qmlFile(importPath+"/"+qmlFiles[j]);
157 if(qmlFile.open(QFile::ReadOnly))
159 QString firstLine=QString(qmlFile.readLine(100));
160 if(firstLine.contains("// uiName:")) { uiName=firstLine.remove(0,10); }
161 else uiName=qmlFiles[j];
162 if(uiName.endsWith("\n")) uiName.chop(1);
163 qDebug() << importPath+"/"+qmlFiles[j] << uiName;
164 uiList.addUI(new uiListElement(uiName,qmlFiles[j]));
169 // Check validity of activeUi
171 for(int j=0;j<uiList.count();j++) validUi|=(((uiListElement*)uiList.get(j))->file())==activeUI;
172 if(!validUi) activeUI=((uiListElement*)uiList.get(0))->file();