Merge branch 'friendlist' into integration
[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         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 "engine.h"
25 #include "ui/mainwindow.h"
26
27 SituareEngine::SituareEngine(QMainWindow *parent)
28     : QObject(parent)
29 {
30     qDebug() << __PRETTY_FUNCTION__;
31     m_ui = new MainWindow;
32
33     m_situareService = new SituareService(this);
34
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     m_facebookAuthenticator->start();
51 }
52
53 SituareEngine::~SituareEngine()
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56     delete m_ui;
57     delete m_facebookAuthenticator;
58 }
59
60 void SituareEngine::loginOk()
61 {
62     qDebug() << __PRETTY_FUNCTION__;
63     m_facebookAuthenticator->hide();
64     m_ui->show();
65     m_situareService->fetchLocations(); // request user locations
66 }
67
68 void SituareEngine::requestAddress()
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
72     m_situareService->reverseGeo(coordinates);
73 }
74
75 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
76 {
77     qDebug() << __PRETTY_FUNCTION__;
78     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
79     m_situareService->updateLocation(coordinates, status, publish);
80 }
81
82 void SituareEngine::updateFriendsList()
83 {
84     qDebug() << __PRETTY_FUNCTION__;
85     //code here
86 }
87
88 void SituareEngine::userDataChanged(User *user, QList<User *> &friendList)
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91     emit userLocationReady(user);
92     qDebug() << friendList.at(0)->name();
93     emit friendsLocationsReady(friendList);
94 }