dolphin/Source/Core/DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.cpp
Vincent Duvert b08e2ec959 GCAdapter: Report libusb open errors to the user
If opening the adapter fails, report the libusb error message in the GUI
instead of “No Adapter Detected”.

The error condition is removed when the adapter is unplugged.
2019-05-29 18:28:24 +02:00

86 lines
2.3 KiB
C++

// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QVBoxLayout>
#include "Core/ConfigManager.h"
#include "InputCommon/GCAdapter.h"
GCPadWiiUConfigDialog::GCPadWiiUConfigDialog(int port, QWidget* parent)
: QDialog(parent), m_port{port}
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
CreateLayout();
LoadSettings();
ConnectWidgets();
}
void GCPadWiiUConfigDialog::CreateLayout()
{
setWindowTitle(tr("GameCube Adapter for Wii U at Port %1").arg(m_port + 1));
const char* error_message = nullptr;
const bool detected = GCAdapter::IsDetected(&error_message);
QString status_text;
if (detected)
{
status_text = tr("Adapter Detected");
}
else if (error_message)
{
status_text = tr("Error Opening Adapter: %1").arg(QString::fromUtf8(error_message));
}
else
{
status_text = tr("No Adapter Detected");
}
m_layout = new QVBoxLayout();
m_status_label = new QLabel(status_text);
m_rumble = new QCheckBox(tr("Enable Rumble"));
m_simulate_bongos = new QCheckBox(tr("Simulate DK Bongos"));
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok);
m_layout->addWidget(m_status_label);
m_layout->addWidget(m_rumble);
m_layout->addWidget(m_simulate_bongos);
m_layout->addWidget(m_button_box);
if (!detected)
{
m_rumble->setEnabled(false);
m_simulate_bongos->setEnabled(false);
}
setLayout(m_layout);
}
void GCPadWiiUConfigDialog::ConnectWidgets()
{
connect(m_rumble, &QCheckBox::toggled, this, &GCPadWiiUConfigDialog::SaveSettings);
connect(m_simulate_bongos, &QCheckBox::toggled, this, &GCPadWiiUConfigDialog::SaveSettings);
connect(m_button_box, &QDialogButtonBox::accepted, this, &GCPadWiiUConfigDialog::accept);
}
void GCPadWiiUConfigDialog::LoadSettings()
{
m_rumble->setChecked(SConfig::GetInstance().m_AdapterRumble[m_port]);
m_simulate_bongos->setChecked(SConfig::GetInstance().m_AdapterKonga[m_port]);
}
void GCPadWiiUConfigDialog::SaveSettings()
{
SConfig::GetInstance().m_AdapterRumble[m_port] = m_rumble->isChecked();
SConfig::GetInstance().m_AdapterKonga[m_port] = m_simulate_bongos->isChecked();
}