X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=Client%2Fcarmainwindow.cpp;h=1d17649d807d91f48f82885362671b271404c0db;hb=8d87a577e3b6a4aaac96788d65b6656a151e1c30;hp=8464b27f900296d78e10013e11b4711dccb548b7;hpb=9a81bc8fe5cb944592f815192817c4056cb168d9;p=speedfreak diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index 8464b27..1d17649 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -30,9 +30,7 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca 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(this,SIGNAL(sendresult()),this,SLOT(sendXml())); time = 0; speed = 0; @@ -40,17 +38,19 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca accelerometer = new Accelerometer(); accelerometer->setSampleRate(100); - accelerometer->start(); measures = new Measures(); this->initializeMeasures(); - timer->setInterval(1000); + timer->setInterval(300); connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout())); + connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName())); ui->labelMeasureTabResult->hide(); + this->setWindowTitle("Speed freak"); + } /** @@ -106,6 +106,7 @@ void CarMainWindow::on_autoStartButton_clicked() //measure = NULL; //measure = new MeasureDialog(); // connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView())); + accelerometer->start(); timer->start(); // Show measure dialog. //measure->show(); @@ -212,34 +213,6 @@ void CarMainWindow::openResultView() } /** - *This slot function is called when the server has finished guery. - */ -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() -{ - sendXml(); -} - -/** - *This slot function is called when login/logout button is clicked. - */ -void CarMainWindow::on_loginLogoutButton_clicked() -{ - //LoginWindow myLogin; - - myLogin->show(); - //ui->loginLogoutButton->setText("logout"); -} - -/** *This slot function is called when registrate button is clicked. */ void CarMainWindow::on_registratePushButton_clicked() @@ -280,9 +253,6 @@ void CarMainWindow::on_comboBoxTopCategory_activated(QString category) void CarMainWindow::on_setUserPushButton_clicked() { myLogin->show(); - - ui->userNameLabel->setText( "User: " + myLogin->getUserName()); - ui->setUserPushButton->setText( "Change User"); } /** @@ -297,15 +267,11 @@ void CarMainWindow::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"); + QUrl qurl("http://api.speedfreak-app.com/api/register"); QNetworkRequest request(qurl); + qDebug() << qurl.toString(); - //write also to a file during development, : - xmlwriter->writeXml(this->myRegistration->getUserName(), - this->myRegistration->getPassword(), - this->myRegistration->getEmail()); + regbuffer->open(QBuffer::ReadWrite); xmlwriter->writeRegistering(regbuffer, this->myRegistration->getUserName(), this->myRegistration->getPassword(), @@ -313,16 +279,13 @@ void CarMainWindow::registrate() //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())); manager->post(request, ("data=" + regbuffer->data())); + qDebug() << "carmainwindow: regbuffer->data(): " << regbuffer->data(); //ackOfRegistration function gets called when HTTP request is completed - //connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfRegistration())); connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(ackOfRegistration(QNetworkReply*))); - connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); + //connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); + regbuffer->close(); } /** @@ -334,60 +297,64 @@ void CarMainWindow::sendXml() qDebug() << "_sendXml"; QBuffer *xmlbuffer = new QBuffer(); - QNetworkReply *currentDownload; - QString category_name = "acceleration-0-100"; //replace with real value from category list QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword(); credentials = "Basic " + credentials.toAscii().toBase64(); - QUrl qurl("http://api.speedfreak-app.com/update/category_name"); + QUrl qurl("http://api.speedfreak-app.com/api/update/" + category_name); + qDebug() << qurl.toString(); QNetworkRequest request(qurl); - request.setRawHeader(QByteArray("Authorization"),credentials.toAscii()); + xmlbuffer->open(QBuffer::ReadWrite); xmlwriter->writeResult(xmlbuffer); + qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data(); - //currentDownload = manager->post(request, ("data=" + xmlbuffer->data())); manager->post(request, ("data=" + xmlbuffer->data())); - //QString data("abcdefg"); //testing - //currentDownload = manager->post(request,"data=" + QUrl::toPercentEncoding(data)); //testing + //connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(ackOfResult(QNetworkReply*))); + //connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); + //QNetworkReply *currentDownload; + //QString data("abcdefg"); + //currentDownload = manager->post(request,"data=" + QUrl::toPercentEncoding(data)); //testing + //currentDownload = manager->post(request, ("data=" + xmlbuffer->data())); //ackOfResult function gets called when HTTP request is completed - //connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfResult())); - connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(ackOfResult(QNetworkReply*))); - connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); + //connect(currentDownload, SIGNAL(finished()), SLOT(ackOfResult())); + xmlbuffer->close(); } /** *@brief Sends request to the server for a top list with authentication information in the header. *@todo Write error handling. - *@todo Replace with real value from category list and limit + *@todo Replace with real value from category list and limitNr */ void CarMainWindow::requestTopList() { - qDebug() << "_registrate" ; + qDebug() << "_requestTopList" ; + QString urlBase = "http://api.speedfreak-app.com/api/results/"; QString category_name = "acceleration-0-100"; //replace with real value from category list/top window - int limit = 5; - //QNetworkReply *currentDownload; + int limitNr = 5; + QString limit = QString::number(limitNr); QString credentials = this->myRegistration->getUserName() + ":" + this->myRegistration->getPassword(); credentials = "Basic " + credentials.toAscii().toBase64(); - QUrl qurl("http://api.speedfreak-app.com/results/category_name/limit"); + QUrl qurl(urlBase + category_name + "/" + limit); + qDebug() << qurl.toString(); QNetworkRequest request(qurl); request.setRawHeader(QByteArray("Authorization"),credentials.toAscii()); - - //currentDownload = manager->post(request, ("data=" )); manager->post(request, ("data=" )); + //connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*))); + //connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); + //QNetworkReply *currentDownload; + //currentDownload = manager->post(request, ("data=" )); //ackOfResult function gets called when HTTP request is completed //connect(currentDownload, SIGNAL(error()),SLOT(errorFromServer())); - connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*))); - connect(manager,SIGNAL(sslErrors(QNetworkReply*)),this,SLOT(errorFromServer(QNetworkReply*))); } /** @@ -397,13 +364,14 @@ void CarMainWindow::requestTopList() void CarMainWindow::ackOfResult(QNetworkReply* reply) { qDebug() << "_ackOfResult"; + qDebug() << reply->readAll(); QNetworkReply::NetworkError errorcode; errorcode = reply->error(); if(errorcode != 0) { qDebug() << errorcode << reply->errorString(); } else { - qDebug() << errorcode; + qDebug() << "errorcode=0"; } } @@ -418,15 +386,13 @@ void CarMainWindow::ackOfRegistration(QNetworkReply* reply) QNetworkReply::NetworkError errorcode; errorcode = reply->error(); if(errorcode != 0) { - qDebug() << errorcode << reply->errorString(); + qDebug() << "errorcode:" << errorcode << reply->errorString(); } else { - qDebug() << errorcode; + qDebug() << "errorcode=0"; } } - - void CarMainWindow::errorFromServer(QNetworkReply* reply) { qDebug() << "_errorFromServer"; @@ -439,7 +405,24 @@ void CarMainWindow::errorFromServer(QNetworkReply* reply) else { qDebug() << errorcode; } +} +/** + *This slot function is called when the server has finished guery. + */ +void CarMainWindow::networkResponse(QNetworkReply *reply) +{ + qDebug() << "_networkResponse"; + xmlreader->xmlRead(reply); + qDebug() << reply->readAll(); + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << errorcode << reply->errorString(); + } + else { + qDebug() << "errorcode=0"; + } } /** @@ -587,5 +570,25 @@ void CarMainWindow::on_pushButtonMeasureTabAbort_clicked() void CarMainWindow::on_pushButtonSendResult_clicked() { - emit sendresult(); + sendXml(); + +} + +void CarMainWindow::updateUserName() +{ + QString newUserName; + + newUserName = myLogin->getUserName(); + ui->userNameLabel->setText( "User: " + newUserName); + + if (newUserName.length()) + { + ui->setUserPushButton->setText( "Change User"); + this->setWindowTitle("Speed freak - " + newUserName); + } + else + { + ui->setUserPushButton->setText( "Set User"); + this->setWindowTitle("Speed freak"); + } }