2 * Http client Connects application to server.
4 * @author Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
5 * @author Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
6 * @author Toni Jussila <toni.jussila@fudeco.com>
7 * @copyright (c) 2010 Speed Freak team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 #include <QMessageBox>
14 #include "httpclient.h"
15 #include "mainwindow.h"
18 * Constructor, connects object to GUI
20 * @param Pointer to carmainwindow, which is temporarily used during development
22 HttpClient::HttpClient(MainWindow *myCarw)
24 qDebug() << "__HttpClient";
26 netManager = new QNetworkAccessManager();
27 myXmlwriter = new XmlWriter();
28 myXmlreader = new XmlReader();
29 connect(myXmlreader, SIGNAL(userInfo(QStringList*)), this, SLOT(sendUsersInfo(QStringList*)));
35 HttpClient::~HttpClient()
37 qDebug() << "__~HttpClient" ;
46 * Sends registration information to the server in xml format.
47 * Reads user name, password and emaol address from resuldialogs internal variables.
49 void HttpClient::requestRegistration()
51 qDebug() << "_requestRegistration" ;
52 qDebug() << myMainw->settingsDialog->registerDialog->getRegUserName() << "+" << myMainw->settingsDialog->registerDialog->getRegPassword() << "+" << myMainw->settingsDialog->registerDialog->getRegEmail();
54 QBuffer *regbuffer = new QBuffer();
55 QUrl qurl("http://www.speedfreak-app.com/users/register");
56 QNetworkRequest request(qurl);
57 qDebug() << qurl.toString();
58 QNetworkReply *currentDownload;
60 regbuffer->open(QBuffer::ReadWrite);
62 // Without profile dialog
63 /*myXmlwriter->writeRegistering(regbuffer,
64 myMainw->settingsDialog->getRegUserName(),
65 myMainw->settingsDialog->getRegPassword(),
66 myMainw->settingsDialog->getRegEmail());*/
67 // With profile dialog
68 /*myXmlwriter->writeRegistering(regbuffer,
69 myMainw->settingsDialog->getRegUserName(),
70 myMainw->settingsDialog->getRegPassword(),
71 myMainw->settingsDialog->getRegEmail(),
72 myMainw->settingsDialog->profileDialog->getDescription());
73 myMainw->settingsDialog->profileDialog->getManufacturer(),
74 myMainw->settingsDialog->profileDialog->getType(),
75 myMainw->settingsDialog->profileDialog->getModel(),
76 myMainw->settingsDialog->profileDialog->getDescription(),
77 myMainw->settingsDialog->profileDialog->getPicture());*/
78 // New way: Registerdialog = register + Profiledialog
79 myXmlwriter->writeRegistering(regbuffer,
80 myMainw->settingsDialog->registerDialog->getRegUserName(),
81 myMainw->settingsDialog->registerDialog->getRegPassword(),
82 myMainw->settingsDialog->registerDialog->getRegEmail(),
83 myMainw->settingsDialog->registerDialog->getDescription());
85 qDebug() << "carmainwindow: regbuffer->data(): " << regbuffer->data();
87 // Registration with picture. Send picture to server
88 if(myMainw->settingsDialog->registerDialog->getPicture() != "" )//&& error == false)
90 qDebug() << "__Registration with picture";
91 QFile pictureFile( myMainw->settingsDialog->registerDialog->getPicture() );
92 if (!pictureFile.open(QIODevice::ReadOnly))
94 qDebug() << "__picture read fail";
97 //currentDownload = netManager->post(request, pictureFile.readAll());
98 currentDownload = netManager->post(request, ("xml=" + regbuffer->data(), "avatar=" + pictureFile.readAll()));
99 //connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfSendingPicture()));
102 // Registration Without picture
105 qDebug() << "____Registration without picture";
106 currentDownload = netManager->post(request, ("xml=" + regbuffer->data()));
109 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRegistration()));
110 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
113 if(myMainw->settingsDialog->registerDialog)
114 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Reguesting registration from server");
120 * Sends result(s) to the server in xml format.
121 * Send authentication information in the header.
123 void HttpClient::sendResultXml(QString category, double result)
125 qDebug() << "_sendResultXml";
126 qDebug() << category;
128 QBuffer *xmlbuffer = new QBuffer();
130 QUrl qurl("http://www.speedfreak-app.com/results/update/" + category);
132 qDebug() << qurl.toString();
133 QNetworkRequest request(qurl);
134 QNetworkReply *currentDownload;
136 xmlbuffer->open(QBuffer::ReadWrite);
137 myXmlwriter->writeResult(xmlbuffer, result);
138 qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
140 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
141 credentials = "Basic " + credentials.toAscii().toBase64();
142 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
144 currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
145 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfResult()));
146 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
149 if(myMainw->accstart->accRealTimeDialog->resultDialog)
150 myMainw->accstart->accRealTimeDialog->resultDialog->setLabelInfoToUser("Sending result to server");
156 * Sends route to the server in xml format.
157 * Send authentication information in the header.
159 * @param QString filename
160 * @param int 1(send to server) or 0(no send)
162 void HttpClient::sendRouteXml(QString oldName, QString newName, int i)
164 qDebug() << "_sendRouteXml";
166 //QString filename = "/home/user/MyDocs/speedfreak/route/route.xml";
167 qDebug() << "__old:" + oldName;
168 QString filename = newName; //+ ".xml";
172 qDebug() << "_rename xml";
174 qDebug() << "__new:" + filename;
175 qDebug() << dir.rename(oldName, filename);
180 qDebug() << "_send route";
181 QFile file(filename);
182 if (!file.open(QFile::ReadOnly))
184 qDebug() << "_sendRouteXml file.open() fail";
188 QUrl qurl("http://speedfreak-app.com/update/route");
189 qDebug() << qurl.toString();
190 QNetworkRequest request(qurl);
191 QNetworkReply *currentDownload;
193 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
194 credentials = "Basic " + credentials.toAscii().toBase64();
195 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
197 currentDownload = netManager->post(request, ("xml=" + file.readAll()));
198 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
199 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
202 if(myMainw->routeSaveDialog->routeDialog)
203 myMainw->routeSaveDialog->routeDialog->setLabelInfoToUser("Sending route to server");
210 * Request the Top10List of certain category from the server.
211 * Send authentication information in the header.
213 * @param Category of results.
214 * @param Limit, the number of results.
216 void HttpClient::requestTopList(QString category, QString limit)
218 qDebug() << "_requestTopList";
219 qDebug() << category;
221 QString urlBase = "http://www.speedfreak-app.com/results/list_results/";
222 QUrl qurl(urlBase + category + "/" + limit);
223 qDebug() << qurl.toString();
224 QNetworkRequest request(qurl);
225 QNetworkReply *currentDownload;
227 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
228 credentials = "Basic " + credentials.toAscii().toBase64();
229 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
231 currentDownload = netManager->post(request, ("data=" ));
232 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfToplist()));
233 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
236 if(myMainw->topResultDialog)
237 myMainw->topResultDialog->setLabelInfoToUser("Reguesting top10 list from server");
241 * Request categories list from the server.
242 * Send authentication information in the header.
244 void HttpClient::requestCategories()
246 qDebug() << "_requestCategories" ;
248 QUrl qurl("http://www.speedfreak-app.com/results/categories");
249 qDebug() << qurl.toString();
250 QNetworkRequest request(qurl);
251 QNetworkReply *currentDownload;
253 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
254 credentials = "Basic " + credentials.toAscii().toBase64();
255 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
257 currentDownload = netManager->post(request, ("data=" ));
258 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfCategories()));
259 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
262 if(myMainw->topResultDialog)
263 myMainw->topResultDialog->setLabelInfoToUser("Reguesting categories from server");
267 * Check that username and password exist on the server.
268 * Send authentication information in the header.
270 void HttpClient::checkLogin()
272 qDebug() << "_checkLogin";
274 QUrl qurl("http://www.speedfreak-app.com/users/login");
275 qDebug() << qurl.toString();
277 QNetworkRequest request(qurl);
278 QNetworkReply *currentDownload;
280 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
281 credentials = "Basic " + credentials.toAscii().toBase64();
282 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
284 currentDownload = netManager->post(request, ("data=" ));
285 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfLogin()));
286 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
289 if(myMainw->settingsDialog)
290 myMainw->settingsDialog->setLabelInfoToUser("Checking login validity from server");
294 * React to servers responce after result has been sent.
296 void HttpClient::ackOfResult()
298 qDebug() << "_ackOfResult";
301 if(myMainw->accstart->accRealTimeDialog->resultDialog)
302 myMainw->accstart->accRealTimeDialog->resultDialog->setLabelInfoToUser("");
304 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
306 QNetworkReply::NetworkError errorcode;
307 errorcode = reply->error();
309 qDebug() << "errorcode:" << errorcode << reply->errorString();
312 if(myMainw->accstart->accRealTimeDialog->resultDialog)
313 QMessageBox::about(myMainw->accstart->accRealTimeDialog->resultDialog, "Server reply to result sending ",reply->errorString());
314 if(myMainw->accstart->accRealTimeDialog->resultDialog)
315 myMainw->accstart->accRealTimeDialog->resultDialog->setLabelInfoToUser("Error");
316 if(myMainw->accstart->accRealTimeDialog->resultDialog)
317 myMainw->accstart->accRealTimeDialog->resultDialog->setSendServerButtonEnabled();
321 if(myMainw->accstart->accRealTimeDialog->resultDialog)
322 QMessageBox::about(myMainw->accstart->accRealTimeDialog->resultDialog, "Server reply to result sending", "Result received " + reply->readAll());
323 if(myMainw->accstart->accRealTimeDialog->resultDialog)
324 myMainw->accstart->accRealTimeDialog->resultDialog->setLabelInfoToUser("Result received");
329 * React to servers responce after route has been sent.
331 void HttpClient::ackOfRoute()
333 qDebug() << "_ackOfRoute";
335 if(myMainw->routeSaveDialog->routeDialog)
336 myMainw->routeSaveDialog->routeDialog->setLabelInfoToUser("");
338 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
340 QNetworkReply::NetworkError errorcode;
341 errorcode = reply->error();
343 qDebug() << "errorcode:" << errorcode << reply->errorString();
344 if(myMainw->routeSaveDialog->routeDialog)
345 QMessageBox::about(myMainw->routeSaveDialog->routeDialog, "Server reply to route sending ",reply->errorString());
346 if(myMainw->routeSaveDialog->routeDialog)
347 myMainw->routeSaveDialog->routeDialog->setSendServerButtonEnabled();
350 qDebug() << "errorcode:" << errorcode << reply->errorString();
351 if(myMainw->routeSaveDialog->routeDialog)
352 QMessageBox::about(myMainw->routeSaveDialog->routeDialog, "Server reply to route sending", "Route received " + reply->readAll());
357 * React to servers responce after registration has been sent.
359 void HttpClient::ackOfRegistration()
361 qDebug() << "_ackOfRegistration";
363 if(myMainw->settingsDialog)
364 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("");
366 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
368 QNetworkReply::NetworkError errorcode;
369 errorcode = reply->error();
371 qDebug() << "errorcode:" << errorcode << reply->errorString();
372 if(myMainw->settingsDialog->registerDialog)
373 QMessageBox::about(myMainw->settingsDialog->registerDialog, "Server reply to registration",reply->readAll());
376 qDebug() << "errorcode=0" << errorcode << reply->errorString();
377 if(myMainw->settingsDialog->registerDialog)
379 QMessageBox::about(myMainw->settingsDialog->registerDialog, "Server reply to registration", "User registration " + reply->readAll());
380 myMainw->settingsDialog->registerDialog->clearRegisterLineEdits();
386 * React to servers responce after request for categories has been sent.
388 void HttpClient::ackOfCategories()
390 qDebug() << "_ackOfCategories";
392 if(myMainw->topResultDialog)
393 myMainw->topResultDialog->setLabelInfoToUser("");
395 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
396 myXmlreader->xmlReadCategories(reply);
398 QNetworkReply::NetworkError errorcode;
399 errorcode = reply->error();
401 qDebug() << "errorcode:" << errorcode << reply->errorString();
402 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories",reply->errorString());
403 if(myMainw->topResultDialog)
404 myMainw->topResultDialog->setLabelInfoToUser("You're not logged! Please register or log in.");
407 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK");
408 if(myMainw->topResultDialog)
409 myMainw->topResultDialog->setLabelInfoToUser("");
414 * React to servers responce after request of TopList in certain category has been sent.
416 void HttpClient::ackOfLogin()
418 qDebug() << "_ackOffLogin";
420 if(myMainw->settingsDialog)
421 myMainw->settingsDialog->setLabelInfoToUser("");
423 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
425 QNetworkReply::NetworkError errorcode;
426 errorcode = reply->error();
429 qDebug() << "errorcode:" << errorcode << reply->errorString();
430 if(myMainw->settingsDialog)
432 QMessageBox::about(myMainw->settingsDialog, "Wrong username or password!","Please try again.");
433 myMainw->settingsDialog->usernameOk(false);
438 qDebug() << "errorcode:" << errorcode << reply->errorString();
439 if(myMainw->settingsDialog)
440 QMessageBox::about(myMainw->settingsDialog, "Server reply to login", "User login " + reply->readAll());
441 // here signal emit to mainwindow for username setting to main panel
443 if( myMainw->settingsDialog)
445 myMainw->settingsDialog->usernameOk(true);
446 myMainw->settingsDialog->close();
452 * Reports errors, when server has sent error signal.
454 void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode)
456 qDebug() << "_errorFromServer";
457 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
460 qDebug() << "errorcode:" << errorcode;
461 //Note that errors are already reported on other each functions for server communication
462 //QMessageBox::about(myMainw, "Server reported an error", reply->errorString());
465 qDebug() << "errorcode:" << errorcode << reply->errorString();
466 qDebug() << reply->readAll();
471 * React to servers responce after request of TopList in certain category has been sent.
473 void HttpClient::ackOfToplist()
475 qDebug() << "_ackOfToplist";
476 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
477 myXmlreader->xmlReadTop10Results(reply,myMainw->settingsDialog->getUserName());
479 QNetworkReply::NetworkError errorcode;
480 errorcode = reply->error();
482 qDebug() << "errorcode:" << errorcode << reply->errorString();
484 if(myMainw->topResultDialog)
486 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list",reply->errorString());
487 myMainw->topResultDialog->setLabelInfoToUser("No results ;(");
491 qDebug() << "errorcode:" << errorcode << reply->errorString();
493 if(myMainw->topResultDialog)
495 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list", "OK " + reply->readAll());
496 myMainw->topResultDialog->setLabelInfoToUser("");
502 * This function sends profile to the server in xml format.
503 * Send authentication information in the header.
505 void HttpClient::sendProfileXml()
507 qDebug() << "_sendProfileXml";
509 QString userName = myMainw->settingsDialog->getUserName();
510 QString filename = userName + "_profile.xml";
511 QFile file(filename);
512 if (!file.open(QFile::ReadWrite | QFile::Text))
514 qDebug() << "_xmlWrite fail";
517 myXmlwriter->writeProfileXmlFile(&file, userName,
518 myMainw->settingsDialog->registerDialog->getManufacturer(),
519 myMainw->settingsDialog->registerDialog->getType(),
520 myMainw->settingsDialog->registerDialog->getModel(),
521 myMainw->settingsDialog->registerDialog->getDescription(),
522 myMainw->settingsDialog->registerDialog->getPicture());
525 if(myMainw->settingsDialog->registerDialog)
526 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Profile saved to phone");
528 // Send xml to server
529 /*QUrl qurl("http://speedfreak-app.com/api/profile");
530 QNetworkRequest request(qurl);
531 qDebug() << qurl.toString();
532 QNetworkReply *currentDownload;
534 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
535 credentials = "Basic " + credentials.toAscii().toBase64();
536 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
538 currentDownload = netManager->post(request, ("xml=" + file.readAll()));
539 bool error = connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfProfile()));*/
543 // Send picture to server
544 /*if(myMainw->settingsDialog->profileDialog->getPicture() != "" && error == false)
546 QFile pictureFile( myMainw->settingsDialog->profileDialog->getPicture() );
547 if (!pictureFile.open(QIODevice::ReadOnly))
549 qDebug() << "__picture read fail";
552 currentDownload = netManager->post(request, pictureFile.readAll());
553 connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfSendingPicture()));
559 * This slot function react to servers responce after request of profile has been sent.
561 bool HttpClient::ackOfProfile()
563 qDebug() << "__ackOfProfile";
564 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
565 QNetworkReply::NetworkError errorcode;
566 errorcode = reply->error();
568 qDebug() << "errorcode:" << errorcode << reply->errorString();
570 if(myMainw->settingsDialog->registerDialog)
572 //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting profile",reply->errorString());
573 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Profile save to server - fail");
578 qDebug() << "errorcode:" << errorcode << reply->errorString();
580 if(myMainw->settingsDialog->registerDialog)
582 //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting profile", "OK " + reply->readAll());
583 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Profile saved to server");
589 * This slot function react to servers responce after request of picture has been sent.
591 void HttpClient::ackOfSendingPicture()
593 qDebug() << "__ackOfSendingPicture";
594 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
595 QNetworkReply::NetworkError errorcode;
596 errorcode = reply->error();
598 qDebug() << "errorcode:" << errorcode << reply->errorString();
600 if(myMainw->settingsDialog->registerDialog)
602 //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting picture",reply->errorString());
603 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Picture save to server - fail");
607 qDebug() << "errorcode:" << errorcode << reply->errorString();
609 if(myMainw->settingsDialog->registerDialog)
611 //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting picture", "OK " + reply->readAll());
612 myMainw->settingsDialog->registerDialog->setLabelInfoToUser("Picture saved to server");
618 * Request the user information of certain user from the server.
619 * Send authentication information in the header.
621 * @param QString username which information we want.
623 void HttpClient::requestUserInfo(QString username)
625 qDebug() << "_requestUsersInfo" ;
627 QUrl qurl("http://speedfreak-app.com/users/info/" + username);
628 qDebug() << qurl.toString();
629 QNetworkRequest request(qurl);
630 QNetworkReply *currentDownload;
632 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
633 credentials = "Basic " + credentials.toAscii().toBase64();
634 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
636 currentDownload = netManager->post(request, ("data=" ));
637 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfUserInfo()));
639 //qDebug() << "requestUserInfo";
644 * React to servers responce after request the user information of certain user.
646 void HttpClient::ackOfUserInfo()
648 qDebug() << "ackUserInfo";
649 /*QString fileName = "user.xml";
650 QFile file(fileName);
651 //file.setFileName( "routetemp.xml");
652 if (!file.open(QFile::ReadOnly))
654 qDebug() << "_xmlShow fail";
658 myXmlreader->xmlReadUserInfo(&file);
661 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
662 //myXmlreader->xmlReadUserInfo(reply);
664 //for(int i = 0; i < myXmlreader->usersList->count(); i++)
666 // myMainw->settingsDialog->sendUsernameToUsersDialog(myXmlreader->usersList->at(i));
668 QNetworkReply::NetworkError errorcode;
669 errorcode = reply->error();
671 qDebug() << "errorcode:" << errorcode << reply->errorString();
672 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories",reply->errorString());
673 if(myMainw->usersDialog)
674 myMainw->usersDialog->setLabelInfoToUser("You're not logged! Please register or log in.");
677 myXmlreader->xmlReadUserInfo(reply);
678 qDebug() << "errorcode:" << errorcode << reply->errorString();
679 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK");
680 if(myMainw->usersDialog)
681 myMainw->usersDialog->setLabelInfoToUser("");
686 * Request the users list of all users from the server.
687 * Send authentication information in the header.
689 void HttpClient::requestUsers()
691 qDebug() << "_requestUsers" ;
693 QUrl qurl("http://www.speedfreak-app.com/users/list_all");
694 qDebug() << qurl.toString();
695 QNetworkRequest request(qurl);
696 QNetworkReply *currentDownload;
698 QString credentials = myMainw->settingsDialog->getUserName() + ":" + myMainw->settingsDialog->getPassword();
699 credentials = "Basic " + credentials.toAscii().toBase64();
700 request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
702 currentDownload = netManager->post(request, ("data=" ));
703 connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfUsers()));
706 //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
709 if(myMainw->usersDialog)
710 myMainw->usersDialog->setLabelInfoToUser("Reguesting users from server");
716 * React to servers responce after request the users list of all users.
718 void HttpClient::ackOfUsers()
720 qDebug() << "ackUsers";
722 //if(myMainw->topResultDialog)
723 // myMainw->topResultDialog->setLabelInfoToUser("");
725 QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
726 //myXmlreader->xmlReadUsers(reply);
728 QNetworkReply::NetworkError errorcode;
729 errorcode = reply->error();
731 qDebug() << "errorcode:" << errorcode << reply->errorString();
732 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories",reply->errorString());
733 if(myMainw->usersDialog)
734 myMainw->usersDialog->setLabelInfoToUser("You're not logged! Please register or log in.");
737 myXmlreader->xmlReadUsers(reply);
738 qDebug() << "errorcode:" << errorcode << reply->errorString();
739 //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting categories ", "OK");
740 if(myMainw->usersDialog)
741 myMainw->usersDialog->setLabelInfoToUser("");
742 for(int i = 0; i < myXmlreader->usersList->count(); i++)
744 myMainw->usersDialog->appendUserToList(myXmlreader->usersList->at(i));
750 * This slot function called when userInfo signal is emitted from xmlreader.
752 * @param QStringList usersInfo includes information from certain user.
754 void HttpClient::sendUsersInfo(QStringList* usersInfo)
756 myMainw->usersDialog->setUserInfo(usersInfo);