Add a setup assistant for unconfigured profiles (#174)

A profile without a callsign of its own now starts in a setup assistant instead
of the twelve-tab settings window. It asks for name, login, locator, bands and
chat category, and optionally for antenna and power, log program, rotator and
AirScout. Login and station can each be taken from another configured profile.

The assistant runs in startRuntime after the profile is resolved and before the
ChatController exists. It works on a ChatPreferences of its own, writes
preferences.xml, and the runtime then reads that file like any stored setting.
It never touches a running session. From the Options menu the runtime is torn
down first and the same profile restarted with the assistant in front.

A station set up anew gets only what the operator confirmed: the bundled
template has several integrations enabled, and the assistant switches off what
was not chosen and names it in its summary. A station left unchanged is written
page by page, only for pages the operator opened. A taken station is the whole
station, every setter listed in wizard-station-setters.txt; a test fails when a
new ChatPreferences setter is classified in neither list.

Changes outside the assistant:
- ChatPreferences.readPreferencesFromXmlFile() returns false when the file could
  not be read or parsed, or its root element is not praktiKST. It reads on as
  before, and its two existing callers ignore the return value.
- ApplicationRuntimeLauncher.switchProfile refuses a second switch while one is
  in progress.
- The Log synch tab's file chooser takes an optional owner dialog.

The design and its reasons are in
docs/superpowers/specs/2026-11-18-einrichtungsassistent-design.md.

Written-by: Claude Fable 5.2
Written-by: DeepSeek V4 Pro
Written-by: Gemini 4 Hydrogen (Antigravity)
Written-by: Codex (GPT-6.2 Sol)
This commit is contained in:
Rsclub2_2 authored and GitHub committed 2026-11-18 23:16:52 +01:00
1 parent b0960a3f04
commit 1dd0139e10
36 files changed
+5768 -25

No files matched your search

@@ -0,0 +1,53 @@
package kst4contest.controller;
import kst4contest.model.ChatPreferences;
/**
* Tells whether a profile has login credentials an operator entered.
*
* <p>Two states count as unconfigured. An empty callsign is what every created or duplicated
* profile starts with, because {@link OperatorProfileManagementService} clears the
* credentials on purpose. The bundled template's credentials are what the root profile of a
* fresh installation carries. Neither can log in as the operator, so neither needs a flag of
* its own in {@code preferences.xml}.</p>
*/
public final class LoginConfiguration {
/** Callsign shipped in {@code praktiKSTpreferences.xml}; held equal by a test. */
public static final String TEMPLATE_CALLSIGN = "DO5AMF";
/** Password shipped in {@code praktiKSTpreferences.xml}; held equal by a test. */
public static final String TEMPLATE_PASSWORD = "changeMe";
private LoginConfiguration() {
// Utility class.
}
/**
* Whether the preferences still hold the bundled template's credentials.
*
* <p>Only the pair counts. The callsign alone belongs to a real operator.</p>
*
* @param preferences preferences of the profile to judge
* @return true for an untouched template
*/
public static boolean carriesTemplateCredentials(final ChatPreferences preferences) {
return TEMPLATE_CALLSIGN.equalsIgnoreCase(trimmed(preferences.getStn_loginCallSign()))
&& TEMPLATE_PASSWORD.equals(preferences.getStn_loginPassword());
}
/**
* Whether the profile has no login an operator entered.
*
* @param preferences preferences of the profile to judge
* @return true when the callsign is empty or the template's credentials are still there
*/
public static boolean isUnconfigured(final ChatPreferences preferences) {
return trimmed(preferences.getStn_loginCallSign()).isEmpty()
|| carriesTemplateCredentials(preferences);
}
private static String trimmed(final String value) {
return value == null ? "" : value.trim();
}
}
@@ -2601,6 +2601,8 @@ public class ChatPreferences {
*/
public boolean readPreferencesFromXmlFile() {
boolean readable = true;
System.out.println("[ChatPreferences, Info]: restoring prefs from file " + storeAndRestorePreferencesFileName);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -2617,6 +2619,10 @@ public class ChatPreferences {
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(xmlConfigFile);
Element rootElement = doc.getDocumentElement();
if (rootElement == null || !"praktiKST".equals(rootElement.getTagName())) {
readable = false;
}
NodeList list;
// --- Schema version (optional) ---
@@ -3457,13 +3463,14 @@ public class ChatPreferences {
} catch (ParserConfigurationException | SAXException | IOException e) {
readable = false;
e.printStackTrace();
System.out.println(e.getCause());
System.out.println(e.getMessage());
}
initializeActualQtfFromDefaultIfRequired();
return true;
return readable;
}
@@ -0,0 +1,79 @@
package kst4contest.controller;
import kst4contest.model.ChatPreferences;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* When a profile counts as not set up yet. The setup wizard appears on exactly this
* condition, so a wrong answer either nags a working station or leaves a newcomer alone
* with the template's callsign.
*/
class LoginConfigurationTest {
@TempDir
Path temporaryDirectory;
private ChatPreferences preferences(String callsign, String password) {
ChatPreferences preferences = new ChatPreferences(temporaryDirectory.resolve("unused.xml"));
preferences.setStn_loginCallSign(callsign);
preferences.setStn_loginPassword(password);
return preferences;
}
@Test
void anEmptyCallsignIsUnconfigured() {
assertTrue(LoginConfiguration.isUnconfigured(preferences("", "secret")));
assertTrue(LoginConfiguration.isUnconfigured(preferences(" ", "secret")));
}
@Test
void theTemplateCredentialsAreUnconfigured() {
ChatPreferences template = preferences("DO5AMF", "changeMe");
assertTrue(LoginConfiguration.carriesTemplateCredentials(template));
assertTrue(LoginConfiguration.isUnconfigured(template));
}
@Test
void theTemplateCallsignWithItsOwnPasswordIsConfigured() {
// The callsign belongs to a real operator; only the pair marks an untouched template.
ChatPreferences owner = preferences("DO5AMF", "a-real-password");
assertFalse(LoginConfiguration.carriesTemplateCredentials(owner));
assertFalse(LoginConfiguration.isUnconfigured(owner));
}
@Test
void aRealLoginIsConfigured() {
assertFalse(LoginConfiguration.isUnconfigured(preferences("DL0TEST", "secret")));
assertFalse(LoginConfiguration.isUnconfigured(preferences("DL0TEST/P", "")));
}
@Test
void theConstantsMatchTheBundledTemplate() throws IOException {
Path templateCopy = temporaryDirectory.resolve("template.xml");
try (InputStream template = ChatPreferences.class
.getResourceAsStream(ChatPreferences.PREFERENCE_RESOURCE)) {
assertNotNull(template, "bundled resource " + ChatPreferences.PREFERENCE_RESOURCE);
Files.copy(template, templateCopy, StandardCopyOption.REPLACE_EXISTING);
}
ChatPreferences fromTemplate = new ChatPreferences(templateCopy);
assertTrue(fromTemplate.readPreferencesFromXmlFile());
assertTrue(LoginConfiguration.carriesTemplateCredentials(fromTemplate),
"the template's credentials changed; a fresh installation would no longer "
+ "be recognised as unconfigured");
}
}
@@ -0,0 +1,72 @@
package kst4contest.model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Pins the return value of {@link ChatPreferences#readPreferencesFromXmlFile()}: it must
* report a failed read as {@code false} so callers such as the setup wizard launcher can
* tell an unreadable profile file from a readable one.
*/
class ChatPreferencesReadResultTest {
@TempDir
Path temporaryDirectory;
@Test
void aFileThatIsNotXmlIsReportedAsUnreadable() throws IOException {
Path file = temporaryDirectory.resolve("notxml.xml");
byte[] original = "this is not xml <<<".getBytes(StandardCharsets.UTF_8);
Files.write(file, original);
ChatPreferences preferences = new ChatPreferences(file);
assertFalse(preferences.readPreferencesFromXmlFile(), "a non-XML file must be reported as unreadable");
assertArrayEquals(original, Files.readAllBytes(file), "the unreadable file must be left untouched");
}
@Test
void aMissingFileIsReportedAsUnreadable() {
Path file = temporaryDirectory.resolve("missing.xml");
ChatPreferences preferences = new ChatPreferences(file);
assertFalse(preferences.readPreferencesFromXmlFile(), "a missing file must be reported as unreadable");
assertFalse(Files.exists(file), "reading a missing file must not create it");
}
@Test
void aWellFormedXmlWithForeignRootIsReportedAsUnreadable() throws IOException {
Path file = temporaryDirectory.resolve("foreign.xml");
byte[] original = "<somethingElse><station><LoginCallSign>DL0TEST</LoginCallSign></station></somethingElse>"
.getBytes(StandardCharsets.UTF_8);
Files.write(file, original);
ChatPreferences preferences = new ChatPreferences(file);
assertFalse(preferences.readPreferencesFromXmlFile(), "a foreign XML root must be reported as unreadable");
assertArrayEquals(original, Files.readAllBytes(file), "the foreign XML file must be left untouched");
}
@Test
void theBundledTemplateIsReadable() throws IOException {
Path templateCopy = temporaryDirectory.resolve("template.xml");
try (InputStream template = ChatPreferences.class
.getResourceAsStream(ChatPreferences.PREFERENCE_RESOURCE)) {
assertNotNull(template, "bundled resource " + ChatPreferences.PREFERENCE_RESOURCE);
Files.copy(template, templateCopy, StandardCopyOption.REPLACE_EXISTING);
}
ChatPreferences fromTemplate = new ChatPreferences(templateCopy);
assertTrue(fromTemplate.readPreferencesFromXmlFile(), "the bundled template must be readable");
}
}