Delay loading of some settings until later

This early in init_ui() the settings may not be available, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-06-12 11:52:59 -07:00
parent 6227372c2f
commit 21be237b0e
2 changed files with 17 additions and 21 deletions

View file

@ -49,16 +49,6 @@ static MainWindow *window = NULL;
int error_count; int error_count;
const char *existing_filename; const char *existing_filename;
const char *getSetting(QSettings &s, QString name)
{
QVariant v;
v = s.value(name);
if (v.isValid()) {
return strdup(v.toString().toUtf8().data());
}
return NULL;
}
#if defined(Q_OS_WIN) && QT_VERSION < 0x050000 #if defined(Q_OS_WIN) && QT_VERSION < 0x050000
static QByteArray encodeUtf8(const QString &fname) static QByteArray encodeUtf8(const QString &fname)
{ {
@ -103,9 +93,6 @@ QString uiLanguage(QLocale *callerLoc)
void init_ui(void) void init_ui(void)
{ {
QVariant v;
QSettings s;
// tell Qt to use system proxies // tell Qt to use system proxies
// note: on Linux, "system" == "environment variables" // note: on Linux, "system" == "environment variables"
QNetworkProxyFactory::setUseSystemConfiguration(true); QNetworkProxyFactory::setUseSystemConfiguration(true);
@ -151,15 +138,7 @@ void init_ui(void)
qDebug() << "can't find Subsurface localization for locale" << uiLang; qDebug() << "can't find Subsurface localization for locale" << uiLang;
} }
} }
s.beginGroup("DiveComputer");
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
default_dive_computer_product = getSetting(s, "dive_computer_product");
default_dive_computer_device = getSetting(s, "dive_computer_device");
s.endGroup();
window = new MainWindow(); window = new MainWindow();
window->loadRecentFiles(&s);
if (existing_filename && existing_filename[0] != '\0') if (existing_filename && existing_filename[0] != '\0')
window->setTitle(MWTF_FILENAME); window->setTitle(MWTF_FILENAME);
else else

View file

@ -769,6 +769,16 @@ void MainWindow::initialUiSetup()
settings.endGroup(); settings.endGroup();
} }
const char *getSetting(QSettings &s, QString name)
{
QVariant v;
v = s.value(name);
if (v.isValid()) {
return strdup(v.toString().toUtf8().data());
}
return NULL;
}
#define TOOLBOX_PREF_BUTTON(pref, setting, button) \ #define TOOLBOX_PREF_BUTTON(pref, setting, button) \
prefs.pref = s.value(#setting).toBool(); \ prefs.pref = s.value(#setting).toBool(); \
ui.button->setChecked(prefs.pref); ui.button->setChecked(prefs.pref);
@ -797,6 +807,13 @@ void MainWindow::readSettings()
TOOLBOX_PREF_BUTTON(hrgraph, hrgraph, profHR); TOOLBOX_PREF_BUTTON(hrgraph, hrgraph, profHR);
TOOLBOX_PREF_BUTTON(rulergraph, rulergraph, profRuler); TOOLBOX_PREF_BUTTON(rulergraph, rulergraph, profRuler);
TOOLBOX_PREF_BUTTON(show_sac, show_sac, profSAC); TOOLBOX_PREF_BUTTON(show_sac, show_sac, profSAC);
s.endGroup();
s.beginGroup("DiveComputer");
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
default_dive_computer_product = getSetting(s, "dive_computer_product");
default_dive_computer_device = getSetting(s, "dive_computer_device");
s.endGroup();
loadRecentFiles(&s);
} }
#undef TOOLBOX_PREF_BUTTON #undef TOOLBOX_PREF_BUTTON