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;
117 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
122 * This slot function opens the route save dialog
124 void MainWindow::on_pushButtonRoute_clicked()
127 routeSaveDialog = new RouteSaveDialog;
129 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
130 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
131 routeSaveDialog->show();
135 * This slot function opens the settings dialog
137 void MainWindow::on_pushButtonSettings_clicked()
139 settingsDialog->show();
143 * This slot function opens the acceleration dialog
145 void MainWindow::on_pushButtonAccelerate_clicked()
148 accstart = new accelerationstart(this);
150 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
151 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
156 * This slot function opens the top results dialog
158 void MainWindow::on_pushButtonResults_clicked()
160 if (!topResultDialog)
161 topResultDialog = new TopResultDialog;
163 clientRequestCategoryList();
164 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
165 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
166 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
167 topResultDialog->show();
171 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
173 void MainWindow::clientRequestCategoryList()
176 httpClient->requestCategories();
180 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
182 void MainWindow::clientRequestTopList(int index)
186 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
188 limit = QString::number(topResultDialog->getLimitNr());
189 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
194 *This function is used to set items to category combobox. Top-tab view.
197 void MainWindow::setCategoryCompoBox()
199 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
200 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
204 *This function prcesses UI updating after a new top10List has been received.
205 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
207 void MainWindow::showTop10()
211 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
213 ind = topResultDialog->getRecentCategoryIndex();
214 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
219 *This function is used to set items to labelTopList. Top-tab view.
221 *@param Size, number of results.
223 void MainWindow::setListViewTopList(QString category, int size)
227 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
229 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
230 topResultDialog->showTopList(topList);
235 * This function register user to server.
237 void MainWindow::clientRegUserToServer()
240 httpClient->requestRegistration();
244 * This function performs login to server.
246 void MainWindow::clientUserLogin()
251 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
252 httpClient->checkLogin();
257 * This function send route data to server.
259 void MainWindow::clientSendRoute()
262 httpClient->sendRouteXml();
266 * This function send acceleration data to server.
268 void MainWindow::clientSendResult(QString category, double result)
270 qDebug() << "__clientSendResult";
272 qDebug() << "_clientSendResult, calling server";
274 httpClient->sendResultXml(category, result);
278 * This slot function called when ever dialog finished.
280 void MainWindow::killDialog()
284 qDebug() << "__MW kill: topResultDialog";
285 delete topResultDialog;
286 topResultDialog = NULL;
290 qDebug() << "__MW kill: routeSaveDialog";
291 //delete routeSaveDialog;
292 //routeSaveDialog = NULL;
296 qDebug() << "__MW kill: accstart";
302 qDebug() << "__MW kill: welcomeDialog";
303 delete welcomeDialog;
304 welcomeDialog = NULL;
308 qDebug() << "__MW kill: helpDialog";
314 void MainWindow::setUsernameToMainPanel()
318 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
322 this->setWindowTitle("SpeedFreak - Not logged");