Keep headless runs' settings in a folder of their own (QET_SETTINGS_DIR)

The MCP server gives each QElectroTech run a private HOME and writes the
element collection path for it (elements_dir) into
~/.config/QElectroTech/QElectroTech.conf there. Only Linux reads that
file: Qt keeps settings in the registry on Windows and in the system
preferences on macOS. So on those systems elements_dir did nothing, and
every run read the user's own settings (#1178).

When QET_SETTINGS_DIR names a folder, QElectroTech now keeps its
settings in <folder>/QElectroTech/QElectroTech.ini on every system. It is
set in main() before the first setting is read. Without the variable
nothing changes.

The server sets it for each run and writes the collection path to the
.ini as well as the .conf, so an older QElectroTech keeps working on
Linux. The path is written with forward slashes: Qt reads a backslash in
these files as an escape. The README notes that elements_dir needs this
on Windows and macOS, and that long arguments go on stdin with "-"
(Windows refuses a command line over 32,767 characters).

tst_settingsdir: a script places a symbol that only the folder's settings
can resolve, while the usual settings file points at an empty collection.
It fails on master and passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-01 08:00:55 +13:00
parent 2a6155e0c9
commit 65a1080cd3
6 changed files with 214 additions and 14 deletions
+14
View File
@@ -35,6 +35,7 @@
#include <QDomImplementation>
#include <QFont>
#include <QSettings>
#include <QStyleFactory>
#include <QtConcurrentRun>
@@ -103,6 +104,19 @@ int main(int argc, char **argv)
QCoreApplication::setOrganizationDomain("qelectrotech.org");
QCoreApplication::setApplicationName("QElectroTech");
// QET_SETTINGS_DIR keeps the settings in an INI file in that folder,
// <folder>/QElectroTech/QElectroTech.ini, instead of the registry on
// Windows, the system preferences on macOS or ~/.config on Linux. A tool
// running QElectroTech headlessly (misc/qet-mcp) can then give each run
// its own settings, and point it at an element collection, on every
// system (issue #1178). Set before anything reads a setting.
const QString settings_dir = qEnvironmentVariable("QET_SETTINGS_DIR");
if (!settings_dir.isEmpty()) {
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, settings_dir);
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, settings_dir);
}
// Refuse invalid data when building QDom documents instead of
// serializing malformed XML (CVE-2026-15037). This is the default
// from Qt 6.12 on; opt in explicitly for older Qt 5/6.