Improved functions that pack info into xml tags.
authortiina.kivilinna-korhola@windowslive.com <tkk@tkk-laptop.(none)>
Sun, 7 Mar 2010 22:29:31 +0000 (00:29 +0200)
committertiina.kivilinna-korhola@windowslive.com <tkk@tkk-laptop.(none)>
Sun, 7 Mar 2010 22:29:31 +0000 (00:29 +0200)
Client/xmlwriter.cpp
Client/xmlwriter.h

index f860975..22dc8d1 100644 (file)
@@ -1,6 +1,5 @@
 #include <QtGui>
 #include <QNetworkRequest>
 #include <QtGui>
 #include <QNetworkRequest>
-//#include <QNetworkReply>
 #include <QIODevice>
 #include <QFile>
 #include <QMessageBox>
 #include <QIODevice>
 #include <QFile>
 #include <QMessageBox>
 #include "xmlwriter.h"
 
 
 #include "xmlwriter.h"
 
 
+
 /**
   *@brief Constructor, connects object to GUI
   *@param Pointer to carmainwindow, which is temporarily used during development
   */
 /**
   *@brief Constructor, connects object to GUI
   *@param Pointer to carmainwindow, which is temporarily used during development
   */
-XmlWriter::XmlWriter(Ui_CarMainWindow* myMainWindow)
+XmlWriter::XmlWriter()
 {
 {
-    ui = myMainWindow;
-}
 
 
+}
 
 /**
   *@brief Destructor
 
 /**
   *@brief Destructor
@@ -29,14 +28,67 @@ XmlWriter::~XmlWriter()
 {
 
 }
 {
 
 }
+/**
+  *@brief Writes registration items into tags.
+  *@param netbuf a buffer where xmlstreamwriter writes to.
+  *@param usr for user name.
+  *@param psswd for password.
+  *@param email.
+  */
+void XmlWriter::writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email)
+//void XmlWriter::writeRegistering(QIODevice *netbuf, QString usr, QString psswd, QString email)
+{
+    xmlwriter.setDevice(netbuf);
+
+    xmlwriter.writeStartDocument();
+    xmlwriter.writeStartElement("user");
+
+    xmlwriter.writeStartElement("login");
+    xmlwriter.writeCharacters(usr);
+    xmlwriter.writeEndElement();
+
+    xmlwriter.writeStartElement("password");
+    xmlwriter.writeCharacters(psswd);
+    xmlwriter.writeEndElement();
+
+    xmlwriter.writeStartElement("email");
+    xmlwriter.writeCharacters(email);
+    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(QIODevice *netbuf)
+{
+    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.writeEndElement();
+    xmlwriter.writeEndDocument();
+}
+
 
 /**
   *@brief Opens and closes a file, when xml information is written into a file,
   *and passes file to writeXmlFile()
 
 /**
   *@brief Opens and closes a file, when xml information is written into a file,
   *and passes file to writeXmlFile()
-  *@note Partly harcoded and commented for git.
-  *@todo Replace hardcoced filename and GUI elements to finally used widgets.
+  *@param usr for user name.
+  *@param psswd for password.
+  *@param email.
+  *@todo Replace hardcoced filename to finally GUI entry widget.
   */
   */
-void XmlWriter::writeXml()
+void XmlWriter::writeXml(QString usr, QString psswd, QString email)
 {
     QString filename = "xmlfile.xml";
     QFile file(filename);
 {
     QString filename = "xmlfile.xml";
     QFile file(filename);
@@ -46,66 +98,39 @@ void XmlWriter::writeXml()
     }
 
     writeXmlFile(&file);
     }
 
     writeXmlFile(&file);
+    //writeRegistering(&file, usr, psswd, email);
+    //writeResult(&file);
     file.close();
 }
 
 /**
   *@brief Writes general xml information.
   *Calls other functions to insert login and result information.
     file.close();
 }
 
 /**
   *@brief Writes general xml information.
   *Calls other functions to insert login and result information.
-  *@todo Check API connection to QBuffer, when Speed Freek network client has been written.
+  *@param device: target of writing, here filename.
+  *@param usr for user name.
+  *@param psswd for password.
+  *@param email.
   */
 bool XmlWriter::writeXmlFile(QIODevice *device)
   */
 bool XmlWriter::writeXmlFile(QIODevice *device)
-//bool XmlWriter::writeXmlFile(QBuffer *device)
 {
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
 {
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
-    xmlwriter.writeStartElement("xml");
-    xmlwriter.writeAttribute("version", "1.0");
-    writeRegister();
     writeItems();
     xmlwriter.writeEndDocument();
 
     return true;
 }
 
     writeItems();
     xmlwriter.writeEndDocument();
 
     return true;
 }
 
