summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2017-10-02 14:48:34 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-02 08:54:03 -0700
commit5595d9a8b014a71ca1d62db9e0c6562d3480d013 (patch)
treeeb4f8948b6c62563dfadd8308ecc83c1d6ea8fe2 /desktop-widgets
parent15c4fadde9b880bd81ad441296227536985c7084 (diff)
downloadsubsurface-5595d9a8b014a71ca1d62db9e0c6562d3480d013.tar.gz
[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>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/plugins/facebook/facebookconnectwidget.cpp38
1 files changed, 33 insertions, 5 deletions
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
index bfe563384..3e11d68f5 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -16,6 +16,7 @@
#include <QDebug>
#include <QMessageBox>
#include <QInputDialog>
+#include <QLoggingCategory>
#ifdef USE_WEBENGINE
#include <QWebEngineView>
#else
@@ -31,6 +32,8 @@
#include "ui_socialnetworksdialog.h"
#include "ui_facebookconnectwidget.h"
+Q_LOGGING_CATEGORY(lcFacebook, "subsurface.facebook")
+
FacebookManager *FacebookManager::instance()
{
static FacebookManager *self = new FacebookManager();
@@ -67,20 +70,26 @@ bool FacebookManager::loggedIn() {
void FacebookManager::tryLogin(const QUrl& loginResponse)
{
+ qCDebug(lcFacebook) << "Response from login call" << loginResponse;
+
QString result = loginResponse.toString();
- if (!result.contains("access_token"))
+ if (!result.contains("access_token")) {
+ qCDebug(lcFacebook) << "Response without access token!";
return;
+ }
if (result.contains("denied_scopes=publish_actions") || result.contains("denied_scopes=user_photos")) {
- qDebug() << "user did not allow us access" << result;
+ qCDebug(lcFacebook) << "user did not allow us access" << result;
return;
}
+
int from = result.indexOf("access_token=") + strlen("access_token=");
int to = result.indexOf("&expires_in");
QString securityToken = result.mid(from, to-from);
auto fb = SettingsObjectWrapper::instance()->facebook;
fb->setAccessToken(securityToken);
+ qCDebug(lcFacebook) << "Got securityToken" << securityToken;
requestUserId();
}
@@ -95,12 +104,14 @@ void FacebookManager::logout()
void FacebookManager::requestAlbumId()
{
+ qCDebug(lcFacebook) << "Starting to request the album id" << albumListUrl();
QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl()));
connect(reply, &QNetworkReply::finished, this, &FacebookManager::albumListReceived);
}
void FacebookManager::albumListReceived()
{
+ qCDebug(lcFacebook) << "Reply for the album id";
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
QJsonArray albumObj = albumsDoc.object().value("data").toArray();
@@ -111,16 +122,19 @@ void FacebookManager::albumListReceived()
QJsonObject obj = v.toObject();
if (obj.value("name").toString() == albumName) {
fb->setAlbumId(obj.value("id").toString());
+ qCDebug(lcFacebook) << "Album" << albumName << "already exists, using id" << obj.value("id").toString();
emit albumIdReceived(fb->albumId());
return;
}
}
+
// No album with the name we requested, create a new one.
createFacebookAlbum();
}
void FacebookManager::createFacebookAlbum()
{
+ qCDebug(lcFacebook) << "Album with name" << albumName << "doesn't exists, creating it.";
QUrlQuery params;
params.addQueryItem("name", albumName );
params.addQueryItem("description", "Subsurface Album");
@@ -142,15 +156,19 @@ void FacebookManager::facebookAlbumCreated()
reply->deleteLater();
if (album.contains("id")) {
+ qCDebug(lcFacebook) << "Album" << albumName << "created successfully with id" << album.value("id").toString();
auto fb = SettingsObjectWrapper::instance()->facebook;
fb->setAlbumId(album.value("id").toString());
emit albumIdReceived(fb->albumId());
return;
+ } else {
+ qCDebug(lcFacebook) << "It was not possible to create the album with name" << albumName;
}
}
void FacebookManager::requestUserId()
{
+ qCDebug(lcFacebook) << "Requesting user id";
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
QNetworkReply *reply = manager->get(QNetworkRequest(userIdRequest));
@@ -163,14 +181,18 @@ void FacebookManager::userIdReceived()
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
QJsonObject obj = jsonDoc.object();
if (obj.keys().contains("id")) {
+ qCDebug(lcFacebook) << "User id requested successfully:" << obj.value("id").toString();
SettingsObjectWrapper::instance()->facebook->setUserId(obj.value("id").toString());
emit justLoggedIn(true);
+ } else {
+ qCDebug(lcFacebook) << "Error, user id unknown, cannot login.";
}
reply->deleteLater();
}
QPixmap FacebookManager::grabProfilePixmap()
{
+ qCDebug(lcFacebook) << "Grabbing Dive Profile pixmap";
ProfileWidget2 *profile = MainWindow::instance()->graphics();
QSize size = fbInfo.profileSize == FacebookInfo::SMALL ? QSize(800,600) :
@@ -193,9 +215,13 @@ QPixmap FacebookManager::grabProfilePixmap()
* and send erroniously *all* of them to facebook. */
void FacebookManager::sendDiveInit()
{
+ qCDebug(lcFacebook) << "Starting to upload the dive to facebook";
+
SocialNetworkDialog dialog(qApp->activeWindow());
- if (dialog.exec() != QDialog::Accepted)
+ if (dialog.exec() != QDialog::Accepted) {
+ qCDebug(lcFacebook) << "User cancelled.";
return;
+ }
fbInfo.bodyText = dialog.text();
fbInfo.profileSize = dialog.profileSize();
@@ -206,9 +232,10 @@ void FacebookManager::sendDiveInit()
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) +
"&source=image" +
"&message=" + fbInfo.bodyText.replace("&quot;", "%22"));
@@ -245,6 +272,7 @@ void FacebookManager::sendDiveToAlbum(const QString& album)
void FacebookManager::uploadFinished()
{
+ qCDebug(lcFacebook) << "Upload finish";
auto reply = qobject_cast<QNetworkReply*>(sender());
QByteArray response = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(response);