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");
29 //routeDialog = new RouteDialog;
30 //connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
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()));
42 httpClient = new HttpClient(this);
43 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
44 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
46 //creditsDialog = new CreditsDialog;
48 welcomeDialog = new WelcomeDialog;
49 welcomeDialog->show();
51 this->setUsernameToMainPanel();
54 ui->pushButtonAccelerate->setAutoFillBackground(true);
55 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 ui->pushButtonRoute->setAutoFillBackground(true);
57 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
58 ui->pushButtonResults->setAutoFillBackground(true);
59 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60 ui->pushButtonSettings->setAutoFillBackground(true);
61 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
62 ui->pushButtonWWW->setAutoFillBackground(true);
63 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64 ui->pushButtonCredits->setAutoFillBackground(true);
65 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
68 MainWindow::~MainWindow()
73 delete routeSaveDialog;
79 delete topResultDialog;
82 delete settingsDialog;
94 void MainWindow::changeEvent(QEvent *e)
96 QMainWindow::changeEvent(e);
98 case QEvent::LanguageChange:
99 ui->retranslateUi(this);
107 * This slot function opens browser to project www page.
109 void MainWindow::on_pushButtonWWW_clicked()
111 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
115 * This slot function opens the credits dialog
117 void MainWindow::on_pushButtonCredits_clicked()
120 helpDialog = new HelpDialog;
122 //creditsDialog->show();
126 * This slot function opens the route save dialog
128 void MainWindow::on_pushButtonRoute_clicked()
131 routeSaveDialog = new RouteSaveDialog;
132 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
133 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
134 routeSaveDialog->show();
138 * This slot function opens the settings dialog
140 void MainWindow::on_pushButtonSettings_clicked()
142 settingsDialog->show();
146 * This slot function opens the acceleration dialog
148 void MainWindow::on_pushButtonAccelerate_clicked()
151 accstart = new accelerationstart(this);
152 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
153 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
158 * This slot function opens the top results dialog
160 void MainWindow::on_pushButtonResults_clicked()
162 if (!topResultDialog)
163 topResultDialog = new TopResultDialog;
164 clientRequestCategoryList();
165 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
166 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
167 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
168 topResultDialog->show();
172 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
174 void MainWindow::clientRequestCategoryList()
176 httpClient->requestCategories();
180 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
182 void MainWindow::clientRequestTopList(int index)
184 QString limit = QString::number(topResultDialog->getLimitNr());
185 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
189 *This function is used to set items to category combobox. Top-tab view.
192 void MainWindow::setCategoryCompoBox()
194 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
198 *This function prcesses UI updating after a new top10List has been received.
199 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
201 void MainWindow::showTop10()
203 int ind = topResultDialog->getRecentCategoryIndex();
204 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
208 *This function is used to set items to labelTopList. Top-tab view.
210 *@param Size, number of results.
212 void MainWindow::setListViewTopList(QString category, int size)
215 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
216 topResultDialog->showTopList(topList);
220 * This function register user to server.
222 void MainWindow::clientRegUserToServer()
224 httpClient->requestRegistration();
228 * This function performs login to server.
230 void MainWindow::clientUserLogin()
232 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
233 httpClient->checkLogin();
237 * This function send route data to server.
239 void MainWindow::clientSendRoute()
241 httpClient->sendRouteXml();
245 * This function send acceleration data to server.
247 void MainWindow::clientSendResult(QString category, double result)
249 qDebug() << "__clientSendResult";
251 qDebug() << "_clientSendResult, calling server";
252 httpClient->sendResultXml(category, result);
256 * This slot function called when ever dialog finished.
258 void MainWindow::killDialog()
262 delete topResultDialog;
263 topResultDialog = NULL;
265 else if(routeSaveDialog)
267 delete routeSaveDialog;
268 routeSaveDialog = NULL;
277 void MainWindow::setUsernameToMainPanel()
281 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
285 this->setWindowTitle("SpeedFreak - Not logged");