From: Janne Änäkkälä Date: Wed, 26 May 2010 11:43:20 +0000 (+0300) Subject: Added functionality for other users listing and viewing other users info. X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=59de9b60440202c309876b262006aae88c7fa5ec Added functionality for other users listing and viewing other users info. --- diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index f200355..08e1695 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -25,6 +25,7 @@ HttpClient::HttpClient(MainWindow *myCarw) netManager = new QNetworkAccessManager(); myXmlwriter = new XmlWriter(); myXmlreader = new XmlReader(); + connect(myXmlreader, SIGNAL(userInfo(QStringList*)), this, SLOT(sendUsersInfo(QStringList*))); } /** @@ -574,3 +575,145 @@ void HttpClient::ackOfSendingPicture() } } } + +/** + *@brief Request the user information of certain user from the server. + *Send authentication information in the header. + *@param username which information we want. + */ +void HttpClient::requestUserInfo(QString username) +{ + qDebug() << "_requestUsersInfo" ; + + QUrl qurl("http://speedfreak-app.com/users/info/" + username); + qDebug() << qurl.toString(); + QNetworkRequest request(qurl); + QNetworkReply *currentDownload; + + 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(ackOfUserInfo())); + + //qDebug() << "requestUserInfo"; + //ackOfUserInfo(); +} + +/** + *@brief React to servers responce after request the user information of certain user. + */ +void HttpClient::ackOfUserInfo() +{ + qDebug() << "ackUserInfo"; + /*QString fileName = "user.xml"; + QFile file(fileName); + //file.setFileName( "routetemp.xml"); + if (!file.open(QFile::ReadOnly)) + { + qDebug() << "_xmlShow fail"; + return; + } + + myXmlreader->xmlReadUserInfo(&file); + file.close();*/ + + QNetworkReply* reply = qobject_cast(sender()); + myXmlreader->xmlReadUserInfo(reply); + + //for(int i = 0; i < myXmlreader->usersList->count(); i++) + //{ + // myMainw->settingsDialog->sendUsernameToUsersDialog(myXmlreader->usersList->at(i)); + //} +} + +/** + *@brief Request the users list of all users from the server. + *Send authentication information in the header. + */ +void HttpClient::requestUsers() +{ + qDebug() << "_requestUsers" ; + + QUrl qurl("http://www.speedfreak-app.com/users/list_all"); + qDebug() << qurl.toString(); + QNetworkRequest request(qurl); + QNetworkReply *currentDownload; + + 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(ackOfUsers())); + + + //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError))); + + //Indicating user + //if(myMainw->topResultDialog) + //myMainw->topResultDialog->setLabelInfoToUser("Reguesting categories from server"); + + //ackOfUsers(); +} + +/** + *@brief React to servers responce after request the users list of all users. + */ +void HttpClient::ackOfUsers() +{ + qDebug() << "ackUsers"; + /* QString fileName = "jtn.xml"; + QFile file(fileName); + //file.setFileName( "routetemp.xml"); + if (!file.open(QFile::ReadOnly)) + { + qDebug() << "_xmlShow fail"; + return; + } + + myXmlreader->xmlReadUsers(&file); + file.close(); + + for(int i = 0; i < myXmlreader->usersList->count(); i++) + { + myMainw->settingsDialog->sendUsernameToUsersDialog(myXmlreader->usersList->at(i)); + }*/ + + qDebug() << "ackUsers"; + + //if(myMainw->topResultDialog) + // myMainw->topResultDialog->setLabelInfoToUser(""); + + QNetworkReply* reply = qobject_cast(sender()); + myXmlreader->xmlReadUsers(reply); + + for(int i = 0; i < myXmlreader->usersList->count(); i++) + { + myMainw->usersDialog->appendUserToList(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->topResultDialog) + myMainw->topResultDialog->setLabelInfoToUser("You're not logged! Please register or log in."); + } + else { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK"); + if(myMainw->topResultDialog) + myMainw->topResultDialog->setLabelInfoToUser(""); + }*/ +} + +/** + * This slot function called when userInfo signal is emitted from xmlreader. + *@param usersInfo includes information from certain user. + */ +void HttpClient::sendUsersInfo(QStringList* usersInfo) +{ + myMainw->usersDialog->setUserInfo(usersInfo); +} diff --git a/Client/httpclient.h b/Client/httpclient.h index 457f7b7..f0eed3f 100644 --- a/Client/httpclient.h +++ b/Client/httpclient.h @@ -52,6 +52,12 @@ public slots: void ackOfSendingPicture(); void errorFromServer(QNetworkReply::NetworkError); void sendProfileXml(); + void requestUserInfo(QString username); + void ackOfUserInfo(); + + void requestUsers(); + void ackOfUsers(); + void sendUsersInfo(QStringList* usersInfo); }; diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index 04aeb97..27a1f4b 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -34,6 +34,8 @@ MainWindow::MainWindow(QWidget *parent) : routeSaveDialog = NULL; topResultDialog = NULL; + usersDialog = NULL; + settingsDialog = new SettingsDialog; connect(settingsDialog, SIGNAL(sendregistration()), this, SLOT(clientRegUserToServer())); connect(settingsDialog, SIGNAL(userNameChanged()), this, SLOT(clientUserLogin())); @@ -429,3 +431,38 @@ void MainWindow::saveProfile() if(httpClient) httpClient->sendProfileXml(); } + +/** + * This slot function calls httpClients requestUserInfo for getting user's information from server. + */ +void MainWindow::requestGetUserInfo(QString name) +{ + qDebug() << "getUserInfo signal " + name; + if(httpClient) + { + httpClient->requestUserInfo(name); + } +} + +/** + * This slot function calls httpClients requestUsers for getting usernames from server. + */ +void MainWindow::requestGetUsers() +{ + qDebug() << "getUsers signal"; + if(httpClient) + { + httpClient->requestUsers(); + } +} + +void MainWindow::on_pushButtonUsers_clicked() +{ + if(!usersDialog) + usersDialog = new UsersDialog; + + connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString))); + //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers())); + requestGetUsers(); + usersDialog->show(); +} diff --git a/Client/mainwindow.h b/Client/mainwindow.h index 509809d..9a5854e 100644 --- a/Client/mainwindow.h +++ b/Client/mainwindow.h @@ -27,6 +27,7 @@ #include "resultdialog.h" #include "helpdialog.h" #include "custombutton.h" +#include "usersdialog.h" namespace Ui { @@ -48,6 +49,7 @@ public: TopResultDialog *topResultDialog; HttpClient *httpClient; HelpDialog *helpDialog; + UsersDialog *usersDialog; protected: void changeEvent(QEvent *e); @@ -64,6 +66,7 @@ private: CustomButton* customButtonHelp; private slots: + void on_pushButtonUsers_clicked(); void clientRequestCategoryList(); void clientRequestTopList(int index); void clientSendRoute(QString,QString,int); @@ -81,6 +84,8 @@ private slots: void OpenWWWPage(); void OpenHelpDialog(); void OpenSettingsDialog(); + void requestGetUserInfo(QString); + void requestGetUsers(); }; #endif // MAINWINDOW_H diff --git a/Client/mainwindow.ui b/Client/mainwindow.ui index 4ad8998..84af0cd 100644 --- a/Client/mainwindow.ui +++ b/Client/mainwindow.ui @@ -33,6 +33,19 @@ true + + + + 170 + 20 + 93 + 27 + + + + Users + + diff --git a/Client/xmlreader.cpp b/Client/xmlreader.cpp index 9c7766b..3341edf 100644 --- a/Client/xmlreader.cpp +++ b/Client/xmlreader.cpp @@ -19,6 +19,8 @@ XmlReader::XmlReader() { qDebug() << "__XmlReader"; myCategoryList = new CategoryList(); + usersList = NULL; + usersInfo = new QStringList(); } /** @@ -263,3 +265,116 @@ void XmlReader::xmlReadProfile(QIODevice *device, ProfileDialog *profileDialog) } profile = NULL; } + +/** + *This function is used to parse user's info of a certain username. + */ +//void XmlReader::xmlReadUserInfo(QIODevice *device) +void XmlReader::xmlReadUserInfo(QNetworkReply *device) +{ + /* + + */ + + /* + */ + + usersInfo->clear(); + xmlreader.clear(); + QByteArray array = device->readAll(); + qDebug() << "array: " << array; + xmlreader.addData(array); + + while(!xmlreader.atEnd()) + { + //Read next node + xmlreader.readNext(); + + //Check if this element is starting element + if(xmlreader.isStartElement()) + { + if(xmlreader.name() == "user") + { + qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + QString data; + data = attr.value("login").toString(); + qDebug() << "user: " << data; + usersInfo->append(data); + data = attr.value("description").toString(); + qDebug() << "description: " << data; + usersInfo->append(data); + + /*data = attr.value("type").toString(); + qDebug() << "type: " << data; + usersInfo.append(data); + data = attr.value("model").toString(); + qDebug() << "model: " << data; + usersInfo.append(data); + data = attr.value("description").toString(); + qDebug() << "description: " << data; + usersInfo.append(data);*/ + //usersList->append(username); + } + } + } + qDebug() << "__emit"; + emit userInfo(usersInfo); +} + +/** + *This function is used to parse usernames. + */ +void XmlReader::xmlReadUsers(QNetworkReply *device) +//void XmlReader::xmlReadUsers(QIODevice *device) +{ + /* + + + + */ + + xmlreader.clear(); + QByteArray array = device->readAll(); + qDebug() << "array: " << array; + xmlreader.addData(array); + //Go trough the xml document + + if (!usersList) + { + usersList = new QStringList(); + qDebug() << "userlist luodaan"; + } + + else + { + usersList->clear(); + qDebug() << "userlist tyhjennetaan"; + } + + while(!xmlreader.atEnd()) + { + //Read next node + xmlreader.readNext(); + qDebug() << xmlreader.name(); + + //Check if this element is starting element + if(xmlreader.isStartElement()) + { + if (xmlreader.name() == "user") + { + qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + QString username; + QString description; + username = attr.value("login").toString(); + description = attr.value("description").toString(); + qDebug() << "user: " << username; + qDebug() << "description: " << description; + usersList->append(username); + } + } + } +} diff --git a/Client/xmlreader.h b/Client/xmlreader.h index 6ba8f66..6dbab29 100644 --- a/Client/xmlreader.h +++ b/Client/xmlreader.h @@ -24,6 +24,7 @@ public: ~XmlReader(); CategoryList *myCategoryList; void xmlReadProfile(QIODevice *device, ProfileDialog *profileDialog); + QStringList *usersList; private: QXmlStreamReader xmlreader; @@ -36,16 +37,23 @@ private: QString user; QString value; QString description; + QStringList *usersInfo; signals: void receivedCategoryList(); void receivedTop10List(); + void userInfo(QStringList *userInfo); public slots: void xmlReadTop10Results(QNetworkReply *device, QString userName); void xmlReadCategories(QNetworkReply *device); //void xmlReadCategories(QIODevice *device); void xmlShow(); + + //void xmlReadUserInfo(QIODevice *device); + void xmlReadUserInfo(QNetworkReply *device); + void xmlReadUsers(QNetworkReply *device); + //void xmlReadUsers(QIODevice *device); }; #endif // XMLREADER_H