Profile dialog development
[speedfreak] / Client / mainwindow.cpp
index 7b04b08..56c7238 100644 (file)
@@ -16,6 +16,9 @@
 #include <QDebug>
 #include "usersettings.h"
 
+/**
+  *
+  */
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
@@ -26,45 +29,83 @@ MainWindow::MainWindow(QWidget *parent) :
     QCoreApplication::setOrganizationDomain("fudeco.com");
     QCoreApplication::setApplicationName("Speed Freak");
 
-    //routeDialog = new RouteDialog;
-    //connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
-
     helpDialog = NULL;
     accstart = NULL;
     routeSaveDialog = NULL;
     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()));
     connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));    
 
-    //creditsDialog = new CreditsDialog;
-
     welcomeDialog = new WelcomeDialog;
     welcomeDialog->show();
 
     this->setUsernameToMainPanel();
 
     //Button settings
-    ui->pushButtonAccelerate->setAutoFillBackground(true);
-    ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
-    ui->pushButtonRoute->setAutoFillBackground(true);
-    ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
-    ui->pushButtonResults->setAutoFillBackground(true);
-    ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     ui->pushButtonSettings->setAutoFillBackground(true);
     ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     ui->pushButtonWWW->setAutoFillBackground(true);
     ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     ui->pushButtonCredits->setAutoFillBackground(true);
     ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
