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