X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=Client%2Fhttpclient.cpp;h=750aa42810744c1ad8cd650471fa63b08f368840;hb=bdc023af59fd2c9ca9f127e86db32eb326acecff;hp=ea44e7a676cc3936830f915412444de220068523;hpb=b5f6266e93bf1e41bfa6ad097a6fa8d8f96a2146;p=speedfreak diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index ea44e7a..750aa42 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -3,6 +3,7 @@ #include "httpclient.h" #include "carmainwindow.h" + /** *@brief Constructor, connects object to GUI *@param Pointer to carmainwindow, which is temporarily used during development @@ -26,7 +27,6 @@ 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() { @@ -49,6 +49,7 @@ void HttpClient::requestRegistration() 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))); + myMainw->setLabelInfoToUser("Reguesting registration from server"); regbuffer->close(); } @@ -56,16 +57,14 @@ void HttpClient::requestRegistration() /** *@brief Sends result(s) to the server in xml format. *Send authentication information in the header. - *@todo Read category elsewhere. */ -void HttpClient::sendResultXml() +void HttpClient::sendResultXml(QString category) { 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); + QUrl qurl("http://api.speedfreak-app.com/api/update/" + category); qDebug() << qurl.toString(); QNetworkRequest request(qurl); QNetworkReply *currentDownload; @@ -74,13 +73,46 @@ void HttpClient::sendResultXml() myXmlwriter->writeResult(xmlbuffer); qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data(); - QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword(); + QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->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))); + myMainw->setLabelInfoToUser("Sending result to server"); + + xmlbuffer->close(); +} + +/** + *@brief Sends route to the server in xml format. + *Send authentication information in the header. + *@todo Check destination URL. + */ +void HttpClient::sendRouteXml() +{ + qDebug() << "_sendResultXml"; + + QBuffer *xmlbuffer = new QBuffer(); + + QUrl qurl("http://api.speedfreak-app.com/api/update/route"); + qDebug() << qurl.toString(); + QNetworkRequest request(qurl); + QNetworkReply *currentDownload; + + xmlbuffer->open(QBuffer::ReadWrite); + myXmlwriter->writeGpsTrack(xmlbuffer, myMainw->gpsData->getGpsDataArray(), myMainw->gpsData->getRoundCounter()); + qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data(); + + QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->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(ackOfRoute())); + //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError))); + myMainw->setLabelInfoToUser("Sending route to server"); xmlbuffer->close(); } @@ -101,13 +133,14 @@ void HttpClient::requestTopList(QString category, QString limit) QNetworkRequest request(qurl); QNetworkReply *currentDownload; - QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword(); + QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->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))); + myMainw->setLabelInfoToUser("Reguesting top10 list from server"); } @@ -124,24 +157,50 @@ void HttpClient::requestCategories() QNetworkRequest request(qurl); QNetworkReply *currentDownload; - QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword(); + QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->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))); + myMainw->setLabelInfoToUser("Reguesting categories from server"); +} + + +/** + *@brief Check that username and password exist on the server. + *Send authentication information in the header. + */ +void HttpClient::checkLogin() +{ + qDebug() << "_checkLogin"; + + QUrl qurl("http://api.speedfreak-app.com/api/login/"); + qDebug() << qurl.toString(); + QNetworkRequest request(qurl); + QNetworkReply *currentDownload; + + QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword(); + credentials = "Basic " + credentials.toAscii().toBase64(); + request.setRawHeader(QByteArray("Authorization"),credentials.toAscii()); + + currentDownload = netManager->post(request, ("data=" )); + connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfLogin())); + //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError))); + myMainw->setLabelInfoToUser("Checking login validity from server"); } /** *@brief React to servers responce after result has been sent. - *@todo Implement consequencies of reply. */ void HttpClient::ackOfResult() { qDebug() << "_ackOfResult"; + myMainw->setLabelInfoToUser(""); + QNetworkReply* reply = qobject_cast(sender()); QNetworkReply::NetworkError errorcode; @@ -152,11 +211,32 @@ void HttpClient::ackOfResult() } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - qDebug() << reply->readAll(); + QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll()); } - } +/** + *@brief React to servers responce after route has been sent. + */ +void HttpClient::ackOfRoute() +{ + qDebug() << "_ackOfRoute"; + + myMainw->setLabelInfoToUser(""); + + QNetworkReply* reply = qobject_cast(sender()); + + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + QMessageBox::about(myMainw, "Server reply to route sending ",reply->errorString()); + } + else { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + QMessageBox::about(myMainw, "Server reply to route sending", "Route received " + reply->readAll()); + } +} /** *@brief React to servers responce after registration has been sent. @@ -166,6 +246,8 @@ void HttpClient::ackOfRegistration() { qDebug() << "_ackOfRegistration"; + myMainw->setLabelInfoToUser(""); + QNetworkReply* reply = qobject_cast(sender()); QNetworkReply::NetworkError errorcode; @@ -178,7 +260,6 @@ void HttpClient::ackOfRegistration() qDebug() << "errorcode=0" << errorcode << reply->errorString(); QMessageBox::about(myMainw, "Server reply to registration", "User registration " + reply->readAll()); } - } @@ -189,6 +270,8 @@ void HttpClient::ackOfCategories() { qDebug() << "_ackOfCategories"; + myMainw->setLabelInfoToUser(""); + QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadCategories(reply); @@ -200,11 +283,35 @@ void HttpClient::ackOfCategories() } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - qDebug() << reply->readAll(); + QMessageBox::about(myMainw, "Server reply to requesting categories ", "OK"); } +} + +/** + *@brief React to servers responce after request of TopList in certain category has been sent. + */ +void HttpClient::ackOfLogin() +{ + qDebug() << "_ackOffLogin"; + + myMainw->setLabelInfoToUser(""); + + QNetworkReply* reply = qobject_cast(sender()); + + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + QMessageBox::about(myMainw, "Server does not recognize your username. Please registrate.",reply->errorString()); + } + else { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + QMessageBox::about(myMainw, "Server reply to login", "User login " + reply->readAll()); + } } + /** *@brief Reports errors, when server has sent error signal. */ @@ -212,29 +319,31 @@ void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode) { qDebug() << "_errorFromServer"; + myMainw->setLabelInfoToUser(""); + QNetworkReply* reply = qobject_cast(sender()); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode; - //Note that errors are already reported on other ach-functions for server communication + //Note that errors are already reported on other each 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"; + myMainw->setLabelInfoToUser(""); + QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadTop10Results(reply); @@ -246,8 +355,7 @@ void HttpClient::ackOfToplist() } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - qDebug() << reply->readAll(); + QMessageBox::about(myMainw, "Server reply to requesting top 10 list", "OK " + reply->readAll()); } - }