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"
22 MainWindow::MainWindow(QWidget *parent) :
24 ui(new Ui::MainWindow)
28 QCoreApplication::setOrganizationName("Fudeco Oy");
29 QCoreApplication::setOrganizationDomain("fudeco.com");
30 QCoreApplication::setApplicationName("Speed Freak");
34 routeSaveDialog = NULL;
35 topResultDialog = NULL;
37 settingsDialog = new SettingsDialog;
38 connect(settingsDialog, SIGNAL(sendregistration()), this, SLOT(clientRegUserToServer()));
39 connect(settingsDialog, SIGNAL(userNameChanged()), this, SLOT(clientUserLogin()));
40 connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
41 connect(settingsDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile()));
43 httpClient = new HttpClient(this);
44 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
45 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
47 welcomeDialog = new WelcomeDialog;
48 welcomeDialog->show();
50 this->setUsernameToMainPanel();
52 //Create icon for acceleration start button
53 QIcon* icon = new QIcon();
54 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
55 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
57 //Acceleration start button
59 customButtonAccelerate = new CustomButton(this,icon);
62 int buttons_x = 50,buttons_y = 165;
63 customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
64 connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
65 customButtonAccelerate->show();
67 //Create icon for route dialog button
69 icon->addFile(QString(":/new/prefix1/Graphics/route.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
70 icon->addFile(QString(":/new/prefix1/Graphics/route_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
74 customButtonRoute = new CustomButton(this,icon);
78 customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
79 connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
80 customButtonRoute->show();
82 //Create icon for results dialog button
84 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
85 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
87 //Results dialog button
89 customButtonResults = new CustomButton(this,icon);
93 customButtonResults->setGeometry(buttons_x,buttons_y,130,130);
94 connect(customButtonResults, SIGNAL(OpenDialog()), this, SLOT(OpenResultDialog()));
95 customButtonResults->show();
96 //Create icon for settings dialog button
98 icon->addFile(QString(":/new/prefix1/Graphics/settings.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
99 icon->addFile(QString(":/new/prefix1/Graphics/settings_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
101 //Settings dialog button
103 customButtonSettings = new CustomButton(this,icon);
107 customButtonSettings->setGeometry(buttons_x,buttons_y,130,130);
108 connect(customButtonSettings, SIGNAL(OpenDialog()), this, SLOT(OpenSettingsDialog()));
109 customButtonSettings->show();
111 //Create icon for www page button
113 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
114 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
118 customButtonWWW = new CustomButton(this,icon);
122 customButtonWWW->setGeometry(buttons_x,buttons_y,130,130);
123 connect(customButtonWWW, SIGNAL(OpenDialog()), this, SLOT(OpenWWWPage()));
124 customButtonWWW->show();
126 //Create icon for help dialog button
128 icon->addFile(QString(":/new/prefix1/Graphics/info.png"), QSize(105,105), QIcon::Normal, QIcon::Off);
129 icon->addFile(QString(":/new/prefix1/Graphics/info_selected.png"), QSize(105,105), QIcon::Normal, QIcon::On);
133 customButtonHelp = new CustomButton(this,icon);
136 customButtonHelp->setGeometry(670,10,105,105);
137 connect(customButtonHelp, SIGNAL(OpenDialog()), this, SLOT(OpenHelpDialog()));
138 customButtonHelp->show();
144 MainWindow::~MainWindow()
149 delete routeSaveDialog;
155 delete topResultDialog;
158 delete settingsDialog;
161 delete welcomeDialog;
169 if(customButtonAccelerate)
170 delete customButtonAccelerate;
171 if(customButtonRoute)
172 delete customButtonRoute;
173 if(customButtonResults)
174 delete customButtonResults;
175 if(customButtonSettings)
176 delete customButtonSettings;
178 delete customButtonWWW;
180 delete customButtonHelp;
186 void MainWindow::changeEvent(QEvent *e)
188 QMainWindow::changeEvent(e);
190 case QEvent::LanguageChange:
191 ui->retranslateUi(this);
199 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
201 void MainWindow::clientRequestCategoryList()
204 httpClient->requestCategories();
208 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
210 void MainWindow::clientRequestTopList(int index)
214 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
216 limit = QString::number(topResultDialog->getLimitNr());
217 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
222 *This function is used to set items to category combobox.
225 void MainWindow::setCategoryCompoBox()
227 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
228 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
232 *This function prcesses UI updating after a new top10List has been received.
233 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
235 void MainWindow::showTop10()
239 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
241 ind = topResultDialog->getRecentCategoryIndex();
242 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
247 *This function is used to set items to labelTopList. Top-tab view.
249 *@param Size, number of results.
251 void MainWindow::setListViewTopList(QString category, int size)
255 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
257 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
258 topResultDialog->showTopList(topList);
263 * This function register user to server.
265 void MainWindow::clientRegUserToServer()
268 httpClient->requestRegistration();
272 * This function performs login to server.
274 void MainWindow::clientUserLogin()
279 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
280 httpClient->checkLogin();
285 * This function send route data to server.
286 * @param QString oldName, old file name
287 * @param QString newName, new file name
290 void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
293 httpClient->sendRouteXml(oldName, newName, i);
297 * This function send acceleration data to server.
299 void MainWindow::clientSendResult(QString category, double result)
301 qDebug() << "__clientSendResult";
303 qDebug() << "_clientSendResult, calling server";
305 httpClient->sendResultXml(category, result);
310 * This slot function called when ever dialog rejected.
312 void MainWindow::killDialog()
316 qDebug() << "__MW kill: topResultDialog";
317 delete topResultDialog;
318 topResultDialog = NULL;
322 //qDebug() << "__MW kill: routeSaveDialog";
323 //delete routeSaveDialog;
324 //routeSaveDialog = NULL;
328 qDebug() << "__MW kill: accstart";
334 qDebug() << "__MW kill: welcomeDialog";
335 delete welcomeDialog;
336 welcomeDialog = NULL;
340 qDebug() << "__MW kill: helpDialog";
349 void MainWindow::setUsernameToMainPanel()
353 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
357 this->setWindowTitle("SpeedFreak - Not logged");
361 * This slot function opens acceleration start dialog.
363 void MainWindow::OpenAccStartDialog()
366 accstart = new accelerationstart(this);
368 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
369 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
373 * This slot function opens the route save dialog
375 void MainWindow::OpenRouteDialog()
378 routeSaveDialog = new RouteSaveDialog;
380 connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
381 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
382 routeSaveDialog->show();
385 * This slot function opens the top results dialog
387 void MainWindow::OpenResultDialog()
389 if (!topResultDialog)
390 topResultDialog = new TopResultDialog;
392 clientRequestCategoryList();
393 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
394 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
395 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
396 topResultDialog->show();
399 * This slot function opens the settings dialog
401 void MainWindow::OpenSettingsDialog()
403 settingsDialog->show();
406 * This slot function opens browser to project www page.
408 void MainWindow::OpenWWWPage()
410 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
413 * This slot function opens the main help dialog
415 void MainWindow::OpenHelpDialog()
418 helpDialog = new HelpDialog;
420 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
425 * This slot function save user profile data to server
427 void MainWindow::saveProfile()
430 httpClient->sendProfileXml();