Moved server clients functions from carmainwindow.cpp to httpclient.cpp.
authorTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Mon, 15 Mar 2010 10:57:16 +0000 (12:57 +0200)
committerTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Mon, 15 Mar 2010 10:57:16 +0000 (12:57 +0200)
Changed one function prototype in xmlwrite to reduce compile warnings.

Client/carmainwindow.cpp
Client/carmainwindow.h
Client/httpclient.cpp
Client/httpclient.h
Client/xmlwriter.cpp
Client/xmlwriter.h

index ed8b953..f1b1bb1 100644 (file)
@@ -25,19 +25,15 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     welcomeDialog = new WelcomeDialog();
     welcomeDialog->show();
 
-    xmlreader = new XmlReader();
-
     initComboBoxStartTabUnits();
     initListViewStartTabAccelerationCategories();
 
     myLogin = new LoginWindow(this);
+    categorylist = new CategoryList();
+    myHttpClient = new HttpClient(this);
     myRegistration = new Registration(this);
-    xmlwriter = new XmlWriter();
-    manager = new QNetworkAccessManager(this);
     connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(registrate()));
 
-    categorylist = new CategoryList();
-
     time = 0;
     speed = 0;
     timer = new QTimer();
@@ -67,9 +63,6 @@ CarMainWindow::~CarMainWindow()
     delete ui;
     //delete result;
     //delete measure;
-    delete xmlreader;
-    delete xmlwriter;
-    delete manager;
     delete categorylist;
     delete welcomeDialog;
 }
@@ -220,7 +213,7 @@ void CarMainWindow::on_registratePushButton_clicked()
   */
 void CarMainWindow::on_buttonTopRefresh_clicked()
 {
-    requestCategories();
+    myHttpClient->requestCategories();
     setCategoryCompoBox();
 }
 
@@ -234,7 +227,7 @@ void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
     int limitNr = 5;                    //replace with real value?
     QString limit = QString::number(limitNr);
     category = "acceleration-0-100";    //replace with real value from category list/top window
-    requestTopList(category, limit);
+    myHttpClient->requestTopList(category, limit);
     setListViewTopList(category,10);
 }
 
