Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Line
};

static std::vector<std::unique_ptr<Line>> lines;
static std::string _filename;

Line::Line(void)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
7 changes: 1 addition & 6 deletions src/maindialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down