14 _device_label = builder->get_widget<Gtk::Label>(
"deviceLabel");
17 _done_button = builder->get_widget<Gtk::Button>(
"bluetoothDoneButton");
20 _devices_list_store = std::dynamic_pointer_cast<Gtk::ListStore>(builder->get_object(
"devicesListStore"));
100 Gtk::TreeModel::Row row = *it;
124 std::ifstream asoundrc;
125 std::ofstream asoundrc_tmp;
127 const std::regex mac_pattern(
"([0-9A-F]{2}:){5}[0-9A-F]{2}");
129 asoundrc.open(
"/home/discman/.asoundrc");
130 asoundrc_tmp.open(
"/home/discman/.asoundrc.tmp");
131 if (asoundrc.good()) {
132 while (getline(asoundrc, line)) {
133 std::string outLine = std::regex_replace(line, mac_pattern, address);
134 asoundrc_tmp << outLine << std::endl;
137 asoundrc_tmp.close();
138 std::filesystem::rename(
"/home/discman/.asoundrc.tmp",
"/home/discman/.asoundrc");
175 const std::vector<std::string> devices =
_adapter.devices();
181 for (
unsigned int i = 0; i < devices.size(); i++) {
189 std::ifstream asoundrc;
191 const std::regex mac_pattern(
"([0-9A-F]{2}:){5}[0-9A-F]{2}");
193 asoundrc.open(
"/home/discman/.asoundrc");
194 if (asoundrc.good()) {
195 while (getline(asoundrc, line)) {
198 if (std::regex_search(line, match, mac_pattern)) {
215 }
catch (
const Bluez::Adapter::DeviceNotFound& e) {
Bluetooth device list columns.
Gtk::TreeModelColumn< Glib::ustring > name_column
Device name column.
Gtk::TreeModelColumn< Glib::ustring > address_column
Device address column (hidden).
Gtk::Button * _connect_button
Connect/Disconnect button.
void on_show()
Called when the Bluetooth device selection screen is navigated to.
Gtk::Button * _bluetooth_button
Button that switches to the Bluetooth device selection screen.
Gtk::Button * _done_button
Done button.
void on_bluetooth_button()
Bluetooth button handler.
sig_conn _signal_connected
Emitted when the chosen device has been connected to.
void on_device_added(const std::string &address)
Called when _adapter discovers a new device.
Gtk::TreeView * _devices_tree_view
Device list.
void set_device_labels()
Updates _device_label and _device_status_label based on current state.
sig_done _signal_done
Emitted when the Done button is clicked.
void get_alsa_device_address()
Retrieves the device MAC address from the ALSA configuration file.
void on_device_initialization_complete(const bool initialized)
Called when the Bluetooth device initialization procedure has finished.
void update_asoundrc(const std::string &address)
Update the ALSA configuration file with the newly selected Bluetooth device.
sig_conn signal_connected()
Getter for _signal_connected.
Bluez::Device * _alsa_device
Bluetooth device retrieved from _adapter.
void on_connect_button_clicked()
Called when the Connect/Disconnect button is clicked.
~BluetoothComponent()
BluetoothComponent destructor.
Glib::RefPtr< Gtk::ListStore > _devices_list_store
Device list model.
BluetoothComponent(Glib::RefPtr< Gtk::Builder > builder)
BluetoothComponent constructor.
sigc::signal< void()> sig_conn
"Connected" signal type.
void build_devices_list()
Builds the initial list of preregistered Bluetooth devices.
void on_device_status_change()
Called when the chosen device pairs, connects or disconnects.
void on_device_removed(const std::string &address)
Called when _adapter reports a removed device.
Gtk::Label * _device_status_label
Label displaying chosen device connection status.
sig_button _signal_button
Emitted when the Bluetooth button is clicked.
std::string _alsa_device_address
MAC address of the chosen device.
sig_done signal_done()
Getter for _signal_done.
sigc::signal< void()> sig_done
"Done with screen" signal type.
DeviceInitialization
Bluetooth device initialization state.
Bluez::Adapter _adapter
Bluetooth adapter used for pairing and connection.
DeviceInitialization _alsa_device_init
Initialization status of the chosen device.
void on_hide()
Called when the Bluetooth device selection screen is navigated from.
Gtk::Label * _device_label
Label displaying the chosen device alias.
sig_button signal_button()
Getter for _signal_button.
void try_get_alsa_device()
Attempts to set _alsa_device based on _alsa_device_address.
void on_devices_list_selection_changed()
Called when a device is clicked in the device list.
void on_done_button_clicked()
Called when the Done button is clicked.