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-16 19:43:49 +00:00
|
|
|
#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT)
|
2015-01-13 18:39:05 +00:00
|
|
|
for (int i = 0; i < ui.listWidget->count(); i++) {
|
2015-09-16 21:36:23 +00:00
|
|
|
if (ui.listWidget->item(i)->text() == "Facebook") {
|
2015-01-13 18:39:05 +00:00
|
|
|
delete ui.listWidget->item(i);
|
2015-09-16 21:36:23 +00:00
|
|
|
QWidget *fbpage = ui.stackedWidget->widget(i);
|
|
|
|
ui.stackedWidget->removeWidget(fbpage);
|
|
|
|
}
|
2015-01-13 18:39:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-26 12:45:14 +00:00
|
|
|
ui.proxyType->clear();
|
|
|
|
ui.proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy);
|
|
|
|
ui.proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy);
|
|
|
|
ui.proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy);
|
|
|
|
ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy);
|
2014-06-26 16:17:50 +00:00
|
|
|
ui.proxyType->setCurrentIndex(-1);
|
2014-12-23 19:51:45 +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
|
2014-06-28 11:01:51 +00:00
|
|
|
connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int)));
|
2014-02-28 04:09:57 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2013-12-04 23:48:37 +00:00
|
|
|
connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int)));
|
|
|
|
connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int)));
|
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
|
|
|
}
|
|
|
|
|
2015-06-14 20:50:13 +00:00
|
|
|
void PreferencesDialog::cloudPinNeeded()
|
2015-06-07 16:54:28 +00:00
|
|
|
{
|
2015-06-14 20:50:13 +00:00
|
|
|
ui.cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY);
|
|
|
|
ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY);
|
|
|
|
ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY);
|
|
|
|
ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY);
|
2015-07-22 14:34:36 +00:00
|
|
|
ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED);
|
|
|
|
ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED);
|
|
|
|
ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED);
|
|
|
|
ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED);
|
2015-06-14 22:42:28 +00:00
|
|
|
if (prefs.cloud_verification_status == CS_VERIFIED) {
|
2015-06-14 21:06:44 +00:00
|
|
|
ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)"));
|
2015-06-14 22:42:28 +00:00
|
|
|
} else {
|
2015-06-14 21:06:44 +00:00
|
|
|
ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage"));
|
2015-06-14 22:42:28 +00:00
|
|
|
}
|
|
|
|
MainWindow::instance()->enableDisableCloudActions();
|
2015-06-07 16:54:28 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
#define DANGER_GF (gf > 100) ? "* { color: red; }" : ""
|
2013-12-04 23:48:37 +00:00
|
|
|
void PreferencesDialog::gflowChanged(int gf)
|
|
|
|
{
|
2013-12-06 16:35:23 +00:00
|
|
|
ui.gflow->setStyleSheet(DANGER_GF);
|
2013-12-04 23:48:37 +00:00
|
|
|
}
|
|
|
|
void PreferencesDialog::gfhighChanged(int gf)
|
|
|
|
{
|
2013-12-06 16:35:23 +00:00
|
|
|
ui.gfhigh->setStyleSheet(DANGER_GF);
|
2013-12-04 23:48:37 +00:00
|
|
|
}
|
2013-12-06 16:35:23 +00:00
|
|
|
#undef DANGER_GF
|
2013-12-04 23:48:37 +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
|
|
|
{
|
2013-06-03 12:08:49 +00:00
|
|
|
// graphs
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.pheThreshold->setValue(prefs.pp_graphs.phe_threshold);
|
|
|
|
ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold);
|
|
|
|
ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold);
|
2014-06-22 14:41:44 +00:00
|
|
|
ui.maxpo2->setValue(prefs.modpO2);
|
2014-04-16 20:03:44 +00:00
|
|
|
ui.red_ceiling->setChecked(prefs.redceiling);
|
2013-10-03 18:54:25 +00:00
|
|
|
|
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2013-11-20 15:11:22 +00:00
|
|
|
ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth);
|
2015-01-05 07:20:26 +00:00
|
|
|
ui.show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint);
|
2015-01-20 18:13:53 +00:00
|
|
|
ui.show_ccr_sensors->setChecked(prefs.show_ccr_sensors);
|
2015-01-10 22:32:36 +00:00
|
|
|
ui.defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0);
|
2015-01-19 14:28:56 +00:00
|
|
|
ui.psro2rate->setValue(prefs.o2consumption / 1000.0);
|
|
|
|
ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio));
|
2013-06-03 12:08:49 +00:00
|
|
|
|
2014-01-11 14:57:06 +00:00
|
|
|
ui.display_unused_tanks->setChecked(prefs.display_unused_tanks);
|
2014-03-27 18:38:07 +00:00
|
|
|
ui.show_average_depth->setChecked(prefs.show_average_depth);
|
2015-09-25 19:15:37 +00:00
|
|
|
|
2013-12-06 16:29:38 +00:00
|
|
|
QSettings s;
|
2014-04-11 06:17:35 +00:00
|
|
|
|
|
|
|
ui.save_uid_local->setChecked(s.value("save_uid_local").toBool());
|
|
|
|
ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper());
|
|
|
|
|
2014-06-26 16:17:50 +00:00
|
|
|
ui.proxyHost->setText(prefs.proxy_host);
|
|
|
|
ui.proxyPort->setValue(prefs.proxy_port);
|
|
|
|
ui.proxyAuthRequired->setChecked(prefs.proxy_auth);
|
|
|
|
ui.proxyUsername->setText(prefs.proxy_user);
|
|
|
|
ui.proxyPassword->setText(prefs.proxy_pass);
|
|
|
|
ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type));
|
2015-09-25 19:15:37 +00:00
|
|
|
|
2015-05-28 19:19:19 +00:00
|
|
|
|
2015-06-01 00:42:12 +00:00
|
|
|
ui.cloud_storage_email->setText(prefs.cloud_storage_email);
|
|
|
|
ui.cloud_storage_password->setText(prefs.cloud_storage_password);
|
|
|
|
ui.save_password_local->setChecked(prefs.save_password_local);
|
2015-06-14 20:50:13 +00:00
|
|
|
cloudPinNeeded();
|
2015-06-12 18:48:56 +00:00
|
|
|
ui.cloud_background_sync->setChecked(prefs.cloud_background_sync);
|
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()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
|
2014-04-11 06:17:35 +00:00
|
|
|
s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper());
|
|
|
|
set_save_userid_local(ui.save_uid_local->checkState());
|
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
// Graph
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("TecDetails");
|
2014-08-27 13:59:36 +00:00
|
|
|
SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui.pheThreshold->value());
|
|
|
|
SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui.po2Threshold->value());
|
|
|
|
SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui.pn2Threshold->value());
|
|
|
|
SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui.maxpo2->value());
|
|
|
|
SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui.red_ceiling->isChecked());
|
|
|
|
SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui.gflow->value());
|
|
|
|
SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui.gfhigh->value());
|
|
|
|
SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui.gf_low_at_maxdepth->isChecked());
|
2015-01-05 07:20:26 +00:00
|
|
|
SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui.show_ccr_setpoint->isChecked());
|
2015-01-20 18:13:53 +00:00
|
|
|
SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui.show_ccr_sensors->isChecked());
|
2014-08-27 13:59:36 +00:00
|
|
|
SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui.display_unused_tanks->isChecked());
|
|
|
|
SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked());
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
// Defaults
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("GeneralSettings");
|
2015-01-19 14:28:56 +00:00
|
|
|
s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0));
|
|
|
|
s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0));
|
|
|
|
s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value()));
|
2013-11-20 12:40:14 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
2014-06-26 16:17:50 +00:00
|
|
|
s.beginGroup("Network");
|
|
|
|
s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt());
|
|
|
|
s.setValue("proxy_host", ui.proxyHost->text());
|
|
|
|
s.setValue("proxy_port", ui.proxyPort->value());
|
|
|
|
SB("proxy_auth", ui.proxyAuthRequired);
|
|
|
|
s.setValue("proxy_user", ui.proxyUsername->text());
|
|
|
|
s.setValue("proxy_pass", ui.proxyPassword->text());
|
|
|
|
s.endGroup();
|
|
|
|
|
2015-06-01 00:42:12 +00:00
|
|
|
s.beginGroup("CloudStorage");
|
2015-06-05 00:26:30 +00:00
|
|
|
QString email = ui.cloud_storage_email->text();
|
|
|
|
QString password = ui.cloud_storage_password->text();
|
2015-07-22 18:10:40 +00:00
|
|
|
QString newpassword = ui.cloud_storage_new_passwd->text();
|
|
|
|
if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) {
|
|
|
|
// deal with password change
|
|
|
|
if (!email.isEmpty() && !password.isEmpty()) {
|
|
|
|
// connect to backend server to check / create credentials
|
|
|
|
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
|
|
|
if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
|
|
|
|
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
|
|
|
|
} else {
|
|
|
|
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
|
|
|
|
connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
|
2015-07-22 22:06:57 +00:00
|
|
|
connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull()));
|
2015-07-22 18:10:40 +00:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword);
|
|
|
|
ui.cloud_storage_new_passwd->setText("");
|
2015-07-22 22:06:57 +00:00
|
|
|
free(prefs.cloud_storage_newpassword);
|
|
|
|
prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword));
|
2015-07-22 18:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (prefs.cloud_verification_status == CS_UNKNOWN ||
|
|
|
|
prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD ||
|
|
|
|
email != prefs.cloud_storage_email ||
|
|
|
|
password != prefs.cloud_storage_password) {
|
|
|
|
|
2015-06-14 20:50:13 +00:00
|
|
|
// different credentials - reset verification status
|
|
|
|
prefs.cloud_verification_status = CS_UNKNOWN;
|
2015-06-22 13:24:16 +00:00
|
|
|
if (!email.isEmpty() && !password.isEmpty()) {
|
|
|
|
// connect to backend server to check / create credentials
|
|
|
|
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
2015-07-06 20:59:14 +00:00
|
|
|
if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
|
2015-06-22 13:24:16 +00:00
|
|
|
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
|
|
|
|
} else {
|
|
|
|
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
|
|
|
|
connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
|
2015-07-22 18:10:40 +00:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password);
|
2015-06-22 13:24:16 +00:00
|
|
|
}
|
2015-06-14 20:50:13 +00:00
|
|
|
}
|
|
|
|
} else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
|
2015-06-09 18:21:03 +00:00
|
|
|
QString pin = ui.cloud_storage_pin->text();
|
|
|
|
if (!pin.isEmpty()) {
|
|
|
|
// connect to backend server to check / create credentials
|
|
|
|
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
|
|
|
if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) {
|
|
|
|
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
|
|
|
|
}
|
|
|
|
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
|
2015-06-22 21:04:31 +00:00
|
|
|
connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
|
2015-07-22 18:10:40 +00:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password, pin);
|
2015-06-09 18:21:03 +00:00
|
|
|
}
|
2015-06-05 00:26:30 +00:00
|
|
|
}
|
|
|
|
SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email);
|
2015-06-01 00:42:12 +00:00
|
|
|
SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked());
|
2015-06-12 14:02:51 +00:00
|
|
|
if (ui.save_password_local->isChecked()) {
|
2015-06-05 00:26:30 +00:00
|
|
|
SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password);
|
2015-06-12 14:02:51 +00:00
|
|
|
} else {
|
2015-06-01 00:42:12 +00:00
|
|
|
s.remove("password");
|
2015-06-12 14:02:51 +00:00
|
|
|
free(prefs.cloud_storage_password);
|
|
|
|
prefs.cloud_storage_password = strdup(qPrintable(password));
|
|
|
|
}
|
2015-06-14 20:50:13 +00:00
|
|
|
SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status);
|
2015-06-12 18:48:56 +00:00
|
|
|
SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked());
|
|
|
|
|
2015-06-15 12:52:12 +00:00
|
|
|
// at this point we intentionally do not have a UI for changing this
|
|
|
|
// it could go into some sort of "advanced setup" or something
|
|
|
|
SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url);
|
2015-05-28 19:19:19 +00:00
|
|
|
s.endGroup();
|
2015-06-22 21:44:05 +00:00
|
|
|
|
2015-09-25 19:25:05 +00:00
|
|
|
<<<<<<< HEAD
|
2015-06-22 21:44:05 +00:00
|
|
|
s.beginGroup("geocoding");
|
2015-10-05 22:02:55 +00:00
|
|
|
#ifdef DISABLED
|
2015-06-22 21:44:05 +00:00
|
|
|
s.setValue("enable_geocoding", ui.enable_geocoding->isChecked());
|
2015-10-05 22:02:55 +00:00
|
|
|
s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked());
|
2015-06-22 21:44:05 +00:00
|
|
|
s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked());
|
2015-10-05 22:02:55 +00:00
|
|
|
#endif
|
2015-07-01 19:32:46 +00:00
|
|
|
s.setValue("cat0", ui.first_item->currentIndex());
|
|
|
|
s.setValue("cat1", ui.second_item->currentIndex());
|
|
|
|
s.setValue("cat2", ui.third_item->currentIndex());
|
2015-06-22 21:44:05 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
2015-09-25 19:25:05 +00:00
|
|
|
=======
|
|
|
|
>>>>>>> Code Cleanup
|
2014-02-08 17:07:06 +00:00
|
|
|
loadSettings();
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2014-04-11 06:17:35 +00:00
|
|
|
|
|
|
|
ui.save_uid_local->setChecked(s.value("save_uid_local").toBool());
|
|
|
|
ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper());
|
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
|
|
|
|
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-07-22 22:06:57 +00:00
|
|
|
void PreferencesDialog::passwordUpdateSuccessfull()
|
|
|
|
{
|
|
|
|
ui.cloud_storage_password->setText(prefs.cloud_storage_password);
|
|
|
|
}
|
|
|
|
|
2014-02-06 13:38:28 +00:00
|
|
|
void PreferencesDialog::emitSettingsChanged()
|
|
|
|
{
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
2014-06-26 12:45:14 +00:00
|
|
|
|
2014-06-28 11:01:51 +00:00
|
|
|
void PreferencesDialog::proxyType_changed(int idx)
|
2014-06-26 12:45:14 +00:00
|
|
|
{
|
|
|
|
if (idx == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int proxyType = ui.proxyType->itemData(idx).toInt();
|
|
|
|
bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy);
|
|
|
|
ui.proxyHost->setEnabled(hpEnabled);
|
|
|
|
ui.proxyPort->setEnabled(hpEnabled);
|
|
|
|
ui.proxyAuthRequired->setEnabled(hpEnabled);
|
|
|
|
ui.proxyUsername->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked());
|
|
|
|
ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked());
|
|
|
|
ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked());
|
|
|
|
}
|