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>
17 #include "usersettings.h"
19 MainWindow::MainWindow(QWidget *parent) :
21 ui(new Ui::MainWindow)
25 QCoreApplication::setOrganizationName("Fudeco Oy");
26 QCoreApplication::setOrganizationDomain("fudeco.com");
27 QCoreApplication::setApplicationName("Speed Freak");
31 routeSaveDialog = NULL;
32 topResultDialog = NULL;
34 settingsDialog = new SettingsDialog;
35 connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
36 connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
37 connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
39 httpClient = new HttpClient(this);
40 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
41 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
43 welcomeDialog = new WelcomeDialog;
44 //welcomeDialog->show();
46 this->setUsernameToMainPanel();
49 ui->pushButtonAccelerate->setAutoFillBackground(true);
50 ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
51 ui->pushButtonRoute->setAutoFillBackground(true);
52 ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
53 ui->pushButtonResults->setAutoFillBackground(true);
54 ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
55 ui->pushButtonSettings->setAutoFillBackground(true);
56 ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
57 ui->pushButtonWWW->setAutoFillBackground(true);
58 ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
59 ui->pushButtonCredits->setAutoFillBackground(true);
60 ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
63 MainWindow::~MainWindow()
68 delete routeSaveDialog;
74 delete topResultDialog;
77 delete settingsDialog;
89 void MainWindow::changeEvent(QEvent *e)
91 QMainWindow::changeEvent(e);
93 case QEvent::LanguageChange:
94 ui->retranslateUi(this);
102 * This slot function opens browser to project www page.
104 void MainWindow::on_pushButtonWWW_clicked()
106 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
110 * This slot function opens the credits dialog
112 void MainWindow::on_pushButtonCredits_clicked()
115 helpDialog = new HelpDialog;
121 * This slot function opens the route save dialog
123 void MainWindow::on_pushButtonRoute_clicked()
126 routeSaveDialog = new RouteSaveDialog;
128 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
129 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
130 routeSaveDialog->show();
134 * This slot function opens the settings dialog
136 void MainWindow::on_pushButtonSettings_clicked()
138 settingsDialog->show();
142 * This slot function opens the acceleration dialog
144 void MainWindow::on_pushButtonAccelerate_clicked()
147 accstart = new accelerationstart(this);
149 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
150 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
155 * This slot function opens the top results dialog
157 void MainWindow::on_pushButtonResults_clicked()
159 if (!topResultDialog)
160 topResultDialog = new TopResultDialog;
162 clientRequestCategoryList();
163 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
164 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
165 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
166 topResultDialog->show();
170 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
172 void MainWindow::clientRequestCategoryList()
175 httpClient->requestCategories();
179 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
181 void MainWindow::clientRequestTopList(int index)
185 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
187 limit = QString::number(topResultDialog->getLimitNr());
188 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
193 *This function is used to set items to category combobox. Top-tab view.
196 void MainWindow::setCategoryCompoBox()
198 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
199 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
203 *This function prcesses UI updating after a new top10List has been received.
204 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
206 void MainWindow::showTop10()
210 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
212 ind = topResultDialog->getRecentCategoryIndex();
213 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
218 *This function is used to set items to labelTopList. Top-tab view.
220 *@param Size, number of results.
222 void MainWindow::setListViewTopList(QString category, int size)
226 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
228 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
229 topResultDialog->showTopList(topList);
234 * This function register user to server.
236 void MainWindow::clientRegUserToServer()
239 httpClient->requestRegistration();
243 * This function performs login to server.
245 void MainWindow::clientUserLogin()
250 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
251 httpClient->checkLogin();
256 * This function send route data to server.
258 void MainWindow::clientSendRoute()
261 httpClient->sendRouteXml();
265 * This function send acceleration data to server.
267 void MainWindow::clientSendResult(QString category, double result)
269 qDebug() << "__clientSendResult";
271 qDebug() << "_clientSendResult, calling server";
273 httpClient->sendResultXml(category, result);
277 * This slot function called when ever dialog finished.
279 void MainWindow::killDialog()
283 qDebug() << "__MW kill: topResultDialog";
284 delete topResultDialog;
285 topResultDialog = NULL;
289 qDebug() << "__MW kill: routeSaveDialog";
290 //delete routeSaveDialog;
291 //routeSaveDialog = NULL;
295 qDebug() << "__MW kill: accstart";
301 qDebug() << "__MW kill: welcomeDialog";
302 delete welcomeDialog;
303 welcomeDialog = NULL;
307 qDebug() << "__MW kill: helpDialog";
315 void MainWindow::setUsernameToMainPanel()
319 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
323 this->setWindowTitle("SpeedFreak - Not logged");