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;
|
double phe_threshold;
|
||||||
} partial_pressure_graphs_t;
|
} partial_pressure_graphs_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *user_id;
|
||||||
|
char *access_token;
|
||||||
|
char *album_name;
|
||||||
|
} facebook_prefs_t;
|
||||||
|
|
||||||
struct preferences {
|
struct preferences {
|
||||||
const char *divelist_font;
|
const char *divelist_font;
|
||||||
const char *default_filename;
|
const char *default_filename;
|
||||||
|
@ -71,6 +77,7 @@ struct preferences {
|
||||||
int pscr_ratio; // dump ratio times 1000
|
int pscr_ratio; // dump ratio times 1000
|
||||||
bool show_pictures_in_profile;
|
bool show_pictures_in_profile;
|
||||||
bool use_default_file;
|
bool use_default_file;
|
||||||
|
facebook_prefs_t facebook;
|
||||||
};
|
};
|
||||||
enum unit_system_values {
|
enum unit_system_values {
|
||||||
METRIC,
|
METRIC,
|
||||||
|
|
|
@ -45,10 +45,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
|
||||||
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();
|
ui.fbConnected->show();
|
||||||
} else {
|
} else {
|
||||||
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
||||||
ui.btnDisconnectFacebook->hide();
|
ui.fbConnected->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui.facebookWebView, &QWebView::urlChanged, this, &PreferencesDialog::facebookLoginResponse);
|
connect(ui.facebookWebView, &QWebView::urlChanged, this, &PreferencesDialog::facebookLoginResponse);
|
||||||
|
@ -83,9 +83,11 @@ void PreferencesDialog::facebookLoginResponse(const QUrl &url)
|
||||||
QNetworkAccessManager *getUserID = new QNetworkAccessManager();
|
QNetworkAccessManager *getUserID = new QNetworkAccessManager();
|
||||||
connect(getUserID, &QNetworkAccessManager::finished, this, &PreferencesDialog::facebookGetUserId);
|
connect(getUserID, &QNetworkAccessManager::finished, this, &PreferencesDialog::facebookGetUserId);
|
||||||
getUserID->get(QNetworkRequest(QUrl("https://graph.facebook.com/me?fields=id&access_token=" + securityToken)));
|
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.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.beginGroup("Facebook");
|
||||||
s.setValue("UserId", obj.value("id").toVariant());
|
s.setValue("UserId", obj.value("id").toVariant());
|
||||||
}
|
}
|
||||||
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreferencesDialog::facebookDisconnect()
|
void PreferencesDialog::facebookDisconnect()
|
||||||
|
@ -109,7 +112,7 @@ void PreferencesDialog::facebookDisconnect()
|
||||||
settings.remove("ConnectToken");
|
settings.remove("ConnectToken");
|
||||||
ui.facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
|
ui.facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
|
||||||
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
ui.facebookWebView->setUrl(QUrl(facebookConnectUrl));
|
||||||
ui.btnDisconnectFacebook->hide();
|
ui.fbConnected->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,10 +215,11 @@ void PreferencesDialog::setUiFromPrefs()
|
||||||
s.beginGroup("WebApps");
|
s.beginGroup("WebApps");
|
||||||
s.beginGroup("Facebook");
|
s.beginGroup("Facebook");
|
||||||
if(s.allKeys().contains("ConnectToken")){
|
if(s.allKeys().contains("ConnectToken")){
|
||||||
ui.btnDisconnectFacebook->show();
|
ui.fbConnected->show();
|
||||||
} else {
|
} else {
|
||||||
ui.btnDisconnectFacebook->hide();
|
ui.fbConnected->hide();
|
||||||
}
|
}
|
||||||
|
ui.facebookAlbum->setText(s.value("Album", "subsurface").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreferencesDialog::restorePrefs()
|
void PreferencesDialog::restorePrefs()
|
||||||
|
@ -361,6 +365,13 @@ void PreferencesDialog::syncSettings()
|
||||||
s.setValue("proxy_pass", ui.proxyPassword->text());
|
s.setValue("proxy_pass", ui.proxyPassword->text());
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
// Facebook
|
||||||
|
s.beginGroup("WebApps");
|
||||||
|
s.beginGroup("Facebook");
|
||||||
|
s.setValue("Album", ui.facebookAlbum->text());
|
||||||
|
s.endGroup();
|
||||||
|
s.endGroup();
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
}
|
}
|
||||||
|
@ -465,6 +476,15 @@ void PreferencesDialog::loadSettings()
|
||||||
GET_TXT("proxy_user", proxy_user);
|
GET_TXT("proxy_user", proxy_user);
|
||||||
GET_TXT("proxy_pass", proxy_pass);
|
GET_TXT("proxy_pass", proxy_pass);
|
||||||
s.endGroup();
|
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)
|
void PreferencesDialog::buttonClicked(QAbstractButton *button)
|
||||||
|
|
|
@ -982,6 +982,34 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<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>
|
<item>
|
||||||
<widget class="QPushButton" name="btnDisconnectFacebook">
|
<widget class="QPushButton" name="btnDisconnectFacebook">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -990,6 +1018,11 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -48,7 +48,12 @@ struct preferences default_prefs = {
|
||||||
.o2consumption = 1000,
|
.o2consumption = 1000,
|
||||||
.pscr_ratio = 100,
|
.pscr_ratio = 100,
|
||||||
.show_pictures_in_profile = true,
|
.show_pictures_in_profile = true,
|
||||||
.tankbar = false
|
.tankbar = false,
|
||||||
|
.facebook = {
|
||||||
|
.user_id = "",
|
||||||
|
.album_name = "subsurface",
|
||||||
|
.access_token = ""
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int run_survey;
|
int run_survey;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue