Facebook integration: Always ask for a folder before sending the photo

This way we are sure that the upload was made in the correct folder.

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-28 21:06:07 -02:00 committed by Dirk Hohndel
parent 571f86485d
commit ed903c42b9
3 changed files with 25 additions and 7 deletions

View file

@ -190,6 +190,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
FacebookManager *fb = FacebookManager::instance(); FacebookManager *fb = FacebookManager::instance();
connect(fb, &FacebookManager::justLoggedIn, ui.facebookPublish, &QPushButton::show); connect(fb, &FacebookManager::justLoggedIn, ui.facebookPublish, &QPushButton::show);
connect(fb, &FacebookManager::justLoggedOut, ui.facebookPublish, &QPushButton::hide); connect(fb, &FacebookManager::justLoggedOut, ui.facebookPublish, &QPushButton::hide);
connect(ui.facebookPublish, &QPushButton::clicked, fb, &FacebookManager::sendDive);
ui.facebookPublish->setVisible(fb->loggedIn()); ui.facebookPublish->setVisible(fb->loggedIn());
} }

View file

@ -13,6 +13,8 @@
#include <QFile> #include <QFile>
#include <QBuffer> #include <QBuffer>
#include <QDebug> #include <QDebug>
#include <QMessageBox>
#include <QInputDialog>
#include "mainwindow.h" #include "mainwindow.h"
#include "profile/profilewidget2.h" #include "profile/profilewidget2.h"
#include "pref.h" #include "pref.h"
@ -85,8 +87,6 @@ void FacebookManager::tryLogin(const QUrl& loginResponse)
sync(); sync();
requestUserId(); requestUserId();
sync(); sync();
requestAlbumId();
sync();
emit justLoggedIn(); emit justLoggedIn();
qDebug() << "End try login"; qDebug() << "End try login";
} }
@ -150,6 +150,7 @@ void FacebookManager::requestAlbumId()
if (album.contains("id")) { if (album.contains("id")) {
s.setValue("AlbumId", album.value("id").toString()); s.setValue("AlbumId", album.value("id").toString());
qDebug() << "Got album ID"; qDebug() << "Got album ID";
sync();
return; return;
} }
@ -188,18 +189,28 @@ void FacebookManager::setDesiredAlbumName(const QString& a)
/* to be changed to export the currently selected dive as shown on the profile. /* 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 * Much much easier, and its also good to people do not select all the dives
* and send erroniously *all* of them to facebook. */ * and send erroniously *all* of them to facebook. */
void FacebookManager::sendDive(int divenr) void FacebookManager::sendDive()
{ {
bool ok;
albumName = QInputDialog::getText(qApp->activeWindow(), tr("Enter Facebook Album"),
tr("Facebook Album:"), QLineEdit::Normal,
"Subsurface", &ok);
if (!ok)
return;
requestAlbumId();
ProfileWidget2 *profile = MainWindow::instance()->graphics(); ProfileWidget2 *profile = MainWindow::instance()->graphics();
QPixmap pix = QPixmap::grabWidget(profile); QPixmap pix = QPixmap::grabWidget(profile);
struct dive* d = current_dive;
QByteArray bytes; QByteArray bytes;
QBuffer buffer(&bytes); QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
pix.save(&buffer, "PNG"); pix.save(&buffer, "PNG");
QUrl url("https://graph.facebook.com/v2.2/" + QString(prefs.facebook.album_id) + "/photos?" + QUrl url("https://graph.facebook.com/v2.2/" + QString(prefs.facebook.album_id) + "/photos?" +
"&access_token=" + QString(prefs.facebook.access_token) + "&access_token=" + QString(prefs.facebook.access_token) +
"&source=image"); "&source=image" +
"&message=" + QString(d->notes).toHtmlEscaped());
QNetworkAccessManager *am = new QNetworkAccessManager(this); QNetworkAccessManager *am = new QNetworkAccessManager(this);
@ -226,5 +237,11 @@ void FacebookManager::sendDive(int divenr)
connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec(); loop.exec();
qDebug() << reply->readAll(); QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
QJsonObject obj = jsonDoc.object();
if (obj.keys().contains("id")){
QMessageBox::
} else {
}
} }

View file

@ -22,7 +22,7 @@ public slots:
void tryLogin(const QUrl& loginResponse); void tryLogin(const QUrl& loginResponse);
void logout(); void logout();
void setDesiredAlbumName(const QString& albumName); void setDesiredAlbumName(const QString& albumName);
void sendDive(int divenr); void sendDive();
private: private:
explicit FacebookManager(QObject *parent = 0); explicit FacebookManager(QObject *parent = 0);