Merge branch 'master' of https://vcs.maemo.org/git/situare
[situare] / src / ui / mainwindow.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Kaj Wallin - kaj.wallin@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <QtGui>
24 #include "mainwindow.h"
25 #include "listviewscreen.h"
26 #include "mapviewscreen.h"
27 #include "settingsdialog.h"
28 #include "facebookservice/facebookauthentication.h"
29 #include "situareservice/situareservice.h"
30 #include "engine/engine.h"
31
32 MainWindow::MainWindow(QWidget *parent)
33     : QMainWindow(parent)
34 {
35     qDebug() << __PRETTY_FUNCTION__;
36
37     createViews();
38     setCentralWidget(m_situareViews);
39     createMenus();
40     setWindowTitle(tr("List view"));
41     this->hide();
42
43     m_situareEngine = new SituareEngine(this);
44     connect(m_situareEngine, SIGNAL(engine_showMainWindow()), this, SLOT(show()));
45     connect(m_situareEngine, SIGNAL(engine_closeMainWindow()), this, SLOT(close()));
46
47     m_locationDialog = new UpdateLocationDialog(this);
48 //    connect(m_listViewScreen->m_personalInfo,
49 //            SIGNAL(launchUpdateFriendsStatus()),
50 //            m_situareEngine,
51 //            SLOT(updateFriendsList()));
52     connect(m_listViewScreen->m_personalInfo,SIGNAL(launchMessageUpdate()),
53             this,SLOT(openLocationUpdateDialog()));
54
55     m_situareEngine->start();
56 }
57
58 MainWindow::~MainWindow()
59 {
60     qDebug() << __PRETTY_FUNCTION__;
61     delete m_toListViewAct;
62     delete m_toMapViewAct;
63     delete m_toSettingsAct;
64     delete m_situareViews;
65 }
66
67 void MainWindow::createMenus()
68 {
69     qDebug() << __PRETTY_FUNCTION__;
70     m_toListViewAct = new QAction(tr("List"), this);
71     m_toListViewAct->setObjectName(tr("List"));
72     connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
73     m_toMapViewAct = new QAction(tr("Map"), this);
74     m_toMapViewAct->setObjectName(tr("Map"));
75     connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
76     m_toSettingsAct = new QAction(tr("Settings"), this);
77     m_toSettingsAct->setObjectName(tr("Settings"));
78     connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
79     m_viewMenu = menuBar()->addMenu(tr("View"));
80     m_viewMenu->addAction(m_toListViewAct);
81     m_viewMenu->addAction(m_toMapViewAct);
82     m_viewMenu->addAction(m_toSettingsAct);
83     m_viewMenu->setObjectName(tr("View Menu"));
84 }
85
86 void MainWindow::createViews()
87 {
88     qDebug() << __PRETTY_FUNCTION__;
89     m_listViewScreen = new ListViewScreen(this);
90     m_mapViewScreen = new MapViewScreen(this);
91
92     m_situareViews = new QStackedWidget;
93     m_situareViews->addWidget(m_listViewScreen);
94     m_situareViews->addWidget(m_mapViewScreen);
95 }
96
97 void MainWindow::toListView()
98 {
99     qDebug() << __PRETTY_FUNCTION__;
100     switchView(0);
101 }
102
103 void MainWindow::toMapView()
104 {
105     qDebug() << __PRETTY_FUNCTION__;
106     switchView(1);
107 }
108
109 void MainWindow::switchView(int nextIndex)
110 {
111     qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
112     if (nextIndex < 0 || nextIndex > 1) {
113         qDebug() << "Illegal parameter value in MainWindow::switchView";
114         return;
115     }
116     m_situareViews->setCurrentIndex(nextIndex);
117     switch (m_situareViews->currentIndex()) {
118         case 0:
119             setWindowTitle(tr("List view"));
120             break;
121         case 1:
122             setWindowTitle(tr("Map view"));
123             break;
124         default:
125             qDebug() << "Illegal switch value in MainWindow::switchView";
126             break;
127     }
128 }
129
130 void MainWindow::openLocationUpdateDialog()
131 {
132     qDebug() << __PRETTY_FUNCTION__;
133     m_locationDialog->exec();
134 }
135
136 void MainWindow::openSettingsDialog()
137 {
138     qDebug() << __PRETTY_FUNCTION__;
139     SettingsDialog *dialog = new SettingsDialog(this);
140     dialog->show();
141 }
142
143