4eeeca8d8eee2c7e906983d8b593cdcd4ebe8806
[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 void MainWindow::on_pushButtonWWW_clicked()
84 {
85     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
86 }
87
88 void MainWindow::on_pushButtonCredits_clicked()
89 {
90     creditsDialog->show();
91 }
92
93 void MainWindow::on_pushButtonRoute_clicked()
94 {
95     routeSaveDialog->show();
96 }
97
98 void MainWindow::on_pushButtonSettings_clicked()
99 {
100     settingsDialog->show();
101 }
102
103 void MainWindow::on_pushButtonAccelerate_clicked()
104 {
105     if(!accstart)
106         accstart = new accelerationstart(this);
107     accstart->show();
108 }
109
110 void MainWindow::on_pushButtonResults_clicked()
111 {
112     topResultDialog->show();
113 }
114
115 /**
116   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
117   */
118 void MainWindow::clientRequestCategoryList()
119 {
120     httpClient->requestCategories();
121 }
122
123 /**
124   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
125   */
126 void MainWindow::clientRequestTopList(int index)
127 {
128     qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
129     QString limit = QString::number(topResultDialog->getLimitNr());
130     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
131 }
132
133 /**
134   *This function is used to set items to category combobox. Top-tab view.
135   *@param
136   */
137 void MainWindow::setCategoryCompoBox()
138 {
139     qDebug() << "_setCategoryCompoBox";
140     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
141 }
142
143 /**
144   *This function prcesses UI updating after a new top10List has been received.
145   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
146   */
147 void MainWindow::showTop10()
148 {
149     qDebug() << "_showTop10";
150     int ind = topResultDialog->getRecentCategoryIndex();
151     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
152 }
153
154 /**
155   *This function is used to set items to labelTopList. Top-tab view.
156   *@param Category
157   *@param Size, number of results.
158   */
159 void MainWindow::setListViewTopList(QString category, int size)
160 {
161     qDebug() << "_setListViewTopList" << category;
162     QString topList;
163     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
164     topResultDialog->showTopList(topList);
165 }
166
167 void MainWindow::regUserToServer()
168 {
169     httpClient->requestRegistration();
170 }
171
172 void MainWindow::userLogin()
173 {
174     httpClient->checkLogin();
175 }