2 * Mainwindow for speedFreak project
4 * @author Rikhard Kuutti <rikhard.kuutti@fudeco.com>
5 * @author Toni Jussila <toni.jussila@fudeco.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 #include "mainwindow.h"
11 #include "ui_mainwindow.h"
13 #include <QDesktopServices>
17 #include "usersettings.h"
19 MainWindow::MainWindow(QWidget *parent) :
21 ui(new Ui::MainWindow)
25 QCoreApplication::setOrganizationName("Fudeco Oy");
26 QCoreApplication::setOrganizationDomain("fudeco.com");
27 QCoreApplication::setApplicationName("Speed Freak");
31 routeSaveDialog = NULL;
32 topResultDialog = NULL;
34 settingsDialog = new SettingsDialog;
35 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
36 connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
37 connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
39 httpClient = new HttpClient(this);
40 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
41 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
43 welcomeDialog = new WelcomeDialog;
44 welcomeDialog->show();
46 this->setUsernameToMainPanel();
49 ui->pushButtonSettings->setAutoFillBackground(true);
50 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
51 ui->pushButtonWWW->setAutoFillBackground(true);
52 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
53 ui->pushButtonCredits->setAutoFillBackground(true);
54 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 //Create icon for acceleration start button
57 QIcon* icon = new QIcon();
58 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
59 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
61 //Acceleration start button
63 customButtonAccelerate = new CustomButton(this,icon);
66 int buttons_x = 50,buttons_y = 165;
67 customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
68 connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
69 customButtonAccelerate->show();
71 //Create icon for route dialog button
73 icon->addFile(QString(":/new/prefix1/Graphics/route.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
74 icon->addFile(QString(":/new/prefix1/Graphics/route_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
78 customButtonRoute = new CustomButton(this,icon);
82 customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
83 connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
84 customButtonRoute->show();
86 //Create icon for results dialog button
88 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
89 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
91 //Results dialog button
93 customButtonResults = new CustomButton(this,icon);
97 customButtonResults->setGeometry(buttons_x,buttons_y,130,130);
98 connect(customButtonResults, SIGNAL(OpenDialog()), this, SLOT(OpenResultDialog()));
99 customButtonResults->show();
102 MainWindow::~MainWindow()
107 delete routeSaveDialog;
113 delete topResultDialog;
116 delete settingsDialog;
119 delete welcomeDialog;
127 if(customButtonAccelerate)
128 delete customButtonAccelerate;
129 if(customButtonRoute)
130 delete customButtonRoute;
131 if(customButtonResults)
132 delete customButtonResults;
136 void MainWindow::changeEvent(QEvent *e)
138 QMainWindow::changeEvent(e);
140 case QEvent::LanguageChange:
141 ui->retranslateUi(this);
149 * This slot function opens browser to project www page.
151 void MainWindow::on_pushButtonWWW_clicked()
153 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
157 * This slot function opens the credits dialog
159 void MainWindow::on_pushButtonCredits_clicked()
162 helpDialog = new HelpDialog;
164 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
169 * This slot function opens the settings dialog
171 void MainWindow::on_pushButtonSettings_clicked()
173 settingsDialog->show();
177 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
179 void MainWindow::clientRequestCategoryList()
182 httpClient->requestCategories();
186 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
188 void MainWindow::clientRequestTopList(int index)
192 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
194 limit = QString::number(topResultDialog->getLimitNr());
195 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
200 *This function is used to set items to category combobox. Top-tab view.
203 void MainWindow::setCategoryCompoBox()
205 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
206 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
210 *This function prcesses UI updating after a new top10List has been received.
211 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
213 void MainWindow::showTop10()
217 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
219 ind = topResultDialog->getRecentCategoryIndex();
220 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
225 *This function is used to set items to labelTopList. Top-tab view.
227 *@param Size, number of results.
229 void MainWindow::setListViewTopList(QString category, int size)
233 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
235 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
236 topResultDialog->showTopList(topList);
241 * This function register user to server.
243 void MainWindow::clientRegUserToServer()
246 httpClient->requestRegistration();
250 * This function performs login to server.
252 void MainWindow::clientUserLogin()
257 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
258 httpClient->checkLogin();
263 * This function send route data to server.
265 void MainWindow::clientSendRoute()
268 httpClient->sendRouteXml();
272 * This function send acceleration data to server.
274 void MainWindow::clientSendResult(QString category, double result)
276 qDebug() << "__clientSendResult";
278 qDebug() << "_clientSendResult, calling server";
280 httpClient->sendResultXml(category, result);
284 * This slot function called when ever dialog rejected.
286 void MainWindow::killDialog()
290 qDebug() << "__MW kill: topResultDialog";
291 delete topResultDialog;
292 topResultDialog = NULL;
296 qDebug() << "__MW kill: routeSaveDialog";
297 //delete routeSaveDialog;
298 //routeSaveDialog = NULL;
302 qDebug() << "__MW kill: accstart";
308 qDebug() << "__MW kill: welcomeDialog";
309 delete welcomeDialog;
310 welcomeDialog = NULL;
314 qDebug() << "__MW kill: helpDialog";
322 void MainWindow::setUsernameToMainPanel()
326 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
330 this->setWindowTitle("SpeedFreak - Not logged");
334 * This slot function opens acceleration start dialog.
336 void MainWindow::OpenAccStartDialog()
339 accstart = new accelerationstart(this);
341 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
342 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
346 * This slot function opens the route save dialog
348 void MainWindow::OpenRouteDialog()
351 routeSaveDialog = new RouteSaveDialog;
353 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
354 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
355 routeSaveDialog->show();
358 * This slot function opens the top results dialog
360 void MainWindow::OpenResultDialog()
362 if (!topResultDialog)
363 topResultDialog = new TopResultDialog;
365 clientRequestCategoryList();
366 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
367 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
368 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
369 topResultDialog->show();