Skip to content

Commit ab65aeb

Browse files
committed
Remove "projectMSDL_UI.properties file
Having three configuration files is just too confusing. Users will rarely need to edit the configuration file by hand, so one "projectMSDL.properties" file in the user's app data dir will suffice.
1 parent cded180 commit ab65aeb

File tree

4 files changed

+56
-107
lines changed

4 files changed

+56
-107
lines changed

src/ProjectMSDLApplication.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void ProjectMSDLApplication::initialize(Poco::Util::Application& self)
4545

4646
try
4747
{
48-
//if (loadConfiguration(PRIO_DEFAULT) == 0)
48+
if (loadConfiguration(PRIO_DEFAULT) == 0)
4949
{
5050
// The file may be located in the ../Resources bundle dir on macOS, elsewhere relative
5151
// to the executable or within an absolute path.
@@ -75,28 +75,25 @@ void ProjectMSDLApplication::initialize(Poco::Util::Application& self)
7575
// Try to load user's custom configuration file.
7676
Poco::Path userConfigurationFile = userConfigurationDir;
7777
userConfigurationFile.setFileName(configFileName);
78-
if (Poco::File(userConfigurationFile).exists())
79-
{
80-
loadConfiguration(userConfigurationFile.toString(), PRIO_DEFAULT - 10);
81-
}
82-
83-
// Lastly, load user's UI configuration file into a separate instance.
84-
// This is used to save any config changes made via the UI, so it can be reset independently.
85-
userConfigurationFile.setFileName(config().getString("application.baseName") + "_UI.properties");
8678
if (!Poco::File(userConfigurationFile).exists())
8779
{
8880
Poco::File(userConfigurationDir).createDirectories();
8981
Poco::File(userConfigurationFile).createFile();
9082
}
91-
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> uiConfiguration = new Poco::Util::PropertyFileConfiguration(userConfigurationFile.toString());
92-
config().add(uiConfiguration, PRIO_DEFAULT - 20);
93-
getSubsystem<ProjectMGUI>().UIConfiguration(uiConfiguration);
83+
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> userConfiguration = new Poco::Util::PropertyFileConfiguration(userConfigurationFile.toString());
84+
config().add(userConfiguration, PRIO_DEFAULT - 10);
85+
86+
// Pass the config data to the UI
87+
getSubsystem<ProjectMGUI>().UserConfiguration(userConfiguration);
9488
}
9589
catch (Poco::Exception& ex)
9690
{
9791
poco_error_f1(logger(), "Failed to load/create user configuration file: %s", ex.displayText());
9892
}
9993

94+
// Add another layer on top for temporary command-line parameter overrides
95+
config().add(new Poco::Util::MapConfiguration(), PRIO_DEFAULT - 30);
96+
10097
Application::initialize(self);
10198
}
10299

src/gui/ProjectMGUI.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ void ProjectMGUI::uninitialize()
6161
_glContext = nullptr;
6262
}
6363

64-
void ProjectMGUI::UIConfiguration(Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config)
64+
void ProjectMGUI::UserConfiguration(Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config)
6565
{
66-
_uiConfig = config;
66+
_userConfiguration = std::move(config);
6767
}
6868

69-
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> ProjectMGUI::UIConfiguration()
69+
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> ProjectMGUI::UserConfiguration()
7070
{
71-
return _uiConfig;
71+
return _userConfiguration;
7272
}
7373

7474
void ProjectMGUI::CommandLineConfiguration(Poco::AutoPtr<Poco::Util::MapConfiguration> config)

src/gui/ProjectMGUI.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ class ProjectMGUI : public Poco::Util::Subsystem
3030
void uninitialize() override;
3131

3232
/**
33-
* @brief Sets the UI configuration file.
34-
* @param config The properties file instance which stores the UI settings.
33+
* @brief Sets the current user's configuration file.
34+
* @param config The properties file instance which stores the settings for the current user.
3535
*/
36-
void UIConfiguration(Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config);
36+
void UserConfiguration(Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> config);
3737

3838
/**
39-
* @brief Returns the UI configuration file.
40-
* @return The properties file instance which stores the UI settings.
39+
* @brief Returns the user configuration file.
40+
* @return The properties file instance which stores the settings for the current user.
4141
*/
42-
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> UIConfiguration();
42+
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> UserConfiguration();
4343

