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>
This commit is contained in:
Tomaz Canabrava 2014-12-24 13:23:31 -02:00 committed by Dirk Hohndel
parent e49b4b72b7
commit a76fdd8d54
5 changed files with 77 additions and 1 deletions

View file

@ -824,6 +824,10 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
popup.addAction(tr("Shift times"), this, SLOT(shiftTimes()));
popup.addAction(tr("Load images"), this, SLOT(loadImages()));
}
if (prefs.facebook.user_id) {
popup.addAction(tr("Publish on Facebook"), this, SLOT(publishFacebook()));
}
// "collapse all" really closes all trips,
// "collapse" keeps the trip with the selected dive open
QAction *actionTaken = popup.exec(event->globalPos());
@ -836,6 +840,12 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
event->accept();
}
void DiveListView::publishFacebook()
{
FacebookManager manager;
manager.checkAlbumExists();
}
void DiveListView::shiftTimes()
{
ShiftTimesDialog::instance()->show();

View file

@ -51,6 +51,7 @@ slots:
void renumberDives();
void shiftTimes();
void loadImages();
void publishFacebook();
static QString lastUsedImageDir();
signals:

View file

@ -18,7 +18,7 @@ static QString facebookConnectUrl =
"client_id=427722490709000"
"&redirect_uri=http://www.facebook.com/connect/login_success.html"
"&response_type=token"
"&scope=publish_actions";
"&scope=publish_actions,user_photos";
PreferencesDialog *PreferencesDialog::instance()
{

View file

@ -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()
{
}

View file

@ -3,6 +3,7 @@
class MinMaxAvgWidgetPrivate;
class QAbstractButton;
class QNetworkReply;
#include <QWidget>
#include <QDialog>
@ -18,6 +19,7 @@ class QAbstractButton;
#include "exif.h"
#include <dive.h>
class MinMaxAvgWidget : public QWidget {
Q_OBJECT
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
@ -212,6 +214,15 @@ private:
Ui::FilterWidget ui;
};
class FacebookManager : public QObject {
Q_OBJECT
public:
FacebookManager();
bool checkAlbumExists();
void createAlbum();
signals:
void requestFinished(const QString& result);
};
bool isGnome3Session();
QImage grayImage(const QImage &coloredImg);