mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Save and restore Facebook Prefs.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5aa9fc6fe7
commit
14a858cf2a
4 changed files with 77 additions and 12 deletions
7
pref.h
7
pref.h
|
@ -18,6 +18,12 @@ typedef struct
|
|||
double phe_threshold;
|
||||
} partial_pressure_graphs_t;
|
||||
|
||||
typedef struct {
|
||||
char *user_id;
|
||||
char *access_token;
|
||||
char *album_name;
|
||||
} facebook_prefs_t;
|
||||
|
||||
struct preferences {
|
||||
const char *divelist_font;
|
||||
const char *default_filename;
|
||||
|
@ -71,6 +77,7 @@ struct preferences {
|
|||
int pscr_ratio; // dump ratio times 1000
|
||||
bool show_pictures_in_profile;
|
||||
bool use_default_file;
|
||||
facebook_prefs_t facebook;
|
||||
};
|
||||
enum unit_system_values {
|
||||
METRIC,
|
||||
|
|
|
@ -45,10 +45,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
|
|||
settings.beginGroup("Facebook");
|
||||
if(settings.allKeys().contains("ConnectToken")){
|
||||
ui.facebookWebView->setHtml("You are connected on Facebook, yey.");
|
||||
ui.btnDisconnectFacebook->show();
|
||||
ui.fbConnected->show();
|
||||
} else {
|
||||
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
||||
ui.btnDisconnectFacebook->hide();
|
||||
ui.fbConnected->hide();
|
||||
}
|
||||
|
||||
connect(ui.facebookWebView, &QWebView::urlChanged, this, &PreferencesDialog::facebookLoginResponse);
|
||||
|
@ -83,9 +83,11 @@ void PreferencesDialog::facebookLoginResponse(const QUrl &url)
|
|||
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();
|
||||
ui.fbConnected->show();
|
||||
|
||||
// only enable when we get the reply for the user_id.
|
||||
setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,6 +101,7 @@ void PreferencesDialog::facebookGetUserId(QNetworkReply *reply)
|
|||
s.beginGroup("Facebook");
|
||||
s.setValue("UserId", obj.value("id").toVariant());
|
||||
}
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
void PreferencesDialog::facebookDisconnect()
|
||||
|
@ -109,7 +112,7 @@ void PreferencesDialog::facebookDisconnect()
|
|||
settings.remove("ConnectToken");
|
||||
ui.facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
|
||||
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
||||
ui.btnDisconnectFacebook->hide();
|
||||
ui.fbConnected->hide();
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,10 +215,11 @@ void PreferencesDialog::setUiFromPrefs()
|
|||
s.beginGroup("WebApps");
|
||||
s.beginGroup("Facebook");
|
||||
if(s.allKeys().contains("ConnectToken")){
|
||||
ui.btnDisconnectFacebook->show();
|
||||
ui.fbConnected->show();
|
||||
} else {
|
||||
ui.btnDisconnectFacebook->hide();
|
||||
ui.fbConnected->hide();
|
||||
}
|
||||
ui.facebookAlbum->setText(s.value("Album", "subsurface").toString());
|
||||
}
|
||||
|
||||
void PreferencesDialog::restorePrefs()
|
||||
|
@ -361,6 +365,13 @@ void PreferencesDialog::syncSettings()
|
|||
s.setValue("proxy_pass", ui.proxyPassword->text());
|
||||
s.endGroup();
|
||||
|
||||
// Facebook
|
||||
s.beginGroup("WebApps");
|
||||
s.beginGroup("Facebook");
|
||||
s.setValue("Album", ui.facebookAlbum->text());
|
||||
s.endGroup();
|
||||
s.endGroup();
|
||||
|
||||
loadSettings();
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
@ -465,6 +476,15 @@ void PreferencesDialog::loadSettings()
|
|||
GET_TXT("proxy_user", proxy_user);
|
||||
GET_TXT("proxy_pass", proxy_pass);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("WebApps");
|
||||
s.beginGroup("Facebook");
|
||||
GET_TXT("UserId", facebook.user_id);
|
||||
GET_TXT("ConnectToken", facebook.access_token);
|
||||
GET_TXT("AlbumName", facebook.album_name);
|
||||
s.endGroup();
|
||||
s.endGroup();
|
||||
qDebug() << prefs.facebook.user_id << prefs.facebook.access_token << prefs.facebook.album_name;
|
||||
}
|
||||
|
||||
void PreferencesDialog::buttonClicked(QAbstractButton *button)
|
||||
|
|
|
@ -983,10 +983,43 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnDisconnectFacebook">
|
||||
<property name="text">
|
||||
<string>Disconnect from facebook</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="fbConnected" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="connectedLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_26">
|
||||
<property name="text">
|
||||
<string>Facebook Album for Subsurface Uploads</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="facebookAlbum"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnDisconnectFacebook">
|
||||
<property name="text">
|
||||
<string>Disconnect from facebook</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -48,7 +48,12 @@ struct preferences default_prefs = {
|
|||
.o2consumption = 1000,
|
||||
.pscr_ratio = 100,
|
||||
.show_pictures_in_profile = true,
|
||||
.tankbar = false
|
||||
.tankbar = false,
|
||||
.facebook = {
|
||||
.user_id = "",
|
||||
.album_name = "subsurface",
|
||||
.access_token = ""
|
||||
}
|
||||
};
|
||||
|
||||
int run_survey;
|
||||
|
|
Loading…
Add table
Reference in a new issue