@@ -256,232 +249,6 @@ void CarMainWindow::on_setUserPushButton_clicked()
 }
 
 /**
-  *@brief Sends registration information to the server in xml format.
-  *Reads user name, password and emaol address from resuldialogs internal variables.
-  *@todo Replace msg box with better reaction to server`s responce.
-  */
-void CarMainWindow::registrate()
-{
-    qDebug() << "_registrate" ;
-    qDebug() << this->myRegistration->getUserName() << "+" << this->myRegistration->getPassword() << "+" << this->myRegistration->getEmail();
-
-    QBuffer *regbuffer = new QBuffer();
-    QUrl qurl("http://api.speedfreak-app.com/api/register");
-    QNetworkRequest request(qurl);
-    qDebug() << qurl.toString();
-    QNetworkReply *currentDownload;
-
-    regbuffer->open(QBuffer::ReadWrite);
-    xmlwriter->writeRegistering(regbuffer,
-                      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)));
-
-    regbuffer->close();
-}
-
-
-/**
-  *@brief Sends result(s) to the server in xml format.
-  *Send authentication information in the header.
-  *@todo Read category elsewhere.
-  */
-void CarMainWindow::sendResultXml()
-{
-    qDebug() << "_sendResultXml";
-
-    QBuffer *xmlbuffer = new QBuffer();
-    QString category_name = "acceleration-0-100";    //replace with real value from category list
-
-    QUrl qurl("http://api.speedfreak-app.com/api/update/" + category_name);
-    qDebug() << qurl.toString();
-    QNetworkRequest request(qurl);
-    QNetworkReply *currentDownload;
-
-    xmlbuffer->open(QBuffer::ReadWrite);
-    xmlwriter->writeResult(xmlbuffer);
-    qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
-
-    QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword();
-    credentials = "Basic " + credentials.toAscii().toBase64();
-    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
-
-    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)));
-
-    xmlbuffer->close();
-}
-
-/**
-  *@brief Request the Top10List of certain category from the server.
-  *Send authentication information in the header.
-  *@param Category of results.
-  *@param Limit, the number of results.
-  */
-void CarMainWindow::requestTopList(QString category, QString limit)
-{
-    qDebug() << "_requestTopList" ;
-
-    QString urlBase = "http://api.speedfreak-app.com/api/results/";
-    QUrl qurl(urlBase + category + "/" + limit);
-    qDebug() << qurl.toString();
-    QNetworkRequest request(qurl);
-    QNetworkReply *currentDownload;
-
-    QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword();
-    credentials = "Basic " + credentials.toAscii().toBase64();
-    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
-
-    currentDownload = manager->post(request, ("data=" ));
-    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfToplist()));
-    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
-}
-
-
-/**
-  *@brief Request categories list from the server.
-  *Send authentication information in the header.
-  */
-void CarMainWindow::requestCategories()
-{
-    qDebug() << "_requestCategories" ;
-
-    QUrl qurl("http://api.speedfreak-app.com/api/categories/");
-    qDebug() << qurl.toString();
-    QNetworkRequest request(qurl);
-    QNetworkReply *currentDownload;
-
-    QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword();
-    credentials = "Basic " + credentials.toAscii().toBase64();
-    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
-
-    currentDownload = manager->post(request, ("data=" ));
-    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfCategories()));
-    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(errorFromServer(QNetworkReply::NetworkError)));
-}
-
-
-/**
-  *@brief React to servers responce after result has been sent.
-  *@todo Implement consequencies of reply.
-  */
-void CarMainWindow::ackOfResult()
-{
-    qDebug() << "_ackOfResult";
-
-    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-
-    QNetworkReply::NetworkError errorcode;
-    errorcode = reply->error();
-    if(errorcode != 0) {
-        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
-        QMessageBox::about(this, "Server reply to result sending ",reply->errorString());
-    }
-    else {
-        qDebug() << "errorcode:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
-    }
-}
-
-
-/**
-  *@brief React to servers responce after registration has been sent.
-  *@todo Implement consequencies of reply.
-  */
-void CarMainWindow::ackOfRegistration()
-{
-    qDebug() << "_ackOfRegistration";
-
-    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-
-    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" << 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.
-  */
-void CarMainWindow::ackOfCategories()
-{
-    qDebug() << "_ackOfCategories";
-
-    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    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:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
-    }
-}
-
-/**
-  *@brief Reports errors, when server has sent error signal.
-  */
-void CarMainWindow::errorFromServer(QNetworkReply::NetworkError errorcode)
-{
-    qDebug() << "_errorFromServer";
-
-    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-
-    if(errorcode != 0) {
-        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:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
-    }
-}
-
-
-/**
-  *@brief React to servers responce after request of TopList in certain category has been sent.
-  *@todo Implement routing reply`s contents to UI.
-  */
-void CarMainWindow::ackOfToplist()
-{
-    qDebug() << "_ackOfToplist";
-
-    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    xmlreader->xmlReadTop10Results(reply);
-
-    QNetworkReply::NetworkError errorcode;
-    errorcode = reply->error();
-    if(errorcode != 0) {
-        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
-        QMessageBox::about(this, "Server reply to requesting top 10 list",reply->errorString());
-    }
-    else {
-        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
-    }
-}
-
-
-/**
   *@brief Just for development, for the real button is not shown until
   *measurin started and there are results.
   *@todo Implement with real code and yet leave sendXml in the bottom in use.
@@ -626,7 +393,7 @@ void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
 
 void CarMainWindow::on_pushButtonSendResult_clicked()
 {
-    sendResultXml();
+    myHttpClient->sendResultXml();
     ui->pushButtonSendResult->setEnabled(false);
 }
 
@@ -648,3 +415,8 @@ void CarMainWindow::updateUserName()
         this->setWindowTitle("Speed freak");
     }
 }
+
+void CarMainWindow::regUserToServer()
+{
+    myHttpClient->requestRegistration();
+}
index 8c7afa8..f7ee50e 100644 (file)
@@ -37,6 +37,7 @@
 #include "measures.h"
 #include "accelerometer.h"
 #include "categorylist.h"
+#include "httpclient.h"
 
 namespace Ui {
     class CarMainWindow;
@@ -47,11 +48,13 @@ class CarMainWindow : public QMainWindow {
 public:
     CarMainWindow(QWidget *parent = 0);
     ~CarMainWindow();
+    Registration *myRegistration;       //Check if this should be public or private
 
-    void setComboBoxStartTabUnits(QStringList units);    //Start-tab view
+
+    void setComboBoxStartTabUnits(QStringList units);       //Start-tab view
     void setListViewStartTabAccelerationCategories(QStringList numbers); //Start-tab view
-    void setListViewTopList(QString category, int size);  //Top-tab view
-    void setCategoryCompoBox(); //Top-tab
+    void setListViewTopList(QString category, int size);    //Top-tab view
+    void setCategoryCompoBox();                             //Top-tab
 
 protected:
     void changeEvent(QEvent *e);
@@ -61,22 +64,18 @@ private:
     //ResultDialog *result;
     //MeasureDialog *measure;
     WelcomeDialog *welcomeDialog;
-    XmlReader *xmlreader;
-    XmlWriter *xmlwriter;
-    QNetworkAccessManager* manager;
+    CategoryList *categorylist;
+    HttpClient *myHttpClient;
     LoginWindow *myLogin;
-    Registration *myRegistration;
-    //void initCategoryCompoBox();    //
-    void initComboBoxStartTabUnits();    //Start-tab view
-    void initListViewStartTabAccelerationCategories();   //Start-tab view
-
+    //void initCategoryCompoBox();
+    void initComboBoxStartTabUnits();                   //Start-tab view
+    void initListViewStartTabAccelerationCategories();  //Start-tab view
     void initializeMeasures();
 
 private:
-    QStringList accelerationCategoriesStartTab; //Start-tab view
-    QStringList units;  //Start-tab view
-    QStringList categories; //Top-tab view
-    CategoryList *categorylist;
+    QStringList accelerationCategoriesStartTab;         //Start-tab view
+    QStringList units;                                  //Start-tab view
+    QStringList categories;                             //Top-tab view
 
     QTimer *timer;
     Accelerometer *accelerometer;
@@ -96,23 +95,15 @@ private slots:
     void on_registratePushButton_clicked();
     void on_comboBoxTopCategory_activated(QString );
     //void on_pushButton_clicked();
-    void on_comboBoxTopCategory_currentIndexChanged(QString category); //Top-tab view
-    void on_listViewStartTabAccelerationCategories_clicked(QModelIndex index); //Start-tab view
-    void updateComboBoxStartTabUnits(QString unit);  //Start-tab view
+    void on_comboBoxTopCategory_currentIndexChanged(QString category);          //Top-tab view
+    void on_listViewStartTabAccelerationCategories_clicked(QModelIndex index);  //Start-tab view
+    void updateComboBoxStartTabUnits(QString unit);     //Start-tab view
     void openResultView();
-    void on_buttonTopRefresh_clicked(); //Top-tab view: button
-    void on_autoStartButton_clicked();  //Start-tab view: button
-    void registrate();
-    void sendResultXml();
-    void requestTopList(QString category, QString limit);
-    void requestCategories();
-    void ackOfResult();
-    void ackOfRegistration();
-    void ackOfCategories();
-    void ackOfToplist();
-    void errorFromServer(QNetworkReply::NetworkError);
+    void on_buttonTopRefresh_clicked();                 //Top-tab view: button
+    void on_autoStartButton_clicked();                  //Start-tab view: button
     void after_timeout();
     void updateUserName();
+    void regUserToServer();
 };
 
 #endif // CARMAINWINDOW_H
index 79231a1..ea44e7a 100644 (file)
@@ -1,12 +1,18 @@
+#include <QString>
+#include <QMessageBox>
 #include "httpclient.h"
+#include "carmainwindow.h"
 
 /**
   *@brief Constructor, connects object to GUI
   *@param Pointer to carmainwindow, which is temporarily used during development
   */
