Added QPixmap for User class and implemented first version of profile 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     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()), this, SLOT(loginOk()));
38     connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
39
40     connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress()));
41     connect(m_situareService, SIGNAL(reverseGeoReady(QString)), m_ui, SIGNAL(reverseGeoReady(QString)));
42     connect(m_ui, SIGNAL(statusUpdate(QString,bool)), this, SLOT(requestUpdateLocation(QString,bool)));
43
44     m_situareService->fetchLocations(); // request user locations
45
46     start();
47 }
48
49 SituareEngine::~SituareEngine()
50 {
51     qDebug() << __PRETTY_FUNCTION__;
52     delete m_ui;
53 }
54
55 void SituareEngine::start()
56 {
57     m_facebookAuthenticator->start();
58 }
59
60 void SituareEngine::loginOk()
61
62 {
63     qDebug() << __PRETTY_FUNCTION__;
64     m_loggedIn = true;
65     m_facebookAuthenticator->close();
66 }
67
68 void SituareEngine::loginScreenClosed()
69 {
70     qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
71     if (m_loggedIn) {
72         m_ui->show();
73         return;
74     }
75     else {
76         m_ui->close();
77     }
78 }
79
80 void SituareEngine::requestAddress()
81 {
82     qDebug() << __PRETTY_FUNCTION__;
83     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
84     m_situareService->reverseGeo(coordinates);
85 }
86
87 void SituareEngine::requestUpdateLocation(const QString &status, const bool &publish)
88 {
89     qDebug() << __PRETTY_FUNCTION__;
90     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
91     m_situareService->updateLocation(coordinates, status, publish);
92 }
93
94 void SituareEngine::updateFriendsList()
95 {
96     qDebug() << __PRETTY_FUNCTION__;
97     //code here
98 }