2013-05-24 18:19:48 +00:00
|
|
|
#include "preferences.h"
|
2013-11-30 17:18:04 +00:00
|
|
|
#include "mainwindow.h"
|
2015-02-09 20:27:59 +00:00
|
|
|
#include "models.h"
|
2015-06-22 21:44:05 +00:00
|
|
|
#include "divelocationmodel.h"
|
2015-07-26 05:08:25 +00:00
|
|
|
#include "prefs-macros.h"
|
|
|
|
#include "qthelper.h"
|
2015-10-06 09:15:38 +00:00
|
|
|
#include "subsurfacestartup.h"
|
2015-02-09 20:27:59 +00:00
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
#include <QSettings>
|
2013-10-14 04:19:13 +00:00
|
|
|
#include <QFileDialog>
|
2013-12-06 16:29:38 +00:00
|
|
|
#include <QMessageBox>
|
2014-04-25 18:32:02 +00:00
|
|
|
#include <QShortcut>
|
2014-06-26 12:45:14 +00:00
|
|
|
#include <QNetworkProxy>
|
2014-12-23 21:29:00 +00:00
|
|
|
#include <QNetworkCookieJar>
|
2015-01-16 19:43:49 +00:00
|
|
|
|
2015-06-05 00:26:30 +00:00
|
|
|
#include "subsurfacewebservices.h"
|
|
|
|
|
2015-07-06 19:11:07 +00:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2014-12-24 23:34:23 +00:00
|
|
|
#include "socialnetworks.h"
|
2015-01-13 18:39:05 +00:00
|
|
|
#include <QWebView>
|
|
|
|
#endif
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
PreferencesDialog *PreferencesDialog::instance()
|
2013-05-24 18:19:48 +00:00
|
|
|
{
|
2014-02-12 14:22:54 +00:00
|
|
|
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
2013-05-24 18:19:48 +00:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
2013-05-24 18:19:48 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
2015-10-06 22:01:00 +00:00
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
2015-01-13 18:39:05 +00:00
|
|
|
|
2015-01-31 06:08:50 +00:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2014-12-24 23:34:23 +00:00
|
|
|
FacebookManager *fb = FacebookManager::instance();
|
2015-01-31 06:10:21 +00:00
|
|
|
facebookWebView = new QWebView(this);
|
2015-09-16 19:43:01 +00:00
|
|
|
ui.fbWebviewContainer->layout()->addWidget(facebookWebView);
|
2015-01-31 06:10:21 +00:00
|
|
|
if (fb->loggedIn()) {
|
|
|
|
facebookLoggedIn();
|
2014-12-23 21:10:57 +00:00
|
|
|
} else {
|
2015-01-31 06:10:21 +00:00
|
|
|
facebookDisconnect();
|
2014-12-23 21:10:57 +00:00
|
|
|
}
|
2015-01-13 18:39:05 +00:00
|
|
|
connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin);
|
2014-12-24 23:34:23 +00:00
|
|
|
connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn);
|
2015-09-16 19:43:01 +00:00
|
|
|
connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout);
|
2014-12-24 23:34:23 +00:00
|
|
|
connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect);
|
2015-01-13 18:39:05 +00:00
|
|
|
#endif
|
2015-10-01 22:48:57 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2015-10-01 21:59:53 +00:00
|
|
|
|
2015-01-13 18:39:05 +00:00
|
|
|
// connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double)));
|
2014-04-25 18:32:02 +00:00
|
|
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
|
|
|
connect(close, SIGNAL(activated()), this, SLOT(close()));
|
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
|
|
|
connect(quit, SIGNAL(activated()), parent, SLOT(close()));
|
2014-02-08 17:07:06 +00:00
|
|
|
loadSettings();
|
2013-06-03 12:08:49 +00:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-02 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-24 23:34:23 +00:00
|
|
|
void PreferencesDialog::facebookLoggedIn()
|
2014-12-23 22:56:51 +00:00
|
|
|
{
|
2015-07-06 19:11:07 +00:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2015-09-16 19:43:01 +00:00
|
|
|
ui.fbDisconnect->show();
|
|
|
|
ui.fbWebviewContainer->hide();
|
|
|
|
ui.fbWebviewContainer->setEnabled(false);
|
2015-01-31 06:10:21 +00:00
|
|
|
ui.FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below"));
|
2015-01-13 18:39:05 +00:00
|
|
|
#endif
|
2014-12-23 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 21:29:00 +00:00
|
|
|
void PreferencesDialog::facebookDisconnect()
|
|
|
|
{
|
2015-01-16 19:43:49 +00:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2015-02-02 15:52:35 +00:00
|
|
|
// remove the connect/disconnect button
|
2015-01-31 06:10:21 +00:00
|
|
|
// and instead add the login view
|
2015-09-16 19:43:01 +00:00
|
|
|
ui.fbDisconnect->hide();
|
|
|
|
ui.fbWebviewContainer->show();
|
|
|
|
ui.fbWebviewContainer->setEnabled(true);
|
2015-01-31 06:10:21 +00:00
|
|
|
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());
|
|
|
|
}
|
2015-01-13 18:39:05 +00:00
|
|
|
#endif
|
2014-12-23 21:29:00 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 20:58:50 +00:00
|
|
|
void PreferencesDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
2013-06-03 12:08:49 +00:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-02 20:58:50 +00:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::setUiFromPrefs()
|
2013-06-02 20:58:50 +00:00
|
|
|
{
|
2015-09-25 19:15:37 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
}
|
2013-05-24 18:19:48 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::restorePrefs()
|
|
|
|
{
|
|
|
|
prefs = oldPrefs;
|
2013-11-20 12:40:14 +00:00
|
|
|
setUiFromPrefs();
|
2013-06-03 12:08:49 +00:00
|
|
|
}
|
2013-05-24 18:19:48 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::rememberPrefs()
|
|
|
|
{
|
|
|
|
oldPrefs = prefs;
|
2013-05-28 18:21:27 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
void PreferencesDialog::syncSettings()
|
|
|
|
{
|
2014-02-08 17:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialog::loadSettings()
|
|
|
|
{
|
2015-01-10 22:32:36 +00:00
|
|
|
// This code was on the mainwindow, it should belong nowhere, but since we didn't
|
2014-02-06 16:18:00 +00:00
|
|
|
// correctly fixed this code yet ( too much stuff on the code calling preferences )
|
|
|
|
// force this here.
|
2015-07-26 05:08:25 +00:00
|
|
|
loadPreferences();
|
2014-02-08 17:07:06 +00:00
|
|
|
QSettings s;
|
2014-02-06 16:18:00 +00:00
|
|
|
QVariant v;
|
2013-05-24 18:19:48 +00:00
|
|
|
}
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void PreferencesDialog::buttonClicked(QAbstractButton *button)
|
2013-06-02 20:58:50 +00:00
|
|
|
{
|
2014-01-16 04:50:56 +00:00
|
|
|
switch (ui.buttonBox->standardButton(button)) {
|
2013-06-02 20:58:50 +00:00
|
|
|
case QDialogButtonBox::Discard:
|
2013-06-03 12:08:49 +00:00
|
|
|
restorePrefs();
|
2014-04-07 17:12:34 +00:00
|
|
|
syncSettings();
|
2013-06-02 20:58:50 +00:00
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
|
|
|
syncSettings();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::FirstButton:
|
|
|
|
syncSettings();
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break; // ignore warnings.
|
|
|
|
}
|
|
|
|
}
|
2013-05-28 18:21:27 +00:00
|
|
|
#undef SB
|
2013-10-14 04:19:13 +00:00
|
|
|
|
2015-10-09 21:11:18 +00:00
|
|
|
#if 0
|
|
|
|
// TODO: Copy this later.
|
2014-06-25 09:46:51 +00:00
|
|
|
void PreferencesDialog::on_resetSettings_clicked()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
QMessageBox response(this);
|
|
|
|
response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
response.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
response.setWindowTitle(tr("Warning"));
|
2014-07-10 23:06:50 +00:00
|
|
|
response.setText(tr("If you click OK, all settings of Subsurface will be reset to their default values. This will be applied immediately."));
|
2014-06-25 09:46:51 +00:00
|
|
|
response.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
int result = response.exec();
|
|
|
|
if (result == QMessageBox::Ok) {
|
2015-10-06 09:15:38 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2014-06-25 09:46:51 +00:00
|
|
|
setUiFromPrefs();
|
2014-07-15 17:43:20 +00:00
|
|
|
Q_FOREACH (QString key, s.allKeys()) {
|
2014-06-25 09:46:51 +00:00
|
|
|
s.remove(key);
|
|
|
|
}
|
|
|
|
syncSettings();
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 21:11:18 +00:00
|
|
|
#endif
|
2014-06-25 09:46:51 +00:00
|
|
|
|
2014-02-06 13:38:28 +00:00
|
|
|
void PreferencesDialog::emitSettingsChanged()
|
|
|
|
{
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|