Skip to content

Commit

Permalink
Fixed devices config not loading at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola02nb committed Jan 2, 2025
1 parent 186cf58 commit 9d245c4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
40 changes: 25 additions & 15 deletions src/DataTypes/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,39 @@ bool Device::operator==(const Device *d) const
return this->id_vendor == d->id_vendor && this->id_product == d->id_product;
}

void Device::updateDevice(const Device *new_device)
void Device::copyConfig(Device* device){
this->lights = device->lights;
this->sidetone = device->sidetone;
this->voice_prompts = device->voice_prompts;
this->inactive_time = device->inactive_time;
this->equalizer_preset = device->equalizer_preset;
this->equalizer_curve = device->equalizer_curve;
this->volume_limiter = device->volume_limiter;
this->rotate_to_mute = device->rotate_to_mute;
this->mic_mute_led_brightness = device->mic_mute_led_brightness;
this->mic_volume = device->mic_volume;
this->bt_when_powered_on = device->bt_when_powered_on;
this->bt_call_volume = device->bt_call_volume;
}

void Device::updateConfig(const QList<Device *> &list){
foreach (Device* device, list) {
if(*this == device)
this->copyConfig(device);
}
}

void Device::updateInfo(const Device *new_device)
{
this->battery = new_device->battery;
this->chatmix = new_device->chatmix;
}

bool Device::updateDevice(const QList<Device *> &new_device_list)
bool Device::updateInfo(const QList<Device *> &new_device_list)
{
foreach (Device *new_device, new_device_list) {
if (*this == new_device) {
this->updateDevice(new_device);
this->updateInfo(new_device);
return true;
}
}
Expand Down Expand Up @@ -193,18 +215,6 @@ void updateDeviceFromSource(QList<Device *> &devicesToUpdate, const Device *sour
}
}

void updateDevicesFromSource(QList<Device *> &devicesToUpdate, const QList<Device *> &sourceDevices)
{
for (Device *toUpdateDevice : devicesToUpdate) {
for (Device *sourceDevice : sourceDevices) {
if (*toUpdateDevice == sourceDevice) {
// Update the connected device with saved device's information
*toUpdateDevice = *sourceDevice;
}
}
};
}

void serializeDevices(const QList<Device *> &devices, const QString &filePath)
{
QJsonArray jsonArray;
Expand Down
8 changes: 5 additions & 3 deletions src/DataTypes/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ class Device
bool operator==(const Device &d) const;
bool operator==(const Device *d) const;

void updateDevice(const Device *new_device);
bool updateDevice(const QList<Device *> &new_device_list);
void copyConfig(Device* device);
void updateConfig(const QList<Device *> &list);

void updateInfo(const Device *new_device);
bool updateInfo(const QList<Device *> &new_device_list);

QJsonObject toJson() const;
static Device *fromJson(const QJsonObject &json);
};

void updateDeviceFromSource(QList<Device *> &devicesToUpdate, const Device *sourceDevice);
void updateDevicesFromSource(QList<Device *> &devicesToUpdate, const QList<Device *> &sourceDevices);

void serializeDevices(const QList<Device *> &devices, const QString &filePath);
QList<Device *> deserializeDevices(const QString &filePath);
Expand Down
6 changes: 5 additions & 1 deletion src/UI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ void MainWindow::loadDevice()
ui->missingheadsetcontrolFrame->setHidden(true);
rescaleAndMoveWindow();
return;
} else {
QList<Device *> savedDevices = getSavedDevices();
selectedDevice->updateConfig(savedDevices);
deleteDevices(savedDevices);
}

QSet<QString> &capabilities = selectedDevice->capabilities;
Expand Down Expand Up @@ -520,7 +524,7 @@ QList<Device *> MainWindow::getSavedDevices()
bool MainWindow::updateSelectedDevice()
{
QList<Device *> newDl = API.getConnectedDevices();
if (!selectedDevice->updateDevice(newDl)) {
if (!selectedDevice->updateInfo(newDl)) {
selectedDevice = nullptr;
return false;
}
Expand Down

0 comments on commit 9d245c4

Please sign in to comment.