-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsbGuardManager.cpp
More file actions
54 lines (44 loc) · 1.82 KB
/
UsbGuardManager.cpp
File metadata and controls
54 lines (44 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "UsbGuardManager.h"
#include <QDebug>
UsbGuardManager::UsbGuardManager(UsbGuardDevicesModel* model, QObject *parent)
: QObject(parent), m_model(model)
{
// 1. Instantiate the D-Bus Proxy
// The proxy connects to the D-Bus in its constructor.
m_proxy = new DBusUsbProxy(this);
// 2. Wire the Signals and Slots
// A. When the proxy has the full, parsed list, give it to the model.
connect(m_proxy, &DBusUsbProxy::deviceListReady,
this, &UsbGuardManager::handleDeviceListReady);
// B. When the D-Bus signals a change, re-request the full list to update.
connect(m_proxy, &DBusUsbProxy::deviceListChanged,
this, &UsbGuardManager::handleDeviceListChanged);
// C. Handle errors (optional, but good practice).
connect(m_proxy, &DBusUsbProxy::errorOccurred,
this, &UsbGuardManager::handleProxyError);
// 3. Initial Data Load
refreshDeviceList();
}
void UsbGuardManager::refreshDeviceList()
{
qDebug() << "Manager requesting device list from D-Bus proxy...";
m_proxy->listDevices();
}
void UsbGuardManager::handleDeviceListReady(const QList<UsbDeviceData>& devices)
{
qDebug() << "Manager received new device list. Passing to model...";
m_model->loadDeviceData(devices);
}
void UsbGuardManager::handleDeviceListChanged()
{
qDebug() << "D-Bus DeviceChanged signal received. Triggering full list refresh...";
// The easiest way to handle a remote change is to re-request the full list.
// A more complex solution would be to parse the D-Bus signal directly
// and update the model's internal data without a full reset.
refreshDeviceList();
}
void UsbGuardManager::handleProxyError(const QString& message)
{
qCritical() << "USBGuard Proxy Error:" << message;
// You could also emit a signal here to notify the main GUI window.
}