Added functionality to change user in settingsdialog.
[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     creditsDialog = new CreditsDialog;
28     routeSaveDialog = new RouteSaveDialog;
29     settingsDialog = new SettingsDialog;
30     connect(settingsDialog,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
31     connect(settingsDialog,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
32     topResultDialog = new TopResultDialog;
33     connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
34     connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
35     accstart = NULL;
36
37     httpClient = new HttpClient(this);
38     connect(httpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
39     connect(httpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
40
41     welcomeDialog = new WelcomeDialog;
42     welcomeDialog->show();
43 }
44
45 MainWindow::~MainWindow()
46 {
47     delete ui;
48
49     delete routeSaveDialog;
50
51     if(!accstart)
52         delete accstart;
53 }
54
55 void MainWindow::changeEvent(QEvent *e)
56 {
57     QMainWindow::changeEvent(e);
58     switch (e->type()) {
59     case QEvent::LanguageChange:
60         ui->retranslateUi(this);
61         break;
62     default:
63         break;
64     }
65 }
66
67 void MainWindow::on_pushButtonWWW_clicked()
68 {
69     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
70 }
71
72 void MainWindow::on_pushButtonCredits_clicked()
73 {
74     creditsDialog->show();
75 }
76
77 void MainWindow::on_pushButtonRoute_clicked()
78 {
79     routeSaveDialog->show();
80 }
81
82 void MainWindow::on_pushButtonSettings_clicked()
83 {
84     settingsDialog->show();
85 }
86
87 void MainWindow::on_pushButtonAccelerate_clicked()
88 {
89     if(!accstart)
90         accstart = new accelerationstart(this);
91     accstart->show();
92 }
93
94 void MainWindow::on_pushButtonResults_clicked()
95 {
96     topResultDialog->show();
97 }
98
99 /**
100   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
101   */
102 void MainWindow::clientRequestCategoryList()
103 {
104     httpClient->requestCategories();
105 }
106
107 /**
108   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
109   */
110 void MainWindow::clientRequestTopList(int index)
111 {
112     qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
113     QString limit = QString::number(topResultDialog->getLimitNr());
114     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
115 }
116
117 /**
118   *This function is used to set items to category combobox. Top-tab view.
119   *@param
120   */
121 void MainWindow::setCategoryCompoBox()
122 {
123     qDebug() << "_setCategoryCompoBox";
124     topResultDialog->setCompoBoxCategories(httpClient->myXmlreader->myCategoryList->getCategoryList());
125 }
126
127 /**
128   *This function prcesses UI updating after a new top10List has been received.
129   *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
130   */
131 void MainWindow::showTop10()
132 {
133     qDebug() << "_showTop10";
134     int ind = topResultDialog->getRecentCategoryIndex();
135     setListViewTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(ind), topResultDialog->getLimitNr());
136 }
137
138 /**
139   *This function is used to set items to labelTopList. Top-tab view.
140   *@param Category
141   *@param Size, number of results.
142   */
143 void MainWindow::setListViewTopList(QString category, int size)
144 {
145     qDebug() << "_setListViewTopList" << category;
146     QString topList;
147     topList.append(httpClient->myXmlreader->myCategoryList->getTopList(category, size));
148     topResultDialog->showTopList(topList);
149 }
150
151 void MainWindow::regUserToServer()
152 {
153     httpClient->requestRegistration();
154 }
155
156 void MainWindow::userLogin()
157 {
158     httpClient->checkLogin();
159 }