Youtube video and text (draft).
[speedfreak] / Client / mainwindow.cpp
1 /*
2  * Mainwindow for speedFreak project
3  *
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
8  */
9
10 #include "mainwindow.h"
11 #include "ui_mainwindow.h"
12
13 #include <QDesktopServices>
14 #include <QUrl>
15 #include <QSettings>
16 #include <QDebug>
17
18 MainWindow::MainWindow(QWidget *parent) :
19     QMainWindow(parent),
20     ui(new Ui::MainWindow)
21 {
22     ui->setupUi(this);
23
24     QCoreApplication::setOrganizationName("Fudeco Oy");
25     QCoreApplication::setOrganizationDomain("fudeco.com");
26     QCoreApplication::setApplicationName("Speed Freak");
27
28     routeDialog = new RouteDialog;
29     connect(routeDialog,SIGNAL(sendroute()),this,SLOT(clientSendRoute()));
30
31     routeSaveDialog = new RouteSaveDialog;
32
33     settingsDialog = new SettingsDialog;
34     connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(clientRegUserToServer()));
35     connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(clientUserLogin()));
36
37     topResultDialog = new TopResultDialog;
38     connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
39     connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
40
41     httpClient = new HttpClient(this);
42     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
43     connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
44
45     resultDialog = new ResultDialog;
46     connect(resultDialog, SIGNAL(sendresult()), this, SLOT(clientSendResult()));
47
48     accstart = NULL;
49
50     creditsDialog = new CreditsDialog;
51
52     welcomeDialog = new WelcomeDialog;
53     welcomeDialog->show();
54
55     //Button settings
56     ui->pushButtonAccelerate->setAutoFillBackground(true);
57     ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
58     ui->pushButtonRoute->setAutoFillBackground(true);
59     ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
60     ui->pushButtonResults->setAutoFillBackground(true);
61     ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
62     ui->pushButtonSettings->setAutoFillBackground(true);
63     ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64     ui->pushButtonWWW->setAutoFillBackground(true);
65     ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
66     ui->pushButtonCredits->setAutoFillBackground(true);
67     ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
68 }
69
70 MainWindow::~MainWindow()
71 {
72     delete ui;
73     delete routeSaveDialog;
74     delete routeDialog;
75
76     if(accstart)
77         delete accstart;
78 }
79
80 void MainWindow::changeEvent(QEvent *e)
81 {
82     QMainWindow::changeEvent(e);
83     switch (e->type()) {
84     case QEvent::LanguageChange:
85         ui->retranslateUi(this);
86         break;
87     default:
88         break;
89     }
90 }
91
92 /**
93   * This slot function opens browser to project www page.
94   */
95 void MainWindow::on_pushButtonWWW_clicked()
96 {
97     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
98 }
99
100 /**
101   * This slot function opens the credits dialog
102   */
103 void MainWindow::on_pushButtonCredits_clicked()
104 {
105     creditsDialog->show();
106 }
107
108 /**
109   * This slot function opens the route save dialog
110   */
111 void MainWindow::on_pushButtonRoute_clicked()
112 {
113     routeSaveDialog->show();
114 }
115
116 /**
117   * This slot function opens the settings dialog
118   */
119 void MainWindow::on_pushButtonSettings_clicked()
120 {
121     settingsDialog->show();
122 }
123
124 /**
125   * This slot function opens the acceleration dialog
126   */
127 void MainWindow::on_pushButtonAccelerate_clicked()
128 {
129     if(!accstart)
130         accstart = new accelerationstart(this);
131     accstart->show();
132 }
133
134 /**
135   * This slot function opens the top results dialog
136   */
137 void MainWindow::on_pushButtonResults_clicked()
138 {
139     topResultDialog->show();
140 }
141
142 /**
143   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
144   */
145 void MainWindow::clientRequestCategoryList()
146 {
147     httpClient->requestCategories();
148 }
149
150 /**
151   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
152   */
153 void MainWindow::clientRequestTopList(int index)
154 {
155     QString limit = QString::number(topResultDialog->getLimitNr());
156     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
157 }
158
159 /**
160   *This function is used to set items to category combobox. Top-tab view.
161   *@param
162   */
163 void MainWindow::setCategoryCompoBox()
164 {
165     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
166 }
167
168 /**
169   *This function prcesses UI updating after a new top10List has been received.
170   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
171   */
172 void MainWindow::showTop10()
173 {
174     int ind = topResultDialog->getRecentCategoryIndex();
175     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
176 }
177
178 /**
179   *This function is used to set items to labelTopList. Top-tab view.
180   *@param Category
181   *@param Size, number of results.
182   */
183 void MainWindow::setListViewTopList(QString category, int size)
184 {
185     QString topList;
186     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
187     topResultDialog->showTopList(topList);
188 }
189
190 void MainWindow::clientRegUserToServer()
191 {
192     httpClient->requestRegistration();
193 }
194
195 /**
196   * This function performs login to server
197   */
198 void MainWindow::clientUserLogin()
199 {
200     httpClient->checkLogin();
201 }
202
203 /**
204   * This function send route to server
205   */
206 void MainWindow::clientSendRoute()
207 {
208     httpClient->sendRouteXml();
209 }
210
211 /**
212   * This function send acceleration data to server
213   */
214 void MainWindow::clientSendResult()
215 {
216     qDebug() << "_clientSendResult";
217     if(accstart) {
218         qDebug() << "_clientSendResult, calling server";
219         httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());
220     }
221 }