Set and delete our avatar from the Self menu and the avatar's menu

As in TeamSpeak 3, Self offers "Set avatar…", which picks an image and
uploads it, and "Delete avatar" while we have one; the old avatar
dialog is gone. Setting (and stealing) is offered only while the server
grants i_client_max_avatar_filesize. Right-clicking our own avatar in
the info panel offers the same two beside saving it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 16:01:16 +00:00
co-authored by Claude Opus 5.5
parent e7d338ce28
commit b1890cbf79
8 changed files with 182 additions and 241 deletions
@@ -15,15 +15,10 @@ import com.ts3client.sound.SoundNotifier;
import com.ts3client.text.TsLink;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import java.awt.Component;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
/**
* One server connection and the views bound to it (tree, info and chat). The
@@ -46,6 +41,7 @@ final class ServerTab {
private final ServerTreePanel treePanel;
private final ChatPanel chatPanel;
private final InfoPanel infoPanel;
private final AvatarActions avatar;
private final JComponent component;
private JSplitPane leftColumn;
private int normalDividerSize;
@@ -107,7 +103,28 @@ final class ServerTab {
}
});
infoPanel.setAvatarStealer(this::stealAvatar);
this.avatar = new AvatarActions(host, conn);
infoPanel.setAvatarHandler(new InfoPanel.AvatarHandler() {
@Override
public void steal(Avatar other) {
avatar.steal(other);
}
@Override
public boolean canSet() {
return session.canSetAvatar();
}
@Override
public void set() {
avatar.choose();
}
@Override
public void delete() {
avatar.delete();
}
});
leftColumn = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, infoPanel);
leftColumn.setResizeWeight(0.68);
@@ -175,29 +192,8 @@ final class ServerTab {
// ---- dialogs ----
void showAvatarDialog() {
if (conn.isConnected()) new AvatarDialog(host, conn).setVisible(true);
}
/** Uploads someone else's avatar as ours. */
private void stealAvatar(Avatar avatar) {
if (!conn.isConnected()) return;
File file;
try {
file = Files.createTempFile("avatar", "." + avatar.format().extension).toFile();
Files.write(file.toPath(), avatar.data());
} catch (IOException e) {
showAvatarError(e.getMessage());
return;
}
conn.setAvatar(file, error -> {
file.delete();
if (error != null) SwingUtilities.invokeLater(() -> showAvatarError(error));
});
}
private void showAvatarError(String error) {
JOptionPane.showMessageDialog(host, "Error uploading avatar: " + error, "Error", JOptionPane.ERROR_MESSAGE);
AvatarActions avatar() {
return avatar;
}
// ---- chat ----