From: Toni Jussila Date: Thu, 6 May 2010 06:45:22 +0000 (+0300) Subject: Profile dialog development X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=3fa5091583bdd9421a4ecd5851d954e9bed58731 Profile dialog development --- diff --git a/Client/categorylist.cpp b/Client/categorylist.cpp index 5ec3703..1f05ffb 100644 --- a/Client/categorylist.cpp +++ b/Client/categorylist.cpp @@ -1,7 +1,8 @@ /* * Categorylist * - * @author Olavi Pulkkinen + * @author Olavi Pulkkinen + * @author Toni Jussila * @copyright (c) 2010 Speed Freak team * @license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -51,6 +52,7 @@ QStringList CategoryList::getCategoryList() */ void CategoryList::appendCategoryList(QString item) { + qDebug() << "__appendCategoryList"; categoryList.append(item); } @@ -61,6 +63,7 @@ void CategoryList::appendCategoryList(QString item) */ void CategoryList::fillCategoryList(int index, QString item) { + qDebug() << "__fillCategoryList"; categoryList.insert(index, item); } @@ -70,6 +73,7 @@ void CategoryList::fillCategoryList(int index, QString item) */ QString CategoryList::itemOfCategoryList(int index) { + qDebug() << "__itemOfCategoryList"; return categoryList.at(index); } @@ -78,6 +82,7 @@ QString CategoryList::itemOfCategoryList(int index) */ void CategoryList::clearCategoryList() { + qDebug() << "__clearCategoryList"; categoryList.clear(); } @@ -86,6 +91,7 @@ void CategoryList::clearCategoryList() */ int CategoryList::sizeOfCategoryList() { + qDebug() << "__sizeOfCategoryList"; return categoryList.size(); } @@ -98,6 +104,7 @@ int CategoryList::sizeOfCategoryList() */ void CategoryList::appendCats(int ind, QString des, QString uni, QString cat) { + qDebug() << "__appendCats"; cats[ind].description = des; cats[ind].unit = uni; cats[ind].category = cat; @@ -109,6 +116,7 @@ void CategoryList::appendCats(int ind, QString des, QString uni, QString cat) */ QString CategoryList::getRecentDescription(int ind) { + qDebug() << "__getRecentDescription"; return cats[ind].description; } @@ -118,6 +126,7 @@ QString CategoryList::getRecentDescription(int ind) */ QString CategoryList::getRecentCategory(int ind) { + qDebug() << "__getRecentCategory"; return cats[ind].category; } @@ -126,6 +135,7 @@ QString CategoryList::getRecentCategory(int ind) */ void CategoryList::clearCats() { + qDebug() << "__clearCats"; for(int i = 0; i < 20; i++) { cats[i].description.clear(); diff --git a/Client/creditsdialog.ui b/Client/creditsdialog.ui index 6c4e306..c326ba2 100644 --- a/Client/creditsdialog.ui +++ b/Client/creditsdialog.ui @@ -13,28 +13,7 @@ Dialog - - - - 20 - 10 - 761 - 61 - - - - - 40 - - - - SpeedFreak - - - Qt::AlignCenter - - - + 70 @@ -50,7 +29,7 @@ Qt::AlignCenter - + 70 @@ -77,7 +56,7 @@ - + 10 @@ -92,7 +71,7 @@ - + 10 @@ -107,7 +86,7 @@ - + 10 @@ -122,7 +101,7 @@ - + 10 @@ -137,7 +116,7 @@ - + 10 @@ -152,7 +131,7 @@ - + 10 @@ -167,7 +146,7 @@ - + 10 @@ -182,7 +161,7 @@ - + 10 @@ -375,7 +354,33 @@ + + + + 170 + -20 + 461 + 121 + + + + + + + :/new/prefix1/Graphics/speedfreak.png + + + true + + + labelSpeedFreak + labelTheFollowing + labelGraphicAndIconsBy + layoutWidget + layoutWidget - + + + diff --git a/Client/helpresultsdialog.ui b/Client/helpresultsdialog.ui index 7c870e8..15aae92 100644 --- a/Client/helpresultsdialog.ui +++ b/Client/helpresultsdialog.ui @@ -57,7 +57,10 @@ list seeking from server. 2. Choose the category from drop box -which results you want to see. +which results you want to see. + + + Qt::AutoText diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index 9c32c38..d4c723c 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -32,6 +32,11 @@ HttpClient::HttpClient(MainWindow *myCarw) HttpClient::~HttpClient() { qDebug() << "__~HttpClient" ; + + if(myXmlwriter) + delete myXmlwriter; + if(myXmlreader) + delete myXmlreader; } /** @@ -145,7 +150,8 @@ void HttpClient::sendRouteXml() */ void HttpClient::requestTopList(QString category, QString limit) { - qDebug() << "_requestTopList" ; + qDebug() << "_requestTopList"; + qDebug() << category; QString urlBase = "http://api.speedfreak-app.com/api/results/"; QUrl qurl(urlBase + category + "/" + limit); @@ -377,7 +383,6 @@ void HttpClient::ackOfLogin() myMainw->settingsDialog->usernameOk(true); myMainw->settingsDialog->close(); } - } } @@ -407,20 +412,141 @@ void HttpClient::ackOfToplist() { qDebug() << "_ackOfToplist"; QNetworkReply* reply = qobject_cast(sender()); - myXmlreader->xmlReadTop10Results(reply); + myXmlreader->xmlReadTop10Results(reply,myMainw->settingsDialog->getUserName()); QNetworkReply::NetworkError errorcode; errorcode = reply->error(); if(errorcode != 0) { qDebug() << "errorcode:" << errorcode << reply->errorString(); - //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list",reply->errorString()); + //Indicating user if(myMainw->topResultDialog) - myMainw->topResultDialog->setLabelInfoToUser("Error"); + { + //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list",reply->errorString()); + myMainw->topResultDialog->setLabelInfoToUser("No results ;("); + } } else { qDebug() << "errorcode:" << errorcode << reply->errorString(); - //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list", "OK " + reply->readAll()); + //Indicating user if(myMainw->topResultDialog) + { + //QMessageBox::about(myMainw->topResultDialog, "Server reply to requesting top 10 list", "OK " + reply->readAll()); myMainw->topResultDialog->setLabelInfoToUser(""); + } + } +} + +/** + * This function sends profile to the server in xml format. + * Send authentication information in the header. + */ +void HttpClient::sendProfileXml() +{ + qDebug() << "_sendProfileXml"; + + QString userName = myMainw->settingsDialog->getUserName(); + QString filename = userName + "_profile.xml"; + QFile file(filename); + if (!file.open(QFile::ReadWrite | QFile::Text)) + { + qDebug() << "_xmlWrite fail"; + return; + } + myXmlwriter->writeProfileXmlFile(&file, userName, + myMainw->settingsDialog->profileDialog->getManufacturer(), + myMainw->settingsDialog->profileDialog->getType(), + myMainw->settingsDialog->profileDialog->getModel(), + myMainw->settingsDialog->profileDialog->getDescription(), + myMainw->settingsDialog->profileDialog->getPicture()); + + //Indicating user + if(myMainw->settingsDialog->profileDialog) + myMainw->settingsDialog->profileDialog->setLabelInfoToUser("Profile saved to phone"); + + QUrl qurl("http://api.speedfreak-app.com/api/profile"); + QNetworkRequest request(qurl); + qDebug() << qurl.toString(); + 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, ("xml=" + file.readAll())); + bool error = connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfProfile())); + + file.close(); + + // Send picture + if(myMainw->settingsDialog->profileDialog->getPicture() != "" && error == false) + { + QFile pictureFile( myMainw->settingsDialog->profileDialog->getPicture() ); + if (!pictureFile.open(QIODevice::ReadOnly)) + { + qDebug() << "__picture read fail"; + return; + } + currentDownload = netManager->post(request, pictureFile.readAll()); + connect(currentDownload, SIGNAL(finished()), this, SLOT(ackOfSendingPicture())); + pictureFile.close(); + } +} + +/** + * This slot function react to servers responce after request of profile has been sent. + */ +bool HttpClient::ackOfProfile() +{ + qDebug() << "__ackOfProfile"; + QNetworkReply* reply = qobject_cast(sender()); + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //Indicating user + if(myMainw->settingsDialog->profileDialog) + { + //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting profile",reply->errorString()); + myMainw->settingsDialog->profileDialog->setLabelInfoToUser("Profile save to server - fail"); + return true; + } + } + else { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //Indicating user + if(myMainw->settingsDialog->profileDialog) + { + //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting profile", "OK " + reply->readAll()); + myMainw->settingsDialog->profileDialog->setLabelInfoToUser("Profile saved to server"); + return false; + } + } +} +/** + * This slot function react to servers responce after request of picture has been sent. + */ +void HttpClient::ackOfSendingPicture() +{ + qDebug() << "__ackOfSendingPicture"; + QNetworkReply* reply = qobject_cast(sender()); + QNetworkReply::NetworkError errorcode; + errorcode = reply->error(); + if(errorcode != 0) { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //Indicating user + if(myMainw->settingsDialog->profileDialog) + { + //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting picture",reply->errorString()); + myMainw->settingsDialog->profileDialog->setLabelInfoToUser("Picture save to server - fail"); + } + } + else { + qDebug() << "errorcode:" << errorcode << reply->errorString(); + //Indicating user + if(myMainw->settingsDialog->profileDialog) + { + //QMessageBox::about(myMainw->settingsDialog->profileDialog, "Server reply to requesting picture", "OK " + reply->readAll()); + myMainw->settingsDialog->profileDialog->setLabelInfoToUser("Picture saved to server"); + } } } diff --git a/Client/httpclient.h b/Client/httpclient.h index 772d1b8..2c4bd84 100644 --- a/Client/httpclient.h +++ b/Client/httpclient.h @@ -48,7 +48,10 @@ public slots: void ackOfCategories(); void ackOfToplist(); void ackOfLogin(); + bool ackOfProfile(); + void ackOfSendingPicture(); void errorFromServer(QNetworkReply::NetworkError); + void sendProfileXml(); }; diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index 2341248..56c7238 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -16,6 +16,9 @@ #include #include "usersettings.h" +/** + * + */ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -32,9 +35,10 @@ MainWindow::MainWindow(QWidget *parent) : topResultDialog = NULL; settingsDialog = new SettingsDialog; - connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer())); - connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin())); - connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel())); + connect(settingsDialog, SIGNAL(sendregistration()), this, SLOT(clientRegUserToServer())); + connect(settingsDialog, SIGNAL(userNameChanged()), this, SLOT(clientUserLogin())); + connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel())); + connect(settingsDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile())); httpClient = new HttpClient(this); connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox())); @@ -99,6 +103,9 @@ MainWindow::MainWindow(QWidget *parent) : customButtonResults->show(); } +/** + * + */ MainWindow::~MainWindow() { delete ui; @@ -133,6 +140,9 @@ MainWindow::~MainWindow() } +/** + * + */ void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); @@ -280,6 +290,7 @@ void MainWindow::clientSendResult(QString category, double result) httpClient->sendResultXml(category, result); } } + /** * This slot function called when ever dialog rejected. */ @@ -316,6 +327,7 @@ void MainWindow::killDialog() helpDialog = NULL; } } + /** * */ @@ -368,3 +380,12 @@ void MainWindow::OpenResultDialog() connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog())); topResultDialog->show(); } + +/** + * This slot function save user profile data to server + */ +void MainWindow::saveProfile() +{ + if(httpClient) + httpClient->sendProfileXml(); +} diff --git a/Client/mainwindow.h b/Client/mainwindow.h index 4fbdb0d..548c339 100644 --- a/Client/mainwindow.h +++ b/Client/mainwindow.h @@ -77,6 +77,7 @@ private slots: void OpenAccStartDialog(); void OpenRouteDialog(); void OpenResultDialog(); + void saveProfile(); }; diff --git a/Client/profiledialog.cpp b/Client/profiledialog.cpp index f6ae507..4870b8a 100644 --- a/Client/profiledialog.cpp +++ b/Client/profiledialog.cpp @@ -1,18 +1,89 @@ +/* + * Profile dialog class + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + +#include +#include +#include +#include +#include +#include +#include #include "profiledialog.h" #include "ui_profiledialog.h" +#include "usersettings.h" +#include "settingsdialog.h" +#include "xmlreader.h" -ProfileDialog::ProfileDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::ProfileDialog) +/** + * Constructor of this class. + * @param QWidget pointer to parent object. By default the value is NULL. + */ +ProfileDialog::ProfileDialog(SettingsDialog *parent) : QDialog(parent), ui(new Ui::ProfileDialog) { + qDebug() << "__ProfileDialog"; ui->setupUi(this); + + if (loginSaved()) + { + this->setWindowTitle("Profile - " + parent->getUserName()); + } + else + { + this->setWindowTitle("Profile"); + } + + // User info label + ui->labelInfoToUser->setVisible(0); + ui->labelInfoToUser->setText(""); + + // Button + imageButtonState = false; + + manufacturer=""; + type=""; + model=""; + description=""; + picture=""; + + // Read user profile xml + QString filename = parent->getUserName() + "_profile.xml"; + QFile file(filename); + + if (!file.open(QFile::ReadOnly)) + { + qDebug() << "_xmlRead fail"; + return; + } + else + { + xmlReader = new XmlReader(); + xmlReader->xmlReadProfile(&file,this); + } + file.close(); } +/** + * Destructor of this class. Deletes all dynamic objects and sets them to NULL. + */ ProfileDialog::~ProfileDialog() { - delete ui; + qDebug() << "__~ProfileDialog"; + + if(ui) + delete ui; + + if(xmlReader) + delete xmlReader; } +/** + * + */ void ProfileDialog::changeEvent(QEvent *e) { QDialog::changeEvent(e); @@ -24,3 +95,162 @@ void ProfileDialog::changeEvent(QEvent *e) break; } } + +/** + * This slot function called when image button clicked. + * + */ +void ProfileDialog::on_buttonImage_clicked() +{ + if (imageButtonState == false) + { + ui->buttonImage->setText("Load image"); + } + else + { + ui->buttonImage->setText("Change image"); + } + + QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath()); + loadPicture(fileName); +} + +/** + * This function load picture. + * @param QString + */ +void ProfileDialog::loadPicture(QString fileName) +{ + if (!fileName.isEmpty()) + { + QImage image(fileName); + if (image.isNull()) + { + QMessageBox::information(this, tr("Profile"),tr("Cannot load %1.").arg(fileName)); + return; + } + ui->labelImage->setPixmap(QPixmap::fromImage(image.scaled(QSize(120,120), Qt::KeepAspectRatio))); + picture = fileName; + } +} + +/** + * This slot function called when save button clicked. + * @todo server connection + */ +void ProfileDialog::on_buttonSave_clicked() +{ + // Save labels data + setManufacturer(ui->lineEditManufacturer->text()); + setType(ui->lineEditType->text()); + setModel(ui->lineEditModel->text()); + setDescription(ui->textEditDescription->toPlainText()); + + // emit settingsdialog --> mainwindow --> httpclient + emit saveprofile(); +} + +/** + * This get function return manufacturer + * @return QString + */ +QString ProfileDialog::getManufacturer() +{ + return manufacturer; +} + +/** + * This get function return type + * @return QString + */ +QString ProfileDialog::getType() +{ + return type; +} + +/** + * This get function return model + * @return QString + */ +QString ProfileDialog::getModel() +{ + return model; +} + +/** + * This get function return description + * @return QString + */ +QString ProfileDialog::getDescription() +{ + return description; +} + +/** + * This get function return description + * @return QString + */ +QString ProfileDialog::getPicture() +{ + return picture; +} + +/** + * This set function set manufacturer + * @param QString + */ +void ProfileDialog::setManufacturer(QString m) +{ + manufacturer = m; + ui->lineEditManufacturer->setText(m); +} + +/** + * This set function set type + * @param QString + */ +void ProfileDialog::setType(QString t) +{ + type = t; + ui->lineEditType->setText(t); +} + +/** + * This set function set model + * @param QString + */ +void ProfileDialog::setModel(QString m) +{ + model = m; + ui->lineEditModel->setText(m); +} + +/** + * This set function set description + * @param QString + */ +void ProfileDialog::setDescription(QString d) +{ + description = d; + ui->textEditDescription->setText(d); +} + +/** + * This set function set description + * @param QString + */ +void ProfileDialog::setPicture(QString p) +{ + picture = p; + loadPicture(p); +} + +/** + * This function set label info text to user + * @param QString + */ +void ProfileDialog::setLabelInfoToUser(QString infoText) +{ + ui->labelInfoToUser->setVisible(1); + this->ui->labelInfoToUser->setText(infoText); +} diff --git a/Client/profiledialog.h b/Client/profiledialog.h index 7a0451a..a040090 100644 --- a/Client/profiledialog.h +++ b/Client/profiledialog.h @@ -1,23 +1,62 @@ +/* + * Profile dialog class + * + * @author Toni Jussila + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + #ifndef PROFILEDIALOG_H #define PROFILEDIALOG_H #include -namespace Ui { +class SettingsDialog; +class XmlReader; + +namespace Ui +{ class ProfileDialog; } -class ProfileDialog : public QDialog { +class ProfileDialog : public QDialog +{ Q_OBJECT public: - ProfileDialog(QWidget *parent = 0); + ProfileDialog(SettingsDialog *parent = 0); ~ProfileDialog(); + XmlReader *xmlReader; + QString getManufacturer(); + QString getType(); + QString getModel(); + QString getDescription(); + QString getPicture(); + void setManufacturer(QString m); + void setType(QString t); + void setModel(QString m); + void setDescription(QString d); + void setPicture(QString p); + void setLabelInfoToUser(QString infoText); protected: void changeEvent(QEvent *e); private: Ui::ProfileDialog *ui; + bool imageButtonState; + void loadPicture(QString); + QString manufacturer; + QString type; + QString model; + QString description; + QString picture; + +private slots: + void on_buttonSave_clicked(); + void on_buttonImage_clicked(); + +signals: + void saveprofile(); }; #endif // PROFILEDIALOG_H diff --git a/Client/profiledialog.ui b/Client/profiledialog.ui index 153e5bf..763f367 100644 --- a/Client/profiledialog.ui +++ b/Client/profiledialog.ui @@ -13,6 +13,162 @@ Dialog + + + + 660 + 130 + 120 + 120 + + + + Save + + + + + + 370 + 30 + 120 + 120 + + + + background-color: rgb(99, 99, 99); + + + QFrame::Box + + + 0 + + + No image + + + Qt::AlignCenter + + + 0 + + + + + + 510 + 30 + 120 + 120 + + + + Load image + + + + + + 630 + 10 + 20 + 361 + + + + Qt::Vertical + + + + + + 10 + 190 + 621 + 131 + + + + + + + Description: + + + + + + + + + + + + 10 + 10 + 351 + 171 + + + + + + + Manufacturer: + + + + + + + 12 + + + + + + + Type: + + + + + + + 12 + + + + + + + Model: + + + + + + + 10 + + + + + + + + + 10 + 330 + 621 + 41 + + + + Label info to user + + diff --git a/Client/routedialog.cpp b/Client/routedialog.cpp index dbe0772..35f232f 100644 --- a/Client/routedialog.cpp +++ b/Client/routedialog.cpp @@ -176,11 +176,11 @@ RouteDialog::RouteDialog(RouteSaveDialog *parent) : qDebug() << "__RouteDialog"; ui->setupUi(this); - helpRoutingDialog = NULL; - this->setWindowTitle("Route"); left = 5; top = 5; right = 495; bottom = 295; // Limits in screen coordinates + helpRoutingDialog = NULL; + // Button settings ui->sendPushButton->setAutoFillBackground(true); ui->sendPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); @@ -196,7 +196,8 @@ RouteDialog::RouteDialog(RouteSaveDialog *parent) : checkLogin(); // Set average speed - ui->avgSpeedValueLabel->setText(QString::number(parent->getAverageSpeed()) + " km/h"); + QString average; + ui->avgSpeedValueLabel->setText(average.sprintf("%.1f", parent->getAverageSpeed()) + " km/h"); ui->distanceValueLabel->setText(parent->getDistanceTraveled() + " km"); } @@ -208,6 +209,8 @@ RouteDialog::~RouteDialog() qDebug() << "__~RouteDialog"; if(ui) delete ui; + if(calibrateDialog) + delete calibrateDialog; } /** @@ -429,13 +432,17 @@ void RouteDialog::paintEvent(QPaintEvent *) /** * */ -bool RouteDialog::readRouteFromFile( QString &routeFile) - { +bool RouteDialog::readRouteFromFile( QString &routeFile , CalibrateDialog *calibrateDialog) +{ QString rFile = routeFile; //Not used Vector temp; QString rivi; QFile file; + progresbar = calibrateDialog; + int progresbarValue = 0; + progresbar->setProgressValue(++progresbarValue); + //QString fileName = QFileDialog::getOpenFileName(this, // tr("Read Route"), "./", tr("Route Files (*.txt)")); @@ -444,6 +451,7 @@ bool RouteDialog::readRouteFromFile( QString &routeFile) if (!file.open(QIODevice::ReadOnly)) { QMessageBox::about(0, "Error", "File not found"); + progresbar->setProgressValue(100); return false; } @@ -559,7 +567,7 @@ bool RouteDialog::readRouteFromFile( QString &routeFile) */ return true; - } +} /** * Find out data range for x-, y- and z-coordinates diff --git a/Client/routedialog.h b/Client/routedialog.h index b3250d7..81e3584 100644 --- a/Client/routedialog.h +++ b/Client/routedialog.h @@ -13,6 +13,7 @@ #include #include class RouteSaveDialog; +class CalibrateDialog; namespace Ui { class RouteDialog; @@ -24,7 +25,7 @@ class RouteDialog : public QDialog { public: RouteDialog(RouteSaveDialog *parent = 0); ~RouteDialog(); - bool readRouteFromFile( QString &routeFile); + bool readRouteFromFile( QString &routeFile, CalibrateDialog *calibrateDialog); int getLeft(); int getTop(); int getRight(); @@ -42,6 +43,7 @@ protected: private: Ui::RouteDialog *ui; + CalibrateDialog *progresbar; int left, top, right, bottom; // Limits in screen coordinates in route dialog void checkLogin(); diff --git a/Client/routesavedialog.cpp b/Client/routesavedialog.cpp index 6d355e6..fcccd5f 100644 --- a/Client/routesavedialog.cpp +++ b/Client/routesavedialog.cpp @@ -11,8 +11,8 @@ #include /** - *Constructor of this class. - *@param QWidget pointer to parent object. By default the value is NULL. + * Constructor of this class. + * @param QWidget pointer to parent object. By default the value is NULL. */ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : QDialog(parent), ui(new Ui::RouteSaveDialog){ @@ -25,6 +25,7 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : location = NULL; gpsData = NULL; helpRoutingDialog = NULL; + calibrateDialog = NULL; //Clear variables averageSpeed = 0.0; @@ -62,6 +63,8 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : ui->labelGpsAvgSpeed->setVisible(0); //GPS average speed label ui->labelDistance->setVisible(0); //GPS distance label ui->labelSignalStrength->setText(""); //GPS signal strength label + + // Timer timerRoutePicture = new QTimer(); timerRoutePicture->setInterval(400); connect(timerRoutePicture, SIGNAL(timeout()),this, SLOT(timerRoutePictureTimeout())); @@ -73,7 +76,7 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : } /** - *Destructor of this class. Deletes all dynamic objects and sets them to NULL. + * Destructor of this class. Deletes all dynamic objects and sets them to NULL. */ RouteSaveDialog::~RouteSaveDialog() { @@ -111,7 +114,7 @@ void RouteSaveDialog::changeEvent(QEvent *e) } /** - *This slot function is called when route start/stop button clicked. + * This slot function is called when route start/stop button clicked. */ void RouteSaveDialog::on_buttonRouteStartStop_clicked() { @@ -148,14 +151,36 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked() timerRoutePicture->stop(); location->stopPollingGPS(); + // Progres bar + if(!calibrateDialog) + calibrateDialog = new CalibrateDialog(); + + calibrateDialog->show(); + calibrateDialog->resetProgressValue(); + int points = 100; + int iteration = 0; + calibrateDialog->setMaxValue( points + 1 ); + + /*do { + calibrateDialog->setProgressValue(iteration); + iteration++; + + } while(iteration != points);*/ + QString routeFile = QString("routetemp.xml"); - if (routeDialog->readRouteFromFile( routeFile ) == true) + if (routeDialog->readRouteFromFile( routeFile , calibrateDialog) == true) { if(!routeDialog) routeDialog = new RouteDialog(this); connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute())); + + calibrateDialog->close(); routeDialog->show(); } + else + { + calibrateDialog->close(); + } //Set GPS speed labels in visible ui->labelGpsSpeed->setVisible(0); @@ -173,7 +198,7 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked() } /** - *This slot function is called when satellite picture timer timeout(400ms). + * This slot function is called when satellite picture timer timeout(400ms). */ void RouteSaveDialog::timerSatellitePictureTimeout() { @@ -192,7 +217,7 @@ void RouteSaveDialog::timerSatellitePictureTimeout() } /** - *This slot function is called when route picture timer timeout(400ms). + * This slot function is called when route picture timer timeout(400ms). */ void RouteSaveDialog::timerRoutePictureTimeout() { diff --git a/Client/routesavedialog.h b/Client/routesavedialog.h index bb1f189..ed35e68 100644 --- a/Client/routesavedialog.h +++ b/Client/routesavedialog.h @@ -18,6 +18,7 @@ #include "gpsdata.h" #include "routedialog.h" #include +#include "calibratedialog.h" namespace Ui { class RouteSaveDialog; @@ -42,6 +43,7 @@ private: QTimer *timerRoutePicture; GPSData *gpsData; Maemo5Location *location; + CalibrateDialog *calibrateDialog; QString gpsSpeed; QString distanceString; QPixmap *pixmapRouteStop; diff --git a/Client/settingsdialog.cpp b/Client/settingsdialog.cpp index a50a681..cf6e26d 100644 --- a/Client/settingsdialog.cpp +++ b/Client/settingsdialog.cpp @@ -19,10 +19,13 @@ SettingsDialog::SettingsDialog(QWidget *parent) : ui->setupUi(this); helpSettingsDialog = NULL; + profileDialog = NULL; this->setWindowTitle("Settings"); this->ui->regEMailLineEdit->setText("@"); + ui->pushButtonProfile->setDisabled(true); + if (loginSaved()) { QString uName, pWord; @@ -43,7 +46,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) : // Button settings ui->pushButtonInfo->setAutoFillBackground(true); ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); + ui->pushButtonProfile->setDisabled(false); } + + ui->pushButtonInfo->setAutoFillBackground(true); + ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); } SettingsDialog::~SettingsDialog() @@ -135,6 +142,7 @@ void SettingsDialog::on_setUserPushButton_clicked() this->password = ui->setUserPasswordLineEdit->text(); ui->setUserPushButton->setText("Log in"); saveLogin( this->username, this->password); + ui->pushButtonProfile->setDisabled(true); emit logout(); } else @@ -211,6 +219,7 @@ void SettingsDialog::usernameOk(bool isOk) ui->setUserPushButton->setText("Log out"); ui->setUserUsernameLineEdit->setDisabled(true); ui->setUserPasswordLineEdit->setDisabled(true); + ui->pushButtonProfile->setDisabled(false); } else @@ -221,6 +230,7 @@ void SettingsDialog::usernameOk(bool isOk) this->username = ui->setUserUsernameLineEdit->text(); this->password = ui->setUserPasswordLineEdit->text(); saveLogin( this->username, this->password); + ui->pushButtonProfile->setDisabled(true); } } @@ -240,14 +250,14 @@ void SettingsDialog::on_pushButtonInfo_clicked() { helpSettingsDialog = new HelpSettingsDialog; } - connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog())); + connect(helpSettingsDialog, SIGNAL(rejected()), this, SLOT(killDialog())); helpSettingsDialog->show(); } /** * This slot function called when ever dialog rejected. */ -void SettingsDialog::killHelpDialog() +void SettingsDialog::killDialog() { if(helpSettingsDialog) { @@ -255,4 +265,30 @@ void SettingsDialog::killHelpDialog() delete helpSettingsDialog; helpSettingsDialog = NULL; } + if(profileDialog) + { + qDebug() << "__Settings kill: profileDialog"; + delete profileDialog; + profileDialog = NULL; + } +} + +/** + * This slot function called when ever profile button clicked. + * Open profile dialog. + */ +void SettingsDialog::on_pushButtonProfile_clicked() +{ + if(!profileDialog) + { + profileDialog = new ProfileDialog(this); + } + connect(profileDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile())); + connect(profileDialog, SIGNAL(rejected()), this, SLOT(killDialog())); + profileDialog->show(); +} + +void SettingsDialog::saveProfile() +{ + emit saveprofile(); } diff --git a/Client/settingsdialog.h b/Client/settingsdialog.h index 4f5858b..0cef1d9 100644 --- a/Client/settingsdialog.h +++ b/Client/settingsdialog.h @@ -12,6 +12,7 @@ #include #include "instructionsdialog.h" #include +#include namespace Ui { class SettingsDialog; @@ -23,6 +24,7 @@ public: SettingsDialog(QWidget *parent = 0); ~SettingsDialog(); HelpSettingsDialog *helpSettingsDialog; + ProfileDialog *profileDialog; void setRegUserName(QString username); void setRegPassword(QString password); void setRegEmail(QString email); @@ -41,6 +43,7 @@ signals: void sendregistration(); void userNameChanged(); void logout(); + void saveprofile(); protected: void changeEvent(QEvent *e); @@ -54,10 +57,12 @@ private: QString password; private slots: + void on_pushButtonProfile_clicked(); void on_pushButtonInfo_clicked(); void on_setUserPushButton_clicked(); void on_registratePushButton_clicked(); - void killHelpDialog(); + void killDialog(); + void saveProfile(); }; #endif // SETTINGSDIALOG_H diff --git a/Client/settingsdialog.ui b/Client/settingsdialog.ui index bf6e945..dc0caae 100644 --- a/Client/settingsdialog.ui +++ b/Client/settingsdialog.ui @@ -257,6 +257,29 @@ + + + + 640 + 180 + 93 + 27 + + + + Profile + + + label + setUserLabel + setUserPushButton + registrateLabel + registratePushButton + layoutWidget + labelInfoToUser + layoutWidget + pushButtonInfo + pushButtonProfile regUserNameLineEdit diff --git a/Client/speedfreak.pro b/Client/speedfreak.pro index 74cc7e2..d3d50a2 100644 --- a/Client/speedfreak.pro +++ b/Client/speedfreak.pro @@ -38,7 +38,8 @@ SOURCES += main.cpp \ helpaccelerationdialog.cpp \ helproutingdialog.cpp \ helpsettingsdialog.cpp \ - custombutton.cpp + custombutton.cpp \ + profiledialog.cpp HEADERS += mainwindow.h \ creditsdialog.h \ routedialog.h \ @@ -67,7 +68,8 @@ HEADERS += mainwindow.h \ helpaccelerationdialog.h \ helproutingdialog.h \ helpsettingsdialog.h \ - custombutton.h + custombutton.h \ + profiledialog.h FORMS += mainwindow.ui \ creditsdialog.ui \ routedialog.ui \ @@ -84,7 +86,8 @@ FORMS += mainwindow.ui \ helpresultsdialog.ui \ helpaccelerationdialog.ui \ helproutingdialog.ui \ - helpsettingsdialog.ui + helpsettingsdialog.ui \ + profiledialog.ui RESOURCES += graphics.qrc contains(QT_CONFIG, hildon):CONFIG += hildon CONFIG += link_pkgconfig diff --git a/Client/speedfreak.pro.user b/Client/speedfreak.pro.user index 37bd8d7..d4093ca 100644 --- a/Client/speedfreak.pro.user +++ b/Client/speedfreak.pro.user @@ -75,12 +75,91 @@ buildconfiguration-Debug-buildstep0 Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qiZb4Pleu0,guid=dfa9e6bbffd50dabf30f2a694bda6acd + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=fi + GDM_LANG=fi_FI.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_PID=1664 + GNOME_KEYRING_SOCKET=/tmp/keyring-BU1Ggo/socket + GTK_MODULES=canberra-gtk-module + GTK_RC_FILES=/etc/gtk/gtkrc:/home/oppilas/.gtkrc-1.2-gnome2 + HOME=/home/oppilas + LANG=fi_FI.UTF-8 + LD_LIBRARY_PATH=/opt/qtsdk-2010.02/lib/qtcreator: + LOGNAME=oppilas + ORBIT_SOCKETDIR=/tmp/orbit-oppilas + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/oppilas + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/ubuntu:@/tmp/.ICE-unix/1679,unix/ubuntu:/tmp/.ICE-unix/1679 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1719 + SSH_AUTH_SOCK=/tmp/keyring-BU1Ggo/socket.ssh + USER=oppilas + USERNAME=oppilas + XAUTHORITY=/var/run/gdm/auth-for-oppilas-CUBiAz/database + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=7bed32bdbfbd7579c7bbdbcd4bbc8b02-1272605389.226561-886088294 + + + /scratchbox/users/oppilas/home/oppilas/qt_codes/garage.git/speedfreak/Client/speedfreak.pro + -spec + linux-g++ + -r + CONFIG+=debug + + /usr/bin/qmake-qt4 + false + /scratchbox/users/oppilas/home/oppilas/qt_codes/garage.git/speedfreak/Client buildconfiguration-Debug-buildstep1 Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-qiZb4Pleu0,guid=dfa9e6bbffd50dabf30f2a694bda6acd + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=fi + GDM_LANG=fi_FI.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_PID=1664 + GNOME_KEYRING_SOCKET=/tmp/keyring-BU1Ggo/socket + GTK_MODULES=canberra-gtk-module + GTK_RC_FILES=/etc/gtk/gtkrc:/home/oppilas/.gtkrc-1.2-gnome2 + HOME=/home/oppilas + LANG=fi_FI.UTF-8 + LD_LIBRARY_PATH=/opt/qtsdk-2010.02/lib/qtcreator: + LOGNAME=oppilas + ORBIT_SOCKETDIR=/tmp/orbit-oppilas + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/oppilas + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/ubuntu:@/tmp/.ICE-unix/1679,unix/ubuntu:/tmp/.ICE-unix/1679 + SHELL=/bin/bash + SPEECHD_PORT=7560 + SSH_AGENT_PID=1719 + SSH_AUTH_SOCK=/tmp/keyring-BU1Ggo/socket.ssh + USER=oppilas + USERNAME=oppilas + XAUTHORITY=/var/run/gdm/auth-for-oppilas-CUBiAz/database + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=7bed32bdbfbd7579c7bbdbcd4bbc8b02-1272605389.226561-886088294 + + false + + -w + + /usr/bin/make + true + /scratchbox/users/oppilas/home/oppilas/qt_codes/garage.git/speedfreak/Client diff --git a/Client/topresultdialog.cpp b/Client/topresultdialog.cpp index 3eeb3b4..0c81ced 100644 --- a/Client/topresultdialog.cpp +++ b/Client/topresultdialog.cpp @@ -36,6 +36,7 @@ TopResultDialog::TopResultDialog(QWidget *parent) : TopResultDialog::~TopResultDialog() { + qDebug() << "__~TopResultDialog"; delete ui; } @@ -66,6 +67,7 @@ void TopResultDialog::setCompoBoxCategories(QStringList list) void TopResultDialog::showTopList(QString str) { + qDebug() << "__showTopList"; ui->labelTopList->setText(str); } diff --git a/Client/topresultdialog.ui b/Client/topresultdialog.ui index b79ce0d..68a25d7 100644 --- a/Client/topresultdialog.ui +++ b/Client/topresultdialog.ui @@ -61,6 +61,9 @@ Top list label + + Qt::RichText + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop diff --git a/Client/xmlreader.cpp b/Client/xmlreader.cpp index b6c1653..9c7766b 100644 --- a/Client/xmlreader.cpp +++ b/Client/xmlreader.cpp @@ -10,6 +10,7 @@ #include #include #include "xmlreader.h" +#include "profiledialog.h" /** *Constructor of this class. @@ -39,7 +40,7 @@ XmlReader::~XmlReader() /** *This function is used to parse top 10 results of a certain category. */ -void XmlReader::xmlReadTop10Results(QNetworkReply *device) +void XmlReader::xmlReadTop10Results(QNetworkReply *device, QString userName) { qDebug() << "_xmlReadTop10Results"; @@ -48,7 +49,7 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) xmlreader.clear(); QByteArray array = device->readAll(); - //qDebug() << "array: " << array; + qDebug() << "array: " << array; xmlreader.addData(array); //xmlreader.addData(device->readAll()); @@ -66,11 +67,12 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) { if(xmlreader.name() == "results") { - //qDebug() << xmlreader.name(); + qDebug() << xmlreader.name(); } + if(xmlreader.name() == "result") { - //qDebug() << xmlreader.name(); + qDebug() << xmlreader.name(); attr = xmlreader.attributes(); user = attr.value("username").toString(); @@ -80,13 +82,30 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) unit = "s"; value = attr.value("value").toString(); + if (userName.toUpper() == user.toUpper())//If user name match highlight result + { + myCategoryList->top10List.append("" + position + "" + + user + "" + + value + " " + + unit + "" + + date + ""); + } + else//If user name not match + { + myCategoryList->top10List.append("" + position + "" + + user + "" + + value + " " + + unit + "" + + date + ""); + } + /* Old way, no highlight myCategoryList->top10List.append(position + "\t" + user + "\t" + value + " " + unit + "\t" + - date + "\n"); + date + "\n");*/ - //qDebug() << position << user << value << unit << date; + qDebug() << position << user << value << unit << date; i++; receivedFlag = 1; } @@ -100,6 +119,10 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device) } } +/** + * + * + */ void XmlReader::xmlReadCategories(QNetworkReply *device) //void XmlReader::xmlReadCategories(QIODevice *device) { @@ -110,7 +133,7 @@ void XmlReader::xmlReadCategories(QNetworkReply *device) xmlreader.clear(); QByteArray array = device->readAll(); - //qDebug() << "array: " << array; + qDebug() << "array: " << array; xmlreader.addData(array); //xmlreader.addData(device->readAll()); @@ -127,17 +150,17 @@ void XmlReader::xmlReadCategories(QNetworkReply *device) { if(xmlreader.name() == "categories") { - //qDebug() << xmlreader.name(); + qDebug() << xmlreader.name(); } if(xmlreader.name() == "category") { - //qDebug() << xmlreader.name(); + qDebug() << xmlreader.name(); attr = xmlreader.attributes(); description = attr.value("description").toString(); unit = attr.value("unit").toString(); category = xmlreader.readElementText(); myCategoryList->appendCats(i, description, unit, category); - //qDebug() << "description: " << description << "unit: " << unit << "category: " << category; + qDebug() << "description: " << description << "unit: " << unit << "category: " << category; i++; receivedFlag = 1; } @@ -170,5 +193,73 @@ void XmlReader::xmlShow() //xmlReadTop10Results(&file); //xmlReadCategories(&file); + //xmlReadProfile(&file); file.close(); } + +/** + * This function is used to read profile xml. + * @param QIODevice device: target of reading, here filename. + * @param ProfileDialog *profileDialog + */ +void XmlReader::xmlReadProfile(QIODevice *device, ProfileDialog *profileDialog) +{ + qDebug() << "_xmlReadProfile"; + + profile = profileDialog; + + xmlreader.clear(); + QByteArray array = device->readAll(); + + xmlreader.addData(array); + + QString login; + QString picture; + + // Go trough the xml document + while(!xmlreader.atEnd()) + { + // Read next node + xmlreader.readNext(); + + // Check if this element is starting element + if(xmlreader.isStartElement()) + { + if(xmlreader.name() == "profile") + { + qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + login = attr.value("login").toString(); + picture = attr.value("picture").toString(); + } + if(xmlreader.name() == "manufacturer") + { + qDebug() << xmlreader.name(); + profile->setManufacturer(xmlreader.readElementText()); + } + if(xmlreader.name() == "type") + { + qDebug() << xmlreader.name(); + profile->setType(xmlreader.readElementText()); + + } + if(xmlreader.name() == "model") + { + qDebug() << xmlreader.name(); + profile->setModel(xmlreader.readElementText()); + + } + if(xmlreader.name() == "description") + { + qDebug() << xmlreader.name(); + profile->setDescription(xmlreader.readElementText()); + } + if(xmlreader.name() == "picture" && picture == "yes") + { + qDebug() << xmlreader.name(); + profile->setPicture(xmlreader.readElementText()); + } + } + } + profile = NULL; +} diff --git a/Client/xmlreader.h b/Client/xmlreader.h index 4a751a3..6ba8f66 100644 --- a/Client/xmlreader.h +++ b/Client/xmlreader.h @@ -15,17 +15,20 @@ #include #include "categorylist.h" +class ProfileDialog; + class XmlReader : public QObject { Q_OBJECT public: XmlReader(); ~XmlReader(); CategoryList *myCategoryList; + void xmlReadProfile(QIODevice *device, ProfileDialog *profileDialog); private: QXmlStreamReader xmlreader; - QXmlStreamAttributes attr; + ProfileDialog *profile; QString category; QString unit; QString date; @@ -39,7 +42,7 @@ signals: void receivedTop10List(); public slots: - void xmlReadTop10Results(QNetworkReply *device); + void xmlReadTop10Results(QNetworkReply *device, QString userName); void xmlReadCategories(QNetworkReply *device); //void xmlReadCategories(QIODevice *device); void xmlShow(); diff --git a/Client/xmlwriter.cpp b/Client/xmlwriter.cpp index 3abe02a..49e9c66 100644 --- a/Client/xmlwriter.cpp +++ b/Client/xmlwriter.cpp @@ -167,3 +167,107 @@ void XmlWriter::writeItems() xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString()); xmlwriter.writeEndElement(); } + +/** + * Write profile xml + * @param QIODevice device: target of writing, here filename. + * @param QString user name + * @param QString manufacturer + * @param QString type + * @param QString model + * @param QString description + * @param QString picture: filename. + */ +void XmlWriter::writeProfileXmlFile(QIODevice *device, QString userName, QString manufacturer, + QString type, QString model, QString description, QString picture) +{ + QString pictureStatus; + if(picture != "") + pictureStatus = "yes"; + else + pictureStatus = "no"; + + /*example of XML: + + + toyota + corolla + 1983 + Fuel efficient, GPS system, only one owner + */ + + xmlwriter.setDevice(device); + xmlwriter.writeStartDocument(); + xmlwriter.writeStartElement("profile"); + xmlwriter.writeAttribute("login", userName); + xmlwriter.writeAttribute("picture", pictureStatus); + xmlwriter.writeStartElement("manufacturer"); + xmlwriter.writeCharacters(manufacturer); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("type"); + xmlwriter.writeCharacters(type); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("model"); + xmlwriter.writeCharacters(model); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("description"); + xmlwriter.writeCharacters(description); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("picture"); + xmlwriter.writeCharacters(picture); + xmlwriter.writeEndElement(); + xmlwriter.writeEndElement(); + xmlwriter.writeEndDocument(); +} + +/** + * Write profile xml + * @param QIODevice device: target of writing, here netbuf. + * @param QString user name + * @param QString manufacturer + * @param QString type + * @param QString model + * @param QString description + * @param QString picture: filename. + */ +void XmlWriter::writeProfileXmlFile(QBuffer *netbuf, QString userName, QString manufacturer, + QString type, QString model, QString description, QString picture) +{ + QString pictureStatus; + if(picture != "") + pictureStatus = "yes"; + else + pictureStatus = "no"; + + /*example of XML: + + + toyota + corolla + 1983 + Fuel efficient, GPS system, only one owner + */ + + xmlwriter.setDevice(netbuf); + xmlwriter.writeStartDocument(); + xmlwriter.writeStartElement("profile"); + xmlwriter.writeAttribute("login", userName); + xmlwriter.writeAttribute("picture", pictureStatus); + xmlwriter.writeStartElement("manufacturer"); + xmlwriter.writeCharacters(manufacturer); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("type"); + xmlwriter.writeCharacters(type); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("model"); + xmlwriter.writeCharacters(model); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("description"); + xmlwriter.writeCharacters(description); + xmlwriter.writeEndElement(); + xmlwriter.writeStartElement("picture"); + xmlwriter.writeCharacters(picture); + xmlwriter.writeEndElement(); + xmlwriter.writeEndElement(); + xmlwriter.writeEndDocument(); +} diff --git a/Client/xmlwriter.h b/Client/xmlwriter.h index ac60175..d98eef4 100644 --- a/Client/xmlwriter.h +++ b/Client/xmlwriter.h @@ -2,6 +2,7 @@ * Xml writer * * @author Tiina Kivilinna-Korhola + * @author Toni Jussila * @copyright (c) 2010 Speed Freak team * license http://opensource.org/licenses/gpl-license.php GNU Public License */ @@ -23,12 +24,13 @@ #include #include - class XmlWriter : public QObject { Q_OBJECT public: XmlWriter(); ~XmlWriter(); + void writeProfileXmlFile(QIODevice *device, QString userName, QString manufacturer, QString type, QString model, QString description, QString picture); + void writeProfileXmlFile(QBuffer *netbuf, QString userName, QString manufacturer, QString type, QString model, QString description, QString picture); private: QXmlStreamWriter xmlwriter; @@ -41,6 +43,7 @@ public slots: //void writeXml(QString usr, QString psswd, QString email); void writeXml(); void writeItems(); + }; #endif // XMLWRITER_H