[Client] Alt badges, breadcrumb trail, investigate button (#7516)

* [Client] Alt badges, breadcrumb trail, investigate button

AltTableDelegate paints palette-tinted match badges with paint-through selection, style warning/critical icons on nonzero counts, and font/elision handling. TabAlts gains a clickable breadcrumb trail, an Investigate-this-user button, and bold usernames. Async alts responses are guarded against stale investigations.

* [Client] Fix alt badge and trail review findings

- Drop the dead VPN warning branch: rowVisible() already hides IP rows
  above the threshold, so setVpnThreshold(), its member and the spin-box
  connect never took effect.
- Dim IP rows at shared_count > 2 instead of > 1: the count already
  includes the investigated account, so every IP row was dimmed.
- Truncate backStack when a breadcrumb is clicked instead of pushing the
  current user again, so the trail keeps a single path and Back works.
- Word-wrap the trail label so a long chain cannot widen the tab.
- Extract the status/match pill painting into widgets/utility/pill_painter
  and use it from both delegates instead of duplicating it.

* [Client] Route investigate() through the trail helper

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-11-08 08:59:50 +01:00 • committed by GitHub
parent 18f9b26a3d
commit 2fba13753b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 298 additions and 29 deletions

View file

@ -3,6 +3,7 @@
#include "../utility/epoch_format.h"
#include "../utility/table_activation.h"
#include "abstract_client.h"
#include "alt_table_delegate.h"
#include "libcockatrice/protocol/pb/response.pb.h"
#include "libcockatrice/protocol/pb/response_user_alts.pb.h"
@ -102,6 +103,18 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
connect(backButton, &QPushButton::clicked, this, &TabAlts::goBack);
statusLabel = new QLabel;
trailLabel = new QLabel;
trailLabel->setTextFormat(Qt::RichText);
trailLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
trailLabel->setOpenExternalLinks(false);
// The trail grows with every hop, so let it wrap instead of forcing the tab
// wider than the window.
trailLabel->setWordWrap(true);
connect(trailLabel, &QLabel::linkActivated, this, [this](const QString &userName) {
if (!userName.isEmpty() && userName != currentUser) {
goToTrailEntry(userName);
}
});
auto *topBar = new QHBoxLayout;
topBar->addWidget(backButton);
@ -136,6 +149,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
altsTable = new QTableWidget(0, COL_ALTS_COUNT);
configureAltTable(altsTable);
altsDelegate = new AltTableDelegate(COL_ALTS_VIA, COL_ALTS_WARNS, COL_ALTS_BANS, COL_ALTS_SHARED, altsTable);
altsTable->setItemDelegateForColumn(COL_ALTS_VIA, altsDelegate);
altsTable->setItemDelegateForColumn(COL_ALTS_WARNS, altsDelegate);
altsTable->setItemDelegateForColumn(COL_ALTS_BANS, altsDelegate);
connectTableActivation(altsTable, this, [this](const QModelIndex &index) {
if (!index.isValid()) {
return;
@ -174,6 +191,10 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
detailsLayout->addLayout(detailGrid);
detailsLayout->addWidget(warnsTable, 1);
detailsLayout->addWidget(bansTable, 1);
investigateSelectedButton = new QPushButton;
investigateSelectedButton->setEnabled(false);
connect(investigateSelectedButton, &QPushButton::clicked, this, &TabAlts::investigateSelected);
detailsLayout->addWidget(investigateSelectedButton);
auto *contentSplitter = new QSplitter(Qt::Horizontal);
contentSplitter->addWidget(altsTable);
@ -186,6 +207,7 @@ TabAlts::TabAlts(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
mainLayout->addLayout(topBar);
mainLayout->addLayout(filterBar);
mainLayout->addWidget(statusLabel);
mainLayout->addWidget(trailLabel);
mainLayout->addWidget(contentSplitter, 1);
retranslateUi();
@ -225,6 +247,8 @@ void TabAlts::retranslateUi()
detailNameLabel->setText(tr("Name:"));
detailCountsLabel->setText(tr("Counts:"));
detailNotesLabel->setText(tr("Admin notes:"));
investigateSelectedButton->setText(tr("Investigate this user"));
investigateSelectedButton->setToolTip(tr("Open the selected account as a new investigation"));
if (!lastAlts.isEmpty()) {
renderTable();
@ -241,6 +265,13 @@ void TabAlts::investigate(const QString &userName)
if (userName.isEmpty() || userName == currentUser) {
return;
}
// Alt matches are symmetric, so revisiting an earlier account is a normal
// double-click. Truncate there instead of pushing it again, so the trail
// stays a single path.
if (backStack.contains(userName)) {
goToTrailEntry(userName);
return;
}
if (!currentUser.isEmpty()) {
backStack << currentUser;
backButton->setEnabled(true);
@ -248,6 +279,20 @@ void TabAlts::investigate(const QString &userName)
loadUser(userName);
}
void TabAlts::goToTrailEntry(const QString &userName)
{
const int index = backStack.indexOf(userName);
if (index < 0) {
investigate(userName);
return;
}
// Clicking an earlier crumb truncates the history there instead of pushing
// another entry, so the trail keeps a single path and Back still works.
backStack.erase(backStack.begin() + index, backStack.end());
backButton->setEnabled(!backStack.isEmpty());
loadUser(userName);
}
void TabAlts::goBack()
{
if (backStack.isEmpty()) {
@ -262,16 +307,41 @@ void TabAlts::loadUser(const QString &userName)
{
currentUser = userName;
searchEdit->setText(userName);
updateTrail();
investigateUser();
}
void TabAlts::updateTrail()
{
QStringList trail = backStack;
trail << currentUser;
trail.removeAll(QString());
QStringList links;
for (const QString &name : trail) {
const QString safeName = name.toHtmlEscaped();
if (name == currentUser) {
links << QStringLiteral("<b>") + safeName + QStringLiteral("</b>");
} else {
links << QStringLiteral("<a href=\"") + safeName + QStringLiteral("\">") + safeName +
QStringLiteral("</a>");
}
}
trailLabel->setText(links.join(QStringLiteral(" › ")));
trailLabel->setVisible(!links.isEmpty());
}
void TabAlts::investigateUser()
{
const QString userName = searchEdit->text().simplified();
if (userName.isEmpty()) {
return;
}
if (userName != currentUser && !currentUser.isEmpty()) {
backStack << currentUser;
backButton->setEnabled(true);
}
currentUser = userName;
updateTrail();
lastAlts.clear();
selectedUser.clear();
clearDetails();
@ -393,9 +463,14 @@ void TabAlts::renderTable()
altsTable->setItem(row, COL_ALTS_WARNS, new QTableWidgetItem(QString::number(alt.warn_count())));
altsTable->setItem(row, COL_ALTS_BANS, new QTableWidgetItem(QString::number(alt.ban_count())));
altsTable->setItem(row, COL_ALTS_ACTIVE, new QTableWidgetItem(alt.is_active() ? tr("yes") : tr("no")));
// shared_count already includes the investigated account, so anything
// above 2 means the address is shared beyond that pair.
if (QString::fromStdString(alt.match_reason()).startsWith(QStringLiteral("ip:")) && alt.has_shared_count() &&
alt.shared_count() > 2) {
for (int col = 0; col < COL_ALTS_COUNT; ++col) {
if (col == COL_ALTS_VIA) {
continue;
}
if (auto *item = altsTable->item(row, col)) {
item->setForeground(dimColor);
}
@ -446,6 +521,13 @@ void TabAlts::onFilterChanged()
renderTable();
}
void TabAlts::investigateSelected()
{
if (!selectedUser.isEmpty() && selectedUser != currentUser) {
investigate(selectedUser);
}
}
void TabAlts::onAltSelected()
{
const auto selected = altsTable->selectedItems();
@ -469,6 +551,7 @@ void TabAlts::requestDetails(const QString &userName)
detailNotesEdit->clear();
warnsTable->setRowCount(0);
bansTable->setRowCount(0);
investigateSelectedButton->setEnabled(userName != currentUser);
Command_ReportUserInfo infoCmd;
infoCmd.set_user_name(userName.toStdString());
@ -508,6 +591,7 @@ void TabAlts::clearDetails()
detailNotesEdit->clear();
warnsTable->setRowCount(0);
bansTable->setRowCount(0);
investigateSelectedButton->setEnabled(false);
}
void TabAlts::userDetailsResponse(const Response &response)