+
+    //Create icon for acceleration start button
+    QIcon* icon = new QIcon();
+    icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
+    icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
+
+    //Acceleration start button
+
+    customButtonAccelerate = new CustomButton(this,icon);
+    delete icon;
+
+    int buttons_x = 50,buttons_y = 165;
+    customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
+    connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
+    customButtonAccelerate->show();
+
+    //Create icon for route dialog button
+    icon = new QIcon();
+    icon->addFile(QString(":/new/prefix1/Graphics/route.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
+    icon->addFile(QString(":/new/prefix1/Graphics/route_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
+
+    //Route dialog button
+
+    customButtonRoute = new CustomButton(this,icon);
+    delete icon;
+
+    buttons_x += 140;
+    customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
+    connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
+    customButtonRoute->show();
+
+    //Create icon for results dialog button
+    icon = new QIcon();
+    icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
+    icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
+
+    //Results dialog button
+
+    customButtonResults = new CustomButton(this,icon);
+    delete icon;
+
+    buttons_x += 140;
+    customButtonResults->setGeometry(buttons_x,buttons_y,130,130);
+    connect(customButtonResults, SIGNAL(OpenDialog()), this, SLOT(OpenResultDialog()));
+    customButtonResults->show();
 }
 
+/**
+  *
+  */
 MainWindow::~MainWindow()
 {
     delete ui;
@@ -89,8 +130,19 @@ MainWindow::~MainWindow()
 
     if(helpDialog)
         delete helpDialog;
+
+    if(customButtonAccelerate)
+        delete customButtonAccelerate;
+    if(customButtonRoute)
+        delete customButtonRoute;
+    if(customButtonResults)
+        delete customButtonResults;
+
 }
 
+/**
+  *
+  */
 void MainWindow::changeEvent(QEvent *e)
 {
     QMainWindow::changeEvent(e);
@@ -118,20 +170,9 @@ void MainWindow::on_pushButtonCredits_clicked()
 {
     if(!helpDialog)
         helpDialog = new HelpDialog;
-    helpDialog->show();
-    //creditsDialog->show();
-}
 
-/**
-  * This slot function opens the route save dialog
-  */
-void MainWindow::on_pushButtonRoute_clicked()
-{
-    if(!routeSaveDialog)
-        routeSaveDialog = new RouteSaveDialog;
-    connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
-    connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
-    routeSaveDialog->show();
+    connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
+    helpDialog->show();
 }
 
 /**
@@ -143,37 +184,12 @@ void MainWindow::on_pushButtonSettings_clicked()
 }
 
 /**
-  * This slot function opens the acceleration dialog
-  */
-void MainWindow::on_pushButtonAccelerate_clicked()
-{
-    if(!accstart)
-        accstart = new accelerationstart(this);
-    connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
-    connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
-    accstart->show();
-}
-
-/**
-  * This slot function opens the top results dialog
-  */
-void MainWindow::on_pushButtonResults_clicked()
-{
-    if (!topResultDialog)
-        topResultDialog = new TopResultDialog;
-    clientRequestCategoryList();
-    connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
-    connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
-    connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
-    topResultDialog->show();
-}
-
-/**
   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
   */
 void MainWindow::clientRequestCategoryList()
 {
-    httpClient->requestCategories();
+    if(httpClient)
+        httpClient->requestCategories();
 }
 
 /**
@@ -181,8 +197,13 @@ void MainWindow::clientRequestCategoryList()
   */
 void MainWindow::clientRequestTopList(int index)
 {
-    QString limit = QString::number(topResultDialog->getLimitNr());
-    httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
+    QString limit;
+
+    if(topResultDialog && httpClient->myXmlreader->myCategoryList)
+    {
+        limit = QString::number(topResultDialog->getLimitNr());
+        httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
+    }
 }
 
 /**
@@ -191,7 +212,8 @@ void MainWindow::clientRequestTopList(int index)
   */
 void MainWindow::setCategoryCompoBox()
 {
-    topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
+    if(topResultDialog && httpClient->myXmlreader->myCategoryList)
+        topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
 }
 
 /**
@@ -200,8 +222,13 @@ void MainWindow::setCategoryCompoBox()
   */
 void MainWindow::showTop10()
 {
-    int ind = topResultDialog->getRecentCategoryIndex();
-    setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
+    int ind;
+
+    if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
+    {
+        ind = topResultDialog->getRecentCategoryIndex();
+        setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
+    }
 }
 
 /**
@@ -212,8 +239,12 @@ void MainWindow::showTop10()
 void MainWindow::setListViewTopList(QString category, int size)
 {
     QString topList;
-    topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
-    topResultDialog->showTopList(topList);
+
+    if(httpClient->myXmlreader->myCategoryList && topResultDialog)
+    {
+        topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
+        topResultDialog->showTopList(topList);
+    }
 }
 
 /**
@@ -221,7 +252,8 @@ void MainWindow::setListViewTopList(QString category, int size)
   */
 void MainWindow::clientRegUserToServer()
 {
-    httpClient->requestRegistration();
+    if(httpClient)
+        httpClient->requestRegistration();
 }
 
 /**
@@ -229,8 +261,12 @@ void MainWindow::clientRegUserToServer()
   */
 void MainWindow::clientUserLogin()
 {
-    connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
-    httpClient->checkLogin();
+    
+    if(httpClient)
+    {
+       connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
+        httpClient->checkLogin();
+    }
 }
 
 /**
@@ -238,7 +274,8 @@ void MainWindow::clientUserLogin()
   */
 void MainWindow::clientSendRoute()
 {
-    httpClient->sendRouteXml();
+    if(httpClient)
+        httpClient->sendRouteXml();
 }
 
 /**
@@ -249,31 +286,51 @@ void MainWindow::clientSendResult(QString category, double result)
     qDebug() << "__clientSendResult";
     if(accstart) {
         qDebug() << "_clientSendResult, calling server";
-        httpClient->sendResultXml(category, result);
+        if(httpClient)
+            httpClient->sendResultXml(category, result);
     }
 }
+
 /**
-  * This slot function called when ever dialog finished.
+  * This slot function called when ever dialog rejected.
   */
 void MainWindow::killDialog()
 {
     if(topResultDialog)
     {
+        qDebug() << "__MW kill: topResultDialog";
         delete topResultDialog;
         topResultDialog = NULL;
     }
-    else if(routeSaveDialog)
+    if(routeSaveDialog)
     {
-        delete routeSaveDialog;
-        routeSaveDialog = NULL;
+        qDebug() << "__MW kill: routeSaveDialog";
+        //delete routeSaveDialog;
+        //routeSaveDialog = NULL;
     }
-    else if(accstart)
+    if(accstart)
     {
+        qDebug() << "__MW kill: accstart";
         delete accstart;
         accstart = NULL;
     }
+    if(welcomeDialog)
+    {
+        qDebug() << "__MW kill: welcomeDialog";
+        delete welcomeDialog;
+        welcomeDialog = NULL;
+    }
+    if(helpDialog)
+    {
+        qDebug() << "__MW kill: helpDialog";
+        delete helpDialog;
+        helpDialog = NULL;
+    }
 }
 
+/**
+  *
+  */
 void MainWindow::setUsernameToMainPanel()
 {
     if (loginSaved())
@@ -285,3 +342,50 @@ void MainWindow::setUsernameToMainPanel()
         this->setWindowTitle("SpeedFreak - Not logged");
     }
 }
+/**
+  * This slot function opens acceleration start dialog.
+  */
+void MainWindow::OpenAccStartDialog()
+{
+    if(!accstart)
+        accstart = new accelerationstart(this);
+
+    connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
+    connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
+    accstart->show();
+}
+/**
+  * This slot function opens the route save dialog
+  */
+void MainWindow::OpenRouteDialog()
+{
+    if(!routeSaveDialog)
+        routeSaveDialog = new RouteSaveDialog;
+
+    connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
+    connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
+    routeSaveDialog->show();
+}
+/**
+  * This slot function opens the top results dialog
+  */
+void MainWindow::OpenResultDialog()
+{
+    if (!topResultDialog)
+        topResultDialog = new TopResultDialog;
+
+    clientRequestCategoryList();
+    connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
+    connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
+    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();
+}