Corrected route drawing dialog to use mxl-file reading route points.
[speedfreak] / Client / mainwindow.cpp
1 /*
2  * Mainwindow for speedFreak project
3  *
4  * @author      Rikhard Kuutti <rikhard.kuutti@fudeco.com>
5  * @copyright   (c) 2010 Speed Freak team
6  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
7  */
8
9 #include "mainwindow.h"
10 #include "ui_mainwindow.h"
11
12 #include <QDesktopServices>
13 #include <QUrl>
14 #include <QSettings>
15 #include <QDebug>
16
17 MainWindow::MainWindow(QWidget *parent) :
18     QMainWindow(parent),
19     ui(new Ui::MainWindow)
20 {
21     ui->setupUi(this);
22
23     QCoreApplication::setOrganizationName("Fudeco Oy");
24     QCoreApplication::setOrganizationDomain("fudeco.com");
25     QCoreApplication::setApplicationName("Speed Freak");
26
27     routeDialog = new RouteDialog;
28     creditsDialog = new CreditsDialog;
29     routeSaveDialog = new RouteSaveDialog;
30     settingsDialog = new SettingsDialog;
31     connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
32     connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
33     topResultDialog = new TopResultDialog;
34     connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
35     connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
36     accstart = NULL;
37
38     httpClient = new HttpClient(this);
39     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
40     connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
41
42     welcomeDialog = new WelcomeDialog;
43     welcomeDialog->show();
44 }
45
46 MainWindow::~MainWindow()
47 {
48     delete ui;
49
50     delete routeSaveDialog;
51     delete routeDialog;
52
53     if(!accstart)
54         delete accstart;
55 }
56
57 void MainWindow::changeEvent(QEvent *e)
58 {
59     QMainWindow::changeEvent(e);
60     switch (e->type()) {
61     case QEvent::LanguageChange:
62         ui->retranslateUi(this);
63         break;
64     default:
65         break;
66     }
67 }
68
69 void MainWindow::on_pushButtonWWW_clicked()
70 {
71     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
72 }
73
74 void MainWindow::on_pushButtonCredits_clicked()
75 {
76     creditsDialog->show();
77 }
78
79 void MainWindow::on_pushButtonRoute_clicked()
80 {
81     routeSaveDialog->show();
82 }
83
84 void MainWindow::on_pushButtonSettings_clicked()
85 {
86     settingsDialog->show();
87 }
88
89 void MainWindow::on_pushButtonAccelerate_clicked()
90 {
91     if(!accstart)
92         accstart = new accelerationstart(this);
93     accstart->show();
94 }
95
96 void MainWindow::on_pushButtonResults_clicked()
97 {
98     topResultDialog->show();
99 }
100
101 /**
102   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
103   */
104 void MainWindow::clientRequestCategoryList()
105 {
106     httpClient->requestCategories();
107 }
108
109 /**
110   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
111   */
112 void MainWindow::clientRequestTopList(int index)
113 {
114     qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
115     QString limit = QString::number(topResultDialog->getLimitNr());
116     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
117 }
118
119 /**
120   *This function is used to set items to category combobox. Top-tab view.
121   *@param
122   */
123 void MainWindow::setCategoryCompoBox()
124 {
125     qDebug() << "_setCategoryCompoBox";
126     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
127 }
128
129 /**
130   *This function prcesses UI updating after a new top10List has been received.
131   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
132   */
133 void MainWindow::showTop10()
134 {
135     qDebug() << "_showTop10";
136     int ind = topResultDialog->getRecentCategoryIndex();
137     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
138 }
139
140 /**
141   *This function is used to set items to labelTopList. Top-tab view.
142   *@param Category
143   *@param Size, number of results.
144   */
145 void MainWindow::setListViewTopList(QString category, int size)
146 {
147     qDebug() << "_setListViewTopList" << category;
148     QString topList;
149     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
150     topResultDialog->showTopList(topList);
151 }
152
153 void MainWindow::regUserToServer()
154 {
155     httpClient->requestRegistration();
156 }
157
158 void MainWindow::userLogin()
159 {
160     httpClient->checkLogin();
161 }