Added msgboxes to server replies acknowledgefunctions.
authorTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Fri, 12 Mar 2010 07:58:22 +0000 (09:58 +0200)
committerTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Fri, 12 Mar 2010 07:58:22 +0000 (09:58 +0200)
Client/carmainwindow.cpp
Client/xmlreader.cpp
Client/xmlreader.h
Client/xmlwriter.cpp
Client/xmlwriter.h

index 0a8c350..ed8b953 100644 (file)
@@ -276,14 +276,12 @@ void CarMainWindow::registrate()
                       this->myRegistration->getUserName(),
                       this->myRegistration->getPassword(),
                       this->myRegistration->getEmail());
-    //Tmp msgbox - later server responce
-    QMessageBox::about(this,"Registrate",this->myRegistration->getUserName() + this->myRegistration->getPassword() + this->myRegistration->getEmail());
 
     currentDownload = manager->post(request, ("xml=" + regbuffer->data()));
     qDebug() << "carmainwindow: regbuffer->data(): " << regbuffer->data();
 
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRegistration()));
-    connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
 
     regbuffer->close();
 }
@@ -316,7 +314,7 @@ void CarMainWindow::sendResultXml()
 
     currentDownload = manager->post(request, ("xml=" + xmlbuffer->data()));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfResult()));
-    connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
 
     xmlbuffer->close();
 }
@@ -343,7 +341,7 @@ void CarMainWindow::requestTopList(QString category, QString limit)
 
     currentDownload = manager->post(request, ("data=" ));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfToplist()));
-    connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
 }
 
 
@@ -366,7 +364,7 @@ void CarMainWindow::requestCategories()
 
     currentDownload = manager->post(request, ("data=" ));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfCategories()));
-    connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
 }
 
 
@@ -379,14 +377,16 @@ void CarMainWindow::ackOfResult()
     qDebug() << "_ackOfResult";
 
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    qDebug() << reply->readAll();
+
     QNetworkReply::NetworkError errorcode;
     errorcode = reply->error();
     if(errorcode != 0) {
-        qDebug() << errorcode << reply->errorString();
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(this, "Server reply to result sending ",reply->errorString());
     }
     else {
-        qDebug() << "errorcode=0";
+        qDebug() << "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
     }
 }
 
@@ -400,35 +400,39 @@ void CarMainWindow::ackOfRegistration()
     qDebug() << "_ackOfRegistration";
 
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    qDebug() << reply->readAll();
+
     QNetworkReply::NetworkError errorcode;
     errorcode = reply->error();
     if(errorcode != 0) {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(this, "Server reply to registration",reply->readAll());
     }
     else {
-        qDebug() << "errorcode=0";
+        qDebug() << "errorcode=0" << errorcode << reply->errorString();
+        QMessageBox::about(this, "Server reply to registration", "User registration " + reply->readAll());
     }
 }
 
 
 /**
   *@brief React to servers responce after request for categories has been sent.
-  *@todo Implement reply`s feeding to categories list.
   */
 void CarMainWindow::ackOfCategories()
 {
     qDebug() << "_ackOfCategories";
 
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    qDebug() << reply->readAll();
+    xmlreader->xmlReadCategories(reply);
+
     QNetworkReply::NetworkError errorcode;
     errorcode = reply->error();
     if(errorcode != 0) {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(this, "Server reply to requesting categories",reply->errorString());
     }
     else {
-        qDebug() << "errorcode=0";
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
     }
 }
 
@@ -439,11 +443,16 @@ void CarMainWindow::errorFromServer(QNetworkReply::NetworkError errorcode)
 {
     qDebug() << "_errorFromServer";
 
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
     if(errorcode != 0) {
-        qDebug() << errorcode;
+        qDebug() <<  "errorcode:" << errorcode;
+        //Note that errors are already reported on other ach-functions for server communication
+        //QMessageBox::about(this, "Server reported an error", reply->errorString());
     }
     else {
-        qDebug() << errorcode;
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
     }
 }
 
@@ -457,15 +466,17 @@ void CarMainWindow::ackOfToplist()
     qDebug() << "_ackOfToplist";
 
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    xmlreader->xmlRead(reply);
-    qDebug() << reply->readAll();
+    xmlreader->xmlReadTop10Results(reply);
+
     QNetworkReply::NetworkError errorcode;
     errorcode = reply->error();
     if(errorcode != 0) {
-        qDebug() << errorcode << reply->errorString();
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(this, "Server reply to requesting top 10 list",reply->errorString());
     }
     else {
-        qDebug() << "errorcode=0";
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
     }
 }
 
index 393cd41..6067038 100644 (file)
@@ -35,9 +35,9 @@ XmlReader::~XmlReader()
 /**
   *This function is used to parsing xml file.
   */
