aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divelistview.cpp10
-rw-r--r--qt-ui/divelistview.h1
-rw-r--r--qt-ui/preferences.cpp2
-rw-r--r--qt-ui/simplewidgets.cpp54
-rw-r--r--qt-ui/simplewidgets.h11
5 files changed, 77 insertions, 1 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index c5ffaaafa..65090e1e8 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 a6522fa9a..c7f1ef775 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 51a1d3567..9502c0c0f 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 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()
+{
+
+}
diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h
index b2b08d552..84f0349a4 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);