Discman
Loading...
Searching...
No Matches
bluetooth_component.h
Go to the documentation of this file.
1
6
7 #ifndef BLUETOOTH_COMPONENT_H
8#define BLUETOOTH_COMPONENT_H
9
10#include <filesystem>
11#include <fstream>
12#include <vector>
13#include <string>
14#include <regex>
15
16#include <glibmm.h>
17#include <gtkmm/builder.h>
18#include <gtkmm/button.h>
19#include <gtkmm/label.h>
20#include <gtkmm/treeview.h>
21#include <gtkmm/treemodel.h>
22#include <gtkmm/liststore.h>
23#include <sigc++/signal.h>
24
25#include <bluez/adapter.h>
26
27#include "component.h"
28
31
32 public:
34 typedef sigc::signal<void()> sig_done;
35
37 typedef sigc::signal<void()> sig_conn;
38
40 typedef sigc::signal<void()> sig_button;
41
44 BluetoothComponent(Glib::RefPtr<Gtk::Builder> builder);
45
48
49 void on_show();
50 void on_hide();
51
54 void on_device_initialization_complete(const bool initialized);
55
59
60 private:
61
68
70 class DevicesListColumnRecord : public Gtk::TreeModel::ColumnRecord {
71 public:
73 this->add(this->address_column);
74 this->add(this->name_column);
75 }
76
77 Gtk::TreeModelColumn<Glib::ustring> address_column;
78 Gtk::TreeModelColumn<Glib::ustring> name_column;
79 };
80
84
85 Bluez::Adapter _adapter;
87 Bluez::Device* _alsa_device;
88
89 Gtk::Button* _bluetooth_button;
90
91 Gtk::Label* _device_label;
93 Gtk::TreeView* _devices_tree_view;
94 Glib::RefPtr<Gtk::ListStore> _devices_list_store;
95 Gtk::Button* _done_button;
96 Gtk::Button* _connect_button;
97
99
100 void on_bluetooth_button();
102 void on_device_added(const std::string& address);
103 void on_device_removed(const std::string& address);
106
108
109 void build_devices_list();
111 void try_get_alsa_device();
112 void set_device_labels();
113
116 void update_asoundrc(const std::string& address);
117
118};
119
120#endif // BLUETOOTH_COMPONENT_H
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.
sigc::signal< void()> sig_button
"Button clicked" signal type.
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.