From dfdff6f3e4d9bee3e5cd5470a2562d89e9502222 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 1 Dec 2024 22:35:26 +0100 Subject: [PATCH] Add GUI to remove and rename known headsets --- dashboard/CMakeLists.txt | 3 + dashboard/main_window.cpp | 10 +++- dashboard/main_window.h | 1 + dashboard/main_window.ui | 4 +- dashboard/manage_headsets.cpp | 104 ++++++++++++++++++++++++++++++++++ dashboard/manage_headsets.h | 51 +++++++++++++++++ dashboard/manage_headsets.ui | 81 ++++++++++++++++++++++++++ dashboard/settings.h | 2 +- 8 files changed, 250 insertions(+), 6 deletions(-) create mode 100644 dashboard/manage_headsets.cpp create mode 100644 dashboard/manage_headsets.h create mode 100644 dashboard/manage_headsets.ui diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index e4e2b7f6..cf154857 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -14,6 +14,9 @@ qt_add_executable(wivrn-dashboard main_window.cpp main_window.h main_window.ui + manage_headsets.cpp + manage_headsets.h + manage_headsets.ui settings.cpp settings.h settings.ui diff --git a/dashboard/main_window.cpp b/dashboard/main_window.cpp index a105002f..eede2555 100644 --- a/dashboard/main_window.cpp +++ b/dashboard/main_window.cpp @@ -31,6 +31,7 @@ #include "adb.h" #include "gui_config.h" +#include "manage_headsets.h" #include "settings.h" #include "ui_main_window.h" #include "utils/flatpak.h" @@ -268,6 +269,7 @@ main_window::main_window() connect(server_interface, &wivrn_server::pairingEnabledChanged, ui->button_pair_headset, &QWidget::setHidden); connect(ui->button_cancel_pairing, &QPushButton::clicked, server_interface, &wivrn_server::disable_pairing); connect(ui->button_pair_headset, &QPushButton::clicked, server_interface, &wivrn_server::enable_pairing); + connect(ui->button_manage_headsets, &QPushButton::clicked, this, &main_window::on_action_manage_headsets); connect(ui->button_start, &QPushButton::clicked, this, &main_window::start_server); connect(ui->button_stop, &QPushButton::clicked, this, &main_window::stop_server); @@ -302,9 +304,6 @@ main_window::main_window() if (not nvidia_layer_missing()) ui->banner_nvidia_layer->hide(); - // TODO implement this - ui->button_known_headsets->hide(); - retranslate(); } @@ -781,6 +780,11 @@ void main_window::on_action_wizard() wizard{}.exec(); } +void main_window::on_action_manage_headsets() +{ + manage_headsets{server_interface}.exec(); +} + void main_window::on_action_usb(const std::string & serial) { auto devs = adb_service.devices(); diff --git a/dashboard/main_window.h b/dashboard/main_window.h index 45eeb158..008463a5 100644 --- a/dashboard/main_window.h +++ b/dashboard/main_window.h @@ -103,6 +103,7 @@ private: void on_action_settings(); void on_action_wizard(); + void on_action_manage_headsets(); void on_action_usb(const std::string & serial); void start_server(); void stop_server(); diff --git a/dashboard/main_window.ui b/dashboard/main_window.ui index c01218a6..09241f08 100644 --- a/dashboard/main_window.ui +++ b/dashboard/main_window.ui @@ -394,9 +394,9 @@ border-radius: 5px; - + - Known headsets + Manage headsets diff --git a/dashboard/manage_headsets.cpp b/dashboard/manage_headsets.cpp new file mode 100644 index 00000000..8d558320 --- /dev/null +++ b/dashboard/manage_headsets.cpp @@ -0,0 +1,104 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "manage_headsets.h" +#include "ui_manage_headsets.h" +#include "wivrn_server.h" +#include +#include + +manage_headsets::manage_headsets(wivrn_server * server_interface) : + server_interface(server_interface) +{ + ui = new Ui::ManageHeadsets; + ui->setupUi(this); + ui->headset_list->setModel(new QStandardItemModel); + + connect(server_interface, &wivrn_server::knownKeysChanged, this, &manage_headsets::update_headet_list); + connect(ui->headset_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, &manage_headsets::on_selection_changed); + connect(ui->button_remove, &QPushButton::clicked, this, &manage_headsets::on_remove_selected); + + QStandardItemModel * headsets = dynamic_cast(ui->headset_list->model()); + connect(headsets, &QStandardItemModel::itemChanged, this, &manage_headsets::on_rename_selected); + + update_headet_list(server_interface->knownKeys()); +} + +void manage_headsets::update_headet_list(const std::vector & new_headsets) +{ + QStandardItemModel * current_headsets = dynamic_cast(ui->headset_list->model()); + assert(current_headsets); + + for (int i = 0; i < current_headsets->rowCount();) + { + QString key = current_headsets->item(i)->data().toString(); + if (not std::ranges::any_of(new_headsets, [&](const wivrn_server::HeadsetKey & x) { return x.public_key == key; })) + current_headsets->removeRow(i); + else + i++; + } + + for (const wivrn_server::HeadsetKey & key: new_headsets) + { + bool found = false; + for (int i = 0; i < current_headsets->rowCount(); i++) + { + if (current_headsets->item(i)->data().toString() == key.public_key) + { + found = true; + break; + } + } + + if (not found) + { + QStandardItem * item = new QStandardItem; + item->setText(key.name); + item->setData(key.public_key); + current_headsets->appendRow(item); + } + } +} + +void manage_headsets::on_selection_changed() +{ + ui->button_remove->setDisabled(ui->headset_list->selectionModel()->selection().empty()); +} + +void manage_headsets::on_remove_selected() +{ + QStandardItemModel * current_headsets = dynamic_cast(ui->headset_list->model()); + assert(current_headsets); + + std::vector keys_to_remove; + for (QItemSelectionRange item: ui->headset_list->selectionModel()->selection()) + { + for (QModelIndex index: item.indexes()) + { + keys_to_remove.push_back(current_headsets->item(index.row())->data().toString()); + } + } + + for (QString key: keys_to_remove) + server_interface->revoke_key(key); +} + +void manage_headsets::on_rename_selected(QStandardItem * item) +{ + server_interface->rename_key(item->data().toString(), item->text()); +} diff --git a/dashboard/manage_headsets.h b/dashboard/manage_headsets.h new file mode 100644 index 00000000..86a23263 --- /dev/null +++ b/dashboard/manage_headsets.h @@ -0,0 +1,51 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "wivrn_server.h" +#include +#include + +namespace Ui +{ +class ManageHeadsets; +} +class IoGithubWivrnServerInterface; +class OrgFreedesktopDBusPropertiesInterface; + +class settings; +class wivrn_server; +class wizard; + +class manage_headsets : public QDialog +{ + Q_OBJECT + + Ui::ManageHeadsets * ui; + wivrn_server * server_interface; + +public: + manage_headsets(wivrn_server * server_interface); + +private: + void update_headet_list(const std::vector & keys); + void on_selection_changed(); + void on_remove_selected(); + void on_rename_selected(QStandardItem * item); +}; diff --git a/dashboard/manage_headsets.ui b/dashboard/manage_headsets.ui new file mode 100644 index 00000000..115c13dc --- /dev/null +++ b/dashboard/manage_headsets.ui @@ -0,0 +1,81 @@ + + + ManageHeadsets + + + + 0 + 0 + 541 + 446 + + + + Manage headsets + + + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Remove + + + + + + + + + + Close + + + + + + + + + + + + + + button_close + clicked() + ManageHeadsets + accept() + + + 516 + 426 + + + 494 + 443 + + + + + diff --git a/dashboard/settings.h b/dashboard/settings.h index c511aaf3..7fd2ac88 100644 --- a/dashboard/settings.h +++ b/dashboard/settings.h @@ -39,7 +39,7 @@ class settings : public QDialog void selected_rectangle_changed(int); public: - settings(wivrn_server * server_interface = nullptr); + settings(wivrn_server * server_interface); ~settings(); private: