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);
76 //Debug, use settings instead
77 autoCenteringToggled(true);
80 MainWindow::~MainWindow()
82 qDebug() << __PRETTY_FUNCTION__;
83 delete m_toListViewAct;
84 delete m_toMapViewAct;
85 delete m_toSettingsAct;
86 delete m_situareViews;
89 void MainWindow::toggleProgressIndicator(bool value)
91 qDebug() << __PRETTY_FUNCTION__;
93 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
96 #endif // Q_WS_MAEMO_5
99 void MainWindow::createMenus()
101 qDebug() << __PRETTY_FUNCTION__;
102 m_toListViewAct = new QAction(tr("List"), this);
103 m_toListViewAct->setObjectName(tr("List"));
104 connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
105 m_toMapViewAct = new QAction(tr("Map"), this);
106 m_toMapViewAct->setObjectName(tr("Map"));
107 connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
108 m_toSettingsAct = new QAction(tr("Settings"), this);
109 m_toSettingsAct->setObjectName(tr("Settings"));
110 connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
111 m_gpsToggleAct = new QAction(tr("GPS enabled"), this);
112 m_gpsToggleAct->setCheckable(true);
113 m_gpsToggleAct->setChecked(true);
114 connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
115 m_autoCenteringAct = new QAction(tr("Auto centering enabled"), this);
116 m_autoCenteringAct->setCheckable(true);
117 m_autoCenteringAct->setChecked(true);
118 connect(m_autoCenteringAct, SIGNAL(toggled(bool)), this, SLOT(autoCenteringToggled(bool)));
119 m_viewMenu = menuBar()->addMenu(tr("View"));
120 m_viewMenu->addAction(m_toListViewAct);
121 m_viewMenu->addAction(m_toMapViewAct);
122 m_viewMenu->addAction(m_toSettingsAct);
123 m_viewMenu->addAction(m_gpsToggleAct);
124 m_viewMenu->addAction(m_autoCenteringAct);
125 m_viewMenu->setObjectName(tr("View Menu"));
128 void MainWindow::createViews()
130 qDebug() << __PRETTY_FUNCTION__;
131 m_listViewScreen = new ListViewScreen(this);
132 m_mapViewScreen = new MapViewScreen(this);
134 m_situareViews = new QStackedWidget;
135 m_situareViews->addWidget(m_listViewScreen);
136 m_situareViews->addWidget(m_mapViewScreen);
139 void MainWindow::toListView()
141 qDebug() << __PRETTY_FUNCTION__;
145 void MainWindow::toMapView()
147 qDebug() << __PRETTY_FUNCTION__;
151 void MainWindow::switchView(int nextIndex)
153 qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
154 if (nextIndex < 0 || nextIndex > 1) {
155 qDebug() << "Illegal parameter value in MainWindow::switchView";
158 m_situareViews->setCurrentIndex(nextIndex);
159 switch (m_situareViews->currentIndex()) {
161 setWindowTitle(tr("List view"));
164 setWindowTitle(tr("Map view"));
167 qDebug() << "Illegal switch value in MainWindow::switchView";
172 void MainWindow::openLocationUpdateDialog()
174 qDebug() << __PRETTY_FUNCTION__;
176 emit requestReverseGeo();
177 m_locationDialog->exec();
180 void MainWindow::openSettingsDialog()
182 qDebug() << __PRETTY_FUNCTION__;
183 SettingsDialog *dialog = new SettingsDialog(this);
187 void MainWindow::gpsActionToggled(bool checked)
189 qDebug() << __PRETTY_FUNCTION__;
192 emit enableGPS(true);
193 m_gpsToggleAct->setText(tr("GPS enabled"));
194 showMaemoInformationBox(tr("GPS enabled"));
195 m_autoCenteringAct->setEnabled(true);
198 emit enableGPS(false);
199 m_gpsToggleAct->setText(tr("GPS disabled"));
200 showMaemoInformationBox(tr("GPS disabled"));
201 m_autoCenteringAct->setEnabled(false);
205 void MainWindow::gpsTimeout()
207 qDebug() << __PRETTY_FUNCTION__;
209 showMaemoInformationBox(tr("GPS timeout"));
212 void MainWindow::gpsError(const QString &message)
214 qDebug() << __PRETTY_FUNCTION__;
216 showMaemoInformationBox(message);
219 void MainWindow::autoCenteringToggled(bool checked)
221 qDebug() << __PRETTY_FUNCTION__ << " " << checked;
224 emit enableAutoCentering(true);
225 m_autoCenteringAct->setText(tr("Auto centering enabled"));
226 showMaemoInformationBox(tr("Auto centering enabled"));
229 emit enableAutoCentering(false);
230 m_autoCenteringAct->setText(tr("Auto centering disabled"));
231 showMaemoInformationBox(tr("Auto centering disabled"));
235 void MainWindow::showMaemoInformationBox(const QString &message)
237 qDebug() << __PRETTY_FUNCTION__;
240 QMaemo5InformationBox::information(this, message,
241 QMaemo5InformationBox::DefaultTimeout);
242 #endif // Q_WS_MAEMO_5