Mirrors the TeamSpeak 3 client's Contacts: clients can be filed as friend,
blocked or neutral from their context menu or by dragging them into the
Contacts window, given a custom and phonetic nickname, shown under either
name or both, and per contact muted automatically, ignored in server/channel
or private chat and pokes, have their away message hidden and whispers
allowed or denied. Friends are green and blocked clients red in the tree
(optional), new contacts start from per-type defaults ("Set Defaults"), and
the global whisper policy lives in Options -> Contacts. "Change Volume..."
adds a per-client dB gain that a contact entry remembers.
Contacts are stored in ~/.ts3jclient/contacts.txt using the exact record
format the official client keeps in the Contacts table of its settings.db
(field names and codes recovered from the binary), so entries move between
the two verbatim. A small read-only pure-Java SQLite reader imports the
official client's list on first run and on demand, without a driver.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
90 lines
3.7 KiB
Java
90 lines
3.7 KiB
Java
package com.ts3client.ui;
|
|
|
|
import com.ts3client.config.Settings;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.DefaultListCellRenderer;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JCheckBox;
|
|
import javax.swing.JComboBox;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JList;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.SwingUtilities;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Component;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.Insets;
|
|
|
|
/**
|
|
* Options page for the contact list: whether friends and blocked clients are
|
|
* coloured in the server tree, whose whispers get through (TeamSpeak's whisper
|
|
* options), and the defaults a new contact starts with.
|
|
*/
|
|
final class ContactsPanel extends JPanel {
|
|
|
|
private final Settings settings;
|
|
private final JCheckBox colorContacts = new JCheckBox("Colour friends and blocked clients in the server tree");
|
|
private final JComboBox<Settings.WhisperPolicy> whisperPolicy = new JComboBox<>(Settings.WhisperPolicy.values());
|
|
|
|
ContactsPanel(Settings settings) {
|
|
super(new BorderLayout());
|
|
this.settings = settings;
|
|
setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
|
|
|
|
JPanel p = new JPanel(new GridBagLayout());
|
|
GridBagConstraints c = new GridBagConstraints();
|
|
c.insets = new Insets(2, 2, 2, 2);
|
|
c.anchor = GridBagConstraints.WEST;
|
|
c.fill = GridBagConstraints.HORIZONTAL;
|
|
c.gridx = 0;
|
|
c.gridwidth = 2;
|
|
|
|
c.gridy = 0;
|
|
colorContacts.setSelected(settings.colorContacts);
|
|
colorContacts.setToolTipText("Friends in green and blocked clients in red, as the TeamSpeak client shows them");
|
|
p.add(colorContacts, c);
|
|
|
|
c.gridy = 1;
|
|
c.insets = new Insets(12, 2, 2, 2);
|
|
p.add(new JLabel("Whispers: who is allowed to whisper to you"), c);
|
|
c.gridy = 2;
|
|
c.insets = new Insets(2, 2, 2, 2);
|
|
whisperPolicy.setSelectedItem(settings.whisperPolicy);
|
|
whisperPolicy.setRenderer(new DefaultListCellRenderer() {
|
|
@Override
|
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
|
boolean selected, boolean focus) {
|
|
super.getListCellRendererComponent(list, value, index, selected, focus);
|
|
if (value instanceof Settings.WhisperPolicy) setText(((Settings.WhisperPolicy) value).label());
|
|
return this;
|
|
}
|
|
});
|
|
whisperPolicy.setToolTipText("<html>Use individual settings in contacts, else allow: a client not on your "
|
|
+ "contact list may whisper to you.<br>Use individual settings in contacts, else deny: only "
|
|
+ "contacts marked \"Allow whisper\" may.<br>Nobody: individual contact settings are ignored.</html>");
|
|
p.add(whisperPolicy, c);
|
|
|
|
c.gridy = 3;
|
|
c.insets = new Insets(12, 2, 2, 2);
|
|
c.fill = GridBagConstraints.NONE;
|
|
JButton defaults = new JButton("Contact defaults…");
|
|
defaults.setToolTipText("Configure default settings when adding a client to the Contact Manager");
|
|
defaults.addActionListener(e -> {
|
|
java.awt.Window owner = SwingUtilities.getWindowAncestor(this);
|
|
new ContactDefaultsDialog(owner instanceof JDialog ? (JDialog) owner : null, settings).setVisible(true);
|
|
});
|
|
p.add(defaults, c);
|
|
|
|
add(p, BorderLayout.NORTH);
|
|
}
|
|
|
|
/** Copies the page into the settings; the caller saves them. */
|
|
void apply() {
|
|
settings.colorContacts = colorContacts.isSelected();
|
|
settings.whisperPolicy = (Settings.WhisperPolicy) whisperPolicy.getSelectedItem();
|
|
}
|
|
}
|