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"
22 MainWindow::MainWindow(QWidget *parent) :
24 ui(new Ui::MainWindow)
28 QCoreApplication::setOrganizationName("Fudeco Oy");
29 QCoreApplication::setOrganizationDomain("fudeco.com");
30 QCoreApplication::setApplicationName("Speed Freak");
34 routeSaveDialog = NULL;
35 topResultDialog = NULL;
37 settingsDialog = new SettingsDialog;
38 connect(settingsDialog, SIGNAL(sendregistration()), this, SLOT(clientRegUserToServer()));
39 connect(settingsDialog, SIGNAL(userNameChanged()), this, SLOT(clientUserLogin()));
40 connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
41 connect(settingsDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile()));
43 httpClient = new HttpClient(this);
44 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
45 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
47 welcomeDialog = new WelcomeDialog;
48 welcomeDialog->show();
50 this->setUsernameToMainPanel();
53 ui->pushButtonSettings->setAutoFillBackground(true);
54 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
55 ui->pushButtonWWW->setAutoFillBackground(true);
56 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
57 ui->pushButtonCredits->setAutoFillBackground(true);
58 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60 //Create icon for acceleration start button
61 QIcon* icon = new QIcon();
62 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
63 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
65 //Acceleration start button
67 customButtonAccelerate = new CustomButton(this,icon);
70 int buttons_x = 50,buttons_y = 165;
71 customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
72 connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
73 customButtonAccelerate->show();
75 //Create icon for route dialog button
77 icon->addFile(QString(":/new/prefix1/Graphics/route.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
78 icon->addFile(QString(":/new/prefix1/Graphics/route_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
82 customButtonRoute = new CustomButton(this,icon);
86 customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
87 connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
88 customButtonRoute->show();
90 //Create icon for results dialog button
92 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
93 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
95 //Results dialog button
97 customButtonResults = new CustomButton(this,icon);
101 customButtonResults->setGeometry(buttons_x,buttons_y,130,130);
102 connect(customButtonResults, SIGNAL(OpenDialog()), this, SLOT(OpenResultDialog()));
103 customButtonResults->show();
109 MainWindow::~MainWindow()
114 delete routeSaveDialog;
120 delete topResultDialog;
123 delete settingsDialog;
126 delete welcomeDialog;
134 if(customButtonAccelerate)
135 delete customButtonAccelerate;
136 if(customButtonRoute)
137 delete customButtonRoute;
138 if(customButtonResults)
139 delete customButtonResults;
146 void MainWindow::changeEvent(QEvent *e)
148 QMainWindow::changeEvent(e);
150 case QEvent::LanguageChange:
151 ui->retranslateUi(this);
159 * This slot function opens browser to project www page.
161 void MainWindow::on_pushButtonWWW_clicked()
163 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
167 * This slot function opens the credits dialog
169 void MainWindow::on_pushButtonCredits_clicked()
172 helpDialog = new HelpDialog;
174 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
179 * This slot function opens the settings dialog
181 void MainWindow::on_pushButtonSettings_clicked()
183 settingsDialog->show();
187 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
189 void MainWindow::clientRequestCategoryList()
192 httpClient->requestCategories();
196 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
198 void MainWindow::clientRequestTopList(int index)
202 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
204 limit = QString::number(topResultDialog->getLimitNr());
205 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
210 *This function is used to set items to category combobox. Top-tab view.
213 void MainWindow::setCategoryCompoBox()
215 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
216 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
220 *This function prcesses UI updating after a new top10List has been received.
221 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
223 void MainWindow::showTop10()
227 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
229 ind = topResultDialog->getRecentCategoryIndex();
230 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
235 *This function is used to set items to labelTopList. Top-tab view.
237 *@param Size, number of results.
239 void MainWindow::setListViewTopList(QString category, int size)
243 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
245 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
246 topResultDialog->showTopList(topList);
251 * This function register user to server.
253 void MainWindow::clientRegUserToServer()
256 httpClient->requestRegistration();
260 * This function performs login to server.
262 void MainWindow::clientUserLogin()
267 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
268 httpClient->checkLogin();
273 * This function send route data to server.
275 void MainWindow::clientSendRoute()
278 httpClient->sendRouteXml();
282 * This function send acceleration data to server.
284 void MainWindow::clientSendResult(QString category, double result)
286 qDebug() << "__clientSendResult";
288 qDebug() << "_clientSendResult, calling server";
290 httpClient->sendResultXml(category, result);
295 * This slot function called when ever dialog rejected.
297 void MainWindow::killDialog()
301 qDebug() << "__MW kill: topResultDialog";
302 delete topResultDialog;
303 topResultDialog = NULL;
307 qDebug() << "__MW kill: routeSaveDialog";
308 //delete routeSaveDialog;
309 //routeSaveDialog = NULL;
313 qDebug() << "__MW kill: accstart";
319 qDebug() << "__MW kill: welcomeDialog";
320 delete welcomeDialog;
321 welcomeDialog = NULL;
325 qDebug() << "__MW kill: helpDialog";
334 void MainWindow::setUsernameToMainPanel()
338 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
342 this->setWindowTitle("SpeedFreak - Not logged");
346 * This slot function opens acceleration start dialog.
348 void MainWindow::OpenAccStartDialog()
351 accstart = new accelerationstart(this);
353 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
354 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
358 * This slot function opens the route save dialog
360 void MainWindow::OpenRouteDialog()
363 routeSaveDialog = new RouteSaveDialog;
365 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
366 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
367 routeSaveDialog->show();
370 * This slot function opens the top results dialog
372 void MainWindow::OpenResultDialog()
374 if (!topResultDialog)
375 topResultDialog = new TopResultDialog;
377 clientRequestCategoryList();
378 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
379 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
380 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
381 topResultDialog->show();
385 * This slot function save user profile data to server
387 void MainWindow::saveProfile()
390 httpClient->sendProfileXml();