forked from GMaxera/QtFacebook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
qfacebook.cpp
executable file
·118 lines (101 loc) · 4.02 KB
/
qfacebook.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* ************************************************************************
* Copyright (c) 2014 GMaxera <[email protected]> *
* *
* This file is part of QtFacebook *
* *
* QtFacebook is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* ********************************************************************** */
#include "qfacebook.h"
#include <QQuickItemGrabResult>
QObject* QFacebook::qFacebookProvider(QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return QFacebook::instance();
}
QFacebook* QFacebook::instance() {
static QFacebook* facebook = new QFacebook();
return facebook;
}
QFacebook::QFacebook(QObject *parent )
: QObject(parent) {
//qDebug() << "Creating QFacebook singleton Instance";
connected = false;
state = SessionClosed;
initPlatformData();
connect( qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
this, SLOT(onApplicationStateChanged(Qt::ApplicationState)) );
connect(this,&QFacebook::onLogin,[&](bool isLogin ,const std::string& msg){
qDebug() << "onLogin " << isLogin << msg.c_str();
this->connected = isLogin;
emit connectedChanged( isLogin );
});
connect(this,&QFacebook::onPermission,[&](bool isLogin ,const std::string& msg){
qDebug() << "onPermission " << isLogin << msg.c_str();
this->setHasWritePermission(isLogin);
});
}
QFacebook::~QFacebook() {
// nothing to do
}
QString QFacebook::getAppID() {
return appID;
}
QString QFacebook::getDisplayName() {
return displayName;
}
bool QFacebook::getConnected() {
return connected;
}
bool QFacebook::hasWritePermission(){
return m_hasWritePermission;
}
void QFacebook::setHasWritePermission(bool val){
m_hasWritePermission = val;
emit hasWritePermissionChanged(m_hasWritePermission);
}
QStringList QFacebook::getRequestPermissions() {
return requestPermissions;
}
QStringList QFacebook::getGrantedPermissions() {
return grantedPermissions;
}
QFacebook::FacebookState QFacebook::getState() {
return state;
}
void QFacebook::onFacebookStateChanged(int newstate , QStringList grantedPermissions) {
state = (FacebookState)newstate;
connected = ( state == SessionOpen || state == SessionOpenTokenExtended );
this->grantedPermissions = grantedPermissions;
emit stateChanged( state );
emit connectedChanged( connected );
emit grantedPermissionsChanged( this->grantedPermissions );
}
bool QFacebook::isReadPermission( QString permission ) {
// FIXME: Does not contains all permissions listed here:
// https://developers.facebook.com/docs/facebook-login/permissions/v2.2
static QStringList knowRead = QStringList()
<< "public_profile"
<< "user_friends"
<< "email"
<< "user_photos";
return knowRead.contains( permission );
}
bool QFacebook::isPermissionGranted(QString permission)
{
return grantedPermissions.contains(permission);
}
void QFacebook::publishQuickItemGrabResult(QQuickItemGrabResult *result, QString message)
{
publishPhoto(QPixmap::fromImage(result->image()), message);
}