summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/plugins
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2017-10-02 14:35:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-10-02 08:54:03 -0700
commit15c4fadde9b880bd81ad441296227536985c7084 (patch)
tree27808113cd4032d6a22cb13b9a597864db75f25c /desktop-widgets/plugins
parente662ce1cec935e13b7f3c078e527e1b05dfeaceb (diff)
downloadsubsurface-15c4fadde9b880bd81ad441296227536985c7084.tar.gz
[Facebook] Use the nonblocking calls to post on fb
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/plugins')
-rw-r--r--desktop-widgets/plugins/facebook/facebook_integration.cpp2
-rw-r--r--desktop-widgets/plugins/facebook/facebookconnectwidget.cpp17
-rw-r--r--desktop-widgets/plugins/facebook/facebookconnectwidget.h5
3 files changed, 17 insertions, 7 deletions
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp
index adb798eec..f1f7e3846 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.cpp
+++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp
@@ -40,5 +40,5 @@ void FacebookPlugin::requestUpload()
{
FacebookManager *instance = FacebookManager::instance();
if (instance->loggedIn())
- instance->sendDive();
+ instance->sendDiveInit();
}
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
index ab79c8731..bfe563384 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -41,6 +41,7 @@ FacebookManager::FacebookManager(QObject *parent) :
QObject(parent),
manager(new QNetworkAccessManager(this))
{
+ connect(this, &FacebookManager::albumIdReceived, this, &FacebookManager::sendDiveToAlbum);
}
static QString graphApi = QStringLiteral("https://graph.facebook.com/v2.10/");
@@ -190,7 +191,7 @@ QPixmap FacebookManager::grabProfilePixmap()
/* 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()
+void FacebookManager::sendDiveInit()
{
SocialNetworkDialog dialog(qApp->activeWindow());
if (dialog.exec() != QDialog::Accepted)
@@ -201,12 +202,16 @@ void FacebookManager::sendDive()
fbInfo.profileData = grabProfilePixmap();
fbInfo.albumId = QString(); // request Album Id wil handle that.
+ // will emit albumIdReceived, that's connected to sendDiveToAlbum
requestAlbumId();
+}
- QUrl url(graphApi + QString(prefs.facebook.album_id) + "/photos?" +
+void FacebookManager::sendDiveToAlbum(const QString& album)
+{
+ QUrl url(graphApi + album + "/photos?" +
"&access_token=" + QString(prefs.facebook.access_token) +
"&source=image" +
- "&message=" + dialog.text().replace("&quot;", "%22"));
+ "&message=" + fbInfo.bodyText.replace("&quot;", "%22"));
QNetworkRequest request(url);
@@ -222,11 +227,11 @@ void FacebookManager::sendDive()
data.append("Content-Disposition: form-data; name=\"uploaded\"; filename=\"" + QString::number(qrand()) + ".png\"\r\n");
data.append("Content-Type: image/jpeg\r\n\r\n"); //data type
- QPixmap pix = grabProfilePixmap();
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
- pix.save(&buffer, "PNG");
+ fbInfo.profileData.save(&buffer, "PNG");
+
data.append(bytes); //let's read the file
data.append("\r\n");
data.append("--" + bound + "--\r\n"); //closing boundary according to rfc 1867
@@ -260,6 +265,8 @@ void FacebookManager::uploadFinished()
+ response),
QMessageBox::Ok);
}
+
+ emit sendDiveFinished();
}
FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), ui(new Ui::FacebookConnectWidget) {
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
index 4bc868835..226100148 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
@@ -41,11 +41,14 @@ signals:
void justLoggedIn(bool triggererd);
void justLoggedOut(bool triggered);
void albumIdReceived(const QString& albumId);
+ void sendDiveFinished();
public slots:
void tryLogin(const QUrl& loginResponse);
void logout();
- void sendDive();
+ void sendDiveInit();
+ void sendDiveToAlbum(const QString& album);
+
void uploadFinished();
void albumListReceived();
void userIdReceived();