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);
50 m_gps->setMode(GPSPositionInterface::Default);
52 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
53 m_situareService, SLOT(credentialsReady(FacebookCredentials)));
54 connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
55 this, SLOT(loginOk()));
56 connect(m_facebookAuthenticator, SIGNAL(quitSituare()),
57 this, SLOT(quitApplication()));
59 connect(m_ui, SIGNAL(requestReverseGeo()),
60 this, SLOT(requestAddress()));
61 connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
62 m_ui, SIGNAL(reverseGeoReady(QString)));
63 connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
64 this, SLOT(requestUpdateLocation(QString,bool)));
65 connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
66 this, SLOT(userDataChanged(User*,QList<User*>&)));
67 connect(this, SIGNAL(userLocationReady(User*)),
68 m_ui, SIGNAL(userLocationReady(User*)));
69 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
70 m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
71 connect(m_situareService, SIGNAL(error(QString)),
72 this, SLOT(error(QString)));
73 connect(m_situareService, SIGNAL(updateWasSuccessful()),
74 this, SLOT(updateWasSuccessful()));
76 connect(m_ui, SIGNAL(refreshUserData()),
77 this, SLOT(refreshUserData()));
79 connect(m_gps, SIGNAL(timeout()),
80 m_ui, SLOT(gpsTimeout()));
81 connect(m_gps, SIGNAL(error(QString)),
82 m_ui, SLOT(gpsError(QString)));
83 connect(m_ui, SIGNAL(enableGPS(bool)),
84 this, SLOT(enableGPS(bool)));
85 connect(m_gps, SIGNAL(position(QPointF, qreal)),
86 m_ui, SIGNAL(positionReceived(QPointF, qreal)));
87 connect(m_ui, SIGNAL(enableAutoCentering(bool)),
88 this, SLOT(enableAutoCentering(bool)));
90 m_facebookAuthenticator->start();
93 SituareEngine::~SituareEngine()
95 qDebug() << __PRETTY_FUNCTION__;
100 void SituareEngine::quitApplication()
102 qDebug() << __PRETTY_FUNCTION__;
104 m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
105 m_facebookAuthenticator->close();
108 void SituareEngine::error(const QString &error)
110 qDebug() << __PRETTY_FUNCTION__;
115 void SituareEngine::loginOk()
117 qDebug() << __PRETTY_FUNCTION__;
119 QSettings settings(DIRECTORY_NAME, FILE_NAME);
120 QVariant gpsEnabled = settings.value(GPS_ENABLED);
121 QVariant autoCenteringEnabled = settings.value(AUTO_CENTERING_ENABLED);
123 m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
124 m_facebookAuthenticator->close();
126 m_situareService->fetchLocations(); // request user locations
128 enableGPS(gpsEnabled.toBool());
129 enableAutoCentering(autoCenteringEnabled.toBool());
132 void SituareEngine::requestAddress()
134 qDebug() << __PRETTY_FUNCTION__;
136 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
137 m_situareService->reverseGeo(coordinates);
140 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
142 qDebug() << __PRETTY_FUNCTION__;
144 m_ui->toggleProgressIndicator(true);
146 QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
147 m_situareService->updateLocation(coordinates, status, publish);
150 void SituareEngine::updateWasSuccessful()
152 qDebug() << __PRETTY_FUNCTION__;
154 m_situareService->fetchLocations();
157 void SituareEngine::refreshUserData()
159 qDebug() << __PRETTY_FUNCTION__;
161 m_ui->toggleProgressIndicator(true);
163 m_situareService->fetchLocations();
166 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
168 qDebug() << __PRETTY_FUNCTION__;
170 m_ui->toggleProgressIndicator(false);
172 emit userLocationReady(user);
173 emit friendsLocationsReady(friendsList);
176 void SituareEngine::enableGPS(bool enabled)
178 qDebug() << __PRETTY_FUNCTION__ << enabled;
181 m_gps->lastPosition();
183 m_ui->setGPSButton(true);
187 m_ui->setGPSButton(false);
191 void SituareEngine::enableAutoCentering(bool enabled)
193 qDebug() << __PRETTY_FUNCTION__ << enabled;
196 m_ui->setAutoCenteringButton(true);
197 m_ui->autoCenteringEnabled(true);
198 m_gps->lastPosition();
201 m_ui->setAutoCenteringButton(false);
202 m_ui->autoCenteringEnabled(false);