4444
/**
4545
* @brief Sets the command line override map.
@@ -129,7 +129,7 @@ class ProjectMGUI : public Poco::Util::Subsystem
129129

130130
ProjectMWrapper* _projectMWrapper{nullptr};
131131

132-
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> _uiConfig; //!< The UI configuration, used to store/reset changes made in the UI's settings dialog.
132+
Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> _userConfiguration; //!< The current user's configuration, used to store/reset changes made in the UI's settings dialog.
133133
Poco::AutoPtr<Poco::Util::MapConfiguration> _commandLineOverrides; //!< The command-line override settings.
134134

135135
Poco::NObserver<ProjectMGUI, DisplayToastNotification> _displayToastNotificationObserver{*this, &ProjectMGUI::DisplayToastNotificationHandler};

src/gui/SettingsWindow.cpp

Lines changed: 36 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ void SettingsWindow::Draw()
3434

3535
if (ImGui::BeginTabItem("projectM"))
3636
{
37-
if (ImGui::BeginTable("projectM", 3, tableFlags))
37+
if (ImGui::BeginTable("projectM", 4, tableFlags))
3838
{
3939
ImGui::TableSetupColumn("##desc", ImGuiTableColumnFlags_WidthFixed, .0f);
4040
ImGui::TableSetupColumn("##setting", ImGuiTableColumnFlags_WidthStretch, .0f);
4141
ImGui::TableSetupColumn("##reset", ImGuiTableColumnFlags_WidthFixed, 100.0f);
42+
ImGui::TableSetupColumn("##override", ImGuiTableColumnFlags_WidthFixed, .0f);
4243

4344
ImGui::TableNextRow();
4445
LabelWithTooltip("Preset Path", "Path to search for preset files if no playlist is loaded.");
@@ -146,20 +147,13 @@ void SettingsWindow::PathSetting(const std::string& property)
146147
{
147148
ImGui::TableSetColumnIndex(1);
148149

149-
auto path = Poco::Util::Application::instance().config().getString(property, "");
150+
auto path = _gui.UserConfiguration()->getString(property, "");
150151
char pathBuffer[2048]{};
151152
strncpy(pathBuffer, path.c_str(), std::min<size_t>(2047, path.size()));
152153

153-
bool isOverridden{false};
154-
if (_gui.CommandLineConfiguration()->has(property))
155-
{
156-
isOverridden = true;
157-
ImGui::BeginDisabled();
158-
}
159-
160154
if (ImGui::InputText(std::string("##path_" + property).c_str(), &pathBuffer[0], IM_ARRAYSIZE(pathBuffer), ImGuiInputTextFlags_EnterReturnsTrue))
161155
{
162-
_gui.UIConfiguration()->setString(property, std::string(pathBuffer));
156+
_gui.UserConfiguration()->setString(property, std::string(pathBuffer));
163157
}
164158

165159
ImGui::SameLine();
@@ -170,140 +164,98 @@ void SettingsWindow::PathSetting(const std::string& property)
170164
}
171165
ImGui::PopID();
172166

173-
if (isOverridden)
167+
ResetButton(property);
168+
169+
if (_gui.CommandLineConfiguration()->has(property))
174170
{
175-
ImGui::EndDisabled();
176171
OverriddenSettingMarker();
177172
}
178-
else
179-
{
180-
ResetButton(property);
181-
}
182173
}
183174

184175

185176
void SettingsWindow::BooleanSetting(const std::string& property, bool defaultValue)
186177
{
187178
ImGui::TableSetColumnIndex(1);
188179

189-
auto value = Poco::Util::Application::instance().config().getBool(property, defaultValue);
190-
191-
bool isOverridden{false};
192-
if (_gui.CommandLineConfiguration()->has(property))
193-
{
194-
isOverridden = true;
195-
ImGui::BeginDisabled();
196-
}
180+
auto value = _gui.UserConfiguration()->getBool(property, defaultValue);
197181

198182
if (ImGui::Checkbox(std::string("##boolean_" + property).c_str(), &value))
199183
{
200-
_gui.UIConfiguration()->setBool(property, value);
184+
_gui.UserConfiguration()->setBool(property, value);
201185
}
202186

203-
if (isOverridden)
187+
ResetButton(property);
188+
189+
if (_gui.CommandLineConfiguration()->has(property))
204190
{
205-
ImGui::EndDisabled();
206191
OverriddenSettingMarker();
207192
}
208-
else
209-
{
210-
ResetButton(property);
211-
}
212193
}
213194

214195
void SettingsWindow::IntegerSetting(const std::string& property, int defaultValue, int min, int max)
215196
{
216197
ImGui::TableSetColumnIndex(1);
217198

218-
auto value = Poco::Util::Application::instance().config().getInt(property, defaultValue);
219-
220-
bool isOverridden{false};
221-
if (_gui.CommandLineConfiguration()->has(property))
222-
{
223-
isOverridden = true;
224-
ImGui::BeginDisabled();
225-
}
199+
auto value = _gui.UserConfiguration()->getInt(property, defaultValue);
226200

227201
if (ImGui::SliderInt(std::string("##integer_" + property).c_str(), &value, min, max))
228202
{
229-
_gui.UIConfiguration()->setInt(property, value);
203+
_gui.UserConfiguration()->setInt(property, value);
230204
}
231205

232-
if (isOverridden)
206+
ResetButton(property);
207+
208+
if (_gui.CommandLineConfiguration()->has(property))
233209
{
234-
ImGui::EndDisabled();
235210
OverriddenSettingMarker();
236211
}
237-
else
238-
{
239-
ResetButton(property);
240-
}
241212
}
242213

243214
void SettingsWindow::IntegerSettingVec(const std::string& property1, const std::string& property2, int defaultValue1, int defaultValue2, int min, int max)
244215
{
245216
ImGui::TableSetColumnIndex(1);
246217

247218
int values[2] = {
248-
Poco::Util::Application::instance().config().getInt(property1, defaultValue1),
249-
Poco::Util::Application::instance().config().getInt(property2, defaultValue2)};
250-
251-
bool isOverridden{false};
252-
if (_gui.CommandLineConfiguration()->has(property1) || _gui.CommandLineConfiguration()->has(property2))
253-
{
254-
isOverridden = true;
255-
ImGui::BeginDisabled();
256-
}
219+
_gui.UserConfiguration()->getInt(property1, defaultValue1),
220+
_gui.UserConfiguration()->getInt(property2, defaultValue2)};
257221

258222
if (ImGui::SliderInt2(std::string("##integer_" + property1 + property2).c_str(), values, min, max))
259223
{
260-
_gui.UIConfiguration()->setInt(property1, values[0]);
261-
_gui.UIConfiguration()->setInt(property2, values[1]);
224+
_gui.UserConfiguration()->setInt(property1, values[0]);
225+
_gui.UserConfiguration()->setInt(property2, values[1]);
262226
}
263227

264-
if (isOverridden)
228+
ResetButton(property1, property2);
229+
230+
if (_gui.CommandLineConfiguration()->has(property1) || _gui.CommandLineConfiguration()->has(property2))
265231
{
266-
ImGui::EndDisabled();
267232
OverriddenSettingMarker();
268233
}
269-
else
270-
{
271-
ResetButton(property1, property2);
272-
}
234+
273235
}
274236

275237
void SettingsWindow::DoubleSetting(const std::string& property, double defaultValue, double min, double max)
276238
{
277239
ImGui::TableSetColumnIndex(1);
278240

279-
auto value = static_cast<float>(Poco::Util::Application::instance().config().getDouble(property, defaultValue));
280-
281-
bool isOverridden{false};
282-
if (_gui.CommandLineConfiguration()->has(property))
283-
{
284-
isOverridden = true;
285-
ImGui::BeginDisabled();
286-
}
241+
auto value = static_cast<float>(_gui.UserConfiguration()->getDouble(property, defaultValue));
287242

288243
if (ImGui::SliderFloat(std::string("##double_" + property).c_str(), &value, static_cast<float>(min), static_cast<float>(max)))
289244
{
290-
_gui.UIConfiguration()->setDouble(property, value);
245+
_gui.UserConfiguration()->setDouble(property, value);
291246
}
292247

293-
if (isOverridden)
248+
ResetButton(property);
249+
250+
if (_gui.CommandLineConfiguration()->has(property))
294251
{
295-
ImGui::EndDisabled();
296252
OverriddenSettingMarker();
297253
}
298-
else
299-
{
300-
ResetButton(property);
301-
}
302254
}
303255

304256
void SettingsWindow::ResetButton(const std::string& property1, const std::string& property2)
305257
{
306-
if (!_gui.UIConfiguration()->has(property1) && (property2.empty() || !_gui.UIConfiguration()->has(property2)))
258+
if (!_gui.UserConfiguration()->has(property1) && (property2.empty() || !_gui.UserConfiguration()->has(property2)))
307259
{
308260
return;
309261
}
@@ -313,25 +265,25 @@ void SettingsWindow::ResetButton(const std::string& property1, const std::string
313265
ImGui::PushID(std::string(property1 + property2 + "_ResetButton").c_str());
314266
if (ImGui::Button("Reset"))
315267
{
316-
_gui.UIConfiguration()->remove(property1);
268+
_gui.UserConfiguration()->remove(property1);
317269
if (!property2.empty())
318270
{
319-
_gui.UIConfiguration()->remove(property2);
271+
_gui.UserConfiguration()->remove(property2);
320272
}
321273
}
322274
ImGui::PopID();
323275
}
324276

325277
void SettingsWindow::OverriddenSettingMarker()
326278
{
327-
ImGui::TableSetColumnIndex(2);
279+
ImGui::TableSetColumnIndex(3);
328280

329-
ImGui::TextColored(ImVec4(1, 0, 0, 1), "[Locked]");
281+
ImGui::TextColored(ImVec4(1, 0, 0, 1), "[!]");
330282
if (ImGui::IsItemHovered())
331283
{
332284
ImGui::BeginTooltip();
333285
ImGui::TextUnformatted("Value set via command line argument.");
334-
ImGui::TextUnformatted("Can only be changed if not overridden.");
286+
ImGui::TextUnformatted("It will only be used if not overridden.");
335287
ImGui::EndTooltip();
336288
}
337289
}

0 commit comments

Comments
 (0)