X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fxmlwriter.cpp;h=7fca219a79dd5bbc7decca0ee0280cfd87940f9b;hp=22dc8d18d47bacaf1ca90d0914121b4340056223;hb=a59cf5da56374b33e497a9f23a8985d74eb73212;hpb=d1703a2e6197257c128add5efc03610074421598 diff --git a/Client/xmlwriter.cpp b/Client/xmlwriter.cpp index 22dc8d1..7fca219 100644 --- a/Client/xmlwriter.cpp +++ b/Client/xmlwriter.cpp @@ -1,13 +1,11 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* + * Xml writer + * + * @author Tiina Kivilinna-Korhola + * @copyright (c) 2010 Speed Freak team + * license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + #include "xmlwriter.h" @@ -28,6 +26,7 @@ XmlWriter::~XmlWriter() { } + /** *@brief Writes registration items into tags. *@param netbuf a buffer where xmlstreamwriter writes to. @@ -36,8 +35,9 @@ XmlWriter::~XmlWriter() *@param email. */ void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email) -//void XmlWriter::writeRegistering(QIODevice *netbuf, QString usr, QString psswd, QString email) { + qDebug() << "_writeRegistering"; + xmlwriter.setDevice(netbuf); xmlwriter.writeStartDocument(); @@ -65,16 +65,52 @@ void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QS *@todo Consider looping when writing many values. *@todo Replace test value to finally used variables. */ -void XmlWriter::writeResult(QBuffer *netbuf) -//void XmlWriter::writeResult(QIODevice *netbuf) +void XmlWriter::writeResult(QBuffer *netbuf, double result) { + qDebug() << "_writeResult"; + xmlwriter.setDevice(netbuf); xmlwriter.writeStartDocument(); xmlwriter.writeStartElement("result"); - xmlwriter.writeAttribute("value", QString::number(14)); - xmlwriter.writeAttribute("unit", "seconds"); - xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString()); + xmlwriter.writeAttribute("value", QString::number(result)); + xmlwriter.writeEndElement(); + xmlwriter.writeEndDocument(); +} + + +/** + *@brief Write track to server. + *@param netbuf where to write. + *@param counter is GPSData::roundCounter. + *@todo Decide suitable attributes. + */ +void XmlWriter::writeGpsTrack(QBuffer *netbuf, int counter, int start, int stop, int lat, int lon, int alt, int speed, int time) +{ + qDebug() << "_writeGpsTrack"; + + double *ptrValue; + //ptrValue = ptrTable; + double tmp = 0; + + xmlwriter.setDevice(netbuf); + + xmlwriter.writeStartDocument(); + + xmlwriter.writeStartElement("Route"); + xmlwriter.writeAttribute("starttime", QDateTime::currentDateTime().toString()); + xmlwriter.writeAttribute("endtime", QDateTime::currentDateTime().toString()); + xmlwriter.writeAttribute("points", QDateTime::currentDateTime().toString()); + for(int i = 0; i < counter; i++) + { + xmlwriter.writeStartElement("point"); + xmlwriter.writeAttribute("lat", QString::number(lat)); + xmlwriter.writeAttribute("lon", QString::number(lon)); + xmlwriter.writeAttribute("alt", QString::number(alt)); + xmlwriter.writeAttribute("speed", QString::number(speed)); + xmlwriter.writeAttribute("time", QString::number(time)); + xmlwriter.writeEndElement(); + } xmlwriter.writeEndElement(); xmlwriter.writeEndDocument(); } @@ -88,9 +124,10 @@ void XmlWriter::writeResult(QBuffer *netbuf) *@param email. *@todo Replace hardcoced filename to finally GUI entry widget. */ -void XmlWriter::writeXml(QString usr, QString psswd, QString email) +//void XmlWriter::writeXml(QString usr, QString psswd, QString email) +void XmlWriter::writeXml() { - QString filename = "xmlfile.xml"; + QString filename = "xmlcategoryfile.xml"; QFile file(filename); if (!file.open(QFile::WriteOnly | QFile::Text)) { qDebug() << "_xmlWrite fail"; @@ -136,27 +173,3 @@ void XmlWriter::writeItems() xmlwriter.writeEndElement(); } - -/** - *@brief A temp function during development, used to create a "serverfile". - */ -void XmlWriter::serverWritesTop() -{ - int i = 0; - int n = 5; - - /* Server sends to client */ - 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(); - } -}