added base class for own and friend locations. added new class for
[situare] / src / engine / engine.cpp
1  /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Henri Lampela - henri.lampela@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21  */
22
23 #include "engine.h"
24 #include "ui/mainwindow.h"
25
26 SituareEngine::SituareEngine(QMainWindow *parent)
27     : QObject(parent)
28 {
29     m_ui = new MainWindow;
30
31     m_networkManager = new QNetworkAccessManager;
32     m_situareService = new SituareService(this,m_networkManager);
33
34     m_loggedIn = false;
35     m_facebookAuthenticator = new FacebookAuthentication();
36
37     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
38             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
39     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
40             this, SLOT(loginOk()));
41
42     connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress()));
43     connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString)));
44     connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool)));
45     connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
46             this, SLOT(userDataChanged(User*,QList<User*>&)));
47     connect(this, SIGNAL(userLocationReady(User*)), m_ui, SIGNAL(userLocationReady(User*)));
48     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)), m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
49
50     start();
51 }
52
53 SituareEngine::~SituareEngine()
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56     delete m_ui;
57 }
58
59 void SituareEngine::start()
60 {
61     m_facebookAuthenticator->start();
62 }
63
64 void SituareEngine::loginOk()
65
66 {
67     qDebug() << __PRETTY_FUNCTION__;
68     m_loggedIn = true;
69     m_facebookAuthenticator->hide();
70     m_ui->show();
71     m_situareService->fetchLocations(); // request user locations
72 }
73
74 void SituareEngine::requestAddress()
75 {
76     qDebug() << __PRETTY_FUNCTION__;
77     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
78     m_situareService->reverseGeo(coordinates);
79 }
80
81 void SituareEngine::requestUpdateLocation(const QString &status, const bool &publish)
82 {
83     qDebug() << __PRETTY_FUNCTION__;
84     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
85     m_situareService->updateLocation(coordinates, status, publish);
86 }
87
88 void SituareEngine::updateFriendsList()
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91     //code here
92 }
93
94 void SituareEngine::userDataChanged(User *user, QList<User *> &friendList)
95 {
96     qDebug() << __PRETTY_FUNCTION__;
97     emit userLocationReady(user);
98     qDebug() << friendList.at(0)->name();
99     emit friendsLocationsReady(friendList);
100 }