diff options
-rw-r--r-- | qt-ui/divelistview.cpp | 2 | ||||
-rw-r--r-- | qt-ui/socialnetworks.cpp | 44 | ||||
-rw-r--r-- | qt-ui/socialnetworks.h | 1 |
3 files changed, 47 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 83d78c4c2..cbbf35152 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -27,6 +27,7 @@ #include <QFileDialog> #include <string> #include <iostream> +#include <QHttpMultiPart> #include "socialnetworks.h" #include "../qthelper.h" @@ -844,6 +845,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) void DiveListView::publishFacebook() { FacebookManager *fb = FacebookManager::instance(); + fb->sendDive(1); } void DiveListView::shiftTimes() diff --git a/qt-ui/socialnetworks.cpp b/qt-ui/socialnetworks.cpp index 76a85566d..f9d5acf54 100644 --- a/qt-ui/socialnetworks.cpp +++ b/qt-ui/socialnetworks.cpp @@ -8,7 +8,9 @@ #include <QNetworkAccessManager> #include <QUrlQuery> #include <QEventLoop> +#include <QHttpMultiPart> #include <QSettings> +#include <QFile> #include <QDebug> #include "pref.h" @@ -180,3 +182,45 @@ void FacebookManager::setDesiredAlbumName(const QString& a) { albumName = a; } + +/* + + +*/ + +void FacebookManager::sendDive(int divenr) +{ + + QUrl url("https://graph.facebook.com/v2.2/" + QString(prefs.facebook.album_id) + "/photos?" + + "&access_token=" + QString(prefs.facebook.access_token) + + "&source=image"); + + + QNetworkAccessManager *am = new QNetworkAccessManager(this); + QFile file("subsurfaceuploadtest.png"); + file.open(QIODevice::ReadOnly); + QNetworkRequest request(url); + + QString bound="margin"; + + //according to rfc 1867 we need to put this string here: + QByteArray data(QString("--" + bound + "\r\n").toLocal8Bit()); + data.append("Content-Disposition: form-data; name=\"action\"\r\n\r\n"); + data.append("https://graph.facebook.com/v2.2/\r\n"); + data.append("--" + bound + "\r\n"); //according to rfc 1867 + data.append("Content-Disposition: form-data; name=\"uploaded\"; filename=\"subsurfaceuploadtest.png\"\r\n"); //name of the input is "uploaded" in my form, next one is a file name. + data.append("Content-Type: image/jpeg\r\n\r\n"); //data type + data.append(file.readAll()); //let's read the file + data.append("\r\n"); + data.append("--" + bound + "--\r\n"); //closing boundary according to rfc 1867 + + request.setRawHeader(QString("Content-Type").toLocal8Bit(),QString("multipart/form-data; boundary=" + bound).toLocal8Bit()); + request.setRawHeader(QString("Content-Length").toLocal8Bit(), QString::number(data.length()).toLocal8Bit()); + QNetworkReply *reply = am->post(request,data); + + QEventLoop loop; + connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + loop.exec(); + + qDebug() << reply->readAll(); +} diff --git a/qt-ui/socialnetworks.h b/qt-ui/socialnetworks.h index ed7804afa..8c474c906 100644 --- a/qt-ui/socialnetworks.h +++ b/qt-ui/socialnetworks.h @@ -22,6 +22,7 @@ public slots: void tryLogin(const QUrl& loginResponse); void logout(); void setDesiredAlbumName(const QString& albumName); + void sendDive(int divenr); private: explicit FacebookManager(QObject *parent = 0); |