Added engine to master
[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)),
43             m_ui, SIGNAL(reverseGeoReady(QString)));
44     connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
45             this, SLOT(requestUpdateLocation(QString,bool)));
46
47     m_facebookAuthenticator->start();
48 }
49
50 SituareEngine::~SituareEngine()
51 {
52     qDebug() << __PRETTY_FUNCTION__;
53     delete m_ui;
54     delete m_facebookAuthenticator;
55 }
56
57 void SituareEngine::loginOk()
58 {
59     qDebug() << __PRETTY_FUNCTION__;
60     m_facebookAuthenticator->hide();
61     m_ui->show();
62     m_situareService->fetchLocations(); // request user locations
63 }
64
65 void SituareEngine::requestAddress()
66 {
67     qDebug() << __PRETTY_FUNCTION__;
68     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
69     m_situareService->reverseGeo(coordinates);
70 }
71
72 void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
73 {
74     qDebug() << __PRETTY_FUNCTION__;
75     QPointF coordinates(65, 25.5); // this will be get from somewhere, map etc...
76     m_situareService->updateLocation(coordinates, status, publish);
77 }
78
79 void SituareEngine::updateFriendsList()
80 {
81     qDebug() << __PRETTY_FUNCTION__;
82     //code here
83 }