aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/simplewidgets.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-12-24 13:23:31 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-24 07:32:36 -0800
commita76fdd8d54600fee1d82e40fddaf3cf563dbc582 (patch)
tree1c6b42f696a2dcf43fa135cfe6981df0757a3fec /qt-ui/simplewidgets.cpp
parente49b4b72b719579a2ff49f4add732fb52c40c953 (diff)
downloadsubsurface-a76fdd8d54600fee1d82e40fddaf3cf563dbc582.tar.gz
Create a Facebook album for Subsurface
We still need to do a lot of stuff on that part. Currently when asking for sending a profile, it will just create a private album. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/simplewidgets.cpp')
-rw-r--r--qt-ui/simplewidgets.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index fc96fce40..6263e5521 100644
--- a/qt-ui/simplewidgets.cpp
+++ b/qt-ui/simplewidgets.cpp
@@ -11,6 +11,14 @@
#include <QSortFilterProxyModel>
#include <QToolButton>
#include <QToolBar>
+#include <QUrlQuery>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QJsonValue>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
#include "exif.h"
#include "dive.h"
#include "file.h"
@@ -653,3 +661,49 @@ void MultiFilter::closeFilter()
MultiFilterSortModel::instance()->clearFilter();
hide();
}
+
+FacebookManager::FacebookManager()
+{
+}
+
+bool FacebookManager::checkAlbumExists()
+{
+ QUrl albumListUrl("https://graph.facebook.com/me/albums?access_token=" + QString(prefs.facebook.access_token));
+ QNetworkAccessManager *manager = new QNetworkAccessManager();
+ QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl));
+
+ // Make this method synchronous.
+ QEventLoop loop;
+ connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+ loop.exec();
+
+ QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
+ QJsonArray albumObj = albumsDoc.object().value("data").toArray();
+ foreach(const QJsonValue &v, albumObj){
+ QJsonObject obj = v.toObject();
+ if (obj.value("name").toString() == QString(prefs.facebook.album_name)) {
+ qDebug() << "Album already exists. Try to get the ID in the next commit.";
+ return false;
+ }
+ }
+
+ qDebug() << "Album doesn't exists, let's create it.";
+ QUrlQuery params;
+ params.addQueryItem("name", prefs.facebook.album_name );
+ params.addQueryItem("description", "Subsurface Album");
+ params.addQueryItem("privacy", "{'value': 'SELF'}");
+
+ QNetworkRequest request(albumListUrl);
+ request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
+ reply = manager->post(request, params.query().toLocal8Bit());
+ connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+ loop.exec();
+
+ qDebug() << reply->readAll();
+
+}
+
+void FacebookManager::createAlbum()
+{
+
+}