diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-12-25 17:22:06 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-12-26 08:33:53 -0800 |
commit | 42bd55877b844caf16c5c7c9a2e49ae67aa15fa5 (patch) | |
tree | c43dd86be856cfaac7f4d14bfc4e77670054077f /qt-ui | |
parent | 3d3eac7cc72d9466464b59c66fb1b5162b789879 (diff) | |
download | subsurface-42bd55877b844caf16c5c7c9a2e49ae67aa15fa5.tar.gz |
Send the current selected dive to Facebook
This still only works for FB app admins at this time.
It always sends the dive that is shown in the profile.
It uses the resolution / size of the profile on screen.
It doesn't add any description and doesn't ask the user for explicit
permission to post (a preview would be even better with the ability to
edit the post).
But it's a great next step!
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/socialnetworks.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/qt-ui/socialnetworks.cpp b/qt-ui/socialnetworks.cpp index f9d5acf54..75d292ba6 100644 --- a/qt-ui/socialnetworks.cpp +++ b/qt-ui/socialnetworks.cpp @@ -11,8 +11,10 @@ #include <QHttpMultiPart> #include <QSettings> #include <QFile> +#include <QBuffer> #include <QDebug> - +#include "mainwindow.h" +#include "profile/profilewidget2.h" #include "pref.h" #define GET_TXT(name, field) \ @@ -183,22 +185,24 @@ void FacebookManager::setDesiredAlbumName(const QString& a) albumName = a; } -/* - - -*/ - +/* to be changed to export the currently selected dive as shown on the profile. + * Much much easier, and its also good to people do not select all the dives + * and send erroniously *all* of them to facebook. */ void FacebookManager::sendDive(int divenr) { + ProfileWidget2 *profile = MainWindow::instance()->graphics(); + QPixmap pix = QPixmap::grabWidget(profile); + QByteArray bytes; + QBuffer buffer(&bytes); + buffer.open(QIODevice::WriteOnly); + pix.save(&buffer, "PNG"); 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"; @@ -208,9 +212,9 @@ void FacebookManager::sendDive(int divenr) 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-Disposition: form-data; name=\"uploaded\"; filename=\"" + QString::number(qrand()) + ".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(bytes); //let's read the file data.append("\r\n"); data.append("--" + bound + "--\r\n"); //closing boundary according to rfc 1867 |