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;
31 creditsDialog = new CreditsDialog;
32 routeSaveDialog = new RouteSaveDialog;
33 routeDialog = new RouteDialog;
34 connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
35 settingsDialog = new SettingsDialog;
36 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
37 connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
38 topResultDialog = new TopResultDialog;
39 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
40 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
41 httpClient = new HttpClient(this);
42 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
43 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
44 resultDialog = new ResultDialog;
45 connect(resultDialog, SIGNAL(sendresult()), this, SLOT(clientSendResult()));
47 welcomeDialog = new WelcomeDialog;
48 welcomeDialog->show();
51 ui->pushButtonAccelerate->setAutoFillBackground(true);
52 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
53 ui->pushButtonRoute->setAutoFillBackground(true);
54 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
55 ui->pushButtonResults->setAutoFillBackground(true);
56 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
57 ui->pushButtonSettings->setAutoFillBackground(true);
58 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
59 ui->pushButtonWWW->setAutoFillBackground(true);
60 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
61 ui->pushButtonCredits->setAutoFillBackground(true);
62 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
65 MainWindow::~MainWindow()
68 delete routeSaveDialog;
75 void MainWindow::changeEvent(QEvent *e)
77 QMainWindow::changeEvent(e);
79 case QEvent::LanguageChange:
80 ui->retranslateUi(this);
88 * This slot function opens browser to project www page.
90 void MainWindow::on_pushButtonWWW_clicked()
92 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
96 * This slot function opens the credits dialog
98 void MainWindow::on_pushButtonCredits_clicked()
100 creditsDialog->show();
104 * This slot function opens the route save dialog
106 void MainWindow::on_pushButtonRoute_clicked()
108 routeSaveDialog->show();
112 * This slot function opens the settings dialog
114 void MainWindow::on_pushButtonSettings_clicked()
116 settingsDialog->show();
120 * This slot function opens the acceleration dialog
122 void MainWindow::on_pushButtonAccelerate_clicked()
125 accstart = new accelerationstart(this);
130 * This slot function opens the top results dialog
132 void MainWindow::on_pushButtonResults_clicked()
134 topResultDialog->show();
138 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
140 void MainWindow::clientRequestCategoryList()
142 httpClient->requestCategories();
146 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
148 void MainWindow::clientRequestTopList(int index)
150 QString limit = QString::number(topResultDialog->getLimitNr());
151 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
155 *This function is used to set items to category combobox. Top-tab view.
158 void MainWindow::setCategoryCompoBox()
160 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
164 *This function prcesses UI updating after a new top10List has been received.
165 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
167 void MainWindow::showTop10()
169 int ind = topResultDialog->getRecentCategoryIndex();
170 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
174 *This function is used to set items to labelTopList. Top-tab view.
176 *@param Size, number of results.
178 void MainWindow::setListViewTopList(QString category, int size)
181 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
182 topResultDialog->showTopList(topList);
185 void MainWindow::clientRegUserToServer()
187 httpClient->requestRegistration();
191 * This function performs login to server
193 void MainWindow::clientUserLogin()
195 httpClient->checkLogin();
198 void MainWindow::clientSendRoute()
200 httpClient->sendRouteXml();
203 void MainWindow::clientSendResult()
205 qDebug() << "_clientSendResult";
207 qDebug() << "_clientSendResult, calling server";
208 httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());