From a7e148c0a8e121aa677e52827d5d4cfbdd4ebea7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 23 Dec 2014 19:29:00 -0200 Subject: [PATCH] Disconnect from facebook manually. Added a button to disconnect from facebook. This clears the webview cookies so it correctly disconnects us from facebook, and clears the access token. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/preferences.cpp | 37 ++++++++++++++++++++++++++++++++----- qt-ui/preferences.h | 2 ++ qt-ui/preferences.ui | 11 +++++++++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index b57040c83..70fbe126e 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -7,8 +7,15 @@ #include #include #include +#include #include +static QString facebookConnectUrl = + "https://www.facebook.com/dialog/oauth?" + "client_id=427722490709000" + "&redirect_uri=http://www.facebook.com/connect/login_success.html" + "&response_type=token"; + PreferencesDialog *PreferencesDialog::instance() { static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance()); @@ -28,21 +35,20 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial ui.proxyType->setCurrentIndex(-1); // Facebook stuff: - QUrl urlLogin("https://www.facebook.com/dialog/oauth?" - "client_id=427722490709000" - "&redirect_uri=http://www.facebook.com/connect/login_success.html" - "&response_type=token"); QSettings settings; settings.beginGroup("WebApps"); settings.beginGroup("Facebook"); if(settings.allKeys().contains("ConnectToken")){ ui.facebookWebView->setHtml("You are connected on Facebook, yey."); + ui.btnDisconnectFacebook->show(); } else { - ui.facebookWebView->setUrl(urlLogin); + ui.facebookWebView->setUrl(QUrl(facebookConnectUrl)); + ui.btnDisconnectFacebook->hide(); } connect(ui.facebookWebView, &QWebView::urlChanged, this, &PreferencesDialog::facebookLoginResponse); + connect(ui.btnDisconnectFacebook, &QPushButton::clicked, this, &PreferencesDialog::facebookDisconnect); connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); @@ -70,9 +76,22 @@ void PreferencesDialog::facebookLoginResponse(const QUrl &url) settings.beginGroup("Facebook"); settings.setValue("ConnectToken", securityToken); ui.facebookWebView->setHtml("We need a better 'you re connected' page. but, YEY. "); + ui.btnDisconnectFacebook->show(); } } +void PreferencesDialog::facebookDisconnect() +{ + QSettings settings; + settings.beginGroup("WebApps"); + settings.beginGroup("Facebook"); + settings.remove("ConnectToken"); + ui.facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar()); + ui.facebookWebView->setUrl(QUrl(facebookConnectUrl)); + ui.btnDisconnectFacebook->hide(); +} + + #define DANGER_GF (gf > 100) ? "* { color: red; }" : "" void PreferencesDialog::gflowChanged(int gf) { @@ -168,6 +187,14 @@ void PreferencesDialog::setUiFromPrefs() ui.proxyPassword->setText(prefs.proxy_pass); ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); ui.btnUseDefaultFile->setChecked(prefs.use_default_file); + + s.beginGroup("WebApps"); + s.beginGroup("Facebook"); + if(s.allKeys().contains("ConnectToken")){ + ui.btnDisconnectFacebook->show(); + } else { + ui.btnDisconnectFacebook->hide(); + } } void PreferencesDialog::restorePrefs() diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h index d7755bad4..1db95a91e 100644 --- a/qt-ui/preferences.h +++ b/qt-ui/preferences.h @@ -31,6 +31,8 @@ slots: void proxyType_changed(int idx); void on_btnUseDefaultFile_toggled(bool toggle); void facebookLoginResponse(const QUrl& url); + void facebookDisconnect(); + private: explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); void setUiFromPrefs(); diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui index 9611b49d9..b9f8bdb66 100644 --- a/qt-ui/preferences.ui +++ b/qt-ui/preferences.ui @@ -6,7 +6,7 @@ 0 0 - 562 + 924 718 @@ -972,7 +972,7 @@ - + @@ -982,6 +982,13 @@ + + + + Disconnect from facebook + + +