Bugfix: top results unit km/h -> s and routedialog max speed
[speedfreak] / Client / mainwindow.cpp
index 8dbfc79..4f32eee 100644 (file)
@@ -25,29 +25,23 @@ MainWindow::MainWindow(QWidget *parent) :
     QCoreApplication::setOrganizationDomain("fudeco.com");
     QCoreApplication::setApplicationName("Speed Freak");
 
-    routeDialog = new RouteDialog;
-    connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
+    //routeDialog = new RouteDialog;
+    //connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
 
-    routeSaveDialog = new RouteSaveDialog;
+    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()));
 
-    topResultDialog = new TopResultDialog;
-    connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
-    connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
-
     httpClient = new HttpClient(this);
     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
-    connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
-
-    resultDialog = new ResultDialog;
-    connect(resultDialog, SIGNAL(sendresult()), this, SLOT(clientSendResult()));
-
-    accstart = NULL;
+    connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));    
 
-    creditsDialog = new CreditsDialog;
+    //creditsDialog = new CreditsDialog;
 
     welcomeDialog = new WelcomeDialog;
     welcomeDialog->show();
@@ -70,11 +64,27 @@ MainWindow::MainWindow(QWidget *parent) :
 MainWindow::~MainWindow()
 {
     delete ui;
-    delete routeSaveDialog;
-    delete routeDialog;
+
+    if(routeSaveDialog)
+        delete routeSaveDialog;
 
     if(accstart)
         delete accstart;
+
+    if(topResultDialog)
+        delete topResultDialog;
+
+    if(settingsDialog)
+        delete settingsDialog;
+
+    if(welcomeDialog)
+        delete welcomeDialog;
+
+    if(httpClient)
+        delete httpClient;
+
+    if(helpDialog)
+        delete helpDialog;
 }
 
 void MainWindow::changeEvent(QEvent *e)
@@ -102,7 +112,10 @@ void MainWindow::on_pushButtonWWW_clicked()
   */
 void MainWindow::on_pushButtonCredits_clicked()
 {
-    creditsDialog->show();
+    if(!helpDialog)
+        helpDialog = new HelpDialog;
+    helpDialog->show();
+    //creditsDialog->show();
 }
 
 /**
@@ -110,6 +123,10 @@ void MainWindow::on_pushButtonCredits_clicked()
   */
 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();
 }
 
@@ -128,6 +145,8 @@ void MainWindow::on_pushButtonAccelerate_clicked()
 {
     if(!accstart)
         accstart = new accelerationstart(this);
+    connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
+    connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     accstart->show();
 }
 
@@ -136,6 +155,12 @@ void MainWindow::on_pushButtonAccelerate_clicked()
   */
 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();
 }
 
@@ -187,13 +212,16 @@ void MainWindow::setListViewTopList(QString category, int size)
     topResultDialog->showTopList(topList);
 }
 
+/**
+  * This function register user to server.
+  */
 void MainWindow::clientRegUserToServer()
 {
     httpClient->requestRegistration();
 }
 
 /**
-  * This function performs login to server
+  * This function performs login to server.
   */
 void MainWindow::clientUserLogin()
 {
@@ -201,7 +229,7 @@ void MainWindow::clientUserLogin()
 }
 
 /**
-  * This function send route to server
+  * This function send route data to server.
   */
 void MainWindow::clientSendRoute()
 {
@@ -209,13 +237,34 @@ void MainWindow::clientSendRoute()
 }
 
 /**
-  * This function send acceleration data to server
+  * This function send acceleration data to server.
   */
-void MainWindow::clientSendResult()
+void MainWindow::clientSendResult(QString category, double result)
 {
-    qDebug() << "_clientSendResult";
+    qDebug() << "__clientSendResult";
     if(accstart) {
         qDebug() << "_clientSendResult, calling server";
-        httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());
+        httpClient->sendResultXml(category, result);
+    }
+}
+/**
+  * This slot function called when ever dialog finished.
+  */
+void MainWindow::killDialog()
+{
+    if(topResultDialog)
+    {
+        delete topResultDialog;
+        topResultDialog = NULL;
+    }
+    else if(routeSaveDialog)
+    {
+        delete routeSaveDialog;
+        routeSaveDialog = NULL;
+    }
+    else if(accstart)
+    {
+        delete accstart;
+        accstart = NULL;
     }
 }