2013-05-24 15:19:48 -03:00
|
|
|
#include "preferences.h"
|
2013-11-30 09:18:04 -08:00
|
|
|
#include "mainwindow.h"
|
2015-02-09 18:27:59 -02:00
|
|
|
#include "models.h"
|
2015-06-22 18:44:05 -03:00
|
|
|
#include "divelocationmodel.h"
|
2015-07-25 22:08:25 -07:00
|
|
|
#include "prefs-macros.h"
|
|
|
|
#include "qthelper.h"
|
2015-10-06 10:15:38 +01:00
|
|
|
#include "subsurfacestartup.h"
|
2015-02-09 18:27:59 -02:00
|
|
|
|
2013-05-24 15:19:48 -03:00
|
|
|
#include <QSettings>
|
2013-10-14 07:19:13 +03:00
|
|
|
#include <QFileDialog>
|
2013-12-06 14:29:38 -02:00
|
|
|
#include <QMessageBox>
|
2014-04-25 20:32:02 +02:00
|
|
|
#include <QShortcut>
|
2014-06-26 16:45:14 +04:00
|
|
|
#include <QNetworkProxy>
|
2014-12-23 19:29:00 -02:00
|
|
|
#include <QNetworkCookieJar>
|
2015-01-17 08:43:49 +13:00
|
|
|
|
2015-06-04 17:26:30 -07:00
|
|
|
#include "subsurfacewebservices.h"
|
|
|
|
|
2015-07-06 12:11:07 -07:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2014-12-24 21:34:23 -02:00
|
|
|
#include "socialnetworks.h"
|
2015-01-13 21:39:05 +03:00
|
|
|
#include <QWebView>
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
PreferencesDialog *PreferencesDialog::instance()
|
2013-05-24 15:19:48 -03:00
|
|
|
{
|
2014-02-12 15:22:54 +01:00
|
|
|
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
2013-05-24 15:19:48 -03:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
|
2013-05-24 15:19:48 -03:00
|
|
|
{
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.setupUi(this);
|
2015-10-06 19:01:00 -03:00
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
2015-01-13 21:39:05 +03:00
|
|
|
|
2015-01-17 08:43:49 +13:00
|
|
|
#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT)
|
2015-01-13 21:39:05 +03:00
|
|
|
for (int i = 0; i < ui.listWidget->count(); i++) {
|
2015-09-16 18:36:23 -03:00
|
|
|
if (ui.listWidget->item(i)->text() == "Facebook") {
|
2015-01-13 21:39:05 +03:00
|
|
|
delete ui.listWidget->item(i);
|
2015-09-16 18:36:23 -03:00
|
|
|
QWidget *fbpage = ui.stackedWidget->widget(i);
|
|
|
|
ui.stackedWidget->removeWidget(fbpage);
|
|
|
|
}
|
2015-01-13 21:39:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-26 16:45:14 +04: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 20:17:50 +04:00
|
|
|
ui.proxyType->setCurrentIndex(-1);
|
2014-12-23 17:51:45 -02:00
|
|
|
|
2015-01-30 22:08:50 -08:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2014-12-24 21:34:23 -02:00
|
|
|
FacebookManager *fb = FacebookManager::instance();
|
2015-01-30 22:10:21 -08:00
|
|
|
facebookWebView = new QWebView(this);
|
2015-09-16 16:43:01 -03:00
|
|
|
ui.fbWebviewContainer->layout()->addWidget(facebookWebView);
|
2015-01-30 22:10:21 -08:00
|
|
|
if (fb->loggedIn()) {
|
|
|
|
facebookLoggedIn();
|
2014-12-23 19:10:57 -02:00
|
|
|
} else {
|
2015-01-30 22:10:21 -08:00
|
|
|
facebookDisconnect();
|
2014-12-23 19:10:57 -02:00
|
|
|
}
|
2015-01-13 21:39:05 +03:00
|
|
|
connect(facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin);
|
2014-12-24 21:34:23 -02:00
|
|
|
connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn);
|
2015-09-16 16:43:01 -03:00
|
|
|
connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout);
|
2014-12-24 21:34:23 -02:00
|
|
|
connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect);
|
2015-01-13 21:39:05 +03:00
|
|
|
#endif
|
2014-06-28 15:01:51 +04:00
|
|
|
connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int)));
|
2014-02-27 20:09:57 -08:00
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
|
2015-10-01 18:59:53 -03:00
|
|
|
|
2015-01-13 21:39:05 +03:00
|
|
|
// connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double)));
|
2014-04-25 20:32:02 +02: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 18:07:06 +01:00
|
|
|
loadSettings();
|
2013-06-03 21:08:49 +09:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-03 05:58:50 +09:00
|
|
|
}
|
|
|
|
|
2014-12-24 21:34:23 -02:00
|
|
|
void PreferencesDialog::facebookLoggedIn()
|
2014-12-23 20:56:51 -02:00
|
|
|
{
|
2015-07-06 12:11:07 -07:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2015-09-16 16:43:01 -03:00
|
|
|
ui.fbDisconnect->show();
|
|
|
|
ui.fbWebviewContainer->hide();
|
|
|
|
ui.fbWebviewContainer->setEnabled(false);
|
2015-01-30 22:10:21 -08:00
|
|
|
ui.FBLabel->setText(tr("To disconnect Subsurface from your Facebook account, use the button below"));
|
2015-01-13 21:39:05 +03:00
|
|
|
#endif
|
2014-12-23 20:56:51 -02:00
|
|
|
}
|
|
|
|
|
2014-12-23 19:29:00 -02:00
|
|
|
void PreferencesDialog::facebookDisconnect()
|
|
|
|
{
|
2015-01-17 08:43:49 +13:00
|
|
|
#if !defined(Q_OS_ANDROID) && defined(FBSUPPORT)
|
2015-02-02 16:52:35 +01:00
|
|
|
// remove the connect/disconnect button
|
2015-01-30 22:10:21 -08:00
|
|
|
// and instead add the login view
|
2015-09-16 16:43:01 -03:00
|
|
|
ui.fbDisconnect->hide();
|
|
|
|
ui.fbWebviewContainer->show();
|
|
|
|
ui.fbWebviewContainer->setEnabled(true);
|
2015-01-30 22:10:21 -08: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 21:39:05 +03:00
|
|
|
#endif
|
2014-12-23 19:29:00 -02:00
|
|
|
}
|
|
|
|
|
2015-06-14 13:50:13 -07:00
|
|
|
void PreferencesDialog::cloudPinNeeded()
|
2015-06-07 09:54:28 -07:00
|
|
|
{
|
2015-06-14 13:50:13 -07: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 07:34:36 -07: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 15:42:28 -07:00
|
|
|
if (prefs.cloud_verification_status == CS_VERIFIED) {
|
2015-06-14 14:06:44 -07:00
|
|
|
ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)"));
|
2015-06-14 15:42:28 -07:00
|
|
|
} else {
|
2015-06-14 14:06:44 -07:00
|
|
|
ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage"));
|
2015-06-14 15:42:28 -07:00
|
|
|
}
|
|
|
|
MainWindow::instance()->enableDisableCloudActions();
|
2015-06-07 09:54:28 -07:00
|
|
|
}
|
|
|
|
|
2013-06-03 05:58:50 +09:00
|
|
|
void PreferencesDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
2013-06-03 21:08:49 +09:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-03 05:58:50 +09:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-06-03 21:08:49 +09:00
|
|
|
void PreferencesDialog::setUiFromPrefs()
|
2013-06-03 05:58:50 +09:00
|
|
|
{
|
2013-12-06 14:29:38 -02:00
|
|
|
QSettings s;
|
2014-04-11 11:47:35 +05:30
|
|
|
|
|
|
|
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 20:17:50 +04: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 16:15:37 -03:00
|
|
|
|
2015-05-28 12:19:19 -07:00
|
|
|
|
2015-05-31 17:42:12 -07: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 13:50:13 -07:00
|
|
|
cloudPinNeeded();
|
2015-06-12 11:48:56 -07:00
|
|
|
ui.cloud_background_sync->setChecked(prefs.cloud_background_sync);
|
2013-06-03 21:08:49 +09:00
|
|
|
}
|
2013-05-24 15:19:48 -03:00
|
|
|
|
2013-06-03 21:08:49 +09:00
|
|
|
void PreferencesDialog::restorePrefs()
|
|
|
|
{
|
|
|
|
prefs = oldPrefs;
|
2013-11-20 13:40:14 +01:00
|
|
|
setUiFromPrefs();
|
2013-06-03 21:08:49 +09:00
|
|
|
}
|
2013-05-24 15:19:48 -03:00
|
|
|
|
2013-06-03 21:08:49 +09:00
|
|
|
void PreferencesDialog::rememberPrefs()
|
|
|
|
{
|
|
|
|
oldPrefs = prefs;
|
2013-05-28 11:21:27 -07:00
|
|
|
}
|
|
|
|
|
2013-05-24 15:19:48 -03:00
|
|
|
void PreferencesDialog::syncSettings()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
|
2014-04-11 11:47:35 +05:30
|
|
|
s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper());
|
|
|
|
set_save_userid_local(ui.save_uid_local->checkState());
|
|
|
|
|
2014-06-26 20:17:50 +04: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-05-31 17:42:12 -07:00
|
|
|
s.beginGroup("CloudStorage");
|
2015-06-04 17:26:30 -07:00
|
|
|
QString email = ui.cloud_storage_email->text();
|
|
|
|
QString password = ui.cloud_storage_password->text();
|
2015-07-22 11:10:40 -07: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 15:06:57 -07:00
|
|
|
connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull()));
|
2015-07-22 11:10:40 -07:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword);
|
|
|
|
ui.cloud_storage_new_passwd->setText("");
|
2015-07-22 15:06:57 -07:00
|
|
|
free(prefs.cloud_storage_newpassword);
|
|
|
|
prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword));
|
2015-07-22 11:10:40 -07: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 13:50:13 -07:00
|
|
|
// different credentials - reset verification status
|
|
|
|
prefs.cloud_verification_status = CS_UNKNOWN;
|
2015-06-22 06:24:16 -07:00
|
|
|
if (!email.isEmpty() && !password.isEmpty()) {
|
|
|
|
// connect to backend server to check / create credentials
|
|
|
|
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
|
2015-07-06 13:59:14 -07:00
|
|
|
if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) {
|
2015-06-22 06:24:16 -07: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 11:10:40 -07:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password);
|
2015-06-22 06:24:16 -07:00
|
|
|
}
|
2015-06-14 13:50:13 -07:00
|
|
|
}
|
|
|
|
} else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
|
2015-06-09 11:21:03 -07: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 14:04:31 -07:00
|
|
|
connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded()));
|
2015-07-22 11:10:40 -07:00
|
|
|
QNetworkReply *reply = cloudAuth->backend(email, password, pin);
|
2015-06-09 11:21:03 -07:00
|
|
|
}
|
2015-06-04 17:26:30 -07:00
|
|
|
}
|
|
|
|
SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email);
|
2015-05-31 17:42:12 -07:00
|
|
|
SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked());
|
2015-06-12 07:02:51 -07:00
|
|
|
if (ui.save_password_local->isChecked()) {
|
2015-06-04 17:26:30 -07:00
|
|
|
SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password);
|
2015-06-12 07:02:51 -07:00
|
|
|
} else {
|
2015-05-31 17:42:12 -07:00
|
|
|
s.remove("password");
|
2015-06-12 07:02:51 -07:00
|
|
|
free(prefs.cloud_storage_password);
|
|
|
|
prefs.cloud_storage_password = strdup(qPrintable(password));
|
|
|
|
}
|
2015-06-14 13:50:13 -07:00
|
|
|
SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status);
|
2015-06-12 11:48:56 -07:00
|
|
|
SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked());
|
|
|
|
|
2015-06-15 05:52:12 -07: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 12:19:19 -07:00
|
|
|
s.endGroup();
|
2015-06-22 18:44:05 -03:00
|
|
|
|
2015-09-25 16:25:05 -03:00
|
|
|
<<<<<<< HEAD
|
2015-06-22 18:44:05 -03:00
|
|
|
s.beginGroup("geocoding");
|
2015-10-05 23:02:55 +01:00
|
|
|
#ifdef DISABLED
|
2015-06-22 18:44:05 -03:00
|
|
|
s.setValue("enable_geocoding", ui.enable_geocoding->isChecked());
|
2015-10-05 23:02:55 +01:00
|
|
|
s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked());
|
2015-06-22 18:44:05 -03:00
|
|
|
s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked());
|
2015-10-05 23:02:55 +01:00
|
|
|
#endif
|
2015-07-01 12:32:46 -07: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 18:44:05 -03:00
|
|
|
s.endGroup();
|
|
|
|
|
2015-09-25 16:25:05 -03:00
|
|
|
=======
|
|
|
|
>>>>>>> Code Cleanup
|
2014-02-08 18:07:06 +01:00
|
|
|
loadSettings();
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialog::loadSettings()
|
|
|
|
{
|
2015-01-10 23:32:36 +01:00
|
|
|
// This code was on the mainwindow, it should belong nowhere, but since we didn't
|
2014-02-06 14:18:00 -02:00
|
|
|
// correctly fixed this code yet ( too much stuff on the code calling preferences )
|
|
|
|
// force this here.
|
2015-07-25 22:08:25 -07:00
|
|
|
loadPreferences();
|
2014-02-08 18:07:06 +01:00
|
|
|
QSettings s;
|
2014-02-06 14:18:00 -02:00
|
|
|
QVariant v;
|
2014-04-11 11:47:35 +05:30
|
|
|
|
|
|
|
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 15:19:48 -03:00
|
|
|
}
|
2013-05-28 11:21:27 -07:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
void PreferencesDialog::buttonClicked(QAbstractButton *button)
|
2013-06-03 05:58:50 +09:00
|
|
|
{
|
2014-01-16 11:50:56 +07:00
|
|
|
switch (ui.buttonBox->standardButton(button)) {
|
2013-06-03 05:58:50 +09:00
|
|
|
case QDialogButtonBox::Discard:
|
2013-06-03 21:08:49 +09:00
|
|
|
restorePrefs();
|
2014-04-07 19:12:34 +02:00
|
|
|
syncSettings();
|
2013-06-03 05:58:50 +09:00
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
|
|
|
syncSettings();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::FirstButton:
|
|
|
|
syncSettings();
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break; // ignore warnings.
|
|
|
|
}
|
|
|
|
}
|
2013-05-28 11:21:27 -07:00
|
|
|
#undef SB
|
2013-10-14 07:19:13 +03:00
|
|
|
|
2014-06-25 17:46:51 +08: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-11 00:06:50 +01: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 17:46:51 +08:00
|
|
|
response.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
|
|
int result = response.exec();
|
|
|
|
if (result == QMessageBox::Ok) {
|
2015-10-06 10:15:38 +01:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2014-06-25 17:46:51 +08:00
|
|
|
setUiFromPrefs();
|
2014-07-15 14:43:20 -03:00
|
|
|
Q_FOREACH (QString key, s.allKeys()) {
|
2014-06-25 17:46:51 +08:00
|
|
|
s.remove(key);
|
|
|
|
}
|
|
|
|
syncSettings();
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 15:06:57 -07:00
|
|
|
void PreferencesDialog::passwordUpdateSuccessfull()
|
|
|
|
{
|
|
|
|
ui.cloud_storage_password->setText(prefs.cloud_storage_password);
|
|
|
|
}
|
|
|
|
|
2014-02-06 11:38:28 -02:00
|
|
|
void PreferencesDialog::emitSettingsChanged()
|
|
|
|
{
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
2014-06-26 16:45:14 +04:00
|
|
|
|
2014-06-28 15:01:51 +04:00
|
|
|
void PreferencesDialog::proxyType_changed(int idx)
|
2014-06-26 16:45:14 +04: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());
|
|
|
|
}
|