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;
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);
76 customButtonRoute = new CustomButton(this,icon);
80 customButtonRoute->setGeometry(buttons_x,buttons_y,130,130);
81 connect(customButtonRoute, SIGNAL(OpenDialog()), this, SLOT(OpenRouteDialog()));
82 customButtonRoute->show();
84 //Create icon for results dialog button
86 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
87 icon->addFile(QString(":/new/prefix1/Graphics/trophy_gold_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
89 //Results dialog button
91 customButtonResults = new CustomButton(this,icon);
95 customButtonResults->setGeometry(buttons_x,buttons_y,130,130);
96 connect(customButtonResults, SIGNAL(OpenDialog()), this, SLOT(OpenResultDialog()));
97 customButtonResults->show();
98 //Create icon for settings dialog button
100 icon->addFile(QString(":/new/prefix1/Graphics/settings.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
101 icon->addFile(QString(":/new/prefix1/Graphics/settings_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
103 //Settings dialog button
105 customButtonSettings = new CustomButton(this,icon);
109 customButtonSettings->setGeometry(buttons_x,buttons_y,130,130);
110 connect(customButtonSettings, SIGNAL(OpenDialog()), this, SLOT(OpenSettingsDialog()));
111 customButtonSettings->show();
113 //Create icon for users dialog button
115 icon->addFile(QString(":/new/prefix1/Graphics/users.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
116 icon->addFile(QString(":/new/prefix1/Graphics/users_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
118 //Users dialog button
119 customButtonUsers = new CustomButton(this,icon);
123 customButtonUsers->setGeometry(buttons_x,buttons_y,130,130);
124 connect(customButtonUsers, SIGNAL(OpenDialog()), this, SLOT(openUsersDialog()));
125 customButtonUsers->show();
127 //Create icon for help dialog button
129 icon->addFile(QString(":/new/prefix1/Graphics/info.png"), QSize(85,85), QIcon::Normal, QIcon::Off);
130 icon->addFile(QString(":/new/prefix1/Graphics/info_selected.png"), QSize(85,85), QIcon::Normal, QIcon::On);
134 customButtonHelp = new CustomButton(this,icon);
137 customButtonHelp->setGeometry(670,10,105,105);
138 connect(customButtonHelp, SIGNAL(OpenDialog()), this, SLOT(OpenHelpDialog()));
139 customButtonHelp->show();
142 //Create icon for www page button
144 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet.png"), QSize(85,85), QIcon::Normal, QIcon::Off);
145 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet_selected.png"), QSize(85,85), QIcon::Normal, QIcon::On);
148 customButtonWWW = new CustomButton(this,icon);
151 customButtonWWW->setGeometry(670,320,105,105);
152 connect(customButtonWWW, SIGNAL(OpenDialog()), this, SLOT(OpenWWWPage()));
153 customButtonWWW->show();
160 MainWindow::~MainWindow()
165 delete routeSaveDialog;
171 delete topResultDialog;
174 delete settingsDialog;
177 delete welcomeDialog;
188 if(customButtonAccelerate)
189 delete customButtonAccelerate;
190 if(customButtonRoute)
191 delete customButtonRoute;
192 if(customButtonResults)
193 delete customButtonResults;
194 if(customButtonSettings)
195 delete customButtonSettings;
197 delete customButtonWWW;
199 delete customButtonHelp;
205 void MainWindow::changeEvent(QEvent *e)
207 QMainWindow::changeEvent(e);
209 case QEvent::LanguageChange:
210 ui->retranslateUi(this);
218 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
220 void MainWindow::clientRequestCategoryList()
223 httpClient->requestCategories();
227 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
229 void MainWindow::clientRequestTopList(int index)
233 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
235 limit = QString::number(topResultDialog->getLimitNr());
236 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
241 *This function is used to set items to category combobox.
244 void MainWindow::setCategoryCompoBox()
246 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
247 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
251 *This function prcesses UI updating after a new top10List has been received.
252 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
254 void MainWindow::showTop10()
258 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
260 ind = topResultDialog->getRecentCategoryIndex();
261 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
266 *This function is used to set items to labelTopList. Top-tab view.
268 *@param Size, number of results.
270 void MainWindow::setListViewTopList(QString category, int size)
274 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
276 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
277 topResultDialog->showTopList(topList);
282 * This function register user to server.
284 void MainWindow::clientRegUserToServer()
287 httpClient->requestRegistration();
291 * This function performs login to server.
293 void MainWindow::clientUserLogin()
298 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
299 httpClient->checkLogin();
304 * This function send route data to server.
305 * @param QString oldName, old file name
306 * @param QString newName, new file name
309 void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
312 httpClient->sendRouteXml(oldName, newName, i);
316 * This function send acceleration data to server.
318 void MainWindow::clientSendResult(QString category, double result)
320 qDebug() << "__clientSendResult";
322 qDebug() << "_clientSendResult, calling server";
324 httpClient->sendResultXml(category, result);
329 * This slot function called when ever dialog rejected.
331 void MainWindow::killDialog()
335 qDebug() << "__MW kill: topResultDialog";
336 delete topResultDialog;
337 topResultDialog = NULL;
341 //qDebug() << "__MW kill: routeSaveDialog";
342 //delete routeSaveDialog;
343 //routeSaveDialog = NULL;
347 qDebug() << "__MW kill: accstart";
353 qDebug() << "__MW kill: welcomeDialog";
354 delete welcomeDialog;
355 welcomeDialog = NULL;
359 qDebug() << "__MW kill: helpDialog";
365 qDebug() << "__MW kill: usersDialog";
374 void MainWindow::setUsernameToMainPanel()
378 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
382 this->setWindowTitle("SpeedFreak - Not logged");
386 * This slot function opens acceleration start dialog.
388 void MainWindow::OpenAccStartDialog()
391 accstart = new accelerationstart(this);
393 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
394 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
398 * This slot function opens the route save dialog
400 void MainWindow::OpenRouteDialog()
403 routeSaveDialog = new RouteSaveDialog;
405 connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
406 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
407 routeSaveDialog->show();
410 * This slot function opens the top results dialog
412 void MainWindow::OpenResultDialog()
414 if (!topResultDialog)
415 topResultDialog = new TopResultDialog;
417 clientRequestCategoryList();
418 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
419 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
420 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
421 topResultDialog->show();
424 * This slot function opens the settings dialog
426 void MainWindow::OpenSettingsDialog()
428 settingsDialog->show();
431 * This slot function opens browser to project www page.
433 void MainWindow::OpenWWWPage()
435 QDesktopServices::openUrl(QUrl("http://www.speedfreak-app.com/"));
438 * This slot function opens the main help dialog
440 void MainWindow::OpenHelpDialog()
443 helpDialog = new HelpDialog;
445 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
450 * This slot function save user profile data to server
452 void MainWindow::saveProfile()
455 httpClient->sendProfileXml();
459 * This slot function calls httpClients requestUserInfo for getting user's information from server.
461 void MainWindow::requestGetUserInfo(QString name)
463 qDebug() << "getUserInfo signal " + name;
466 httpClient->requestUserInfo(name);
471 * This slot function calls httpClients requestUsers for getting usernames from server.
473 void MainWindow::requestGetUsers()
475 qDebug() << "getUsers signal";
478 httpClient->requestUsers();
482 void MainWindow::openUsersDialog()
485 usersDialog = new UsersDialog;
487 connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString)));
488 //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers()));
490 connect(usersDialog, SIGNAL(rejected()), this, SLOT(killDialog()));