mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-20 17:11:36 -08:00
Add GUI to remove and rename known headsets
This commit is contained in:
1 parent
1dae8c1421
commit
dfdff6f3e4
8 files changed
+250
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -394,9 +394,9 @@ border-radius: 5px;
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_known_headsets">
|
||||
<widget class="QPushButton" name="button_manage_headsets">
|
||||
<property name="text">
|
||||
<string>Known headsets</string>
|
||||
<string>Manage headsets</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <[email protected]>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "manage_headsets.h"
|
||||
#include "ui_manage_headsets.h"
|
||||
#include "wivrn_server.h"
|
||||
#include <QStandardItemModel>
|
||||
#include <algorithm>
|
||||
|
||||
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<QStandardItemModel *>(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<wivrn_server::HeadsetKey> & new_headsets)
|
||||
{
|
||||
QStandardItemModel * current_headsets = dynamic_cast<QStandardItemModel *>(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<QStandardItemModel *>(ui->headset_list->model());
|
||||
assert(current_headsets);
|
||||
|
||||
std::vector<QString> 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());
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <[email protected]>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wivrn_server.h"
|
||||
#include <QDialog>
|
||||
#include <QStandardItem>
|
||||
|
||||
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<wivrn_server::HeadsetKey> & keys);
|
||||
void on_selection_changed();
|
||||
void on_remove_selected();
|
||||
void on_rename_selected(QStandardItem * item);
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ManageHeadsets</class>
|
||||
<widget class="QDialog" name="ManageHeadsets">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>541</width>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Manage headsets</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="headset_list"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_remove">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-remove"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_close">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="window-close"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>button_close</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ManageHeadsets</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>516</x>
|
||||
<y>426</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>494</x>
|
||||
<y>443</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user