Route save dialog development. Added: GPS,icons...
[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     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     //Button settings
46     ui->pushButtonAccelerate->setAutoFillBackground(true);
47     ui->pushButtonAccelerate->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
48     ui->pushButtonRoute->setAutoFillBackground(true);
49     ui->pushButtonRoute->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
50     ui->pushButtonResults->setAutoFillBackground(true);
51     ui->pushButtonResults->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
52     ui->pushButtonSettings->setAutoFillBackground(true);
53     ui->pushButtonSettings->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
54     ui->pushButtonWWW->setAutoFillBackground(true);
55     ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
56 }
57
58 MainWindow::~MainWindow()
59 {
60     delete ui;
61     delete routeSaveDialog;
62
63     if(!accstart)
64         delete accstart;
65 }
66
67 void MainWindow::changeEvent(QEvent *e)
68 {
69     QMainWindow::changeEvent(e);
70     switch (e->type()) {
71     case QEvent::LanguageChange:
72         ui->retranslateUi(this);
73         break;
74     default:
75         break;
76     }
77 }
78
79 void MainWindow::on_pushButtonWWW_clicked()
80 {
81     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
82 }
83
84 void MainWindow::on_pushButtonCredits_clicked()
85 {
86     creditsDialog->show();
87 }
88
89 void MainWindow::on_pushButtonRoute_clicked()
90 {
91     routeSaveDialog->show();
92 }
93
94 void MainWindow::on_pushButtonSettings_clicked()
95 {
96     settingsDialog->show();
97 }
98
99 void MainWindow::on_pushButtonAccelerate_clicked()
100 {
101     if(!accstart)
102         accstart = new accelerationstart(this);
103     accstart->show();
104 }
105
106 void MainWindow::on_pushButtonResults_clicked()
107 {
108     topResultDialog->show();
109 }
110
111 /**
112   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
113   */
114 void MainWindow::clientRequestCategoryList()
115 {
116     httpClient->requestCategories();
117 }
118
119 /**
120   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
121   */
122 void MainWindow::clientRequestTopList(int index)
123 {
124     qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
125     QString limit = QString::number(topResultDialog->getLimitNr());
126     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
127 }
128
129 /**
130   *This function is used to set items to category combobox. Top-tab view.
131   *@param
132   */
133 void MainWindow::setCategoryCompoBox()
134 {
135     qDebug() << "_setCategoryCompoBox";
136     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
137 }
138
139 /**
140   *This function prcesses UI updating after a new top10List has been received.
141   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
142   */
143 void MainWindow::showTop10()
144 {
145     qDebug() << "_showTop10";
146     int ind = topResultDialog->getRecentCategoryIndex();
147     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
148 }
149
150 /**
151   *This function is used to set items to labelTopList. Top-tab view.
152   *@param Category
153   *@param Size, number of results.
154   */
155 void MainWindow::setListViewTopList(QString category, int size)
156 {
157     qDebug() << "_setListViewTopList" << category;
158     QString topList;
159     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
160     topResultDialog->showTopList(topList);
161 }
162
163 void MainWindow::regUserToServer()
164 {
165     httpClient->requestRegistration();
166 }
167
168 void MainWindow::userLogin()
169 {
170     httpClient->checkLogin();
171 }