Bugfix: top results unit km/h -> s and routedialog max speed
[speedfreak] / Client / mainwindow.cpp
index d4df9c8..4f32eee 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * Mainwindow for speedFreak project
  *
- * @author      Rikhard Kuutti <rikhard.kuutti@fudeco.com>
+ * @author      Rikhard Kuutti         <rikhard.kuutti@fudeco.com>
+ * @author      Toni Jussila   <toni.jussila@fudeco.com>
  * @copyright   (c) 2010 Speed Freak team
  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
@@ -24,32 +25,66 @@ MainWindow::MainWindow(QWidget *parent) :
     QCoreApplication::setOrganizationDomain("fudeco.com");
     QCoreApplication::setApplicationName("Speed Freak");
 
-    creditsDialog = new CreditsDialog;
-    routeSaveDialog = new RouteSaveDialog;
-    settingsDialog = new SettingsDialog;
-    connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
-    connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
-    topResultDialog = new TopResultDialog;
-    connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
-    connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
+    //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()));
 
     httpClient = new HttpClient(this);
     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
-    connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
+    connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));    
+
+    //creditsDialog = new CreditsDialog;
 
     welcomeDialog = new WelcomeDialog;
     welcomeDialog->show();
+
+    //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)");
 }
 
 MainWindow::~MainWindow()
 {
     delete ui;
 
-    delete routeSaveDialog;
+    if(routeSaveDialog)
+        delete routeSaveDialog;
 
-    if(!accstart)
+    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)
@@ -64,35 +99,68 @@ void MainWindow::changeEvent(QEvent *e)
     }
 }
 
+/**
+  * This slot function opens browser to project www page.
+  */
 void MainWindow::on_pushButtonWWW_clicked()
 {
     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
 }
 
+/**
+  * This slot function opens the credits dialog
+  */
 void MainWindow::on_pushButtonCredits_clicked()
 {
-    creditsDialog->show();
+    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();
 }
 
+/**
+  * This slot function opens the settings dialog
+  */
 void MainWindow::on_pushButtonSettings_clicked()
 {
     settingsDialog->show();
 }
 
+/**
+  * 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(topResultDialog, 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();
 }
 
@@ -109,7 +177,6 @@ void MainWindow::clientRequestCategoryList()
   */
 void MainWindow::clientRequestTopList(int index)
 {
-    qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
     QString limit = QString::number(topResultDialog->getLimitNr());
     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
 }
@@ -120,7 +187,6 @@ void MainWindow::clientRequestTopList(int index)
   */
 void MainWindow::setCategoryCompoBox()
 {
-    qDebug() << "_setCategoryCompoBox";
     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
 }
 
@@ -130,7 +196,6 @@ void MainWindow::setCategoryCompoBox()
   */
 void MainWindow::showTop10()
 {
-    qDebug() << "_showTop10";
     int ind = topResultDialog->getRecentCategoryIndex();
     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
 }
@@ -142,18 +207,64 @@ void MainWindow::showTop10()
   */
 void MainWindow::setListViewTopList(QString category, int size)
 {
-    qDebug() << "_setListViewTopList" << category;
     QString topList;
     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
     topResultDialog->showTopList(topList);
 }
 
-void MainWindow::regUserToServer()
+/**
+  * This function register user to server.
+  */
+void MainWindow::clientRegUserToServer()
 {
     httpClient->requestRegistration();
 }
 
-void MainWindow::userLogin()
+/**
+  * This function performs login to server.
+  */
+void MainWindow::clientUserLogin()
 {
     httpClient->checkLogin();
 }
+
+/**
+  * This function send route data to server.
+  */
+void MainWindow::clientSendRoute()
+{
+    httpClient->sendRouteXml();
+}
+
+/**
+  * This function send acceleration data to server.
+  */
+void MainWindow::clientSendResult(QString category, double result)
+{
+    qDebug() << "__clientSendResult";
+    if(accstart) {
+        qDebug() << "_clientSendResult, calling server";
+        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;
+    }
+}