Show each channel's own icon in the tree
Channels carry a channel_icon_id just like groups do; track it on ChannelNode from the channel list and the create/edit events, and paint it in the same right-aligned strip that already carries a client's group icons. Spacers keep their bare look. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,8 @@ public final class ChannelNode {
|
||||
public boolean hasPassword;
|
||||
public boolean permanent;
|
||||
public int maxClients = -1;
|
||||
/** Id of the channel's custom icon in the server's file repository, or 0 for none. */
|
||||
public long iconId;
|
||||
|
||||
/** Populated when the tree is rebuilt. */
|
||||
public final List<ChannelNode> children = new ArrayList<>();
|
||||
|
||||
@@ -316,6 +316,10 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
node.permanent = ch.isPermanent();
|
||||
node.topic = ch.getTopic() == null ? "" : ch.getTopic();
|
||||
node.maxClients = ch.getMaxClients();
|
||||
// channellist omits the icon on some servers; keep what events gave us.
|
||||
if (ch.get("channel_icon_id") != null) {
|
||||
node.iconId = safeLong(ch.get("channel_icon_id"));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -607,7 +611,8 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
int pid = safeInt(e, "cpid");
|
||||
if (pid == 0) pid = safeInt(e, "pid");
|
||||
int order = safeInt(e, "channel_order");
|
||||
model.putChannel(cid, name, pid, order);
|
||||
ChannelNode node = model.putChannel(cid, name, pid, order);
|
||||
node.iconId = safeLong(e, "channel_icon_id");
|
||||
model.relinkChannel(cid, pid, order);
|
||||
ui.onModelChanged();
|
||||
}
|
||||
@@ -625,6 +630,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
String name = e.get("channel_name");
|
||||
if (name != null) ch.name = name;
|
||||
if (e.get("channel_order") != null) ch.order = e.getInt("channel_order");
|
||||
if (e.get("channel_icon_id") != null) ch.iconId = safeLong(e, "channel_icon_id");
|
||||
ui.onModelChanged();
|
||||
}
|
||||
}
|
||||
@@ -647,7 +653,7 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
String name = e.get("channel_name");
|
||||
int pid = safeInt(e, "cpid");
|
||||
int order = safeInt(e, "channel_order");
|
||||
model.putChannel(cid, name, pid, order);
|
||||
model.putChannel(cid, name, pid, order).iconId = safeLong(e, "channel_icon_id");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1047,10 +1053,14 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
// ---- helpers ----
|
||||
|
||||
private static long safeLong(BaseEvent e, String key) {
|
||||
return safeLong(e.get(key));
|
||||
}
|
||||
|
||||
/** @return the parsed value, or 0 when it is absent or not a number */
|
||||
private static long safeLong(String value) {
|
||||
try {
|
||||
String v = e.get(key);
|
||||
return v == null ? 0 : Long.parseLong(v.trim());
|
||||
} catch (Exception ex) {
|
||||
return value == null ? 0 : Long.parseLong(value.trim());
|
||||
} catch (NumberFormatException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user