Updated user and friendslist signals and image fetching
[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     qDebug() << __PRETTY_FUNCTION__;
30     m_ui = new MainWindow;
31
32     m_situareService = new SituareService(this);
33
34     m_facebookAuthenticator = new FacebookAuthentication();
35
36     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
37             m_situareService, SLOT(credentialsReady(FacebookCredentials)));
38     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
39             this, SLOT(loginOk()));
40
41     connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress()));
42     connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString)));
43     connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool)));
44     connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)),
45             this, SLOT(userDataChanged(User*,QList<User*>&)));
46     connect(this, SIGNAL(userLocationReady(User*)), m_ui, SIGNAL(userLocationReady(User*)));
47     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)), m_ui, SIGNAL(friendsLocationsReady(QList<User*>&)));
48         connect(m_situareService, SIGNAL(error(QString)), this, SLOT(error(QString)));
49     connect(m_situareService, SIGNAL(updateWasSuccessful()), this, SLOT(updateWasSuccessful()));
50
51     m_facebookAuthenticator->start();
52 }
53
54 SituareEngine::~SituareEngine()
55 {
56     qDebug() << __PRETTY_FUNCTION__;
57     delete m_ui;
58     delete m_facebookAuthenticator;
59 }
60
61 void SituareEngine::error(const QString &error)
62 {
63     qDebug() << __PRETTY_FUNCTION__;
64     qDebug() << error;
65     // ToDo: signal UI?
66 }
67
68 void SituareEngine::loginOk()
69 {
70     qDebug() << __PRETTY_FUNCTION__;
71     m_facebookAuthenticator->hide();
72     m_ui->show();
73     m_situareService->fetchLocations(); // request user locations
74 }
75
76 void SituareEngine::requestAddress()
77 {
78     qDebug() << __PRETTY_FUNCTION__;
79
80     QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
81     m_situareService->reverseGeo(coordinates);
82 }
83
84 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
85 {
86     qDebug() << __PRETTY_FUNCTION__;
87
88     QPointF coordinates(65.0109, 25.5092); // this will be get from somewhere, map etc...
89     m_situareService->updateLocation(coordinates, status, publish);
90 }
91
92 void SituareEngine::updateWasSuccessful()
93 {
94     qDebug() << __PRETTY_FUNCTION__;
95
96     m_situareService->fetchLocations();
97 }
98
99 void SituareEngine::updateFriendsList()
100 {
101     qDebug() << __PRETTY_FUNCTION__;
102     //code here
103 }
104
105 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
106 {
107     qDebug() << __PRETTY_FUNCTION__;
108
109     emit userLocationReady(user);
110     emit friendsLocationsReady(friendsList);
111 }