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;
174 if(customButtonAccelerate)
175 delete customButtonAccelerate;
176 if(customButtonRoute)
177 delete customButtonRoute;
178 if(customButtonResults)
179 delete customButtonResults;
180 if(customButtonSettings)
181 delete customButtonSettings;
183 delete customButtonWWW;
185 delete customButtonHelp;
191 void MainWindow::changeEvent(QEvent *e)
193 QMainWindow::changeEvent(e);
195 case QEvent::LanguageChange:
196 ui->retranslateUi(this);
204 *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
206 void MainWindow::clientRequestCategoryList()
209 httpClient->requestCategories();
213 *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
215 void MainWindow::clientRequestTopList(int index)
219 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
221 limit = QString::number(topResultDialog->getLimitNr());
222 httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
227 *This function is used to set items to category combobox.
230 void MainWindow::setCategoryCompoBox()
232 if(topResultDialog && httpClient->myXmlreader->myCategoryList)
233 topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
237 *This function prcesses UI updating after a new top10List has been received.
238 *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
240 void MainWindow::showTop10()
244 if(topResultDialog && httpClient->myXmlreader->myCategoryList && topResultDialog)
246 ind = topResultDialog->getRecentCategoryIndex();
247 setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
252 *This function is used to set items to labelTopList. Top-tab view.
254 *@param Size, number of results.
256 void MainWindow::setListViewTopList(QString category, int size)
260 if(httpClient->myXmlreader->myCategoryList && topResultDialog)
262 topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
263 topResultDialog->showTopList(topList);
268 * This function register user to server.
270 void MainWindow::clientRegUserToServer()
273 httpClient->requestRegistration();
277 * This function performs login to server.
279 void MainWindow::clientUserLogin()
284 connect(httpClient, SIGNAL(loginOK()), this, SLOT(setUsernameToMainPanel()));
285 httpClient->checkLogin();
290 * This function send route data to server.
291 * @param QString oldName, old file name
292 * @param QString newName, new file name
295 void MainWindow::clientSendRoute(QString oldName, QString newName, int i)
298 httpClient->sendRouteXml(oldName, newName, i);
302 * This function send acceleration data to server.
304 void MainWindow::clientSendResult(QString category, double result)
306 qDebug() << "__clientSendResult";
308 qDebug() << "_clientSendResult, calling server";
310 httpClient->sendResultXml(category, result);
315 * This slot function called when ever dialog rejected.
317 void MainWindow::killDialog()
321 qDebug() << "__MW kill: topResultDialog";
322 delete topResultDialog;
323 topResultDialog = NULL;
327 //qDebug() << "__MW kill: routeSaveDialog";
328 //delete routeSaveDialog;
329 //routeSaveDialog = NULL;
333 qDebug() << "__MW kill: accstart";
339 qDebug() << "__MW kill: welcomeDialog";
340 delete welcomeDialog;
341 welcomeDialog = NULL;
345 qDebug() << "__MW kill: helpDialog";
351 qDebug() << "__MW kill: usersDialog";
360 void MainWindow::setUsernameToMainPanel()
364 this->setWindowTitle("SpeedFreak - " + settingsDialog->getUserName());
368 this->setWindowTitle("SpeedFreak - Not logged");
372 * This slot function opens acceleration start dialog.
374 void MainWindow::OpenAccStartDialog()
377 accstart = new accelerationstart(this);
379 connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
380 connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
384 * This slot function opens the route save dialog
386 void MainWindow::OpenRouteDialog()
389 routeSaveDialog = new RouteSaveDialog;
391 connect(routeSaveDialog, SIGNAL(sendroute(QString,QString,int)), this, SLOT(clientSendRoute(QString,QString,int)));
392 connect(routeSaveDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
393 routeSaveDialog->show();
396 * This slot function opens the top results dialog
398 void MainWindow::OpenResultDialog()
400 if (!topResultDialog)
401 topResultDialog = new TopResultDialog;
403 clientRequestCategoryList();
404 connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
405 connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
406 connect(topResultDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
407 topResultDialog->show();
410 * This slot function opens the settings dialog
412 void MainWindow::OpenSettingsDialog()
414 settingsDialog->show();
417 * This slot function opens browser to project www page.
419 void MainWindow::OpenWWWPage()
421 QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
424 * This slot function opens the main help dialog
426 void MainWindow::OpenHelpDialog()
429 helpDialog = new HelpDialog;
431 connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
436 * This slot function save user profile data to server
438 void MainWindow::saveProfile()
441 httpClient->sendProfileXml();
445 * This slot function calls httpClients requestUserInfo for getting user's information from server.
447 void MainWindow::requestGetUserInfo(QString name)
449 qDebug() << "getUserInfo signal " + name;
452 httpClient->requestUserInfo(name);
457 * This slot function calls httpClients requestUsers for getting usernames from server.
459 void MainWindow::requestGetUsers()
461 qDebug() << "getUsers signal";
464 httpClient->requestUsers();
468 void MainWindow::on_pushButtonUsers_clicked()
471 usersDialog = new UsersDialog;
473 connect(usersDialog, SIGNAL(getUserInfo(QString)), this, SLOT(requestGetUserInfo(QString)));
474 //connect(usersDialog, SIGNAL(getUsers()), this, SLOT(requestGetUsers()));
476 connect(usersDialog, SIGNAL(rejected()), this, SLOT(killDialog()));