mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Name what a taken station drops and keep a profile from being its own donor
Written-by: Gemini 4 Hydrogen (Antigravity) Written-by: Claude Fable 5.2
This commit is contained in:
14 files changed
+211
-12
No files matched your search
@@ -584,3 +584,6 @@ wizard.source.stationTake=Station von Profil „{0}" übernehmen (Locator {1})
|
||||
wizard.source.stationTakeFrom=Station von einem anderen Profil übernehmen
|
||||
wizard.entry.donor=Profil
|
||||
wizard.summary.takenFrom=Übernommen von Profil „{0}"
|
||||
wizard.switch.so2r=SO2R
|
||||
wizard.switch.rotator2=PSTRotator 2
|
||||
wizard.summary.fallbackBand=Ausweichband für Spots
|
||||
@@ -593,3 +593,6 @@ wizard.source.stationTake=Take the station from profile "{0}" (locator {1})
|
||||
wizard.source.stationTakeFrom=Take the station from another profile
|
||||
wizard.entry.donor=Profile
|
||||
wizard.summary.takenFrom=Taken from profile "{0}"
|
||||
wizard.switch.so2r=SO2R
|
||||
wizard.switch.rotator2=PSTRotator 2
|
||||
wizard.summary.fallbackBand=Fallback band for spots
|
||||
@@ -303,6 +303,8 @@ private fun switchName(switch: WizardSwitch, strings: Strings): String = when (s
|
||||
WizardSwitch.CLUSTER_SERVER -> strings.wizardSwitchClusterServer
|
||||
WizardSwitch.ROTATOR -> strings.wizardSwitchRotator
|
||||
WizardSwitch.AIRSCOUT -> strings.wizardSwitchAirScout
|
||||
WizardSwitch.SO2R -> strings.wizardSwitchSo2r
|
||||
WizardSwitch.ROTATOR_2 -> strings.wizardSwitchRotator2
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -442,6 +444,10 @@ private fun SummaryPage(state: SetupWizardState, strings: Strings, saveFailed: B
|
||||
WizardBand.entries.filter { it in state.bands }.joinToString(", ") { it.label }
|
||||
.ifEmpty { strings.wizardSummaryNone },
|
||||
)
|
||||
SummaryRow(
|
||||
strings.wizardSummaryFallbackBand,
|
||||
if (state.summaryFallbackBand.isBlank()) strings.wizardSummaryNone else "${state.summaryFallbackBand} MHz",
|
||||
)
|
||||
SummaryRow(
|
||||
strings.stationMainCategory,
|
||||
state.category?.let(::categoryName) ?: strings.wizardSummaryNone,
|
||||
|
||||
@@ -426,22 +426,45 @@ class SetupWizardState(prefs: ChatPreferences, val donors: List<WizardDonor> = e
|
||||
val summaryClusterServer: Boolean
|
||||
get() = if (logShown) integrations.networked && integrations.clusterServer else integrations.storedClusterServer
|
||||
|
||||
/**
|
||||
* The fallback band prefix the profile has after Save, for the summary: taken with the
|
||||
* donor's station when chosen, otherwise left as the own profile holds it.
|
||||
*/
|
||||
val summaryFallbackBand: String
|
||||
get() {
|
||||
val sourcePrefs = stationDonor?.takeIf { stationSource == WizardSource.TAKE }?.prefs ?: ownPrefs
|
||||
return sourcePrefs.getNotify_optionalFrequencyPrefix()?.get().orEmpty()
|
||||
}
|
||||
|
||||
/** Rotator 2 only counts while SO2R uses it, as on the Station tab. */
|
||||
private fun so2rSwitches(prefs: ChatPreferences): Set<WizardSwitch> = buildSet {
|
||||
if (prefs.isTrxSynch_so2rEnabled()) {
|
||||
add(WizardSwitch.SO2R)
|
||||
if (prefs.isStn_pstRotator2Enabled()) add(WizardSwitch.ROTATOR_2)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* What is on in the own profile and will be off after Save, for the summary. Always
|
||||
* against the own profile: with a station taken from another one, that is what the
|
||||
* operator loses, whatever the other profile had.
|
||||
*
|
||||
* A page that is not part of the run contributes what its profile holds -- the own one
|
||||
* for a station left unchanged, the donor's for a station taken over.
|
||||
* for a station left unchanged, the donor's for a station taken over. The wizard never
|
||||
* writes SO2R or rotator 2 itself, so after Save they come from the donor when taking
|
||||
* over a station, otherwise from the own profile.
|
||||
*/
|
||||
val switchedOff: List<WizardSwitch>
|
||||
get() {
|
||||
val neverAskedPrefs = stationDonor?.takeIf { stationSource == WizardSource.TAKE }?.prefs ?: ownPrefs
|
||||
val after = buildSet {
|
||||
if (secondChat) add(WizardSwitch.SECOND_CHAT)
|
||||
addAll(if (logShown) integrations.answeredLogSwitches() else integrations.storedLogSwitches())
|
||||
addAll(if (gearShown) integrations.answeredGearSwitches() else integrations.storedGearSwitches())
|
||||
addAll(so2rSwitches(neverAskedPrefs))
|
||||
}
|
||||
val before = ownSwitches + if (ownStation.secondChat) setOf(WizardSwitch.SECOND_CHAT) else emptySet()
|
||||
val before = ownSwitches + so2rSwitches(ownPrefs) +
|
||||
if (ownStation.secondChat) setOf(WizardSwitch.SECOND_CHAT) else emptySet()
|
||||
return WizardSwitch.entries.filter { it in before && it !in after }
|
||||
}
|
||||
|
||||
|
||||
@@ -133,16 +133,25 @@ internal class DonorCandidate(val profileId: String, val displayName: String, va
|
||||
|
||||
/**
|
||||
* Reads the candidates that can serve as donors: the file exists, can be read, and holds a
|
||||
* login an operator entered.
|
||||
* login an operator entered. A candidate whose file is the same file as [activeFile] (for
|
||||
* example through a symbolic link) is skipped so a profile never becomes its own donor.
|
||||
*
|
||||
* A candidate's file is opened through `ChatPreferences(Path)` and never through the
|
||||
* constructor that takes a name below the application directory: that one seeds a missing
|
||||
* file from the bundled template, and looking for a donor must not create a profile's file.
|
||||
* Nothing here writes.
|
||||
*/
|
||||
internal fun loadDonors(candidates: List<DonorCandidate>): List<WizardDonor> =
|
||||
internal fun loadDonors(
|
||||
candidates: List<DonorCandidate>,
|
||||
activeFile: Path? = null,
|
||||
): List<WizardDonor> =
|
||||
candidates.mapNotNull { candidate ->
|
||||
if (!Files.isRegularFile(candidate.file)) return@mapNotNull null
|
||||
if (activeFile != null && Files.exists(activeFile) &&
|
||||
runCatching { Files.isSameFile(candidate.file, activeFile) }.getOrDefault(false)
|
||||
) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
val prefs = ChatPreferences(candidate.file)
|
||||
// A throwing read counts as failed, as for the profile being set up.
|
||||
@@ -168,7 +177,17 @@ object SetupWizardLauncher {
|
||||
run(
|
||||
ChatPreferences(preferencesRelativeFileName),
|
||||
forced,
|
||||
{ loadDonors(otherProfiles(preferencesRelativeFileName)) },
|
||||
{
|
||||
loadDonors(
|
||||
otherProfiles(preferencesRelativeFileName),
|
||||
activeFile = Path.of(
|
||||
ApplicationFileUtils.getFilePath(
|
||||
ApplicationConstants.APPLICATION_NAME,
|
||||
preferencesRelativeFileName,
|
||||
)
|
||||
),
|
||||
)
|
||||
},
|
||||
SetupWizardWindow::show,
|
||||
)
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ class WizardAntenna(prefs: ChatPreferences) {
|
||||
|
||||
private val storedBeamWidthDeg = prefs.getStn_antennaBeamWidthDeg()
|
||||
private val storedGainDbi = prefs.getStn_pathAnalysisOwnAntennaGainDbi()
|
||||
private val storedHeightMeters = prefs.getStn_pathAnalysisOwnAntennaHeightMeters()
|
||||
// The XML reader assigns the field directly without clamping, whereas the setter and path analysis treat < 0 as 0.
|
||||
private val storedHeightMeters = prefs.getStn_pathAnalysisOwnAntennaHeightMeters().coerceAtLeast(0.0)
|
||||
private val storedTxPowerWatts = prefs.getStn_pathAnalysisOwnTxPowerWatts()
|
||||
private val storedHeightAslText = elevationText(prefs.getStn_pathAnalysisOwnHeightAslMeters())
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ enum class WizardSwitch {
|
||||
CLUSTER_SERVER,
|
||||
ROTATOR,
|
||||
AIRSCOUT,
|
||||
SO2R,
|
||||
ROTATOR_2,
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+17
@@ -272,4 +272,21 @@ class SetupWizardContentScreenTest {
|
||||
|
||||
assertEquals(WizardPage.ENTRY, state.page, "which profile is not said yet")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSummaryShowsTheFallbackBandForSpots() = runComposeUiTest {
|
||||
val prefs = configuredProfile().apply {
|
||||
setStn_bandActive144(false)
|
||||
setStn_bandActive432(true)
|
||||
setNotify_optionalFrequencyPrefix("144")
|
||||
}
|
||||
val state = SetupWizardState(prefs)
|
||||
state.chooseLoginSource(WizardSource.KEEP)
|
||||
state.chooseStationSource(WizardSource.KEEP)
|
||||
state.next()
|
||||
state.next()
|
||||
show(state)
|
||||
|
||||
onNodeWithText("144 MHz").assertExists()
|
||||
}
|
||||
}
|
||||
@@ -349,4 +349,98 @@ class SetupWizardDonorTest(@param:TempDir private val directory: Path) {
|
||||
assertFalse(restored.isStn_pstRotatorEnabled(), "the operator switched the taken rotator off")
|
||||
assertEquals("JN58QA", restored.getStn_loginLocatorMainCat(), "the operator changed the taken locator")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun takingAStationNamesSo2rAndRotatorTwoWhenTheDonorDropsThem() {
|
||||
val own = emptyProfile().apply {
|
||||
setTrxSynch_so2rEnabled(true)
|
||||
setStn_pstRotator2Enabled(true)
|
||||
}
|
||||
val donorOff = contestStation()
|
||||
val donorOn = WizardDonor("both-on", "Beide an", prefs {
|
||||
integrationsOff()
|
||||
setStn_loginCallSign("DL0BOTH")
|
||||
setStn_loginPassword("secret")
|
||||
setStn_loginLocatorMainCat("JO50AA")
|
||||
setStn_bandActive144(true)
|
||||
setLoginChatCategoryMain(ChatCategory(2))
|
||||
setLoginToSecondChatEnabled(false)
|
||||
setTrxSynch_so2rEnabled(true)
|
||||
setStn_pstRotator2Enabled(true)
|
||||
})
|
||||
|
||||
val takeDrops = SetupWizardState(own, listOf(donorOff)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.TAKE)
|
||||
next()
|
||||
}
|
||||
assertEquals(
|
||||
listOf(WizardSwitch.SO2R, WizardSwitch.ROTATOR_2),
|
||||
takeDrops.switchedOff.takeLast(2),
|
||||
)
|
||||
|
||||
val keep = SetupWizardState(own, listOf(donorOff)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.KEEP)
|
||||
next()
|
||||
}
|
||||
assertFalse(WizardSwitch.SO2R in keep.switchedOff)
|
||||
assertFalse(WizardSwitch.ROTATOR_2 in keep.switchedOff)
|
||||
|
||||
val takeKeeps = SetupWizardState(own, listOf(donorOn)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.TAKE)
|
||||
next()
|
||||
}
|
||||
assertFalse(WizardSwitch.SO2R in takeKeeps.switchedOff)
|
||||
assertFalse(WizardSwitch.ROTATOR_2 in takeKeeps.switchedOff)
|
||||
|
||||
val ownRotator2WithoutSo2r = emptyProfile().apply {
|
||||
setTrxSynch_so2rEnabled(false)
|
||||
setStn_pstRotator2Enabled(true)
|
||||
}
|
||||
val noSo2r = SetupWizardState(ownRotator2WithoutSo2r, listOf(donorOff)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.TAKE)
|
||||
next()
|
||||
}
|
||||
assertFalse(WizardSwitch.ROTATOR_2 in noSo2r.switchedOff)
|
||||
assertFalse(WizardSwitch.SO2R in noSo2r.switchedOff)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSummaryFallbackBandFollowsTheStationSource() {
|
||||
val own = emptyProfile().apply { setNotify_optionalFrequencyPrefix("144") }
|
||||
val donor = WizardDonor("uhf", "UHF", prefs {
|
||||
integrationsOff()
|
||||
setStn_loginCallSign("DL0UHF")
|
||||
setStn_loginPassword("secret")
|
||||
setStn_loginLocatorMainCat("JO50AA")
|
||||
setStn_bandActive432(true)
|
||||
setLoginChatCategoryMain(ChatCategory(2))
|
||||
setLoginToSecondChatEnabled(false)
|
||||
setNotify_optionalFrequencyPrefix("432")
|
||||
})
|
||||
|
||||
val take = SetupWizardState(own, listOf(donor)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.TAKE)
|
||||
next()
|
||||
}
|
||||
assertEquals("432", take.summaryFallbackBand)
|
||||
|
||||
val keep = SetupWizardState(own, listOf(donor)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.KEEP)
|
||||
next()
|
||||
}
|
||||
assertEquals("144", keep.summaryFallbackBand)
|
||||
|
||||
val fresh = SetupWizardState(own, listOf(donor)).apply {
|
||||
chooseLoginSource(WizardSource.NEW)
|
||||
chooseStationSource(WizardSource.NEW)
|
||||
next()
|
||||
}
|
||||
assertEquals("144", fresh.summaryFallbackBand)
|
||||
}
|
||||
}
|
||||
+18
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Files
|
||||
@@ -203,4 +204,21 @@ class SetupWizardLauncherTest(@param:TempDir private val directory: Path) {
|
||||
assertEquals(1, loaded)
|
||||
assertEquals(emptyList<WizardDonor>(), seen)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aLinkedDirectoryToTheActiveProfileIsNotOfferedAsItsOwnDonor() {
|
||||
val dirB = Files.createDirectory(directory.resolve("b"))
|
||||
val fileInB = dirB.resolve("preferences.xml")
|
||||
Files.copy(configuredFile(), fileInB, StandardCopyOption.REPLACE_EXISTING)
|
||||
val linkA = directory.resolve("a")
|
||||
val linked = runCatching { Files.createSymbolicLink(linkA, dirB) }
|
||||
Assumptions.assumeTrue(
|
||||
linked.isSuccess,
|
||||
"file system refused symbolic link: ${linked.exceptionOrNull()?.message}",
|
||||
)
|
||||
|
||||
val candidates = listOf(DonorCandidate("b", "B", fileInB))
|
||||
assertTrue(loadDonors(candidates, activeFile = linkA.resolve("preferences.xml")).isEmpty())
|
||||
assertEquals(listOf("b"), loadDonors(candidates).map { it.profileId })
|
||||
}
|
||||
}
|
||||
@@ -135,4 +135,17 @@ class WizardAntennaTest {
|
||||
assertEquals("612", antenna.heightAslText)
|
||||
assertTrue(antenna.complete)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aNegativeStoredAntennaHeightIsClampedToZero() {
|
||||
val prefs = stored()
|
||||
val field = ChatPreferences::class.java.getDeclaredField("stn_pathAnalysisOwnAntennaHeightMeters")
|
||||
field.isAccessible = true
|
||||
field.setDouble(prefs, -2.0)
|
||||
|
||||
val antenna = WizardAntenna(prefs)
|
||||
|
||||
assertEquals(0.0, antenna.heightMeters)
|
||||
assertTrue(antenna.complete)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user