From: Tiina Kivilinna-Korhola Date: Wed, 31 Mar 2010 06:53:20 +0000 (+0300) Subject: Connecting client-server communication to new GUI. X-Git-Tag: v0.2-RC1~21 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=9bcfcd7c2bf5ae2071d8d9d0d2242ab97789f78e;p=speedfreak Connecting client-server communication to new GUI. --- diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index 984a0db..8cc9a79 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -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(); } @@ -73,14 +73,14 @@ void HttpClient::sendResultXml(QString category, double result) 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(); } @@ -106,14 +106,14 @@ void HttpClient::sendRouteXml() 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, ("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"); file.close(); } @@ -134,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"); } @@ -158,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"); } @@ -182,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"); } @@ -200,7 +200,7 @@ void HttpClient::ackOfResult() { qDebug() << "_ackOfResult"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -208,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()); } } @@ -223,7 +223,7 @@ void HttpClient::ackOfRoute() { qDebug() << "_ackOfRoute"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -231,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()); } } @@ -247,7 +247,7 @@ void HttpClient::ackOfRegistration() { qDebug() << "_ackOfRegistration"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -255,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()); } } @@ -271,7 +271,7 @@ void HttpClient::ackOfCategories() { qDebug() << "_ackOfCategories"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadCategories(reply); @@ -280,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"); } } @@ -296,7 +296,7 @@ void HttpClient::ackOfLogin() { qDebug() << "_ackOffLogin"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -304,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()); } } @@ -320,7 +320,7 @@ void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode) { qDebug() << "_errorFromServer"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); @@ -343,7 +343,7 @@ void HttpClient::ackOfToplist() { qDebug() << "_ackOfToplist"; - myMainw->setLabelInfoToUser(""); + //myMainw->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); myXmlreader->xmlReadTop10Results(reply); @@ -352,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()); } } diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index a304463..d4df9c8 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -27,12 +27,16 @@ MainWindow::MainWindow(QWidget *parent) : creditsDialog = new CreditsDialog; routeSaveDialog = new RouteSaveDialog; settingsDialog = new SettingsDialog; + connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(regUserToServer())); + connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(userLogin())); topResultDialog = new TopResultDialog; connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList())); connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int))); accstart = NULL; httpClient = new HttpClient(this); + connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox())); + connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10())); welcomeDialog = new WelcomeDialog; welcomeDialog->show(); @@ -109,3 +113,47 @@ void MainWindow::clientRequestTopList(int index) QString limit = QString::number(topResultDialog->getLimitNr()); httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit); } + +/** + *This function is used to set items to category combobox. Top-tab view. + *@param + */ +void MainWindow::setCategoryCompoBox() +{ + qDebug() << "_setCategoryCompoBox"; + topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList()); +} + +/** + *This function prcesses UI updating after a new top10List has been received. + *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged. + */ +void MainWindow::showTop10() +{ + qDebug() << "_showTop10"; + int ind = topResultDialog->getRecentCategoryIndex(); + setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr()); +} + +/** + *This function is used to set items to labelTopList. Top-tab view. + *@param Category + *@param Size, number of results. + */ +void MainWindow::setListViewTopList(QString category, int size) +{ + qDebug() << "_setListViewTopList" << category; + QString topList; + topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size)); + topResultDialog->showTopList(topList); +} + +void MainWindow::regUserToServer() +{ + httpClient->requestRegistration(); +} + +void MainWindow::userLogin() +{ + httpClient->checkLogin(); +} diff --git a/Client/mainwindow.h b/Client/mainwindow.h index 8bd9d8c..f05a62c 100644 --- a/Client/mainwindow.h +++ b/Client/mainwindow.h @@ -45,6 +45,7 @@ protected: private: Ui::MainWindow *ui; + void setListViewTopList(QString category, int size); private slots: void on_pushButtonResults_clicked(); @@ -55,6 +56,10 @@ private slots: void on_pushButtonWWW_clicked(); void clientRequestCategoryList(); void clientRequestTopList(int index); + void setCategoryCompoBox(); + void showTop10(); + void regUserToServer(); + void userLogin(); }; #endif // MAINWINDOW_H diff --git a/Client/settingsdialog.cpp b/Client/settingsdialog.cpp index e44580d..e19e4e6 100644 --- a/Client/settingsdialog.cpp +++ b/Client/settingsdialog.cpp @@ -7,6 +7,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : { ui->setupUi(this); this->setWindowTitle("Settings"); + this->ui->regEMailLineEdit->setText("@meili.fi"); instructionsDialog = new InstructionsDialog; } @@ -45,7 +46,7 @@ void SettingsDialog::on_registratePushButton_clicked() this->regPassword = ui->regPasswordLineEdit->text(); this->regEmail = ui->regEMailLineEdit->text(); - //emit sendregistration(); + emit sendregistration(); close(); } @@ -90,7 +91,7 @@ void SettingsDialog::on_setUserPushButton_clicked() this->username = ui->setUserUsernameLineEdit->text(); this->password = ui->setUserPasswordLineEdit->text(); - //emit userNameChanged(); + emit userNameChanged(); close(); } diff --git a/Client/settingsdialog.h b/Client/settingsdialog.h index de21746..09e76f4 100644 --- a/Client/settingsdialog.h +++ b/Client/settingsdialog.h @@ -25,6 +25,10 @@ public: QString getUserName(); QString getPassword(); +signals: + void sendregistration(); + void userNameChanged(); + protected: void changeEvent(QEvent *e);