2 * Mainwindow for speedFreak project
4 * @author Rikhard Kuutti <rikhard.kuutti@fudeco.com>
5 * @author Toni Jussila <toni.jussila@fudeco.com>
6 * @author Janne Änäkkälä <janne.anakkala@fudeco.com>
7 * @copyright (c) 2010 Speed Freak team
8 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 #include <QDesktopServices>
15 #include "mainwindow.h"
16 #include "ui_mainwindow.h"
17 #include "usersettings.h"
20 * Constructor of this class.
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;
39 settingsDialog = new SettingsDialog;
40 connect(settingsDialog, SIGNAL(sendregistration()), this, SLOT(clientRegUserToServer()));
41 connect(settingsDialog, SIGNAL(userNameChanged()), this, SLOT(clientUserLogin()));
42 connect(settingsDialog, SIGNAL(logout()), this, SLOT(setUsernameToMainPanel()));
43 connect(settingsDialog, SIGNAL(saveprofile()), this, SLOT(saveProfile()));
45 httpClient = new HttpClient(this);
46 connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
47 connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
49 welcomeDialog = new WelcomeDialog;
50 welcomeDialog->show();
52 this->setUsernameToMainPanel();
54 // Create icon for acceleration start button
55 QIcon* icon = new QIcon();
56 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
57 icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
59 // Acceleration start button
61 customButtonAccelerate = new CustomButton(this,icon);
64 int buttons_x = 50,buttons_y = 165;
65 customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
66 connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
67 customButtonAccelerate->show();
69 // Create icon for route dialog button
71 icon->addFile(QString(":/new/prefix1/Graphics/route.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
72 icon->addFile(QString(":/new/prefix1/Graphics/route_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
74 // Route dialog button
75 customButtonRoute = new CustomButton(this,icon);
79 customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
80 connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
81 customButtonRoute->show();
83 // Create icon for results dialog button
85 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
86 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
88 // 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
102 customButtonSettings = new CustomButton(this,icon);
106 customButtonSettings->setGeometry(buttons_x,buttons_y,130,130);
107 connect(customButtonSettings, SIGNAL(OpenDialog()), this, SLOT(OpenSettingsDialog()));
108 customButtonSettings->show();
110 //Create icon for users dialog button
112 icon->addFile(QString(":/new/prefix1/Graphics/users.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
113 icon->addFile(QString(":/new/prefix1/Graphics/users_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
115 //Users dialog button
116 customButtonUsers = new CustomButton(this,icon);
118 // Create icon for www page button
120 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
121 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
124 customButtonWWW = new CustomButton(this,icon);
129 customButtonUsers->setGeometry(buttons_x,buttons_y,130,130);
130 connect(customButtonUsers, SIGNAL(OpenDialog()), this, SLOT(openUsersDialog()));
131 customButtonUsers->show();
133 // Create icon for help dialog button
135 icon->addFile(QString(":/new/prefix1/Graphics/info.png"), QSize(85,85), QIcon::Normal, QIcon::Off);
136 icon->addFile(QString(":/new/prefix1/Graphics/info_selected.png"), QSize(85,85), QIcon::Normal, QIcon::On);
138 // Help dialog button
139 customButtonHelp = new CustomButton(this,icon);
142 customButtonHelp->setGeometry(670,10,105,105);
143 connect(customButtonHelp, SIGNAL(OpenDialog()), this, SLOT(OpenHelpDialog()));
144 customButtonHelp->show();
147 //Create icon for www page button
149 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet.png"), QSize(85,85), QIcon::Normal, QIcon::Off);
150 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet_selected.png"), QSize(85,85), QIcon::Normal, QIcon::On);
153 customButtonWWW = new CustomButton(this,icon);
156 customButtonWWW->setGeometry(670,320,105,105);
157 connect(customButtonWWW, SIGNAL(OpenDialog()), this, SLOT(OpenWWWPage()));
158 customButtonWWW->show();
163 * Destructor of this class
165 MainWindow::~MainWindow()
170 delete routeSaveDialog;
176 delete topResultDialog;
179 delete settingsDialog;
182 delete welcomeDialog;
193 if(customButtonAccelerate)
194 delete customButtonAccelerate;
195 if(customButtonRoute)
196 delete customButtonRoute;
197 if(customButtonResults)
198 delete customButtonResults;
199 if(customButtonSettings)
200 delete customButtonSettings;
202 delete customButtonWWW;
204 delete customButtonHelp;
210 void MainWindow::changeEvent(QEvent *e)
212 QMainWindow::changeEvent(e);
214 case QEvent::LanguageChange:
215 ui->retranslateUi(this);
223 * This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
225 void MainWindow::clientRequestCategoryList()
228 httpClient->requestCategories();
232 * This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
236 void MainWindow::clientRequestTopList(int index)
240 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
242 limit = QString::number(topResultDialog->getLimitNr());
243 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
248 * This function is used to set items to category combobox.
250 void MainWindow::setCategoryCompoBox()
252 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
253 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
257 * This function prcesses UI updating after a new top10List has been received.
259 * @todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
261 void MainWindow::showTop10()
265 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
267 ind = topResultDialog->getRecentCategoryIndex();
268 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
273 * This function is used to set items to labelTopList.
275 * @param QString Category
276 * @param int Size, number of results.
278 void MainWindow::setListViewTopList(QString category, int size)
282 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
284 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
285 topResultDialog->showTopList(topList);
290 * This function register user to server.
292 void MainWindow::clientRegUserToServer()
295 httpClient->requestRegistration();
299 * This function performs login to server.
301 void MainWindow::clientUserLogin()
305 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
306 httpClient->checkLogin();
311 * This function send route data to server.
313 * @param QString oldName, old file name
314 * @param QString newName, new file name
317 void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
320 httpClient->sendRouteXml(oldName, newName, i);
324 * This function send acceleration data to server.
326 * @param QString category
327 * @param double result
329 void MainWindow::clientSendResult(QString category, double result)
331 qDebug() << "__clientSendResult";
333 qDebug() << "_clientSendResult, calling server";
335 httpClient->sendResultXml(category, result);
340 * This slot function called when ever dialog rejected.
342 void MainWindow::killDialog()
346 qDebug() << "__MW kill: topResultDialog";
347 delete topResultDialog;
348 topResultDialog = NULL;
352 //qDebug() << "__MW kill: routeSaveDialog";
353 //delete routeSaveDialog;
354 //routeSaveDialog = NULL;
358 qDebug() << "__MW kill: accstart";
364 qDebug() << "__MW kill: welcomeDialog";
365 delete welcomeDialog;
366 welcomeDialog = NULL;
370 qDebug() << "__MW kill: helpDialog";
376 qDebug() << "__MW kill: usersDialog";
383 * Set user name to main panel.
385 void MainWindow::setUsernameToMainPanel()
389 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
393 this->setWindowTitle("SpeedFreak - Not logged");
397 * This slot function opens acceleration start dialog.
399 void MainWindow::OpenAccStartDialog()
402 accstart = new accelerationstart(this);
404 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
405 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
409 * This slot function opens the route save dialog
411 void MainWindow::OpenRouteDialog()
414 routeSaveDialog = new RouteSaveDialog;
416 connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
417 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
418 routeSaveDialog->show();
421 * This slot function opens the top results dialog
423 void MainWindow::OpenResultDialog()
425 if (!topResultDialog)
426 topResultDialog = new TopResultDialog;
428 clientRequestCategoryList();
429 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
430 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
431 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
432 topResultDialog->show();
435 * This slot function opens the settings dialog
437 void MainWindow::OpenSettingsDialog()
439 settingsDialog->show();
442 * This slot function opens browser to project www page.
444 void MainWindow::OpenWWWPage()
446 QDesktopServices::openUrl(QUrl("http://www.speedfreak-app.com/"));
449 * This slot function opens the main help dialog
451 void MainWindow::OpenHelpDialog()
454 helpDialog = new HelpDialog;
456 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
461 * This slot function save user profile data to server.
463 void MainWindow::saveProfile()
466 httpClient->sendProfileXml();
470 * This slot function calls httpClients requestUserInfo for getting user's information from server.
472 * @param QString name
474 void MainWindow::requestGetUserInfo(QString name)
476 qDebug() << "getUserInfo signal " + name;
479 httpClient->requestUserInfo(name);
484 * This slot function calls httpClients requestUsers for getting usernames from server.
486 void MainWindow::requestGetUsers()
488 qDebug() << "getUsers signal";
491 httpClient->requestUsers();
496 * This slot function open users dialog.
498 void MainWindow::openUsersDialog()
501 usersDialog = new UsersDialog;
503 connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString)));
504 //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers()));
506 connect(usersDialog, SIGNAL(rejected()), this, SLOT(killDialog()));