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