2 #include <QNetworkRequest>
10 #include <QApplication>
11 #include "xmlwriter.h"
16 *@brief Constructor, connects object to GUI
17 *@param Pointer to carmainwindow, which is temporarily used during development
19 XmlWriter::XmlWriter()
27 XmlWriter::~XmlWriter()
32 *@brief Writes registration items into tags.
33 *@param netbuf a buffer where xmlstreamwriter writes to.
34 *@param usr for user name.
35 *@param psswd for password.
38 void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email)
39 //void XmlWriter::writeRegistering(QIODevice *netbuf, QString usr, QString psswd, QString email)
41 xmlwriter.setDevice(netbuf);
43 xmlwriter.writeStartDocument();
44 xmlwriter.writeStartElement("user");
46 xmlwriter.writeStartElement("login");
47 xmlwriter.writeCharacters(usr);
48 xmlwriter.writeEndElement();
50 xmlwriter.writeStartElement("password");
51 xmlwriter.writeCharacters(psswd);
52 xmlwriter.writeEndElement();
54 xmlwriter.writeStartElement("email");
55 xmlwriter.writeCharacters(email);
56 xmlwriter.writeEndElement();
58 xmlwriter.writeEndElement();
59 xmlwriter.writeEndDocument();
64 *@brief Writes Speed Freek results items as tags and contents into a buffer.
65 *@todo Consider looping when writing many values.
66 *@todo Replace test value to finally used variables.
68 void XmlWriter::writeResult(QBuffer *netbuf)
69 //void XmlWriter::writeResult(QIODevice *netbuf)
71 xmlwriter.setDevice(netbuf);
73 xmlwriter.writeStartDocument();
74 xmlwriter.writeStartElement("result");
75 xmlwriter.writeAttribute("value", QString::number(14));
76 xmlwriter.writeAttribute("unit", "seconds");
77 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
78 xmlwriter.writeEndElement();
79 xmlwriter.writeEndDocument();
84 *@brief Opens and closes a file, when xml information is written into a file,
85 *and passes file to writeXmlFile()
86 *@param usr for user name.
87 *@param psswd for password.
89 *@todo Replace hardcoced filename to finally GUI entry widget.
91 void XmlWriter::writeXml(QString usr, QString psswd, QString email)
93 QString filename = "xmlfile.xml";
95 if (!file.open(QFile::WriteOnly | QFile::Text)) {
96 qDebug() << "_xmlWrite fail";
101 //writeRegistering(&file, usr, psswd, email);
102 //writeResult(&file);
107 *@brief Writes general xml information.
108 *Calls other functions to insert login and result information.
109 *@param device: target of writing, here filename.
110 *@param usr for user name.
111 *@param psswd for password.
114 bool XmlWriter::writeXmlFile(QIODevice *device)
116 xmlwriter.setDevice(device);
117 xmlwriter.writeStartDocument();
119 xmlwriter.writeEndDocument();
126 *@brief Writes Speed Freek results items as tags and contents to earlier defined target.
127 *@todo Consider looping when writing many values.
128 *@todo Replace testing values to finally used variabls.
130 void XmlWriter::writeItems()
132 xmlwriter.writeStartElement("result");
133 xmlwriter.writeAttribute("value", QString::number(14)); //tmp testing value
134 xmlwriter.writeAttribute("unit", "seconds");
135 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
136 xmlwriter.writeEndElement();
141 *@brief A temp function during development, used to create a "serverfile".
143 void XmlWriter::serverWritesTop()
148 /* Server sends to client */
149 xmlwriter.writeStartElement("results");
150 xmlwriter.writeAttribute("category", "acceleration-0-40");
151 xmlwriter.writeAttribute("unit", "seconds");
152 xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
154 for (i = 0; i < n; i++) {
155 xmlwriter.writeStartElement("result");
156 xmlwriter.writeAttribute("position", QString::number(i));
157 xmlwriter.writeAttribute("user", "test123");
158 xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
159 xmlwriter.writeAttribute("value", QString::number(i+i+1));
160 xmlwriter.writeEndElement();