With this patch series facebook is back at work, yey.

Beware that not eveyrthing is complete and we still need to manually copy
things to it's correct place.

The facebook now is a plugin ( wich simplifies some things, and makes a few
things more complex ), so after build, if you run subsurface you won't
notice anything different.

create a folder named plugins near the executable and copy the build/
desktop-widgets/plugins/facebook/*.so to it, things should now work,
there will be a new Menu item named 'Share on' with the options that the
plugin gives us.

works: connect, disconnect, share.
From 91c14ba6c95ee9fa279dd93c4e0268637eb58a0a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 10:33:29 -0200
Subject: [PATCH 1/6] Convert most of the old code for FacebookPlugin to the
 new System

It should still not work correctly - but the plugin should be almost
ready - I'll do some papercuts on the next few commits.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 desktop-widgets/plugins/facebook/CMakeLists.txt    |   3 +-
 .../plugins/facebook/facebookconnectwidget.cpp     | 331 +++++++++++++++++++++
 .../plugins/facebook/facebookconnectwidget.h       |  61 ++++
 .../plugins/facebook/facebookconnectwidget.ui      | 104 +++++++
 .../plugins/facebook/socialnetworksdialog.ui       | 184 ++++++++++++
 desktop-widgets/socialnetworksdialog.ui            | 184 ------------
 6 files changed, 682 insertions(+), 185 deletions(-)
 create mode 100644 desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
 create mode 100644 desktop-widgets/plugins/facebook/facebookconnectwidget.h
 create mode 100644 desktop-widgets/plugins/facebook/facebookconnectwidget.ui
 create mode 100644 desktop-widgets/plugins/facebook/socialnetworksdialog.ui
 delete mode 100644 desktop-widgets/socialnetworksdialog.ui

diff --git a/desktop-widgets/plugins/facebook/CMakeLists.txt b/desktop-widgets/plugins/facebook/CMakeLists.txt
index 8628bd0..82a6c77 100644
--- a/desktop-widgets/plugins/facebook/CMakeLists.txt
+++ b/desktop-widgets/plugins/facebook/CMakeLists.txt
@@ -1,4 +1,5 @@
-set(FACEBOOK_PLUGIN_SRCS facebook_integration.cpp)
+set(FACEBOOK_PLUGIN_SRCS facebook_integration.cpp facebookconnectwidget.cpp)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 add_library(facebook_integration SHARED ${FACEBOOK_PLUGIN_SRCS})
 
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
new file mode 100644
index 0000000..0fba4a0
--- /dev/null
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -0,0 +1,331 @@
+#include "facebookconnectwidget.h"
+
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QNetworkReply>
+#include <QNetworkRequest>
+#include <QNetworkAccessManager>
+#include <QNetworkCookieJar>
+
+#include <QUrlQuery>
+#include <QEventLoop>
+#include <QHttpMultiPart>
+#include <QSettings>
+#include <QFile>
+#include <QBuffer>
+#include <QDebug>
+#include <QMessageBox>
+#include <QInputDialog>
+#include <QWebView>
+
+#include "mainwindow.h"
+#include "profile-widget/profilewidget2.h"
+#include "pref.h"
+#include "helpers.h"
+#include "ui_socialnetworksdialog.h"
+#include "ui_facebookconnectwidget.h"
+
+#if SAVE_FB_CREDENTIALS
+#define GET_TXT(name, field)                                             \
+	v = s.value(QString(name));                                      \
+	if (v.isValid())                                                 \
+		prefs.field = strdup(v.toString().toUtf8().constData()); \
+	else                                                             \
+		prefs.field = default_prefs.field
+#endif
+
+FacebookManager *FacebookManager::instance()
+{
+	static FacebookManager *self = new FacebookManager();
+	return self;
+}
+
+FacebookManager::FacebookManager(QObject *parent) : QObject(parent)
+{
+	sync();
+}
+
+QUrl FacebookManager::connectUrl() {
+	return QUrl("https://www.facebook.com/dialog/oauth?";
+		"client_id=427722490709000"
+		"&redirect_uri=http://www.facebook.com/connect/login_success.html";
+		"&response_type=token,granted_scopes"
+		"&display=popup"
+		"&scope=publish_actions,user_photos"
+	);
+}
+
+bool FacebookManager::loggedIn() {
+	return prefs.facebook.access_token != NULL;
+}
+
+void FacebookManager::sync()
+{
+#if SAVE_FB_CREDENTIALS
+	QSettings s;
+	s.beginGroup("WebApps");
+	s.beginGroup("Facebook");
+
+	QVariant v;
+	GET_TXT("ConnectToken", facebook.access_token);
+	GET_TXT("UserId", facebook.user_id);
+	GET_TXT("AlbumId", facebook.album_id);
+#endif
+}
+
+void FacebookManager::tryLogin(const QUrl& loginResponse)
+{
+	QString result = loginResponse.toString();
+	if (!result.contains("access_token"))
+		return;
+
+	if (result.contains("denied_scopes=publish_actions") || result.contains("denied_scopes=user_photos")) {
+		qDebug() << "user did not allow us access" << result;
+		return;
+	}
+	int from = result.indexOf("access_token=") + strlen("access_token=");
+	int to = result.indexOf("&expires_in");
+	QString securityToken = result.mid(from, to-from);
+
+#if SAVE_FB_CREDENTIALS
+	QSettings settings;
+	settings.beginGroup("WebApps");
+	settings.beginGroup("Facebook");
+	settings.setValue("ConnectToken", securityToken);
+	sync();
+#else
+	prefs.facebook.access_token = copy_string(securityToken.toUtf8().data());
+#endif
+	requestUserId();
+	sync();
+	emit justLoggedIn(true);
+}
+
+void FacebookManager::logout()
+{
+#if SAVE_FB_CREDENTIALS
+	QSettings settings;
+	settings.beginGroup("WebApps");
+	settings.beginGroup("Facebook");
+	settings.remove("ConnectToken");
+	settings.remove("UserId");
+	settings.remove("AlbumId");
+	sync();
+#else
+	free(prefs.facebook.access_token);
+	free(prefs.facebook.album_id);
+	free(prefs.facebook.user_id);
+	prefs.facebook.access_token = NULL;
+	prefs.facebook.album_id = NULL;
+	prefs.facebook.user_id = NULL;
+#endif
+	emit justLoggedOut(true);
+}
+
+void FacebookManager::requestAlbumId()
+{
+	QUrl albumListUrl("https://graph.facebook.com/me/albums?access_token="; + QString(prefs.facebook.access_token));
+	QNetworkAccessManager *manager = new QNetworkAccessManager();
+	QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl));
+
+	QEventLoop loop;
+	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+	loop.exec();
+
+#if SAVE_FB_CREDENTIALS
+	QSettings s;
+	s.beginGroup("WebApps");
+	s.beginGroup("Facebook");
+#endif
+
+	QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
+	QJsonArray albumObj = albumsDoc.object().value("data").toArray();
+	foreach(const QJsonValue &v, albumObj){
+		QJsonObject obj = v.toObject();
+		if (obj.value("name").toString() == albumName) {
+#if SAVE_FB_CREDENTIALS
+			s.setValue("AlbumId", obj.value("id").toString());
+#else
+			prefs.facebook.album_id = copy_string(obj.value("id").toString().toUtf8().data());
+#endif
+			return;
+		}
+	}
+
+	QUrlQuery params;
+	params.addQueryItem("name", albumName );
+	params.addQueryItem("description", "Subsurface Album");
+	params.addQueryItem("privacy", "{'value': 'SELF'}");
+
+	QNetworkRequest request(albumListUrl);
+	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
+	reply = manager->post(request, params.query().toLocal8Bit());
+	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+	loop.exec();
+
+	albumsDoc = QJsonDocument::fromJson(reply->readAll());
+	QJsonObject album = albumsDoc.object();
+	if (album.contains("id")) {
+#if SAVE_FB_CREDENTIALS
+		s.setValue("AlbumId", album.value("id").toString());
+#else
+		prefs.facebook.album_id = copy_string(album.value("id").toString().toUtf8().data());
+#endif
+		sync();
+		return;
+	}
+}
+
+void FacebookManager::requestUserId()
+{
+	QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token="; + QString(prefs.facebook.access_token));
+	QNetworkAccessManager *getUserID = new QNetworkAccessManager();
+	QNetworkReply *reply = getUserID->get(QNetworkRequest(userIdRequest));
+
+	QEventLoop loop;
+	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+	loop.exec();
+
+	QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
+	QJsonObject obj = jsonDoc.object();
+	if (obj.keys().contains("id")){
+#if SAVE_FB_CREDENTIALS
+		QSettings s;
+		s.beginGroup("WebApps");
+		s.beginGroup("Facebook");
+		s.setValue("UserId", obj.value("id").toVariant());
+#else
+		prefs.facebook.user_id = copy_string(obj.value("id").toString().toUtf8().data());
+#endif
+		return;
+	}
+}
+
+void FacebookManager::setDesiredAlbumName(const QString& a)
+{
+	albumName = a;
+}
+
+/* to be changed to export the currently selected dive as shown on the profile.
+ * Much much easier, and its also good to people do not select all the dives
+ * and send erroniously *all* of them to facebook. */
+void FacebookManager::sendDive()
+{
+	SocialNetworkDialog dialog(qApp->activeWindow());
+	if (dialog.exec() != QDialog::Accepted)
+		return;
+
+	setDesiredAlbumName(dialog.album());
+	requestAlbumId();
+
+	ProfileWidget2 *profile = MainWindow::instance()->graphics();
+	profile->setToolTipVisibile(false);
+	QPixmap pix = QPixmap::grabWidget(profile);
+	profile->setToolTipVisibile(true);
+	QByteArray bytes;
+	QBuffer buffer(&bytes);
+	buffer.open(QIODevice::WriteOnly);
+	pix.save(&buffer, "PNG");
+	QUrl url("https://graph.facebook.com/v2.2/"; + QString(prefs.facebook.album_id) + "/photos?" +
+		 "&access_token=" + QString(prefs.facebook.access_token) +
+		 "&source=image" +
+		 "&message=" + dialog.text().replace("&quot;", "%22"));
+
+	QNetworkAccessManager *am = new QNetworkAccessManager(this);
+	QNetworkRequest request(url);
+
+	QString bound="margin";
+
+	//according to rfc 1867 we need to put this string here:
+	QByteArray data(QString("--" + bound + "\r\n").toLocal8Bit());
+	data.append("Content-Disposition: form-data; name=\"action\"\r\n\r\n");
+	data.append("https://graph.facebook.com/v2.2/\r\n";);
+	data.append("--" + bound + "\r\n");   //according to rfc 1867
+	data.append("Content-Disposition: form-data; name=\"uploaded\"; filename=\"" + QString::number(qrand()) + ".png\"\r\n");  //name of the input is "uploaded" in my form, next one is a file name.
+	data.append("Content-Type: image/jpeg\r\n\r\n"); //data type
+	data.append(bytes);   //let's read the file
+	data.append("\r\n");
+	data.append("--" + bound + "--\r\n");  //closing boundary according to rfc 1867
+
+	request.setRawHeader(QString("Content-Type").toLocal8Bit(),QString("multipart/form-data; boundary=" + bound).toLocal8Bit());
+	request.setRawHeader(QString("Content-Length").toLocal8Bit(), QString::number(data.length()).toLocal8Bit());
+	QNetworkReply *reply = am->post(request,data);
+
+	QEventLoop loop;
+	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
+	loop.exec();
+
+	QByteArray response = reply->readAll();
+	QJsonDocument jsonDoc = QJsonDocument::fromJson(response);
+	QJsonObject obj = jsonDoc.object();
+	if (obj.keys().contains("id")){
+		QMessageBox::information(qApp->activeWindow(),
+			tr("Photo upload sucessfull"),
+			tr("Your dive profile was updated to Facebook."),
+		QMessageBox::Ok);
+	} else {
+		QMessageBox::information(qApp->activeWindow(),
+			tr("Photo upload failed"),
+			tr("Your dive profile was not updated to Facebook, \n "
+			   "please send the following to the developer. \n"
+			   + response),
+		QMessageBox::Ok);
+	}
+}
+
+FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), ui(new Ui::FacebookConnectWidget) {
+  	FacebookManager *fb = FacebookManager::instance();
+	facebookWebView = new QWebView(this);
+	ui->fbWebviewContainer->layout()->addWidget(facebookWebView);
+	if (fb->loggedIn()) {
+		facebookLoggedIn();
+	} else {
+		facebookDisconnect();
+	}
+	connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin);
+	connect(fb, &FacebookManager::justLoggedIn, this, &FacebookConnectWidget::facebookLoggedIn);
+}
+
+void FacebookConnectWidget::facebookLoggedIn()
+{
+	ui->fbWebviewContainer->hide();
+	ui->fbWebviewContainer->setEnabled(false);
+	ui->FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below"));
+}
+
+void FacebookConnectWidget::facebookDisconnect()
+{
+	// remove the connect/disconnect button
+	// and instead add the login view
+	ui->fbWebviewContainer->show();
+	ui->fbWebviewContainer->setEnabled(true);
+	ui->FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline"));
+	if (facebookWebView) {
+		facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
+		facebookWebView->setUrl(FacebookManager::instance()->connectUrl());
+	}
+}
+
+SocialNetworkDialog::SocialNetworkDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
+{
+
+}
+
+QString SocialNetworkDialog::name() const
+{
+	return _name;
+}
+
+QString SocialNetworkDialog::album() const
+{
+	return _album;
+}
+
+QString SocialNetworkDialog::text() const
+{
+	return _text;
+}
+
+
+
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
new file mode 100644
index 0000000..40e1027
--- /dev/null
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
@@ -0,0 +1,61 @@
+#ifndef FACEBOOKCONNECTWIDGET_H
+#define FACEBOOKCONNECTWIDGET_H
+
+#include <QDialog>
+class QWebView;
+namespace Ui {
+  class FacebookConnectWidget;
+}
+
+class FacebookManager : public QObject
+{
+	Q_OBJECT
+public:
+	static FacebookManager *instance();
+	void requestAlbumId();
+	void requestUserId();
+	void sync();
+	QUrl connectUrl();
+	bool loggedIn();
+signals:
+	void justLoggedIn(bool triggererd);
+	void justLoggedOut(bool triggered);
+
+public slots:
+	void tryLogin(const QUrl& loginResponse);
+	void logout();
+	void setDesiredAlbumName(const QString& albumName);
+	void sendDive();
+
+private:
+	explicit FacebookManager(QObject *parent = 0);
+	QString albumName;
+};
+
+
+class FacebookConnectWidget : public QDialog {
+  Q_OBJECT
+public:
+	explicit FacebookConnectWidget(QWidget* parent = 0);
+	void facebookLoggedIn();
+	void facebookDisconnect();
+private:
+	Ui::FacebookConnectWidget *ui;
+	QWebView *facebookWebView;
+};
+
+class SocialNetworkDialog : public QDialog {
+	Q_OBJECT
+public:
+	explicit SocialNetworkDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
+	QString album() const;
+	QString name() const;
+	QString text() const;
+	
+private:
+	QString _album;
+	QString _name;
+	QString _text;
+};
+
+#endif 
\ No newline at end of file
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.ui b/desktop-widgets/plugins/facebook/facebookconnectwidget.ui
new file mode 100644
index 0000000..e34dfb1
--- /dev/null
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.ui
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FacebookConnectWidget</class>
+ <widget class="QDialog" name="FacebookConnectWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>835</width>
+    <height>698</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Preferences</string>
+  </property>
+  <property name="windowIcon">
+   <iconset>
+    <normalon>:/subsurface-icon</normalon>
+   </iconset>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <property name="leftMargin">
+    <number>5</number>
+   </property>
+   <property name="topMargin">
+    <number>5</number>
+   </property>
+   <property name="rightMargin">
+    <number>5</number>
+   </property>
+   <property name="bottomMargin">
+    <number>5</number>
+   </property>
+   <item>
+    <layout class="QHBoxLayout" name="mainHorizontalLayout">
+     <item>
+      <widget class="QStackedWidget" name="stackedWidget">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="currentIndex">
+        <number>0</number>
+       </property>
+       <widget class="QWidget" name="facebook_page">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <layout class="QVBoxLayout" name="fbLayout" stretch="0">
+         <property name="spacing">
+          <number>5</number>
+         </property>
+         <property name="leftMargin">
+          <number>5</number>
+         </property>
+         <property name="topMargin">
+          <number>5</number>
+         </property>
+         <property name="rightMargin">
+          <number>5</number>
+         </property>
+         <property name="bottomMargin">
+          <number>5</number>
+         </property>
+         <item>
+          <widget class="QWidget" name="widget" native="true">
+           <layout class="QVBoxLayout" name="verticalLayout_9">
+            <item>
+             <widget class="QLabel" name="FBLabel">
+              <property name="sizePolicy">
+               <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+               </sizepolicy>
+              </property>
+              <property name="text">
+               <string>Connect to facebook text placeholder</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QWidget" name="fbWebviewContainer" native="true">
+              <layout class="QVBoxLayout" name="verticalLayout_10"/>
+             </widget>
+            </item>
+           </layout>
+          </widget>
+         </item>
+        </layout>
+       </widget>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/desktop-widgets/plugins/facebook/socialnetworksdialog.ui b/desktop-widgets/plugins/facebook/socialnetworksdialog.ui
new file mode 100644
index 0000000..e8953d1
--- /dev/null
+++ b/desktop-widgets/plugins/facebook/socialnetworksdialog.ui
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SocialnetworksDialog</class>
+ <widget class="QDialog" name="SocialnetworksDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>475</width>
+    <height>416</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QDialogButtonBox" name="buttonBox">
+   <property name="geometry">
+    <rect>
+     <x>290</x>
+     <y>380</y>
+     <width>166</width>
+     <height>22</height>
+    </rect>
+   </property>
+   <property name="orientation">
+    <enum>Qt::Horizontal</enum>
+   </property>
+   <property name="standardButtons">
+    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+   </property>
+  </widget>
+  <widget class="QWidget" name="layoutWidget">
+   <property name="geometry">
+    <rect>
+     <x>10</x>
+     <y>15</y>
+     <width>451</width>
+     <height>361</height>
+    </rect>
+   </property>
+   <layout class="QGridLayout" name="gridLayout" rowstretch="0,1,0,0,0,0,0,0,0,0,0">
+    <property name="leftMargin">
+     <number>1</number>
+    </property>
+    <property name="topMargin">
+     <number>1</number>
+    </property>
+    <property name="rightMargin">
+     <number>1</number>
+    </property>
+    <property name="bottomMargin">
+     <number>1</number>
+    </property>
+    <item row="1" column="0" colspan="2">
+     <widget class="QLabel" name="label_4">
+      <property name="text">
+       <string>The text to the right will be posted as the description with your profile picture to Facebook. The album name is required (the profile picture will be posted to that album).</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+      </property>
+      <property name="wordWrap">
+       <bool>true</bool>
+      </property>
+     </widget>
+    </item>
+    <item row="2" column="0">
+     <widget class="QLabel" name="label_2">
+      <property name="text">
+       <string>Album</string>
+      </property>
+     </widget>
+    </item>
+    <item row="3" column="0">
+     <widget class="QLineEdit" name="album">
+      <property name="toolTip">
+       <string>The profile picture will be posted in this album (required)</string>
+      </property>
+     </widget>
+    </item>
+    <item row="4" column="0">
+     <widget class="QLabel" name="label_3">
+      <property name="text">
+       <string>Include</string>
+      </property>
+     </widget>
+    </item>
+    <item row="5" column="0">
+     <widget class="QCheckBox" name="date">
+      <property name="text">
+       <string>Date and time</string>
+      </property>
+     </widget>
+    </item>
+    <item row="6" column="0">
+     <widget class="QCheckBox" name="duration">
+      <property name="text">
+       <string>Duration</string>
+      </property>
+     </widget>
+    </item>
+    <item row="7" column="0">
+     <widget class="QCheckBox" name="Location">
+      <property name="text">
+       <string>Location</string>
+      </property>
+     </widget>
+    </item>
+    <item row="8" column="0">
+     <widget class="QCheckBox" name="Divemaster">
+      <property name="text">
+       <string>Divemaster</string>
+      </property>
+     </widget>
+    </item>
+    <item row="9" column="0">
+     <widget class="QCheckBox" name="Buddy">
+      <property name="text">
+       <string>Buddy</string>
+      </property>
+     </widget>
+    </item>
+    <item row="10" column="0">
+     <widget class="QCheckBox" name="Notes">
+      <property name="text">
+       <string>Notes</string>
+      </property>
+     </widget>
+    </item>
+    <item row="0" column="0" colspan="2">
+     <widget class="QLabel" name="label">
+      <property name="font">
+       <font>
+        <weight>75</weight>
+        <bold>true</bold>
+       </font>
+      </property>
+      <property name="text">
+       <string>Facebook post preview</string>
+      </property>
+     </widget>
+    </item>
+    <item row="2" column="1" rowspan="9">
+     <widget class="QPlainTextEdit" name="text"/>
+    </item>
+   </layout>
+  </widget>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>SocialnetworksDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>SocialnetworksDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/desktop-widgets/socialnetworksdialog.ui b/desktop-widgets/socialnetworksdialog.ui
deleted file mode 100644
index e8953d1..0000000
--- a/desktop-widgets/socialnetworksdialog.ui
+++ /dev/null
@@ -1,184 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>SocialnetworksDialog</class>
- <widget class="QDialog" name="SocialnetworksDialog">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>475</width>
-    <height>416</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Dialog</string>
-  </property>
-  <widget class="QDialogButtonBox" name="buttonBox">
-   <property name="geometry">
-    <rect>
-     <x>290</x>
-     <y>380</y>
-     <width>166</width>
-     <height>22</height>
-    </rect>
-   </property>
-   <property name="orientation">
-    <enum>Qt::Horizontal</enum>
-   </property>
-   <property name="standardButtons">
-    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-   </property>
-  </widget>
-  <widget class="QWidget" name="layoutWidget">
-   <property name="geometry">
-    <rect>
-     <x>10</x>
-     <y>15</y>
-     <width>451</width>
-     <height>361</height>
-    </rect>
-   </property>
-   <layout class="QGridLayout" name="gridLayout" rowstretch="0,1,0,0,0,0,0,0,0,0,0">
-    <property name="leftMargin">
-     <number>1</number>
-    </property>
-    <property name="topMargin">
-     <number>1</number>
-    </property>
-    <property name="rightMargin">
-     <number>1</number>
-    </property>
-    <property name="bottomMargin">
-     <number>1</number>
-    </property>
-    <item row="1" column="0" colspan="2">
-     <widget class="QLabel" name="label_4">
-      <property name="text">
-       <string>The text to the right will be posted as the description with your profile picture to Facebook. The album name is required (the profile picture will be posted to that album).</string>
-      </property>
-      <property name="alignment">
-       <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
-      </property>
-      <property name="wordWrap">
-       <bool>true</bool>
-      </property>
-     </widget>
-    </item>
-    <item row="2" column="0">
-     <widget class="QLabel" name="label_2">
-      <property name="text">
-       <string>Album</string>
-      </property>
-     </widget>
-    </item>
-    <item row="3" column="0">
-     <widget class="QLineEdit" name="album">
-      <property name="toolTip">
-       <string>The profile picture will be posted in this album (required)</string>
-      </property>
-     </widget>
-    </item>
-    <item row="4" column="0">
-     <widget class="QLabel" name="label_3">
-      <property name="text">
-       <string>Include</string>
-      </property>
-     </widget>
-    </item>
-    <item row="5" column="0">
-     <widget class="QCheckBox" name="date">
-      <property name="text">
-       <string>Date and time</string>
-      </property>
-     </widget>
-    </item>
-    <item row="6" column="0">
-     <widget class="QCheckBox" name="duration">
-      <property name="text">
-       <string>Duration</string>
-      </property>
-     </widget>
-    </item>
-    <item row="7" column="0">
-     <widget class="QCheckBox" name="Location">
-      <property name="text">
-       <string>Location</string>
-      </property>
-     </widget>
-    </item>
-    <item row="8" column="0">
-     <widget class="QCheckBox" name="Divemaster">
-      <property name="text">
-       <string>Divemaster</string>
-      </property>
-     </widget>
-    </item>
-    <item row="9" column="0">
-     <widget class="QCheckBox" name="Buddy">
-      <property name="text">
-       <string>Buddy</string>
-      </property>
-     </widget>
-    </item>
-    <item row="10" column="0">
-     <widget class="QCheckBox" name="Notes">
-      <property name="text">
-       <string>Notes</string>
-      </property>
-     </widget>
-    </item>
-    <item row="0" column="0" colspan="2">
-     <widget class="QLabel" name="label">
-      <property name="font">
-       <font>
-        <weight>75</weight>
-        <bold>true</bold>
-       </font>
-      </property>
-      <property name="text">
-       <string>Facebook post preview</string>
-      </property>
-     </widget>
-    </item>
-    <item row="2" column="1" rowspan="9">
-     <widget class="QPlainTextEdit" name="text"/>
-    </item>
-   </layout>
-  </widget>
- </widget>
- <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>SocialnetworksDialog</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>248</x>
-     <y>254</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>157</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>rejected()</signal>
-   <receiver>SocialnetworksDialog</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>316</x>
-     <y>260</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>286</x>
-     <y>274</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
-</ui>
-- 
2.6.2

