fix styling issues

This commit is contained in:
2026-02-09 21:01:56 +01:00
parent ea9ab4b2cb
commit d1b81c4d3e
20 changed files with 778 additions and 207 deletions

View File

@@ -2,6 +2,120 @@
#include <memory>
BluetoothSettings::BluetoothSettings() : bluetoothIsPowered(this->bluetoothController->isPowered()), bluetoothIsScanning(this->bluetoothController->isDiscovering()) {
set_orientation(Gtk::Orientation::VERTICAL);
set_spacing(12);
add_css_class("bluetooth-settings");
powerButton->add_css_class("power-button");
setBluetoothPowered(bluetoothIsPowered);
powerButton->set_tooltip_text(bluetoothIsPowered ? "Turn Bluetooth Off" : "Turn Bluetooth On");
powerButton->signal_clicked().connect([this]() {
bluetoothIsPowered = !bluetoothIsPowered;
this->bluetoothController->setPowered(bluetoothIsPowered);
});
this->buttonRow.append(*powerButton);
scanButton->add_css_class("power-button");
setScanning(bluetoothIsScanning);
scanButton->set_tooltip_text(bluetoothIsScanning ? "Stop Scanning" : "Start Scanning");
scanButton->signal_clicked().connect([this]() {
bluetoothIsScanning = !bluetoothIsScanning;
if (bluetoothIsScanning) {
this->bluetoothController->startDiscovery();
} else {
this->bluetoothController->stopDiscovery();
}
});
this->buttonRow.append(*scanButton);
this->buttonRow.set_spacing(12);
append(this->buttonRow);
connectedDevicesBox.add_css_class("active-devices");
connectedDevicesBox.set_orientation(Gtk::Orientation::VERTICAL);
connectedDevicesScroll.set_child(connectedDevicesBox);
connectedDevicesScroll.set_policy(Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC);
connectedDevicesScroll.set_propagate_natural_height(true);
connectedDevicesScroll.set_max_content_height(200);
append(connectedDevicesScroll);
availableDevicesBox.add_css_class("available-devices");
availableDevicesBox.set_orientation(Gtk::Orientation::VERTICAL);
availableDevicesScroll.set_child(availableDevicesBox);
availableDevicesScroll.set_policy(Gtk::PolicyType::NEVER, Gtk::PolicyType::AUTOMATIC);
availableDevicesScroll.set_propagate_natural_height(true);
availableDevicesScroll.set_max_content_height(200);
append(availableDevicesScroll);
this->bluetoothController->signalPoweredChanged().connect([this](bool powered) {
bluetoothIsPowered = powered;
setBluetoothPowered(powered);
});
this->bluetoothController->signalDiscoveringChanged().connect([this](bool scanning) {
bluetoothIsScanning = scanning;
setScanning(scanning);
});
auto devices = this->bluetoothController->getDevices();
for (const auto &device : devices) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
if (device.connected) {
connectedDevicesBox.append(*row);
} else {
availableDevicesBox.append(*row);
}
}
this->bluetoothController->signalDeviceAdded().connect([this](const BluetoothDevice &device) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
if (device.connected) {
connectedDevicesBox.append(*row);
} else {
availableDevicesBox.append(*row);
}
});
this->bluetoothController->signalDeviceRemoved().connect([this](const std::string &object_path) {
auto it = deviceRows.find(object_path);
if (it != deviceRows.end()) {
auto parent = it->second->get_parent();
if (parent) {
dynamic_cast<Gtk::Box *>(parent)->remove(*it->second);
}
deviceRows.erase(it);
}
});
this->bluetoothController->signalDeviceChanged().connect([this](const BluetoothDevice &device) {
auto it = deviceRows.find(device.object_path);
if (it != deviceRows.end()) {
it->second->updateDevice(device);
// Move between boxes if connection status changed
auto parent = it->second->get_parent();
Gtk::Box *targetBox = device.connected ? &connectedDevicesBox : &availableDevicesBox;
if (parent != targetBox) {
if (parent) {
dynamic_cast<Gtk::Box *>(parent)->remove(*it->second);
}
targetBox->append(*it->second);
}
}
});
}
void BluetoothSettings::setBluetoothPowered(bool powered) {
this->bluetoothIsPowered = powered;
@@ -28,54 +142,4 @@ void BluetoothSettings::setScanning(bool scanning) {
scanButton->add_css_class("power-button-off");
scanButton->set_tooltip_text("Start Scanning");
}
}
BluetoothSettings::BluetoothSettings() : bluetoothIsPowered(this->bluetoothController->isPowered()) {
set_orientation(Gtk::Orientation::VERTICAL);
set_spacing(12);
auto devices = this->bluetoothController->getDevices();
powerButton->add_css_class("power-button");
setBluetoothPowered(bluetoothIsPowered);
powerButton->set_tooltip_text(bluetoothIsPowered ? "Turn Bluetooth Off" : "Turn Bluetooth On");
powerButton->signal_clicked().connect([this]() {
bluetoothIsPowered = !bluetoothIsPowered;
this->bluetoothController->setPowered(bluetoothIsPowered);
});
append(*powerButton);
this->bluetoothController->signalPoweredChanged().connect([this](bool powered) {
bluetoothIsPowered = powered;
setBluetoothPowered(powered);
});
for (const auto &device : devices) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
append(*row);
}
bluetoothController->signalDeviceAdded().connect([this](const BluetoothDevice &device) {
auto row = std::make_shared<BluetoothSettingsRow>(device);
deviceRows[device.object_path] = row;
append(*row);
});
bluetoothController->signalDeviceRemoved().connect([this](const std::string &object_path) {
auto it = deviceRows.find(object_path);
if (it != deviceRows.end()) {
remove(*it->second);
deviceRows.erase(it);
}
});
bluetoothController->signalDeviceChanged().connect([this](const BluetoothDevice &device) {
auto it = deviceRows.find(device.object_path);
if (it != deviceRows.end()) {
it->second->updateDevice(device);
}
});
}

View File

@@ -0,0 +1,90 @@
#include "widgets/controlCenter/bluetoothSettingsRow.hpp"
#include <spdlog/spdlog.h>
#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);
std::string shortName = StringHelper::trimToSize(device.name.empty() ? "Unknown Device" : device.name, 14);
nameLabel.set_text(shortName);
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);
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);
std::string shortName = StringHelper::trimToSize(device.name.empty() ? "Unknown Device" : device.name, 14);
nameLabel.set_text(shortName);
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);
}

View File

@@ -21,7 +21,6 @@ ControlCenter::ControlCenter(Icon::Type icon, std::string name)
this->tabRow.set_orientation(Gtk::Orientation::HORIZONTAL);
this->tabRow.set_spacing(4);
this->tabRow.set_margin_bottom(4);
this->tabRow.add_css_class("control-center-tab-row");
this->mediaTabButton = std::make_unique<TabButton>(Icon::PLAY_CIRCLE);
@@ -78,12 +77,15 @@ void ControlCenter::setActiveTab(const std::string &tab_name) {
this->mediaTabButton->setActive(false);
this->infoTabButton->setActive(false);
this->timerButton->setActive(false);
this->settingsTabButton->setActive(false);
if (tab_name == "controls") {
this->mediaTabButton->setActive(true);
} else if (tab_name == "info") {
this->infoTabButton->setActive(true);
} else if (tab_name == "timer") {
this->timerButton->setActive(true);
} else if (tab_name == "settings") {
this->settingsTabButton->setActive(true);
}
}