#pragma once #include "components/button/iconButton.hpp" #include "connection/dbus/bluetooth.hpp" #include "gtkmm/box.h" #include "gtkmm/button.h" #include "gtkmm/image.h" #include "gtkmm/label.h" class BluetoothSettingsRow : public Gtk::Box { public: BluetoothSettingsRow(const BluetoothDevice &device) : device(device) { set_orientation(Gtk::Orientation::HORIZONTAL); set_spacing(10); set_margin_bottom(6); if (!device.icon.empty()) { this->icon.set_from_icon_name(device.icon); this->icon.set_pixel_size(24); append(this->icon); } nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name); nameLabel.set_halign(Gtk::Align::START); nameLabel.set_valign(Gtk::Align::CENTER); 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"); append(addressLabel); pairButton.set_label(device.paired ? "Unpair" : "Pair"); pairButton.signal_clicked().connect([device]() { if (device.paired) { BluetoothController::getInstance()->unpairDevice(device.object_path); } else { BluetoothController::getInstance()->pairDevice(device.object_path); } }); append(pairButton); connectButton.set_label(device.connected ? "Disconnect" : "Connect"); connectButton.signal_clicked().connect([device]() { if (device.connected) { BluetoothController::getInstance()->disconnectDevice(device.object_path); } else { BluetoothController::getInstance()->connectDevice(device.object_path); } }); append(connectButton); trustButton.set_label(device.trusted ? "Distrust" : "Trust"); trustButton.signal_clicked().connect([device]() { BluetoothController::getInstance()->trustDevice(device.object_path, !device.trusted); }); append(trustButton); } void updateDevice(const BluetoothDevice &device) { this->device = device; if (!device.icon.empty()) { this->icon.set_from_icon_name(device.icon); } nameLabel.set_text(device.name.empty() ? "Unknown Device" : device.name); addressLabel.set_text(device.address); pairButton.set_label(device.paired ? "Unpair" : "Pair"); connectButton.set_label(device.connected ? "Disconnect" : "Connect"); trustButton.set_label(device.trusted ? "Distrust" : "Trust"); } private: BluetoothDevice device; Gtk::Image icon; Gtk::Label nameLabel; Gtk::Label addressLabel; Gtk::Button pairButton; Gtk::Button connectButton; Gtk::Button trustButton; }; class BluetoothSettings : public Gtk::Box { public: BluetoothSettings(); private: std::shared_ptr bluetoothController = BluetoothController::getInstance(); std::map activeBluetoothDevices; std::map> deviceRows; std::shared_ptr powerButton = std::make_shared(Icon::POWER_SETTINGS_NEW); std::shared_ptr scanButton = std::make_shared(Icon::BLUETOOTH_SEARCHING); Gtk::Box connectedDevicesBox; Gtk::Box availableDevicesBox; bool bluetoothIsPowered = false; bool bluetoothIsScanning = false; void addBluetoothDevice(const BluetoothDevice &device); void removeBluetoothDevice(const std::string &object_path); void updateBluetoothDevice(const BluetoothDevice &device); void setBluetoothPowered(bool powered); void setScanning(bool scanning); };