-void XmlReader::xmlRead(QNetworkReply *device)
+void XmlReader::xmlReadTop10Results(QNetworkReply *device)
 {
-    qDebug() << "_xmlRead";
+    qDebug() << "_xmlReadTop10Results";
 
     xmlreader.addData(device->readAll());
 
@@ -103,13 +103,49 @@ void XmlReader::xmlRead(QNetworkReply *device)
     }
 }
 
+void XmlReader::xmlReadCategories(QNetworkReply *device)
+//void XmlReader::xmlReadCategories(QIODevice *device)
+{
+    qDebug() << "_xmlReadCategories";
+
+    int i = 0;
+
+    QByteArray array = device->readAll();
+    qDebug() << array;
+    xmlreader.addData(array);
+
+    //Go trough the xml document
+    while(!xmlreader.atEnd())
+    {
+        //Read next node
+        xmlreader.readNext();
+
+        //Check if this element is starting element
+        if(xmlreader.isStartElement())
+        {
+            if(xmlreader.name() == "categories")
+            {
+                qDebug() << xmlreader.name();
+            }
+            if(xmlreader.name() == "category")
+            {
+                qDebug() << xmlreader.name();
+                categoryList.insert(i, xmlreader.readElementText());
+                qDebug() << "i=" << i << categoryList.at(i);
+                i++;
+            }
+        }
+    }
+}
+
 /**
   *This function is used to read example xml file (results.xml).
   *@todo Read real xml.
   */
 void XmlReader::xmlShow()
 {
-    QString filename = "results.xml";
+    //QString filename = "results.xml";
+    QString filename = "xmlcategoryfile.xml";
     QFile file(filename);
 
     if (!file.open(QFile::ReadOnly))
@@ -118,7 +154,8 @@ void XmlReader::xmlShow()
         return;
     }
 
-    //xmlRead(&file);
+    //xmlReadTop10Results(&file);
+    //xmlReadCategories(&file);
     file.close();
 }
 
index 921ceb2..43615a7 100644 (file)
@@ -23,6 +23,7 @@ public:
 private:
     QXmlStreamReader xmlreader;
     QStringList top10List;              // Next 4 to be removed. Categorylist now in own class.
+    QStringList categoryList;
     QString top10AccelerationList;
     QString top10SpeedList;
     QString top10GforceList;
@@ -36,7 +37,9 @@ private:
     QString value;
 
 public slots:
-    void xmlRead(QNetworkReply *device);
+    void xmlReadTop10Results(QNetworkReply *device);
+    void xmlReadCategories(QNetworkReply *device);
+    //void xmlReadCategories(QIODevice *device);
     void xmlShow();
 };
 
index ff288d1..2b1c463 100644 (file)
@@ -93,7 +93,7 @@ void XmlWriter::writeResult(QBuffer *netbuf)
   */
 void XmlWriter::writeXml(QString usr, QString psswd, QString email)
 {
-    QString filename = "xmlfile.xml";
+    QString filename = "xmlcategoryfile.xml";
     QFile file(filename);
     if (!file.open(QFile::WriteOnly | QFile::Text)) {
         qDebug() << "_xmlWrite fail";
@@ -119,6 +119,7 @@ bool XmlWriter::writeXmlFile(QIODevice *device)
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
     writeItems();
+    //serverWritesXml();
     xmlwriter.writeEndDocument();
 
     return true;
@@ -143,12 +144,14 @@ void XmlWriter::writeItems()
 /**
   *@brief A temp function during development, used to create a "serverfile".
   */
-void XmlWriter::serverWritesTop()
+void XmlWriter::serverWritesXml()
 {
+    /* Server sends to client */
+    /*
     int i = 0;
     int n = 5;
 
-    /* Server sends to client */
+    //Write top 10 Results
     xmlwriter.writeStartElement("results");
     xmlwriter.writeAttribute("category", "acceleration-0-40");
     xmlwriter.writeAttribute("unit", "seconds");
@@ -162,4 +165,21 @@ void XmlWriter::serverWritesTop()
         xmlwriter.writeAttribute("value", QString::number(i+i+1));
         xmlwriter.writeEndElement();
     }
+    */
+    //Write categories
+    xmlwriter.writeStartElement("categories");
+
+    xmlwriter.writeStartElement("category");
+    xmlwriter.writeCharacters("acceleration-0-10");
+    xmlwriter.writeEndElement();
+
+    xmlwriter.writeStartElement("category");
+    xmlwriter.writeCharacters("acceleration-0-60");
+    xmlwriter.writeEndElement();
+
+    xmlwriter.writeStartElement("category");
+    xmlwriter.writeCharacters("acceleration-0-100");
+    xmlwriter.writeEndElement();
+
+    xmlwriter.writeEndElement();
 }
index 539ccab..e24a60a 100644 (file)
@@ -40,7 +40,7 @@ public slots:
     bool writeXmlFile(QIODevice *device);
     void writeXml(QString usr, QString psswd, QString email);
     void writeItems();
-    void serverWritesTop();
+    void serverWritesXml();
 
 };