UI: add a dialog that shows local hardware IDs
This commit is contained in:
parent
482e8bf3e2
commit
a4130ba373
10 changed files with 260 additions and 42 deletions
123
qt/OpenRGBHardwareIDsDialog.cpp
Normal file
123
qt/OpenRGBHardwareIDsDialog.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#include "OpenRGBHardwareIDsDialog.h"
|
||||
#include "ui_OpenRGBHardwareIDsDialog.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
#include "ResourceManager.h"
|
||||
#include "StringUtils.h"
|
||||
#include <QString>
|
||||
#include <QClipboard>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <libusb.h>
|
||||
#else
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#endif
|
||||
|
||||
Ui::OpenRGBHardwareIDsDialog::OpenRGBHardwareIDsDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::OpenRGBHardwareIDsDialogUi)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
Ui::OpenRGBHardwareIDsDialog::~OpenRGBHardwareIDsDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
int Ui::OpenRGBHardwareIDsDialog::show()
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Add i2c busses infos |
|
||||
\*---------------------------------------------------------*/
|
||||
std::vector<i2c_smbus_interface*> i2CBusses = ResourceManager::get()->GetI2CBusses();
|
||||
|
||||
strings.push_back("i2c busses");
|
||||
|
||||
for(i2c_smbus_interface* bus : i2CBusses)
|
||||
{
|
||||
char line[512];
|
||||
sprintf(line, "%04X:%04X %04X:%04X - %s", bus->pci_vendor, bus->pci_device, bus->pci_subsystem_vendor, bus->pci_subsystem_device, bus->device_name);
|
||||
strings.push_back(line);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Add HID devices infos |
|
||||
\*---------------------------------------------------------*/
|
||||
hid_device_info* hid_devices = NULL;
|
||||
hid_devices = hid_enumerate(0,0);
|
||||
|
||||
hid_device_info* current_hid_device;
|
||||
current_hid_device = hid_devices;
|
||||
|
||||
strings.push_back("HID devices");
|
||||
|
||||
while(current_hid_device)
|
||||
{
|
||||
const char* manu_name = StringUtils::wchar_to_char(current_hid_device->manufacturer_string);
|
||||
const char* prod_name = StringUtils::wchar_to_char(current_hid_device->product_string);
|
||||
|
||||
char line[512];
|
||||
|
||||
sprintf(line, "[%04X:%04X U=%04X P=0x%04X I=%d] %s - %s", current_hid_device->vendor_id, current_hid_device->product_id, current_hid_device->usage, current_hid_device->usage_page, current_hid_device->interface_number, manu_name, prod_name);
|
||||
|
||||
strings.push_back(line);
|
||||
current_hid_device = current_hid_device->next;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Add LibUSB devices infos |
|
||||
\*---------------------------------------------------------*/
|
||||
libusb_device** devices = nullptr;
|
||||
|
||||
strings.push_back("LibUSB devices");
|
||||
|
||||
int ret;
|
||||
|
||||
ret = libusb_init(NULL);
|
||||
|
||||
if(ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = libusb_get_device_list(NULL, &devices);
|
||||
|
||||
if(ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deviceCount = ret;
|
||||
|
||||
for(int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
libusb_device* device = devices[i];
|
||||
libusb_device_descriptor descriptor;
|
||||
|
||||
ret = libusb_get_device_descriptor(device, &descriptor);
|
||||
|
||||
if(ret < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
sprintf(line, "%04X:%04X", descriptor.idVendor, descriptor.idProduct);
|
||||
strings.push_back(line);
|
||||
}
|
||||
|
||||
if(devices != nullptr)
|
||||
{
|
||||
libusb_free_device_list(devices, 1);
|
||||
}
|
||||
|
||||
ui->HardwareIdsList->addItems(strings);
|
||||
|
||||
return this->exec();
|
||||
}
|
||||
|
||||
void Ui::OpenRGBHardwareIDsDialog::on_CopyToClipboardButton_clicked()
|
||||
{
|
||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||
clipboard->setText(strings.join("\n"));
|
||||
}
|
||||
31
qt/OpenRGBHardwareIDsDialog.h
Normal file
31
qt/OpenRGBHardwareIDsDialog.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef OPENRGBHARDWAREIDSDIALOG_H
|
||||
#define OPENRGBHARDWAREIDSDIALOG_H
|
||||
|
||||
#include "ui_OpenRGBHardwareIDsDialog.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class OpenRGBHardwareIDsDialog;
|
||||
}
|
||||
|
||||
class Ui::OpenRGBHardwareIDsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OpenRGBHardwareIDsDialog(QWidget *parent = nullptr);
|
||||
~OpenRGBHardwareIDsDialog();
|
||||
|
||||
int show();
|
||||
|
||||
private slots:
|
||||
void on_CopyToClipboardButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::OpenRGBHardwareIDsDialogUi *ui;
|
||||
QStringList strings;
|
||||
};
|
||||
|
||||
#endif // OPENRGBHARDWAREIDSDIALOG_H
|
||||
31
qt/OpenRGBHardwareIDsDialog.ui
Normal file
31
qt/OpenRGBHardwareIDsDialog.ui
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OpenRGBHardwareIDsDialogUi</class>
|
||||
<widget class="QWidget" name="OpenRGBHardwareIDsDialogUi">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>425</width>
|
||||
<height>273</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListWidget" name="HardwareIdsList"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="CopyToClipboardButton">
|
||||
<property name="text">
|
||||
<string>Copy to clipboard</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#include "OpenRGBSupportedDevicesPage.h"
|
||||
#include "ui_OpenRGBSupportedDevicesPage.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "OpenRGBHardwareIDsDialog.h"
|
||||
|
||||
using namespace Ui;
|
||||
|
||||
|
|
@ -52,6 +53,12 @@ void OpenRGBSupportedDevicesPage::on_SaveButton_clicked()
|
|||
detectorTableModel->applySettings();
|
||||
}
|
||||
|
||||
void OpenRGBSupportedDevicesPage::on_GetHardwareIDsButton_clicked()
|
||||
{
|
||||
OpenRGBHardwareIDsDialog dialog(this);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
void OpenRGBSupportedDevicesPage::on_Filter_textChanged(const QString &arg1)
|
||||
{
|
||||
#ifdef _QT6
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public:
|
|||
private slots:
|
||||
void changeEvent(QEvent *event);
|
||||
void on_SaveButton_clicked();
|
||||
void on_GetHardwareIDsButton_clicked();
|
||||
|
||||
void on_Filter_textChanged(const QString &arg1);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="GetHardwareIDsButton">
|
||||
<property name="text">
|
||||
<string>Get hardware IDs</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue