Copy a station from one profile's preferences to another's

Written-by: DeepSeek V4 Pro
Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 22:22:05 +01:00
1 parent 9e5759adfe
commit 918f84dc8a
4 files changed
+415

No files matched your search

@@ -0,0 +1,106 @@
package kst4contest.view.compose.wizard
import kst4contest.model.ChatCategory
import kst4contest.model.ChatPreferences
/**
* Copies the station from one profile's preferences to another's.
*
* "The station" is what hangs on the site and the equipment: locator, bands, chat
* categories, antenna and path-analysis values, log program, frequency source, DX cluster
* server, rotators, AirScout. It is deliberately more than the setup wizard asks about -- a
* further operator at the same station should inherit the second rotator and the Win-Test
* station filter too, without ever seeing a question for them.
*
* It is deliberately not the operator: login, names, language, appearance, layout,
* shortcuts, snippets, beacons, automatic answers, sounds, filters. Nor the server address
* or the spotter callsign.
*
* Which setter belongs where is decided line by line in
* `src/test/resources/wizard-station-setters.txt` and `wizard-other-setters.txt`; a test
* holds this function and those lists together, and fails when ChatPreferences gains a
* setter nobody classified.
*
* Nothing is written to a file here, and [from] is only read.
*/
internal fun copyStation(from: ChatPreferences, to: ChatPreferences) {
// Location, bands and chats. The categories are copied by number: the two profiles
// must not share one mutable ChatCategory.
to.setStn_loginLocatorMainCat(from.getStn_loginLocatorMainCat())
to.setLoginChatCategoryMain(from.getLoginChatCategoryMain()?.let { ChatCategory(it.categoryNumber) })
to.setLoginChatCategorySecond(from.getLoginChatCategorySecond()?.let { ChatCategory(it.categoryNumber) })
to.setLoginToSecondChatEnabled(from.isLoginToSecondChatEnabled())
// Bands.
to.setStn_bandActive50(from.isStn_bandActive50())
to.setStn_bandActive70(from.isStn_bandActive70())
to.setStn_bandActive144(from.isStn_bandActive144())
to.setStn_bandActive432(from.isStn_bandActive432())
to.setStn_bandActive1240(from.isStn_bandActive1240())
to.setStn_bandActive2300(from.isStn_bandActive2300())
to.setStn_bandActive3400(from.isStn_bandActive3400())
to.setStn_bandActive5600(from.isStn_bandActive5600())
to.setStn_bandActive10G(from.isStn_bandActive10G())
// Antenna, defaults and everything the path analysis needs to know about the site.
to.setStn_antennaBeamWidthDeg(from.getStn_antennaBeamWidthDeg())
to.setStn_qtfDefault(from.getStn_qtfDefault())
to.setStn_maxQRBDefault(from.getStn_maxQRBDefault())
to.setStn_useQtfFilterDirectionAsAntennaHeading(from.isStn_useQtfFilterDirectionAsAntennaHeading())
to.setStn_pathAnalysisOwnAntennaGainDbi(from.getStn_pathAnalysisOwnAntennaGainDbi())
to.setStn_pathAnalysisOwnAntennaHeightMeters(from.getStn_pathAnalysisOwnAntennaHeightMeters())
to.setStn_pathAnalysisOwnTxPowerWatts(from.getStn_pathAnalysisOwnTxPowerWatts())
to.setStn_pathAnalysisOwnHeightAslMeters(from.getStn_pathAnalysisOwnHeightAslMeters())
to.setStn_pathAnalysisDefaultTargetAntennaGainDbi(from.getStn_pathAnalysisDefaultTargetAntennaGainDbi())
to.setStn_pathAnalysisDefaultTargetAntennaHeightMeters(from.getStn_pathAnalysisDefaultTargetAntennaHeightMeters())
to.setStn_pathAnalysisDefaultTargetTxPowerWatts(from.getStn_pathAnalysisDefaultTargetTxPowerWatts())
to.setStn_pathAnalysisDxHighestPointInSquare(from.isStn_pathAnalysisDxHighestPointInSquare())
to.setStn_pathAnalysisDemRootDirectory(from.getStn_pathAnalysisDemRootDirectory())
to.setStn_pathAnalysisDemDatasetId(from.getStn_pathAnalysisDemDatasetId())
to.setStn_pathAnalysisVhfFeederLossPerStationDb(from.getStn_pathAnalysisVhfFeederLossPerStationDb())
to.setStn_pathAnalysisFeederLossIncreaseDbPer200MHz(from.getStn_pathAnalysisFeederLossIncreaseDbPer200MHz())
to.setStn_pathAnalysisMaxEstimatedFeederLossPerStationDb(from.getStn_pathAnalysisMaxEstimatedFeederLossPerStationDb())
to.setStn_pathAnalysisRequiredSsbSignalDbm(from.getStn_pathAnalysisRequiredSsbSignalDbm())
to.setStn_pathAnalysisRequiredCwSignalDbm(from.getStn_pathAnalysisRequiredCwSignalDbm())
to.setStn_pathAnalysisContestMarginDb(from.getStn_pathAnalysisContestMarginDb())
// Log sources. All of them as they are: a station may run several at once.
to.setLogsynch_fileBasedWkdCallInterpreterEnabled(from.isLogsynch_fileBasedWkdCallInterpreterEnabled())
to.setLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly(from.getLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly())
to.setLogsynch_ucxUDPWkdCallListenerEnabled(from.isLogsynch_ucxUDPWkdCallListenerEnabled())
to.setLogsynch_ucxUDPWkdCallListenerPort(from.getLogsynch_ucxUDPWkdCallListenerPort())
to.setLogsynch_wintestNetworkListenerEnabled(from.isLogsynch_wintestNetworkListenerEnabled())
to.setLogsynch_wintestNetworkPort(from.getLogsynch_wintestNetworkPort())
to.setLogsynch_wintestNetworkBroadcastAddress(from.getLogsynch_wintestNetworkBroadcastAddress())
to.setLogsynch_wintestNetworkStationNameOfKST(from.getLogsynch_wintestNetworkStationNameOfKST())
to.setLogsynch_wintestNetworkStationIDOfKST(from.getLogsynch_wintestNetworkStationIDOfKST())
to.setLogsynch_wintestNetworkStationNameOfWintestClient1(from.getLogsynch_wintestNetworkStationNameOfWintestClient1())
to.setLogsynch_wintestNetworkStationNameOfWintestClient2(from.getLogsynch_wintestNetworkStationNameOfWintestClient2())
to.setLogsynch_wintestNetworkSkedPushEnabled(from.isLogsynch_wintestNetworkSkedPushEnabled())
to.setLogsynch_wintestNetworkSimulationEnabled(from.isLogsynch_wintestNetworkSimulationEnabled())
to.setLogsynch_wintestSkedMode(from.getLogsynch_wintestSkedMode())
// Frequency sources, SO2R and the DX cluster server for the log program.
to.setLogsynch_wintestQrgSyncEnabled(from.isLogsynch_wintestQrgSyncEnabled())
to.setLogsynch_wintestUsePassQrg(from.isLogsynch_wintestUsePassQrg())
to.setTrxSynch_ucxLogUDPListenerEnabled(from.isTrxSynch_ucxLogUDPListenerEnabled())
to.setTrxSynch_so2rEnabled(from.isTrxSynch_so2rEnabled())
to.setNotify_dxClusterServerEnabled(from.isNotify_dxClusterServerEnabled())
to.setNotify_dxclusterServerPort(from.getNotify_dxclusterServerPort())
// Rotators.
to.setStn_pstRotatorEnabled(from.isStn_pstRotatorEnabled())
to.setStn_pstRotatorHost(from.getStn_pstRotatorHost())
to.setStn_pstRotatorPort(from.getStn_pstRotatorPort())
to.setStn_pstRotator2Enabled(from.isStn_pstRotator2Enabled())
to.setStn_pstRotator2Host(from.getStn_pstRotator2Host())
to.setStn_pstRotator2Port(from.getStn_pstRotator2Port())
// AirScout.
to.setAirScout_asUDPListenerEnabled(from.isAirScout_asUDPListenerEnabled())
to.setAirScout_asCommunicationPort(from.getAirScout_asCommunicationPort())
to.setAirScout_asServerNameString(from.getAirScout_asServerNameString())
to.setAirScout_asClientNameString(from.getAirScout_asClientNameString())
to.setAirScout_autoBandSelectionEnabled(from.isAirScout_autoBandSelectionEnabled())
to.setAirScout_asBandString(from.getAirScout_asBandString())
}
@@ -0,0 +1,171 @@
package kst4contest.view.compose.wizard
import kst4contest.model.ChatCategory
import kst4contest.model.ChatPreferences
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import java.io.File
import java.lang.reflect.Modifier
import java.nio.file.Path
/**
* What "the station" is when one profile takes it from another.
*
* The two lists under src/test/resources are the decision, one line per ChatPreferences
* setter. A setter in neither list fails the first test, so a new setting cannot be forgotten
* here: somebody has to say whether another operator at the same station should inherit it.
*/
class WizardStationCopyTest {
private fun lines(name: String): Set<String> =
File("src/test/resources/$name").readLines().map { it.trim() }.filter { it.isNotEmpty() }.toSet()
private val stationSetters = lines("wizard-station-setters.txt")
private val otherSetters = lines("wizard-other-setters.txt")
/** Every public setter with one parameter, the shape every preference has. */
private fun allSetters(): Set<String> =
ChatPreferences::class.java.methods
.filter { it.name.startsWith("set") && it.parameterCount == 1 && Modifier.isPublic(it.modifiers) }
.map { it.name }
.toSet()
private fun prefs(configure: ChatPreferences.() -> Unit = {}): ChatPreferences =
ChatPreferences(Path.of("wizard-station-copy-test-unused.xml")).apply(configure)
@Test
fun everySetterIsClassified() {
val all = allSetters()
assertEquals(
emptySet<String>(),
all - stationSetters - otherSetters,
"new ChatPreferences setters: add each to wizard-station-setters.txt (and to copyStation) " +
"or to wizard-other-setters.txt",
)
assertEquals(emptySet<String>(), (stationSetters + otherSetters) - all, "listed setters that no longer exist")
assertEquals(emptySet<String>(), stationSetters.intersect(otherSetters), "a setter cannot be in both lists")
}
@Test
fun copyStationCallsExactlyTheStationSetters() {
val target = Mockito.mock(ChatPreferences::class.java)
copyStation(prefs(), target)
val called = Mockito.mockingDetails(target).invocations
.map { it.method.name }
.filter { it.startsWith("set") }
assertEquals(stationSetters, called.toSet(), "copyStation and wizard-station-setters.txt disagree")
assertEquals(called.size, called.toSet().size, "a setter was called twice")
assertTrue(
Mockito.mockingDetails(target).invocations.none { it.method.name == "writePreferencesToXmlFile" },
"copying must not write a file",
)
}
@Test
fun theStationArrivesIncludingWhatTheWizardNeverAsks() {
val donor = prefs {
setStn_loginLocatorMainCat("JO50AA")
setStn_bandActive144(true)
setStn_bandActive1240(true)
setStn_bandActive432(false)
setLoginChatCategoryMain(ChatCategory(2))
setLoginToSecondChatEnabled(true)
setLoginChatCategorySecond(ChatCategory(3))
setStn_qtfDefault(270.0)
setStn_maxQRBDefault(800.0)
setStn_pathAnalysisDemRootDirectory("/srv/dem")
setStn_pathAnalysisContestMarginDb(9.0)
setTrxSynch_so2rEnabled(true)
setStn_pstRotator2Enabled(true)
setStn_pstRotator2Port(12020)
// Several log sources at once: the wizard's own question could not express this.
setLogsynch_wintestNetworkListenerEnabled(true)
setLogsynch_fileBasedWkdCallInterpreterEnabled(true)
setLogsynch_wintestNetworkStationNameOfWintestClient1("RUN")
setLogsynch_wintestUsePassQrg(true)
setAirScout_asBandString("4320000")
}
val target = prefs {
setStn_bandActive432(true)
setLoginChatCategoryMain(ChatCategory(3))
}
copyStation(donor, target)
assertEquals("JO50AA", target.getStn_loginLocatorMainCat())
assertTrue(target.isStn_bandActive144())
assertTrue(target.isStn_bandActive1240())
assertFalse(target.isStn_bandActive432(), "a band the donor does not have goes off")
assertEquals(2, target.getLoginChatCategoryMain().categoryNumber)
assertTrue(target.isLoginToSecondChatEnabled())
assertEquals(3, target.getLoginChatCategorySecond().categoryNumber)
assertEquals(270.0, target.getStn_qtfDefault())
assertEquals(800.0, target.getStn_maxQRBDefault())
assertEquals("/srv/dem", target.getStn_pathAnalysisDemRootDirectory())
assertEquals(9.0, target.getStn_pathAnalysisContestMarginDb())
assertTrue(target.isTrxSynch_so2rEnabled())
assertTrue(target.isStn_pstRotator2Enabled())
assertEquals(12020, target.getStn_pstRotator2Port())
assertTrue(target.isLogsynch_wintestNetworkListenerEnabled())
assertTrue(target.isLogsynch_fileBasedWkdCallInterpreterEnabled())
assertEquals("RUN", target.getLogsynch_wintestNetworkStationNameOfWintestClient1())
assertTrue(target.isLogsynch_wintestUsePassQrg())
assertEquals("4320000", target.getAirScout_asBandString())
}
@Test
fun whatBelongsToTheOperatorStays() {
val donor = prefs {
setStn_loginCallSign("DL0TEST")
setStn_loginPassword("donor-secret")
setStn_loginNameMainCat("Donor")
setStn_loginNameSecondCat("Donor SHF")
setGuiOptions_language("en")
setGUI_darkModeActiveByDefault(true)
setStn_on4kstServersDns("donor.example")
setNotify_DXCSrv_SpottersCallSign("DL0TEST")
setBcn_beaconTextMainCat("donor beacon")
}
val target = prefs {
setStn_loginCallSign("DM5XX")
setStn_loginPassword("own-secret")
setStn_loginNameMainCat("Own")
setStn_loginNameSecondCat("Own SHF")
setGuiOptions_language("de")
setGUI_darkModeActiveByDefault(false)
setStn_on4kstServersDns("own.example")
setNotify_DXCSrv_SpottersCallSign("DM5XX")
setBcn_beaconTextMainCat("own beacon")
}
copyStation(donor, target)
assertEquals("DM5XX", target.getStn_loginCallSign())
assertEquals("own-secret", target.getStn_loginPassword())
assertEquals("Own", target.getStn_loginNameMainCat())
assertEquals("Own SHF", target.getStn_loginNameSecondCat())
assertEquals("de", target.getGuiOptions_language())
assertFalse(target.isGUI_darkModeActiveByDefault())
assertEquals("own.example", target.getStn_on4kstServersDns())
assertEquals("DM5XX", target.getNotify_DXCSrv_SpottersCallSign().get())
assertEquals("own beacon", target.getBcn_beaconTextMainCat())
}
@Test
fun theDonorIsNotChangedAndSharesNoObjectWithTheTarget() {
val donor = prefs { setLoginChatCategoryMain(ChatCategory(2)) }
val target = prefs()
copyStation(donor, target)
target.getLoginChatCategoryMain().categoryNumber = 7
assertEquals(2, donor.getLoginChatCategoryMain().categoryNumber, "the two profiles must not share a category object")
}
}
@@ -0,0 +1,73 @@
setActualQTF
setBcn_beaconIntervalInMinutesMainCat
setBcn_beaconIntervalInMinutesSecondCat
setBcn_beaconTextMainCat
setBcn_beaconTextSecondCat
setBcn_beaconsEnabledMainCat
setBcn_beaconsEnabledSecondCat
setBcn_contestScoreSum
setChatState
setGUI_darkModeActive
setGUI_darkModeActiveByDefault
setGUIclusterAndQSOMonStage_SceneSizeHW
setGUImainWindowLeftSplitPane_dividerposition
setGUImainWindowRightSplitPane_dividerposition
setGUImessageSectionSplitpane_dividerposition
setGUIpnl_directedMSGWin_dividerpositionDefault
setGUIscn_ChatwindowMainSceneSizeHW
setGUIselectedCallSignSplitPane_dividerposition
setGUIsettingsStageSceneSizeHW
setGUIstage_updateStage_SceneSizeHW
setGUIstationMapAlwaysOnTop
setGUIstationMapClusteringEnabled
setGUIstationMapPathAnalysisVisible
setGUIstationMapStagePositionXY
setGUIstationMapStageSceneSizeHW
setGuiOptions_defaultFilterNothing
setGuiOptions_defaultFilterPmToMe
setGuiOptions_defaultFilterPmToOther
setGuiOptions_defaultFilterPublicMsgs
setGuiOptions_language
setGuiOptions_paletteOverridesDay
setGuiOptions_paletteOverridesEvening
setGuiOptions_rememberWindowPositions
setGuiOptions_showFreshCallHintInBandColumns
setGuiOptions_showGrossFieldWorkedHintInBandColumns
setLogSynch_storeWorkedCallSignsFileNameUDPMessageBackup
setLogsynch_storeWorkedCallSignsFileNameUDPMessageBackup
setLstNotify_QSOSniffer_sniffedPrefixLocList
setLst_txtShortCutBtnList
setLst_txtSnipList
setMYQRGFirstCat
setMYQRGSecondCat
setMessageHandling_autoAnswerEnabled
setMessageHandling_autoAnswerEnabledSecondCat
setMessageHandling_autoAnswerTextMainCat
setMessageHandling_autoAnswerTextSecondCat
setMessageHandling_autoAnswerToQRGRequestEnabled
setMessageHandling_beaconUnworkedstationsPrefix
setMessageHandling_debugModeToFileEnabled
setMessageHandling_unworkedStnRequesterBeaconsEnabled
setMessageHandling_unworkedStnRequesterBeaconsInterval
setMessageHandling_unworkedStnRequesterBeaconsText
setNotify_DXCSrv_SpottersCallSign
setNotify_DXClusterServerTriggerBearing
setNotify_DXClusterServerTriggerOnQRGDetect
setNotify_bandUpgradeHintOnLogEnabled
setNotify_bandUpgradePriorityBoostEnabled
setNotify_momentumWindowSeconds
setNotify_noReplyPenaltyMinutes
setNotify_optionalFrequencyPrefix
setNotify_playCWCallsignsOnRxedPMs
setNotify_playSimpleSounds
setNotify_playVoiceCallsignsOnRxedPMs
setNotify_positiveSignalsPatterns
setProgramVersion
setStn_loginAFKState
setStn_loginCallSign
setStn_loginNameMainCat
setStn_loginNameSecondCat
setStn_loginPassword
setStn_on4kstServersDns
setStn_on4kstServersPort
setStoreAndRestorePreferencesFileName
@@ -0,0 +1,65 @@
setAirScout_asBandString
setAirScout_asClientNameString
setAirScout_asCommunicationPort
setAirScout_asServerNameString
setAirScout_asUDPListenerEnabled
setAirScout_autoBandSelectionEnabled
setLoginChatCategoryMain
setLoginChatCategorySecond
setLoginToSecondChatEnabled
setLogsynch_fileBasedWkdCallInterpreterEnabled
setLogsynch_fileBasedWkdCallInterpreterFileNameReadOnly
setLogsynch_ucxUDPWkdCallListenerEnabled
setLogsynch_ucxUDPWkdCallListenerPort
setLogsynch_wintestNetworkBroadcastAddress
setLogsynch_wintestNetworkListenerEnabled
setLogsynch_wintestNetworkPort
setLogsynch_wintestNetworkSimulationEnabled
setLogsynch_wintestNetworkSkedPushEnabled
setLogsynch_wintestNetworkStationIDOfKST
setLogsynch_wintestNetworkStationNameOfKST
setLogsynch_wintestNetworkStationNameOfWintestClient1
setLogsynch_wintestNetworkStationNameOfWintestClient2
setLogsynch_wintestQrgSyncEnabled
setLogsynch_wintestSkedMode
setLogsynch_wintestUsePassQrg
setNotify_dxClusterServerEnabled
setNotify_dxclusterServerPort
setStn_antennaBeamWidthDeg
setStn_bandActive10G
setStn_bandActive1240
setStn_bandActive144
setStn_bandActive2300
setStn_bandActive3400
setStn_bandActive432
setStn_bandActive50
setStn_bandActive5600
setStn_bandActive70
setStn_loginLocatorMainCat
setStn_maxQRBDefault
setStn_pathAnalysisContestMarginDb
setStn_pathAnalysisDefaultTargetAntennaGainDbi
setStn_pathAnalysisDefaultTargetAntennaHeightMeters
setStn_pathAnalysisDefaultTargetTxPowerWatts
setStn_pathAnalysisDemDatasetId
setStn_pathAnalysisDemRootDirectory
setStn_pathAnalysisDxHighestPointInSquare
setStn_pathAnalysisFeederLossIncreaseDbPer200MHz
setStn_pathAnalysisMaxEstimatedFeederLossPerStationDb
setStn_pathAnalysisOwnAntennaGainDbi
setStn_pathAnalysisOwnAntennaHeightMeters
setStn_pathAnalysisOwnHeightAslMeters
setStn_pathAnalysisOwnTxPowerWatts
setStn_pathAnalysisRequiredCwSignalDbm
setStn_pathAnalysisRequiredSsbSignalDbm
setStn_pathAnalysisVhfFeederLossPerStationDb
setStn_pstRotator2Enabled
setStn_pstRotator2Host
setStn_pstRotator2Port
setStn_pstRotatorEnabled
setStn_pstRotatorHost
setStn_pstRotatorPort
setStn_qtfDefault
setStn_useQtfFilterDirectionAsAntennaHeading
setTrxSynch_so2rEnabled
setTrxSynch_ucxLogUDPListenerEnabled