Added help and setting dialog's fonts changed bigger.
[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     helpDialog = 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     resultDialog = new ResultDialog;
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     if(!helpDialog)
106         helpDialog = new HelpDialog;
107     helpDialog->show();
108     //creditsDialog->show();
109 }
110
111 /**
112   * This slot function opens the route save dialog
113   */
114 void MainWindow::on_pushButtonRoute_clicked()
115 {
116     routeSaveDialog->show();
117 }
118
119 /**
120   * This slot function opens the settings dialog
121   */
122 void MainWindow::on_pushButtonSettings_clicked()
123 {
124     settingsDialog->show();
125 }
126
127 /**
128   * This slot function opens the acceleration dialog
129   */
130 void MainWindow::on_pushButtonAccelerate_clicked()
131 {
132     if(!accstart)
133         accstart = new accelerationstart(this);
134     connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
135     accstart->show();
136 }
137
138 /**
139   * This slot function opens the top results dialog
140   */
141 void MainWindow::on_pushButtonResults_clicked()
142 {
143     topResultDialog->show();
144 }
145
146 /**
147   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
148   */
149 void MainWindow::clientRequestCategoryList()
150 {
151     httpClient->requestCategories();
152 }
153
154 /**
155   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
156   */
157 void MainWindow::clientRequestTopList(int index)
158 {
159     QString limit = QString::number(topResultDialog->getLimitNr());
160     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
161 }
162
163 /**
164   *This function is used to set items to category combobox. Top-tab view.
165   *@param
166   */
167 void MainWindow::setCategoryCompoBox()
168 {
169     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
170 }
171
172 /**
173   *This function prcesses UI updating after a new top10List has been received.
174   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
175   */
176 void MainWindow::showTop10()
177 {
178     int ind = topResultDialog->getRecentCategoryIndex();
179     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
180 }
181
182 /**
183   *This function is used to set items to labelTopList. Top-tab view.
184   *@param Category
185   *@param Size, number of results.
186   */
187 void MainWindow::setListViewTopList(QString category, int size)
188 {
189     QString topList;
190     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
191     topResultDialog->showTopList(topList);
192 }
193
194 void MainWindow::clientRegUserToServer()
195 {
196     httpClient->requestRegistration();
197 }
198
199 /**
200   * This function performs login to server
201   */
202 void MainWindow::clientUserLogin()
203 {
204     httpClient->checkLogin();
205 }
206
207 /**
208   * This function send route to server
209   */
210 void MainWindow::clientSendRoute()
211 {
212     httpClient->sendRouteXml();
213 }
214
215 /**
216   * This function send acceleration data to server
217   */
218 void MainWindow::clientSendResult(QString category, double result)
219 {
220     /*QMessageBox msgBox;
221     msgBox.setWindowTitle("client send result!");
222     msgBox.setText("client send result!");
223     msgBox.setDefaultButton(QMessageBox::Ok);
224     msgBox.exec();*/
225
226     qDebug() << "__clientSendResult";
227     if(accstart) {
228         qDebug() << "_clientSendResult, calling server";
229         httpClient->sendResultXml(category, result);
230         //httpClient->sendResultXml(accstart->getMeasureCategory(), resultDialog->getResult());
231     }
232 }