-/**
-  *@brief Writes Speed Freek application specific items as tags and contents.
-  *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
-  *@todo Replace hardcoced user, password and email to finally used GUI elements.
-  */
-void XmlWriter::writeRegister()
-{
-    xmlwriter.writeStartElement("user");
-
-    xmlwriter.writeStartElement("login");
-    xmlwriter.writeCharacters("test123");
-    xmlwriter.writeEndElement();
-
-    xmlwriter.writeStartElement("password");
-    xmlwriter.writeCharacters("thisisaveryinsecurepassword");
-    xmlwriter.writeEndElement();
-
-    //Is this neacessary when sending results
-    xmlwriter.writeStartElement("email");
-    xmlwriter.writeCharacters("test@example.com");
-    xmlwriter.writeEndElement();
-
-    xmlwriter.writeEndElement();
-}
 
 /**
 
 /**
-  *@brief Writes Speed Freek results items as tags and contents.
-  *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
-  *@todo Consider looping of writing QMap values.
-  *@todo Replace hardcoced names to finally used values.
+  *@brief Writes Speed Freek results items as tags and contents to earlier defined target.
+  *@todo Consider looping when writing many values.
+  *@todo Replace testing values to finally used variabls.
   */
 void XmlWriter::writeItems()
 {
   */
 void XmlWriter::writeItems()
 {
-    //During development
-    this->fillResultmap();
-
     xmlwriter.writeStartElement("result");
     xmlwriter.writeStartElement("result");
-    xmlwriter.writeAttribute("value", QString::number(resultmap.value("speed")));
+    xmlwriter.writeAttribute("value", QString::number(14)); //tmp testing value
     xmlwriter.writeAttribute("unit", "seconds");
     xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
     xmlwriter.writeEndElement();
     xmlwriter.writeAttribute("unit", "seconds");
     xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
     xmlwriter.writeEndElement();
@@ -113,16 +138,6 @@ void XmlWriter::writeItems()
 
 
 /**
 
 
 /**
-  *@brief A temp function during development, used until real QMap available.
-  */
-void XmlWriter::fillResultmap()
-{
-    resultmap["acceleration"] = 9;
-    resultmap["speed"] = 48;
-    resultmap["distance"] = 600;
-}
-
-/**
   *@brief A temp function during development, used to create a "serverfile".
   */
 void XmlWriter::serverWritesTop()
   *@brief A temp function during development, used to create a "serverfile".
   */
 void XmlWriter::serverWritesTop()
@@ -132,7 +147,7 @@ void XmlWriter::serverWritesTop()
 
     /* Server sends to client */
     xmlwriter.writeStartElement("results");
 
     /* Server sends to client */
     xmlwriter.writeStartElement("results");
-    xmlwriter.writeAttribute("category", "acceleration-0-100");
+    xmlwriter.writeAttribute("category", "acceleration-0-40");
     xmlwriter.writeAttribute("unit", "seconds");
     xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
 
     xmlwriter.writeAttribute("unit", "seconds");
     xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
 
index 00cc5d8..c664d42 100644 (file)
@@ -1,26 +1,35 @@
 #ifndef XMLWRITER_H
 #define XMLWRITER_H
 
 #ifndef XMLWRITER_H
 #define XMLWRITER_H
 
-#include "ui_carmainwindow.h"
+#include <QXmlStreamWriter>
+#include <QBuffer>
+
+
+/**
+  *This class
+  *@author Tiina Kivilinna-Korhola
+  *@copyright   (c) 2010 Speed Freak team
+  *@license     http://opensource.org/licenses/gpl-license.php GNU Public License
+  */
 
 
 class XmlWriter : public QObject
 {
 public:
 
 
 class XmlWriter : public QObject
 {
 public:
-    XmlWriter(Ui_CarMainWindow* myMainWindow);
+    XmlWriter();
     ~XmlWriter();
 
 private:
     QXmlStreamWriter xmlwriter;
     ~XmlWriter();
 
 private:
     QXmlStreamWriter xmlwriter;
-    QMap<QString, int> resultmap;
-    Ui_CarMainWindow* ui;
 
 public slots:
 
 public slots:
-    bool writeXmlFile(QIODevice* device);
+    void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
+    //void writeRegistering(QIODevice *netbuf, QString usr, QString psswd, QString email);
+    void writeResult(QBuffer *netbuf);
+    //void writeResult(QIODevice *netbuf);
+    bool writeXmlFile(QIODevice *device);
+    void writeXml(QString usr, QString psswd, QString email);
     void writeItems();
     void writeItems();
-    void fillResultmap();
-    void writeXml();
-    void writeRegister();
     void serverWritesTop();
 
 };
     void serverWritesTop();
 
 };