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;
49 creditsDialog = new CreditsDialog;
51 welcomeDialog = new WelcomeDialog;
52 welcomeDialog->show();
55 ui->pushButtonAccelerate->setAutoFillBackground(true);
56 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
57 ui->pushButtonRoute->setAutoFillBackground(true);
58 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
59 ui->pushButtonResults->setAutoFillBackground(true);
60 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
61 ui->pushButtonSettings->setAutoFillBackground(true);
62 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
63 ui->pushButtonWWW->setAutoFillBackground(true);
64 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
65 ui->pushButtonCredits->setAutoFillBackground(true);
66 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
69 MainWindow::~MainWindow()
72 delete routeSaveDialog;
79 void MainWindow::changeEvent(QEvent *e)
81 QMainWindow::changeEvent(e);
83 case QEvent::LanguageChange:
84 ui->retranslateUi(this);
92 * This slot function opens browser to project www page.
94 void MainWindow::on_pushButtonWWW_clicked()
96 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
100 * This slot function opens the credits dialog
102 void MainWindow::on_pushButtonCredits_clicked()
104 creditsDialog->show();
108 * This slot function opens the route save dialog
110 void MainWindow::on_pushButtonRoute_clicked()
112 routeSaveDialog->show();
116 * This slot function opens the settings dialog
118 void MainWindow::on_pushButtonSettings_clicked()
120 settingsDialog->show();
124 * This slot function opens the acceleration dialog
126 void MainWindow::on_pushButtonAccelerate_clicked()
129 accstart = new accelerationstart(this);
130 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
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(QString category, double result)
216 /*QMessageBox msgBox;
217 msgBox.setWindowTitle("client send result!");
218 msgBox.setText("client send result!");
219 msgBox.setDefaultButton(QMessageBox::Ok);
222 qDebug() << "__clientSendResult";
224 qDebug() << "_clientSendResult, calling server";
225 httpClient->sendResultXml(category, result);
226 //httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());