From d975ea264cccd378fd5640faed64c29b3fa58363 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Wed, 4 Nov 2015 21:24:51 -0200
Subject: [PATCH] Re-add the signal connections

The signal connections from the old preferences got lost when
we moved to the new ones because Designer is broken and can't
handle signals / connactions from copy/pasted content.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 .../preferences/preferences_defaults.ui            |  37 +++-
 desktop-widgets/preferences/preferences_network.ui |  66 +++++--
 desktop-widgets/preferences/preferences_units.ui   | 220 ++++++++++++++++++++-
 3 files changed, 297 insertions(+), 26 deletions(-)

diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui
index 632e827..627d22c 100644
--- a/desktop-widgets/preferences/preferences_defaults.ui
+++ b/desktop-widgets/preferences/preferences_defaults.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>555</width>
+    <width>561</width>
     <height>558</height>
    </rect>
   </property>
@@ -247,5 +247,38 @@
   </layout>
  </widget>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>btnUseDefaultFile</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>chooseFile</receiver>
+   <slot>setHidden(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>462</x>
+     <y>136</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>528</x>
+     <y>145</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>velocitySlider</sender>
+   <signal>valueChanged(int)</signal>
+   <receiver>velocitySpinBox</receiver>
+   <slot>setValue(int)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>437</x>
+     <y>299</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>531</x>
+     <y>301</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>
diff --git a/desktop-widgets/preferences/preferences_network.ui b/desktop-widgets/preferences/preferences_network.ui
index 8bb9bf9..0899c7c 100644
--- a/desktop-widgets/preferences/preferences_network.ui
+++ b/desktop-widgets/preferences/preferences_network.ui
@@ -89,16 +89,6 @@
       <item row="0" column="1" colspan="3">
        <widget class="QComboBox" name="proxyType"/>
       </item>
-      <item row="2" column="1" colspan="3">
-       <widget class="QCheckBox" name="proxyAuthRequired">
-        <property name="layoutDirection">
-         <enum>Qt::LeftToRight</enum>
-        </property>
-        <property name="text">
-         <string>Requires authentication</string>
-        </property>
-       </widget>
-      </item>
       <item row="3" column="1">
        <widget class="QLineEdit" name="proxyUsername">
         <property name="sizePolicy">
@@ -135,6 +125,16 @@
         </property>
        </widget>
       </item>
+      <item row="2" column="1" colspan="3">
+       <widget class="QCheckBox" name="proxyAuthRequired">
+        <property name="layoutDirection">
+         <enum>Qt::LeftToRight</enum>
+        </property>
+        <property name="text">
+         <string>Requires authentication</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
@@ -241,16 +241,7 @@
       <property name="spacing">
        <number>5</number>
       </property>
-      <property name="leftMargin">
-       <number>5</number>
-      </property>
-      <property name="topMargin">
-       <number>5</number>
-      </property>
-      <property name="rightMargin">
-       <number>5</number>
-      </property>
-      <property name="bottomMargin">
+      <property name="margin">
        <number>5</number>
       </property>
       <item>
@@ -289,5 +280,38 @@
   </layout>
  </widget>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>proxyAuthRequired</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>proxyUsername</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>207</x>
+     <y>107</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>213</x>
+     <y>128</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>proxyAuthRequired</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>proxyPassword</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>555</x>
+     <y>109</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>556</x>
+     <y>137</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>
diff --git a/desktop-widgets/preferences/preferences_units.ui b/desktop-widgets/preferences/preferences_units.ui
index bb1ffba..e100a90 100644
--- a/desktop-widgets/preferences/preferences_units.ui
+++ b/desktop-widgets/preferences/preferences_units.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>374</height>
+    <width>455</width>
+    <height>515</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -75,6 +75,9 @@
         <property name="text">
          <string>meter</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup</string>
+        </attribute>
        </widget>
       </item>
       <item row="0" column="2">
@@ -82,6 +85,9 @@
         <property name="text">
          <string>feet</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup</string>
+        </attribute>
        </widget>
       </item>
       <item row="1" column="0">
@@ -96,6 +102,9 @@
         <property name="text">
          <string>bar</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_2</string>
+        </attribute>
        </widget>
       </item>
       <item row="1" column="2">
@@ -103,6 +112,9 @@
         <property name="text">
          <string>psi</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_2</string>
+        </attribute>
        </widget>
       </item>
       <item row="2" column="0">
@@ -117,6 +129,9 @@
         <property name="text">
          <string>&amp;liter</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_3</string>
+        </attribute>
        </widget>
       </item>
       <item row="2" column="2">
@@ -124,6 +139,9 @@
         <property name="text">
          <string>cu ft</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_3</string>
+        </attribute>
        </widget>
       </item>
       <item row="3" column="0">
@@ -138,6 +156,9 @@
         <property name="text">
          <string>celsius</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_4</string>
+        </attribute>
        </widget>
       </item>
       <item row="3" column="2">
@@ -145,6 +166,9 @@
         <property name="text">
          <string>fahrenheit</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_4</string>
+        </attribute>
        </widget>
       </item>
       <item row="4" column="0">
@@ -159,6 +183,9 @@
         <property name="text">
          <string>kg</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_5</string>
+        </attribute>
        </widget>
       </item>
       <item row="4" column="2">
@@ -166,6 +193,9 @@
         <property name="text">
          <string>lbs</string>
         </property>
+        <attribute name="buttonGroup">
+         <string notr="true">buttonGroup_5</string>
+        </attribute>
        </widget>
       </item>
      </layout>
@@ -247,5 +277,189 @@
   </layout>
  </widget>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>metric</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>meter</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>188</x>
+     <y>50</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>254</x>
+     <y>125</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>metric</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>bar</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>188</x>
+     <y>49</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>254</x>
+     <y>151</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>metric</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>liter</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>188</x>
+     <y>55</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>254</x>
+     <y>178</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>metric</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>celsius</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>188</x>
+     <y>47</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>254</x>
+     <y>206</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>metric</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>kg</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>188</x>
+     <y>44</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>254</x>
+     <y>233</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>imperial</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>feet</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>278</x>
+     <y>47</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>377</x>
+     <y>119</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>imperial</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>psi</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>278</x>
+     <y>50</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>377</x>
+     <y>151</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>imperial</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>cuft</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>278</x>
+     <y>53</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>377</x>
+     <y>176</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>imperial</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>fahrenheit</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>278</x>
+     <y>51</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>377</x>
+     <y>208</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>imperial</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>lbs</receiver>
+   <slot>setChecked(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>278</x>
+     <y>46</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>377</x>
+     <y>231</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>personalize</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>units_group</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>377</x>
+     <y>46</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>388</x>
+     <y>86</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+ <buttongroups>
+  <buttongroup name="buttonGroup"/>
+  <buttongroup name="buttonGroup_2"/>
+  <buttongroup name="buttonGroup_3"/>
+  <buttongroup name="buttonGroup_4"/>
+  <buttongroup name="buttonGroup_5"/>
+ </buttongroups>
 </ui>
-- 
2.6.2

From 1bd8e511992efab7e286868d0753f014c5e529d8 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 10:51:50 -0200
Subject: [PATCH 2/6] Make it possible to connect to facebook again

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 desktop-widgets/mainwindow.cpp                             | 1 +
 desktop-widgets/plugins/facebook/facebook_integration.cpp  | 6 +++++-
 desktop-widgets/plugins/facebook/facebookconnectwidget.cpp | 3 ++-
 subsurface-core/pluginmanager.cpp                          | 4 +++-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index b9112c1..740b38f 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -260,6 +260,7 @@ MainWindow::MainWindow() : QMainWindow(),
 			toggle_connection->setText(plugin->socialNetworkName());
 			toggle_connection->setIcon(QIcon(plugin->socialNetworkIcon()));
 			toggle_connection->setData(QVariant::fromValue(plugin));
+			connect(toggle_connection, &QAction::triggered, [plugin](bool triggered){ plugin->requestLogin(); });
 
 			QAction *share_on = new QAction(this);
 			share_on->setText(plugin->socialNetworkName());
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp
index 700c8f6..28e6525 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.cpp
+++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp
@@ -1,4 +1,7 @@
 #include "facebook_integration.h"
+#include "facebookconnectwidget.h"
+
+#include <QDebug>
 
 FacebookPlugin::FacebookPlugin(QObject* parent): QObject(parent)
 {
@@ -12,7 +15,8 @@ bool FacebookPlugin::isConnected()
 
 void FacebookPlugin::requestLogin()
 {
-
+	FacebookConnectWidget connectDialog;
+	connectDialog.exec();
 }
 
 void FacebookPlugin::requestLogoff()
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
index 0fba4a0..f42bd9b 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -275,7 +275,8 @@ void FacebookManager::sendDive()
 }
 
 FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), ui(new Ui::FacebookConnectWidget) {
-  	FacebookManager *fb = FacebookManager::instance();
+	ui->setupUi(this);
+	FacebookManager *fb = FacebookManager::instance();
 	facebookWebView = new QWebView(this);
 	ui->fbWebviewContainer->layout()->addWidget(facebookWebView);
 	if (fb->loggedIn()) {
diff --git a/subsurface-core/pluginmanager.cpp b/subsurface-core/pluginmanager.cpp
index 5c0f225..28c9782 100644
--- a/subsurface-core/pluginmanager.cpp
+++ b/subsurface-core/pluginmanager.cpp
@@ -40,8 +40,10 @@ void PluginManager::loadPlugins()
 		if(!plugin)
 			continue;
 
-		if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin))
+		if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)) {
+			qDebug() << "Adding the plugin: " << social->socialNetworkName();
 			_socialNetworks.push_back(social);
+		}
 	}
 }
 
