/* * SPDX-FileCopyrightText: 2025 Felix Morgner * SPDX-License-Identifier: LGPL-2.1-only */ #include "participant_row.hpp" #include "messages.hpp" #include "resources.hpp" #include "template_widget.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Turns::gui { namespace { auto constexpr static TYPE_NAME = "ParticipantRow"; auto constexpr static TEMPLATE = resource::participant_row_ui; auto css_class_for(Participant::Disposition value) -> Glib::ustring { using Disposition = Participant::Disposition; switch (value) { case Disposition::Friendly: return "disposition-friendly"; case Disposition::Hostile: return "disposition-hostile"; case Disposition::Secret: return "disposition-secret"; default: return ""; } } auto format_priority(float priority) -> Glib::ustring { return std::vformat(_(message::priority_number), std::make_format_args(priority)); } } // namespace ParticipantRow::ParticipantRow() : Glib::ObjectBase(TYPE_NAME) , template_widget{TEMPLATE} , m_delete{get_widget("delete")} , m_edit{get_widget("edit")} , m_subtitle{get_widget("subtitle")} , m_title{get_widget("title")} , m_toggle_defeated{get_widget("toggle_defeated")} , m_delete_enabled{*this, "delete-enabled", true} , m_edit_enabled{*this, "edit-enabled", true} { m_delete->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantRow::handle_delete)); m_edit->signal_clicked().connect(sigc::mem_fun(*this, &ParticipantRow::handle_edit)); Glib::Binding::bind_property(m_subtitle->property_label(), m_subtitle->property_visible(), Glib::Binding::Flags::DEFAULT, sigc::mem_fun(&Glib::ustring::size)); Glib::Binding::bind_property(m_title->property_label(), m_title->property_visible(), Glib::Binding::Flags::INVERT_BOOLEAN, sigc::mem_fun(&Glib::ustring::size)); Glib::Binding::bind_property(m_toggle_defeated->property_active(), m_toggle_defeated->property_icon_name(), Glib::Binding::Flags::SYNC_CREATE, [](auto active) { return active ? "face-sick-symbolic" : "face-smile-symbolic"; }); Glib::Binding::bind_property(delete_enabled(), m_delete->property_sensitive(), Glib::Binding::Flags::SYNC_CREATE); Glib::Binding::bind_property(edit_enabled(), m_edit->property_sensitive(), Glib::Binding::Flags::SYNC_CREATE); } ParticipantRow::ParticipantRow(Glib::RefPtr participant) : ParticipantRow{} { Glib::Binding::bind_property(participant->property_name(), m_title->property_label(), Glib::Binding::Flags::SYNC_CREATE); Glib::Binding::bind_property(participant->property_priority(), m_subtitle->property_label(), Glib::Binding::Flags::SYNC_CREATE, &format_priority); Glib::Binding::bind_property(participant->property_disposition(), m_toggle_defeated->property_css_classes(), Glib::Binding::Flags::SYNC_CREATE, [this](auto value) { auto classes = m_toggle_defeated->get_css_classes(); auto removed = std::ranges::remove_if(classes, [](auto cls) { return (cls == "disposition-friendly") | (cls == "disposition-hostile") || (cls == "disposition-secret"); }); classes.erase(removed.begin(), removed.end()); classes.push_back(css_class_for(value)); return classes; }); Glib::Binding::bind_property(participant->property_active(), property_css_classes(), Glib::Binding::Flags::SYNC_CREATE, [this](auto value) { auto classes = get_css_classes(); if (!value) { std::erase(classes, "active-participant"); } else { classes.push_back("active-participant"); } return classes; }); } auto ParticipantRow::delete_enabled() -> Glib::PropertyProxy { return m_delete_enabled.get_proxy(); } auto ParticipantRow::edit_enabled() -> Glib::PropertyProxy { return m_edit_enabled.get_proxy(); } auto ParticipantRow::handle_delete() -> void { auto index = Glib::Variant::create(get_index()); activate_action("win.delete", index); } auto ParticipantRow::handle_edit() -> void { auto index = Glib::Variant::create(get_index()); activate_action("win.edit", index); } } // namespace Turns::gui