2022-02-07 15:00:02 +06:00
|
|
|
/*
|
2023-01-06 15:36:05 -05:00
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* This file is part of the 86Box distribution.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Device configuration UI code.
|
2022-02-07 15:00:02 +06:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
|
2022-02-07 15:00:02 +06:00
|
|
|
* Cacodemon345
|
|
|
|
|
*
|
2023-01-06 15:36:05 -05:00
|
|
|
* Copyright 2021 Joakim L. Gilje
|
|
|
|
|
* Copyright 2022 Cacodemon345
|
2022-02-07 15:00:02 +06:00
|
|
|
*/
|
2021-11-25 10:20:56 +01:00
|
|
|
#include "qt_deviceconfig.hpp"
|
|
|
|
|
#include "ui_qt_deviceconfig.h"
|
2022-02-09 00:29:19 +06:00
|
|
|
#include "qt_settings.hpp"
|
2021-11-25 10:20:56 +01:00
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QComboBox>
|
2024-05-03 17:02:13 +02:00
|
|
|
#include <QPushButton>
|
2021-11-25 10:20:56 +01:00
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
#include <QCheckBox>
|
2023-01-20 22:58:56 +06:00
|
|
|
#include <QFrame>
|
2023-02-16 00:00:31 +06:00
|
|
|
#include <QLineEdit>
|
2023-01-20 22:58:56 +06:00
|
|
|
#include <QLabel>
|
2023-02-14 20:37:58 -05:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QSettings>
|
2021-11-25 10:20:56 +01:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include <86box/86box.h>
|
2022-09-10 13:32:46 +02:00
|
|
|
#include <86box/ini.h>
|
2021-11-25 10:20:56 +01:00
|
|
|
#include <86box/config.h>
|
|
|
|
|
#include <86box/device.h>
|
2021-12-17 11:10:32 +01:00
|
|
|
#include <86box/midi_rtmidi.h>
|
2022-07-22 23:35:18 -04:00
|
|
|
#include <86box/mem.h>
|
2024-03-29 08:23:55 -04:00
|
|
|
#include <86box/random.h>
|
2022-07-22 23:35:18 -04:00
|
|
|
#include <86box/rom.h>
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "qt_filefield.hpp"
|
2021-12-06 10:29:53 +01:00
|
|
|
#include "qt_models_common.hpp"
|
2023-02-14 20:37:58 -05:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
# include <sys/stat.h>
|
|
|
|
|
# include <sys/sysmacros.h>
|
|
|
|
|
#endif
|
2023-02-15 23:09:41 +06:00
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#endif
|
2021-11-25 10:20:56 +01:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
DeviceConfig::DeviceConfig(QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, ui(new Ui::DeviceConfig)
|
2021-11-25 10:20:56 +01:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceConfig::~DeviceConfig()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 20:37:58 -05:00
|
|
|
static QStringList
|
|
|
|
|
EnumerateSerialDevices()
|
|
|
|
|
{
|
2023-05-29 01:30:51 -04:00
|
|
|
QStringList serialDevices;
|
|
|
|
|
QStringList ttyEntries;
|
2023-02-14 20:37:58 -05:00
|
|
|
QByteArray devstr(1024, 0);
|
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
QDir class_dir("/sys/class/tty/");
|
|
|
|
|
QDir dev_dir("/dev/");
|
|
|
|
|
ttyEntries = class_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::System, QDir::SortFlag::Name);
|
|
|
|
|
for (int i = 0; i < ttyEntries.size(); i++) {
|
|
|
|
|
if (class_dir.exists(ttyEntries[i] + "/device/driver/") && dev_dir.exists(ttyEntries[i])
|
|
|
|
|
&& QFileInfo(dev_dir.canonicalPath() + '/' + ttyEntries[i]).isReadable()
|
|
|
|
|
&& QFileInfo(dev_dir.canonicalPath() + '/' + ttyEntries[i]).isWritable()) {
|
|
|
|
|
serialDevices.push_back("/dev/" + ttyEntries[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef Q_OS_WINDOWS
|
2023-02-15 23:09:41 +06:00
|
|
|
for (int i = 1; i < 256; i++) {
|
|
|
|
|
devstr[0] = 0;
|
2024-05-03 17:02:13 +02:00
|
|
|
snprintf(devstr.data(), 1024, R"(\\.\COM%d)", i);
|
|
|
|
|
const auto handle = CreateFileA(devstr.data(),
|
|
|
|
|
GENERIC_READ | GENERIC_WRITE, 0,
|
|
|
|
|
nullptr, OPEN_EXISTING,
|
|
|
|
|
0, nullptr);
|
|
|
|
|
const auto dwError = GetLastError();
|
|
|
|
|
if ((handle != INVALID_HANDLE_VALUE) || (dwError == ERROR_ACCESS_DENIED) ||
|
|
|
|
|
(dwError == ERROR_GEN_FAILURE) || (dwError == ERROR_SHARING_VIOLATION) ||
|
|
|
|
|
(dwError == ERROR_SEM_TIMEOUT)) {
|
2023-02-15 23:09:41 +06:00
|
|
|
if (handle != INVALID_HANDLE_VALUE) CloseHandle(handle);
|
|
|
|
|
serialDevices.push_back(QString(devstr));
|
|
|
|
|
}
|
2023-02-14 20:37:58 -05:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
|
QDir dev_dir("/dev/");
|
|
|
|
|
dev_dir.setNameFilters({ "tty.*", "cu.*" });
|
|
|
|
|
QDir::Filters serial_dev_flags = QDir::Files | QDir::NoSymLinks | QDir::Readable | QDir::Writable | QDir::NoDotAndDotDot | QDir::System;
|
|
|
|
|
for (const auto &device : dev_dir.entryInfoList(serial_dev_flags, QDir::SortFlag::Name)) {
|
|
|
|
|
serialDevices.push_back(device.canonicalFilePath());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return serialDevices;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
void
|
2024-05-03 17:02:13 +02:00
|
|
|
DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
|
2022-11-19 08:49:04 -05:00
|
|
|
{
|
2024-05-03 17:02:13 +02:00
|
|
|
auto * device_context = static_cast<device_context_t *>(dc);
|
|
|
|
|
const auto * config = static_cast<const _device_config_ *>(c);
|
|
|
|
|
const QString blank = "";
|
|
|
|
|
int p;
|
|
|
|
|
int q;
|
2021-11-25 10:20:56 +01:00
|
|
|
|
|
|
|
|
while (config->type != -1) {
|
2024-05-03 17:02:13 +02:00
|
|
|
const int config_type = config->type & CONFIG_TYPE_MASK;
|
|
|
|
|
|
|
|
|
|
/* Ignore options of the wrong class. */
|
|
|
|
|
if (!!(config->type & CONFIG_DEP) != is_dep)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If this is a BIOS-dependent option and it's BIOS, ignore it. */
|
|
|
|
|
if (!!(config->type & CONFIG_DEP) && (config_type == CONFIG_BIOS))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const int config_major_type = (config_type >> CONFIG_SHIFT) << CONFIG_SHIFT;
|
|
|
|
|
|
|
|
|
|
int value = 0;
|
2024-05-08 13:55:21 -04:00
|
|
|
auto selected = blank;
|
2024-05-03 17:02:13 +02:00
|
|
|
|
|
|
|
|
switch (config_major_type) {
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
case CONFIG_TYPE_INT:
|
|
|
|
|
value = config_get_int(device_context->name, const_cast<char *>(config->name),
|
|
|
|
|
config->default_int);
|
|
|
|
|
break;
|
|
|
|
|
case CONFIG_TYPE_HEX16:
|
|
|
|
|
value = config_get_hex16(device_context->name, const_cast<char *>(config->name),
|
|
|
|
|
config->default_int);
|
|
|
|
|
break;
|
|
|
|
|
case CONFIG_TYPE_HEX20:
|
|
|
|
|
value = config_get_hex20(device_context->name, const_cast<char *>(config->name),
|
|
|
|
|
config->default_int);
|
|
|
|
|
break;
|
|
|
|
|
case CONFIG_TYPE_STRING:
|
|
|
|
|
selected = config_get_string(device_context->name, const_cast<char *>(config->name),
|
|
|
|
|
const_cast<char *>(config->default_string));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 10:20:56 +01:00
|
|
|
switch (config->type) {
|
2024-05-03 17:02:13 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_BINARY:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QCheckBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setChecked(value > 0);
|
|
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-03-11 20:41:00 +01:00
|
|
|
#ifdef USE_RTMIDI
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_MIDI_OUT:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QComboBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setMaxVisibleItems(30);
|
|
|
|
|
auto *model = cbox->model();
|
|
|
|
|
int currentIndex = -1;
|
|
|
|
|
for (int i = 0; i < rtmidi_out_get_num_devs(); i++) {
|
|
|
|
|
char midiName[512] = { 0 };
|
|
|
|
|
rtmidi_out_get_dev_name(i, midiName);
|
2021-11-25 10:20:56 +01:00
|
|
|
|
2024-05-03 17:02:13 +02:00
|
|
|
Models::AddEntry(model, midiName, i);
|
|
|
|
|
if (i == value)
|
|
|
|
|
currentIndex = i;
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
cbox->setCurrentIndex(currentIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_MIDI_IN:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QComboBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setMaxVisibleItems(30);
|
|
|
|
|
auto *model = cbox->model();
|
|
|
|
|
int currentIndex = -1;
|
|
|
|
|
for (int i = 0; i < rtmidi_in_get_num_devs(); i++) {
|
|
|
|
|
char midiName[512] = { 0 };
|
|
|
|
|
rtmidi_in_get_dev_name(i, midiName);
|
2021-12-03 02:12:35 +06:00
|
|
|
|
2024-05-03 17:02:13 +02:00
|
|
|
Models::AddEntry(model, midiName, i);
|
|
|
|
|
if (i == value)
|
|
|
|
|
currentIndex = i;
|
2021-12-03 02:12:35 +06:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
cbox->setCurrentIndex(currentIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-03-11 20:41:00 +01:00
|
|
|
#endif
|
2024-05-03 17:02:13 +02:00
|
|
|
case CONFIG_INT:
|
2021-12-06 10:29:53 +01:00
|
|
|
case CONFIG_SELECTION:
|
|
|
|
|
case CONFIG_HEX16:
|
|
|
|
|
case CONFIG_HEX20:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QComboBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setMaxVisibleItems(30);
|
|
|
|
|
auto *model = cbox->model();
|
|
|
|
|
int currentIndex = -1;
|
2021-12-03 02:12:35 +06:00
|
|
|
|
2024-05-03 17:02:13 +02:00
|
|
|
for (auto *sel = config->selection; (sel != nullptr) && (sel->description != nullptr) &&
|
|
|
|
|
(strlen(sel->description) > 0); ++sel) {
|
|
|
|
|
int row = Models::AddEntry(model, sel->description, sel->value);
|
|
|
|
|
|
|
|
|
|
if (sel->value == value)
|
|
|
|
|
currentIndex = row;
|
2021-12-03 02:12:35 +06:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
cbox->setCurrentIndex(currentIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_BIOS:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QComboBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setMaxVisibleItems(30);
|
|
|
|
|
auto *model = cbox->model();
|
|
|
|
|
int currentIndex = -1;
|
2022-07-22 23:35:18 -04:00
|
|
|
|
2024-05-03 17:02:13 +02:00
|
|
|
q = 0;
|
|
|
|
|
for (auto *bios = config->bios; (bios != nullptr) && (bios->name != nullptr) &&
|
|
|
|
|
(strlen(bios->name) > 0); ++bios) {
|
|
|
|
|
p = 0;
|
|
|
|
|
for (int d = 0; d < bios->files_no; d++)
|
|
|
|
|
p += !!rom_present(const_cast<char *>(bios->files[d]));
|
|
|
|
|
if (p == bios->files_no) {
|
|
|
|
|
const int row = Models::AddEntry(model, bios->name, q);
|
2024-05-08 13:55:21 -04:00
|
|
|
if (!strcmp(selected.toUtf8().constData(), bios->internal_name))
|
2024-05-03 17:02:13 +02:00
|
|
|
currentIndex = row;
|
2022-07-22 23:35:18 -04:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
q++;
|
2022-11-19 08:49:04 -05:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
cbox->setCurrentIndex(currentIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_SPINNER:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *spinBox = new QSpinBox();
|
|
|
|
|
spinBox->setObjectName(config->name);
|
|
|
|
|
spinBox->setMaximum(config->spinner.max);
|
|
|
|
|
spinBox->setMinimum(config->spinner.min);
|
|
|
|
|
if (config->spinner.step > 0)
|
|
|
|
|
spinBox->setSingleStep(config->spinner.step);
|
|
|
|
|
spinBox->setValue(value);
|
|
|
|
|
this->ui->formLayout->addRow(config->description, spinBox);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_FNAME:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *fileField = new FileField();
|
|
|
|
|
fileField->setObjectName(config->name);
|
|
|
|
|
fileField->setFileName(selected);
|
|
|
|
|
fileField->setFilter(QString(config->file_filter).left(static_cast<int>(strcspn(config->file_filter,
|
|
|
|
|
"|"))));
|
|
|
|
|
this->ui->formLayout->addRow(config->description, fileField);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-16 00:00:31 +06:00
|
|
|
case CONFIG_STRING:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
const auto lineEdit = new QLineEdit;
|
|
|
|
|
lineEdit->setObjectName(config->name);
|
|
|
|
|
lineEdit->setCursor(Qt::IBeamCursor);
|
|
|
|
|
lineEdit->setText(selected);
|
|
|
|
|
this->ui->formLayout->addRow(config->description, lineEdit);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-14 20:37:58 -05:00
|
|
|
case CONFIG_SERPORT:
|
2024-05-03 17:02:13 +02:00
|
|
|
{
|
|
|
|
|
auto *cbox = new QComboBox();
|
|
|
|
|
cbox->setObjectName(config->name);
|
|
|
|
|
cbox->setMaxVisibleItems(30);
|
|
|
|
|
auto *model = cbox->model();
|
|
|
|
|
int currentIndex = 0;
|
|
|
|
|
auto serialDevices = EnumerateSerialDevices();
|
2023-02-14 20:37:58 -05:00
|
|
|
|
2024-05-03 17:02:13 +02:00
|
|
|
Models::AddEntry(model, "None", -1);
|
|
|
|
|
for (int i = 0; i < serialDevices.size(); i++) {
|
|
|
|
|
const int row = Models::AddEntry(model, serialDevices[i], i);
|
|
|
|
|
if (selected == serialDevices[i])
|
|
|
|
|
currentIndex = row;
|
2023-02-14 20:37:58 -05:00
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
|
|
|
|
|
this->ui->formLayout->addRow(config->description, cbox);
|
|
|
|
|
cbox->setCurrentIndex(currentIndex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-29 08:23:55 -04:00
|
|
|
case CONFIG_MAC:
|
|
|
|
|
{
|
|
|
|
|
// QHBoxLayout for the line edit widget and the generate button
|
2024-05-03 17:02:13 +02:00
|
|
|
const auto hboxLayout = new QHBoxLayout();
|
|
|
|
|
const auto generateButton = new QPushButton(tr("Generate"));
|
|
|
|
|
const auto lineEdit = new QLineEdit;
|
2024-03-29 08:23:55 -04:00
|
|
|
// Allow the line edit to expand and fill available space
|
|
|
|
|
lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
|
|
|
|
|
lineEdit->setInputMask("HH:HH:HH;0");
|
|
|
|
|
lineEdit->setObjectName(config->name);
|
|
|
|
|
// Display the current or generated MAC in uppercase
|
|
|
|
|
// When stored it will be converted to lowercase
|
2024-05-03 17:02:13 +02:00
|
|
|
if (config_get_mac(device_context->name, config->name,
|
|
|
|
|
config->default_int) & 0xFF000000) {
|
|
|
|
|
lineEdit->setText(QString::asprintf("%02X:%02X:%02X", random_generate(),
|
|
|
|
|
random_generate(), random_generate()));
|
2024-03-29 08:23:55 -04:00
|
|
|
} else {
|
2024-05-03 17:02:13 +02:00
|
|
|
auto current_mac = QString(config_get_string(device_context->name, config->name,
|
|
|
|
|
const_cast<char *>(config->default_string)));
|
2024-03-29 08:23:55 -04:00
|
|
|
lineEdit->setText(current_mac.toUpper());
|
|
|
|
|
}
|
|
|
|
|
// Action for the generate button
|
|
|
|
|
connect(generateButton, &QPushButton::clicked, [lineEdit] {
|
2024-05-03 17:02:13 +02:00
|
|
|
lineEdit->setText(QString::asprintf("%02X:%02X:%02X", random_generate(),
|
|
|
|
|
random_generate(), random_generate()));
|
2024-03-29 08:23:55 -04:00
|
|
|
});
|
|
|
|
|
hboxLayout->addWidget(lineEdit);
|
|
|
|
|
hboxLayout->addWidget(generateButton);
|
2024-05-03 17:02:13 +02:00
|
|
|
this->ui->formLayout->addRow(config->description, hboxLayout);
|
2024-03-29 08:23:55 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
|
|
|
|
++config;
|
|
|
|
|
}
|
2024-05-03 17:02:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *settings)
|
|
|
|
|
{
|
|
|
|
|
DeviceConfig dc(settings);
|
|
|
|
|
dc.setWindowTitle(QString("%1 Device Configuration").arg(device->name));
|
|
|
|
|
|
|
|
|
|
device_context_t device_context;
|
|
|
|
|
device_set_context(&device_context, device, instance);
|
|
|
|
|
|
|
|
|
|
const auto device_label = new QLabel(device->name);
|
|
|
|
|
device_label->setAlignment(Qt::AlignCenter);
|
|
|
|
|
dc.ui->formLayout->addRow(device_label);
|
|
|
|
|
const auto line = new QFrame;
|
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
dc.ui->formLayout->addRow(line);
|
|
|
|
|
const _device_config_ *config = device->config;
|
|
|
|
|
|
|
|
|
|
dc.ProcessConfig(&device_context, config, false);
|
2021-11-25 10:20:56 +01:00
|
|
|
|
2022-02-06 01:50:30 +06:00
|
|
|
dc.setFixedSize(dc.minimumSizeHint());
|
2024-05-03 17:02:13 +02:00
|
|
|
if (dc.exec() == QDialog::Accepted) {
|
2021-11-25 10:20:56 +01:00
|
|
|
config = device->config;
|
|
|
|
|
while (config->type != -1) {
|
|
|
|
|
switch (config->type) {
|
2024-05-03 17:02:13 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_BINARY:
|
|
|
|
|
{
|
2024-05-03 17:02:13 +02:00
|
|
|
const auto *cbox = dc.findChild<QCheckBox *>(config->name);
|
2022-11-19 08:49:04 -05:00
|
|
|
config_set_int(device_context.name, const_cast<char *>(config->name), cbox->isChecked() ? 1 : 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONFIG_MIDI_OUT:
|
|
|
|
|
case CONFIG_MIDI_IN:
|
|
|
|
|
case CONFIG_SELECTION:
|
|
|
|
|
{
|
|
|
|
|
auto *cbox = dc.findChild<QComboBox *>(config->name);
|
|
|
|
|
config_set_int(device_context.name, const_cast<char *>(config->name), cbox->currentData().toInt());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONFIG_BIOS:
|
|
|
|
|
{
|
|
|
|
|
auto *cbox = dc.findChild<QComboBox *>(config->name);
|
|
|
|
|
int idx = cbox->currentData().toInt();
|
|
|
|
|
config_set_string(device_context.name, const_cast<char *>(config->name), const_cast<char *>(config->bios[idx].internal_name));
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-14 20:37:58 -05:00
|
|
|
case CONFIG_SERPORT:
|
|
|
|
|
{
|
|
|
|
|
auto *cbox = dc.findChild<QComboBox *>(config->name);
|
|
|
|
|
auto path = cbox->currentText().toUtf8();
|
|
|
|
|
if (path == "None")
|
|
|
|
|
path = "";
|
|
|
|
|
config_set_string(device_context.name, const_cast<char *>(config->name), path);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-16 00:00:31 +06:00
|
|
|
case CONFIG_STRING:
|
|
|
|
|
{
|
|
|
|
|
auto *lineEdit = dc.findChild<QLineEdit *>(config->name);
|
|
|
|
|
config_set_string(device_context.name, const_cast<char *>(config->name), lineEdit->text().toUtf8());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-11-19 08:49:04 -05:00
|
|
|
case CONFIG_HEX16:
|
|
|
|
|
{
|
|
|
|
|
auto *cbox = dc.findChild<QComboBox *>(config->name);
|
|
|
|
|
config_set_hex16(device_context.name, const_cast<char *>(config->name), cbox->currentData().toInt());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONFIG_HEX20:
|
|
|
|
|
{
|
|
|
|
|
auto *cbox = dc.findChild<QComboBox *>(config->name);
|
|
|
|
|
config_set_hex20(device_context.name, const_cast<char *>(config->name), cbox->currentData().toInt());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONFIG_FNAME:
|
|
|
|
|
{
|
|
|
|
|
auto *fbox = dc.findChild<FileField *>(config->name);
|
|
|
|
|
auto fileName = fbox->fileName().toUtf8();
|
|
|
|
|
config_set_string(device_context.name, const_cast<char *>(config->name), fileName.data());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CONFIG_SPINNER:
|
|
|
|
|
{
|
|
|
|
|
auto *spinBox = dc.findChild<QSpinBox *>(config->name);
|
|
|
|
|
config_set_int(device_context.name, const_cast<char *>(config->name), spinBox->value());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-29 08:23:55 -04:00
|
|
|
case CONFIG_MAC:
|
|
|
|
|
{
|
|
|
|
|
const auto *lineEdit = dc.findChild<QLineEdit *>(config->name);
|
|
|
|
|
// Store the mac address as lowercase
|
|
|
|
|
auto macText = lineEdit->displayText().toLower();
|
|
|
|
|
config_set_string(device_context.name, config->name, macText.toUtf8().constData());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
|
|
|
|
config++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
QString
|
2024-05-03 17:02:13 +02:00
|
|
|
DeviceConfig::DeviceName(const _device_ *device, const char *internalName, const int bus)
|
2022-11-19 08:49:04 -05:00
|
|
|
{
|
2024-05-03 17:02:13 +02:00
|
|
|
if (QStringLiteral("none") == internalName)
|
2022-01-06 01:41:57 +06:00
|
|
|
return tr("None");
|
2024-05-03 17:02:13 +02:00
|
|
|
else if (QStringLiteral("internal") == internalName)
|
2022-01-06 01:41:57 +06:00
|
|
|
return tr("Internal controller");
|
2024-05-03 17:02:13 +02:00
|
|
|
else if (device == nullptr)
|
|
|
|
|
return "";
|
|
|
|
|
else {
|
2021-11-25 10:20:56 +01:00
|
|
|
char temp[512];
|
|
|
|
|
device_get_name(device, bus, temp);
|
2022-01-06 16:58:11 +06:00
|
|
|
return tr(temp, nullptr, 512);
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
|
|
|
|
}
|