Android: create, edit and delete channels
A one-page channel editor with what the desktop dialog has but the permissions and the icon: name, password, topic, description, type, sorting, talk power, codec preset or codec and quality, and the limits. Create channel is on the server sheet; create sub-channel, edit and delete on the channel sheet, each only with the permission for it. The codec list, presets and bandwidth move to core for both editors. Core gains channel delete, and the desktop channel menu a Delete Channel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,12 +28,9 @@ import java.awt.Insets;
|
||||
*/
|
||||
final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
/** TeamSpeak's ceiling for {@code channel_delete_delay}, in seconds. */
|
||||
private static final int MAX_DELETE_DELAY = 604800;
|
||||
|
||||
private final JTextField phoneticName = new JTextField();
|
||||
private final JSpinner deleteDelay =
|
||||
Spinners.compact(new JSpinner(new SpinnerNumberModel(0, 0, MAX_DELETE_DELAY, 1)));
|
||||
Spinners.compact(new JSpinner(new SpinnerNumberModel(0, 0, ChannelSettings.MAX_DELETE_DELAY, 1)));
|
||||
private final JButton deleteDelayMax = new JButton("max");
|
||||
private final JCheckBox encrypted = new JCheckBox("Voice Data encrypted");
|
||||
|
||||
@@ -55,7 +52,7 @@ final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
deleteDelay.setToolTipText("<html><p>Delay in seconds after temporary channels are deleted"
|
||||
+ " after the last user left the channel.</p></html>");
|
||||
deleteDelayMax.setToolTipText("Set delete delay to maximum value");
|
||||
deleteDelayMax.addActionListener(a -> deleteDelay.setValue(MAX_DELETE_DELAY));
|
||||
deleteDelayMax.addActionListener(a -> deleteDelay.setValue(ChannelSettings.MAX_DELETE_DELAY));
|
||||
encrypted.setToolTipText("Voice data in this channel will be encrypted.");
|
||||
|
||||
ButtonGroup users = new ButtonGroup();
|
||||
@@ -105,7 +102,7 @@ final class ChannelAdvancedPanel extends JPanel implements ChannelDialog.Tab {
|
||||
@Override
|
||||
public void read(ChannelSettings settings) {
|
||||
phoneticName.setText(settings.phoneticName);
|
||||
deleteDelay.setValue(Math.min(MAX_DELETE_DELAY, Math.max(0, settings.deleteDelay)));
|
||||
deleteDelay.setValue(Math.min(ChannelSettings.MAX_DELETE_DELAY, Math.max(0, settings.deleteDelay)));
|
||||
encrypted.setSelected(settings.encrypted);
|
||||
|
||||
if (settings.maxClientsUnlimited) maxUsersUnlimited.setSelected(true);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ts3client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
import com.ts3client.net.ChannelCodec;
|
||||
import com.ts3client.net.ChannelSettings;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -24,27 +25,11 @@ import java.awt.Insets;
|
||||
*/
|
||||
final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
/** Codec names in TeamSpeak's own id order, which is what the combo box index is. */
|
||||
private static final String[] CODEC_NAMES = {
|
||||
"Speex Narrowband", "Speex Wideband", "Speex Ultra-Wideband",
|
||||
"CELT Mono", "Opus Voice", "Opus Music"};
|
||||
|
||||
/**
|
||||
* Bandwidth per talking client in KiB/s at quality 0 and 10, per codec, as published by
|
||||
* TeamSpeak. The steps in between are interpolated: the client shows a figure per
|
||||
* quality step, and only the two ends of each codec's range are documented.
|
||||
*/
|
||||
private static final double[][] BANDWIDTH_RANGE = {
|
||||
{2.49, 5.22}, {2.69, 7.37}, {2.73, 7.57}, {6.10, 13.92}, {2.73, 7.71}, {3.08, 11.87}};
|
||||
|
||||
private static final int CODEC_OPUS_VOICE = 4;
|
||||
private static final int CODEC_OPUS_MUSIC = 5;
|
||||
|
||||
private final JRadioButton voiceMobile = new JRadioButton("Voice Mobile");
|
||||
private final JRadioButton voiceDesktop = new JRadioButton("Voice Desktop");
|
||||
private final JRadioButton music = new JRadioButton("Music");
|
||||
private final JRadioButton custom = new JRadioButton("Custom");
|
||||
private final JComboBox<String> codec = new JComboBox<>(CODEC_NAMES);
|
||||
private final JComboBox<String> codec = new JComboBox<>(ChannelCodec.NAMES);
|
||||
private final JSlider quality = new JSlider(0, 10, 6);
|
||||
private final JLabel qualityValue = new JLabel("6");
|
||||
private final JLabel bandwidth = new JLabel();
|
||||
@@ -59,9 +44,9 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
presets.add(voiceDesktop);
|
||||
presets.add(music);
|
||||
presets.add(custom);
|
||||
voiceMobile.addActionListener(a -> applyPreset(CODEC_OPUS_VOICE, 4));
|
||||
voiceDesktop.addActionListener(a -> applyPreset(CODEC_OPUS_VOICE, 6));
|
||||
music.addActionListener(a -> applyPreset(CODEC_OPUS_MUSIC, 6));
|
||||
voiceMobile.addActionListener(a -> applyPreset(ChannelCodec.Preset.VOICE_MOBILE));
|
||||
voiceDesktop.addActionListener(a -> applyPreset(ChannelCodec.Preset.VOICE_DESKTOP));
|
||||
music.addActionListener(a -> applyPreset(ChannelCodec.Preset.MUSIC));
|
||||
custom.addActionListener(a -> setCustomEnabled(true));
|
||||
|
||||
codec.addActionListener(a -> updateBandwidth());
|
||||
@@ -77,12 +62,15 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
@Override
|
||||
public void read(ChannelSettings settings) {
|
||||
codec.setSelectedIndex(Math.max(0, Math.min(CODEC_NAMES.length - 1, settings.codec)));
|
||||
quality.setValue(Math.max(0, Math.min(10, settings.codecQuality)));
|
||||
if (settings.codec == CODEC_OPUS_VOICE && settings.codecQuality == 4) voiceMobile.setSelected(true);
|
||||
else if (settings.codec == CODEC_OPUS_VOICE && settings.codecQuality == 6) voiceDesktop.setSelected(true);
|
||||
else if (settings.codec == CODEC_OPUS_MUSIC && settings.codecQuality == 6) music.setSelected(true);
|
||||
else custom.setSelected(true);
|
||||
codec.setSelectedIndex(ChannelCodec.clampCodec(settings.codec));
|
||||
quality.setValue(Math.max(0, Math.min(ChannelCodec.MAX_QUALITY, settings.codecQuality)));
|
||||
ChannelCodec.Preset preset = ChannelCodec.Preset.of(settings.codec, settings.codecQuality);
|
||||
if (preset == null) custom.setSelected(true);
|
||||
else switch (preset) {
|
||||
case VOICE_MOBILE -> voiceMobile.setSelected(true);
|
||||
case VOICE_DESKTOP -> voiceDesktop.setSelected(true);
|
||||
case MUSIC -> music.setSelected(true);
|
||||
}
|
||||
setCustomEnabled(custom.isSelected());
|
||||
updateBandwidth();
|
||||
}
|
||||
@@ -93,9 +81,9 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
settings.codecQuality = quality.getValue();
|
||||
}
|
||||
|
||||
private void applyPreset(int codecId, int qualityValue) {
|
||||
codec.setSelectedIndex(codecId);
|
||||
quality.setValue(qualityValue);
|
||||
private void applyPreset(ChannelCodec.Preset preset) {
|
||||
codec.setSelectedIndex(preset.codec);
|
||||
quality.setValue(preset.quality);
|
||||
setCustomEnabled(false);
|
||||
updateBandwidth();
|
||||
}
|
||||
@@ -107,10 +95,7 @@ final class ChannelAudioPanel extends JPanel implements ChannelDialog.Tab {
|
||||
|
||||
private void updateBandwidth() {
|
||||
qualityValue.setText(Integer.toString(quality.getValue()));
|
||||
int index = Math.max(0, Math.min(BANDWIDTH_RANGE.length - 1, codec.getSelectedIndex()));
|
||||
double[] range = BANDWIDTH_RANGE[index];
|
||||
double value = range[0] + (range[1] - range[0]) * quality.getValue() / 10.0;
|
||||
bandwidth.setText(String.format("%.2f KiB/s", value));
|
||||
bandwidth.setText(ChannelCodec.bandwidthText(codec.getSelectedIndex(), quality.getValue()));
|
||||
}
|
||||
|
||||
private JPanel presetBox() {
|
||||
|
||||
@@ -32,6 +32,9 @@ final class ChannelMenu {
|
||||
JMenuItem edit = new JMenuItem("Edit Channel", Icons.of("CHANNEL_EDIT"));
|
||||
edit.addActionListener(a -> actions.editChannel(channel));
|
||||
menu.add(edit);
|
||||
JMenuItem delete = new JMenuItem("Delete Channel", Icons.of("CHANNEL_DELETE"));
|
||||
delete.addActionListener(a -> actions.deleteChannel(channel));
|
||||
menu.add(delete);
|
||||
menu.addSeparator();
|
||||
addSubscriptionItems(menu, channel, actions);
|
||||
JMenuItem files = new JMenuItem("Browse files", Icons.of("FILETRANSFER"));
|
||||
|
||||
@@ -297,6 +297,23 @@ final class ServerTabTreeActions implements ServerTreePanel.Actions {
|
||||
ChannelDialog.toEdit(host, conn, groupIcons, channel).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChannel(ChannelNode channel) {
|
||||
if (!conn.isConnected()) return;
|
||||
// Like TeamSpeak, a channel that is not empty takes its sub-channels along and sends its clients away.
|
||||
boolean occupied = !channel.children.isEmpty() || !channel.clients.isEmpty();
|
||||
String question = "Delete channel \"" + channel.name + "\""
|
||||
+ (occupied ? " with its sub-channels and the clients in it?" : "?");
|
||||
if (JOptionPane.showConfirmDialog(host, question, "Delete Channel", JOptionPane.OK_CANCEL_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||
return;
|
||||
}
|
||||
conn.deleteChannel(channel.id, true, error -> {
|
||||
if (error != null) SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(host,
|
||||
"Could not delete the channel: " + error, "Error", JOptionPane.ERROR_MESSAGE));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createChannel(ChannelNode parent, ChannelSettings.Type type) {
|
||||
if (!conn.isConnected()) return;
|
||||
|
||||
@@ -65,6 +65,8 @@ public final class ServerTreePanel extends JPanel {
|
||||
/** Opens the channel editor for a channel. */
|
||||
void editChannel(ChannelNode channel);
|
||||
|
||||
void deleteChannel(ChannelNode channel);
|
||||
|
||||
/**
|
||||
* Opens the channel creator.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user