aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2017-09-29 11:54:12 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-09-29 12:57:28 -0700
commit475dfe1194d63ce4c081987a13076198bfcdd820 (patch)
treefed87589549bdb491c057819672fce69c8cca62f
parent7b8832bc0ba1d287baae247307d3352da1371b55 (diff)
downloadsubsurface-475dfe1194d63ce4c081987a13076198bfcdd820.tar.gz
[Facebook] Use only one Network Manager
Fixes quite a few memory leaks. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--desktop-widgets/plugins/facebook/facebookconnectwidget.cpp22
-rw-r--r--desktop-widgets/plugins/facebook/facebookconnectwidget.h6
2 files changed, 16 insertions, 12 deletions
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
index de0fcb682..7d77e49bb 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -47,13 +47,19 @@ FacebookManager *FacebookManager::instance()
return self;
}
-FacebookManager::FacebookManager(QObject *parent) : QObject(parent)
+FacebookManager::FacebookManager(QObject *parent) :
+ QObject(parent),
+ manager(new QNetworkAccessManager(this))
{
- albumListUrl = QUrl("https://graph.facebook.com/me/albums?access_token=" + QString(prefs.facebook.access_token));
}
static QString graphApi = QStringLiteral("https://graph.facebook.com/v2.10/");
+QUrl FacebookManager::albumListUrl()
+{
+ return QUrl("https://graph.facebook.com/me/albums?access_token=" + QString(prefs.facebook.access_token));
+}
+
QUrl FacebookManager::connectUrl() {
return QUrl("https://www.facebook.com/dialog/oauth?"
"client_id=427722490709000"
@@ -99,8 +105,7 @@ void FacebookManager::logout()
void FacebookManager::requestAlbumId()
{
- QNetworkAccessManager *manager = new QNetworkAccessManager();
- QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl));
+ QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl()));
connect(reply, &QNetworkReply::finished, this, &FacebookManager::albumListReceived);
}
@@ -129,10 +134,9 @@ void FacebookManager::createFacebookAlbum()
params.addQueryItem("description", "Subsurface Album");
params.addQueryItem("privacy", "{'value': 'SELF'}");
- QNetworkRequest request(albumListUrl);
+ QNetworkRequest request(albumListUrl());
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
- QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->post(request, params.query().toLocal8Bit());
connect(reply, &QNetworkReply::finished, this, &FacebookManager::facebookAlbumCreated);
}
@@ -152,8 +156,7 @@ void FacebookManager::facebookAlbumCreated()
void FacebookManager::requestUserId()
{
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
- QNetworkAccessManager *getUserID = new QNetworkAccessManager();
- QNetworkReply *reply = getUserID->get(QNetworkRequest(userIdRequest));
+ QNetworkReply *reply = manager->get(QNetworkRequest(userIdRequest));
QEventLoop loop;
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
@@ -197,7 +200,6 @@ void FacebookManager::sendDive()
"&source=image" +
"&message=" + dialog.text().replace("&quot;", "%22"));
- QNetworkAccessManager *am = new QNetworkAccessManager(this);
QNetworkRequest request(url);
QString bound="margin";
@@ -217,7 +219,7 @@ void FacebookManager::sendDive()
request.setRawHeader(QByteArray("Content-Type"),QString("multipart/form-data; boundary=" + bound).toLocal8Bit());
request.setRawHeader(QByteArray("Content-Length"), QString::number(data.length()).toLocal8Bit());
- QNetworkReply *reply = am->post(request,data);
+ QNetworkReply *reply = manager->post(request,data);
connect(reply, &QNetworkReply::finished, this, &FacebookManager::uploadFinished);
}
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
index c47f4be66..e39286832 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
@@ -10,6 +10,7 @@ class QWebEngineView;
class QWebView;
#endif
class QNetworkReply;
+class QNetworkAccessManager;
namespace Ui {
class FacebookConnectWidget;
@@ -24,6 +25,7 @@ public:
void requestAlbumId();
void requestUserId();
QUrl connectUrl();
+ QUrl albumListUrl();
bool loggedIn();
signals:
void justLoggedIn(bool triggererd);
@@ -41,12 +43,12 @@ public slots:
private:
explicit FacebookManager(QObject *parent = 0);
QString albumName;
- QUrl albumListUrl;
+ QNetworkAccessManager *manager;
};
class FacebookConnectWidget : public QDialog {
- Q_OBJECT
+ Q_OBJECT
public:
explicit FacebookConnectWidget(QWidget* parent = 0);
void facebookLoggedIn();