| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | #include "preferences.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-30 09:18:04 -08:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2013-06-02 19:52:18 +09:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2013-10-14 07:19:13 +03:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							| 
									
										
										
										
											2013-12-06 17:14:50 -02:00
										 |  |  | #include <QSortFilterProxyModel>
 | 
					
						
							| 
									
										
										
										
											2014-04-25 20:32:02 +02:00
										 |  |  | #include <QShortcut>
 | 
					
						
							| 
									
										
										
										
											2014-06-26 16:45:14 +04:00
										 |  |  | #include <QNetworkProxy>
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-06-28 15:20:42 +03:00
										 |  |  | 	dialog->setAttribute(Qt::WA_QuitOnClose, false); | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 	LanguageModel::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); | 
					
						
							| 
									
										
										
										
											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-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 *))); | 
					
						
							| 
									
										
										
										
											2013-12-05 00:48:37 +01:00
										 |  |  | 	connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); | 
					
						
							|  |  |  | 	connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int))); | 
					
						
							| 
									
										
										
										
											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-02-27 20:09:57 -08:00
										 |  |  | #define DANGER_GF (gf > 100) ? "* { color: red; }" : ""
 | 
					
						
							| 
									
										
										
										
											2013-12-05 00:48:37 +01:00
										 |  |  | void PreferencesDialog::gflowChanged(int gf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-06 14:35:23 -02:00
										 |  |  | 	ui.gflow->setStyleSheet(DANGER_GF); | 
					
						
							| 
									
										
										
										
											2013-12-05 00:48:37 +01:00
										 |  |  | } | 
					
						
							|  |  |  | void PreferencesDialog::gfhighChanged(int gf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-06 14:35:23 -02:00
										 |  |  | 	ui.gfhigh->setStyleSheet(DANGER_GF); | 
					
						
							| 
									
										
										
										
											2013-12-05 00:48:37 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-06 14:35:23 -02:00
										 |  |  | #undef DANGER_GF
 | 
					
						
							| 
									
										
										
										
											2013-12-05 00:48:37 +01: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-06-03 21:08:49 +09:00
										 |  |  | 	// graphs
 | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07: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 16:41:44 +02:00
										 |  |  | 	ui.maxpo2->setValue(prefs.modpO2); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	ui.red_ceiling->setChecked(prefs.redceiling); | 
					
						
							| 
									
										
										
										
											2013-12-08 14:18:26 +01:00
										 |  |  | 	ui.units_group->setEnabled(ui.personalize->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ui.gflow->setValue(prefs.gflow); | 
					
						
							|  |  |  | 	ui.gfhigh->setValue(prefs.gfhigh); | 
					
						
							| 
									
										
										
										
											2013-11-20 16:11:22 +01:00
										 |  |  | 	ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); | 
					
						
							| 
									
										
										
										
											2013-06-03 21:08:49 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// units
 | 
					
						
							|  |  |  | 	if (prefs.unit_system == METRIC) | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.metric->setChecked(true); | 
					
						
							| 
									
										
										
										
											2013-06-03 21:08:49 +09:00
										 |  |  | 	else if (prefs.unit_system == IMPERIAL) | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 		ui.imperial->setChecked(true); | 
					
						
							| 
									
										
										
										
											2013-06-03 21:08:49 +09:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07: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 14:18:27 +01:00
										 |  |  | 	ui.kg->setChecked(prefs.units.weight == units::KG); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.lbs->setChecked(prefs.units.weight == units::LBS); | 
					
						
							| 
									
										
										
										
											2013-12-08 14:18:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-18 19:06:51 -02:00
										 |  |  | 	ui.font->setCurrentFont(QString(prefs.divelist_font)); | 
					
						
							| 
									
										
										
										
											2013-10-03 11:54:25 -07:00
										 |  |  | 	ui.fontsize->setValue(prefs.font_size); | 
					
						
							|  |  |  | 	ui.defaultfilename->setText(prefs.default_filename); | 
					
						
							| 
									
										
										
										
											2013-11-24 23:21:29 +01:00
										 |  |  | 	ui.default_cylinder->clear(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = 0; tank_info[i].name != NULL; i++) { | 
					
						
							| 
									
										
										
										
											2013-11-24 23:21:29 +01: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 13:40:14 +01:00
										 |  |  | 	ui.displayinvalid->setChecked(prefs.display_invalid_dives); | 
					
						
							| 
									
										
										
										
											2014-01-11 21:57:06 +07:00
										 |  |  | 	ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); | 
					
						
							| 
									
										
										
										
											2014-03-27 13:38:07 -05:00
										 |  |  | 	ui.show_average_depth->setChecked(prefs.show_average_depth); | 
					
						
							| 
									
										
										
										
											2013-10-04 07:57:48 +02: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 19:10:31 -03:00
										 |  |  | 	ui.velocitySlider->setValue(prefs.animation_speed); | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 17:14:50 -02:00
										 |  |  | 	QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); | 
					
						
							|  |  |  | 	filterModel->setSourceModel(LanguageModel::instance()); | 
					
						
							|  |  |  | 	filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							|  |  |  | 	ui.languageView->setModel(filterModel); | 
					
						
							| 
									
										
										
										
											2013-12-07 17:32:17 +02:00
										 |  |  | 	filterModel->sort(0); | 
					
						
							| 
									
										
										
										
											2013-12-06 17:14:50 -02:00
										 |  |  | 	connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString))); | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 	s.beginGroup("Language"); | 
					
						
							| 
									
										
										
										
											2013-12-12 06:44:09 +01:00
										 |  |  | 	ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); | 
					
						
							| 
									
										
										
										
											2013-12-18 18:18:33 -02:00
										 |  |  | 	QAbstractItemModel *m = ui.languageView->model(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); | 
					
						
							| 
									
										
										
										
											2013-12-18 18:18:33 -02:00
										 |  |  | 	if (languages.count()) | 
					
						
							|  |  |  | 		ui.languageView->setCurrentIndex(languages.first()); | 
					
						
							| 
									
										
										
										
											2014-03-11 17:36:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											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)); | 
					
						
							| 
									
										
										
										
											2014-07-16 18:40:49 -03:00
										 |  |  | 	ui.btnUseDefaultFile->setChecked(prefs.use_default_file); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | #define GET_UNIT(name, field, f, t)                                 \
 | 
					
						
							|  |  |  | 	v = s.value(QString(name));                                 \ | 
					
						
							|  |  |  | 	if (v.isValid())                                            \ | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 		prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	else                                                        \ | 
					
						
							| 
									
										
										
										
											2014-05-05 15:56:11 -07:00
										 |  |  | 		prefs.units.field = default_prefs.units.field | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GET_BOOL(name, field)                           \
 | 
					
						
							|  |  |  | 	v = s.value(QString(name));                     \ | 
					
						
							|  |  |  | 	if (v.isValid())                                \ | 
					
						
							| 
									
										
										
										
											2014-05-05 15:56:49 -07:00
										 |  |  | 		prefs.field = v.toBool();               \ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	else                                            \ | 
					
						
							| 
									
										
										
										
											2014-05-05 15:56:11 -07:00
										 |  |  | 		prefs.field = default_prefs.field | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GET_DOUBLE(name, field)             \
 | 
					
						
							|  |  |  | 	v = s.value(QString(name));         \ | 
					
						
							|  |  |  | 	if (v.isValid())                    \ | 
					
						
							|  |  |  | 		prefs.field = v.toDouble(); \ | 
					
						
							|  |  |  | 	else                                \ | 
					
						
							| 
									
										
										
										
											2014-05-05 15:56:11 -07:00
										 |  |  | 		prefs.field = default_prefs.field | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define GET_INT(name, field)             \
 | 
					
						
							|  |  |  | 	v = s.value(QString(name));      \ | 
					
						
							|  |  |  | 	if (v.isValid())                 \ | 
					
						
							|  |  |  | 		prefs.field = v.toInt(); \ | 
					
						
							|  |  |  | 	else                             \ | 
					
						
							| 
									
										
										
										
											2014-05-05 15:56:11 -07:00
										 |  |  | 		prefs.field = default_prefs.field | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-26 20:17:50 +04:00
										 |  |  | #define GET_INT_DEF(name, field, defval)                                             \
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	v = s.value(QString(name));                                      \ | 
					
						
							|  |  |  | 	if (v.isValid())                                                 \ | 
					
						
							| 
									
										
										
										
											2014-06-26 20:17:50 +04:00
										 |  |  | 		prefs.field = v.toInt(); \ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	else                                                             \ | 
					
						
							| 
									
										
										
										
											2014-06-26 20:17:50 +04:00
										 |  |  | 		prefs.field = defval | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08: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 15:56:11 -07:00
										 |  |  | 		prefs.field = default_prefs.field | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-27 06:59:36 -07: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 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()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 	// Graph
 | 
					
						
							| 
									
										
										
										
											2013-05-26 10:49:05 -07:00
										 |  |  | 	s.beginGroup("TecDetails"); | 
					
						
							| 
									
										
										
										
											2014-08-27 06:59:36 -07: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()); | 
					
						
							|  |  |  | 	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 10:49:05 -07:00
										 |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2013-05-28 11:21:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 	// Units
 | 
					
						
							| 
									
										
										
										
											2013-05-26 10:49:05 -07:00
										 |  |  | 	s.beginGroup("Units"); | 
					
						
							| 
									
										
										
										
											2014-08-27 06:59:36 -07: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 11:54:25 -07: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 07:57:48 +02:00
										 |  |  | 	s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:49:05 -07:00
										 |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 	// Defaults
 | 
					
						
							| 
									
										
										
										
											2013-05-26 10:49:05 -07:00
										 |  |  | 	s.beginGroup("GeneralSettings"); | 
					
						
							| 
									
										
										
										
											2013-11-23 21:54:51 -08:00
										 |  |  | 	s.setValue("default_filename", ui.defaultfilename->text()); | 
					
						
							| 
									
										
										
										
											2013-11-24 23:21:29 +01:00
										 |  |  | 	s.setValue("default_cylinder", ui.default_cylinder->currentText()); | 
					
						
							| 
									
										
										
										
											2014-07-16 18:40:49 -03:00
										 |  |  | 	s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-11-20 13:40:14 +01:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Display"); | 
					
						
							| 
									
										
										
										
											2014-08-27 06:59:36 -07: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 14:30:59 -02:00
										 |  |  | 	s.setValue("displayinvalid", ui.displayinvalid->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:49:05 -07:00
										 |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2013-05-24 15:19:48 -03:00
										 |  |  | 	s.sync(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	// Locale
 | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 	QLocale loc; | 
					
						
							|  |  |  | 	s.beginGroup("Language"); | 
					
						
							| 
									
										
										
										
											2013-12-12 06:44:09 +01: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 15:22:54 +01:00
										 |  |  | 		QMessageBox::warning(MainWindow::instance(), tr("Restart required"), | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 				     tr("To correctly load a new language you must restart Subsurface.")); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-06 17:48:38 -02:00
										 |  |  | 	s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-12-06 14:29:38 -02:00
										 |  |  | 	s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2014-02-08 18:07:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	// Animation
 | 
					
						
							| 
									
										
										
										
											2014-03-11 17:36:49 -03:00
										 |  |  | 	s.beginGroup("Animations"); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	s.setValue("animation_speed", ui.velocitySlider->value()); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-08 18:07:06 +01:00
										 |  |  | 	loadSettings(); | 
					
						
							|  |  |  | 	emit settingsChanged(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PreferencesDialog::loadSettings() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02: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 14:29:38 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02: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 16:41:44 +02:00
										 |  |  | 	GET_DOUBLE("modpO2", modpO2); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 	GET_BOOL("ead", ead); | 
					
						
							| 
									
										
										
										
											2014-04-16 22:03:44 +02: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 08:11:14 -06:00
										 |  |  | 	GET_BOOL("tankbar", tankbar); | 
					
						
							| 
									
										
										
										
											2014-09-15 14:09:00 +02:00
										 |  |  | 	GET_BOOL("percentagegraph", percentagegraph); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 	GET_INT("gflow", gflow); | 
					
						
							|  |  |  | 	GET_INT("gfhigh", gfhigh); | 
					
						
							|  |  |  | 	GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth); | 
					
						
							| 
									
										
										
										
											2014-02-27 12:31:00 -03:00
										 |  |  | 	GET_BOOL("zoomed_plot", zoomed_plot); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02: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 13:38:07 -05:00
										 |  |  | 	GET_BOOL("show_average_depth", show_average_depth); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("GeneralSettings"); | 
					
						
							|  |  |  | 	GET_TXT("default_filename", default_filename); | 
					
						
							|  |  |  | 	GET_TXT("default_cylinder", default_cylinder); | 
					
						
							| 
									
										
										
										
											2014-07-16 18:40:49 -03:00
										 |  |  | 	GET_BOOL("use_default_file", use_default_file); | 
					
						
							| 
									
										
										
										
											2014-02-06 14:18:00 -02:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Display"); | 
					
						
							| 
									
										
										
										
											2014-08-27 06:00:10 -07: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 14:18:00 -02:00
										 |  |  | 	qApp->setFont(defaultFont); | 
					
						
							|  |  |  | 	GET_INT("displayinvalid", display_invalid_dives); | 
					
						
							|  |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2014-03-11 17:36:49 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Animations"); | 
					
						
							| 
									
										
										
										
											2014-07-21 19:10:31 -03:00
										 |  |  | 	GET_INT("animation_speed", animation_speed); | 
					
						
							| 
									
										
										
										
											2014-06-26 20:17:50 +04:00
										 |  |  | 	s.endGroup(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.beginGroup("Network"); | 
					
						
							| 
									
										
										
										
											2014-06-26 22:21:02 +04:00
										 |  |  | 	GET_INT_DEF("proxy_type", proxy_type, QNetworkProxy::DefaultProxy); | 
					
						
							| 
									
										
										
										
											2014-06-26 20:17:50 +04: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 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
										 |  |  | 
 | 
					
						
							|  |  |  | void PreferencesDialog::on_chooseFile_clicked() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-19 23:08:20 -08:00
										 |  |  | 	QFileInfo fi(system_default_filename()); | 
					
						
							| 
									
										
										
										
											2014-07-11 00:06:50 +01:00
										 |  |  | 	QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open default log file"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)")); | 
					
						
							| 
									
										
										
										
											2014-02-11 19:49:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (!choosenFileName.isEmpty()) | 
					
						
							| 
									
										
										
										
											2014-02-11 19:49:56 +01:00
										 |  |  | 		ui.defaultfilename->setText(choosenFileName); | 
					
						
							| 
									
										
										
										
											2013-10-14 07:19:13 +03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-06 11:38:28 -02: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) { | 
					
						
							|  |  |  | 		prefs = default_prefs; | 
					
						
							|  |  |  | 		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(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-16 18:40:49 -03: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); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |