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;
34 settingsDialog = new SettingsDialog;
35 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
36 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)));
42 httpClient = new HttpClient(this);
43 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
44 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
46 resultDialog = new ResultDialog;
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()
106 helpDialog = new HelpDialog;
108 //creditsDialog->show();
112 * This slot function opens the route save dialog
114 void MainWindow::on_pushButtonRoute_clicked()
116 routeSaveDialog->show();
120 * This slot function opens the settings dialog
122 void MainWindow::on_pushButtonSettings_clicked()
124 settingsDialog->show();
128 * This slot function opens the acceleration dialog
130 void MainWindow::on_pushButtonAccelerate_clicked()
133 accstart = new accelerationstart(this);
134 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
139 * This slot function opens the top results dialog
141 void MainWindow::on_pushButtonResults_clicked()
143 topResultDialog->show();
147 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
149 void MainWindow::clientRequestCategoryList()
151 httpClient->requestCategories();
155 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
157 void MainWindow::clientRequestTopList(int index)
159 QString limit = QString::number(topResultDialog->getLimitNr());
160 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
164 *This function is used to set items to category combobox. Top-tab view.
167 void MainWindow::setCategoryCompoBox()
169 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
173 *This function prcesses UI updating after a new top10List has been received.
174 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
176 void MainWindow::showTop10()
178 int ind = topResultDialog->getRecentCategoryIndex();
179 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
183 *This function is used to set items to labelTopList. Top-tab view.
185 *@param Size, number of results.
187 void MainWindow::setListViewTopList(QString category, int size)
190 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
191 topResultDialog->showTopList(topList);
194 void MainWindow::clientRegUserToServer()
196 httpClient->requestRegistration();
200 * This function performs login to server
202 void MainWindow::clientUserLogin()
204 httpClient->checkLogin();
208 * This function send route to server
210 void MainWindow::clientSendRoute()
212 httpClient->sendRouteXml();
216 * This function send acceleration data to server
218 void MainWindow::clientSendResult(QString category, double result)
220 /*QMessageBox msgBox;
221 msgBox.setWindowTitle("client send result!");
222 msgBox.setText("client send result!");
223 msgBox.setDefaultButton(QMessageBox::Ok);
226 qDebug() << "__clientSendResult";
228 qDebug() << "_clientSendResult, calling server";
229 httpClient->sendResultXml(category, result);
230 //httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());