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()));
31 routeSaveDialog = new RouteSaveDialog;
33 settingsDialog = new SettingsDialog;
34 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
35 connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
37 topResultDialog = new TopResultDialog;
38 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
39 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()));
45 resultDialog = new ResultDialog;
46 connect(resultDialog, SIGNAL(sendresult()), this, SLOT(clientSendResult()));
50 creditsDialog = new CreditsDialog;
52 welcomeDialog = new WelcomeDialog;
53 welcomeDialog->show();
56 ui->pushButtonAccelerate->setAutoFillBackground(true);
57 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
58 ui->pushButtonRoute->setAutoFillBackground(true);
59 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60 ui->pushButtonResults->setAutoFillBackground(true);
61 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
62 ui->pushButtonSettings->setAutoFillBackground(true);
63 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64 ui->pushButtonWWW->setAutoFillBackground(true);
65 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
66 ui->pushButtonCredits->setAutoFillBackground(true);
67 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
70 MainWindow::~MainWindow()
73 delete routeSaveDialog;
80 void MainWindow::changeEvent(QEvent *e)
82 QMainWindow::changeEvent(e);
84 case QEvent::LanguageChange:
85 ui->retranslateUi(this);
93 * This slot function opens browser to project www page.
95 void MainWindow::on_pushButtonWWW_clicked()
97 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
101 * This slot function opens the credits dialog
103 void MainWindow::on_pushButtonCredits_clicked()
105 creditsDialog->show();
109 * This slot function opens the route save dialog
111 void MainWindow::on_pushButtonRoute_clicked()
113 routeSaveDialog->show();
117 * This slot function opens the settings dialog
119 void MainWindow::on_pushButtonSettings_clicked()
121 settingsDialog->show();
125 * This slot function opens the acceleration dialog
127 void MainWindow::on_pushButtonAccelerate_clicked()
130 accstart = new accelerationstart(this);
135 * This slot function opens the top results dialog
137 void MainWindow::on_pushButtonResults_clicked()
139 topResultDialog->show();
143 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
145 void MainWindow::clientRequestCategoryList()
147 httpClient->requestCategories();
151 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
153 void MainWindow::clientRequestTopList(int index)
155 QString limit = QString::number(topResultDialog->getLimitNr());
156 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
160 *This function is used to set items to category combobox. Top-tab view.
163 void MainWindow::setCategoryCompoBox()
165 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
169 *This function prcesses UI updating after a new top10List has been received.
170 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
172 void MainWindow::showTop10()
174 int ind = topResultDialog->getRecentCategoryIndex();
175 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
179 *This function is used to set items to labelTopList. Top-tab view.
181 *@param Size, number of results.
183 void MainWindow::setListViewTopList(QString category, int size)
186 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
187 topResultDialog->showTopList(topList);
190 void MainWindow::clientRegUserToServer()
192 httpClient->requestRegistration();
196 * This function performs login to server
198 void MainWindow::clientUserLogin()
200 httpClient->checkLogin();
204 * This function send route to server
206 void MainWindow::clientSendRoute()
208 httpClient->sendRouteXml();
212 * This function send acceleration data to server
214 void MainWindow::clientSendResult()
216 qDebug() << "_clientSendResult";
218 qDebug() << "_clientSendResult, calling server";
219 httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());