-- 
2.6.2

From ad39cf3c1f29db1ad8b57cd64cb301ba76eb1c28 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 10:58:59 -0200
Subject: [PATCH 3/6] Change from uploadCurrentDive to requestUpload call

Since we can't forbit the plugins to upload more than just the
current dive, it's better to change the name of the call.
also add a stub to make sure it's calling the right method inside
the plugin.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 desktop-widgets/mainwindow.cpp                            | 1 +
 desktop-widgets/plugins/facebook/facebook_integration.cpp | 4 ++--
 desktop-widgets/plugins/facebook/facebook_integration.h   | 2 +-
 subsurface-core/isocialnetworkintegration.h               | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 740b38f..e727fce 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -268,6 +268,7 @@ MainWindow::MainWindow() : QMainWindow(),
 			share_on->setData(QVariant::fromValue(plugin));
 			ui.menuShare_on->addAction(share_on);
 			connections->addAction(toggle_connection);
+			connect(share_on, &QAction::triggered, [plugin](bool triggered) { plugin->requestUpload(); }
 		}
 		ui.menuShare_on->addSeparator();
 		ui.menuShare_on->addMenu(connections);
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp
index 28e6525..43f74b8 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.cpp
+++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp
@@ -34,7 +34,7 @@ QString FacebookPlugin::socialNetworkName() const
 	return tr("Facebook");
 }
 
-void FacebookPlugin::uploadCurrentDive()
+void FacebookPlugin::requestUpload()
 {
-
+	qDebug() << "Upload Requested";
 }
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.h b/desktop-widgets/plugins/facebook/facebook_integration.h
index a9d212e..99362e7 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.h
+++ b/desktop-widgets/plugins/facebook/facebook_integration.h
@@ -15,7 +15,7 @@ public:
   virtual void requestLogoff();
   virtual QString socialNetworkIcon() const;
   virtual QString socialNetworkName() const;
-  virtual void uploadCurrentDive();
+  virtual void requestUpload();
 };
 
 #endif
\ No newline at end of file
diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h
index 778a171..0a38f95 100644
--- a/subsurface-core/isocialnetworkintegration.h
+++ b/subsurface-core/isocialnetworkintegration.h
@@ -64,7 +64,7 @@ public:
 	 * to update to the social network. All widget stuff related to sendint
 	 * dive information should be executed inside this function.
 	 */
-	virtual void uploadCurrentDive() = 0;
+	virtual void requestUpload() = 0;
 };
 
 Q_DECLARE_INTERFACE(ISocialNetworkIntegration, "org.subsurface.ISocialNetworkIntegration.v1")
-- 
2.6.2

From c40400516dafa947d17b97f1eb9a4402772e8507 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 11:01:03 -0200
Subject: [PATCH 4/6] We are not using this code anymore, rip it off

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 desktop-widgets/mainwindow.cpp | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index e727fce..12aed9c 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -243,16 +243,6 @@ MainWindow::MainWindow() : QMainWindow(),
 	find_all_templates();
 #endif
 