-HttpClient::HttpClient()
+HttpClient::HttpClient(CarMainWindow *myCarw)
 {
+    myMainw = myCarw;
     netManager = new QNetworkAccessManager();
+    myXmlwriter = new XmlWriter();
+    myXmlreader = new XmlReader();
 }
 
 /**
@@ -16,3 +22,232 @@ HttpClient::~HttpClient()
 {
 
 }
+
+/**
+  *@brief Sends registration information to the server in xml format.
+  *Reads user name, password and emaol address from resuldialogs internal variables.
+  *@todo Replace msg box with better reaction to server`s responce.
+  */
+void HttpClient::requestRegistration()
+{
+    qDebug() << "_requestRegistration" ;
+    qDebug() <<  myMainw->myRegistration->getUserName() << "+" <<  myMainw->myRegistration->getPassword() << "+" <<  myMainw->myRegistration->getEmail();
+
+    QBuffer *regbuffer = new QBuffer();
+    QUrl qurl("http://api.speedfreak-app.com/api/register");
+    QNetworkRequest request(qurl);
+    qDebug() << qurl.toString();
+    QNetworkReply *currentDownload;
+
+    regbuffer->open(QBuffer::ReadWrite);
+    myXmlwriter->writeRegistering(regbuffer,
+                       myMainw->myRegistration->getUserName(),
+                       myMainw->myRegistration->getPassword(),
+                       myMainw->myRegistration->getEmail());
+    qDebug() << "carmainwindow: regbuffer->data(): " << regbuffer->data();
+
+    currentDownload = netManager->post(request, ("xml=" + regbuffer->data()));
+    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRegistration()));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+
+    regbuffer->close();
+}
+
+/**
+  *@brief Sends result(s) to the server in xml format.
+  *Send authentication information in the header.
+  *@todo Read category elsewhere.
+  */
+void HttpClient::sendResultXml()
+{
+    qDebug() << "_sendResultXml";
+
+    QBuffer *xmlbuffer = new QBuffer();
+    QString category_name = "acceleration-0-100";    //replace with real value from category list
+
+    QUrl qurl("http://api.speedfreak-app.com/api/update/" + category_name);
+    qDebug() << qurl.toString();
+    QNetworkRequest request(qurl);
+    QNetworkReply *currentDownload;
+
+    xmlbuffer->open(QBuffer::ReadWrite);
+    myXmlwriter->writeResult(xmlbuffer);
+    qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
+
+    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    credentials = "Basic " + credentials.toAscii().toBase64();
+    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+
+    currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
+    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfResult()));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+
+    xmlbuffer->close();
+}
+
+/**
+  *@brief Request the Top10List of certain category from the server.
+  *Send authentication information in the header.
+  *@param Category of results.
+  *@param Limit, the number of results.
+  */
+void HttpClient::requestTopList(QString category, QString limit)
+{
+    qDebug() << "_requestTopList" ;
+
+    QString urlBase = "http://api.speedfreak-app.com/api/results/";
+    QUrl qurl(urlBase + category + "/" + limit);
+    qDebug() << qurl.toString();
+    QNetworkRequest request(qurl);
+    QNetworkReply *currentDownload;
+
+    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    credentials = "Basic " + credentials.toAscii().toBase64();
+    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+
+    currentDownload = netManager->post(request, ("data=" ));
+    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfToplist()));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+}
+
+
+/**
+  *@brief Request categories list from the server.
+  *Send authentication information in the header.
+  */
+void HttpClient::requestCategories()
+{
+    qDebug() << "_requestCategories" ;
+
+    QUrl qurl("http://api.speedfreak-app.com/api/categories/");
+    qDebug() << qurl.toString();
+    QNetworkRequest request(qurl);
+    QNetworkReply *currentDownload;
+
+    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    credentials = "Basic " + credentials.toAscii().toBase64();
+    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+
+    currentDownload = netManager->post(request, ("data=" ));
+    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfCategories()));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+}
+
+
+/**
+  *@brief React to servers responce after result has been sent.
+  *@todo Implement consequencies of reply.
+  */
+void HttpClient::ackOfResult()
+{
+    qDebug() << "_ackOfResult";
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
+    QNetworkReply::NetworkError errorcode;
+    errorcode = reply->error();
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to result sending ",reply->errorString());
+    }
+    else {
+        qDebug() << "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
+    }
+
+}
+
+
+/**
+  *@brief React to servers responce after registration has been sent.
+  *@todo Implement consequencies of reply.
+  */
+void HttpClient::ackOfRegistration()
+{
+    qDebug() << "_ackOfRegistration";
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
+    QNetworkReply::NetworkError errorcode;
+    errorcode = reply->error();
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to registration",reply->readAll());
+    }
+    else {
+        qDebug() << "errorcode=0" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to registration", "User registration " + reply->readAll());
+    }
+
+}
+
+
+/**
+  *@brief React to servers responce after request for categories has been sent.
+  */
+void HttpClient::ackOfCategories()
+{
+    qDebug() << "_ackOfCategories";
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+    myXmlreader->xmlReadCategories(reply);
+
+    QNetworkReply::NetworkError errorcode;
+    errorcode = reply->error();
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to requesting categories",reply->errorString());
+    }
+    else {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
+    }
+
+}
+
+/**
+  *@brief Reports errors, when server has sent error signal.
+  */
+void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode)
+{
+    qDebug() << "_errorFromServer";
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode;
+        //Note that errors are already reported on other ach-functions for server communication
+        //QMessageBox::about(myMainw, "Server reported an error", reply->errorString());
+    }
+    else {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
+    }
+
+}
+
+
+/**
+  *@brief React to servers responce after request of TopList in certain category has been sent.
+  *@todo Implement routing reply`s contents to UI.
+  */
+void HttpClient::ackOfToplist()
+{
+    qDebug() << "_ackOfToplist";
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+    myXmlreader->xmlReadTop10Results(reply);
+
+    QNetworkReply::NetworkError errorcode;
+    errorcode = reply->error();
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to requesting top 10 list",reply->errorString());
+    }
+    else {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        qDebug() << reply->readAll();
+    }
+
+}
+
index 0ade96c..f01f23b 100644 (file)
 #include <QNetworkAccessManager>
 #include <QNetworkRequest>
 #include <QNetworkReply>
