From b2cdf44bbd2808a4e8432ec9eaefd816b868e310 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Mon, 17 Aug 2026 03:58:41 +0200 Subject: [PATCH] [UserList] Show amount of online buddies (#7126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [UserList] Show amount of online buddies Took 11 minutes * [UserList] Replace early return with if-else in updateSectionDivider RickyRister nit: the code is easier to follow with a standard if-else branch instead of an early return for the Buddy section. Took 1 minute --------- Co-authored-by: Lukas BrĂ¼bach --- .../widgets/server/user/user_list_widget.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp b/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp index afcd3f87a..be52b9871 100644 --- a/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp +++ b/cockatrice/src/interface/widgets/server/user/user_list_widget.cpp @@ -1639,15 +1639,27 @@ void UserListWidget::updateSectionDivider(Section section) return; } int visible = 0; + int online = 0; for (int i = 0; i < divider->childCount(); ++i) { - if (!divider->child(i)->isHidden()) { + QTreeWidgetItem *child = divider->child(i); + if (!child->isHidden()) { ++visible; + if (child->data(0, UserListRoles::Online).toBool()) { + ++online; + } } } // The tree draws no branches (rows are flush), so the divider carries its // own collapse arrow glyph. const QString arrow = divider->isExpanded() ? QStringLiteral("\u25BE") : QStringLiteral("\u25B8"); - divider->setText(0, tr("%1 %2 (%3)").arg(arrow, sectionTitle(section)).arg(visible)); + if (section == Section::Buddy) { + // The buddy divider reports how many of the shown buddies are online, + // mirroring the "Buddies online: %1 / %2" title of the non-sectioned + // buddy list. + divider->setText(0, tr("%1 %2 (%3/%4)").arg(arrow, sectionTitle(section)).arg(online).arg(visible)); + } else { + divider->setText(0, tr("%1 %2 (%3)").arg(arrow, sectionTitle(section)).arg(visible)); + } } void UserListWidget::handleSectionExpansion(QTreeWidgetItem *item, bool expanded)