-#if defined(FBSUPPORT)
-	FacebookManager *fb = FacebookManager::instance();
-	connect(fb, SIGNAL(justLoggedIn(bool)), ui.actionFacebook, SLOT(setEnabled(bool)));
-	connect(fb, SIGNAL(justLoggedOut(bool)), ui.actionFacebook, SLOT(setEnabled(bool)));
-	connect(ui.actionFacebook, SIGNAL(triggered(bool)), fb, SLOT(sendDive()));
-	ui.actionFacebook->setEnabled(fb->loggedIn());
-#else
-	ui.actionFacebook->setEnabled(false);
-#endif
-
 	if(PluginManager::instance().socialNetworkIntegrationPlugins().count()) {
 		QMenu *connections = new QMenu(tr("Connect to"));
 		for(ISocialNetworkIntegration *plugin : PluginManager::instance().socialNetworkIntegrationPlugins()){
-- 
2.6.2

From 0813aa2b28ff217b138d508f2a35e4f58ca42fa8 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 11:50:04 -0200
Subject: [PATCH 5/6] Facebook Plugin is aware of it's connection status

This patch makes facebook plugin aware of it's connection status
enabling uploads only when connected, and hooking some things up.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 desktop-widgets/mainwindow.cpp                     |  2 +-
 .../plugins/facebook/facebook_integration.cpp      | 17 ++++++++------
 .../plugins/facebook/facebook_integration.h        | 27 ++++++++++++++--------
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index 12aed9c..14ba967 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -258,7 +258,7 @@ MainWindow::MainWindow() : QMainWindow(),
 			share_on->setData(QVariant::fromValue(plugin));
 			ui.menuShare_on->addAction(share_on);
 			connections->addAction(toggle_connection);
-			connect(share_on, &QAction::triggered, [plugin](bool triggered) { plugin->requestUpload(); }
+			connect(share_on, &QAction::triggered, [plugin](bool triggered) { plugin->requestUpload(); });
 		}
 		ui.menuShare_on->addSeparator();
 		ui.menuShare_on->addMenu(connections);
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp
index 43f74b8..f817f9d 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.cpp
+++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp
@@ -3,25 +3,26 @@
 
 #include <QDebug>
 
-FacebookPlugin::FacebookPlugin(QObject* parent): QObject(parent)
+FacebookPlugin::FacebookPlugin(QObject* parent): QObject(parent),
+	fbConnectWidget(new FacebookConnectWidget()),
+	fbUploadDialog(new SocialNetworkDialog())
 {
-
 }
 
 bool FacebookPlugin::isConnected()
 {
-	return false;
+	FacebookManager *instance = FacebookManager::instance();
+	return instance->loggedIn();
 }
 
 void FacebookPlugin::requestLogin()
 {
-	FacebookConnectWidget connectDialog;
-	connectDialog.exec();
+	fbConnectWidget->exec();
 }
 
 void FacebookPlugin::requestLogoff()
 {
-
+	FacebookManager::instance()->logout();
 }
 
 QString FacebookPlugin::socialNetworkIcon() const
@@ -36,5 +37,7 @@ QString FacebookPlugin::socialNetworkName() const
 
 void FacebookPlugin::requestUpload()
 {
-	qDebug() << "Upload Requested";
+	FacebookManager *instance = FacebookManager::instance();
+	if (instance->loggedIn())
+		fbUploadDialog->exec();
 }
diff --git a/desktop-widgets/plugins/facebook/facebook_integration.h b/desktop-widgets/plugins/facebook/facebook_integration.h
index 99362e7..714f636 100644
--- a/desktop-widgets/plugins/facebook/facebook_integration.h
+++ b/desktop-widgets/plugins/facebook/facebook_integration.h
@@ -4,18 +4,25 @@
 #include "subsurface-core/isocialnetworkintegration.h"
 #include <QString>
 
+class FacebookConnectWidget;
+class SocialNetworkDialog;
+class FacebookManager;
+
 class FacebookPlugin : public QObject, public ISocialNetworkIntegration {
-  Q_OBJECT
-  Q_PLUGIN_METADATA(IID "org.subsurface.plugins.ISocialNetworkIntegration")
-  Q_INTERFACES(ISocialNetworkIntegration)
+	Q_OBJECT
+	Q_PLUGIN_METADATA(IID "org.subsurface.plugins.ISocialNetworkIntegration")
+	Q_INTERFACES(ISocialNetworkIntegration)
 public:
-  explicit FacebookPlugin(QObject* parent = 0);
-  virtual bool isConnected();
-  virtual void requestLogin();
-  virtual void requestLogoff();
-  virtual QString socialNetworkIcon() const;
-  virtual QString socialNetworkName() const;
-  virtual void requestUpload();
+	explicit FacebookPlugin(QObject* parent = 0);
+	virtual bool isConnected();
+	virtual void requestLogin();
+	virtual void requestLogoff();
+	virtual QString socialNetworkIcon() const;
+	virtual QString socialNetworkName() const;
+	virtual void requestUpload();
+private:
+	FacebookConnectWidget *fbConnectWidget;
+	SocialNetworkDialog *fbUploadDialog;
 };
 
 #endif
\ No newline at end of file
-- 
2.6.2

From ce264b8afd0349d9264e24ee6a76ead3c419f90e Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Sun, 8 Nov 2015 12:10:13 -0200
Subject: [PATCH 6/6] Finish the first facebook integration plugin

Now the plugin is usable, one can use it to send stuff to facebook.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 .../plugins/facebook/facebookconnectwidget.cpp     |  53 +++-
 .../plugins/facebook/facebookconnectwidget.h       |  14 +-
 desktop-widgets/socialnetworks.cpp                 | 326 ---------------------
 desktop-widgets/socialnetworks.h                   |  49 ----
 4 files changed, 51 insertions(+), 391 deletions(-)
 delete mode 100644 desktop-widgets/socialnetworks.cpp
 delete mode 100644 desktop-widgets/socialnetworks.h

diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
index f42bd9b..264244b 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp
@@ -308,25 +308,60 @@ void FacebookConnectWidget::facebookDisconnect()
 	}
 }
 
