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>
18 MainWindow::MainWindow(QWidget *parent) :
20 ui(new Ui::MainWindow)
24 QCoreApplication::setOrganizationName("Fudeco Oy");
25 QCoreApplication::setOrganizationDomain("fudeco.com");
26 QCoreApplication::setApplicationName("Speed Freak");
28 //routeDialog = new RouteDialog;
29 //connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
33 routeSaveDialog = NULL;
34 topResultDialog = NULL;
36 settingsDialog = new SettingsDialog;
37 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
38 connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
40 httpClient = new HttpClient(this);
41 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
42 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
44 //creditsDialog = new CreditsDialog;
46 welcomeDialog = new WelcomeDialog;
47 welcomeDialog->show();
50 ui->pushButtonAccelerate->setAutoFillBackground(true);
51 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
52 ui->pushButtonRoute->setAutoFillBackground(true);
53 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
54 ui->pushButtonResults->setAutoFillBackground(true);
55 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 ui->pushButtonSettings->setAutoFillBackground(true);
57 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
58 ui->pushButtonWWW->setAutoFillBackground(true);
59 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60 ui->pushButtonCredits->setAutoFillBackground(true);
61 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64 MainWindow::~MainWindow()
69 delete routeSaveDialog;
75 delete topResultDialog;
78 delete settingsDialog;
90 void MainWindow::changeEvent(QEvent *e)
92 QMainWindow::changeEvent(e);
94 case QEvent::LanguageChange:
95 ui->retranslateUi(this);
103 * This slot function opens browser to project www page.
105 void MainWindow::on_pushButtonWWW_clicked()
107 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
111 * This slot function opens the credits dialog
113 void MainWindow::on_pushButtonCredits_clicked()
116 helpDialog = new HelpDialog;
118 //creditsDialog->show();
122 * This slot function opens the route save dialog
124 void MainWindow::on_pushButtonRoute_clicked()
127 routeSaveDialog = new RouteSaveDialog;
128 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
129 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
130 routeSaveDialog->show();
134 * This slot function opens the settings dialog
136 void MainWindow::on_pushButtonSettings_clicked()
138 settingsDialog->show();
142 * This slot function opens the acceleration dialog
144 void MainWindow::on_pushButtonAccelerate_clicked()
147 accstart = new accelerationstart(this);
148 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
149 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
154 * This slot function opens the top results dialog
156 void MainWindow::on_pushButtonResults_clicked()
158 if (!topResultDialog)
159 topResultDialog = new TopResultDialog;
160 clientRequestCategoryList();
161 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
162 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
163 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
164 topResultDialog->show();
168 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
170 void MainWindow::clientRequestCategoryList()
172 httpClient->requestCategories();
176 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
178 void MainWindow::clientRequestTopList(int index)
180 QString limit = QString::number(topResultDialog->getLimitNr());
181 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
185 *This function is used to set items to category combobox. Top-tab view.
188 void MainWindow::setCategoryCompoBox()
190 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
194 *This function prcesses UI updating after a new top10List has been received.
195 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
197 void MainWindow::showTop10()
199 int ind = topResultDialog->getRecentCategoryIndex();
200 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
204 *This function is used to set items to labelTopList. Top-tab view.
206 *@param Size, number of results.
208 void MainWindow::setListViewTopList(QString category, int size)
211 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
212 topResultDialog->showTopList(topList);
216 * This function register user to server.
218 void MainWindow::clientRegUserToServer()
220 httpClient->requestRegistration();
224 * This function performs login to server.
226 void MainWindow::clientUserLogin()
228 httpClient->checkLogin();
232 * This function send route data to server.
234 void MainWindow::clientSendRoute()
236 httpClient->sendRouteXml();
240 * This function send acceleration data to server.
242 void MainWindow::clientSendResult(QString category, double result)
244 qDebug() << "__clientSendResult";
246 qDebug() << "_clientSendResult, calling server";
247 httpClient->sendResultXml(category, result);
251 * This slot function called when ever dialog finished.
253 void MainWindow::killDialog()
257 delete topResultDialog;
258 topResultDialog = NULL;
260 else if(routeSaveDialog)
262 delete routeSaveDialog;
263 routeSaveDialog = NULL;