[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>
This commit is contained in:
Tomaz Canabrava 2017-09-29 11:54:12 +02:00 committed by Dirk Hohndel
parent 7b8832bc0b
commit 475dfe1194
2 changed files with 16 additions and 12 deletions

View file

@ -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);
}

View file

@ -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();