-SocialNetworkDialog::SocialNetworkDialog(QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
+SocialNetworkDialog::SocialNetworkDialog(QWidget *parent) :
+	QDialog(parent),
+	ui( new Ui::SocialnetworksDialog())
 {
-
+	ui->setupUi(this);
+	ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+	connect(ui->date, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->duration, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->Buddy, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->Divemaster, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->Location, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->Notes, SIGNAL(clicked()), this, SLOT(selectionChanged()));
+	connect(ui->album, SIGNAL(textChanged(QString)), this, SLOT(albumChanged()));
 }
 
-QString SocialNetworkDialog::name() const
+void SocialNetworkDialog::albumChanged()
 {
-	return _name;
+	QAbstractButton *button = ui->buttonBox->button(QDialogButtonBox::Ok);
+	button->setEnabled(!ui->album->text().isEmpty());
 }
 
-QString SocialNetworkDialog::album() const
+void SocialNetworkDialog::selectionChanged()
 {
-	return _album;
+	struct dive *d = current_dive;
+	QString fullText;
+	if (ui->date->isChecked()) {
+		fullText += tr("Dive date: %1 \n").arg(get_short_dive_date_string(d->when));
+	}
+	if (ui->duration->isChecked()) {
+		fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds,
+									       tr("h:", "abbreviation for hours plus separator"),
+									       tr("min", "abbreviation for minutes")));
+	}
+	if (ui->Location->isChecked()) {
+		fullText += tr("Dive location: %1 \n").arg(get_dive_location(d));
+	}
+	if (ui->Buddy->isChecked()) {
+		fullText += tr("Buddy: %1 \n").arg(d->buddy);
+	}
+	if (ui->Divemaster->isChecked()) {
+		fullText += tr("Divemaster: %1 \n").arg(d->divemaster);
+	}
+	if (ui->Notes->isChecked()) {
+		fullText += tr("\n%1").arg(d->notes);
+	}
+	ui->text->setPlainText(fullText);
 }
 
