From 28d7fdcbf1646f7b175907bf79718d7495ee7935 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Janne=20=C3=84n=C3=A4kk=C3=A4l=C3=A4?= Date: Thu, 27 May 2010 11:05:07 +0300 Subject: [PATCH 1/1] Added error handling to listing of users and showing of user information. --- Client/httpclient.cpp | 44 ++++++++++++++++++++++++++++++-------------- Client/usersdialog.cpp | 5 +++++ Client/usersdialog.h | 1 + Client/usersdialog.ui | 13 +++++++++++++ 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index d5049fd..e43f761 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -636,12 +636,27 @@ void HttpClient::ackOfUserInfo() file.close();*/ QNetworkReply* reply = qobject_cast(sender()); - myXmlreader->xmlReadUserInfo(reply); + //myXmlreader->xmlReadUserInfo(reply); //for(int i = 0; i < myXmlreader->usersList->count(); i++) //{ // myMainw->settingsDialog->sendUsernameToUsersDialog(myXmlreader->usersList->at(i)); //} + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories",reply->errorString()); + if(myMainw->usersDialog) + myMainw->usersDialog->setLabelInfoToUser("You're not logged! Please register or log in."); + } + else { + myXmlreader->xmlReadUserInfo(reply); + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK"); + if(myMainw->usersDialog) + myMainw->usersDialog->setLabelInfoToUser(""); + } } /** @@ -668,8 +683,8 @@ void HttpClient::requestUsers() //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError))); //Indicating user - //if(myMainw->topResultDialog) - //myMainw->topResultDialog->setLabelInfoToUser("Reguesting categories from server"); + if(myMainw->usersDialog) + myMainw->usersDialog->setLabelInfoToUser("Reguesting users from server"); //ackOfUsers(); } @@ -703,26 +718,27 @@ void HttpClient::ackOfUsers() // myMainw->topResultDialog->setLabelInfoToUser(""); QNetworkReply* reply = qobject_cast(sender()); - myXmlreader->xmlReadUsers(reply); + //myXmlreader->xmlReadUsers(reply); - for(int i = 0; i < myXmlreader->usersList->count(); i++) - { - myMainw->usersDialog->appendUserToList(myXmlreader->usersList->at(i)); - } - /* QNetworkReply::NetworkError errorcode; + QNetworkReply::NetworkError errorcode; errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories",reply->errorString()); - if(myMainw->topResultDialog) - myMainw->topResultDialog->setLabelInfoToUser("You're not logged! Please register or log in."); + if(myMainw->usersDialog) + myMainw->usersDialog->setLabelInfoToUser("You're not logged! Please register or log in."); } else { + myXmlreader->xmlReadUsers(reply); qDebug() << "errorcode:" << errorcode << reply->errorString(); //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK"); - if(myMainw->topResultDialog) - myMainw->topResultDialog->setLabelInfoToUser(""); - }*/ + if(myMainw->usersDialog) + myMainw->usersDialog->setLabelInfoToUser(""); + for(int i = 0; i < myXmlreader->usersList->count(); i++) + { + myMainw->usersDialog->appendUserToList(myXmlreader->usersList->at(i)); + } + } } /** diff --git a/Client/usersdialog.cpp b/Client/usersdialog.cpp index 2d7186c..c61c5d1 100644 --- a/Client/usersdialog.cpp +++ b/Client/usersdialog.cpp @@ -86,3 +86,8 @@ void UsersDialog::setUserInfo(QStringList *usersInfo) } //ui->labelDescriptionHeader->setText("Description: " + usersInfo->at(4)); } + +void UsersDialog::setLabelInfoToUser(QString infoText) +{ + this->ui->labelInfoToUser->setText(infoText); +} diff --git a/Client/usersdialog.h b/Client/usersdialog.h index 91e3a82..db291f9 100644 --- a/Client/usersdialog.h +++ b/Client/usersdialog.h @@ -15,6 +15,7 @@ public: ~UsersDialog(); void appendUserToList(QString usrname); void setUserInfo(QStringList *usersInfo); + void setLabelInfoToUser(QString infoText); protected: void changeEvent(QEvent *e); diff --git a/Client/usersdialog.ui b/Client/usersdialog.ui index 64b7bf8..f716fe4 100644 --- a/Client/usersdialog.ui +++ b/Client/usersdialog.ui @@ -177,6 +177,19 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 10 + 320 + 671 + 51 + + + + Info label + + -- 1.7.9.5