X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Fhttpclient.cpp;h=8cc9a7958c8ed05fcf0c53772b46d86384291a8b;hp=750aa42810744c1ad8cd650471fa63b08f368840;hb=d07fff46e25495a5e3737804e4217ad363b4a040;hpb=92119e4b7587534a8de1e117b1fea4c016f3fcd7 diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index 750aa42..8cc9a79 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -1,14 +1,14 @@ #include #include #include "httpclient.h" -#include "carmainwindow.h" +#include "mainwindow.h" /** *@brief Constructor, connects object to GUI *@param Pointer to carmainwindow, which is temporarily used during development */ -HttpClient::HttpClient(CarMainWindow *myCarw) +HttpClient::HttpClient(MainWindow *myCarw) { myMainw = myCarw; netManager = new QNetworkAccessManager(); @@ -31,7 +31,7 @@ HttpClient::~HttpClient() void HttpClient::requestRegistration() { qDebug() << "_requestRegistration" ; - qDebug() << myMainw->myRegistration->getUserName() << "+" << myMainw->myRegistration->getPassword() << "+" << myMainw->myRegistration->getEmail(); + qDebug() << myMainw->settingsDialog->getRegUserName() << "+" << myMainw->settingsDialog->getRegPassword() << "+" << myMainw->settingsDialog->getRegEmail(); QBuffer *regbuffer = new QBuffer(); QUrl qurl("http://api.speedfreak-app.com/api/register"); @@ -41,15 +41,15 @@ void HttpClient::requestRegistration() regbuffer->open(QBuffer::ReadWrite); myXmlwriter->writeRegistering(regbuffer, - myMainw->myRegistration->getUserName(), - myMainw->myRegistration->getPassword(), - myMainw->myRegistration->getEmail()); + myMainw->settingsDialog->getRegUserName(), + myMainw->settingsDialog->getRegPassword(), + myMainw->settingsDialog->getRegEmail()); 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))); - myMainw->setLabelInfoToUser("Reguesting registration from server"); + //myMainw->setLabelInfoToUser("Reguesting registration from server"); regbuffer->close(); } @@ -58,7 +58,7 @@ void HttpClient::requestRegistration() *@brief Sends result(s) to the server in xml format. *Send authentication information in the header. */ -void HttpClient::sendResultXml(QString category) +void HttpClient::sendResultXml(QString category, double result) { qDebug() << "_sendResultXml"; @@ -70,17 +70,17 @@ void HttpClient::sendResultXml(QString category) QNetworkReply *currentDownload; xmlbuffer->open(QBuffer::ReadWrite); - myXmlwriter->writeResult(xmlbuffer); + myXmlwriter->writeResult(xmlbuffer, result); qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data(); - QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword(); + QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->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"); + //myMainw->setLabelInfoToUser("Sending result to server"); xmlbuffer->close(); } @@ -92,29 +92,30 @@ void HttpClient::sendResultXml(QString category) */ void HttpClient::sendRouteXml() { - qDebug() << "_sendResultXml"; + qDebug() << "_sendRouteXml"; - QBuffer *xmlbuffer = new QBuffer(); + QString filename = "route.xml"; + QFile file(filename); + if (!file.open(QFile::ReadOnly)) { + qDebug() << "_sendRouteXml file.open() fail"; + return; + } 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(); + QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword(); credentials = "Basic " + credentials.toAscii().toBase64(); request.setRawHeader(QByteArray("Authorization"),credentials.toAscii()); - currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data())); + currentDownload = netManager->post(request, ("xml=" + file.readAll())); connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute())); //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError))); - myMainw->setLabelInfoToUser("Sending route to server"); + //myMainw->setLabelInfoToUser("Sending route to server"); - xmlbuffer->close(); + file.close(); } /** @@ -133,14 +134,14 @@ void HttpClient::requestTopList(QString category, QString limit) QNetworkRequest request(qurl); QNetworkReply *currentDownload; - QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword(); + QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->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"); + //myMainw->setLabelInfoToUser("Reguesting top10 list from server"); } @@ -157,14 +158,14 @@ void HttpClient::requestCategories() QNetworkRequest request(qurl); QNetworkReply *currentDownload; - QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword(); + QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->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"); + //myMainw->setLabelInfoToUser("Reguesting categories from server"); } @@ -181,14 +182,14 @@ void HttpClient::checkLogin() QNetworkRequest request(qurl); QNetworkReply *currentDownload; - QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword(); + QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->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"); + //myMainw->setLabelInfoToUser("Checking login validity from server"); } @@ -199,7 +200,7 @@ void HttpClient::ackOfResult() { qDebug() << "_ackOfResult"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -207,11 +208,11 @@ void HttpClient::ackOfResult() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to result sending ",reply->errorString()); + //QMessageBox::about(myMainw, "Server reply to result sending ",reply->errorString()); } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll()); + //QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll()); } } @@ -222,7 +223,7 @@ void HttpClient::ackOfRoute() { qDebug() << "_ackOfRoute"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -230,11 +231,11 @@ void HttpClient::ackOfRoute() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to route sending ",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()); + //QMessageBox::about(myMainw, "Server reply to route sending", "Route received " + reply->readAll()); } } @@ -246,7 +247,7 @@ void HttpClient::ackOfRegistration() { qDebug() << "_ackOfRegistration"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -254,11 +255,11 @@ void HttpClient::ackOfRegistration() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to registration",reply->readAll()); + //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()); + //QMessageBox::about(myMainw, "Server reply to registration", "User registration " + reply->readAll()); } } @@ -270,7 +271,7 @@ void HttpClient::ackOfCategories() { qDebug() << "_ackOfCategories"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadCategories(reply); @@ -279,11 +280,11 @@ void HttpClient::ackOfCategories() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to requesting categories",reply->errorString()); + //QMessageBox::about(myMainw, "Server reply to requesting categories",reply->errorString()); } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to requesting categories ", "OK"); + //QMessageBox::about(myMainw, "Server reply to requesting categories ", "OK"); } } @@ -295,7 +296,7 @@ void HttpClient::ackOfLogin() { qDebug() << "_ackOffLogin"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -303,11 +304,11 @@ void HttpClient::ackOfLogin() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server does not recognize your username. Please registrate.",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()); + //QMessageBox::about(myMainw, "Server reply to login", "User login " + reply->readAll()); } } @@ -319,7 +320,7 @@ void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode) { qDebug() << "_errorFromServer"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -342,7 +343,7 @@ void HttpClient::ackOfToplist() { qDebug() << "_ackOfToplist"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadTop10Results(reply); @@ -351,11 +352,11 @@ void HttpClient::ackOfToplist() errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to requesting top 10 list",reply->errorString()); + //QMessageBox::about(myMainw, "Server reply to requesting top 10 list",reply->errorString()); } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - QMessageBox::about(myMainw, "Server reply to requesting top 10 list", "OK " + reply->readAll()); + //QMessageBox::about(myMainw, "Server reply to requesting top 10 list", "OK " + reply->readAll()); } }