Save or steal other people's avatars from the info panel

Right-clicking a client's avatar offers to save it to a file or to take
it as our own avatar on that server, as the Android picture viewer does.
Our own avatar only offers saving.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 15:56:11 +00:00
co-authored by Claude Opus 5.5
parent 8fc7be826c
commit e7d338ce28
2 changed files with 108 additions and 0 deletions
@@ -9,15 +9,21 @@ import com.ts3client.net.ChannelNode;
import com.ts3client.net.ConnectionListener.ChatScope;
import com.ts3client.net.PictureDownloads;
import com.ts3client.net.TeamspeakConnection;
import com.ts3client.net.avatar.Avatar;
import com.ts3client.session.ServerSession;
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
@@ -101,6 +107,8 @@ final class ServerTab {
}
});
infoPanel.setAvatarStealer(this::stealAvatar);
leftColumn = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, infoPanel);
leftColumn.setResizeWeight(0.68);
leftColumn.setContinuousLayout(true);
@@ -171,6 +179,27 @@ final class ServerTab {
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);
}
// ---- chat ----
private void onSendChat(ChatPanel.Target target, int clientId, String text) {