On Wed, Dec 24, 2014 at 7:57 AM, Tomaz Canabrava <[email protected]> wrote:

>
> Em 24/12/2014 05:39, "Robert C. Helling" <[email protected]> escreveu:
> >
> >
> > On 24 Dec 2014, at 00:02, Tomaz Canabrava <[email protected]> wrote:
> >
> > Hi,
> >
> >> It doesn't do anything yet besides logging in, saving user info and
> logging out, but since dirk really want some patches, there you go. :)
> >
> >
> > great.
> >
> > I don’t know if that is supposed to work, but I cannot login, I get an
> error "App ist nicht eingerichtet: Die App-Entwickler haben diese App nicht
> richtig für die Facebook-Anmeldung eingerichtet.” saying the app is not
> configured: the application developers have not properly set up the up
> for Facebook login.
> >
> > Whatever that means.
> >
> > Another issue: I admit, I do not really understand this OAuth process.
> But when I looked into it (to see how difficult this social media
> integration would be) I came to the conclusion that we would need some sort
> of subsurface application identifiert, that would identify subsurface
> to Facebook and that we are supposed to keep secret. At that point I
> considered this a show stopper for an open source application. Was I
> misguided or how are you going to overcome this?
>
> This secret is not going to be used on client side software, and you not
> being abre tô login is because the configuration of the app is the Facebook
> side is e asked just for developers ( and im the only developer, yet.)  Ill
> try to find out how to enable stuff tô others besides myself.
>
> But belive me, if you use my account, things works. ;p
>

good lord, I should be forbidden to write anything when I'm sleepy.
Anyhow, New patch:
Create a Facebook album
From 06767294b40c2ed8dd355010c4de3ceebf2aaef4 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 24 Dec 2014 13:23:31 -0200
Subject: [PATCH 8/8] Creates an 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 <[email protected]>
---
 qt-ui/divelistview.cpp  | 10 +++++++++
 qt-ui/divelistview.h    |  1 +
 qt-ui/preferences.cpp   |  2 +-
 qt-ui/simplewidgets.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 qt-ui/simplewidgets.h   | 11 ++++++++++
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index c5ffaaa..65090e1 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -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();
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index a6522fa..c7f1ef7 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -51,6 +51,7 @@ slots:
 	void renumberDives();
 	void shiftTimes();
 	void loadImages();
+	void publishFacebook();
 	static QString lastUsedImageDir();
 
 signals:
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index 51a1d35..9502c0c 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -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()
 {
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp
index fc96fce..6263e55 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()
+{
+
+}
diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h
index b2b08d5..84f0349 100644
--- a/qt-ui/simplewidgets.h
+++ b/qt-ui/simplewidgets.h
@@ -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);
 
-- 
2.2.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to