Users dialog files added.
[speedfreak] / Client / xmlwriter.cpp
index fd46a6d..cb97457 100644 (file)
@@ -2,21 +2,20 @@
  * Xml writer
  *
  * @author     Tiina Kivilinna-Korhola
+ * @author     Toni Jussila <toni.jussila@fudeco.com>
  * @copyright  (c) 2010 Speed Freak team
  * license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
 
 #include "xmlwriter.h"
 
-
-
 /**
   *@brief Constructor, connects object to GUI
   *@param Pointer to carmainwindow, which is temporarily used during development
   */
 XmlWriter::XmlWriter()
 {
-    tmpvalue = 3010;
+
 }
 
 /**
@@ -34,7 +33,7 @@ XmlWriter::~XmlWriter()
   *@param psswd for password.
   *@param email.
   */
-void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email)
+void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email, QString description)
 {
     qDebug() << "_writeRegistering";
 
@@ -55,17 +54,20 @@ void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QS
     xmlwriter.writeCharacters(email);
     xmlwriter.writeEndElement();
 
+    xmlwriter.writeStartElement("description");
+    xmlwriter.writeCharacters(description);
+    xmlwriter.writeEndElement();
+
     xmlwriter.writeEndElement();
     xmlwriter.writeEndDocument();
 }
 
-
 /**
   *@brief Writes Speed Freek results items as tags and contents into a buffer.
   *@todo Consider looping when writing many values.
   *@todo Replace test value to finally used variables.
   */
-void XmlWriter::writeResult(QBuffer *netbuf)
+void XmlWriter::writeResult(QBuffer *netbuf, double result)
 {
     qDebug() << "_writeResult";
 
@@ -73,14 +75,11 @@ void XmlWriter::writeResult(QBuffer *netbuf)
 
     xmlwriter.writeStartDocument();
     xmlwriter.writeStartElement("result");
-    tmpvalue++;
-    qDebug() << tmpvalue;
-    xmlwriter.writeAttribute("value", QString::number(tmpvalue));
+    xmlwriter.writeAttribute("value", QString::number(result));
     xmlwriter.writeEndElement();
     xmlwriter.writeEndDocument();
 }
 
-
 /**
   *@brief Write track to server.
   *@param netbuf where to write.
@@ -117,7 +116,6 @@ void XmlWriter::writeGpsTrack(QBuffer *netbuf, int counter, int start, int stop,
     xmlwriter.writeEndDocument();
 }
 
-
 /**
   *@brief Opens and closes a file, when xml information is written into a file,
   *and passes file to writeXmlFile()
@@ -160,7 +158,6 @@ bool XmlWriter::writeXmlFile(QIODevice *device)
     return true;
 }
 
-
 /**
   *@brief Writes Speed Freek results items as tags and contents to earlier defined target.
   *@todo Consider looping when writing many values.
@@ -175,3 +172,106 @@ void XmlWriter::writeItems()
     xmlwriter.writeEndElement();
 }
 
+/**
+  * Write profile xml
+  * @param QIODevice device: target of writing, here filename.
+  * @param QString user name
+  * @param QString manufacturer
+  * @param QString type
+  * @param QString model
+  * @param QString description
+  * @param QString picture: filename.
+  */
+void XmlWriter::writeProfileXmlFile(QIODevice *device, QString userName, QString manufacturer,
+                                    QString type, QString model, QString description, QString picture)
+{
+    QString pictureStatus;
+    if(picture != "")
+        pictureStatus = "yes";
+    else
+        pictureStatus = "no";
+
+    /*example of XML:
+    <?xml version="1.0" encoding="UTF-8"?>
+    <profile login="test827" picture="yes">
+            <manufacturer>toyota</manufacturer>
+            <type>corolla</type>
+            <model>1983</model>
+            <description>Fuel efficient, GPS system, only one owner</description>
+    </profile>*/
+
+    xmlwriter.setDevice(device);
+    xmlwriter.writeStartDocument();
+        xmlwriter.writeStartElement("profile");
+        xmlwriter.writeAttribute("login", userName);
+        xmlwriter.writeAttribute("picture", pictureStatus);
+            xmlwriter.writeStartElement("manufacturer");
+                xmlwriter.writeCharacters(manufacturer);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("type");
+                xmlwriter.writeCharacters(type);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("model");
+                xmlwriter.writeCharacters(model);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("description");
+                xmlwriter.writeCharacters(description);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("picture");
+                xmlwriter.writeCharacters(picture);
+            xmlwriter.writeEndElement();
+        xmlwriter.writeEndElement();
+    xmlwriter.writeEndDocument();
+}
+
+/**
+  * Write profile xml
+  * @param QIODevice device: target of writing, here netbuf.
+  * @param QString user name
+  * @param QString manufacturer
+  * @param QString type
+  * @param QString model
+  * @param QString description
+  * @param QString picture: filename.
+  */
+void XmlWriter::writeProfileXmlFile(QBuffer *netbuf, QString userName, QString manufacturer,
+                                    QString type, QString model, QString description, QString picture)
+{
+    QString pictureStatus;
+    if(picture != "")
+        pictureStatus = "yes";
+    else
+        pictureStatus = "no";
+
+    /*example of XML:
+    <?xml version="1.0" encoding="UTF-8"?>
+    <profile login="test827" picture="yes">
+            <manufacturer>toyota</manufacturer>
+            <type>corolla</type>
+            <model>1983</model>
+            <description>Fuel efficient, GPS system, only one owner</description>
+    </profile>*/
+
+    xmlwriter.setDevice(netbuf);
+    xmlwriter.writeStartDocument();
+        xmlwriter.writeStartElement("profile");
+        xmlwriter.writeAttribute("login", userName);
+        xmlwriter.writeAttribute("picture", pictureStatus);
+            xmlwriter.writeStartElement("manufacturer");
+                xmlwriter.writeCharacters(manufacturer);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("type");
+                xmlwriter.writeCharacters(type);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("model");
+                xmlwriter.writeCharacters(model);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("description");
+                xmlwriter.writeCharacters(description);
+            xmlwriter.writeEndElement();
+            xmlwriter.writeStartElement("picture");
+                xmlwriter.writeCharacters(picture);
+            xmlwriter.writeEndElement();
+        xmlwriter.writeEndElement();
+    xmlwriter.writeEndDocument();
+}