diff --git a/src/HeadsetControlQt/headsetcontrolqt.cpp b/src/HeadsetControlQt/headsetcontrolqt.cpp index b549c46..96e52b7 100644 --- a/src/HeadsetControlQt/headsetcontrolqt.cpp +++ b/src/HeadsetControlQt/headsetcontrolqt.cpp @@ -37,13 +37,15 @@ HeadsetControlQt::HeadsetControlQt(QWidget *parent) { ui->setupUi(this); setWindowIcon(QIcon(":/icons/icon.png")); - loadSettings(); initUI(); createTrayIcon(); + createTrayMenu(); + loadSettings(); + setupUIConnections(); updateHeadsetInfo(); + connect(worker, &Worker::workRequested, worker, &Worker::doWork); connect(worker, &Worker::sendHeadsetInfo, this, &::HeadsetControlQt::handleHeadsetInfo); - connect(timer, &QTimer::timeout, worker, &Worker::requestWork); worker->moveToThread(&workerThread); @@ -92,7 +94,6 @@ void HeadsetControlQt::initUI() setFrameColorBasedOnWindow(this, ui->frame_2); populateComboBoxes(); checkStartupCheckbox(); - setupUIConnections(); } void HeadsetControlQt::setupUIConnections() @@ -105,6 +106,7 @@ void HeadsetControlQt::setupUIConnections() connect(ui->themeComboBox, &QComboBox::currentIndexChanged, this, &HeadsetControlQt::onThemeComboBoxCurrentIndexChanged); connect(ui->lowBatteryThresholdSpinBox, &QSpinBox::valueChanged, this, &HeadsetControlQt::saveSettings); connect(ui->soundBatteryCheckBox, &QCheckBox::stateChanged, this, &HeadsetControlQt::saveSettings); + connect(ui->languageComboBox, &QComboBox::currentIndexChanged, this, &HeadsetControlQt::changeApplicationLanguage); } void HeadsetControlQt::populateComboBoxes() @@ -112,6 +114,13 @@ void HeadsetControlQt::populateComboBoxes() ui->themeComboBox->addItem(tr("System")); ui->themeComboBox->addItem(tr("Dark")); ui->themeComboBox->addItem(tr("Light")); + ui->languageComboBox->addItem("System"); + ui->languageComboBox->addItem("english"); + ui->languageComboBox->addItem("français"); + ui->languageComboBox->addItem("deutsch"); + ui->languageComboBox->addItem("español"); + ui->languageComboBox->addItem("italiano"); + ui->languageComboBox->addItem("magyar"); } void HeadsetControlQt::checkStartupCheckbox() @@ -126,6 +135,12 @@ void HeadsetControlQt::checkStartupCheckbox() void HeadsetControlQt::createTrayIcon() { trayIcon->setIcon(QIcon(":/icons/icon.png")); + trayIcon->show(); + connect(trayIcon, &QSystemTrayIcon::activated, this, &HeadsetControlQt::trayIconActivated); +} + +void HeadsetControlQt::createTrayMenu() +{ QMenu *trayMenu = new QMenu(this); QAction *showAction = new QAction(tr("Show"), this); connect(showAction, &QAction::triggered, this, &HeadsetControlQt::toggleWindow); @@ -134,8 +149,6 @@ void HeadsetControlQt::createTrayIcon() connect(exitAction, &QAction::triggered, this, &QApplication::quit); trayMenu->addAction(exitAction); trayIcon->setContextMenu(trayMenu); - trayIcon->show(); - connect(trayIcon, &QSystemTrayIcon::activated, this, &HeadsetControlQt::trayIconActivated); } void HeadsetControlQt::createDefaultSettings() @@ -181,6 +194,8 @@ void HeadsetControlQt::applySettings() ui->themeComboBox->setCurrentIndex(settings.value("theme").toInt()); ui->lowBatteryThresholdSpinBox->setValue(settings.value("low_battery_threshold").toInt()); ui->soundBatteryCheckBox->setChecked(settings.value("sound_low_battery").toBool()); + ui->languageComboBox->setCurrentIndex(settings.value("language").toInt()); + changeApplicationLanguage(); setSidetone(); toggleLED(ui->ledBox->isChecked()); } @@ -194,6 +209,7 @@ void HeadsetControlQt::saveSettings() settings["theme"] = ui->themeComboBox->currentIndex(); settings["low_battery_threshold"] = ui->lowBatteryThresholdSpinBox->value(); settings["sound_low_battery"] = ui->soundBatteryCheckBox->isChecked(); + settings["language"] = ui->languageComboBox->currentIndex(); QFile file(settingsFile); if (file.open(QIODevice::WriteOnly)) { @@ -284,7 +300,6 @@ void HeadsetControlQt::sendNotificationBasedOnBattery(const QJsonObject &headset void HeadsetControlQt::sendSoundNotificationBasedOnBattery(const QJsonObject &headsetInfo) { QJsonObject batteryInfo = headsetInfo["battery"].toObject(); - QString headsetName = headsetInfo["device"].toString(); int batteryLevel = batteryInfo["level"].toInt(); QString batteryStatus = batteryInfo["status"].toString(); bool available = (batteryStatus == "BATTERY_AVAILABLE"); @@ -519,3 +534,40 @@ void HeadsetControlQt::sendFirstMinimizeNotification() firstRun = false; } } + +void HeadsetControlQt::changeApplicationLanguage() +{ + QString language = ui->languageComboBox->currentText().toLower(); + QTranslator translator; + + if (qApp->removeTranslator(&translator)) { + } + + QString languageCode; + if (language == "system") { + QLocale systemLocale; + languageCode = systemLocale.name().left(2); + } else { + QMap languageCodes; + languageCodes["english"] = "en"; + languageCodes["français"] = "fr"; + languageCodes["deutsch"] = "de"; + languageCodes["español"] = "es"; + languageCodes["italiano"] = "it"; + languageCodes["magyar"] = "hu"; + + languageCode = languageCodes.value(language, "en"); + } + + QString translationFile = QString(":/translations/tr/HeadsetControl-Qt_%1.qm").arg(languageCode); + if (translator.load(translationFile)) { + qApp->installTranslator(&translator); + } else { + qWarning() << "Failed to load translation file:" << translationFile; + } + + ui->retranslateUi(this); + delete trayIcon->contextMenu(); + createTrayMenu(); + saveSettings(); +} diff --git a/src/HeadsetControlQt/headsetcontrolqt.h b/src/HeadsetControlQt/headsetcontrolqt.h index eb7b84d..1ec9d54 100644 --- a/src/HeadsetControlQt/headsetcontrolqt.h +++ b/src/HeadsetControlQt/headsetcontrolqt.h @@ -38,6 +38,7 @@ private slots: void trayIconActivated(QSystemTrayIcon::ActivationReason reason); void onStartupCheckBoxStateChanged(); void handleHeadsetInfo(const QJsonObject &headsetInfo); + void changeApplicationLanguage(); private: void initUI(); @@ -45,6 +46,7 @@ private slots: void populateComboBoxes(); void checkStartupCheckbox(); void createTrayIcon(); + void createTrayMenu(); void loadSettings(); void applySettings(); void saveSettings(); diff --git a/src/HeadsetControlQt/headsetcontrolqt.ui b/src/HeadsetControlQt/headsetcontrolqt.ui index 52d8f14..0286122 100644 --- a/src/HeadsetControlQt/headsetcontrolqt.ui +++ b/src/HeadsetControlQt/headsetcontrolqt.ui @@ -6,8 +6,8 @@ 0 0 - 388 - 429 + 380 + 460 @@ -70,8 +70,8 @@ QFrame::Shadow::Raised - - + + 0 @@ -79,58 +79,55 @@ - Run at startup + Low battery threshold - - + + 0 25 - - Qt::LayoutDirection::RightToLeft + + + 16777215 + 16777215 + - - + + 0 + + + 100 - - + + 0 25 - - Low battery threshold + + QComboBox::SizeAdjustPolicy::AdjustToContents - - + + 0 25 - - - 16777215 - 16777215 - - - - 0 - - - 100 + + Run at startup @@ -147,6 +144,22 @@ + + + + + 0 + 25 + + + + Qt::LayoutDirection::RightToLeft + + + + + + @@ -160,16 +173,26 @@ - - + + 0 25 - - QComboBox::SizeAdjustPolicy::AdjustToContents + + Language + + + + + + + + 0 + 25 + @@ -190,7 +213,7 @@ - device + device diff --git a/src/Resources/tr/HeadsetControl-Qt_de.ts b/src/Resources/tr/HeadsetControl-Qt_de.ts index 8cca5b7..6024b22 100644 --- a/src/Resources/tr/HeadsetControl-Qt_de.ts +++ b/src/Resources/tr/HeadsetControl-Qt_de.ts @@ -5,7 +5,7 @@ HeadsetControlQt - + HeadsetControl-Qt HeadsetControl-Qt @@ -15,119 +15,123 @@ Kein unterstütztes Headset gefunden. - + Run at startup Beim Start ausführen - + Low battery threshold Schwellenwert für niedrigen Batteriestand - + Icon theme Symbolthema - device - Gerät + Gerät + + + + Language + Sprache - + Settings Einstellungen - + Battery Batterie - + Sidetone Seitenklang - + Lights Beleuchtung - + Disable lights on low battery Beleuchtung bei niedrigem Batteriestand deaktivieren - + Send notification on low battery Benachrichtigung bei niedrigem Batteriestand senden - + Beep on low battery Piepston bei niedrigem Batteriestand - + System System - + Dark Dunkel - + Light Hell - - - + + + Show Anzeigen - + Exit Beenden - + Low battery Niedriger Batteriestand - + %1 has %2% battery left. %1 hat noch %2% Batterieladung übrig. - + Off Aus - + No headset connected Kein Headset verbunden - + No Device Found Kein Gerät gefunden - + Hide Verbergen - + The application is still running in the background. Die Anwendung läuft weiterhin im Hintergrund. diff --git a/src/Resources/tr/HeadsetControl-Qt_en.ts b/src/Resources/tr/HeadsetControl-Qt_en.ts index 86b19c0..79b9bd9 100644 --- a/src/Resources/tr/HeadsetControl-Qt_en.ts +++ b/src/Resources/tr/HeadsetControl-Qt_en.ts @@ -5,62 +5,62 @@ HeadsetControlQt - + HeadsetControl-Qt - - device - + + Language + - + Battery - + Sidetone - + Lights - + Disable lights on low battery - + Send notification on low battery - + Beep on low battery - + Settings - + Icon theme - + Run at startup - + Low battery threshold @@ -70,64 +70,64 @@ - + System - + Dark - + Light - - - + + + Show - + Exit - + Low battery - + %1 has %2% battery left. - + Off - + No headset connected - + No Device Found - + Hide - + The application is still running in the background. diff --git a/src/Resources/tr/HeadsetControl-Qt_es.ts b/src/Resources/tr/HeadsetControl-Qt_es.ts index 0c2fe21..66fcdf5 100644 --- a/src/Resources/tr/HeadsetControl-Qt_es.ts +++ b/src/Resources/tr/HeadsetControl-Qt_es.ts @@ -5,7 +5,7 @@ HeadsetControlQt - + HeadsetControl-Qt HeadsetControl-Qt @@ -15,119 +15,123 @@ No se encontró un auricular compatible. - + Run at startup Ejecutar al inicio - + Low battery threshold Umbral de batería baja - + Icon theme Tema de iconos - device - dispositivo + dispositivo + + + + Language + Idioma - + Settings Ajustes - + Battery Batería - + Sidetone Retroalimentación - + Lights Luces - + Disable lights on low battery Desactivar luces con batería baja - + Send notification on low battery Enviar notificación con batería baja - + Beep on low battery Pitido con batería baja - + System Sistema - + Dark Oscuro - + Light Claro - - - + + + Show Mostrar - + Exit Salir - + Low battery Batería baja - + %1 has %2% battery left. %1 tiene %2% de batería restante. - + Off Apagado - + No headset connected Ningún auricular conectado - + No Device Found No se encontró ningún dispositivo - + Hide Ocultar - + The application is still running in the background. La aplicación sigue ejecutándose en segundo plano. diff --git a/src/Resources/tr/HeadsetControl-Qt_fr.ts b/src/Resources/tr/HeadsetControl-Qt_fr.ts index 6a7f1a0..b4cf651 100644 --- a/src/Resources/tr/HeadsetControl-Qt_fr.ts +++ b/src/Resources/tr/HeadsetControl-Qt_fr.ts @@ -5,62 +5,62 @@ HeadsetControlQt - + HeadsetControl-Qt - - device - + + Language + Langage - + Battery Batterie - + Sidetone Retour voix - + Lights LEDs - + Disable lights on low battery Désactiver les LEDs quand la batterie est faible - + Send notification on low battery Envoyer une notification quand la batterie est faible - + Beep on low battery Bip audio quand la batterie est faible - + Settings Paramètres - + Icon theme Thème d'icones - + Run at startup Lancer au démarrage - + Low battery threshold Niveau batterie faible @@ -70,64 +70,64 @@ Aucun casque détecté. - + System Système - + Dark Sombre - + Light Clair - - - + + + Show Afficher - + Exit Quitter - + Low battery Batterie faible - + %1 has %2% battery left. %2% de batterie restant pour %1. - + Off Éteint - + No headset connected Pas de casque connecté - + No Device Found Aucun casque détecté - + Hide Masquer - + The application is still running in the background. L'application tourne toujours en arrière plan. diff --git a/src/Resources/tr/HeadsetControl-Qt_hu.ts b/src/Resources/tr/HeadsetControl-Qt_hu.ts index 378015b..dee559d 100644 --- a/src/Resources/tr/HeadsetControl-Qt_hu.ts +++ b/src/Resources/tr/HeadsetControl-Qt_hu.ts @@ -5,62 +5,66 @@ HeadsetControlQt - + HeadsetControl-Qt - device - eszköz + eszköz - + + Language + Nyelv + + + Battery Akkumulátor - + Sidetone - + Lights Fények - + Disable lights on low battery Fények ki alacsony akku szintnél - + Send notification on low battery Értesítés alacsony akku szintnél - + Beep on low battery Hangjelzés alacsony akku szintnél - + Settings Beállítások - + Icon theme Ikon stílus - + Run at startup Indítás bejelentkezéskor - + Low battery threshold Alacsony akku határérték @@ -70,64 +74,64 @@ Nem található támogatott fejhallgató. - + System Rendszer - + Dark Sötét - + Light Világos - - - + + + Show Mutat - + Exit Kilépés - + Low battery Alacsony akkumulátor szint - + %1 has %2% battery left. %1 akku töltöttség %2%. - + Off Ki - + No headset connected Nincs csatlakoztatva fejhallgató - + No Device Found Eszköz nem található - + Hide Elrejt - + The application is still running in the background. Az alkalmazás továbbra is fut a háttérben. diff --git a/src/Resources/tr/HeadsetControl-Qt_it.ts b/src/Resources/tr/HeadsetControl-Qt_it.ts index 202b4e1..219a62c 100644 --- a/src/Resources/tr/HeadsetControl-Qt_it.ts +++ b/src/Resources/tr/HeadsetControl-Qt_it.ts @@ -5,7 +5,7 @@ HeadsetControlQt - + HeadsetControl-Qt HeadsetControl-Qt @@ -15,119 +15,123 @@ Nessun auricolare supportato trovato. - + Run at startup Esegui all'avvio - + Low battery threshold Soglia di batteria bassa - + Icon theme Tema delle icone - device - dispositivo + dispositivo + + + + Language + Lingua - + Settings Impostazioni - + Battery Batteria - + Sidetone Sidetone - + Lights Luci - + Disable lights on low battery Disattiva luci con batteria scarica - + Send notification on low battery Invia notifica quando la batteria è scarica - + Beep on low battery Segnale acustico con batteria scarica - + System Sistema - + Dark Scuro - + Light Chiaro - - - + + + Show Mostra - + Exit Esci - + Low battery Batteria scarica - + %1 has %2% battery left. %1 ha il %2% di batteria rimanente. - + Off Spento - + No headset connected Nessun auricolare connesso - + No Device Found Nessun dispositivo trovato - + Hide Nascondi - + The application is still running in the background. L'applicazione è ancora in esecuzione in secondo piano. diff --git a/src/main.cpp b/src/main.cpp index 59d3e4b..a8414d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,12 +10,6 @@ int main(int argc, char *argv[]) a.setStyle("fusion"); #endif a.setQuitOnLastWindowClosed(false); - QLocale locale; - QString languageCode = locale.name().section('_', 0, 0); - QTranslator translator; - if (translator.load(":/translations/tr/HeadsetControl-Qt_" + languageCode + ".qm")) { - a.installTranslator(&translator); - } HeadsetControlQt w; return a.exec();