aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-12-23 20:56:51 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-24 06:37:58 -0800
commit5aa9fc6fe76837181d523bad768209556dfca90e (patch)
tree64e3729d194381e168283e94bfaa42ce24b7b61d /qt-ui
parent9a2f836b1a8dc70772a85bb91b171889157b3425 (diff)
downloadsubsurface-5aa9fc6fe76837181d523bad768209556dfca90e.tar.gz
Get and save the UserID for use with Facebook.
Next: Publish something with the Graph API. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/preferences.cpp20
-rw-r--r--qt-ui/preferences.h2
2 files changed, 21 insertions, 1 deletions
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index 11264b2b4..76b35c1e7 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -8,7 +8,10 @@
#include <QShortcut>
#include <QNetworkProxy>
#include <QNetworkCookieJar>
+#include <QNetworkReply>
#include <QWebView>
+#include <QJsonDocument>
+
static QString facebookConnectUrl =
"https://www.facebook.com/dialog/oauth?"
@@ -76,11 +79,28 @@ void PreferencesDialog::facebookLoginResponse(const QUrl &url)
settings.beginGroup("WebApps");
settings.beginGroup("Facebook");
settings.setValue("ConnectToken", securityToken);
+
+ QNetworkAccessManager *getUserID = new QNetworkAccessManager();
+ connect(getUserID, &QNetworkAccessManager::finished, this, &PreferencesDialog::facebookGetUserId);
+ getUserID->get(QNetworkRequest(QUrl("https://graph.facebook.com/me?fields=id&access_token=" + securityToken)));
+
ui.facebookWebView->setHtml("We need a better 'you re connected' page. but, YEY. ");
ui.btnDisconnectFacebook->show();
}
}
+void PreferencesDialog::facebookGetUserId(QNetworkReply *reply)
+{
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
+ QJsonObject obj = jsonDoc.object();
+ if (obj.keys().contains("id")){
+ QSettings s;
+ s.beginGroup("WebApps");
+ s.beginGroup("Facebook");
+ s.setValue("UserId", obj.value("id").toVariant());
+ }
+}
+
void PreferencesDialog::facebookDisconnect()
{
QSettings settings;
diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h
index 1db95a91e..d455f536c 100644
--- a/qt-ui/preferences.h
+++ b/qt-ui/preferences.h
@@ -32,7 +32,7 @@ slots:
void on_btnUseDefaultFile_toggled(bool toggle);
void facebookLoginResponse(const QUrl& url);
void facebookDisconnect();
-
+ void facebookGetUserId(QNetworkReply *reply);
private:
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
void setUiFromPrefs();