Hi Dirk, I am sorry for the problems in the previous patch. I correct the problems and tested. I believe it is all right, if not, please let me know.
P.S: I'm very bad with english, sorry for that.
From 393b7ec12c398e19530e6618fc20025822fb4210 Mon Sep 17 00:00:00 2001 From: Edi Anderson Lobo <ediandersonl...@gmail.com> Date: Sun, 16 Oct 2016 16:46:43 -0200 Subject: [PATCH 1/5] Checkboxes disabled by default. I disabled the checkbox to activate them during the runtime. So when the data associated with checkbox is not null, the checkbox is enabled. So null data will not be sent to facebook. Signed-off-by: Edi Anderson Lobo <ediandersonl...@gmail.com> --- .../plugins/facebook/socialnetworksdialog.ui | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/desktop-widgets/plugins/facebook/socialnetworksdialog.ui b/desktop-widgets/plugins/facebook/socialnetworksdialog.ui index e8953d1..e4b8c3a 100644 --- a/desktop-widgets/plugins/facebook/socialnetworksdialog.ui +++ b/desktop-widgets/plugins/facebook/socialnetworksdialog.ui @@ -87,6 +87,9 @@ </item> <item row="5" column="0"> <widget class="QCheckBox" name="date"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Date and time</string> </property> @@ -94,6 +97,9 @@ </item> <item row="6" column="0"> <widget class="QCheckBox" name="duration"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Duration</string> </property> @@ -101,6 +107,9 @@ </item> <item row="7" column="0"> <widget class="QCheckBox" name="Location"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Location</string> </property> @@ -108,6 +117,9 @@ </item> <item row="8" column="0"> <widget class="QCheckBox" name="Divemaster"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Divemaster</string> </property> @@ -115,6 +127,9 @@ </item> <item row="9" column="0"> <widget class="QCheckBox" name="Buddy"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Buddy</string> </property> @@ -122,6 +137,9 @@ </item> <item row="10" column="0"> <widget class="QCheckBox" name="Notes"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Notes</string> </property> -- 2.10.0
From cc76eed30cc6a6da1d14c3c73ccaa6a1851c3b0c Mon Sep 17 00:00:00 2001 From: Edi Anderson Lobo <ediandersonl...@gmail.com> Date: Sun, 16 Oct 2016 17:19:18 -0200 Subject: [PATCH 2/5] Added an new validation method. This method enables only checkboxes that have non-zero values associated with them. Signed-off-by: Edi Anderson Lobo <ediandersonl...@gmail.com> --- desktop-widgets/plugins/facebook/facebookconnectwidget.h | 1 + 1 file changed, 1 insertion(+) diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h index e970978..39c637a 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h @@ -55,6 +55,7 @@ public slots: void albumChanged(); private: Ui::SocialnetworksDialog *ui; + void enableCheckboxes(); }; #endif -- 2.10.0
From 17657592c31c7306131ef5995a27fd2428ed1154 Mon Sep 17 00:00:00 2001 From: Edi Anderson Lobo <ediandersonl...@gmail.com> Date: Mon, 17 Oct 2016 20:15:22 -0200 Subject: [PATCH 4/5] Changes in facebookconnectwidget.(h,cpp) Moved the definition of FacebookManager class to bottom, because needed pass a pointer of type SocialNetworkDialog to sendDive method of FacebookManager class because SocialNetworkDialog class was defined after FacebookManager, so SocialNetworkDialog was unknown to FacebookManager. Added an method 'enableCheckboxes', to determine whether the checkboxes must be enabled. They will be enabled if the values associated with their respective fields are not null. In FacebookManager::sendDive replace the local SocialNetworkDialog dialog by an pointer for the object SocialNetworkDialog which had already been allocated in the constructor of the class FacebookPlugin, avoiding the creation of a new object. In FacebookConnectWidget::facebookLoggedIn, added an QMessageBox to inform how to disconnect subsurface from Facebook account, instead of hiding the dialog widgets to display the same message. In FacebookConnectWidget::facebookDisconnect, useless code removed after my changes. Created SocialNetworkDialog::enableCheckboxes for show checkboxes that dont have null data associated with them. Created SocialNetworkDialog::clearDialog slot, to clear it after be used. Signed-off-by: Edi Anderson Lobo <ediandersonl...@gmail.com> --- .../plugins/facebook/facebookconnectwidget.cpp | 83 +++++++++++++++++----- .../plugins/facebook/facebookconnectwidget.h | 53 +++++++------- 2 files changed, 92 insertions(+), 44 deletions(-) diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp index e0d2aab..5a026fe 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.cpp @@ -157,13 +157,12 @@ void FacebookManager::setDesiredAlbumName(const QString& 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() +void FacebookManager::sendDive(SocialNetworkDialog *dialog) { - SocialNetworkDialog dialog(qApp->activeWindow()); - if (dialog.exec() != QDialog::Accepted) + if (dialog->exec() != QDialog::Accepted) return; - setDesiredAlbumName(dialog.album()); + setDesiredAlbumName(dialog->album()); requestAlbumId(); ProfileWidget2 *profile = MainWindow::instance()->graphics(); @@ -177,7 +176,7 @@ void FacebookManager::sendDive() 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(""", "%22")); + "&message=" + dialog->text().replace(""", "%22")); QNetworkAccessManager *am = new QNetworkAccessManager(this); QNetworkRequest request(url); @@ -226,6 +225,7 @@ FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), FacebookManager *fb = FacebookManager::instance(); facebookWebView = new QWebView(this); ui->fbWebviewContainer->layout()->addWidget(facebookWebView); + ui->FBLabel->setText(tr("To connect to Facebook, please log in. This enables Subsurface to publish dives to your timeline")); if (fb->loggedIn()) { facebookLoggedIn(); } else { @@ -233,22 +233,22 @@ FacebookConnectWidget::FacebookConnectWidget(QWidget *parent) : QDialog(parent), } connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin); connect(fb, &FacebookManager::justLoggedIn, this, &FacebookConnectWidget::facebookLoggedIn); + connect(fb, &FacebookManager::justLoggedOut,this, &FacebookConnectWidget::facebookDisconnect); } 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")); + close(); + QMessageBox::information(qApp->activeWindow(), + tr("Facebook account"), + tr("To disconnect Subsurface from your \n " + "account, use the menu \n" + "\"Share-on->Disconnect to->Facebook.\""), + QMessageBox::Ok); } 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()); @@ -260,6 +260,7 @@ SocialNetworkDialog::SocialNetworkDialog(QWidget *parent) : ui( new Ui::SocialnetworksDialog()) { ui->setupUi(this); + setFixedSize(size()); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); connect(ui->date, SIGNAL(clicked()), this, SLOT(selectionChanged())); connect(ui->duration, SIGNAL(clicked()), this, SLOT(selectionChanged())); @@ -268,12 +269,54 @@ SocialNetworkDialog::SocialNetworkDialog(QWidget *parent) : 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())); + connect(this, &QDialog::accepted, this, &SocialNetworkDialog::clearDialog); + connect(this, &QDialog::rejected, this, &SocialNetworkDialog::clearDialog); + clearDialog(); +} + +void SocialNetworkDialog::enableCheckboxes(bool enable) +{ + struct dive *d = current_dive; + if (d != NULL) { + ui->duration->setEnabled(enable); + if (get_short_dive_date_string(d->when) != "" ) { + ui->date->setEnabled(enable); + } + if (get_dive_location(d) != NULL) { + ui->Location->setEnabled(enable); + } + if (d->buddy != NULL) { + ui->Buddy->setEnabled(enable); + } + if (d->divemaster != NULL) { + ui->Divemaster->setEnabled(enable); + } + if ( d->notes != NULL) { + ui->Notes->setEnabled(enable); + } + } + + if (!enable) + ui->text->setDisabled(!enable); + else + ui->text->setEnabled(enable); } void SocialNetworkDialog::albumChanged() { QAbstractButton *button = ui->buttonBox->button(QDialogButtonBox::Ok); - button->setEnabled(!ui->album->text().isEmpty()); + bool enabled = !ui->album->text().isEmpty(); + button->setEnabled(enabled); + enableCheckboxes(enabled); + if (!enabled) { + ui->text->clear(); + ui->duration->setChecked(enabled); + ui->date->setChecked(enabled); + ui->Location->setChecked(enabled); + ui->Buddy->setChecked(enabled); + ui->Divemaster->setChecked(enabled); + ui->Notes->setChecked(enabled); + } } void SocialNetworkDialog::selectionChanged() @@ -303,12 +346,18 @@ void SocialNetworkDialog::selectionChanged() ui->text->setPlainText(fullText); } -QString SocialNetworkDialog::text() const { +QString SocialNetworkDialog::text() const +{ return ui->text->toPlainText().toHtmlEscaped(); } -QString SocialNetworkDialog::album() const { +QString SocialNetworkDialog::album() const +{ return ui->album->text().toHtmlEscaped(); } - +void SocialNetworkDialog::clearDialog() +{ + ui->album->clear(); + emit ui->album->textChanged(QString()); +} diff --git a/desktop-widgets/plugins/facebook/facebookconnectwidget.h b/desktop-widgets/plugins/facebook/facebookconnectwidget.h index 39c637a..e3b8b12 100644 --- a/desktop-widgets/plugins/facebook/facebookconnectwidget.h +++ b/desktop-widgets/plugins/facebook/facebookconnectwidget.h @@ -8,32 +8,8 @@ namespace Ui { class SocialnetworksDialog; } -class FacebookManager : public QObject +class FacebookConnectWidget : public QDialog { - Q_OBJECT -public: - static FacebookManager *instance(); - void requestAlbumId(); - void requestUserId(); - 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); @@ -44,7 +20,8 @@ private: QWebView *facebookWebView; }; -class SocialNetworkDialog : public QDialog { +class SocialNetworkDialog : public QDialog +{ Q_OBJECT public: SocialNetworkDialog(QWidget *parent = 0); @@ -53,9 +30,31 @@ public: public slots: void selectionChanged(); void albumChanged(); + void clearDialog(); private: Ui::SocialnetworksDialog *ui; - void enableCheckboxes(); + void enableCheckboxes(bool enable); }; +class FacebookManager : public QObject +{ + Q_OBJECT +public: + static FacebookManager *instance(); + void requestAlbumId(); + void requestUserId(); + 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(SocialNetworkDialog *dialog); +private: + explicit FacebookManager(QObject *parent = 0); + QString albumName; +}; #endif -- 2.10.0
From c7ac6302ba5bcadf88aaf780a3899ae56850f3cf Mon Sep 17 00:00:00 2001 From: Edi Anderson Lobo <ediandersonl...@gmail.com> Date: Mon, 17 Oct 2016 20:44:31 -0200 Subject: [PATCH 5/5] Removed call to widget. Removed call to widget (SocialNetworkDialog) because it was called twice, an in FacebookPlugin::requestUpload() and after this, was called again in FacebookManager::sendDive, method responsible by send data to facebook. So,I pass an pointer of type SocialNetworkDialog to FacebookManager::sendDive and call the widget SocialNetworkDialog inside it, to send data. Signed-off-by: Edi Anderson Lobo <ediandersonl...@gmail.com> --- desktop-widgets/plugins/facebook/facebook_integration.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp index 58d757e..a0464d1 100644 --- a/desktop-widgets/plugins/facebook/facebook_integration.cpp +++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp @@ -7,7 +7,7 @@ FacebookPlugin::FacebookPlugin(QObject* parent) : fbConnectWidget(new FacebookConnectWidget()), fbUploadDialog(new SocialNetworkDialog()) { - Q_UNUSED(parent) + Q_UNUSED(parent); } bool FacebookPlugin::isConnected() @@ -39,6 +39,7 @@ QString FacebookPlugin::socialNetworkName() const void FacebookPlugin::requestUpload() { FacebookManager *instance = FacebookManager::instance(); - if (instance->loggedIn()) - fbUploadDialog->exec(); + if (instance->loggedIn()) { + instance->sendDive(fbUploadDialog); + } } -- 2.10.0
From d0cb55194f92a927268878dd06ccbcd90843be36 Mon Sep 17 00:00:00 2001 From: Edi Anderson Lobo <ediandersonl...@gmail.com> Date: Mon, 17 Oct 2016 19:46:27 -0200 Subject: [PATCH 3/5] Change menu name dynamically. Associated an QAction *toggle_connection with the QMenu *connections to ensure that QAction don't be orphan. In this way, I can change the name of menu dynamically. In this way when user click on menu (Share on -> Connect to) it be changed to (Share on-> Disconnet to) and so on. Signed-off-by: Edi Anderson Lobo <ediandersonl...@gmail.com> --- desktop-widgets/mainwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 33151ef..802f722 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -335,7 +335,7 @@ void MainWindow::setupSocialNetworkMenu() #ifdef FBSUPPORT QMenu *connections = new QMenu(tr("Connect to")); FacebookPlugin *facebookPlugin = new FacebookPlugin(); - QAction *toggle_connection = new QAction(this); + QAction *toggle_connection = new QAction(connections); QObject *obj = qobject_cast<QObject*>(facebookPlugin); toggle_connection->setText(facebookPlugin->socialNetworkName()); toggle_connection->setIcon(QIcon(facebookPlugin->socialNetworkIcon())); @@ -363,6 +363,7 @@ void MainWindow::socialNetworkRequestConnect() plugin->requestLogoff(); else plugin->requestLogin(); + qobject_cast<QMenu*>(action->parentWidget())->setTitle(plugin->isConnected() ? tr("Disconnect to") : tr("Connect to")); } void MainWindow::socialNetworkRequestUpload() -- 2.10.0
_______________________________________________ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface