summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Patrick Valsecchi <patrick@thus.ch>2013-11-20 13:40:14 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-21 08:11:40 -0800
commit4c4a7a6d968fa27de72f1510c55d327a7e919d7c (patch)
tree8efda997313870e3b433a8a49b94a47af830fc54
parente0b376622c505ee631b87b54aefa0130bbfa1237 (diff)
downloadsubsurface-4c4a7a6d968fa27de72f1510c55d327a7e919d7c.tar.gz
Refactoring of the configuration handling.
Before, when clicking the OK button on the preferences GUI, we were updating in-memory preferences from the GUI, saving them to the configuration file from the GUI, reloading from the file to the in-memory preferences. Then, to add to the ducplication, when the application was exiting, some fields were saved again. Basically the first step and the last step were useless appart from the fact the the other steps where missing a few fields here and there. This patch removes the first step and fixes the missing fields. Signed-off-by: Patrick Valsecchi <patrick@thus.ch> ACKed-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-gui.cpp3
-rw-r--r--qt-ui/maintab.cpp1
-rw-r--r--qt-ui/mainwindow.cpp54
-rw-r--r--qt-ui/preferences.cpp49
-rw-r--r--qt-ui/preferences.h1
-rw-r--r--qt-ui/profilegraphics.cpp1
-rw-r--r--qt-ui/tableview.cpp1
-rw-r--r--subsurfacestartup.c2
-rw-r--r--subsurfacestartup.h2
9 files changed, 23 insertions, 91 deletions
diff --git a/qt-gui.cpp b/qt-gui.cpp
index a943bff76..c868f6648 100644
--- a/qt-gui.cpp
+++ b/qt-gui.cpp
@@ -116,9 +116,6 @@ void init_ui(int *argcp, char ***argvp)
}
QSettings s;
- s.beginGroup("GeneralSettings");
- prefs.default_filename = getSetting(s, "default_filename");
- s.endGroup();
s.beginGroup("DiveComputer");
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
default_dive_computer_product = getSetting(s,"dive_computer_product");
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index a56b2fc5d..e3cf0bccb 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -21,7 +21,6 @@
#include <QDebug>
#include <QSet>
#include <QTableView>
-#include <QSettings>
#include <QPalette>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 53198902c..23c972741 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -557,6 +557,13 @@ bool MainWindow::askSaveChanges()
else \
prefs.field = default_prefs.field
+#define GET_TXT(name, field) \
+ v = s.value(QString(name)); \
+ if (v.isValid()) \
+ prefs.field = strdup(v.toString().toUtf8().constData()); \
+ else \
+ prefs.field = default_prefs.field
+
void MainWindow::initialUiSetup()
{
@@ -620,18 +627,17 @@ void MainWindow::readSettings()
GET_BOOL("show_sac", show_sac);
s.endGroup();
+ s.beginGroup("GeneralSettings");
+ GET_TXT("default_filename", default_filename);
+ s.endGroup();
+
s.beginGroup("Display");
- v = s.value(QString("divelist_font"));
- if (v.isValid())
- prefs.divelist_font = strdup(v.toString().toUtf8().data());
+ GET_TXT("divelist_font", divelist_font);
+ GET_INT("font_size", font_size);
+ GET_INT("displayinvalid", display_invalid_dives);
+ s.endGroup();
}
-#define SAVE_VALUE(name, field) \
- if (prefs.field != default_prefs.field) \
- settings.setValue(name, prefs.field); \
- else \
- settings.remove(name)
-
void MainWindow::writeSettings()
{
QSettings settings;
@@ -643,36 +649,6 @@ void MainWindow::writeSettings()
saveSplitterSizes();
}
settings.endGroup();
-
- settings.beginGroup("Units");
- SAVE_VALUE("length", units.length);
- SAVE_VALUE("pressure", units.pressure);
- SAVE_VALUE("volume", units.volume);
- SAVE_VALUE("temperature", units.temperature);
- SAVE_VALUE("weight", units.weight);
- SAVE_VALUE("vertical_speed_time", units.vertical_speed_time);
- settings.endGroup();
- settings.beginGroup("TecDetails");
- SAVE_VALUE("po2graph", pp_graphs.po2);
- SAVE_VALUE("pn2graph", pp_graphs.pn2);
- SAVE_VALUE("phegraph", pp_graphs.phe);
- SAVE_VALUE("po2threshold", pp_graphs.po2_threshold);
- SAVE_VALUE("pn2threshold", pp_graphs.pn2_threshold);
- SAVE_VALUE("phethreshold", pp_graphs.phe_threshold);
- SAVE_VALUE("mod", mod);
- SAVE_VALUE("modppO2", mod_ppO2);
- SAVE_VALUE("ead", ead);
- SAVE_VALUE("redceiling", profile_red_ceiling);
- SAVE_VALUE("calcceiling", profile_calc_ceiling);
- SAVE_VALUE("calcceiling3m", calc_ceiling_3m_incr);
- SAVE_VALUE("calcalltissues", calc_all_tissues);
- SAVE_VALUE("dcceiling", profile_dc_ceiling);
- SAVE_VALUE("gflow", gflow);
- SAVE_VALUE("gfhigh", gfhigh);
- settings.endGroup();
- settings.beginGroup("GeneralSettings");
- SAVE_VALUE("default_filename", default_filename);
- settings.endGroup();
}
void MainWindow::closeEvent(QCloseEvent *event)
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp
index b9fb26018..f638d9d7d 100644
--- a/qt-ui/preferences.cpp
+++ b/qt-ui/preferences.cpp
@@ -77,7 +77,7 @@ void PreferencesDialog::setUiFromPrefs()
ui.font->setFont(QString(prefs.divelist_font));
ui.fontsize->setValue(prefs.font_size);
ui.defaultfilename->setText(prefs.default_filename);
- ui.displayinvalid->setChecked(prefs.show_invalid);
+ ui.displayinvalid->setChecked(prefs.display_invalid_dives);
ui.show_sac->setChecked(prefs.show_sac);
ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES);
ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS);
@@ -86,6 +86,7 @@ void PreferencesDialog::setUiFromPrefs()
void PreferencesDialog::restorePrefs()
{
prefs = oldPrefs;
+ setUiFromPrefs();
}
void PreferencesDialog::rememberPrefs()
@@ -93,41 +94,6 @@ void PreferencesDialog::rememberPrefs()
oldPrefs = prefs;
}
-#define SP(V, B) prefs.V = (int)(B->isChecked() ? 1 : 0)
-
-void PreferencesDialog::setPrefsFromUi()
-{
- SP(pp_graphs.phe, ui.phe);
- SP(pp_graphs.po2, ui.po2);
- SP(pp_graphs.pn2, ui.pn2);
- prefs.pp_graphs.phe_threshold = ui.pheThreshold->value();
- prefs.pp_graphs.po2_threshold = ui.po2Threshold->value();
- prefs.pp_graphs.pn2_threshold = ui.pn2Threshold->value();
- SP(ead, ui.ead_end_eadd);
- SP(mod, ui.mod);
- prefs.mod_ppO2 = ui.maxppo2->value();
- SP(profile_dc_ceiling, ui.dc_reported_ceiling);
- SP(profile_red_ceiling, ui.red_ceiling);
- SP(profile_calc_ceiling, ui.calculated_ceiling);
- SP(calc_ceiling_3m_incr, ui.increment_3m);
- SP(calc_ndl_tts, ui.calc_ndl_tts);
- SP(calc_all_tissues, ui.all_tissues);
- prefs.gflow = ui.gflow->value();
- prefs.gfhigh = ui.gfhigh->value();
- prefs.unit_system = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE);
- prefs.units.temperature = ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS;
- prefs.units.length = ui.feet->isChecked() ? units::FEET : units::METERS;
- prefs.units.pressure = ui.psi->isChecked() ? units::PSI : units::BAR;
- prefs.units.volume = ui.cuft->isChecked() ? units::CUFT : units::LITER;
- prefs.units.weight = ui.lbs->isChecked() ? units::LBS : units::KG;
- prefs.units.vertical_speed_time = ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS;
- prefs.divelist_font = strdup(ui.font->font().family().toUtf8().data());
- prefs.font_size = ui.fontsize->value();
- prefs.default_filename = strdup(ui.defaultfilename->text().toUtf8().data());
- prefs.display_invalid_dives = ui.displayinvalid->isChecked();
- SP(show_sac, ui.show_sac);
-}
-
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
void PreferencesDialog::syncSettings()
@@ -170,9 +136,12 @@ void PreferencesDialog::syncSettings()
s.endGroup();
// Defaults
s.beginGroup("GeneralSettings");
- s.value("table_fonts", ui.font->font().family());
- s.value("font_size", ui.fontsize->value());
s.value("default_filename", ui.defaultfilename->text());
+ s.endGroup();
+
+ s.beginGroup("Display");
+ s.value("divelist_font", ui.font->font().family());
+ s.value("font_size", ui.fontsize->value());
s.value("displayinvalid", ui.displayinvalid->isChecked());
s.endGroup();
s.sync();
@@ -185,16 +154,12 @@ void PreferencesDialog::buttonClicked(QAbstractButton* button)
switch(ui.buttonBox->standardButton(button)){
case QDialogButtonBox::Discard:
restorePrefs();
- setUiFromPrefs();
- syncSettings();
close();
break;
case QDialogButtonBox::Apply:
- setPrefsFromUi();
syncSettings();
break;
case QDialogButtonBox::FirstButton:
- setPrefsFromUi();
syncSettings();
close();
break;
diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h
index c9590db07..1cd3d9096 100644
--- a/qt-ui/preferences.h
+++ b/qt-ui/preferences.h
@@ -26,7 +26,6 @@ public slots:
private:
explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
void setUiFromPrefs();
- void setPrefsFromUi();
void setUIFromSettings();
Ui::PreferencesDialog ui;
struct preferences oldPrefs;
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 3e7cff237..834d7bdb1 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -1557,7 +1557,6 @@ void ToolTipItem::persistPos()
s.beginGroup("ProfileMap");
s.setValue("tooltip_position", currentPos);
s.endGroup();
- s.sync();
}
void ToolTipItem::readPos()
diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp
index d9731b477..80100218a 100644
--- a/qt-ui/tableview.cpp
+++ b/qt-ui/tableview.cpp
@@ -36,7 +36,6 @@ TableView::~TableView()
s.setValue(QString("colwidth%1").arg(i), ui.tableView->columnWidth(i));
}
s.endGroup();
- s.sync();
}
void TableView::setBtnToolTip(const QString& tooltip)
diff --git a/subsurfacestartup.c b/subsurfacestartup.c
index 1cf52e3b0..8d5e609a9 100644
--- a/subsurfacestartup.c
+++ b/subsurfacestartup.c
@@ -26,7 +26,7 @@ struct preferences default_prefs = {
.gflow = 30,
.gfhigh = 75,
.font_size = 14.0,
- .show_invalid = FALSE,
+ .display_invalid_dives = FALSE,
.show_sac = FALSE,
};
diff --git a/subsurfacestartup.h b/subsurfacestartup.h
index c979dc71e..e5d7750f7 100644
--- a/subsurfacestartup.h
+++ b/subsurfacestartup.h
@@ -10,8 +10,6 @@
extern "C" {
#endif
-extern struct preferences prefs;
-extern struct preferences default_prefs;
extern bool imported;
void setup_system_prefs(void);