diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index 63704046..71d1f7c6 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -34,6 +34,7 @@ class MuWireSettings { boolean startChatServer int maxChatConnections boolean advertiseChat + File chatWelcomeFile Set watchedDirectories float downloadSequentialRatio int hostClearInterval, hostHopelessInterval, hostRejectInterval @@ -85,6 +86,9 @@ class MuWireSettings { startChatServer = Boolean.valueOf(props.getProperty("startChatServer","false")) maxChatConnections = Integer.valueOf(props.get("maxChatConnections", "-1")) advertiseChat = Boolean.valueOf(props.getProperty("advertiseChat","true")) + String chatWelcomeProp = props.getProperty("chatWelcomeFile") + if (chatWelcomeProp != null) + chatWelcomeFile = new File(chatWelcomeProp) watchedDirectories = DataUtil.readEncodedSet(props, "watchedDirectories") watchedKeywords = DataUtil.readEncodedSet(props, "watchedKeywords") @@ -136,6 +140,8 @@ class MuWireSettings { props.setProperty("startChatServer", String.valueOf(startChatServer)) props.setProperty("maxChatConnectios", String.valueOf(maxChatConnections)) props.setProperty("advertiseChat", String.valueOf(advertiseChat)) + if (chatWelcomeFile != null) + props.setProperty("chatWelcomeFile", chatWelcomeFile.getAbsolutePath()) DataUtil.writeEncodedSet(watchedDirectories, "watchedDirectories", props) DataUtil.writeEncodedSet(watchedKeywords, "watchedKeywords", props) diff --git a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy index f1f3e54e..47997cc6 100644 --- a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy +++ b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy @@ -25,6 +25,8 @@ import net.i2p.util.ConcurrentHashSet @Log class ChatServer { public static final String CONSOLE = "__CONSOLE__" + private static final String DEFAULT_WELCOME = "Welcome to my chat server! Type /HELP for list of available commands" + private final EventBus eventBus private final MuWireSettings settings private final TrustService trustService @@ -55,7 +57,14 @@ class ChatServer { connections.put(me.destination, LocalChatLink.INSTANCE) joinRoom(me, CONSOLE) shortNames.put(me.getHumanReadableName(), me) - echo("/SAY Welcome to my chat server! Type /HELP for list of available commands.",me.destination) + echo(getWelcome(),me.destination) + } + + private String getWelcome() { + String welcome = DEFAULT_WELCOME + if (settings.chatWelcomeFile != null) + welcome = settings.chatWelcomeFile.text + "/SAY $welcome" } private void sendPings() { @@ -110,7 +119,7 @@ class ChatServer { joinRoom(client, CONSOLE) shortNames.put(client.getHumanReadableName(), client) connection.start() - echo("/SAY Welcome to my chat server! Type /HELP for help on available commands",connection.endpoint.destination) + echo(getWelcome(),connection.endpoint.destination) } void onChatDisconnectionEvent(ChatDisconnectionEvent e) { diff --git a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy index 09f35722..17b854a9 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/OptionsController.groovy @@ -155,6 +155,9 @@ class OptionsController { int maxChatLines = Integer.parseInt(view.maxChatLinesField.text) model.maxChatLines = maxChatLines uiSettings.maxChatLines = maxChatLines + + if (model.chatWelcomeFile != null) + settings.chatWelcomeFile = new File(model.chatWelcomeFile) core.saveMuSettings() @@ -237,6 +240,19 @@ class OptionsController { model.incompleteLocation = chooser.getSelectedFile().getAbsolutePath() } + @ControllerAction + void chooseChatFile() { + def chooser = new JFileChooser() + chooser.with { + setFileHidingEnabled(false) + setDialogTitle("Select location of chat server welcome file") + setFileSelectionMode(JFileChooser.FILES_ONLY) + int rv = chooser.showOpenDialog(null) + if (rv == JFileChooser.APPROVE_OPTION) + model.chatWelcomeFile = getSelectedFile().getAbsolutePath() + } + } + @ControllerAction void automaticFont() { model.automaticFontSize = true diff --git a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy index e98365d0..6e0c6eaf 100644 --- a/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy +++ b/gui/griffon-app/models/com/muwire/gui/OptionsModel.groovy @@ -61,6 +61,7 @@ class OptionsModel { @Observable int maxChatConnections @Observable boolean advertiseChat @Observable int maxChatLines + @Observable String chatWelcomeFile void mvcGroupInit(Map args) { MuWireSettings settings = application.context.get("muwire-settings") @@ -114,5 +115,6 @@ class OptionsModel { maxChatConnections = settings.maxChatConnections advertiseChat = settings.advertiseChat maxChatLines = uiSettings.maxChatLines + chatWelcomeFile = settings.chatWelcomeFile?.getAbsolutePath() } } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy index 808e7199..3ab4464a 100644 --- a/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/OptionsView.groovy @@ -280,13 +280,16 @@ class OptionsView { constraints : gbc(gridx : 0, gridy : 0, fill : GridBagConstraints.HORIZONTAL, weightx: 100)) { gridBagLayout() label(text : "Start chat server on startup", constraints : gbc(gridx: 0, gridy: 0, anchor: GridBagConstraints.LINE_START, weightx: 100)) - startChatServerCheckbox = checkBox(selected : bind{model.startChatServer}, constraints : gbc(gridx:1, gridy:0, anchor:GridBagConstraints.LINE_END)) + startChatServerCheckbox = checkBox(selected : bind{model.startChatServer}, constraints : gbc(gridx:2, gridy:0, anchor:GridBagConstraints.LINE_END)) label(text : "Maximum chat connections (-1 means unlimited)", constraints : gbc(gridx: 0, gridy:1, anchor:GridBagConstraints.LINE_START, weightx:100)) - maxChatConnectionsField = textField(text : bind {model.maxChatConnections}, constraints : gbc(gridx: 1, gridy : 1, anchor:GridBagConstraints.LINE_END)) + maxChatConnectionsField = textField(text : bind {model.maxChatConnections}, constraints : gbc(gridx: 2, gridy : 1, anchor:GridBagConstraints.LINE_END)) label(text : "Advertise chat ability in search results", constraints : gbc(gridx: 0, gridy:2, anchor:GridBagConstraints.LINE_START, weightx:100)) - advertiseChatCheckbox = checkBox(selected : bind{model.advertiseChat}, constraints : gbc(gridx:1, gridy:2, anchor:GridBagConstraints.LINE_END)) + advertiseChatCheckbox = checkBox(selected : bind{model.advertiseChat}, constraints : gbc(gridx:2, gridy:2, anchor:GridBagConstraints.LINE_END)) label(text : "Maximum lines of scrollback (-1 means unlimited)", constraints : gbc(gridx:0, gridy:3, anchor : GridBagConstraints.LINE_START, weightx: 100)) - maxChatLinesField = textField(text : bind{model.maxChatLines}, constraints : gbc(gridx:1, gridy: 3, anchor: GridBagConstraints.LINE_END)) + maxChatLinesField = textField(text : bind{model.maxChatLines}, constraints : gbc(gridx:2, gridy: 3, anchor: GridBagConstraints.LINE_END)) + label(text : "Welcome message file", constraints : gbc(gridx : 0, gridy : 4, anchor : GridBagConstraints.LINE_START, weightx: 100)) + label(text : bind {model.chatWelcomeFile}, constraints : gbc(gridx : 1, gridy : 4)) + button(text : "Choose", constraints : gbc(gridx : 2, gridy : 4, anchor : GridBagConstraints.LINE_END), chooseChatFileAction) } panel(constraints : gbc(gridx: 0, gridy : 1, weighty: 100)) }