Added friend find button to FriendListItem.
[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       Jussi Laitinen jussi.laitinen@ixonos.com
8
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.
12
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.
17
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,
21    USA.
22 */
23
24 #include <QtGui>
25
26 #ifdef Q_WS_MAEMO_5
27 #include <QtMaemo5/QMaemo5InformationBox>
28 #endif // Q_WS_MAEMO_5
29
30 #include "mainwindow.h"
31 #include "mapviewscreen.h"
32 #include "settingsdialog.h"
33 #include "facebookservice/facebookauthentication.h"
34 #include "situareservice/situareservice.h"
35
36 MainWindow::MainWindow(QWidget *parent)
37     : QMainWindow(parent)
38 {
39     qDebug() << __PRETTY_FUNCTION__;
40
41     m_mapViewScreen = new MapViewScreen(this);
42     setCentralWidget(m_mapViewScreen);
43     createMenus();
44     setWindowTitle(tr("Situare"));
45     hide();
46
47     m_locationDialog = new UpdateLocationDialog(this);
48
49     connect(this, SIGNAL(reverseGeoReady(QString)),
50             m_locationDialog, SLOT(setAddress(QString)));
51     connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
52             SIGNAL(statusUpdate(QString,bool)));
53
54     connect(this, SIGNAL(userLocationReady(User*)),
55             m_mapViewScreen, SIGNAL(userLocationReady(User*)));
56     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
57             m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
58
59     connect(this, SIGNAL(enableAutoCentering(bool)),
60             m_mapViewScreen, SLOT(enableAutoCentering(bool)));
61     connect(this, SIGNAL(positionReceived(QPointF)),
62             m_mapViewScreen, SLOT(positionReceived(QPointF)));
63     connect(m_mapViewScreen, SIGNAL(mapLocationChanged()), this, SLOT(mapLocationChanged()));
64
65     this->toggleProgressIndicator(true);
66 }
67
68 void MainWindow::toggleProgressIndicator(bool value)
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71 #ifdef Q_WS_MAEMO_5
72     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
73 #else
74     Q_UNUSED(value);
75 #endif // Q_WS_MAEMO_5
76 }
77
78 void MainWindow::createMenus()
79 {
80     qDebug() << __PRETTY_FUNCTION__;
81
82     m_toSettingsAct = new QAction(tr("Settings"), this);
83     m_toSettingsAct->setObjectName(tr("Settings"));
84     connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
85         m_gpsToggleAct = new QAction(tr("GPS"), this);
86     m_gpsToggleAct->setCheckable(true);
87     m_gpsToggleAct->setChecked(true);
88     connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
89     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
90     m_autoCenteringAct->setCheckable(true);
91     m_autoCenteringAct->setChecked(true);
92     connect(m_autoCenteringAct, SIGNAL(toggled(bool)), this, SLOT(autoCenteringToggled(bool)));    
93
94     m_viewMenu = menuBar()->addMenu(tr("Main"));
95
96     m_viewMenu->addAction(m_toSettingsAct);
97         m_viewMenu->addAction(m_gpsToggleAct);
98     m_viewMenu->addAction(m_autoCenteringAct);
99     m_viewMenu->setObjectName(tr("Menu"));
100 }
101
102 void MainWindow::openLocationUpdateDialog()
103 {
104     qDebug() << __PRETTY_FUNCTION__;
105
106     emit requestReverseGeo();
107     m_locationDialog->exec();
108 }
109
110 void MainWindow::openSettingsDialog()
111 {
112     qDebug() << __PRETTY_FUNCTION__;
113     SettingsDialog *dialog = new SettingsDialog(this);
114     dialog->show();
115 }
116
117 void MainWindow::gpsActionToggled(bool checked)
118 {
119     qDebug() << __PRETTY_FUNCTION__;
120
121     if (checked) {
122         emit enableGPS(true);
123         showMaemoInformationBox(tr("GPS enabled"));
124         m_autoCenteringAct->setVisible(true);
125     }
126     else {
127         emit enableGPS(false);
128         showMaemoInformationBox(tr("GPS disabled"));
129         m_autoCenteringAct->setVisible(false);
130
131     }
132 }
133
134 void MainWindow::gpsTimeout()
135 {
136     qDebug() << __PRETTY_FUNCTION__;
137
138     showMaemoInformationBox(tr("GPS timeout"));
139 }
140
141 void MainWindow::gpsError(const QString &message)
142 {
143     qDebug() << __PRETTY_FUNCTION__;
144
145     showMaemoInformationBox(message);
146 }
147
148 void MainWindow::mapLocationChanged()
149 {
150     qDebug() << __PRETTY_FUNCTION__;
151
152     m_autoCenteringAct->setChecked(false);
153 }
154
155 void MainWindow::autoCenteringToggled(bool checked)
156 {
157     qDebug() << __PRETTY_FUNCTION__ << " " << checked;
158
159     if (checked) {
160         emit enableAutoCentering(true);
161         showMaemoInformationBox(tr("Auto centering enabled"));
162     }
163     else {
164         emit enableAutoCentering(false);
165         showMaemoInformationBox(tr("Auto centering disabled"));
166     }
167 }
168
169 void MainWindow::showMaemoInformationBox(const QString &message)
170 {
171     qDebug() << __PRETTY_FUNCTION__;
172
173 #ifdef Q_WS_MAEMO_5
174     QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
175 #else
176     Q_UNUSED(message);
177 #endif
178 }