diff --git a/src/environment.cpp b/src/environment.cpp index 84d780e..d1faabf 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -24,6 +24,7 @@ class Line }; static std::vector> lines; +static std::string _filename; Line::Line(void) { @@ -104,6 +105,10 @@ static void processLine(QString line) void environmentInit(std::string filename) { + // Store filename in this translation unit so that environmentSave() uses the same one with no + // additional effort from the caller. + _filename = filename; + if (access(filename.c_str(), F_OK)) { info("environment file not found '{}'", filename); return; @@ -117,9 +122,9 @@ void environmentInit(std::string filename) stream.close(); } -void environmentSave(std::string filename) +void environmentSave(void) { - std::ofstream ofs(filename); + std::ofstream ofs(_filename); for (auto &line : lines) { if (!line->isKeyValuePair) { ofs << line->data.toStdString() << std::endl; diff --git a/src/environment.h b/src/environment.h index c6a15c0..38e9722 100644 --- a/src/environment.h +++ b/src/environment.h @@ -8,6 +8,6 @@ int environmentGetInt(QString key); void environmentSet(QString key, QString value); void environmentSetInt(QString key, int value); void environmentInit(std::string filename); -void environmentSave(std::string filename); +void environmentSave(void); #endif /* ENVIRONMENT_H */ diff --git a/src/maindialog.cpp b/src/maindialog.cpp index ca9709f..07da5c1 100644 --- a/src/maindialog.cpp +++ b/src/maindialog.cpp @@ -148,13 +148,8 @@ void MainDialog::onApply() m_pageMouse->onApply(); m_pageLanguage->onApply(); - // TODO: Get filename in a more consistent way - share common code with main.cpp - std::string config_home = std::getenv("HOME") + std::string("/.config/labwc"); - std::string config_dir = std::getenv("LABWC_CONFIG_DIR") ?: config_home; - std::string environment_file = config_dir + "/environment"; - xml_save(); - environmentSave(environment_file); + environmentSave(); /* reconfigure labwc */ if (!fork()) {