-QString SocialNetworkDialog::text() const
-{
-	return _text;
+QString SocialNetworkDialog::text() const {
+	return ui->text->toPlainText().toHtmlEscaped();
 }
 
+QString SocialNetworkDialog::album() const {
+	return ui->album->text().toHtmlEscaped();
+}
 
 
diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
index 40e1027..8b13b0d 100644
--- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h
+++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h
@@ -5,6 +5,7 @@
 class QWebView;
 namespace Ui {
   class FacebookConnectWidget;
+  class SocialnetworksDialog;
 }
 
 class FacebookManager : public QObject
@@ -47,15 +48,14 @@ private:
 class SocialNetworkDialog : public QDialog {
 	Q_OBJECT
 public:
-	explicit SocialNetworkDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
-	QString album() const;
-	QString name() const;
+	SocialNetworkDialog(QWidget *parent = 0);
 	QString text() const;
-	
+	QString album() const;
+public slots:
+	void selectionChanged();
+	void albumChanged();
 private:
-	QString _album;
-	QString _name;
-	QString _text;
+	Ui::SocialnetworksDialog *ui;
 };
 
 #endif 
\ No newline at end of file
diff --git a/desktop-widgets/socialnetworks.cpp b/desktop-widgets/socialnetworks.cpp
deleted file mode 100644
index 0794c76..0000000
--- a/desktop-widgets/socialnetworks.cpp
+++ /dev/null
@@ -1,326 +0,0 @@
-#include "socialnetworks.h"
-
-#include <QJsonDocument>
-#include <QJsonArray>
-#include <QJsonObject>
-#include <QNetworkReply>
-#include <QNetworkRequest>
-#include <QNetworkAccessManager>
-#include <QUrlQuery>
-#include <QEventLoop>
-#include <QHttpMultiPart>
-#include <QSettings>
-#include <QFile>
-#include <QBuffer>
-#include <QDebug>
-#include <QMessageBox>
-#include <QInputDialog>
-#include "mainwindow.h"
-#include "profile-widget/profilewidget2.h"
-#include "pref.h"
-#include "helpers.h"
-#include "ui_socialnetworksdialog.h"
-
-#if SAVE_FB_CREDENTIALS
-#define GET_TXT(name, field)                                             \
-	v = s.value(QString(name));                                      \
-	if (v.isValid())                                                 \
-		prefs.field = strdup(v.toString().toUtf8().constData()); \
-	else                                                             \
-		prefs.field = default_prefs.field
-#endif
-
-FacebookManager *FacebookManager::instance()
-{
-	static FacebookManager *self = new FacebookManager();
-	return self;
-}
-
-FacebookManager::FacebookManager(QObject *parent) : QObject(parent)
-{
-	sync();
-}
-
-QUrl FacebookManager::connectUrl() {
-	return QUrl("https://www.facebook.com/dialog/oauth?";
-		"client_id=427722490709000"
-		"&redirect_uri=http://www.facebook.com/connect/login_success.html";
-		"&response_type=token,granted_scopes"
-		"&display=popup"
-		"&scope=publish_actions,user_photos"
-	);
-}
-
-bool FacebookManager::loggedIn() {
-	return prefs.facebook.access_token != NULL;
-}
-
-void FacebookManager::sync()
-{
-#if SAVE_FB_CREDENTIALS
-	QSettings s;
-	s.beginGroup("WebApps");
-	s.beginGroup("Facebook");
-
-	QVariant v;
-	GET_TXT("ConnectToken", facebook.access_token);
-	GET_TXT("UserId", facebook.user_id);
-	GET_TXT("AlbumId", facebook.album_id);
-#endif
-}
-
-void FacebookManager::tryLogin(const QUrl& loginResponse)
-{
-	QString result = loginResponse.toString();
-	if (!result.contains("access_token"))
-		return;
-
-	if (result.contains("denied_scopes=publish_actions") || result.contains("denied_scopes=user_photos")) {
-		qDebug() << "user did not allow us access" << result;
-		return;
-	}
-	int from = result.indexOf("access_token=") + strlen("access_token=");
-	int to = result.indexOf("&expires_in");
-	QString securityToken = result.mid(from, to-from);
-
-#if SAVE_FB_CREDENTIALS
-	QSettings settings;
-	settings.beginGroup("WebApps");
-	settings.beginGroup("Facebook");
-	settings.setValue("ConnectToken", securityToken);
-	sync();
-#else
-	prefs.facebook.access_token = copy_string(securityToken.toUtf8().data());
-#endif
-	requestUserId();
-	sync();
-	emit justLoggedIn(true);
-}
-
-void FacebookManager::logout()
-{
-#if SAVE_FB_CREDENTIALS
-	QSettings settings;
-	settings.beginGroup("WebApps");
-	settings.beginGroup("Facebook");
-	settings.remove("ConnectToken");
-	settings.remove("UserId");
-	settings.remove("AlbumId");
-	sync();
-#else
-	free(prefs.facebook.access_token);
-	free(prefs.facebook.album_id);
-	free(prefs.facebook.user_id);
-	prefs.facebook.access_token = NULL;
-	prefs.facebook.album_id = NULL;
-	prefs.facebook.user_id = NULL;
-#endif
-	emit justLoggedOut(true);
-}
-
-void FacebookManager::requestAlbumId()
-{
-	QUrl albumListUrl("https://graph.facebook.com/me/albums?access_token="; + QString(prefs.facebook.access_token));
-	QNetworkAccessManager *manager = new QNetworkAccessManager();
-	QNetworkReply *reply = manager->get(QNetworkRequest(albumListUrl));
-
-	QEventLoop loop;
-	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
-	loop.exec();
-
-#if SAVE_FB_CREDENTIALS
-	QSettings s;
-	s.beginGroup("WebApps");
-	s.beginGroup("Facebook");
-#endif
-
-	QJsonDocument albumsDoc = QJsonDocument::fromJson(reply->readAll());
-	QJsonArray albumObj = albumsDoc.object().value("data").toArray();
-	foreach(const QJsonValue &v, albumObj){
-		QJsonObject obj = v.toObject();
-		if (obj.value("name").toString() == albumName) {
-#if SAVE_FB_CREDENTIALS
-			s.setValue("AlbumId", obj.value("id").toString());
-#else
-			prefs.facebook.album_id = copy_string(obj.value("id").toString().toUtf8().data());
-#endif
-			return;
-		}
-	}
-
-	QUrlQuery params;
-	params.addQueryItem("name", albumName );
-	params.addQueryItem("description", "Subsurface Album");
-	params.addQueryItem("privacy", "{'value': 'SELF'}");
-
-	QNetworkRequest request(albumListUrl);
-	request.setHeader(QNetworkRequest::ContentTypeHeader, "application/octet-stream");
-	reply = manager->post(request, params.query().toLocal8Bit());
-	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
-	loop.exec();
-
-	albumsDoc = QJsonDocument::fromJson(reply->readAll());
-	QJsonObject album = albumsDoc.object();
-	if (album.contains("id")) {
-#if SAVE_FB_CREDENTIALS
-		s.setValue("AlbumId", album.value("id").toString());
-#else
-		prefs.facebook.album_id = copy_string(album.value("id").toString().toUtf8().data());
-#endif
-		sync();
-		return;
-	}
-}
-
-void FacebookManager::requestUserId()
-{
-	QUrl userIdRequest("https://graph.facebook.com/me?fields=id&access_token="; + QString(prefs.facebook.access_token));
-	QNetworkAccessManager *getUserID = new QNetworkAccessManager();
-	QNetworkReply *reply = getUserID->get(QNetworkRequest(userIdRequest));
-
-	QEventLoop loop;
-	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
-	loop.exec();
-
-	QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll());
-	QJsonObject obj = jsonDoc.object();
-	if (obj.keys().contains("id")){
-#if SAVE_FB_CREDENTIALS
-		QSettings s;
-		s.beginGroup("WebApps");
-		s.beginGroup("Facebook");
-		s.setValue("UserId", obj.value("id").toVariant());
-#else
-		prefs.facebook.user_id = copy_string(obj.value("id").toString().toUtf8().data());
-#endif
-		return;
-	}
-}
-
-void FacebookManager::setDesiredAlbumName(const QString& a)
-{
-	albumName = a;
-}
-
-/* to be changed to export the currently selected dive as shown on the profile.
- * Much much easier, and its also good to people do not select all the dives
- * and send erroniously *all* of them to facebook. */
-void FacebookManager::sendDive()
-{
-	SocialNetworkDialog dialog(qApp->activeWindow());
-	if (dialog.exec() != QDialog::Accepted)
-		return;
-
-	setDesiredAlbumName(dialog.album());
-	requestAlbumId();
-
-	ProfileWidget2 *profile = MainWindow::instance()->graphics();
-	profile->setToolTipVisibile(false);
-	QPixmap pix = QPixmap::grabWidget(profile);
-	profile->setToolTipVisibile(true);
-	QByteArray bytes;
-	QBuffer buffer(&bytes);
-	buffer.open(QIODevice::WriteOnly);
-	pix.save(&buffer, "PNG");
-	QUrl url("https://graph.facebook.com/v2.2/"; + QString(prefs.facebook.album_id) + "/photos?" +
-		 "&access_token=" + QString(prefs.facebook.access_token) +
-		 "&source=image" +
-		 "&message=" + dialog.text().replace("&quot;", "%22"));
-
-	QNetworkAccessManager *am = new QNetworkAccessManager(this);
-	QNetworkRequest request(url);
-
-	QString bound="margin";
-
-	//according to rfc 1867 we need to put this string here:
-	QByteArray data(QString("--" + bound + "\r\n").toLocal8Bit());
-	data.append("Content-Disposition: form-data; name=\"action\"\r\n\r\n");
-	data.append("https://graph.facebook.com/v2.2/\r\n";);
-	data.append("--" + bound + "\r\n");   //according to rfc 1867
-	data.append("Content-Disposition: form-data; name=\"uploaded\"; filename=\"" + QString::number(qrand()) + ".png\"\r\n");  //name of the input is "uploaded" in my form, next one is a file name.
-	data.append("Content-Type: image/jpeg\r\n\r\n"); //data type
-	data.append(bytes);   //let's read the file
-	data.append("\r\n");
-	data.append("--" + bound + "--\r\n");  //closing boundary according to rfc 1867
-
-	request.setRawHeader(QString("Content-Type").toLocal8Bit(),QString("multipart/form-data; boundary=" + bound).toLocal8Bit());
-	request.setRawHeader(QString("Content-Length").toLocal8Bit(), QString::number(data.length()).toLocal8Bit());
-	QNetworkReply *reply = am->post(request,data);
-
-	QEventLoop loop;
-	connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
-	loop.exec();
-
-	QByteArray response = reply->readAll();
-	QJsonDocument jsonDoc = QJsonDocument::fromJson(response);
-	QJsonObject obj = jsonDoc.object();
-	if (obj.keys().contains("id")){
-		QMessageBox::information(qApp->activeWindow(),
-			tr("Photo upload sucessfull"),
-			tr("Your dive profile was updated to Facebook."),
-		QMessageBox::Ok);
-	} else {
-		QMessageBox::information(qApp->activeWindow(),
-			tr("Photo upload failed"),
-			tr("Your dive profile was not updated to Facebook, \n "
-			   "please send the following to the developer. \n"
-			   + response),
-		QMessageBox::Ok);
-	}
-}
-
-SocialNetworkDialog::SocialNetworkDialog(QWidget *parent) :
-	QDialog(parent),
-	ui( new Ui::SocialnetworksDialog())
-{
-	ui->setupUi(this);
-	ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
-	connect(ui->date, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->duration, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->Buddy, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->Divemaster, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->Location, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->Notes, SIGNAL(clicked()), this, SLOT(selectionChanged()));
-	connect(ui->album, SIGNAL(textChanged(QString)), this, SLOT(albumChanged()));
-}
-
-void SocialNetworkDialog::albumChanged()
-{
-	QAbstractButton *button = ui->buttonBox->button(QDialogButtonBox::Ok);
-	button->setEnabled(!ui->album->text().isEmpty());
-}
-
-void SocialNetworkDialog::selectionChanged()
-{
-	struct dive *d = current_dive;
-	QString fullText;
-	if (ui->date->isChecked()) {
-		fullText += tr("Dive date: %1 \n").arg(get_short_dive_date_string(d->when));
-	}
-	if (ui->duration->isChecked()) {
-		fullText += tr("Duration: %1 \n").arg(get_dive_duration_string(d->duration.seconds,
-									       tr("h:", "abbreviation for hours plus separator"),
-									       tr("min", "abbreviation for minutes")));
-	}
-	if (ui->Location->isChecked()) {
-		fullText += tr("Dive location: %1 \n").arg(get_dive_location(d));
-	}
-	if (ui->Buddy->isChecked()) {
-		fullText += tr("Buddy: %1 \n").arg(d->buddy);
-	}
-	if (ui->Divemaster->isChecked()) {
-		fullText += tr("Divemaster: %1 \n").arg(d->divemaster);
-	}
-	if (ui->Notes->isChecked()) {
-		fullText += tr("\n%1").arg(d->notes);
-	}
-	ui->text->setPlainText(fullText);
-}
-
-QString SocialNetworkDialog::text() const {
-	return ui->text->toPlainText().toHtmlEscaped();
-}
-
-QString SocialNetworkDialog::album() const {
-	return ui->album->text().toHtmlEscaped();
-}
diff --git a/desktop-widgets/socialnetworks.h b/desktop-widgets/socialnetworks.h
deleted file mode 100644
index 2f63915..0000000
--- a/desktop-widgets/socialnetworks.h
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef FACEBOOKMANAGER_H
-#define FACEBOOKMANAGER_H
-
-#include <QObject>
-#include <QUrl>
-#include <QDialog>
-
-class FacebookManager : public QObject
-{
-	Q_OBJECT
-public:
-	static FacebookManager *instance();
-	void requestAlbumId();
-	void requestUserId();
-	void sync();
-	QUrl connectUrl();
-	bool loggedIn();
-signals:
-	void justLoggedIn(bool triggererd);
-	void justLoggedOut(bool triggered);
-
-public slots:
-	void tryLogin(const QUrl& loginResponse);
-	void logout();
-	void setDesiredAlbumName(const QString& albumName);
-	void sendDive();
-
-private:
-	explicit FacebookManager(QObject *parent = 0);
-	QString albumName;
-};
-
-namespace  Ui {
-	class SocialnetworksDialog;
-}
-
-class SocialNetworkDialog : public QDialog {
-	Q_OBJECT
-public:
-	SocialNetworkDialog(QWidget *parent);
-	QString text() const;
-	QString album() const;
-public slots:
-	void selectionChanged();
-	void albumChanged();
-private:
-	Ui::SocialnetworksDialog *ui;
-};
-#endif // FACEBOOKMANAGER_H
-- 
2.6.2

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to