diff --git a/.gitignore b/.gitignore index bf96c2c..bb665dd 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,9 @@ *.out *.app +#Translations +*.qm + # Folders build/* diff --git a/HeadsetControl-GUI.pro b/HeadsetControl-GUI.pro index 5f781aa..5b3f98a 100644 --- a/HeadsetControl-GUI.pro +++ b/HeadsetControl-GUI.pro @@ -36,18 +36,21 @@ FORMS += \ src/UI/settingswindow.ui TRANSLATIONS += \ - src/Resources/tr/HeadsetControl_GUI_en_US.ts \ - src/Resources/tr/HeadsetControl_GUI_it_IT.ts + src/Resources/tr/HeadsetControl_GUI_en.ts \ + src/Resources/tr/HeadsetControl_GUI_it.ts RESOURCES += \ - src/Resources/icons.qrc \ - src/Resources/translations.qrc + src/Resources/icons.qrc RC_FILE = src/Resources/appicon.rc DISTFILES += \ .gitignore +CONFIG += lrelease +QM_FILES_RESOURCE_PREFIX=/translations/tr +CONFIG += embed_translations + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin diff --git a/src/Resources/icons.qrc b/src/Resources/icons.qrc index 1151afb..8094897 100644 --- a/src/Resources/icons.qrc +++ b/src/Resources/icons.qrc @@ -1,14 +1,14 @@ - icons/battery-charging.png - icons/battery-level-full.png - icons/battery-low.png - icons/battery-medium.png - icons/headphones.png - icons/battery-charging-inv.png - icons/battery-level-full-inv.png - icons/battery-low-inv.png - icons/battery-medium-inv.png - icons/headphones-inv.png + icons/battery-charging-dark.png + icons/battery-level-full-dark.png + icons/battery-low-dark.png + icons/battery-medium-dark.png + icons/headphones-dark.png + icons/battery-charging-light.png + icons/battery-level-full-light.png + icons/battery-low-light.png + icons/battery-medium-light.png + icons/headphones-light.png diff --git a/src/Resources/icons/battery-charging.png b/src/Resources/icons/battery-charging-dark.png similarity index 100% rename from src/Resources/icons/battery-charging.png rename to src/Resources/icons/battery-charging-dark.png diff --git a/src/Resources/icons/battery-charging-inv.png b/src/Resources/icons/battery-charging-light.png similarity index 100% rename from src/Resources/icons/battery-charging-inv.png rename to src/Resources/icons/battery-charging-light.png diff --git a/src/Resources/icons/battery-level-full.png b/src/Resources/icons/battery-level-full-dark.png similarity index 100% rename from src/Resources/icons/battery-level-full.png rename to src/Resources/icons/battery-level-full-dark.png diff --git a/src/Resources/icons/battery-level-full-inv.png b/src/Resources/icons/battery-level-full-light.png similarity index 100% rename from src/Resources/icons/battery-level-full-inv.png rename to src/Resources/icons/battery-level-full-light.png diff --git a/src/Resources/icons/battery-low.png b/src/Resources/icons/battery-low-dark.png similarity index 100% rename from src/Resources/icons/battery-low.png rename to src/Resources/icons/battery-low-dark.png diff --git a/src/Resources/icons/battery-low-inv.png b/src/Resources/icons/battery-low-light.png similarity index 100% rename from src/Resources/icons/battery-low-inv.png rename to src/Resources/icons/battery-low-light.png diff --git a/src/Resources/icons/battery-medium.png b/src/Resources/icons/battery-medium-dark.png similarity index 100% rename from src/Resources/icons/battery-medium.png rename to src/Resources/icons/battery-medium-dark.png diff --git a/src/Resources/icons/battery-medium-inv.png b/src/Resources/icons/battery-medium-light.png similarity index 100% rename from src/Resources/icons/battery-medium-inv.png rename to src/Resources/icons/battery-medium-light.png diff --git a/src/Resources/icons/headphones.png b/src/Resources/icons/headphones-dark.png similarity index 100% rename from src/Resources/icons/headphones.png rename to src/Resources/icons/headphones-dark.png diff --git a/src/Resources/icons/headphones-inv.png b/src/Resources/icons/headphones-light.png similarity index 100% rename from src/Resources/icons/headphones-inv.png rename to src/Resources/icons/headphones-light.png diff --git a/src/Resources/tr/HeadsetControl_GUI_en_US.ts b/src/Resources/tr/HeadsetControl_GUI_en.ts similarity index 69% rename from src/Resources/tr/HeadsetControl_GUI_en_US.ts rename to src/Resources/tr/HeadsetControl_GUI_en.ts index 327e35f..8a0d69a 100644 --- a/src/Resources/tr/HeadsetControl_GUI_en_US.ts +++ b/src/Resources/tr/HeadsetControl_GUI_en.ts @@ -9,396 +9,396 @@ - + + Missing headsetcontrol!<br/>Download <a href="https://github.com/Sapd/HeadsetControl/releases/latest">headsetcontrol</a> in the program folder. + + + + + Open Program Folder + + + + HeadsetControl couldn't find any compatible or working headsets. :( - + Device: Vendor: Model: - + No info of the device - + Battery: - + No compatible Device found! - + Other - + Lights: - + RGB OFF - + RGB ON - + Sidetone Level: - + Quiet (Off) - - + + Loud - + Voice Prompts: - + Voice Off - + Voice On - + Notification Sound: - + Test 0 - + Test 1 - + Inactivity Timer: - + 0 Minute (Off) - + 90 Minutes - + Chatmix: - + None - + Equalizer - + Equalizer preset: - + Equalizer: - + Apply Equalizer - + Volume Limiter: - + Limiter Off - + Limiter On - + Microphone - + Rotate to mute: - + Off - + On - + Muted led brightness: - + Low (Off) - + High - + Microphone volume: - + Quiet - + Bluetooth - + Bluetooth when powered on: - + Bluetooth Off - + Bluetooth On - + Bluetooth call volume: - + BT and PC - + PC -12dB - + BT only - + File - + Help - + Check Updates - + About - - + + Credits - + Load Device - + Settings - + Hide/Show - + Turn Lights On - + Turn Lights Off - + Exit - - Missing headsetcontrol - - - - - Missing headsetcontrol<br/>Download <a href='https://github.com/Sapd/HeadsetControl/releases/latest'>headsetcontrol</a> in the opened folder. - - - - + Headset Off - + HeadsetControl Headset Off - + % - Charging - + HeadsetControl Battery Charging - + % - Descharging - + HeadsetControl Battery: - + Battery Alert! - + The battery of your headset is running low - + No battery info - + Game - + Chat - + Check for updates - - + + up-to date v - + Newer version - + About this program - + You can find HeadsetControl-GUI source code on <a href='https://github.com/LeoKlaus/HeadsetControl-GUI'>GitHub</a>.<br/>Made by:<br/> - <a href='https://github.com/LeoKlaus'>LeoKlaus</a><br/> - <a href='https://github.com/nicola02nb'>nicola02nb</a><br/>Version: - + Big shout-out to:<br/> - <a href='https://github.com/Sapd'>Sapd</a> for <a href='https://github.com/Sapd/HeadsetControl'>HeadsetCoontrol diff --git a/src/Resources/tr/HeadsetControl_GUI_en_US.qm b/src/Resources/tr/HeadsetControl_GUI_en_US.qm deleted file mode 100644 index 022d218..0000000 Binary files a/src/Resources/tr/HeadsetControl_GUI_en_US.qm and /dev/null differ diff --git a/src/Resources/tr/HeadsetControl_GUI_it_IT.ts b/src/Resources/tr/HeadsetControl_GUI_it.ts similarity index 71% rename from src/Resources/tr/HeadsetControl_GUI_it_IT.ts rename to src/Resources/tr/HeadsetControl_GUI_it.ts index f752d8e..a896587 100644 --- a/src/Resources/tr/HeadsetControl_GUI_it_IT.ts +++ b/src/Resources/tr/HeadsetControl_GUI_it.ts @@ -9,12 +9,22 @@ HeadsetControl-GUI - + + Missing headsetcontrol!<br/>Download <a href="https://github.com/Sapd/HeadsetControl/releases/latest">headsetcontrol</a> in the program folder. + Manca headsetcontrol!<br/>Scarica <a href="https://github.com/Sapd/HeadsetControl/releases/latest">headsetcontrol</a> nella cartella del programma. + + + + Open Program Folder + Apri Cartella del Programma + + + HeadsetControl couldn't find any compatible or working headsets. :( HeadsetControl non è riuscito a trovare delle cuffie funizionanti o compatibili. :( - + Device: Vendor: Model: @@ -23,387 +33,377 @@ Distributore: Modello: - + No info of the device Nessuna informazione sul dipositivo - + Battery: Batteria: - + No compatible Device found! Nessun dispositivo compatibile è stato trovato! - + Other Altro - + Lights: Luci: - + RGB OFF RGB OFF - + RGB ON RGB ON - + Sidetone Level: Tono Laterale: - + Quiet (Off) Silenzioso (Spento) - - + + Loud Forte - + Voice Prompts: Istruzioni Vocali: - + Voice Off Voce Accesa - + Voice On Voce Spenta - + Notification Sound: Suono di Notifica: - + Test 0 Prova 0 - + Test 1 Prova 1 - + Inactivity Timer: Tempo di Inattività: - + 0 Minute (Off) 0 Minuti (Spento) - + 90 Minutes 90 Minuti - + Chatmix: Chatmix: - + None Nessun valore - + Equalizer Equalizzatore - + Equalizer preset: Preset Equalizzatore: - + Equalizer: Equalizzatore: - + Apply Equalizer Applica Equalizzatore - + Volume Limiter: Limitatore Volume: - + Limiter Off Limitatore Spento - + Limiter On Limitatore Acceso - + Microphone Microfono - + Rotate to mute: Ruota per mutare: - + Off Spento - + On Acceso - + Muted led brightness: Luminosità microfono mutato: - + Low (Off) Basso (Spento) - + High Alto - + Microphone volume: Volume microfono: - + Quiet Basso - + Bluetooth Bluetooth - + Bluetooth when powered on: Bluetooth quando accese: - + Bluetooth Off Bluetooth Spento - + Bluetooth On Bluetooth Acceso - + Bluetooth call volume: Bluetoot volume chiamata: - + BT and PC BT e PC - + PC -12dB PC -12dB - + BT only Solo BT - + File File - + Help Aiuto - + Check Updates Controlla Aggiornamenti - + About About - - + + Credits Crediti - + Load Device Carica Dispositivo - + Settings Impostazioni - + Hide/Show Nascondi/Mostra - + Turn Lights On Accendi le Luci - + Turn Lights Off Spegni le Luci - + Exit Esci - - Missing headsetcontrol - Manca headsetcontrol.exe - - - - Missing headsetcontrol<br/>Download <a href='https://github.com/Sapd/HeadsetControl/releases/latest'>headsetcontrol</a> in the opened folder. - Manca headsetcontrol<br/>Scarica <a href='https://github.com/Sapd/HeadsetControl/releases/latest'>headsetcontrol</a> nella cartella aperta. - - - + Headset Off Cuffie Spente - + HeadsetControl Headset Off HeadsetControl Cuffie Spente - + % - Charging % - In Carica - + HeadsetControl Battery Charging HeadsetControl Batteria in Carica - + % - Descharging % - Batteria in scarica - + HeadsetControl Battery: HeadsetControl Batteria: - + Battery Alert! Attenzione Batteria! - + The battery of your headset is running low La batteria delle tue cuffie è scarica - + No battery info No informazioni sulla batteria - + Game Gioco - + Chat Chat - + Check for updates Controlla Aggirnamenti - - + + up-to date v aggiornato v - + Newer version Nuova versione - + About this program - + You can find HeadsetControl-GUI source code on <a href='https://github.com/LeoKlaus/HeadsetControl-GUI'>GitHub</a>.<br/>Made by:<br/> - <a href='https://github.com/LeoKlaus'>LeoKlaus</a><br/> - <a href='https://github.com/nicola02nb'>nicola02nb</a><br/>Version: Puoi trovare il codice sorgente di HeadsetControl-GUI su <a href='https://github.com/LeoKlaus/HeadsetControl-GUI'>GitHub</a>.<br/>Fatto da:<br/> - <a href='https://github.com/LeoKlaus'>LeoKlaus</a><br/> - <a href='https://github.com/nicola02nb'>nicola02nb</a><br/>Versione: - + Big shout-out to:<br/> - <a href='https://github.com/Sapd'>Sapd</a> for <a href='https://github.com/Sapd/HeadsetControl'>HeadsetCoontrol Un grande riconoscimento va a:<br/> - <a href='https://github.com/Sapd'>Sapd</a> per <a href='https://github.com/Sapd/HeadsetControl'>HeadsetCoontrol diff --git a/src/Resources/tr/HeadsetControl_GUI_it_IT.qm b/src/Resources/tr/HeadsetControl_GUI_it_IT.qm deleted file mode 100644 index 6f07255..0000000 Binary files a/src/Resources/tr/HeadsetControl_GUI_it_IT.qm and /dev/null differ diff --git a/src/Resources/translations.qrc b/src/Resources/translations.qrc deleted file mode 100644 index c246505..0000000 --- a/src/Resources/translations.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - tr/HeadsetControl_GUI_en_US.qm - tr/HeadsetControl_GUI_it_IT.qm - - diff --git a/src/UI/mainwindow.cpp b/src/UI/mainwindow.cpp index c2d3f9d..49838e9 100644 --- a/src/UI/mainwindow.cpp +++ b/src/UI/mainwindow.cpp @@ -30,22 +30,7 @@ MainWindow::MainWindow(QWidget *parent) updateIconsTheme(); updateStyle(); resetGUI(); - - if (!fileExists(HEADSETCONTROL_FILE_PATH)) { - openFileExplorer(PROGRAM_APP_PATH); - DialogInfo *dialog = new DialogInfo(this); - dialog->setTitle(tr("Missing headsetcontrol")); - dialog->setLabel(tr("Missing headsetcontrol
" - "Download headsetcontrol in the opened folder.")); - dialog->exec(); - } else { - loadDevices(); - if (!deviceList.isEmpty() && n_connected > 0) { - loadDevice(); - } - } + updateGUI(); connect(&API, &HeadsetControlAPI::actionSuccesful, this, &::MainWindow::saveDevicesSettings); @@ -87,6 +72,11 @@ void MainWindow::bindEvents() connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAbout); connect(ui->actionCredits, &QAction::triggered, this, &MainWindow::showCredits); + //Error frames + connect(ui->openfolderPushButton, &QPushButton::clicked, this, [=]() { + openFileExplorer(PROGRAM_APP_PATH); + }); + // Other Section connect(ui->onlightButton, &QPushButton::clicked, &API, [=]() { API.setLights(selectedDevice, true); @@ -159,10 +149,20 @@ void MainWindow::bindEvents() } //Tray Icon Section -void MainWindow::setupTrayIcon() +void MainWindow::changeTrayIconTo(QString iconPath) { - trayIconPath = ":/icons/headphones-inv.png"; + trayIconPath = iconPath; + if (isAppDarkMode()) { + trayIconPath.replace("-dark", "-light"); + } else { + trayIconPath.replace("-light", "-dark"); + } trayIcon->setIcon(QIcon(trayIconPath)); +} + +void MainWindow::setupTrayIcon() +{ + changeTrayIconTo(":/icons/headphones-light.png"); trayIcon->setToolTip("HeadsetControl"); trayMenu = new QMenu(this); @@ -203,17 +203,16 @@ bool MainWindow::isAppDarkMode() void MainWindow::updateIconsTheme() { - QString inv = ""; + QString t = ""; if (isAppDarkMode()) { - inv = "-inv"; - trayIconPath.replace(".png", "-inv.png"); + //qApp->setWindowIcon(QIcon(":/icons/headphones-light.png")); + t = "-light"; } else { - trayIconPath.replace("-inv.png", ".png"); + //qApp->setWindowIcon(QIcon(":/icons/headphones-dark.png")); + t = "-dark"; } - setWindowIcon(QIcon(":/icons/headphones" + inv + ".png")); - qApp->setWindowIcon(QIcon(":/icons/headphones" + inv + ".png")); - trayIcon->setIcon(QIcon(trayIconPath)); + changeTrayIconTo(trayIconPath); } void MainWindow::updateStyle() @@ -260,7 +259,8 @@ void MainWindow::moveToBottomRight() QRect screenGeometry = screen->availableGeometry(); int x = screenGeometry.width() - width(); - int y = screenGeometry.height() - height() - ui->notSupportedFrame->height(); + int y = screenGeometry.height() - height() - ui->notSupportedFrame->height() + - ui->missingheadsetcontrolFrame->height(); move(x, y); } @@ -270,6 +270,7 @@ void MainWindow::resetGUI() ledOn->setEnabled(false); ledOff->setEnabled(false); + ui->missingheadsetcontrolFrame->setHidden(false); ui->notSupportedFrame->setHidden(false); ui->deviceinfoFrame->setHidden(true); @@ -292,6 +293,7 @@ void MainWindow::resetGUI() ui->equalizerpresetFrame->setHidden(true); ui->equalizerFrame->setHidden(true); ui->applyEqualizer->setEnabled(false); + clearEqualizerSliders(ui->equalizerLayout); ui->rotatetomuteFrame->setHidden(true); ui->muteledbrightnessFrame->setHidden(true); @@ -322,6 +324,7 @@ void MainWindow::loadDevice(int deviceIndex) selectedDevice = deviceList.value(deviceIndex); QSet &capabilities = selectedDevice->capabilities; + ui->missingheadsetcontrolFrame->setHidden(true); ui->notSupportedFrame->setHidden(true); qDebug() << selectedDevice->capabilities; @@ -486,16 +489,29 @@ QList MainWindow::getSavedDevices() void MainWindow::updateDevice() { - if (selectedDevice != nullptr) { - QList newDl = API.getConnectedDevices(); - selectedDevice->updateDevice(newDl); - } + QList newDl = API.getConnectedDevices(); + selectedDevice->updateDevice(newDl); } //Update GUI Section void MainWindow::updateGUI() { - updateDevice(); + if (!fileExists(HEADSETCONTROL_FILE_PATH)) { + resetGUI(); + ui->notSupportedFrame->setHidden(true); + selectedDevice = nullptr; + } else { + if (selectedDevice == nullptr) { + loadDevices(); + if (!deviceList.isEmpty() && n_connected > 0) { + loadDevice(); + } else { + ui->missingheadsetcontrolFrame->setHidden(true); + } + } else { + updateDevice(); + } + } setBatteryStatus(); setChatmixStatus(); } @@ -503,6 +519,11 @@ void MainWindow::updateGUI() // Info Section Events void MainWindow::setBatteryStatus() { + if (selectedDevice == nullptr) { + changeTrayIconTo(":/icons/headphones-light.png"); + return; + } + QString status = selectedDevice->battery.status; int batteryLevel = selectedDevice->battery.level; QString level = QString::number(batteryLevel); @@ -517,43 +538,43 @@ void MainWindow::setBatteryStatus() if (status == "BATTERY_UNAVAILABLE") { ui->batteryPercentage->setText(tr("Headset Off")); trayIcon->setToolTip(tr("HeadsetControl \r\nHeadset Off")); - trayIconPath = ":/icons/headphones-inv.png"; + changeTrayIconTo(":/icons/headphones-light.png"); } else if (status == "BATTERY_CHARGING") { ui->batteryPercentage->setText(level + tr("% - Charging")); trayIcon->setToolTip(tr("HeadsetControl \r\nBattery Charging")); - trayIconPath = ":/icons/battery-charging-inv.png"; + changeTrayIconTo(":/icons/battery-charging-light.png"); } else if (status == "BATTERY_AVAILABLE") { ui->batteryPercentage->setText(level + tr("% - Descharging")); trayIcon->setToolTip(tr("HeadsetControl \r\nBattery: ") + level + "%"); if (level.toInt() > 75) { - trayIconPath = ":/icons/battery-level-full-inv.png"; + changeTrayIconTo(":/icons/battery-level-full-light.png"); notified = false; } else if (level.toInt() > settings.batteryLowThreshold) { - trayIconPath = ":/icons/battery-medium-inv.png"; + changeTrayIconTo(":/icons/battery-medium-light.png"); notified = false; } else { - trayIconPath = ":/icons/battery-low-inv.png"; + changeTrayIconTo(":/icons/battery-low-light.png"); if (!notified) { trayIcon->showMessage(tr("Battery Alert!"), tr("The battery of your headset is running low"), - QIcon(":/icons/battery-low-inv.png")); + QIcon(":/icons/battery-low-light.png")); notified = true; } } } else { ui->batteryPercentage->setText(tr("No battery info")); trayIcon->setToolTip("HeadsetControl"); - trayIconPath = ":/icons/headphones-inv.png"; - } - - if (!isAppDarkMode()) { - trayIconPath.replace("-inv", ""); + changeTrayIconTo(":/icons/headphones-light.png"); } - trayIcon->setIcon(QIcon(trayIconPath)); } void MainWindow::setChatmixStatus() { + if (selectedDevice == nullptr) { + ui->chatmixvalueLabel->setText(tr("None")); + return; + } + int chatmix = selectedDevice->chatmix; QString chatmixValue = QString::number(chatmix); QString chatmixStatus; diff --git a/src/UI/mainwindow.h b/src/UI/mainwindow.h index 45765cf..9561836 100644 --- a/src/UI/mainwindow.h +++ b/src/UI/mainwindow.h @@ -55,7 +55,7 @@ class MainWindow : public QMainWindow int n_connected = 0, n_saved = 0; HeadsetControlAPI API; - Device *selectedDevice; + Device *selectedDevice = nullptr; QList deviceList; QList slidersEq; @@ -63,6 +63,7 @@ class MainWindow : public QMainWindow void bindEvents(); //Tray Icon Section + void changeTrayIconTo(QString iconPath); void setupTrayIcon(); //Theme mode Section diff --git a/src/UI/mainwindow.ui b/src/UI/mainwindow.ui index b5786c9..373baf9 100644 --- a/src/UI/mainwindow.ui +++ b/src/UI/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 488 - 690 + 792 @@ -24,10 +24,6 @@ HeadsetControl-GUI - - - :/icons/headphones-inv.png:/icons/headphones-inv.png - @@ -54,6 +50,83 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::LeftToRight + + + Missing headsetcontrol!<br/>Download <a href="https://github.com/Sapd/HeadsetControl/releases/latest">headsetcontrol</a> in the program folder. + + + Qt::AutoText + + + Qt::AlignCenter + + + false + + + Qt::TextBrowserInteraction + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Open Program Folder + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + @@ -1781,8 +1854,6 @@ Model: muteledbrightnessSlider micvolumeSlider - - - + diff --git a/src/Utils/headsetcontrolapi.cpp b/src/Utils/headsetcontrolapi.cpp index 368d9ec..f3447e0 100644 --- a/src/Utils/headsetcontrolapi.cpp +++ b/src/Utils/headsetcontrolapi.cpp @@ -10,52 +10,6 @@ HeadsetControlAPI::HeadsetControlAPI(QString headsetcontrolFilePath) sendCommand(QStringList()); } -// HC rleated functions -QString HeadsetControlAPI::sendCommand(const QStringList &args_list) -{ - QProcess *proc = new QProcess(); - QStringList args = QStringList() << QString("--output") << QString("JSON"); - //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; - - return output; -} - -Action HeadsetControlAPI::sendAction(const QStringList &args_list) -{ - QString output = sendCommand(args_list); - QJsonDocument jsonDoc = QJsonDocument::fromJson(output.toUtf8()); - QJsonObject jsonInfo = jsonDoc.object(); - QJsonArray actions = jsonInfo["actions"].toArray(); - Action action; - if (!actions.isEmpty()) { - QJsonObject jaction = actions[0].toObject(); - - action.device = jaction["device"].toString(); - action.capability = jaction["capability"].toString(); - action.status = jaction["status"].toString(); - action.error_message = jaction["error_message"].toString(); - - action.success = action.status == "success"; - - qDebug() << "Device:\t" << action.device; - qDebug() << "Capability:" << action.capability; - qDebug() << "Status:\t" << action.status; - if (!action.success) { - qDebug() << "Error:\t" << action.error_message; - } - } - - return action; -} - QString HeadsetControlAPI::getName() { return name; @@ -104,6 +58,53 @@ QList HeadsetControlAPI::getConnectedDevices() return devices; } +// HC rleated functions +QString HeadsetControlAPI::sendCommand(const QStringList &args_list) +{ + QProcess *proc = new QProcess(); + QStringList args = QStringList() << QString("--output") << QString("JSON"); + //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(); + + return output; +} + +Action HeadsetControlAPI::sendAction(const QStringList &args_list) +{ + QString output = sendCommand(args_list); + QJsonDocument jsonDoc = QJsonDocument::fromJson(output.toUtf8()); + QJsonObject jsonInfo = jsonDoc.object(); + QJsonArray actions = jsonInfo["actions"].toArray(); + Action action; + if (!actions.isEmpty()) { + QJsonObject jaction = actions[0].toObject(); + + action.device = jaction["device"].toString(); + action.capability = jaction["capability"].toString(); + action.status = jaction["status"].toString(); + action.error_message = jaction["error_message"].toString(); + + action.success = action.status == "success"; + + qDebug() << "Device:\t" << action.device; + qDebug() << "Capability:" << action.capability; + qDebug() << "Status:\t" << action.status; + if (!action.success) { + qDebug() << "Error:\t" << action.error_message; + } + } + + return action; +} + void HeadsetControlAPI::setSidetone(Device *device, int level) { QStringList args = QStringList() << QString("--sidetone") << QString::number(level); diff --git a/src/Utils/headsetcontrolapi.h b/src/Utils/headsetcontrolapi.h index 1636bd1..e7a9b55 100644 --- a/src/Utils/headsetcontrolapi.h +++ b/src/Utils/headsetcontrolapi.h @@ -3,6 +3,7 @@ #include "device.h" +#include #include #include @@ -32,6 +33,7 @@ class HeadsetControlAPI : public QObject private: QString headsetcontrolFilePath; + QFile headsetcontrol; QString name; QVersionNumber version; diff --git a/src/main.cpp b/src/main.cpp index afe6131..bc2fa93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ #include const QString APP_NAME = "HeadsetControl-GUI"; -const QString GUI_VERSION = "0.16.3"; +const QString GUI_VERSION = "0.16.4"; int main(int argc, char *argv[]) {