Sends table contents from memory.
~CarMainWindow();
Registration *myRegistration; //Check if this should be public or private
LoginWindow *myLogin;
+ GPSData *gpsData;
void setComboBoxStartTabUnits(QStringList units); //Start-tab view
void setListViewStartTabAccelerationCategories(QStringList numbers); //Start-tab view
CategoryList *myCategorylist;
HttpClient *myHttpClient;
RouteDialog *myRoute;
- GPSData *gpsData;
Maemo5Location *location;
//void initCategoryCompoBox();
void initComboBoxStartTabUnits(); //Start-tab view
/**
*Append an item in the end of the categorylist.
+ *@param Item.
*/
void CategoryList::appendCategoryList(QString item)
{
/**
*Input an item into the categorylist.
+ *@param Index.
+ *@param Item to be appended.
*/
void CategoryList::fillCategoryList(int index, QString item)
{
/**
*Show an item of the categorylist.
+ *@param Index.
*/
QString CategoryList::itemOfCategoryList(int index)
{
void CategoryList::clearCategoryList()
{
categoryList.clear();
- qDebug() << "_clearCategoryList" ;
}
/**
}
/**
- *This function is used to get items to top list of current category.
+ *Append an item in the end of the categoryelementable.
+ *@param Index.
+ *@param Description of category.
+ *@param Unit.
+ *@param Category.
+ */
+void CategoryList::appendCats(int ind, QString des, QString uni, QString cat)
+{
+ cats[ind].description = des;
+ cats[ind].unit = uni;
+ cats[ind].category = cat;
+}
+
+/**
+ *Clear categs.
+ */
+QString CategoryList::desOfCats(int ind)
+{
+ return cats[ind].description;
+}
+
+/**
+ *Clear cats.
+ */
+void CategoryList::clearCats()
+{
+ for(int i = 0; i < 10; i++)
+ {
+ cats[i].description.clear();
+ cats[i].unit.clear();
+ cats[i].category.clear();
+ }
+}
+
+/**
+ *This function is used to get items to top list of the category that is chosen from combobox.
*@param QString category
*@param int size
*/
* Categorylist
*
* @author Olavi Pulkkinen <olavi.pulkkinena@fudeco.com>
+ * @author Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
* @copyright (c) 2010 Speed Freak team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
QString getTopList( QString category, int size);
void clearCategoryList();
int sizeOfCategoryList();
+ void appendCats(int ind, QString des, QString uni, QString cat);
+ void clearCats();
+ QString desOfCats(int i);
private:
- QStringList categoryList;
+ QStringList categoryList; //Stores categories. categoryList is routed to UI.
+ typedef struct {
+ QString category; //name of category variable
+ QString description; //verbal description of category
+ QString unit; //km/h, miles/h
+ } categoryElements;
+ categoryElements cats[10];
};
route << "Stop: " << routeStopTime << "\n";
file.close();
}
+
+double* GPSData::getGpsDataArray()
+{
+ return *gpsDataArray;
+}
+
+int GPSData::getRoundCounter()
+{
+ return roundCounter;
+}
void startRouteRecording(QString time);
void stopRouteRecording(QString time);
int roundCounter; //testing, move private!!!
+ double *getGpsDataArray();
+ int getRoundCounter();
private:
Maemo5Location *location;
/**
*@brief Sends result(s) to the server in xml format.
*Send authentication information in the header.
- *@todo Read category elsewhere.
*/
void HttpClient::sendResultXml(QString category)
{
}
/**
+ *@brief Sends route to the server in xml format.
+ *Send authentication information in the header.
+ *@todo Check destination URL.
+ */
+void HttpClient::sendRouteXml()
+{
+ qDebug() << "_sendResultXml";
+
+ QBuffer *xmlbuffer = new QBuffer();
+
+ QUrl qurl("http://api.speedfreak-app.com/api/update/route");
+ qDebug() << qurl.toString();
+ QNetworkRequest request(qurl);
+ QNetworkReply *currentDownload;
+
+ xmlbuffer->open(QBuffer::ReadWrite);
+ myXmlwriter->writeGpsTrack(xmlbuffer, myMainw->gpsData->getGpsDataArray(), myMainw->gpsData->getRoundCounter());
+ qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
+
+ QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
+ credentials = "Basic " + credentials.toAscii().toBase64();
+ request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+
+ currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
+ connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
+ //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+
+ xmlbuffer->close();
+}
+
+/**
*@brief Request the Top10List of certain category from the server.
*Send authentication information in the header.
*@param Category of results.
qDebug() << "errorcode:" << errorcode << reply->errorString();
QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll());
}
-
}
+/**
+ *@brief React to servers responce after result has been sent.
+ *@todo Implement consequencies of reply.
+ */
+void HttpClient::ackOfRoute()
+{
+ qDebug() << "_ackOfRoute";
+
+ QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
+ QNetworkReply::NetworkError errorcode;
+ errorcode = reply->error();
+ if(errorcode != 0) {
+ qDebug() << "errorcode:" << errorcode << reply->errorString();
+ QMessageBox::about(myMainw, "Server reply to route sending ",reply->errorString());
+ }
+ else {
+ qDebug() << "errorcode:" << errorcode << reply->errorString();
+ QMessageBox::about(myMainw, "Server reply to route sending", "Route received " + reply->readAll());
+ }
+}
/**
*@brief React to servers responce after registration has been sent.
void requestRegistration();
void checkLogin();
void sendResultXml(QString category);
+ void sendRouteXml();
void requestTopList(QString category, QString limit);
void requestCategories();
void ackOfResult();
+ void ackOfRoute();
void ackOfRegistration();
void ackOfCategories();
void ackOfToplist();
if(myCategoryList->sizeOfCategoryList() != 0) {
myCategoryList->clearCategoryList();
}
- //qDebug() << "sizeOfCategoryList(): " << myCategoryList->sizeOfCategoryList();
+ myCategoryList->clearCats();
//Go trough the xml document
while(!xmlreader.atEnd())
if(xmlreader.name() == "category")
{
qDebug() << xmlreader.name();
- myCategoryList->appendCategoryList(xmlreader.readElementText());
- qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i);
+ attr = xmlreader.attributes();
+ description = attr.value("description").toString();
+ unit = attr.value("unit").toString();
+ category = xmlreader.readElementText();
+ myCategoryList->appendCategoryList(category);
+ myCategoryList->appendCats(i, description, unit, category);
+ //qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i);
+ //qDebug() << "description: " << description << "unit: " << unit << "category: " << category;
i++;
receivedFlag = 1;
}
QString position;
QString user;
QString value;
+ QString description;
signals:
void receivedCategoryList();
XmlWriter::XmlWriter()
{
tmpvalue = 110;
- trackInd = 0;
}
/**
/**
*@brief Write track to server.
- *@param Starting index of gps results table.
- *@param Ending index of gps results table.
- *@todo Connect to real values.
- *@todo Decide suitable parameters.
+ *@param ptrTable points to GPSData::gpsDataArray[100][4].
+ *@param counter is GPSData::roundCounter.
+ *@todo Decide suitable attributes.
*/
-void XmlWriter::writeGpsTrack(int startInd, int stopInd)
+void XmlWriter::writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter)
{
qDebug() << "_writeGpsTrack";
- analyzeGpsData();
- int i = 0;
+ double *ptrValue;
+ ptrValue = ptrTable;
+ double tmp = 0;
+
+ xmlwriter.setDevice(netbuf);
+
+ xmlwriter.writeStartDocument();
xmlwriter.writeStartElement("gpx");
xmlwriter.writeAttribute("someattribute", "abc");
xmlwriter.writeCharacters("Example Track");
xmlwriter.writeEndElement();
xmlwriter.writeStartElement("trkseg");
- for(i = startInd; i < (stopInd - startInd); i++) {
+ for(int i = 0; i < counter; i++)
+ {
xmlwriter.writeStartElement("trkpt");
- xmlwriter.writeAttribute("lat", QString::number(trackTable[i].latitude));
- xmlwriter.writeAttribute("lon", QString::number(trackTable[i].longitude));
+ tmp = *ptrValue;
+ ptrValue++;
+ xmlwriter.writeAttribute("lat", QString::number(tmp)); //gpspoints[i][0]
+ tmp = *ptrValue;
+ ptrValue++;
+ xmlwriter.writeAttribute("lon", QString::number(tmp)); //gpspoints[i][1]
xmlwriter.writeStartElement("ele");
- xmlwriter.writeCharacters(QString::number(trackTable[i].altitude));
- xmlwriter.writeEndElement();
- xmlwriter.writeStartElement("time");
- xmlwriter.writeCharacters(QString::number(trackTable[i].time));
+ tmp = *ptrValue;
+ ptrValue++;
+ xmlwriter.writeCharacters(QString::number(tmp)); //gpspoints[i][2]
xmlwriter.writeEndElement();
xmlwriter.writeStartElement("speed");
- xmlwriter.writeCharacters(QString::number(trackTable[i].speed));
- xmlwriter.writeEndElement();
- xmlwriter.writeStartElement("track");
- xmlwriter.writeCharacters(QString::number(trackTable[i].track));
+ tmp = *ptrValue;
+ ptrValue++;
+ xmlwriter.writeCharacters(QString::number(tmp)); //gpspoints[i][3]
xmlwriter.writeEndElement();
xmlwriter.writeEndElement(); //trkpt
}
- xmlwriter.writeEndElement(); //trkseg
- xmlwriter.writeEndElement(); //trk
- xmlwriter.writeEndElement(); //gpx
+ xmlwriter.writeEndElement(); //trkseg
+ xmlwriter.writeEndElement(); //trk
+ xmlwriter.writeEndElement(); //gpx
+ xmlwriter.writeEndDocument();
}
xmlwriter.setDevice(device);
xmlwriter.writeStartDocument();
//writeItems();
- //serverWritesXml();
- writeGpsTrack(0, 16);
+ serverWritesXml();
xmlwriter.writeEndDocument();
return true;
*/
void XmlWriter::serverWritesXml()
{
- /* Server sends to client */
- /*
- int i = 0;
- int n = 5;
-
- //Write top 10 Results
- xmlwriter.writeStartElement("results");
- xmlwriter.writeAttribute("category", "acceleration-0-40");
- xmlwriter.writeAttribute("unit", "seconds");
- xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
-
- for (i = 0; i < n; i++) {
- xmlwriter.writeStartElement("result");
- xmlwriter.writeAttribute("position", QString::number(i));
- xmlwriter.writeAttribute("user", "test123");
- xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
- xmlwriter.writeAttribute("value", QString::number(i+i+1));
- xmlwriter.writeEndElement();
- }
- */
//Write categories
xmlwriter.writeStartElement("categories");
xmlwriter.writeEndElement();
}
-
-
-/**
- *@brief A temp function during development, used to create data for drawing route and for server.
- */
-void XmlWriter::analyzeGpsData()
-{
- qDebug() << "_analyzeGpsData";
-
- double startTime;
- int tableSize = 0;
-
- qDebug() << "sizeof(analyzeTable)" << sizeof(analyzeTable);
- tableSize = 16;
-
- for(int i = 1; i < tableSize; i++)
- {
- //example of one feature whose consequent values are compared and saved if they differentiate too much
- if(analyzeTable[i].speed < (analyzeTable[i-1].speed - 1) ||
- analyzeTable[i].speed > (analyzeTable[i-1].speed + 1) )
- {
- trackTable[trackInd] = analyzeTable[i];
- trackInd++;
- qDebug() << "trackTable[trackInd].speed" << trackTable[trackInd].speed;
- }
- }
-}
-
-void XmlWriter::initPointTable(gpsPoint *table, int count, double add1, int add2, int add3)
-{
- qDebug() << "_initPointTable";
-
- int i = 1;
- int j = 0;
-
- table[0].latitude = 67.00;
- table[0].longitude = 27.50;
- table[0].altitude = 7.00;
- table[0].speed = 0;
- table[0].time = 0;
-
- for(j = 0; j < count; j++)
- {
- table[i].latitude = table[i-1].latitude + add1;
- //table[i].longitude = table[i-1].longitude + add1;
- table[i].altitude = table[i-1].altitude + add1;
- table[i].speed = table[i-1].speed + add2;
- table[i].track = table[i-1].track + 1;
- table[i].time = table[i-1].time + add3;
- i++;
- }
- for(j = 0; j < count; j++)
- {
- //table[i].latitude = table[i-1].latitude + add1;
- table[i].longitude = table[i-1].longitude + add1;
- table[i].altitude = table[i-1].altitude -add1;
- table[i].speed = table[i-1].speed + add2;
- table[i].track = table[i-1].track + 1;
- table[i].time = table[i-1].time + add3;
- i++;
- }
- for(j = 0; j < count; j++)
- {
- table[i].latitude = table[i-1].latitude - add1;
- //table[i].longitude = table[i-1].longitude + add1;
- table[i].altitude = table[i-1].altitude + add1;
- table[i].speed = table[i-1].speed - add2;
- table[i].track = table[i-1].track - 1;
- table[i].time = table[i-1].time + add3;
- i++;
- }
- for(j = 0; j < count; j++)
- {
- //table[i].latitude = table[i-1].latitude + add1;
- table[i].longitude = table[i-1].longitude - add1;
- table[i].altitude = table[i-1].altitude - add1;
- table[i].speed = table[i-1].speed - add2;
- table[i].track = table[i-1].track - 1;
- table[i].time = table[i-1].time + add3;
- i++;
- }
-}
-
-
XmlWriter();
~XmlWriter();
int tmpvalue;
- typedef struct {
- double time;
- double latitude;
- double longitude;
- double altitude;
- double speed;
- double track;
- } gpsPoint;
- gpsPoint trackTable[100];
- gpsPoint analyzeTable[100];
int trackInd;
private:
public slots:
void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
void writeResult(QBuffer *netbuf);
+ void writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter);
bool writeXmlFile(QIODevice *device);
//void writeXml(QString usr, QString psswd, QString email);
void writeXml();
void writeItems();
void serverWritesXml();
- void writeGpsTrack(int startInd, int stopInd);
- void initPointTable(gpsPoint *table, int count, double add1, int add2, int add3);
- void analyzeGpsData();
};
#endif // XMLWRITER_H