+#include "xmlwriter.h"
+#include "xmlreader.h"
+class CarMainWindow;
+
 
 
 class HttpClient : public QObject
 {
     Q_OBJECT
 public:
-    HttpClient();
+    HttpClient(CarMainWindow *myCarw);
     ~HttpClient();
 
 private:
+    CarMainWindow *myMainw;
     QNetworkAccessManager *netManager;
+    XmlWriter *myXmlwriter;
+    XmlReader *myXmlreader;
 
 public slots:
+    void requestRegistration();
+    void sendResultXml();
+    void requestTopList(QString category, QString limit);
+    void requestCategories();
+    void ackOfResult();
+    void ackOfRegistration();
+    void ackOfCategories();
+    void ackOfToplist();
+    void errorFromServer(QNetworkReply::NetworkError);
 
 };
 
index 2b1c463..dac4d62 100644 (file)
@@ -91,7 +91,8 @@ void XmlWriter::writeResult(QBuffer *netbuf)
   *@param email.
   *@todo Replace hardcoced filename to finally GUI entry widget.
   */
-void XmlWriter::writeXml(QString usr, QString psswd, QString email)
+//void XmlWriter::writeXml(QString usr, QString psswd, QString email)
+void XmlWriter::writeXml()
 {
     QString filename = "xmlcategoryfile.xml";
     QFile file(filename);
index e24a60a..89a6ad0 100644 (file)
@@ -38,7 +38,8 @@ public slots:
     void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
     void writeResult(QBuffer *netbuf);
     bool writeXmlFile(QIODevice *device);
-    void writeXml(QString usr, QString psswd, QString email);
+    //void writeXml(QString usr, QString psswd, QString email);
+    void writeXml();
     void writeItems();
     void serverWritesXml();