Added classes.
[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     topResultDialog = new TopResultDialog;
31     connect(topResultDialog, SIGNAL(refreshCategoryList()), this, SLOT(clientRequestCategoryList()));
32     connect(topResultDialog, SIGNAL(refreshTopList(int)), this, SLOT(clientRequestTopList(int)));
33     accstart = NULL;
34
35     httpClient = new HttpClient(this);
36
37     welcomeDialog = new WelcomeDialog;
38     welcomeDialog->show();
39 }
40
41 MainWindow::~MainWindow()
42 {
43     delete ui;
44
45     delete routeSaveDialog;
46
47     if(!accstart)
48         delete accstart;
49 }
50
51 void MainWindow::changeEvent(QEvent *e)
52 {
53     QMainWindow::changeEvent(e);
54     switch (e->type()) {
55     case QEvent::LanguageChange:
56         ui->retranslateUi(this);
57         break;
58     default:
59         break;
60     }
61 }
62
63 void MainWindow::on_pushButtonWWW_clicked()
64 {
65     QDesktopServices::openUrl(QUrl("http://garage.maemo.org/projects/speedfreak/"));
66 }
67
68 void MainWindow::on_pushButtonCredits_clicked()
69 {
70     creditsDialog->show();
71 }
72
73 void MainWindow::on_pushButtonRoute_clicked()
74 {
75     routeSaveDialog->show();
76 }
77
78 void MainWindow::on_pushButtonSettings_clicked()
79 {
80     settingsDialog->show();
81 }
82
83 void MainWindow::on_pushButtonAccelerate_clicked()
84 {
85     if(!accstart)
86         accstart = new accelerationstart(this);
87     accstart->show();
88 }
89
90 void MainWindow::on_pushButtonResults_clicked()
91 {
92     topResultDialog->show();
93 }
94
95 /**
96   *This slot function is called when ever mytTopResultDialog emits signal refreshCategoryList button clicked.
97   */
98 void MainWindow::clientRequestCategoryList()
99 {
100     httpClient->requestCategories();
101 }
102
103 /**
104   *This slot function is called when ever mytTopResultDialog emits signal refreshTopList button clicked.
105   */
106 void MainWindow::clientRequestTopList(int index)
107 {
108     qDebug() << "index" << index << httpClient->myXmlreader->myCategoryList->getRecentCategory(index);
109     QString limit = QString::number(topResultDialog->getLimitNr());
110     httpClient->requestTopList(httpClient->myXmlreader->myCategoryList->getRecentCategory(index), limit);
111 }