Bugfix: Settings help dialog has wrong names in buttons because changes have been...
[speedfreak] / Client / mainwindow.cpp
index 7b04b08..c01329c 100644 (file)
@@ -26,9 +26,6 @@ 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;
@@ -43,8 +40,6 @@ MainWindow::MainWindow(QWidget *parent) :
     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
     connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));    
 
-    //creditsDialog = new CreditsDialog;
-
     welcomeDialog = new WelcomeDialog;
     welcomeDialog->show();
 
@@ -63,6 +58,20 @@ MainWindow::MainWindow(QWidget *parent) :
     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)");
+    /*
+    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);
+
+    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();
+    */
 }
 
 MainWindow::~MainWindow()
@@ -89,6 +98,10 @@ MainWindow::~MainWindow()
 
     if(helpDialog)
         delete helpDialog;
+/*
+    if(customButtonAccelerate)
+        delete customButtonAccelerate;
+*/
 }
 
 void MainWindow::changeEvent(QEvent *e)
@@ -118,8 +131,9 @@ void MainWindow::on_pushButtonCredits_clicked()
 {
     if(!helpDialog)
         helpDialog = new HelpDialog;
+
+    connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     helpDialog->show();
-    //creditsDialog->show();
 }
 
 /**
@@ -129,8 +143,9 @@ void MainWindow::on_pushButtonRoute_clicked()
 {
     if(!routeSaveDialog)
         routeSaveDialog = new RouteSaveDialog;
+
     connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
-    connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
+    connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     routeSaveDialog->show();
 }
 
@@ -149,6 +164,7 @@ 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();
@@ -161,6 +177,7 @@ 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)));
@@ -173,7 +190,8 @@ void MainWindow::on_pushButtonResults_clicked()
   */
 void MainWindow::clientRequestCategoryList()
 {
-    httpClient->requestCategories();
+    if(httpClient)
+        httpClient->requestCategories();
 }
 
 /**
@@ -181,8 +199,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 +214,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 +224,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 +241,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 +254,8 @@ void MainWindow::setListViewTopList(QString category, int size)
   */
 void MainWindow::clientRegUserToServer()
 {
-    httpClient->requestRegistration();
+    if(httpClient)
+        httpClient->requestRegistration();
 }
 
 /**
@@ -229,8 +263,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 +276,8 @@ void MainWindow::clientUserLogin()
   */
 void MainWindow::clientSendRoute()
 {
-    httpClient->sendRouteXml();
+    if(httpClient)
+        httpClient->sendRouteXml();
 }
 
 /**
@@ -249,7 +288,8 @@ 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);
     }
 }
 /**
@@ -259,21 +299,38 @@ 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,14 @@ 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();
+}