mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
[Facebook] Lots of debug messages
Important debug messages, don't remove. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
15c4fadde9
commit
5595d9a8b0
1 changed files with 36 additions and 8 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QLoggingCategory>
|
||||||
#ifdef USE_WEBENGINE
|
#ifdef USE_WEBENGINE
|
||||||
#include <QWebEngineView>
|
#include <QWebEngineView>
|
||||||
#else
|
#else
|
||||||
|
@ -31,6 +32,8 @@
|
||||||
#include "ui_socialnetworksdialog.h"
|
#include "ui_socialnetworksdialog.h"
|
||||||
#include "ui_facebookconnectwidget.h"
|
#include "ui_facebookconnectwidget.h"
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(lcFacebook, "subsurface.facebook")
|
||||||
|
|
||||||
FacebookManager *FacebookManager::instance()
|
FacebookManager *FacebookManager::instance()
|
||||||
{
|
{
|
||||||
static FacebookManager *self = new FacebookManager();
|
static FacebookManager *self = new FacebookManager();
|
||||||
|
@ -67,20 +70,26 @@ bool FacebookManager::loggedIn() {
|
||||||
|
|
||||||
void FacebookManager::tryLogin(const QUrl& loginResponse)
|
void FacebookManager::tryLogin(const QUrl& loginResponse)
|
||||||
{
|
{
|
||||||
QString result = loginResponse.toString();
|
qCDebug(lcFacebook) << "Response from login call" << loginResponse;
|
||||||
if (!result.contains("access_token"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (result.contains("denied_scopes=publish_actions") || result.contains("denied_scopes=user_photos")) {
|
QString result = loginResponse.toString();
|
||||||
qDebug() << "user did not allow us access" << result;
|
if (!result.contains("access_token")) {
|
||||||
|
qCDebug(lcFacebook) << "Response without access token!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.contains("denied_scopes=publish_actions") || result.contains("denied_scopes=user_photos")) {
|
||||||
|
qCDebug(lcFacebook) << "user did not allow us access" << result;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int from = result.indexOf("access_token=") + strlen("access_token=");
|
int from = result.indexOf("access_token=") + strlen("access_token=");
|
||||||
int to = result.indexOf("&expires_in");
|
int to = result.indexOf("&expires_in");
|
||||||
QString securityToken = result.mid(from, to-from);
|
QString securityToken = result.mid(from, to-from);
|
||||||
|
|
||||||
auto fb = SettingsObjectWrapper::instance()->facebook;
|
auto fb = SettingsObjectWrapper::instance()->facebook;
|
||||||
fb->setAccessToken(securityToken);
|
fb->setAccessToken(securityToken);
|
||||||
|
qCDebug(lcFacebook) << "Got securityToken" << securityToken;
|
||||||
requestUserId();
|
requestUserId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,12 +104,14 @@ void FacebookManager::logout()
|
||||||
|
|
||||||
void FacebookManager::requestAlbumId()
|
void FacebookManager::requestAlbumId()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Starting to request the album id" << albumListUrl();
|
||||||
QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl()));
|
QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl()));
|
||||||
connect(reply, &QNetworkReply::finished, this, &FacebookManager::albumListReceived);
|
connect(reply, &QNetworkReply::finished, this, &FacebookManager::albumListReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FacebookManager::albumListReceived()
|
void FacebookManager::albumListReceived()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Reply for the album id";
|
||||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
|
QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
|
||||||
QJsonArray albumObj = albumsDoc.object().value("data").toArray();
|
QJsonArray albumObj = albumsDoc.object().value("data").toArray();
|
||||||
|
@ -111,16 +122,19 @@ void FacebookManager::albumListReceived()
|
||||||
QJsonObject obj = v.toObject();
|
QJsonObject obj = v.toObject();
|
||||||
if (obj.value("name").toString() == albumName) {
|
if (obj.value("name").toString() == albumName) {
|
||||||
fb->setAlbumId(obj.value("id").toString());
|
fb->setAlbumId(obj.value("id").toString());
|
||||||
|
qCDebug(lcFacebook) << "Album" << albumName << "already exists, using id" << obj.value("id").toString();
|
||||||
emit albumIdReceived(fb->albumId());
|
emit albumIdReceived(fb->albumId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No album with the name we requested, create a new one.
|
// No album with the name we requested, create a new one.
|
||||||
createFacebookAlbum();
|
createFacebookAlbum();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FacebookManager::createFacebookAlbum()
|
void FacebookManager::createFacebookAlbum()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Album with name" << albumName << "doesn't exists, creating it.";
|
||||||
QUrlQuery params;
|
QUrlQuery params;
|
||||||
params.addQueryItem("name", albumName );
|
params.addQueryItem("name", albumName );
|
||||||
params.addQueryItem("description", "Subsurface Album");
|
params.addQueryItem("description", "Subsurface Album");
|
||||||
|
@ -142,15 +156,19 @@ void FacebookManager::facebookAlbumCreated()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
if (album.contains("id")) {
|
if (album.contains("id")) {
|
||||||
|
qCDebug(lcFacebook) << "Album" << albumName << "created successfully with id" << album.value("id").toString();
|
||||||
auto fb = SettingsObjectWrapper::instance()->facebook;
|
auto fb = SettingsObjectWrapper::instance()->facebook;
|
||||||
fb->setAlbumId(album.value("id").toString());
|
fb->setAlbumId(album.value("id").toString());
|
||||||
emit albumIdReceived(fb->albumId());
|
emit albumIdReceived(fb->albumId());
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
qCDebug(lcFacebook) << "It was not possible to create the album with name" << albumName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FacebookManager::requestUserId()
|
void FacebookManager::requestUserId()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Requesting user id";
|
||||||
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
|
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
|
||||||
QNetworkReply *reply = manager->get(QNetworkRequest(userIdRequest));
|
QNetworkReply *reply = manager->get(QNetworkRequest(userIdRequest));
|
||||||
|
|
||||||
|
@ -163,14 +181,18 @@ void FacebookManager::userIdReceived()
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
|
||||||
QJsonObject obj = jsonDoc.object();
|
QJsonObject obj = jsonDoc.object();
|
||||||
if (obj.keys().contains("id")) {
|
if (obj.keys().contains("id")) {
|
||||||
|
qCDebug(lcFacebook) << "User id requested successfully:" << obj.value("id").toString();
|
||||||
SettingsObjectWrapper::instance()->facebook->setUserId(obj.value("id").toString());
|
SettingsObjectWrapper::instance()->facebook->setUserId(obj.value("id").toString());
|
||||||
emit justLoggedIn(true);
|
emit justLoggedIn(true);
|
||||||
|
} else {
|
||||||
|
qCDebug(lcFacebook) << "Error, user id unknown, cannot login.";
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap FacebookManager::grabProfilePixmap()
|
QPixmap FacebookManager::grabProfilePixmap()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Grabbing Dive Profile pixmap";
|
||||||
ProfileWidget2 *profile = MainWindow::instance()->graphics();
|
ProfileWidget2 *profile = MainWindow::instance()->graphics();
|
||||||
|
|
||||||
QSize size = fbInfo.profileSize == FacebookInfo::SMALL ? QSize(800,600) :
|
QSize size = fbInfo.profileSize == FacebookInfo::SMALL ? QSize(800,600) :
|
||||||
|
@ -193,9 +215,13 @@ QPixmap FacebookManager::grabProfilePixmap()
|
||||||
* and send erroniously *all* of them to facebook. */
|
* and send erroniously *all* of them to facebook. */
|
||||||
void FacebookManager::sendDiveInit()
|
void FacebookManager::sendDiveInit()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Starting to upload the dive to facebook";
|
||||||
|
|
||||||
SocialNetworkDialog dialog(qApp->activeWindow());
|
SocialNetworkDialog dialog(qApp->activeWindow());
|
||||||
if (dialog.exec() != QDialog::Accepted)
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
|
qCDebug(lcFacebook) << "User cancelled.";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fbInfo.bodyText = dialog.text();
|
fbInfo.bodyText = dialog.text();
|
||||||
fbInfo.profileSize = dialog.profileSize();
|
fbInfo.profileSize = dialog.profileSize();
|
||||||
|
@ -206,9 +232,10 @@ void FacebookManager::sendDiveInit()
|
||||||
requestAlbumId();
|
requestAlbumId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FacebookManager::sendDiveToAlbum(const QString& album)
|
void FacebookManager::sendDiveToAlbum(const QString& albumId)
|
||||||
{
|
{
|
||||||
QUrl url(graphApi + album + "/photos?" +
|
qCDebug(lcFacebook) << "Starting to upload the dive to album" << albumName << "id" << albumId;
|
||||||
|
QUrl url(graphApi + albumId + "/photos?" +
|
||||||
"&access_token=" + QString(prefs.facebook.access_token) +
|
"&access_token=" + QString(prefs.facebook.access_token) +
|
||||||
"&source=image" +
|
"&source=image" +
|
||||||
"&message=" + fbInfo.bodyText.replace(""", "%22"));
|
"&message=" + fbInfo.bodyText.replace(""", "%22"));
|
||||||
|
@ -245,6 +272,7 @@ void FacebookManager::sendDiveToAlbum(const QString& album)
|
||||||
|
|
||||||
void FacebookManager::uploadFinished()
|
void FacebookManager::uploadFinished()
|
||||||
{
|
{
|
||||||
|
qCDebug(lcFacebook) << "Upload finish";
|
||||||
auto reply = qobject_cast<QNetworkReply*>(sender());
|
auto reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
QByteArray response = reply->readAll();
|
QByteArray response = reply->readAll();
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(response);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(response);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue