4 * @author Tiina Kivilinna-Korhola
5 * @copyright (c) 2010 Speed Freak team
6 * license http://opensource.org/licenses/gpl-license.php GNU Public License
10 #include <QNetworkRequest>
13 #include <QMessageBox>
18 #include <QApplication>
19 #include "xmlwriter.h"
24 *@brief Constructor, connects object to GUI
25 *@param Pointer to carmainwindow, which is temporarily used during development
27 XmlWriter::XmlWriter()
35 XmlWriter::~XmlWriter()
40 *@brief Writes registration items into tags.
41 *@param netbuf a buffer where xmlstreamwriter writes to.
42 *@param usr for user name.
43 *@param psswd for password.
46 void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email)
47 //void XmlWriter::writeRegistering(QIODevice *netbuf, QString usr, QString psswd, QString email)
49 xmlwriter.setDevice(netbuf);
51 xmlwriter.writeStartDocument();
52 xmlwriter.writeStartElement("user");
54 xmlwriter.writeStartElement("login");
55 xmlwriter.writeCharacters(usr);
56 xmlwriter.writeEndElement();
58 xmlwriter.writeStartElement("password");
59 xmlwriter.writeCharacters(psswd);
60 xmlwriter.writeEndElement();
62 xmlwriter.writeStartElement("email");
63 xmlwriter.writeCharacters(email);
64 xmlwriter.writeEndElement();
66 xmlwriter.writeEndElement();
67 xmlwriter.writeEndDocument();
72 *@brief Writes Speed Freek results items as tags and contents into a buffer.
73 *@todo Consider looping when writing many values.
74 *@todo Replace test value to finally used variables.
76 void XmlWriter::writeResult(QBuffer *netbuf)
77 //void XmlWriter::writeResult(QIODevice *netbuf)
79 xmlwriter.setDevice(netbuf);
81 xmlwriter.writeStartDocument();
82 xmlwriter.writeStartElement("result");
83 xmlwriter.writeAttribute("value", QString::number(14));
84 xmlwriter.writeAttribute("unit", "seconds");
85 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
86 xmlwriter.writeEndElement();
87 xmlwriter.writeEndDocument();
92 *@brief Opens and closes a file, when xml information is written into a file,
93 *and passes file to writeXmlFile()
94 *@param usr for user name.
95 *@param psswd for password.
97 *@todo Replace hardcoced filename to finally GUI entry widget.
99 void XmlWriter::writeXml(QString usr, QString psswd, QString email)
101 QString filename = "xmlfile.xml";
102 QFile file(filename);
103 if (!file.open(QFile::WriteOnly | QFile::Text)) {
104 qDebug() << "_xmlWrite fail";
109 //writeRegistering(&file, usr, psswd, email);
110 //writeResult(&file);
115 *@brief Writes general xml information.
116 *Calls other functions to insert login and result information.
117 *@param device: target of writing, here filename.
118 *@param usr for user name.
119 *@param psswd for password.
122 bool XmlWriter::writeXmlFile(QIODevice *device)
124 xmlwriter.setDevice(device);
125 xmlwriter.writeStartDocument();
127 xmlwriter.writeEndDocument();
134 *@brief Writes Speed Freek results items as tags and contents to earlier defined target.
135 *@todo Consider looping when writing many values.
136 *@todo Replace testing values to finally used variabls.
138 void XmlWriter::writeItems()
140 xmlwriter.writeStartElement("result");
141 xmlwriter.writeAttribute("value", QString::number(14)); //tmp testing value
142 xmlwriter.writeAttribute("unit", "seconds");
143 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
144 xmlwriter.writeEndElement();
149 *@brief A temp function during development, used to create a "serverfile".
151 void XmlWriter::serverWritesTop()
156 /* Server sends to client */
157 xmlwriter.writeStartElement("results");
158 xmlwriter.writeAttribute("category", "acceleration-0-40");
159 xmlwriter.writeAttribute("unit", "seconds");
160 xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
162 for (i = 0; i < n; i++) {
163 xmlwriter.writeStartElement("result");
164 xmlwriter.writeAttribute("position", QString::number(i));
165 xmlwriter.writeAttribute("user", "test123");
166 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
167 xmlwriter.writeAttribute("value", QString::number(i+i+1));
168 xmlwriter.writeEndElement();