From 17e3c2e022ce062ce991564ac259b8e8ea4ae417 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Tue, 15 Oct 2024 21:17:03 +0200 Subject: [PATCH] Fix #149 --- dashboard/settings.cpp | 96 ++++++++++++++++++++++++--------- dashboard/settings.h | 2 + dashboard/settings.ui | 120 +++-------------------------------------- dashboard/wivrn_en.ts | 46 +++++++++------- dashboard/wivrn_fr.ts | 46 +++++++++------- 5 files changed, 133 insertions(+), 177 deletions(-) diff --git a/dashboard/settings.cpp b/dashboard/settings.cpp index f49f023c..f265339f 100644 --- a/dashboard/settings.cpp +++ b/dashboard/settings.cpp @@ -130,8 +130,12 @@ settings::settings(wivrn_server * server_interface) : connect(ui->combo_select_game, &QComboBox::currentIndexChanged, this, &settings::on_selected_game_changed); connect(ui->button_game_browse, &QPushButton::clicked, this, &settings::on_browse_game); + // Use a queued connection so that the slot is called after the widgets have been laid out + connect(ui->radio_manual_encoder, &QRadioButton::toggled, this, [&](bool value) { + if (value) + ui->scrollArea->ensureWidgetVisible(ui->layout_encoder_config); }, Qt::QueuedConnection); + connect(ui->partitionner, &rectangle_partitionner::selected_index_change, this, &settings::selected_rectangle_changed); - // connect(ui->partitionner, &rectangle_partitionner::rectangles_change, this, [](){}); connect(ui->encoder, &QComboBox::currentIndexChanged, this, &settings::on_selected_encoder_changed); connect(ui->encoder, &QComboBox::currentIndexChanged, this, &settings::on_encoder_settings_changed); @@ -142,6 +146,7 @@ settings::settings(wivrn_server * server_interface) : setWindowModality(Qt::WindowModality::ApplicationModal); + fill_steam_games_list(); load_settings(); ui->partitionner->set_paint([&](QPainter & painter, QRect rect, const QVariant & data, int index, bool selected) { @@ -186,6 +191,19 @@ settings::~settings() ui = nullptr; } +void settings::fill_steam_games_list() +{ + ui->combo_select_game->clear(); + ui->combo_select_game->addItem(tr("None", "Game selection combo box")); + ui->combo_select_game->addItem(tr("Custom...", "Game selection combo box")); + + auto apps = steam_apps(); + for (auto & app: apps) + { + ui->combo_select_game->addItem(QString::fromUtf8(app.name), QVariant::fromValue(app)); + } +} + void settings::on_selected_encoder_changed() { int encoder = ui->encoder->currentIndex(); @@ -317,6 +335,7 @@ void settings::restore_defaults() ui->bitrate->setValue(50); ui->radio_auto_foveation->setChecked(true); ui->radio_auto_encoder->setChecked(true); + ui->layout_encoder_config->setVisible(false); std::vector rectangles; std::vector encoder_config; @@ -327,7 +346,7 @@ void settings::restore_defaults() ui->partitionner->set_rectangles(rectangles); ui->partitionner->set_rectangles_data(encoder_config); - ui->partitionner->set_selected_index(-1); + ui->partitionner->set_selected_index(0); ui->combo_select_game->setCurrentIndex(0); ui->edit_game_path->setText(""); @@ -351,7 +370,9 @@ void settings::load_settings() // Encoders configuration try { - json_doc = nlohmann::json::parse(server_interface->jsonConfiguration().toUtf8()); + auto conf = server_interface->jsonConfiguration(); + qDebug() << "Server config" << conf; + json_doc = nlohmann::json::parse(conf.toUtf8()); } catch (std::exception & e) { @@ -420,7 +441,15 @@ void settings::load_settings() ui->partitionner->set_rectangles(rectangles); ui->partitionner->set_rectangles_data(encoder_config); - ui->partitionner->set_selected_index(-1); + + if (rectangles.size() == 1) + { + ui->partitionner->set_selected_index(0); + // Force updating the combo boxes, if the selected index is already 0 the signal is not called + selected_rectangle_changed(0); + } + else + ui->partitionner->set_selected_index(-1); // Foveation try @@ -445,35 +474,52 @@ void settings::load_settings() } // Bitrate - ui->bitrate->setValue(json_doc.value("bitrate", 50'000'000.0) / 1'000'000); + try + { + ui->bitrate->setValue(json_doc.value("bitrate", 50'000'000.0) / 1'000'000); + } + catch (...) + { + ui->bitrate->setValue(50); + } // Automatically started application std::vector application; - - if (json_doc["application"].is_array()) - application = json_doc.value>("application", {}); - else if (json_doc["application"].is_string()) - application.push_back(json_doc["application"]); - - ui->combo_select_game->clear(); - ui->combo_select_game->addItem(tr("None", "Game selection combo box")); - ui->combo_select_game->addItem(tr("Custom...", "Game selection combo box")); - - auto apps = steam_apps(); - for (auto & app: apps) + try { - ui->combo_select_game->addItem(QString::fromUtf8(app.name), QVariant::fromValue(app)); + if (json_doc["application"].is_array()) + application = json_doc.value>("application", {}); + else if (json_doc["application"].is_string()) + application.push_back(json_doc["application"]); - if (application.size() == 2 and application[0] == "steam" and application[1] == app.url) + int game_index = 0; + if (application.size() == 2 and application[0] == "steam") { - ui->combo_select_game->setCurrentIndex(ui->combo_select_game->count() - 1); - } - } + auto url = application[1]; - if (not application.empty() and ui->combo_select_game->currentIndex() == 0) + // Indices 0 and 1 are None and Custom + for (int i = 2, n = ui->combo_select_game->count(); i < n; i++) + { + QVariant data = ui->combo_select_game->itemData(i); + if (data.value().url == url) + { + game_index = i; + break; + } + } + } + + if (game_index == 0 and not application.empty()) + { + game_index = 1; + set_application(application); + } + + ui->combo_select_game->setCurrentIndex(game_index); + } + catch (...) { - ui->combo_select_game->setCurrentIndex(1); - set_application(application); + ui->combo_select_game->setCurrentIndex(0); } // Update the compatible codecs diff --git a/dashboard/settings.h b/dashboard/settings.h index 454881cb..c511aaf3 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -51,6 +51,8 @@ private: void save_settings(); void restore_defaults(); + void fill_steam_games_list(); + void set_application(const std::vector & app); std::vector application(); }; diff --git a/dashboard/settings.ui b/dashboard/settings.ui index acc6c047..9e8ad1d5 100644 --- a/dashboard/settings.ui +++ b/dashboard/settings.ui @@ -223,9 +223,6 @@ - - false - 0 @@ -259,9 +256,6 @@ - - false - 100 @@ -278,15 +272,15 @@ - - false - 100 0 + + No encoder selected + Auto @@ -311,15 +305,15 @@ - - false - 100 0 + + No encoder selected + Auto @@ -344,9 +338,6 @@ - - false - 220 @@ -363,9 +354,6 @@ - - false - 100 @@ -751,102 +739,6 @@ The recommended values are between 20% and 50% for headsets without eye tracking - - radio_manual_encoder - toggled(bool) - partitionner - setEnabled(bool) - - - 888 - 663 - - - 449 - 745 - - - - - radio_manual_encoder - toggled(bool) - encoder - setEnabled(bool) - - - 888 - 663 - - - 952 - 695 - - - - - radio_manual_encoder - toggled(bool) - codec - setEnabled(bool) - - - 888 - 663 - - - 952 - 734 - - - - - radio_manual_encoder - toggled(bool) - encoder_label - setEnabled(bool) - - - 888 - 663 - - - 715 - 695 - - - - - radio_manual_encoder - toggled(bool) - codec_label - setEnabled(bool) - - - 888 - 663 - - - 715 - 734 - - - - - radio_manual_encoder - toggled(bool) - message - setEnabled(bool) - - - 888 - 663 - - - 764 - 778 - - - radio_manual_encoder toggled(bool) diff --git a/dashboard/wivrn_en.ts b/dashboard/wivrn_en.ts index e91cafa7..36ae2014 100644 --- a/dashboard/wivrn_en.ts +++ b/dashboard/wivrn_en.ts @@ -204,17 +204,17 @@ <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>You can drag an edge to resize or remove encoders.</p></body></html> - + nvenc (NVIDIA GPUs) nvenc (NVIDIA GPUs) - + vaapi (AMD and Intel GPUs) vaapi (AMD and Intel GPUs) - + x264 (software encoding) x264 (software encoding) @@ -226,12 +226,12 @@ Manual - + Application to start when a headset connects Application to start when a headset connects - + Path Path @@ -260,13 +260,19 @@ <html><head/><body><p>To add a new encoder, split an existing encoder by clicking near an edge.</p><p>Drag an edge to resize or remove encoders.</p></body></html> - + Encoder Encoder - - + + + No encoder selected + No encoder selected + + + + Auto Auto @@ -277,7 +283,7 @@ Automatic - + A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. A weaker foveation gives a uniform sharpness in the whole image. @@ -297,17 +303,17 @@ The recommended values are between 20% and 50% for headsets without eye tracking Automatic - + WiVRn settings WiVRn settings - + Codec Codec - + Mbit/s Mbit/s @@ -325,7 +331,7 @@ The recommended values are between 20% and 50% for headsets without eye tracking Browse - + % % @@ -640,36 +646,38 @@ Do you want to install it? settings - + Invalid settings Invalid settings - + The encoder configuration is invalid, the default values will be restored. The encoder configuration is invalid, the default values will be restored. - + + None Game selection combo box None - + + Custom... Game selection combo box Custom... - + Not all headsets and GPUs support AV1 Not all headsets and GPUs support AV1 - + Select game Select game diff --git a/dashboard/wivrn_fr.ts b/dashboard/wivrn_fr.ts index 98227cbc..c565b288 100644 --- a/dashboard/wivrn_fr.ts +++ b/dashboard/wivrn_fr.ts @@ -204,17 +204,17 @@ <html><head/><body><p>Pour ajouter un encodeur, découpez un encodeur existant en cliquant près d'un bord.</p><p>Vous pouvez déplacer un bord pour redimensionner ou supprimer un encodeur.</p></body></html> - + nvenc (NVIDIA GPUs) nvenc (GPUs NVIDIA) - + vaapi (AMD and Intel GPUs) vaapi (GPUs AMD et Intel) - + x264 (software encoding) x264 (encodage logiciel) @@ -226,12 +226,12 @@ Manuelle - + Application to start when a headset connects Application à démarrer quand un casque est connecté - + Path Chemin @@ -260,13 +260,19 @@ <html><head/><body><p>Pour ajouter un encodeur, découpez un encodeur existant en cliquant près d'un bord.</p><p>Déplacez un bord pour redimensionner ou supprimer un encodeur.</p></body></html> - + Encoder Encodeur - - + + + No encoder selected + Aucun encodeur sélectionné + + + + Auto Automatique @@ -277,7 +283,7 @@ Automatique - + A stronger foveation makes the image sharper in the center than in the periphery and makes the decoding faster. This is better for fast paced games. A weaker foveation gives a uniform sharpness in the whole image. @@ -297,17 +303,17 @@ Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi des Automatique - + WiVRn settings Paramètres de WiVRn - + Codec Codec - + Mbit/s Mbit/s @@ -325,7 +331,7 @@ Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi des Parcourir - + % % @@ -640,36 +646,38 @@ Voulez-vous l'installer ? settings - + Invalid settings Paramètres invalides - + The encoder configuration is invalid, the default values will be restored. La configuration des encodeurs est invalide, les valeurs par défaut seront restaurées. - + + None Game selection combo box Aucun - + + Custom... Game selection combo box Personnalisé... - + Not all headsets and GPUs support AV1 Tous les casques et GPUs ne supportent pas AV1 - + Select game Choisir un jeu