From 141fe3145feef07dfba61dbefb99ca08c98988c3 Mon Sep 17 00:00:00 2001 From: Nicola <61830443+nicola02nb@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:53:59 +0100 Subject: [PATCH] Done a Bunch of stuff for multiple device support --- src/DataTypes/device.cpp | 110 +++++----- src/DataTypes/device.h | 8 +- src/DataTypes/settings.cpp | 2 + src/UI/mainwindow.cpp | 345 ++++++++++++++++---------------- src/UI/mainwindow.h | 22 +- src/UI/mainwindow.ui | 274 ++++++++++++++++++++----- src/Utils/headsetcontrolapi.cpp | 152 +++++++++----- src/Utils/headsetcontrolapi.h | 48 +++-- 8 files changed, 605 insertions(+), 356 deletions(-) diff --git a/src/DataTypes/device.cpp b/src/DataTypes/device.cpp index 57c2a93..5d9edc2 100644 --- a/src/DataTypes/device.cpp +++ b/src/DataTypes/device.cpp @@ -110,9 +110,9 @@ void Device::updateDevice(const Device *new_device) bool Device::updateDevice(const QList &new_device_list) { - for (int i = 0; i < new_device_list.length(); ++i) { - if (this != new_device_list.at(i)) { - this->updateDevice(new_device_list.at(i)); + foreach (Device *new_device, new_device_list) { + if (*this == new_device) { + this->updateDevice(new_device); return true; } } @@ -145,69 +145,63 @@ QJsonObject Device::toJson() const return json; } -Device Device::fromJson(const QJsonObject &json) +Device *Device::fromJson( + const QJsonObject &json) { - Device device; - device.device = json["device"].toString(); - device.vendor = json["vendor"].toString(); - device.product = json["product"].toString(); - device.id_vendor = json["id_vendor"].toString(); - device.id_product = json["id_product"].toString(); - - device.lights = json["lights"].toInt(); - device.sidetone = json["sidetone"].toInt(); - device.voice_prompts = json["voice_prompts"].toInt(); - device.inactive_time = json["inactive_time"].toInt(); - device.equalizer_preset = json["equalizer_preset"].toInt(); + Device *device = new Device(); + device->device = json["device"].toString(); + device->vendor = json["vendor"].toString(); + device->product = json["product"].toString(); + device->id_vendor = json["id_vendor"].toString(); + device->id_product = json["id_product"].toString(); + + device->lights = json["lights"].toInt(); + device->sidetone = json["sidetone"].toInt(); + device->voice_prompts = json["voice_prompts"].toInt(); + device->inactive_time = json["inactive_time"].toInt(); + device->equalizer_preset = json["equalizer_preset"].toInt(); QJsonArray curveArray = json["equalizer_curve"].toArray(); for (const auto &value : curveArray) { - device.equalizer_curve.append(value.toDouble()); + device->equalizer_curve.append(value.toDouble()); } - device.volume_limiter = json["volume_limiter"].toInt(); - device.rotate_to_mute = json["rotate_to_mute"].toInt(); - device.mic_mute_led_brightness = json["mic_mute_led_brightness"].toInt(); - device.mic_volume = json["mic_volume"].toInt(); - device.bt_when_powered_on = json["bt_when_powered_on"].toInt(); - device.bt_call_volume = json["bt_call_volume"].toInt(); + device->volume_limiter = json["volume_limiter"].toInt(); + device->rotate_to_mute = json["rotate_to_mute"].toInt(); + device->mic_mute_led_brightness = json["mic_mute_led_brightness"].toInt(); + device->mic_volume = json["mic_volume"].toInt(); + device->bt_when_powered_on = json["bt_when_powered_on"].toInt(); + device->bt_call_volume = json["bt_call_volume"].toInt(); return device; } +void updateDeviceFromSource(QList &devicesToUpdate, const Device *sourceDevice) +{ + bool found = false; + for (Device *toUpdateDevice : devicesToUpdate) { + if (*toUpdateDevice == sourceDevice) { + // Update the saved device with connected device's information + *toUpdateDevice = *sourceDevice; + found = true; + } + }; + if (!found) { + Device *toAppend = new Device(); + *toAppend = *sourceDevice; + devicesToUpdate.append(toAppend); + } +} + void updateDevicesFromSource(QList &devicesToUpdate, const QList &sourceDevices) { - for (Device *sourceDevice : sourceDevices) { - bool deviceFound = false; - for (Device *toUpdateDevice : devicesToUpdate) { - if (toUpdateDevice->id_vendor == sourceDevice->id_vendor - && toUpdateDevice->id_product == sourceDevice->id_product) { + for (Device *toUpdateDevice : devicesToUpdate) { + for (Device *sourceDevice : sourceDevices) { + if (*toUpdateDevice == sourceDevice) { // Update the connected device with saved device's information - toUpdateDevice->lights = sourceDevice->lights; - toUpdateDevice->sidetone = sourceDevice->sidetone; - toUpdateDevice->voice_prompts = sourceDevice->voice_prompts; - toUpdateDevice->inactive_time = sourceDevice->inactive_time; - - toUpdateDevice->equalizer_preset = sourceDevice->equalizer_preset; - toUpdateDevice->equalizer_curve = sourceDevice->equalizer_curve; - toUpdateDevice->volume_limiter = sourceDevice->volume_limiter; - - toUpdateDevice->rotate_to_mute = sourceDevice->rotate_to_mute; - toUpdateDevice->mic_mute_led_brightness = sourceDevice->mic_mute_led_brightness; - toUpdateDevice->mic_volume = sourceDevice->mic_volume; - - toUpdateDevice->bt_when_powered_on = sourceDevice->bt_when_powered_on; - toUpdateDevice->bt_call_volume = sourceDevice->bt_call_volume; - - deviceFound = true; - break; + *toUpdateDevice = *sourceDevice; } } - - if (!deviceFound) { - // If the device wasn't found in saved devices, add it - devicesToUpdate.append(sourceDevice); - } }; } @@ -224,6 +218,7 @@ void serializeDevices(const QList &devices, const QString &filePath) file.write(doc.toJson()); file.close(); qDebug() << "Devices Serialized" << jsonArray; + qDebug(); } } @@ -237,11 +232,22 @@ QList deserializeDevices(const QString &filePath) QJsonArray jsonArray = doc.array(); for (const auto &value : jsonArray) { - Device *device = new Device(Device::fromJson(value.toObject())); + Device *device = Device::fromJson(value.toObject()); devices.append(device); } file.close(); + qDebug() << "Devices Deserialized" << jsonArray; + qDebug(); } return devices; } + +void deleteDevices( + QList deviceList) +{ + for (Device *device : deviceList) { + delete device; + } + deviceList.clear(); +} diff --git a/src/DataTypes/device.h b/src/DataTypes/device.h index dc02931..a771c75 100644 --- a/src/DataTypes/device.h +++ b/src/DataTypes/device.h @@ -40,6 +40,9 @@ class Device Device(); Device(const QJsonObject &jsonObj, QString jsonData); + // Index + int index = -1; + // Status QString status; @@ -80,12 +83,15 @@ class Device bool updateDevice(const QList &new_device_list); QJsonObject toJson() const; - static Device fromJson(const QJsonObject &json); + static Device *fromJson(const QJsonObject &json); }; +void updateDeviceFromSource(QList &devicesToUpdate, const Device *sourceDevice); void updateDevicesFromSource(QList &devicesToUpdate, const QList &sourceDevices); void serializeDevices(const QList &devices, const QString &filePath); QList deserializeDevices(const QString &filePath); +void deleteDevices(QList deviceList); + #endif // DEVICE_H diff --git a/src/DataTypes/settings.cpp b/src/DataTypes/settings.cpp index 4bb769d..4eef14f 100644 --- a/src/DataTypes/settings.cpp +++ b/src/DataTypes/settings.cpp @@ -41,6 +41,7 @@ Settings loadSettingsFromFile(const QString &filePath) s.styleName = json["styleName"].toString(); } qDebug() << "Settings Loaded:\t" << json; + qDebug(); } return s; @@ -67,4 +68,5 @@ void saveSettingstoFile(const Settings &settings, const QString &filePath) file.write(doc.toJson()); file.close(); qDebug() << "Settings Saved:\t" << json; + qDebug(); } diff --git a/src/UI/mainwindow.cpp b/src/UI/mainwindow.cpp index a5e055a..3f5052f 100644 --- a/src/UI/mainwindow.cpp +++ b/src/UI/mainwindow.cpp @@ -22,6 +22,19 @@ MainWindow::MainWindow(QWidget *parent) , timerGUI(new QTimer(this)) , API(HeadsetControlAPI(HEADSETCONTROL_FILE_PATH)) { + qDebug() << "Headsetcontrol"; + qDebug() << "Name:" << API.getName(); + qDebug() << "Version:" << API.getVersion(); + qDebug() << "ApiVersion:" << API.getApiVersion(); + qDebug() << "HidApiVersion:" << API.getHidApiVersion(); + qDebug(); + qDebug() << "Headsetcontrol-GUI"; + qDebug() << "Version" << qApp->applicationVersion(); + qDebug() << "AppPath" << PROGRAM_CONFIG_PATH; + qDebug() << "ConfigPath" << PROGRAM_CONFIG_PATH; + qDebug() << "SettingsPath" << PROGRAM_SETTINGS_FILEPATH; + qDebug(); + QDir().mkpath(PROGRAM_CONFIG_PATH); createStartMenuShortcut(); settings = loadSettingsFromFile(PROGRAM_SETTINGS_FILEPATH); @@ -48,14 +61,6 @@ MainWindow::MainWindow(QWidget *parent) hide(); } -void MainWindow::deleteDevices(QList deviceList) -{ - for (Device *device : deviceList) { - delete device; - } - deviceList.clear(); -} - MainWindow::~MainWindow() { timerGUI->stop(); @@ -100,28 +105,28 @@ void MainWindow::bindEvents() // Other Section connect(ui->onlightButton, &QPushButton::clicked, &API, [=]() { - API.setLights(selectedDevice, true); + API.setLights(currentDevice, true); }); connect(ui->offlightButton, &QPushButton::clicked, &API, [=]() { - API.setLights(selectedDevice, false); + API.setLights(currentDevice, false); }); connect(ui->sidetoneSlider, &QSlider::sliderReleased, &API, [=]() { - API.setSidetone(selectedDevice, ui->sidetoneSlider->value()); + API.setSidetone(currentDevice, ui->sidetoneSlider->value()); }); connect(ui->voiceOnButton, &QPushButton::clicked, &API, [=]() { - API.setVoicePrompts(selectedDevice, true); + API.setVoicePrompts(currentDevice, true); }); connect(ui->voiceOffButton, &QPushButton::clicked, &API, [=]() { - API.setVoicePrompts(selectedDevice, true); + API.setVoicePrompts(currentDevice, true); }); connect(ui->notification0Button, &QPushButton::clicked, &API, [=]() { - API.playNotificationSound(selectedDevice, 0); + API.playNotificationSound(currentDevice, 0); }); connect(ui->notification1Button, &QPushButton::clicked, &API, [=]() { - API.playNotificationSound(selectedDevice, 1); + API.playNotificationSound(currentDevice, 1); }); connect(ui->inactivitySlider, &QSlider::sliderReleased, &API, [=]() { - API.setInactiveTime(selectedDevice, ui->inactivitySlider->value()); + API.setInactiveTime(currentDevice, ui->inactivitySlider->value()); }); // Equalizer Section @@ -129,43 +134,46 @@ void MainWindow::bindEvents() &QComboBox::activated, this, &MainWindow::equalizerPresetChanged); - connect(ui->applyEqualizer, &QPushButton::clicked, this, &MainWindow::applyEqualizer); + connect(ui->equalizerliveupdateCheckBox, &QCheckBox::checkStateChanged, this, [=](int state) { + equalizerLiveUpdate = (state == Qt::Checked); + }); + connect(ui->applyEqualizer, &QPushButton::clicked, this, [=]() { applyEqualizer(); }); connect(ui->volumelimiterOffButton, &QPushButton::clicked, &API, [=]() { - API.setVolumeLimiter(selectedDevice, false); + API.setVolumeLimiter(currentDevice, false); }); connect(ui->volumelimiterOnButton, &QPushButton::clicked, &API, [=]() { - API.setVolumeLimiter(selectedDevice, true); + API.setVolumeLimiter(currentDevice, true); }); // Microphone Section connect(ui->muteledbrightnessSlider, &QSlider::sliderReleased, &API, [=]() { - API.setMuteLedBrightness(selectedDevice, ui->muteledbrightnessSlider->value()); + API.setMuteLedBrightness(currentDevice, ui->muteledbrightnessSlider->value()); }); connect(ui->micvolumeSlider, &QSlider::sliderReleased, &API, [=]() { - API.setMicrophoneVolume(selectedDevice, ui->micvolumeSlider->value()); + API.setMicrophoneVolume(currentDevice, ui->micvolumeSlider->value()); }); connect(ui->rotateOn, &QPushButton::clicked, &API, [=]() { - API.setRotateToMute(selectedDevice, true); + API.setRotateToMute(currentDevice, true); }); connect(ui->rotateOff, &QPushButton::clicked, &API, [=]() { - API.setRotateToMute(selectedDevice, false); + API.setRotateToMute(currentDevice, false); }); // Bluetooth Section connect(ui->btwhenonOffButton, &QPushButton::clicked, &API, [=]() { - API.setBluetoothWhenPoweredOn(selectedDevice, false); + API.setBluetoothWhenPoweredOn(currentDevice, false); }); connect(ui->btwhenonOnButton, &QPushButton::clicked, &API, [=]() { - API.setBluetoothWhenPoweredOn(selectedDevice, true); + API.setBluetoothWhenPoweredOn(currentDevice, true); }); connect(ui->btbothRadioButton, &QRadioButton::clicked, &API, [=]() { - API.setBluetoothCallVolume(selectedDevice, 0); + API.setBluetoothCallVolume(currentDevice, 0); }); connect(ui->btpcdbRadioButton, &QRadioButton::clicked, &API, [=]() { - API.setBluetoothCallVolume(selectedDevice, 1); + API.setBluetoothCallVolume(currentDevice, 1); }); connect(ui->btonlyRadioButton, &QRadioButton::clicked, &API, [=]() { - API.setBluetoothCallVolume(selectedDevice, 2); + API.setBluetoothCallVolume(currentDevice, 2); }); } @@ -178,15 +186,15 @@ void MainWindow::changeTrayIconTo(QString iconName) void MainWindow::setupTrayIcon() { - changeTrayIconTo("headphones"); + trayIcon->setIcon(QIcon(":/icons/light/png/headphones.png")); trayIcon->setToolTip("HeadsetControl"); trayMenu->addAction(tr("Hide/Show"), this, &MainWindow::toggleWindow); ledOn = trayMenu->addAction(tr("Turn Lights On"), &API, [=]() { - API.setLights(selectedDevice, true); + API.setLights(currentDevice, true); }); ledOff = trayMenu->addAction(tr("Turn Lights Off"), &API, [=]() { - API.setLights(selectedDevice, false); + API.setLights(currentDevice, false); }); trayMenu->addAction(tr("Exit"), this, &QApplication::quit); @@ -237,8 +245,7 @@ void MainWindow::updateStyle() } else { setStyleSheet(defaultStyle); } - minimizeWindowSize(); - moveToBottomRight(); + rescaleAndMoveWindow(); } //Window Position and Size Section @@ -246,8 +253,7 @@ void MainWindow::toggleWindow() { if (isHidden()) { show(); - minimizeWindowSize(); - moveToBottomRight(); + rescaleAndMoveWindow(); if (firstShow) { checkForUpdates(firstShow); firstShow = false; @@ -270,6 +276,12 @@ void MainWindow::moveToBottomRight() move(finalPosition.width() - 5, finalPosition.height() - 35); } +void MainWindow::rescaleAndMoveWindow() +{ + minimizeWindowSize(); + moveToBottomRight(); +} + void MainWindow::resetGUI() { ledOn->setEnabled(false); @@ -298,7 +310,7 @@ void MainWindow::resetGUI() ui->equalizerpresetFrame->setHidden(true); ui->equalizerFrame->setHidden(true); ui->applyEqualizer->setEnabled(false); - clearEqualizerSliders(ui->equalizerLayout); + clearEqualizerSliders(); ui->rotatetomuteFrame->setHidden(true); ui->muteledbrightnessFrame->setHidden(true); @@ -317,40 +329,37 @@ void MainWindow::sendAppNotification(const QString &title, } //Devices Managing Section -void MainWindow::loadDevices() -{ - deleteDevices(connectedDevices); - QList saved = getSavedDevices(); - connectedDevices = API.getConnectedDevices(); - updateDevicesFromSource(connectedDevices, saved); - - deleteDevices(saved); -} - -void MainWindow::loadDevice(int deviceIndex) +void MainWindow::loadDevice() { resetGUI(); - if (deviceIndex < 0) { - selectedDevice = nullptr; + currentDevice = API.getDevice(); + if (currentDevice == nullptr) { + API.setSelectedDevice(0); + ui->missingheadsetcontrolFrame->setHidden(true); + rescaleAndMoveWindow(); return; } - selectedDevice = connectedDevices.value(deviceIndex); - QSet &capabilities = selectedDevice->capabilities; + QSet &capabilities = currentDevice->capabilities; ui->missingheadsetcontrolFrame->setHidden(true); ui->notSupportedFrame->setHidden(true); - qDebug() << selectedDevice->capabilities; + qDebug() << "Selected Device"; + qDebug() << "Index:\t" << QString::number(API.getSelectedDevice()); + qDebug() << "Device:\t" << currentDevice->device; + qDebug() << "Caps:\t" << currentDevice->capabilities; // Info section - ui->deviceinfovalueLabel->setText(selectedDevice->device + "
" + selectedDevice->vendor - + "
" + selectedDevice->product); + ui->deviceinfovalueLabel->setText(currentDevice->device + "
" + currentDevice->vendor + + "
" + currentDevice->product); ui->deviceinfoFrame->setHidden(false); if (capabilities.contains("CAP_BATTERY_STATUS")) { ui->batteryFrame->setHidden(false); setBatteryStatus(); + qDebug() << "Battery:\t" << currentDevice->battery.status + << QString::number(currentDevice->battery.level); } ui->tabWidget->show(); @@ -381,13 +390,14 @@ void MainWindow::loadDevice(int deviceIndex) ui->chatmixFrame->setHidden(false); ui->tabWidget->setTabEnabled(0, true); setChatmixStatus(); + qDebug() << "Chatmix:\t" << QString::number(currentDevice->chatmix); } // Equalizer Section - if (capabilities.contains("CAP_EQUALIZER_PRESET") && !selectedDevice->presets_list.empty()) { + if (capabilities.contains("CAP_EQUALIZER_PRESET") && !currentDevice->presets_list.empty()) { ui->equalizerpresetFrame->setHidden(false); ui->tabWidget->setTabEnabled(1, true); } - if (capabilities.contains("CAP_EQUALIZER") && selectedDevice->equalizer.bands_number > 0) { + if (capabilities.contains("CAP_EQUALIZER") && currentDevice->equalizer.bands_number > 0) { ui->equalizerFrame->setHidden(false); ui->tabWidget->setTabEnabled(1, true); } @@ -418,61 +428,60 @@ void MainWindow::loadDevice(int deviceIndex) ui->tabWidget->setTabEnabled(3, true); } + qDebug(); loadGUIValues(); - minimizeWindowSize(); - moveToBottomRight(); + rescaleAndMoveWindow(); } void MainWindow::loadGUIValues() { - if (selectedDevice->lights >= 0) { - ui->onlightButton->setChecked(selectedDevice->lights); - ui->offlightButton->setChecked(!selectedDevice->lights); + if (currentDevice->lights >= 0) { + ui->onlightButton->setChecked(currentDevice->lights); + ui->offlightButton->setChecked(!currentDevice->lights); } - if (selectedDevice->sidetone >= 0) { - ui->sidetoneSlider->setSliderPosition(selectedDevice->sidetone); + if (currentDevice->sidetone >= 0) { + ui->sidetoneSlider->setSliderPosition(currentDevice->sidetone); } - if (selectedDevice->voice_prompts >= 0) { - ui->voiceOnButton->setChecked(selectedDevice->voice_prompts); - ui->voiceOffButton->setChecked(!selectedDevice->voice_prompts); + if (currentDevice->voice_prompts >= 0) { + ui->voiceOnButton->setChecked(currentDevice->voice_prompts); + ui->voiceOffButton->setChecked(!currentDevice->voice_prompts); } - if (selectedDevice->inactive_time >= 0) { - ui->inactivitySlider->setSliderPosition(selectedDevice->inactive_time); + if (currentDevice->inactive_time >= 0) { + ui->inactivitySlider->setSliderPosition(currentDevice->inactive_time); } - QHBoxLayout *equalizerLayout = ui->equalizerLayout; - clearEqualizerSliders(equalizerLayout); - createEqualizerSliders(equalizerLayout); + clearEqualizerSliders(); + createEqualizerSliders(); ui->equalizerPresetcomboBox->clear(); - for (int i = 0; i < selectedDevice->presets_list.size(); ++i) { - ui->equalizerPresetcomboBox->addItem(selectedDevice->presets_list.at(i).name); + for (EqualizerPreset &preset : currentDevice->presets_list) { + ui->equalizerPresetcomboBox->addItem(preset.name); } ui->equalizerPresetcomboBox->setCurrentIndex(-1); - if (selectedDevice->equalizer_preset >= 0) { - ui->equalizerPresetcomboBox->setCurrentIndex(selectedDevice->equalizer_preset); - } else if (selectedDevice->equalizer_curve.length() == selectedDevice->equalizer.bands_number) { - setEqualizerSliders(selectedDevice->equalizer_curve); + if (currentDevice->equalizer_preset >= 0) { + ui->equalizerPresetcomboBox->setCurrentIndex(currentDevice->equalizer_preset); + } else if (currentDevice->equalizer_curve.length() == currentDevice->equalizer.bands_number) { + setEqualizerSliders(currentDevice->equalizer_curve); } - if (selectedDevice->volume_limiter >= 0) { - ui->volumelimiterOnButton->setChecked(selectedDevice->volume_limiter); - ui->volumelimiterOffButton->setChecked(!selectedDevice->volume_limiter); + if (currentDevice->volume_limiter >= 0) { + ui->volumelimiterOnButton->setChecked(currentDevice->volume_limiter); + ui->volumelimiterOffButton->setChecked(!currentDevice->volume_limiter); } - if (selectedDevice->rotate_to_mute >= 0) { - ui->rotateOn->setChecked(selectedDevice->rotate_to_mute); - ui->rotateOff->setChecked(!selectedDevice->rotate_to_mute); + if (currentDevice->rotate_to_mute >= 0) { + ui->rotateOn->setChecked(currentDevice->rotate_to_mute); + ui->rotateOff->setChecked(!currentDevice->rotate_to_mute); } - if (selectedDevice->mic_mute_led_brightness >= 0) { - ui->muteledbrightnessSlider->setSliderPosition(selectedDevice->mic_mute_led_brightness); + if (currentDevice->mic_mute_led_brightness >= 0) { + ui->muteledbrightnessSlider->setSliderPosition(currentDevice->mic_mute_led_brightness); } - if (selectedDevice->mic_volume >= 0) { - ui->micvolumeSlider->setSliderPosition(selectedDevice->mic_volume); + if (currentDevice->mic_volume >= 0) { + ui->micvolumeSlider->setSliderPosition(currentDevice->mic_volume); } - if (selectedDevice->bt_call_volume >= 0) { - switch (selectedDevice->bt_call_volume) { + if (currentDevice->bt_call_volume >= 0) { + switch (currentDevice->bt_call_volume) { case 0: ui->btbothRadioButton->setChecked(true); break; @@ -486,16 +495,16 @@ void MainWindow::loadGUIValues() break; } } - if (selectedDevice->bt_when_powered_on >= 0) { - ui->btwhenonOnButton->setChecked(selectedDevice->bt_when_powered_on); - ui->btwhenonOffButton->setChecked(!selectedDevice->bt_when_powered_on); + if (currentDevice->bt_when_powered_on >= 0) { + ui->btwhenonOnButton->setChecked(currentDevice->bt_when_powered_on); + ui->btwhenonOffButton->setChecked(!currentDevice->bt_when_powered_on); } } void MainWindow::saveDevicesSettings() { QList toSave = getSavedDevices(); - updateDevicesFromSource(toSave, connectedDevices); + updateDeviceFromSource(toSave, currentDevice); serializeDevices(toSave, DEVICES_SETTINGS_FILEPATH); @@ -507,14 +516,18 @@ QList MainWindow::getSavedDevices() return deserializeDevices(DEVICES_SETTINGS_FILEPATH); } -void MainWindow::updateDevice() +bool MainWindow::updateSelectedDevice() { QList newDl = API.getConnectedDevices(); - if (!selectedDevice->updateDevice(newDl)) { - selectedDevice = nullptr; + if (!currentDevice->updateDevice(newDl)) { + currentDevice = nullptr; + return false; } + setBatteryStatus(); + setChatmixStatus(); deleteDevices(newDl); + return true; } //Update GUI Section @@ -523,33 +536,25 @@ void MainWindow::updateGUI() if (!fileExists(HEADSETCONTROL_FILE_PATH)) { resetGUI(); ui->notSupportedFrame->setHidden(true); - selectedDevice = nullptr; + rescaleAndMoveWindow(); + currentDevice = nullptr; } else { - if (selectedDevice == nullptr) { - loadDevices(); - if (connectedDevices.isEmpty()) { - ui->missingheadsetcontrolFrame->setHidden(true); - } else { - loadDevice(); - } - } else { - updateDevice(); + if (currentDevice == nullptr || !updateSelectedDevice()) { + loadDevice(); } } - setBatteryStatus(); - setChatmixStatus(); } // Info Section Events void MainWindow::setBatteryStatus() { - if (selectedDevice == nullptr) { + if (currentDevice == nullptr) { changeTrayIconTo("headphones"); return; } - QString status = selectedDevice->battery.status; - int batteryLevel = selectedDevice->battery.level; + QString status = currentDevice->battery.status; + int batteryLevel = currentDevice->battery.level; QString level = QString::number(batteryLevel); if (batteryLevel >= 0) { @@ -572,7 +577,7 @@ void MainWindow::setBatteryStatus() tr("The battery has been charged to 100%"), QIcon("battery-level-full")); if (settings.audioNotification) { - API.playNotificationSound(selectedDevice, 1); + API.playNotificationSound(currentDevice, 1); } notified = true; } @@ -592,7 +597,7 @@ void MainWindow::setBatteryStatus() tr("The battery of your headset is running low"), QIcon("battery-low")); if (settings.audioNotification) { - API.playNotificationSound(selectedDevice, 0); + API.playNotificationSound(currentDevice, 0); } notified = true; } @@ -608,12 +613,12 @@ void MainWindow::setChatmixStatus() { QString chatmixStatus = tr("None"); - if (selectedDevice == nullptr) { + if (currentDevice == nullptr) { ui->chatmixvalueLabel->setText(chatmixStatus); return; } - int chatmix = selectedDevice->chatmix; + int chatmix = currentDevice->chatmix; QString chatmixValue = QString::number(chatmix); if (chatmix < 65) chatmixStatus = tr("Game"); @@ -628,100 +633,100 @@ void MainWindow::setChatmixStatus() void MainWindow::equalizerPresetChanged() { int index = ui->equalizerPresetcomboBox->currentIndex(); - setEqualizerSliders(selectedDevice->presets_list.value(index).values); - API.setEqualizerPreset(selectedDevice, index); + setEqualizerSliders(currentDevice->presets_list.value(index).values); + API.setEqualizerPreset(currentDevice, index); } -void MainWindow::applyEqualizer() +void MainWindow::applyEqualizer( + bool saveToFile) { ui->equalizerPresetcomboBox->setCurrentIndex(-1); QList values; - for (QSlider *slider : slidersEq) { - values.append(slider->value() * selectedDevice->equalizer.band_step); + for (QSlider *slider : equalizerSliders) { + values.append(slider->value() * currentDevice->equalizer.band_step); } - API.setEqualizer(selectedDevice, values); + API.setEqualizer(currentDevice, values, saveToFile); } //Equalizer Slidesrs Section -void MainWindow::createEqualizerSliders(QHBoxLayout *layout) +void MainWindow::createEqualizerSliders() { - if (selectedDevice->equalizer.bands_number > 0) { - int i; - for (i = 0; i < selectedDevice->equalizer.bands_number; ++i) { - QLabel *l = new QLabel(QString::number(i)); - l->setAlignment(Qt::AlignHCenter); - + QHBoxLayout *layout = ui->equalizerLayout; + int &bands_number = currentDevice->equalizer.bands_number; + if (bands_number > 0) { + for (int i = 0; i < bands_number; ++i) { QSlider *s = new QSlider(Qt::Vertical); - s->setMaximum(selectedDevice->equalizer.band_max / selectedDevice->equalizer.band_step); - s->setMinimum(selectedDevice->equalizer.band_min / selectedDevice->equalizer.band_step); + s->setMaximum(currentDevice->equalizer.band_max / currentDevice->equalizer.band_step); + s->setMinimum(currentDevice->equalizer.band_min / currentDevice->equalizer.band_step); s->setSingleStep(1); - s->setTickInterval(1 / selectedDevice->equalizer.band_step); - s->setTickPosition(QSlider::TicksBothSides); - if (selectedDevice->equalizer_curve.size() == selectedDevice->equalizer.bands_number) { - s->setValue(selectedDevice->equalizer_curve.value(i)); + s->setTickInterval(1 / currentDevice->equalizer.band_step); + if (currentDevice->equalizer_curve.size() == bands_number) { + s->setValue(currentDevice->equalizer_curve.value(i)); } else { - s->setValue(selectedDevice->equalizer.band_baseline); + s->setValue(currentDevice->equalizer.band_baseline); } - QVBoxLayout *lb = new QVBoxLayout(); - lb->addWidget(l); - lb->addWidget(s); - - slidersEq.append(s); - layout->addLayout(lb); + equalizerSliders.append(s); + layout->addWidget(s); + connect(s, &QAbstractSlider::sliderReleased, this, [=]() { + if (equalizerLiveUpdate) + applyEqualizer(false); + }); } ui->applyEqualizer->setEnabled(true); } } -void MainWindow::setEqualizerSliders(double value) +void MainWindow::clearEqualizerSliders() { - for (QSlider *slider : slidersEq) { - slider->setValue(value / selectedDevice->equalizer.band_step); + QHBoxLayout *layout = ui->equalizerLayout; + while (QLayoutItem *item = layout->takeAt(0)) { + if (QWidget *widget = item->widget()) { + widget->disconnect(); + widget->deleteLater(); + } + delete item; + } + equalizerSliders.clear(); +} + +void MainWindow::setEqualizerSliders( + double value) +{ + for (QSlider *slider : equalizerSliders) { + slider->setValue(value / currentDevice->equalizer.band_step); } } void MainWindow::setEqualizerSliders(QList values) { int i = 0; - if (values.length() == selectedDevice->equalizer.bands_number) { - for (QSlider *slider : slidersEq) { - slider->setValue((int) (values[i++] / selectedDevice->equalizer.band_step)); + if (values.length() == currentDevice->equalizer.bands_number) { + for (QSlider *slider : equalizerSliders) { + slider->setValue((int) (values[i++] / currentDevice->equalizer.band_step)); } } else { + setEqualizerSliders(0); qDebug() << "ERROR: Bad Equalizer Preset"; } } -void MainWindow::clearEqualizerSliders(QLayout *layout) -{ - QLayoutItem *item; - while (!layout->isEmpty()) { - item = layout->takeAt(0); - delete item->widget(); - delete item; - slidersEq.removeFirst(); - } -} - // Tool Bar Events void MainWindow::selectDevice() { - this->loadDevices(); + QList connectedDevices = API.getConnectedDevices(); LoaddeviceWindow *loadDevWindow = new LoaddeviceWindow(connectedDevices, this); + timerGUI->stop(); if (loadDevWindow->exec() == QDialog::Accepted) { int index = loadDevWindow->getDeviceIndex(); if (index >= 0 && index < connectedDevices.length()) { - if (index == 0) { - ui->tabWidget->setDisabled(false); - } else { - ui->tabWidget->setDisabled(true); - } - loadDevice(index); + API.setSelectedDevice(index); + loadDevice(); } } delete (loadDevWindow); + timerGUI->start(); } void MainWindow::editProgramSetting() @@ -740,14 +745,16 @@ void MainWindow::checkForUpdates(bool firstStart) { bool needsUpdate = false; - const QVersionNumber &local_hc = API.getVersion(); - const QVersionNumber local_gui = QVersionNumber::fromString(qApp->applicationVersion()); + const QString &hcVersion = API.getVersion(); + const QString &guiVersion = qApp->applicationVersion(); + const QVersionNumber &local_hc = QVersionNumber::fromString(hcVersion); + const QVersionNumber local_gui = QVersionNumber::fromString(guiVersion); QString v1 = getLatestGitHubReleaseVersion("Sapd", "HeadsetControl"); QString v2 = getLatestGitHubReleaseVersion("LeoKlaus", "HeadsetControl-GUI"); QVersionNumber remote_hc = QVersionNumber::fromString(v1); QVersionNumber remote_gui = QVersionNumber::fromString(v2); - QString s1 = tr("up-to date v") + local_hc.toString(); - QString s2 = tr("up-to date v") + local_gui.toString(); + QString s1 = tr("up-to date v") + hcVersion; + QString s2 = tr("up-to date v") + guiVersion; if (!(v1 == "") && remote_hc > local_hc) { s1 = tr("Newer version") + " -> connectedDevices; + Device *currentDevice = nullptr; - QList slidersEq; - - void deleteDevices(QList deviceList); + QList equalizerSliders; + bool equalizerLiveUpdate = false; void bindEvents(); @@ -78,15 +76,15 @@ class MainWindow : public QMainWindow //Window Position and Size Section void minimizeWindowSize(); void moveToBottomRight(); + void rescaleAndMoveWindow(); void toggleWindow(); //Utility void sendAppNotification(const QString &title, const QString &description, const QIcon &icon); //Devices Managing Section - void updateDevice(); - void loadDevice(int deviceIndex = 0); - void loadDevices(); + bool updateSelectedDevice(); + void loadDevice(); void loadGUIValues(); QList getSavedDevices(); @@ -95,10 +93,10 @@ class MainWindow : public QMainWindow void setChatmixStatus(); //Equalizer Slidesrs Section - void createEqualizerSliders(QHBoxLayout *layout); + void createEqualizerSliders(); + void clearEqualizerSliders(); void setEqualizerSliders(double value); void setEqualizerSliders(QList values); - void clearEqualizerSliders(QLayout *layout); private slots: void changeEvent(QEvent *e); @@ -114,7 +112,7 @@ private slots: // Equalizer Section Events void equalizerPresetChanged(); - void applyEqualizer(); + void applyEqualizer(bool saveToFile = true); // Tool Bar Events void selectDevice(); diff --git a/src/UI/mainwindow.ui b/src/UI/mainwindow.ui index c9839e1..3bcd624 100644 --- a/src/UI/mainwindow.ui +++ b/src/UI/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 488 - 792 + 823 @@ -80,7 +80,7 @@ Qt::AlignmentFlag::AlignCenter - false + true Qt::TextInteractionFlag::TextBrowserInteraction @@ -151,6 +151,9 @@ Qt::AlignmentFlag::AlignCenter + + true + @@ -191,6 +194,12 @@ 0 + + + 120 + 16777215 + + Segoe UI @@ -204,6 +213,9 @@ Vendor: Model: + + true + @@ -323,6 +335,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -484,6 +499,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -571,6 +589,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -688,6 +709,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -765,6 +789,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -844,6 +874,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -858,6 +894,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -949,6 +988,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -960,6 +1005,9 @@ Model: Chatmix: + + true + @@ -1056,6 +1104,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1067,6 +1121,9 @@ Model: Equalizer preset: + + true + @@ -1112,32 +1169,99 @@ Model: QFrame::Shadow::Raised - - - - - - 120 - 0 - - - - - Segoe UI - 11 - false - true - - - - Equalizer: - - + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + + Segoe UI + 11 + false + true + + + + Equalizer: + + + true + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + LiveUpdate + + + + + + + + + + + Lows + + + + + + + Mids + + + Qt::AlignmentFlag::AlignCenter + + + + + + + Highs + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + false + + + + - + - + @@ -1153,7 +1277,7 @@ Model: - 120 + 16777215 16777215 @@ -1194,6 +1318,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1205,6 +1335,9 @@ Model: Volume Limiter: + + true + @@ -1283,6 +1416,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1297,6 +1436,9 @@ Model: Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + true + @@ -1358,6 +1500,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1469,6 +1617,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1603,6 +1757,12 @@ Model: 0 + + + 120 + 16777215 + + Segoe UI @@ -1623,6 +1783,12 @@ Model: + + + 0 + 0 + + Bluetooth Off @@ -1643,6 +1809,12 @@ Model: + + + 0 + 0 + + Bluetooth On @@ -1705,31 +1877,33 @@ Model: - + - - - - - BT and PC - - - - - - - PC -12dB - - - - - - - BT only - - - - + + + BT and PC + + + + + + + PC -12dB + + + + + + + + 0 + 0 + + + + BT only + + diff --git a/src/Utils/headsetcontrolapi.cpp b/src/Utils/headsetcontrolapi.cpp index 6ad7c6f..de3d099 100644 --- a/src/Utils/headsetcontrolapi.cpp +++ b/src/Utils/headsetcontrolapi.cpp @@ -7,7 +7,20 @@ HeadsetControlAPI::HeadsetControlAPI(QString headsetcontrolFilePath) { this->headsetcontrolFilePath = headsetcontrolFilePath; - sendCommand(QStringList()); + parseOutput(sendCommand(QStringList())); +} + +int HeadsetControlAPI::getSelectedDevice() +{ + return selectedDevice; +} + +void HeadsetControlAPI::setSelectedDevice(const int &deviceIndex) +{ + if (deviceIndex >= 0) + selectedDevice = deviceIndex; + else + selectedDevice = 0; } QString HeadsetControlAPI::getName() @@ -15,45 +28,52 @@ QString HeadsetControlAPI::getName() return name; } -QVersionNumber HeadsetControlAPI::getVersion() +QString HeadsetControlAPI::getVersion() { return version; } -QVersionNumber HeadsetControlAPI::getApiVersion() +QString HeadsetControlAPI::getApiVersion() { return api_version; } -QVersionNumber HeadsetControlAPI::getHidApiVersion() +QString HeadsetControlAPI::getHidApiVersion() { return hidapi_version; } +Device *HeadsetControlAPI::getDevice() +{ + QList connectedList = getConnectedDevices(); + Device *connectedDevice = connectedList.value(selectedDevice); + Device *device = nullptr; + if (connectedDevice != nullptr) { + device = new Device(); + *device = *connectedDevice; + } + deleteDevices(connectedList); + + return device; +} + QList HeadsetControlAPI::getConnectedDevices() { - QStringList args = QStringList() << QString("--output") << QString("JSON"); + QStringList args = QStringList(); QString output = sendCommand(args); - QJsonDocument jsonDoc = QJsonDocument::fromJson(output.toUtf8()); - QJsonObject jsonInfo = jsonDoc.object(); - - name = jsonInfo["name"].toString(); - version = QVersionNumber::fromString(jsonInfo["version"].toString()); - api_version = QVersionNumber::fromString(jsonInfo["api_version"].toString()); - hidapi_version = QVersionNumber::fromString(jsonInfo["hidapi_version"].toString()); + QJsonObject jsonInfo = parseOutput(output); int device_number = jsonInfo["device_count"].toInt(); qDebug() << "Found" << device_number << "devices:"; QList devices; QJsonArray jsonDevices = jsonInfo["devices"].toArray(); - if (!jsonDoc.isNull()) { - for (int i = 0; i < device_number; ++i) { - Device *device = new Device(jsonDevices[i].toObject(), output); - devices.append(device); - qDebug() << "\t" << device->device; - } + for (int i = 0; i < device_number; ++i) { + Device *device = new Device(jsonDevices[i].toObject(), output); + devices.append(device); + qDebug() << "[" + QString::number(i) + "] " + device->device; } + qDebug(); return devices; } @@ -62,28 +82,44 @@ QList HeadsetControlAPI::getConnectedDevices() QString HeadsetControlAPI::sendCommand(const QStringList &args_list) { QProcess *proc = new QProcess(); - QStringList args = QStringList() << QString("--output") << QString("JSON"); + QStringList args = QStringList(); + args << QString("--output") << QString("JSON"); + args << QString("--device") << QString::number(selectedDevice); //args << QString("--test-device"); //Uncomment this to enable all "modules" args << args_list; proc->start(headsetcontrolFilePath, args); proc->waitForFinished(); QString output = proc->readAllStandardOutput(); - qDebug() << "Command: \t" << headsetcontrolFilePath; - qDebug() << "\tArgs: \theadsetcontrol " << args; - // qDebug() << output; - qDebug() << "Error: \t" << proc->error(); + qDebug() << "Command:\t" << headsetcontrolFilePath; + qDebug() << "Args:\t" << args; + qDebug() << "Error:\t" << proc->exitStatus(); + //qDebug() << "Output:" << output; + qDebug(); delete (proc); return output; } -Action HeadsetControlAPI::sendAction(const QStringList &args_list) +QJsonObject HeadsetControlAPI::parseOutput( + const QString &output) { - QString output = sendCommand(args_list); QJsonDocument jsonDoc = QJsonDocument::fromJson(output.toUtf8()); QJsonObject jsonInfo = jsonDoc.object(); + + name = jsonInfo["name"].toString(); + version = jsonInfo["version"].toString(); + api_version = jsonInfo["api_version"].toString(); + hidapi_version = jsonInfo["hidapi_version"].toString(); + + return jsonInfo; +} + +Action HeadsetControlAPI::sendAction(const QStringList &args_list) +{ + QString output = sendCommand(args_list); + QJsonObject jsonInfo = parseOutput(output); QJsonArray actions = jsonInfo["actions"].toArray(); Action action; if (!actions.isEmpty()) { @@ -102,72 +138,80 @@ Action HeadsetControlAPI::sendAction(const QStringList &args_list) if (!action.success) { qDebug() << "Error:\t" << action.error_message; } + qDebug(); } return action; } -void HeadsetControlAPI::setSidetone(Device *device, int level) +void HeadsetControlAPI::setSidetone( + Device *device, int level, bool emitSignal) { QStringList args = QStringList() << QString("--sidetone") << QString::number(level); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->sidetone = level; emit actionSuccesful(); } } -void HeadsetControlAPI::setLights(Device *device, bool enabled) +void HeadsetControlAPI::setLights( + Device *device, bool enabled, bool emitSignal) { QStringList args = QStringList() << QString("--light") << QString::number(enabled); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->lights = enabled; emit actionSuccesful(); } } -void HeadsetControlAPI::setVoicePrompts(Device *device, bool enabled) +void HeadsetControlAPI::setVoicePrompts( + Device *device, bool enabled, bool emitSignal) { QStringList args = QStringList() << QString("--voice-prompt") << QString::number(enabled); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->voice_prompts = enabled; emit actionSuccesful(); } } -void HeadsetControlAPI::setInactiveTime(Device *device, int time) +void HeadsetControlAPI::setInactiveTime( + Device *device, int time, bool emitSignal) { QStringList args = QStringList() << QString("--inactive-time") << QString::number(time); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->inactive_time = time; emit actionSuccesful(); } } -void HeadsetControlAPI::playNotificationSound(Device *device, int id) +void HeadsetControlAPI::playNotificationSound( + Device *device, int id, bool emitSignal) { QStringList args = QStringList() << QString("--notificate") << QString::number(id); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->notification_sound = id; emit actionSuccesful(); } } -void HeadsetControlAPI::setVolumeLimiter(Device *device, bool enabled) +void HeadsetControlAPI::setVolumeLimiter( + Device *device, bool enabled, bool emitSignal) { QStringList args = QStringList() << QString("--volume-limiter") << QString::number(enabled); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->volume_limiter = enabled; emit actionSuccesful(); } } -void HeadsetControlAPI::setEqualizer(Device *device, QList equalizerValues) +void HeadsetControlAPI::setEqualizer( + Device *device, QList equalizerValues, bool emitSignal) { QString equalizer = ""; for (double value : equalizerValues) { @@ -176,69 +220,75 @@ void HeadsetControlAPI::setEqualizer(Device *device, QList equalizerValu equalizer.removeLast(); QStringList args = QStringList() << QString("--equalizer") << equalizer; Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->equalizer_curve = equalizerValues; device->equalizer_preset = -1; emit actionSuccesful(); } } -void HeadsetControlAPI::setEqualizerPreset(Device *device, int number) +void HeadsetControlAPI::setEqualizerPreset( + Device *device, int number, bool emitSignal) { QStringList args = QStringList() << QString("--equalizer-preset") << QString::number(number); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->equalizer_preset = number; emit actionSuccesful(); } } -void HeadsetControlAPI::setRotateToMute(Device *device, bool enabled) +void HeadsetControlAPI::setRotateToMute( + Device *device, bool enabled, bool emitSignal) { QStringList args = QStringList() << QString("--rotate-to-mute") << QString::number(enabled); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->rotate_to_mute = enabled; emit actionSuccesful(); } } -void HeadsetControlAPI::setMuteLedBrightness(Device *device, int brightness) +void HeadsetControlAPI::setMuteLedBrightness( + Device *device, int brightness, bool emitSignal) { QStringList args = QStringList() << QString("--microphone-mute-led-brightness") << QString::number(brightness); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->mic_mute_led_brightness = brightness; emit actionSuccesful(); } } -void HeadsetControlAPI::setMicrophoneVolume(Device *device, int volume) +void HeadsetControlAPI::setMicrophoneVolume( + Device *device, int volume, bool emitSignal) { QStringList args = QStringList() << QString("--microphone-volume") << QString::number(volume); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->mic_volume = volume; emit actionSuccesful(); } } -void HeadsetControlAPI::setBluetoothWhenPoweredOn(Device *device, bool enabled) +void HeadsetControlAPI::setBluetoothWhenPoweredOn( + Device *device, bool enabled, bool emitSignal) { QStringList args = QStringList() << QString("--bt-when-powered-on") << QString::number(enabled); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->bt_when_powered_on = enabled; emit actionSuccesful(); } } -void HeadsetControlAPI::setBluetoothCallVolume(Device *device, int option) +void HeadsetControlAPI::setBluetoothCallVolume( + Device *device, int option, bool emitSignal) { QStringList args = QStringList() << QString("--bt-call-volume") << QString::number(option); Action a = sendAction(args); - if (a.success) { + if (emitSignal && a.success) { device->bt_call_volume = option; emit actionSuccesful(); } diff --git a/src/Utils/headsetcontrolapi.h b/src/Utils/headsetcontrolapi.h index e7a9b55..848c562 100644 --- a/src/Utils/headsetcontrolapi.h +++ b/src/Utils/headsetcontrolapi.h @@ -25,40 +25,46 @@ class HeadsetControlAPI : public QObject HeadsetControlAPI(QString headsetcontrolFilePath); QString getName(); - QVersionNumber getVersion(); - QVersionNumber getApiVersion(); - QVersionNumber getHidApiVersion(); + QString getVersion(); + QString getApiVersion(); + QString getHidApiVersion(); + int getSelectedDevice(); + void setSelectedDevice(const int &deviceIndex); + + Device *getDevice(); QList getConnectedDevices(); private: QString headsetcontrolFilePath; QFile headsetcontrol; + int selectedDevice = 0; QString name; - QVersionNumber version; - QVersionNumber api_version; - QVersionNumber hidapi_version; + QString version; + QString api_version; + QString hidapi_version; QString sendCommand(const QStringList &args_list); + QJsonObject parseOutput(const QString &output); Action sendAction(const QStringList &args_list); public slots: - void setSidetone(Device *device, int level); - void setLights(Device *device, bool enabled); - void setVoicePrompts(Device *device, bool enabled); - void setInactiveTime(Device *device, int time); - void playNotificationSound(Device *device, int id); - void setVolumeLimiter(Device *device, bool enabled); - void setEqualizer(Device *device, QList equalizerValues); - void setEqualizerPreset(Device *device, int number); - - void setRotateToMute(Device *device, bool enabled); - void setMuteLedBrightness(Device *device, int brightness); - void setMicrophoneVolume(Device *device, int volume); - - void setBluetoothWhenPoweredOn(Device *device, bool enabled); - void setBluetoothCallVolume(Device *device, int option); + void setSidetone(Device *device, int level, bool emitSignal = true); + void setLights(Device *device, bool enabled, bool emitSignal = true); + void setVoicePrompts(Device *device, bool enabled, bool emitSignal = true); + void setInactiveTime(Device *device, int time, bool emitSignal = true); + void playNotificationSound(Device *device, int id, bool emitSignal = true); + void setVolumeLimiter(Device *device, bool enabled, bool emitSignal = true); + void setEqualizer(Device *device, QList equalizerValues, bool emitSignal = true); + void setEqualizerPreset(Device *device, int number, bool emitSignal = true); + + void setRotateToMute(Device *device, bool enabled, bool emitSignal = true); + void setMuteLedBrightness(Device *device, int brightness, bool emitSignal = true); + void setMicrophoneVolume(Device *device, int volume, bool emitSignal = true); + + void setBluetoothWhenPoweredOn(Device *device, bool enabled, bool emitSignal = true); + void setBluetoothCallVolume(Device *device, int option, bool emitSignal = true); signals: void actionSuccesful();