2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Henri Lampela - henri.lampela@ixonos.com
6 Kaj Wallin - kaj.wallin@ixonos.com
7 Jussi Laitinen jussi.laitinen@ixonos.com
9 Situare is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 version 2 as published by the Free Software Foundation.
13 Situare is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Situare; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include <QtMaemo5/QMaemo5InformationBox>
28 #endif // Q_WS_MAEMO_5
30 #include "mainwindow.h"
31 #include "listviewscreen.h"
32 #include "mapviewscreen.h"
33 #include "settingsdialog.h"
34 #include "facebookservice/facebookauthentication.h"
35 #include "situareservice/situareservice.h"
37 MainWindow::MainWindow(QWidget *parent)
40 qDebug() << __PRETTY_FUNCTION__;
43 setCentralWidget(m_situareViews);
45 setWindowTitle(tr("List view"));
48 m_locationDialog = new UpdateLocationDialog(this);
49 connect(m_listViewScreen,SIGNAL(launchUpdateDialog()),
50 this,SLOT(openLocationUpdateDialog()));
52 connect(this, SIGNAL(reverseGeoReady(QString)),
53 m_locationDialog, SLOT(setAddress(QString)));
54 connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
55 SIGNAL(statusUpdate(QString,bool)));
57 connect(this, SIGNAL(userLocationReady(User*)),
58 m_mapViewScreen, SIGNAL(userLocationReady(User*)));
59 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
60 m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
62 connect(this, SIGNAL(userLocationReady(User*)),
63 m_listViewScreen, SLOT(userDataReceived(User*)));
64 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
65 m_listViewScreen, SLOT(friendInfoReceived(QList<User*>&)));
66 connect(m_listViewScreen, SIGNAL(updateFriendsData()),
67 this, SIGNAL(refreshUserData()));
69 connect(this, SIGNAL(enableAutoCentering(bool)),
70 m_mapViewScreen, SLOT(enableAutoCentering(bool)));
71 connect(this, SIGNAL(positionReceived(QPointF)),
72 m_mapViewScreen, SLOT(positionReceived(QPointF)));
74 this->toggleProgressIndicator(true);
77 MainWindow::~MainWindow()
79 qDebug() << __PRETTY_FUNCTION__;
80 delete m_toListViewAct;
81 delete m_toMapViewAct;
82 delete m_toSettingsAct;
83 delete m_situareViews;
86 void MainWindow::toggleProgressIndicator(bool value)
88 qDebug() << __PRETTY_FUNCTION__;
90 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
93 #endif // Q_WS_MAEMO_5
96 void MainWindow::createMenus()
98 qDebug() << __PRETTY_FUNCTION__;
99 m_toListViewAct = new QAction(tr("List"), this);
100 m_toListViewAct->setObjectName(tr("List"));
101 connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
102 m_toMapViewAct = new QAction(tr("Map"), this);
103 m_toMapViewAct->setObjectName(tr("Map"));
104 connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
105 m_toSettingsAct = new QAction(tr("Settings"), this);
106 m_toSettingsAct->setObjectName(tr("Settings"));
107 connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
108 m_gpsToggleAct = new QAction(tr("GPS enabled"), this);
109 m_gpsToggleAct->setCheckable(true);
110 m_gpsToggleAct->setChecked(true);
111 connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
112 m_autoCenteringAct = new QAction(tr("Auto centering enabled"), this);
113 m_autoCenteringAct->setCheckable(true);
114 m_autoCenteringAct->setChecked(true);
115 connect(m_autoCenteringAct, SIGNAL(toggled(bool)), this, SLOT(autoCenteringToggled(bool)));
116 m_viewMenu = menuBar()->addMenu(tr("View"));
117 m_viewMenu->addAction(m_toListViewAct);
118 m_viewMenu->addAction(m_toMapViewAct);
119 m_viewMenu->addAction(m_toSettingsAct);
120 m_viewMenu->addAction(m_gpsToggleAct);
121 m_viewMenu->addAction(m_autoCenteringAct);
122 m_viewMenu->setObjectName(tr("View Menu"));
125 void MainWindow::createViews()
127 qDebug() << __PRETTY_FUNCTION__;
128 m_listViewScreen = new ListViewScreen(this);
129 m_mapViewScreen = new MapViewScreen(this);
131 m_situareViews = new QStackedWidget;
132 m_situareViews->addWidget(m_listViewScreen);
133 m_situareViews->addWidget(m_mapViewScreen);
136 void MainWindow::toListView()
138 qDebug() << __PRETTY_FUNCTION__;
142 void MainWindow::toMapView()
144 qDebug() << __PRETTY_FUNCTION__;
148 void MainWindow::switchView(int nextIndex)
150 qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
151 if (nextIndex < 0 || nextIndex > 1) {
152 qDebug() << "Illegal parameter value in MainWindow::switchView";
155 m_situareViews->setCurrentIndex(nextIndex);
156 switch (m_situareViews->currentIndex()) {
158 setWindowTitle(tr("List view"));
161 setWindowTitle(tr("Map view"));
164 qDebug() << "Illegal switch value in MainWindow::switchView";
169 void MainWindow::openLocationUpdateDialog()
171 qDebug() << __PRETTY_FUNCTION__;
173 emit requestReverseGeo();
174 m_locationDialog->exec();
177 void MainWindow::openSettingsDialog()
179 qDebug() << __PRETTY_FUNCTION__;
180 SettingsDialog *dialog = new SettingsDialog(this);
184 void MainWindow::gpsActionToggled(bool checked)
186 qDebug() << __PRETTY_FUNCTION__;
189 emit enableGPS(true);
190 m_gpsToggleAct->setText(tr("GPS enabled"));
191 showMaemoInformationBox(tr("GPS enabled"));
192 m_autoCenteringAct->setVisible(true);
195 emit enableGPS(false);
196 m_gpsToggleAct->setText(tr("GPS disabled"));
197 showMaemoInformationBox(tr("GPS disabled"));
198 m_autoCenteringAct->setVisible(false);
203 void MainWindow::gpsTimeout()
205 qDebug() << __PRETTY_FUNCTION__;
207 showMaemoInformationBox(tr("GPS timeout"));
210 void MainWindow::gpsError(const QString &message)
212 qDebug() << __PRETTY_FUNCTION__;
214 showMaemoInformationBox(message);
217 void MainWindow::autoCenteringToggled(bool checked)
219 qDebug() << __PRETTY_FUNCTION__ << " " << checked;
222 emit enableAutoCentering(true);
223 m_autoCenteringAct->setText(tr("Auto centering enabled"));
224 showMaemoInformationBox(tr("Auto centering enabled"));
227 emit enableAutoCentering(false);
228 m_autoCenteringAct->setText(tr("Auto centering disabled"));
229 showMaemoInformationBox(tr("Auto centering disabled"));
233 void MainWindow::showMaemoInformationBox(const QString &message)
235 qDebug() << __PRETTY_FUNCTION__;
238 QMaemo5InformationBox::information(this, message,
239 QMaemo5InformationBox::DefaultTimeout);
240 #endif // Q_WS_MAEMO_5