From e94a4eed987de3e484b85284f2d70ebc03e74727 Mon Sep 17 00:00:00 2001 From: "tiina.kivilinna-korhola@windowslive.com" Date: Mon, 8 Mar 2010 00:30:53 +0200 Subject: [PATCH] Added functions for sending registration and results to the server. Added a tmp callback() for development. --- Client/carmainwindow.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++-- Client/carmainwindow.h | 14 +++++- Client/carmainwindow.ui | 4 +- 3 files changed, 121 insertions(+), 7 deletions(-) diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index 67be42d..167bf33 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -27,8 +27,12 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca myLogin = new LoginWindow(this); myRegistration = new Registration(this); + xmlwriter = new XmlWriter(); manager = new QNetworkAccessManager(this); connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*))); + connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(registrate())); + connect(result,SIGNAL(sendresult()),this,SLOT(sendXml())); + } /** @@ -40,6 +44,8 @@ CarMainWindow::~CarMainWindow() delete result; delete measure; delete xmlreader; + delete xmlwriter; + delete manager; } /** @@ -183,17 +189,16 @@ void CarMainWindow::openResultView() */ void CarMainWindow::networkResponse(QNetworkReply *reply) { + } /** *This slot function is called when the user will to send data to server. + *@todo Where is this callback connected? */ void CarMainWindow::on_pushButton_clicked() { - QNetworkRequest postData; - postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c")); - manager->get(postData); - + sendXml(); } /** @@ -251,3 +256,100 @@ void CarMainWindow::on_setUserPushButton_clicked() ui->userNameLabel->setText( "User: " + myLogin->getUserName()); ui->setUserPushButton->setText( "Change User"); } + +/** + *@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. + *@todo Write error handling. + */ +void CarMainWindow::registrate() +{ + qDebug() << "_registrate" ; + qDebug() << this->myRegistration->getUserName() << "+" << this->myRegistration->getPassword() << "+" << this->myRegistration->getEmail(); + + QBuffer *regbuffer = new QBuffer(); + + QNetworkReply *currentDownload; + + QUrl qurl("http//:api.speedfreak-app.com/register"); + QNetworkRequest request(qurl); + + //write also to a file during development, : + xmlwriter->writeXml(this->myRegistration->getUserName(), + this->myRegistration->getPassword(), + this->myRegistration->getEmail()); + xmlwriter->writeRegistering(regbuffer, + 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, ("data=" + regbuffer->data())); + + //ackFromServer function gets called when HTTP request is completed + connect(currentDownload, SIGNAL(finished()),SLOT(ackOfRegistration())); +} + +/** + *@brief Sends result(s) to the server in xml format with authentication information in the header. + *@todo Write error handling. + */ +void CarMainWindow::sendXml() +{ + qDebug() << "_sendXml"; + + QBuffer *xmlbuffer = new QBuffer(); + QNetworkReply *currentDownload; + + QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword(); + credentials = "Basic " + credentials.toAscii().toBase64(); + + QUrl qurl("http//:api.speedfreak-app.com/update/acceleration-0-40"); + QNetworkRequest request(qurl); + + request.setRawHeader(QByteArray("Authorization"),credentials.toAscii()); + + xmlwriter->writeResult(xmlbuffer); + + currentDownload = manager->post(request, ("data=" + xmlbuffer->data())); + //QString data("abcdefg"); //testing + //currentDownload = manager->post(request,"data=" + QUrl::toPercentEncoding(data)); //testing + + + //ackFromServer function gets called when HTTP request is completed + connect(currentDownload, SIGNAL(finished()),SLOT(ackOfResult())); + +} + +/** + *@brief React to servers responce after result has been sent. + *@todo Implement function and write error handling. + */ +void CarMainWindow::ackOfResult() +{ + qDebug() << "Server acknowledged posting of result"; +} + +/** + *@brief React to servers responce after registration has been sent. + *@todo Implement function and write error handling. + */ + +void CarMainWindow::ackOfRegistration() +{ + qDebug() << "Server acknowledged registration"; +} + + +/** + *@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. + */ + +void CarMainWindow::on_manualStartButton_clicked() +{ + sendXml(); +} diff --git a/Client/carmainwindow.h b/Client/carmainwindow.h index 89868c6..dfb2402 100644 --- a/Client/carmainwindow.h +++ b/Client/carmainwindow.h @@ -18,12 +18,18 @@ #include #include #include -#include #include +#include +#include +#include +#include +#include +#include #include "resultdialog.h" #include "measuredialog.h" #include "loginwindow.h" #include "registration.h" +#include "xmlwriter.h" #include "xmlreader.h" #include "ui_carmainwindow.h" #include "stringlistmodel.h" @@ -51,6 +57,7 @@ private: ResultDialog *result; MeasureDialog *measure; XmlReader *xmlreader; + XmlWriter *xmlwriter; QNetworkAccessManager* manager; LoginWindow *myLogin; Registration *myRegistration; @@ -64,6 +71,7 @@ private: QStringList categories; //Top-tab view private slots: + void on_manualStartButton_clicked(); void on_setUserPushButton_clicked(); void on_registratePushButton_clicked(); void on_loginLogoutButton_clicked(); @@ -76,6 +84,10 @@ private slots: void openResultView(); void on_buttonTopRefresh_clicked(); //Top-tab view: button void on_autoStartButton_clicked(); //Start-tab view: button + void registrate(); + void sendXml(); + void ackOfResult(); + void ackOfRegistration(); }; #endif // CARMAINWINDOW_H diff --git a/Client/carmainwindow.ui b/Client/carmainwindow.ui index 0df2dae..1ccc396 100644 --- a/Client/carmainwindow.ui +++ b/Client/carmainwindow.ui @@ -24,7 +24,7 @@ - 2 + 0 @@ -311,7 +311,7 @@ 0 0 800 - 25 + 27 -- 1.7.9.5