2013-05-24 18:19:48 +00:00
|
|
|
#include "preferences.h"
|
2013-11-30 17:18:04 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-24 18:19:48 +00:00
|
|
|
#include <QSettings>
|
2013-06-02 10:52:18 +00:00
|
|
|
#include <QDebug>
|
2013-10-14 04:19:13 +00:00
|
|
|
#include <QFileDialog>
|
2013-12-06 16:29:38 +00:00
|
|
|
#include <QMessageBox>
|
2013-12-06 19:14:50 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
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>
|
2014-12-23 22:56:51 +00:00
|
|
|
#include <QNetworkReply>
|
2014-12-23 19:51:45 +00:00
|
|
|
#include <QWebView>
|
2014-12-23 22:56:51 +00:00
|
|
|
#include <QJsonDocument>
|
2014-12-24 23:34:23 +00:00
|
|
|
#include "socialnetworks.h"
|
2014-12-23 21:29:00 +00:00
|
|
|
|
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-06-28 12:20:42 +00:00
|
|
|
dialog->setAttribute(Qt::WA_QuitOnClose, false);
|
2013-12-06 16:29:38 +00:00
|
|
|
LanguageModel::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);
|
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
|
|
|
|
|
|
|
// Facebook stuff:
|
2014-12-24 23:34:23 +00:00
|
|
|
FacebookManager *fb = FacebookManager::instance();
|
|
|
|
if(fb->loggedIn()){
|
2014-12-23 21:10:57 +00:00
|
|
|
ui.facebookWebView->setHtml("You are connected on Facebook, yey.");
|
|
|
|
} else {
|
2014-12-24 23:34:23 +00:00
|
|
|
ui.facebookWebView->setUrl(fb->connectUrl());
|
2014-12-23 21:10:57 +00:00
|
|
|
}
|
2014-12-24 23:34:23 +00:00
|
|
|
connect(ui.facebookWebView, &QWebView::urlChanged, fb, &FacebookManager::tryLogin);
|
|
|
|
connect(fb, &FacebookManager::justLoggedIn, this, &PreferencesDialog::facebookLoggedIn);
|
|
|
|
connect(ui.btnDisconnectFacebook, &QPushButton::clicked, fb, &FacebookManager::logout);
|
|
|
|
connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect);
|
2014-12-23 20:39:47 +00:00
|
|
|
|
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)));
|
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
|
|
|
{
|
2014-12-24 23:34:23 +00:00
|
|
|
ui.facebookWebView->setHtml("We need a better 'you re connected' page. but, YEY. ");
|
|
|
|
ui.fbConnected->show();
|
2014-12-23 22:56:51 +00:00
|
|
|
}
|
|
|
|
|
2014-12-23 21:29:00 +00:00
|
|
|
void PreferencesDialog::facebookDisconnect()
|
|
|
|
{
|
2014-12-24 23:34:23 +00:00
|
|
|
ui.facebookWebView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
|
|
|
|
ui.facebookWebView->setUrl(FacebookManager::instance()->connectUrl());
|
|
|
|
ui.fbConnected->hide();
|
2014-12-23 21:29:00 +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-12-08 13:18:26 +00:00
|
|
|
ui.units_group->setEnabled(ui.personalize->isChecked());
|
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);
|
2013-06-03 12:08:49 +00:00
|
|
|
|
|
|
|
// units
|
|
|
|
if (prefs.unit_system == METRIC)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.metric->setChecked(true);
|
2013-06-03 12:08:49 +00:00
|
|
|
else if (prefs.unit_system == IMPERIAL)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.imperial->setChecked(true);
|
2013-06-03 12:08:49 +00:00
|
|
|
else
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.personalize->setChecked(true);
|
|
|
|
|
|
|
|
ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS);
|
|
|
|
ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT);
|
|
|
|
ui.meter->setChecked(prefs.units.length == units::METERS);
|
|
|
|
ui.feet->setChecked(prefs.units.length == units::FEET);
|
|
|
|
ui.bar->setChecked(prefs.units.pressure == units::BAR);
|
|
|
|
ui.psi->setChecked(prefs.units.pressure == units::PSI);
|
|
|
|
ui.liter->setChecked(prefs.units.volume == units::LITER);
|
|
|
|
ui.cuft->setChecked(prefs.units.volume == units::CUFT);
|
2013-12-08 13:18:27 +00:00
|
|
|
ui.kg->setChecked(prefs.units.weight == units::KG);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.lbs->setChecked(prefs.units.weight == units::LBS);
|
2013-12-08 13:18:26 +00:00
|
|
|
|
2013-12-18 21:06:51 +00:00
|
|
|
ui.font->setCurrentFont(QString(prefs.divelist_font));
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.fontsize->setValue(prefs.font_size);
|
|
|
|
ui.defaultfilename->setText(prefs.default_filename);
|
2013-11-24 22:21:29 +00:00
|
|
|
ui.default_cylinder->clear();
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = 0; tank_info[i].name != NULL; i++) {
|
2013-11-24 22:21:29 +00:00
|
|
|
ui.default_cylinder->addItem(tank_info[i].name);
|
|
|
|
if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0)
|
|
|
|
ui.default_cylinder->setCurrentIndex(i);
|
|
|
|
}
|
2013-11-20 12:40:14 +00:00
|
|
|
ui.displayinvalid->setChecked(prefs.display_invalid_dives);
|
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);
|
2013-10-04 05:57:48 +00:00
|
|
|
ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES);
|
|
|
|
ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS);
|
2014-07-21 22:10:31 +00:00
|
|
|
ui.velocitySlider->setValue(prefs.animation_speed);
|
2013-12-06 16:29:38 +00:00
|
|
|
|
2013-12-06 19:14:50 +00:00
|
|
|
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel();
|
|
|
|
filterModel->setSourceModel(LanguageModel::instance());
|
|
|
|
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
ui.languageView->setModel(filterModel);
|
2013-12-07 15:32:17 +00:00
|
|
|
filterModel->sort(0);
|
2013-12-06 19:14:50 +00:00
|
|
|
connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString)));
|
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());
|
|
|
|
|
2013-12-06 16:29:38 +00:00
|
|
|
s.beginGroup("Language");
|
2013-12-12 05:44:09 +00:00
|
|
|
ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
|
2013-12-18 20:18:33 +00:00
|
|
|
QAbstractItemModel *m = ui.languageView->model();
|
2014-02-28 04:09:57 +00:00
|
|
|
QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString());
|
2013-12-18 20:18:33 +00:00
|
|
|
if (languages.count())
|
|
|
|
ui.languageView->setCurrentIndex(languages.first());
|
2014-03-11 20:36:49 +00:00
|
|
|
|
|
|
|
s.endGroup();
|
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));
|
2014-07-16 21:40:49 +00:00
|
|
|
ui.btnUseDefaultFile->setChecked(prefs.use_default_file);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
|
|
|
|
2014-02-06 16:18:00 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
#define GET_UNIT(name, field, f, t) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
2014-02-06 16:18:00 +00:00
|
|
|
prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \
|
2014-02-28 04:09:57 +00:00
|
|
|
else \
|
2014-05-05 22:56:11 +00:00
|
|
|
prefs.units.field = default_prefs.units.field
|
2014-02-28 04:09:57 +00:00
|
|
|
|
|
|
|
#define GET_BOOL(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
2014-05-05 22:56:49 +00:00
|
|
|
prefs.field = v.toBool(); \
|
2014-02-28 04:09:57 +00:00
|
|
|
else \
|
2014-05-05 22:56:11 +00:00
|
|
|
prefs.field = default_prefs.field
|
2014-02-28 04:09:57 +00:00
|
|
|
|
|
|
|
#define GET_DOUBLE(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = v.toDouble(); \
|
|
|
|
else \
|
2014-05-05 22:56:11 +00:00
|
|
|
prefs.field = default_prefs.field
|
2014-02-28 04:09:57 +00:00
|
|
|
|
|
|
|
#define GET_INT(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = v.toInt(); \
|
|
|
|
else \
|
2014-05-05 22:56:11 +00:00
|
|
|
prefs.field = default_prefs.field
|
2014-02-28 04:09:57 +00:00
|
|
|
|
2014-06-26 16:17:50 +00:00
|
|
|
#define GET_INT_DEF(name, field, defval) \
|
2014-02-28 04:09:57 +00:00
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
2014-06-26 16:17:50 +00:00
|
|
|
prefs.field = v.toInt(); \
|
2014-02-28 04:09:57 +00:00
|
|
|
else \
|
2014-06-26 16:17:50 +00:00
|
|
|
prefs.field = defval
|
2014-02-28 04:09:57 +00:00
|
|
|
|
|
|
|
#define GET_TXT(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
|
|
|
else \
|
2014-05-05 22:56:11 +00:00
|
|
|
prefs.field = default_prefs.field
|
2014-02-06 16:18:00 +00:00
|
|
|
|
2014-08-27 13:59:36 +00:00
|
|
|
#define SAVE_OR_REMOVE_SPECIAL(_setting, _default, _compare, _value) \
|
|
|
|
if (_compare != _default) \
|
|
|
|
s.setValue(_setting, _value); \
|
|
|
|
else \
|
|
|
|
s.remove(_setting)
|
|
|
|
|
|
|
|
#define SAVE_OR_REMOVE(_setting, _default, _value) \
|
|
|
|
if (_value != _default) \
|
|
|
|
s.setValue(_setting, _value); \
|
|
|
|
else \
|
|
|
|
s.remove(_setting)
|
|
|
|
|
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());
|
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
|
|
|
// Units
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("Units");
|
2014-08-27 13:59:36 +00:00
|
|
|
QString unitSystem[] = {"metric", "imperial", "personal"};
|
|
|
|
short unitValue = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE);
|
|
|
|
SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]);
|
2013-10-03 18:54:25 +00:00
|
|
|
s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
|
|
|
|
s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS);
|
|
|
|
s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR);
|
|
|
|
s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER);
|
|
|
|
s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG);
|
2013-10-04 05:57:48 +00:00
|
|
|
s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2014-04-16 20:03:44 +00:00
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
// Defaults
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("GeneralSettings");
|
2013-11-24 05:54:51 +00:00
|
|
|
s.setValue("default_filename", ui.defaultfilename->text());
|
2013-11-24 22:21:29 +00:00
|
|
|
s.setValue("default_cylinder", ui.default_cylinder->currentText());
|
2014-07-16 21:40:49 +00:00
|
|
|
s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked());
|
2013-11-20 12:40:14 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("Display");
|
2014-08-27 13:59:36 +00:00
|
|
|
SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui.font->currentFont().toString(), ui.font->currentFont());
|
|
|
|
SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui.fontsize->value());
|
2013-12-06 16:30:59 +00:00
|
|
|
s.setValue("displayinvalid", ui.displayinvalid->isChecked());
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-24 18:19:48 +00:00
|
|
|
s.sync();
|
|
|
|
|
2014-04-16 20:03:44 +00:00
|
|
|
// Locale
|
2013-12-06 16:29:38 +00:00
|
|
|
QLocale loc;
|
|
|
|
s.beginGroup("Language");
|
2013-12-12 05:44:09 +00:00
|
|
|
bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
|
|
|
|
if (useSystemLang != ui.languageSystemDefault->isChecked() ||
|
|
|
|
(!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) {
|
2014-02-12 14:22:54 +00:00
|
|
|
QMessageBox::warning(MainWindow::instance(), tr("Restart required"),
|
2013-12-06 16:29:38 +00:00
|
|
|
tr("To correctly load a new language you must restart Subsurface."));
|
|
|
|
}
|
2013-12-06 19:48:38 +00:00
|
|
|
s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked());
|
2013-12-06 16:29:38 +00:00
|
|
|
s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole));
|
2014-02-06 16:18:00 +00:00
|
|
|
s.endGroup();
|
2014-02-08 17:07:06 +00:00
|
|
|
|
2014-04-16 20:03:44 +00:00
|
|
|
// Animation
|
2014-03-11 20:36:49 +00:00
|
|
|
s.beginGroup("Animations");
|
2014-05-22 18:40:22 +00:00
|
|
|
s.setValue("animation_speed", ui.velocitySlider->value());
|
2014-04-16 20:03:44 +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();
|
|
|
|
|
2014-02-08 17:07:06 +00:00
|
|
|
loadSettings();
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialog::loadSettings()
|
|
|
|
{
|
2014-02-06 16:18:00 +00:00
|
|
|
// This code was on the mainwindow, it should belong nowhere, but since we dind't
|
|
|
|
// correctly fixed this code yet ( too much stuff on the code calling preferences )
|
|
|
|
// force this here.
|
2013-12-06 16:29:38 +00:00
|
|
|
|
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());
|
|
|
|
|
2014-02-06 16:18:00 +00:00
|
|
|
s.beginGroup("Units");
|
|
|
|
if (s.value("unit_system").toString() == "metric") {
|
|
|
|
prefs.unit_system = METRIC;
|
|
|
|
prefs.units = SI_units;
|
|
|
|
} else if (s.value("unit_system").toString() == "imperial") {
|
|
|
|
prefs.unit_system = IMPERIAL;
|
|
|
|
prefs.units = IMPERIAL_units;
|
|
|
|
} else {
|
|
|
|
prefs.unit_system = PERSONALIZE;
|
|
|
|
GET_UNIT("length", length, units::FEET, units::METERS);
|
|
|
|
GET_UNIT("pressure", pressure, units::PSI, units::BAR);
|
|
|
|
GET_UNIT("volume", volume, units::CUFT, units::LITER);
|
|
|
|
GET_UNIT("temperature", temperature, units::FAHRENHEIT, units::CELSIUS);
|
|
|
|
GET_UNIT("weight", weight, units::LBS, units::KG);
|
|
|
|
}
|
|
|
|
GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
|
|
|
|
s.endGroup();
|
|
|
|
s.beginGroup("TecDetails");
|
|
|
|
GET_BOOL("po2graph", pp_graphs.po2);
|
|
|
|
GET_BOOL("pn2graph", pp_graphs.pn2);
|
|
|
|
GET_BOOL("phegraph", pp_graphs.phe);
|
|
|
|
GET_DOUBLE("po2threshold", pp_graphs.po2_threshold);
|
|
|
|
GET_DOUBLE("pn2threshold", pp_graphs.pn2_threshold);
|
|
|
|
GET_DOUBLE("phethreshold", pp_graphs.phe_threshold);
|
|
|
|
GET_BOOL("mod", mod);
|
2014-06-22 14:41:44 +00:00
|
|
|
GET_DOUBLE("modpO2", modpO2);
|
2014-02-06 16:18:00 +00:00
|
|
|
GET_BOOL("ead", ead);
|
2014-04-16 20:03:44 +00:00
|
|
|
GET_BOOL("redceiling", redceiling);
|
|
|
|
GET_BOOL("dcceiling", dcceiling);
|
|
|
|
GET_BOOL("calcceiling", calcceiling);
|
|
|
|
GET_BOOL("calcceiling3m", calcceiling3m);
|
|
|
|
GET_BOOL("calcndltts", calcndltts);
|
|
|
|
GET_BOOL("calcalltissues", calcalltissues);
|
|
|
|
GET_BOOL("hrgraph", hrgraph);
|
2014-08-15 14:11:14 +00:00
|
|
|
GET_BOOL("tankbar", tankbar);
|
2014-09-15 12:09:00 +00:00
|
|
|
GET_BOOL("percentagegraph", percentagegraph);
|
2014-02-06 16:18:00 +00:00
|
|
|
GET_INT("gflow", gflow);
|
|
|
|
GET_INT("gfhigh", gfhigh);
|
|
|
|
GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
|
2015-01-05 07:20:26 +00:00
|
|
|
GET_BOOL("show_ccr_setpoint",show_ccr_setpoint);
|
2014-02-27 15:31:00 +00:00
|
|
|
GET_BOOL("zoomed_plot", zoomed_plot);
|
2014-02-06 16:18:00 +00:00
|
|
|
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
|
|
|
GET_BOOL("show_sac", show_sac);
|
|
|
|
GET_BOOL("display_unused_tanks", display_unused_tanks);
|
2014-03-27 18:38:07 +00:00
|
|
|
GET_BOOL("show_average_depth", show_average_depth);
|
2014-02-06 16:18:00 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("GeneralSettings");
|
|
|
|
GET_TXT("default_filename", default_filename);
|
|
|
|
GET_TXT("default_cylinder", default_cylinder);
|
2014-07-16 21:40:49 +00:00
|
|
|
GET_BOOL("use_default_file", use_default_file);
|
2014-02-06 16:18:00 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("Display");
|
2014-08-27 13:00:10 +00:00
|
|
|
// get the font from the settings or our defaults
|
|
|
|
// respect the system default font size if none is explicitly set
|
|
|
|
QFont defaultFont = s.value("divelist_font", prefs.divelist_font).value<QFont>();
|
|
|
|
if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) {
|
|
|
|
prefs.font_size = qApp->font().pointSizeF();
|
|
|
|
system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit
|
|
|
|
}
|
|
|
|
prefs.font_size = s.value("font_size", prefs.font_size).toFloat();
|
|
|
|
// painful effort to ignore previous default fonts on Windows - ridiculous
|
|
|
|
QString fontName = defaultFont.toString();
|
|
|
|
if (fontName.contains(","))
|
|
|
|
fontName = fontName.left(fontName.indexOf(","));
|
|
|
|
if (subsurface_ignore_font(fontName.toUtf8().constData())) {
|
|
|
|
defaultFont = QFont(prefs.divelist_font);
|
|
|
|
} else {
|
|
|
|
free((void *)prefs.divelist_font);
|
|
|
|
prefs.divelist_font = strdup(fontName.toUtf8().constData());
|
|
|
|
}
|
|
|
|
defaultFont.setPointSizeF(prefs.font_size);
|
2014-02-06 16:18:00 +00:00
|
|
|
qApp->setFont(defaultFont);
|
|
|
|
GET_INT("displayinvalid", display_invalid_dives);
|
|
|
|
s.endGroup();
|
2014-03-11 20:36:49 +00:00
|
|
|
|
|
|
|
s.beginGroup("Animations");
|
2014-07-21 22:10:31 +00:00
|
|
|
GET_INT("animation_speed", animation_speed);
|
2014-06-26 16:17:50 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("Network");
|
2014-06-26 18:21:02 +00:00
|
|
|
GET_INT_DEF("proxy_type", proxy_type, QNetworkProxy::DefaultProxy);
|
2014-06-26 16:17:50 +00:00
|
|
|
GET_TXT("proxy_host", proxy_host);
|
|
|
|
GET_INT("proxy_port", proxy_port);
|
|
|
|
GET_BOOL("proxy_auth", proxy_auth);
|
|
|
|
GET_TXT("proxy_user", proxy_user);
|
|
|
|
GET_TXT("proxy_pass", proxy_pass);
|
|
|
|
s.endGroup();
|
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
|
|
|
|
|
|
|
void PreferencesDialog::on_chooseFile_clicked()
|
|
|
|
{
|
2013-11-20 07:08:20 +00:00
|
|
|
QFileInfo fi(system_default_filename());
|
2014-07-10 23:06:50 +00:00
|
|
|
QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)"));
|
2014-02-11 18:49:56 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
if (!choosenFileName.isEmpty())
|
2014-02-11 18:49:56 +00:00
|
|
|
ui.defaultfilename->setText(choosenFileName);
|
2013-10-14 04:19:13 +00:00
|
|
|
}
|
2014-02-06 13:38:28 +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) {
|
|
|
|
prefs = default_prefs;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
2014-07-16 21:40:49 +00:00
|
|
|
|
|
|
|
void PreferencesDialog::on_btnUseDefaultFile_toggled(bool toggle)
|
|
|
|
{
|
|
|
|
if (toggle) {
|
|
|
|
ui.defaultfilename->setText(system_default_filename());
|
|
|
|
ui.defaultfilename->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui.defaultfilename->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|