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)");
62 QIcon* icon = new QIcon();
63 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
64 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
66 customButtonAccelerate = new CustomButton(this,icon);
69 int buttons_x = 50,buttons_y = 165;
70 customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
71 connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
73 customButtonAccelerate->show();
77 MainWindow::~MainWindow()
82 delete routeSaveDialog;
88 delete topResultDialog;
91 delete settingsDialog;
102 if(customButtonAccelerate)
103 delete customButtonAccelerate;
107 void MainWindow::changeEvent(QEvent *e)
109 QMainWindow::changeEvent(e);
111 case QEvent::LanguageChange:
112 ui->retranslateUi(this);
120 * This slot function opens browser to project www page.
122 void MainWindow::on_pushButtonWWW_clicked()
124 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
128 * This slot function opens the credits dialog
130 void MainWindow::on_pushButtonCredits_clicked()
133 helpDialog = new HelpDialog;
135 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
140 * This slot function opens the route save dialog
142 void MainWindow::on_pushButtonRoute_clicked()
145 routeSaveDialog = new RouteSaveDialog;
147 connect(routeSaveDialog, SIGNAL(sendroute()), this, SLOT(clientSendRoute()));
148 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
149 routeSaveDialog->show();
153 * This slot function opens the settings dialog
155 void MainWindow::on_pushButtonSettings_clicked()
157 settingsDialog->show();
161 * This slot function opens the acceleration dialog
163 void MainWindow::on_pushButtonAccelerate_clicked()
166 accstart = new accelerationstart(this);
168 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
169 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
174 * This slot function opens the top results dialog
176 void MainWindow::on_pushButtonResults_clicked()
178 if (!topResultDialog)
179 topResultDialog = new TopResultDialog;
181 clientRequestCategoryList();
182 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
183 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
184 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
185 topResultDialog->show();
189 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
191 void MainWindow::clientRequestCategoryList()
194 httpClient->requestCategories();
198 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
200 void MainWindow::clientRequestTopList(int index)
204 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
206 limit = QString::number(topResultDialog->getLimitNr());
207 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
212 *This function is used to set items to category combobox. Top-tab view.
215 void MainWindow::setCategoryCompoBox()
217 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
218 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
222 *This function prcesses UI updating after a new top10List has been received.
223 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
225 void MainWindow::showTop10()
229 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
231 ind = topResultDialog->getRecentCategoryIndex();
232 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
237 *This function is used to set items to labelTopList. Top-tab view.
239 *@param Size, number of results.
241 void MainWindow::setListViewTopList(QString category, int size)
245 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
247 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
248 topResultDialog->showTopList(topList);
253 * This function register user to server.
255 void MainWindow::clientRegUserToServer()
258 httpClient->requestRegistration();
262 * This function performs login to server.
264 void MainWindow::clientUserLogin()
269 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
270 httpClient->checkLogin();
275 * This function send route data to server.
277 void MainWindow::clientSendRoute()
280 httpClient->sendRouteXml();
284 * This function send acceleration data to server.
286 void MainWindow::clientSendResult(QString category, double result)
288 qDebug() << "__clientSendResult";
290 qDebug() << "_clientSendResult, calling server";
292 httpClient->sendResultXml(category, result);
296 * This slot function called when ever dialog finished.
298 void MainWindow::killDialog()
302 qDebug() << "__MW kill: topResultDialog";
303 delete topResultDialog;
304 topResultDialog = NULL;
308 qDebug() << "__MW kill: routeSaveDialog";
309 //delete routeSaveDialog;
310 //routeSaveDialog = NULL;
314 qDebug() << "__MW kill: accstart";
320 qDebug() << "__MW kill: welcomeDialog";
321 delete welcomeDialog;
322 welcomeDialog = NULL;
326 qDebug() << "__MW kill: helpDialog";
332 void MainWindow::setUsernameToMainPanel()
336 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
340 this->setWindowTitle("SpeedFreak - Not logged");
344 * This slot function opens acceleration start dialog.
346 void MainWindow::OpenAccStartDialog()
349 accstart = new accelerationstart(this);
350 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
351 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));