summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-12-23 21:45:06 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-12-24 06:38:12 -0800
commit14a858cf2a9e9dfd113dad049625bdb055830478 (patch)
tree3dbd3d00748444e5443d6267ecbba2e179393784
parent5aa9fc6fe76837181d523bad768209556dfca90e (diff)
downloadsubsurface-14a858cf2a9e9dfd113dad049625bdb055830478.tar.gz
Save and restore Facebook Prefs.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--pref.h7
-rw-r--r--qt-ui/preferences.cpp34
-rw-r--r--qt-ui/preferences.ui41
-rw-r--r--subsurfacestartup.c7
4 files changed, 77 insertions, 12 deletions
diff --git a/pref.h b/pref.h
index 733a194bf..16336f22f 100644
--- a/pref.h
+++ b/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,
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index 76b35c1e7..51a1d3567 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -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)
diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui
index b9f8bdb66..a89dde894 100644
--- a/qt-ui/preferences.ui
+++ b/qt-ui/preferences.ui
@@ -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>
diff --git a/subsurfacestartup.c b/subsurfacestartup.c
index 618e942f3..f63f4e7b2 100644
--- a/subsurfacestartup.c
+++ b/subsurfacestartup.c
@@ -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;