2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
6 Henri Lampela - henri.lampela@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,
24 #include "situarecommon.h"
26 #include "ui/mainwindow.h"
27 #include "gps/gpspositioninterface.h"
30 #include "gps/gpsposition.h"
32 #include "gps/gpspositionmockup.h"
35 SituareEngine::SituareEngine(QMainWindow *parent)
38 qDebug() << __PRETTY_FUNCTION__;
39 m_ui = new MainWindow;
41 m_situareService = new SituareService(this);
43 m_facebookAuthenticator = new FacebookAuthentication();
46 m_gps = new GPSPosition(this);
48 m_gps = new GPSPositionMockup(this);
51 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
52 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
53 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
54 this, SLOT(loginOk()));
55 connect(m_facebookAuthenticator, SIGNAL(quitSituare()),
56 this, SLOT(quitApplication()));
58 connect(m_ui, SIGNAL(requestReverseGeo()),
59 this, SLOT(requestAddress()));
60 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
61 m_ui, SIGNAL(reverseGeoReady(QString)));
62 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
63 this, SLOT(requestUpdateLocation(QString,bool)));
64 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
65 this, SLOT(userDataChanged(User*,QList<User*>&)));
66 connect(this, SIGNAL(userLocationReady(User*)),
67 m_ui, SIGNAL(userLocationReady(User*)));
68 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
69 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
70 connect(m_situareService, SIGNAL(error(QString)),
71 this, SLOT(error(QString)));
72 connect(m_situareService, SIGNAL(updateWasSuccessful()),
73 this, SLOT(updateWasSuccessful()));
75 connect(m_ui, SIGNAL(refreshUserData()),
76 this, SLOT(refreshUserData()));
78 connect(m_gps, SIGNAL(timeout()),
79 m_ui, SLOT(gpsTimeout()));
80 connect(m_gps, SIGNAL(error(QString)),
81 m_ui, SLOT(gpsError(QString)));
82 connect(m_ui, SIGNAL(enableGPS(bool)),
83 this, SLOT(enableGPS(bool)));
84 connect(m_gps, SIGNAL(position(QPointF, qreal)),
85 m_ui, SIGNAL(positionReceived(QPointF, qreal)));
86 connect(m_ui, SIGNAL(enableAutoCentering(bool)),
87 this, SLOT(enableAutoCentering(bool)));
89 m_facebookAuthenticator->start();
92 SituareEngine::~SituareEngine()
94 qDebug() << __PRETTY_FUNCTION__;
99 void SituareEngine::quitApplication()
101 qDebug() << __PRETTY_FUNCTION__;
103 m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
104 m_facebookAuthenticator->close();
107 void SituareEngine::error(const QString &error)
109 qDebug() << __PRETTY_FUNCTION__;
114 void SituareEngine::loginOk()
116 qDebug() << __PRETTY_FUNCTION__;
118 QSettings settings(DIRECTORY_NAME, FILE_NAME);
119 QVariant gpsEnabled = settings.value(GPS_ENABLED);
120 QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
122 m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
123 m_facebookAuthenticator->close();
125 m_situareService->fetchLocations(); // request user locations
127 qDebug() << __PRETTY_FUNCTION__ << "GPS: " << gpsEnabled;
128 qDebug() << __PRETTY_FUNCTION__ << "Center: " << autoCenteringEnabled;
129 enableGPS(gpsEnabled.toBool());
130 enableAutoCentering(autoCenteringEnabled.toBool());
133 void SituareEngine::requestAddress()
135 qDebug() << __PRETTY_FUNCTION__;
137 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
138 m_situareService->reverseGeo(coordinates);
141 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
143 qDebug() << __PRETTY_FUNCTION__;
145 m_ui->toggleProgressIndicator(true);
147 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
148 m_situareService->updateLocation(coordinates, status, publish);
151 void SituareEngine::updateWasSuccessful()
153 qDebug() << __PRETTY_FUNCTION__;
155 m_situareService->fetchLocations();
158 void SituareEngine::refreshUserData()
160 qDebug() << __PRETTY_FUNCTION__;
162 m_ui->toggleProgressIndicator(true);
164 m_situareService->fetchLocations();
167 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
169 qDebug() << __PRETTY_FUNCTION__;
171 m_ui->toggleProgressIndicator(false);
173 emit userLocationReady(user);
174 emit friendsLocationsReady(friendsList);
177 void SituareEngine::enableGPS(bool enabled)
179 qDebug() << __PRETTY_FUNCTION__ << enabled;
182 m_gps->lastPosition();
184 m_ui->setGPSButton(true);
188 m_ui->setGPSButton(false);
192 void SituareEngine::enableAutoCentering(bool enabled)
194 qDebug() << __PRETTY_FUNCTION__ << enabled;
197 m_ui->setAutoCenteringButton(true);
198 m_ui->autoCenteringEnabled(true);
199 m_gps->lastPosition();
202 m_ui->setAutoCenteringButton(false);
203 m_ui->autoCenteringEnabled(false);