#include "widgets/controlCenter/bluetoothSettingsRow.hpp" #include #include "components/button/iconButton.hpp" #include "connection/dbus/bluetooth.hpp" #include "helpers/string.hpp" #include "services/notificationController.hpp" BluetoothSettingsRow::BluetoothSettingsRow(const BluetoothDevice &device) : device(device), pairButton(device.paired ? Icon::BLUETOOTH_CONNECTED : Icon::BLUETOOTH), connectButton(device.connected ? Icon::LINK : Icon::LINK_OFF), trustButton(device.trusted ? Icon::DONE_ALL : Icon::REMOVE_DONE) { set_orientation(Gtk::Orientation::HORIZONTAL); set_spacing(10); add_css_class("bluetooth-settings-row"); set_hexpand(true); set_halign(Gtk::Align::FILL); if (!device.icon.empty()) { this->icon.set_from_icon_name(device.icon); this->icon.set_pixel_size(24); append(this->icon); } auto deviceInfoBox = Gtk::Box(Gtk::Orientation::VERTICAL); deviceInfoBox.set_spacing(2); append(deviceInfoBox); nameLabel.set_ellipsize(Pango::EllipsizeMode::END); nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name ); nameLabel.set_halign(Gtk::Align::START); nameLabel.set_valign(Gtk::Align::CENTER); deviceInfoBox.append(nameLabel); addressLabel.set_text(device.address); addressLabel.set_halign(Gtk::Align::START); addressLabel.set_valign(Gtk::Align::CENTER); addressLabel.add_css_class("bluetooth-device-address"); deviceInfoBox.append(addressLabel); deviceInfoBox.set_size_request(140, -1); auto buttonBox = Gtk::Box(Gtk::Orientation::HORIZONTAL); buttonBox.set_hexpand(true); buttonBox.set_halign(Gtk::Align::END); append(buttonBox); pairButton.signal_clicked().connect([this]() { if (this->device.paired) { BluetoothController::getInstance()->unpairDevice(this->device.object_path); } else { BluetoothController::getInstance()->pairDevice(this->device.object_path); } }); buttonBox.append(pairButton); connectButton.signal_clicked().connect([this]() { if (this->device.connected) { BluetoothController::getInstance()->disconnectDevice(this->device.object_path); } else { BluetoothController::getInstance()->connectDevice(this->device.object_path); } }); buttonBox.append(connectButton); trustButton.signal_clicked().connect([this]() { BluetoothController::getInstance()->trustDevice(this->device.object_path, !this->device.trusted); }); buttonBox.append(trustButton); } void BluetoothSettingsRow::updateDevice(const BluetoothDevice &device) { this->device = device; if (!device.icon.empty()) { this->icon.set_from_icon_name(device.icon); } spdlog::info("Updating device {}: paired={}, connected={}, trusted={}", device.name, device.paired, device.connected, device.trusted); nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name); addressLabel.set_text(device.address); pairButton.setIcon(device.paired ? Icon::BLUETOOTH_CONNECTED : Icon::BLUETOOTH); connectButton.setIcon(device.connected ? Icon::LINK : Icon::LINK_OFF); trustButton.setIcon(device.trusted ? Icon::DONE_ALL : Icon::REMOVE_DONE); }