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 www page button
115 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
116 icon->addFile(QString(":/new/prefix1/Graphics/applications_internet_selected.png"), QSize(125,125), QIcon::Normal, QIcon::On);
120 customButtonWWW = new CustomButton(this,icon);
124 customButtonWWW->setGeometry(buttons_x,buttons_y,130,130);
125 connect(customButtonWWW, SIGNAL(OpenDialog()), this, SLOT(OpenWWWPage()));
126 customButtonWWW->show();
128 //Create icon for help dialog button
130 icon->addFile(QString(":/new/prefix1/Graphics/info.png"), QSize(105,105), QIcon::Normal, QIcon::Off);
131 icon->addFile(QString(":/new/prefix1/Graphics/info_selected.png"), QSize(105,105), QIcon::Normal, QIcon::On);
135 customButtonHelp = new CustomButton(this,icon);
138 customButtonHelp->setGeometry(670,10,105,105);
139 connect(customButtonHelp, SIGNAL(OpenDialog()), this, SLOT(OpenHelpDialog()));
140 customButtonHelp->show();
146 MainWindow::~MainWindow()
151 delete routeSaveDialog;
157 delete topResultDialog;
160 delete settingsDialog;
163 delete welcomeDialog;
171 if(customButtonAccelerate)
172 delete customButtonAccelerate;
173 if(customButtonRoute)
174 delete customButtonRoute;
175 if(customButtonResults)
176 delete customButtonResults;
177 if(customButtonSettings)
178 delete customButtonSettings;
180 delete customButtonWWW;
182 delete customButtonHelp;
188 void MainWindow::changeEvent(QEvent *e)
190 QMainWindow::changeEvent(e);
192 case QEvent::LanguageChange:
193 ui->retranslateUi(this);
201 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
203 void MainWindow::clientRequestCategoryList()
206 httpClient->requestCategories();
210 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
212 void MainWindow::clientRequestTopList(int index)
216 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
218 limit = QString::number(topResultDialog->getLimitNr());
219 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
224 *This function is used to set items to category combobox.
227 void MainWindow::setCategoryCompoBox()
229 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
230 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
234 *This function prcesses UI updating after a new top10List has been received.
235 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
237 void MainWindow::showTop10()
241 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
243 ind = topResultDialog->getRecentCategoryIndex();
244 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
249 *This function is used to set items to labelTopList. Top-tab view.
251 *@param Size, number of results.
253 void MainWindow::setListViewTopList(QString category, int size)
257 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
259 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
260 topResultDialog->showTopList(topList);
265 * This function register user to server.
267 void MainWindow::clientRegUserToServer()
270 httpClient->requestRegistration();
274 * This function performs login to server.
276 void MainWindow::clientUserLogin()
281 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
282 httpClient->checkLogin();
287 * This function send route data to server.
288 * @param QString oldName, old file name
289 * @param QString newName, new file name
292 void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
295 httpClient->sendRouteXml(oldName, newName, i);
299 * This function send acceleration data to server.
301 void MainWindow::clientSendResult(QString category, double result)
303 qDebug() << "__clientSendResult";
305 qDebug() << "_clientSendResult, calling server";
307 httpClient->sendResultXml(category, result);
312 * This slot function called when ever dialog rejected.
314 void MainWindow::killDialog()
318 qDebug() << "__MW kill: topResultDialog";
319 delete topResultDialog;
320 topResultDialog = NULL;
324 //qDebug() << "__MW kill: routeSaveDialog";
325 //delete routeSaveDialog;
326 //routeSaveDialog = NULL;
330 qDebug() << "__MW kill: accstart";
336 qDebug() << "__MW kill: welcomeDialog";
337 delete welcomeDialog;
338 welcomeDialog = NULL;
342 qDebug() << "__MW kill: helpDialog";
351 void MainWindow::setUsernameToMainPanel()
355 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
359 this->setWindowTitle("SpeedFreak - Not logged");
363 * This slot function opens acceleration start dialog.
365 void MainWindow::OpenAccStartDialog()
368 accstart = new accelerationstart(this);
370 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
371 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
375 * This slot function opens the route save dialog
377 void MainWindow::OpenRouteDialog()
380 routeSaveDialog = new RouteSaveDialog;
382 connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
383 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
384 routeSaveDialog->show();
387 * This slot function opens the top results dialog
389 void MainWindow::OpenResultDialog()
391 if (!topResultDialog)
392 topResultDialog = new TopResultDialog;
394 clientRequestCategoryList();
395 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
396 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
397 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
398 topResultDialog->show();
401 * This slot function opens the settings dialog
403 void MainWindow::OpenSettingsDialog()
405 settingsDialog->show();
408 * This slot function opens browser to project www page.
410 void MainWindow::OpenWWWPage()
412 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
415 * This slot function opens the main help dialog
417 void MainWindow::OpenHelpDialog()
420 helpDialog = new HelpDialog;
422 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
427 * This slot function save user profile data to server
429 void MainWindow::saveProfile()
432 httpClient->sendProfileXml();
436 * This slot function calls httpClients requestUserInfo for getting user's information from server.
438 void MainWindow::requestGetUserInfo(QString name)
440 qDebug() << "getUserInfo signal " + name;
443 httpClient->requestUserInfo(name);
448 * This slot function calls httpClients requestUsers for getting usernames from server.
450 void MainWindow::requestGetUsers()
452 qDebug() << "getUsers signal";
455 httpClient->requestUsers();
459 void MainWindow::on_pushButtonUsers_clicked()
462 usersDialog = new UsersDialog;
464 connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString)));
465 //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers()));