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()));
32 routeSaveDialog = NULL;
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()));
48 //creditsDialog = new CreditsDialog;
50 welcomeDialog = new WelcomeDialog;
51 welcomeDialog->show();
54 ui->pushButtonAccelerate->setAutoFillBackground(true);
55 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 ui->pushButtonRoute->setAutoFillBackground(true);
57 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
58 ui->pushButtonResults->setAutoFillBackground(true);
59 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60 ui->pushButtonSettings->setAutoFillBackground(true);
61 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
62 ui->pushButtonWWW->setAutoFillBackground(true);
63 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64 ui->pushButtonCredits->setAutoFillBackground(true);
65 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
68 MainWindow::~MainWindow()
71 delete routeSaveDialog;
78 void MainWindow::changeEvent(QEvent *e)
80 QMainWindow::changeEvent(e);
82 case QEvent::LanguageChange:
83 ui->retranslateUi(this);
91 * This slot function opens browser to project www page.
93 void MainWindow::on_pushButtonWWW_clicked()
95 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
99 * This slot function opens the credits dialog
101 void MainWindow::on_pushButtonCredits_clicked()
104 helpDialog = new HelpDialog;
106 //creditsDialog->show();
110 * This slot function opens the route save dialog
112 void MainWindow::on_pushButtonRoute_clicked()
115 routeSaveDialog = new RouteSaveDialog;
116 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
117 routeSaveDialog->show();
121 * This slot function opens the settings dialog
123 void MainWindow::on_pushButtonSettings_clicked()
125 settingsDialog->show();
129 * This slot function opens the acceleration dialog
131 void MainWindow::on_pushButtonAccelerate_clicked()
134 accstart = new accelerationstart(this);
135 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
140 * This slot function opens the top results dialog
142 void MainWindow::on_pushButtonResults_clicked()
144 topResultDialog->show();
148 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
150 void MainWindow::clientRequestCategoryList()
152 httpClient->requestCategories();
156 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
158 void MainWindow::clientRequestTopList(int index)
160 QString limit = QString::number(topResultDialog->getLimitNr());
161 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
165 *This function is used to set items to category combobox. Top-tab view.
168 void MainWindow::setCategoryCompoBox()
170 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
174 *This function prcesses UI updating after a new top10List has been received.
175 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
177 void MainWindow::showTop10()
179 int ind = topResultDialog->getRecentCategoryIndex();
180 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
184 *This function is used to set items to labelTopList. Top-tab view.
186 *@param Size, number of results.
188 void MainWindow::setListViewTopList(QString category, int size)
191 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
192 topResultDialog->showTopList(topList);
198 void MainWindow::clientRegUserToServer()
200 httpClient->requestRegistration();
204 * This function performs login to server
206 void MainWindow::clientUserLogin()
208 httpClient->checkLogin();
212 * This function send route to server
214 void MainWindow::clientSendRoute()
216 httpClient->sendRouteXml();
220 * This function send acceleration data to server
222 void MainWindow::clientSendResult(QString category, double result)
224 qDebug() << "__clientSendResult";
226 qDebug() << "_clientSendResult, calling server";
227 httpClient->sendResultXml(category, result);