mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
[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:
parent
7b8832bc0b
commit
475dfe1194
2 changed files with 16 additions and 12 deletions
|
@ -47,13 +47,19 @@ FacebookManager *FacebookManager::instance()
|
||||||
return self;
|
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/");
|
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() {
|
QUrl FacebookManager::connectUrl() {
|
||||||
return QUrl("https://www.facebook.com/dialog/oauth?"
|
return QUrl("https://www.facebook.com/dialog/oauth?"
|
||||||
"client_id=427722490709000"
|
"client_id=427722490709000"
|
||||||
|
@ -99,8 +105,7 @@ void FacebookManager::logout()
|
||||||
|
|
||||||
void FacebookManager::requestAlbumId()
|
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);
|
connect(reply, &QNetworkReply::finished, this, &FacebookManager::albumListReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,10 +134,9 @@ void FacebookManager::createFacebookAlbum()
|
||||||
params.addQueryItem("description", "Subsurface Album");
|
params.addQueryItem("description", "Subsurface Album");
|
||||||
params.addQueryItem("privacy", "{'value': 'SELF'}");
|
params.addQueryItem("privacy", "{'value': 'SELF'}");
|
||||||
|
|
||||||
QNetworkRequest request(albumListUrl);
|
QNetworkRequest request(albumListUrl());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
|
||||||
|
|
||||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
|
||||||
QNetworkReply *reply = manager->post(request, params.query().toLocal8Bit());
|
QNetworkReply *reply = manager->post(request, params.query().toLocal8Bit());
|
||||||
connect(reply, &QNetworkReply::finished, this, &FacebookManager::facebookAlbumCreated);
|
connect(reply, &QNetworkReply::finished, this, &FacebookManager::facebookAlbumCreated);
|
||||||
}
|
}
|
||||||
|
@ -152,8 +156,7 @@ void FacebookManager::facebookAlbumCreated()
|
||||||
void FacebookManager::requestUserId()
|
void FacebookManager::requestUserId()
|
||||||
{
|
{
|
||||||
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
|
QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token=" + QString(prefs.facebook.access_token));
|
||||||
QNetworkAccessManager *getUserID = new QNetworkAccessManager();
|
QNetworkReply *reply = manager->get(QNetworkRequest(userIdRequest));
|
||||||
QNetworkReply *reply = getUserID->get(QNetworkRequest(userIdRequest));
|
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
|
@ -197,7 +200,6 @@ void FacebookManager::sendDive()
|
||||||
"&source=image" +
|
"&source=image" +
|
||||||
"&message=" + dialog.text().replace(""", "%22"));
|
"&message=" + dialog.text().replace(""", "%22"));
|
||||||
|
|
||||||
QNetworkAccessManager *am = new QNetworkAccessManager(this);
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
|
|
||||||
QString bound="margin";
|
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-Type"),QString("multipart/form-data; boundary=" + bound).toLocal8Bit());
|
||||||
request.setRawHeader(QByteArray("Content-Length"), QString::number(data.length()).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);
|
connect(reply, &QNetworkReply::finished, this, &FacebookManager::uploadFinished);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ class QWebEngineView;
|
||||||
class QWebView;
|
class QWebView;
|
||||||
#endif
|
#endif
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FacebookConnectWidget;
|
class FacebookConnectWidget;
|
||||||
|
@ -24,6 +25,7 @@ public:
|
||||||
void requestAlbumId();
|
void requestAlbumId();
|
||||||
void requestUserId();
|
void requestUserId();
|
||||||
QUrl connectUrl();
|
QUrl connectUrl();
|
||||||
|
QUrl albumListUrl();
|
||||||
bool loggedIn();
|
bool loggedIn();
|
||||||
signals:
|
signals:
|
||||||
void justLoggedIn(bool triggererd);
|
void justLoggedIn(bool triggererd);
|
||||||
|
@ -41,12 +43,12 @@ public slots:
|
||||||
private:
|
private:
|
||||||
explicit FacebookManager(QObject *parent = 0);
|
explicit FacebookManager(QObject *parent = 0);
|
||||||
QString albumName;
|
QString albumName;
|
||||||
QUrl albumListUrl;
|
QNetworkAccessManager *manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class FacebookConnectWidget : public QDialog {
|
class FacebookConnectWidget : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FacebookConnectWidget(QWidget* parent = 0);
|
explicit FacebookConnectWidget(QWidget* parent = 0);
|
||||||
void facebookLoggedIn();
|
void facebookLoggedIn();
|
||||||
|
|
Loading…
Add table
Reference in a new issue