mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 22:35:27 +00:00
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
cc69e6ffa2
commit
a7e148c0a8
3 changed files with 43 additions and 7 deletions
|
@ -7,8 +7,15 @@
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
|
#include <QNetworkCookieJar>
|
||||||
#include <QWebView>
|
#include <QWebView>
|
||||||
|
|
||||||
|
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()
|
PreferencesDialog *PreferencesDialog::instance()
|
||||||
{
|
{
|
||||||
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
||||||
|
@ -28,21 +35,20 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
|
||||||
ui.proxyType->setCurrentIndex(-1);
|
ui.proxyType->setCurrentIndex(-1);
|
||||||
|
|
||||||
// Facebook stuff:
|
// 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;
|
QSettings settings;
|
||||||
settings.beginGroup("WebApps");
|
settings.beginGroup("WebApps");
|
||||||
settings.beginGroup("Facebook");
|
settings.beginGroup("Facebook");
|
||||||
if(settings.allKeys().contains("ConnectToken")){
|
if(settings.allKeys().contains("ConnectToken")){
|
||||||
ui.facebookWebView->setHtml("You are connected on Facebook, yey.");
|
ui.facebookWebView->setHtml("You are connected on Facebook, yey.");
|
||||||
|
ui.btnDisconnectFacebook->show();
|
||||||
} else {
|
} else {
|
||||||
ui.facebookWebView->setUrl(urlLogin);
|
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
||||||
|
ui.btnDisconnectFacebook->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui.facebookWebView, &QWebView::urlChanged, this, &PreferencesDialog::facebookLoginResponse);
|
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.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int)));
|
||||||
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
||||||
|
@ -70,9 +76,22 @@ void PreferencesDialog::facebookLoginResponse(const QUrl &url)
|
||||||
settings.beginGroup("Facebook");
|
settings.beginGroup("Facebook");
|
||||||
settings.setValue("ConnectToken", securityToken);
|
settings.setValue("ConnectToken", securityToken);
|
||||||
ui.facebookWebView->setHtml("We need a better 'you re connected' page. but, YEY. ");
|
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; }" : ""
|
#define DANGER_GF (gf > 100) ? "* { color: red; }" : ""
|
||||||
void PreferencesDialog::gflowChanged(int gf)
|
void PreferencesDialog::gflowChanged(int gf)
|
||||||
{
|
{
|
||||||
|
@ -168,6 +187,14 @@ void PreferencesDialog::setUiFromPrefs()
|
||||||
ui.proxyPassword->setText(prefs.proxy_pass);
|
ui.proxyPassword->setText(prefs.proxy_pass);
|
||||||
ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type));
|
ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type));
|
||||||
ui.btnUseDefaultFile->setChecked(prefs.use_default_file);
|
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()
|
void PreferencesDialog::restorePrefs()
|
||||||
|
|
|
@ -31,6 +31,8 @@ slots:
|
||||||
void proxyType_changed(int idx);
|
void proxyType_changed(int idx);
|
||||||
void on_btnUseDefaultFile_toggled(bool toggle);
|
void on_btnUseDefaultFile_toggled(bool toggle);
|
||||||
void facebookLoginResponse(const QUrl& url);
|
void facebookLoginResponse(const QUrl& url);
|
||||||
|
void facebookDisconnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
void setUiFromPrefs();
|
void setUiFromPrefs();
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>562</width>
|
<width>924</width>
|
||||||
<height>718</height>
|
<height>718</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -972,7 +972,7 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_6">
|
<widget class="QWidget" name="page_6">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWebView" name="facebookWebView">
|
<widget class="QWebView" name="facebookWebView">
|
||||||
<property name="url">
|
<property name="url">
|
||||||
|
@ -982,6 +982,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnDisconnectFacebook">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disconnect from facebook</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
Loading…
Add table
Reference in a new issue