1
0
Fork 0

yuzu/configuration: Specify string conversions explicitly

This commit is contained in:
Lioncash 2019-07-26 21:11:14 +02:00 committed by fearlessTobi
parent 45ff10c9a0
commit 64a154e890
8 changed files with 98 additions and 67 deletions

View File

@ -19,9 +19,9 @@ ConfigureAudio::ConfigureAudio(QWidget* parent)
ui->setupUi(this); ui->setupUi(this);
ui->output_sink_combo_box->clear(); ui->output_sink_combo_box->clear();
ui->output_sink_combo_box->addItem("auto"); ui->output_sink_combo_box->addItem(QString::fromUtf8(AudioCore::auto_device_name));
for (const char* id : AudioCore::GetSinkIDs()) { for (const char* id : AudioCore::GetSinkIDs()) {
ui->output_sink_combo_box->addItem(id); ui->output_sink_combo_box->addItem(QString::fromUtf8(id));
} }
ui->emulation_combo_box->addItem(tr("HLE (fast)")); ui->emulation_combo_box->addItem(tr("HLE (fast)"));
@ -131,7 +131,7 @@ void ConfigureAudio::ApplyConfiguration() {
void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) { void ConfigureAudio::UpdateAudioOutputDevices(int sink_index) {
ui->audio_device_combo_box->clear(); ui->audio_device_combo_box->clear();
ui->audio_device_combo_box->addItem(AudioCore::auto_device_name); ui->audio_device_combo_box->addItem(QString::fromUtf8(AudioCore::auto_device_name));
const std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString(); const std::string sink_id = ui->output_sink_combo_box->itemText(sink_index).toStdString();
for (const auto& device : AudioCore::GetDeviceListForSink(sink_id)) { for (const auto& device : AudioCore::GetDeviceListForSink(sink_id)) {

View File

@ -84,7 +84,7 @@ void ConfigureCamera::ConnectEvents() {
ui->camera_file->setDisabled(state == Qt::Checked); ui->camera_file->setDisabled(state == Qt::Checked);
ui->toolButton->setDisabled(state == Qt::Checked); ui->toolButton->setDisabled(state == Qt::Checked);
if (state == Qt::Checked) { if (state == Qt::Checked) {
ui->camera_file->setText(""); ui->camera_file->setText(QString{});
} }
}); });
connect(ui->camera_file, &QLineEdit::textChanged, this, [=] { StopPreviewing(); }); connect(ui->camera_file, &QLineEdit::textChanged, this, [=] { StopPreviewing(); });
@ -120,7 +120,7 @@ void ConfigureCamera::UpdateImageSourceUI() {
ui->prompt_before_load->setChecked(false); ui->prompt_before_load->setChecked(false);
ui->camera_file_label->setHidden(true); ui->camera_file_label->setHidden(true);
ui->camera_file->setHidden(true); ui->camera_file->setHidden(true);
ui->camera_file->setText(""); ui->camera_file->setText(QString{});
ui->toolButton->setHidden(true); ui->toolButton->setHidden(true);
break; break;
case 1: /* still image */ case 1: /* still image */
@ -132,7 +132,7 @@ void ConfigureCamera::UpdateImageSourceUI() {
ui->prompt_before_load->setChecked(true); ui->prompt_before_load->setChecked(true);
ui->camera_file->setDisabled(true); ui->camera_file->setDisabled(true);
ui->toolButton->setDisabled(true); ui->toolButton->setDisabled(true);
ui->camera_file->setText(""); ui->camera_file->setText(QString{});
} else { } else {
ui->camera_file->setDisabled(false); ui->camera_file->setDisabled(false);
ui->toolButton->setDisabled(false); ui->toolButton->setDisabled(false);
@ -250,7 +250,7 @@ void ConfigureCamera::SetConfiguration() {
ui->camera_file->setDisabled(camera_config[index].empty()); ui->camera_file->setDisabled(camera_config[index].empty());
ui->toolButton->setDisabled(camera_config[index].empty()); ui->toolButton->setDisabled(camera_config[index].empty());
if (camera_config[index].empty()) { if (camera_config[index].empty()) {
ui->camera_file->setText(""); ui->camera_file->setText(QString{});
} }
} }
if (camera_name[index] == "qt") { if (camera_name[index] == "qt") {
@ -270,10 +270,10 @@ void ConfigureCamera::OnToolButtonClicked() {
QList<QByteArray> types = QImageReader::supportedImageFormats(); QList<QByteArray> types = QImageReader::supportedImageFormats();
QList<QString> temp_filters; QList<QString> temp_filters;
for (const QByteArray& type : types) { for (const QByteArray& type : types) {
temp_filters << QString("*." + QString(type)); temp_filters << QString("*." + QString::fromUtf8(type));
} }
QString filter = tr("Supported image files (%1)").arg(temp_filters.join(" ")); QString filter = tr("Supported image files (%1)").arg(temp_filters.join(QStringLiteral(" ")));
QString path = QFileDialog::getOpenFileName(this, tr("Open File"), ".", filter); QString path = QFileDialog::getOpenFileName(this, tr("Open File"), QStringLiteral("."), filter);
if (!path.isEmpty()) { if (!path.isEmpty()) {
ui->camera_file->setText(path); ui->camera_file->setText(path);
} }

View File

@ -72,11 +72,10 @@ void ConfigureDialog::PopulateSelectionList() {
ui->selectorList->clear(); ui->selectorList->clear();
const std::array<std::pair<QString, QStringList>, 4> items{ const std::array<std::pair<QString, QStringList>, 4> items{
{{tr("General"), {{tr("General"), {tr("General"), tr("Web"), tr("Debug"), tr("UI")}},
{QT_TR_NOOP("General"), QT_TR_NOOP("Web"), QT_TR_NOOP("Debug"), QT_TR_NOOP("UI")}}, {tr("System"), {tr("System"), tr("Audio"), tr("Camera")}},
{tr("System"), {QT_TR_NOOP("System"), QT_TR_NOOP("Audio"), QT_TR_NOOP("Camera")}}, {tr("Graphics"), {tr("Graphics")}},
{tr("Graphics"), {QT_TR_NOOP("Graphics")}}, {tr("Controls"), {tr("Input"), tr("Hotkeys")}}}};
{tr("Controls"), {QT_TR_NOOP("Input"), QT_TR_NOOP("Hotkeys")}}}};
for (const auto& entry : items) { for (const auto& entry : items) {
auto* const item = new QListWidgetItem(entry.first); auto* const item = new QListWidgetItem(entry.first);
@ -121,11 +120,11 @@ void ConfigureDialog::UpdateVisibleTabs() {
return; return;
const std::map<QString, QWidget*> widgets = { const std::map<QString, QWidget*> widgets = {
{"General", ui->generalTab}, {"System", ui->systemTab}, {QStringLiteral("General"), ui->generalTab}, {QStringLiteral("System"), ui->systemTab},
{"Input", ui->inputTab}, {"Hotkeys", ui->hotkeysTab}, {QStringLiteral("Input"), ui->inputTab}, {QStringLiteral("Hotkeys"), ui->hotkeysTab},
{"Graphics", ui->graphicsTab}, {"Audio", ui->audioTab}, {QStringLiteral("Graphics"), ui->graphicsTab}, {QStringLiteral("Audio"), ui->audioTab},
{"Camera", ui->cameraTab}, {"Debug", ui->debugTab}, {QStringLiteral("Camera"), ui->cameraTab}, {QStringLiteral("Debug"), ui->debugTab},
{"Web", ui->webTab}, {"UI", ui->uiTab}}; {QStringLiteral("Web"), ui->webTab}, {QStringLiteral("UI"), ui->uiTab}};
ui->tabWidget->clear(); ui->tabWidget->clear();

View File

@ -32,7 +32,7 @@ static QString GetKeyName(int key_code) {
case Qt::Key_Alt: case Qt::Key_Alt:
return QObject::tr("Alt"); return QObject::tr("Alt");
case Qt::Key_Meta: case Qt::Key_Meta:
return ""; return QString{};
default: default:
return QKeySequence(key_code).toString(); return QKeySequence(key_code).toString();
} }
@ -52,46 +52,70 @@ static void SetAnalogButton(const Common::ParamPackage& input_param,
static QString ButtonToText(const Common::ParamPackage& param) { static QString ButtonToText(const Common::ParamPackage& param) {
if (!param.Has("engine")) { if (!param.Has("engine")) {
return QObject::tr("[not set]"); return QObject::tr("[not set]");
} else if (param.Get("engine", "") == "keyboard") { }
if (param.Get("engine", "") == "keyboard") {
return GetKeyName(param.Get("code", 0)); return GetKeyName(param.Get("code", 0));
} else if (param.Get("engine", "") == "sdl") { }
if (param.Get("engine", "") == "sdl") {
if (param.Has("hat")) { if (param.Has("hat")) {
return QString(QObject::tr("Hat %1 %2")) const QString hat_str = QString::fromStdString(param.Get("hat", ""));
.arg(param.Get("hat", "").c_str(), param.Get("direction", "").c_str()); const QString direction_str = QString::fromStdString(param.Get("direction", ""));
return QObject::tr("Hat %1 %2").arg(hat_str, direction_str);
} }
if (param.Has("axis")) { if (param.Has("axis")) {
return QString(QObject::tr("Axis %1%2")) const QString axis_str = QString::fromStdString(param.Get("axis", ""));
.arg(param.Get("axis", "").c_str(), param.Get("direction", "").c_str()); const QString direction_str = QString::fromStdString(param.Get("direction", ""));
return QObject::tr("Axis %1%2").arg(axis_str, direction_str);
} }
if (param.Has("button")) { if (param.Has("button")) {
return QString(QObject::tr("Button %1")).arg(param.Get("button", "").c_str()); const QString button_str = QString::fromStdString(param.Get("button", ""));
return QObject::tr("Button %1").arg(button_str);
} }
return QString();
} else { return {};
}
return QObject::tr("[unknown]"); return QObject::tr("[unknown]");
} }
};
static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) { static QString AnalogToText(const Common::ParamPackage& param, const std::string& dir) {
if (!param.Has("engine")) { if (!param.Has("engine")) {
return QObject::tr("[not set]"); return QObject::tr("[not set]");
} else if (param.Get("engine", "") == "analog_from_button") { }
if (param.Get("engine", "") == "analog_from_button") {
return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); return ButtonToText(Common::ParamPackage{param.Get(dir, "")});
} else if (param.Get("engine", "") == "sdl") { }
if (param.Get("engine", "") == "sdl") {
if (dir == "modifier") { if (dir == "modifier") {
return QString(QObject::tr("[unused]")); return QObject::tr("[unused]");
} }
if (dir == "left" || dir == "right") { if (dir == "left" || dir == "right") {
return QString(QObject::tr("Axis %1")).arg(param.Get("axis_x", "").c_str()); const QString axis_x_str = QString::fromStdString(param.Get("axis_x", ""));
} else if (dir == "up" || dir == "down") {
return QString(QObject::tr("Axis %1")).arg(param.Get("axis_y", "").c_str()); return QObject::tr("Axis %1").arg(axis_x_str);
} }
return QString();
} else { if (dir == "up" || dir == "down") {
const QString axis_y_str = QString::fromStdString(param.Get("axis_y", ""));
return QObject::tr("Axis %1").arg(axis_y_str);
}
return {};
}
return QObject::tr("[unknown]"); return QObject::tr("[unknown]");
} }
};
ConfigureInput::ConfigureInput(QWidget* parent) ConfigureInput::ConfigureInput(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),

View File

@ -81,10 +81,10 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureMotionTouch>()) { : QDialog(parent), ui(std::make_unique<Ui::ConfigureMotionTouch>()) {
ui->setupUi(this); ui->setupUi(this);
for (auto [provider, name] : MotionProviders) { for (auto [provider, name] : MotionProviders) {
ui->motion_provider->addItem(tr(name), provider); ui->motion_provider->addItem(tr(name), QString::fromUtf8(provider));
} }
for (auto [provider, name] : TouchProviders) { for (auto [provider, name] : TouchProviders) {
ui->touch_provider->addItem(tr(name), provider); ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider));
} }
ui->udp_learn_more->setOpenExternalLinks(true); ui->udp_learn_more->setOpenExternalLinks(true);
@ -140,7 +140,7 @@ void ConfigureMotionTouch::UpdateUiDisplay() {
ui->touch_calibration->setVisible(true); ui->touch_calibration->setVisible(true);
ui->touch_calibration_config->setVisible(true); ui->touch_calibration_config->setVisible(true);
ui->touch_calibration_label->setVisible(true); ui->touch_calibration_label->setVisible(true);
ui->touch_calibration->setText(QString("(%1, %2) - (%3, %4)") ui->touch_calibration->setText(QStringLiteral("(%1, %2) - (%3, %4)")
.arg(QString::number(min_x), QString::number(min_y), .arg(QString::number(min_x), QString::number(min_y),
QString::number(max_x), QString::number(max_y))); QString::number(max_x), QString::number(max_y)));
} else { } else {

View File

@ -389,7 +389,7 @@ void ConfigureSystem::UpdateBirthdayComboBox(int birthmonth_index) {
void ConfigureSystem::ConfigureTime() { void ConfigureSystem::ConfigureTime() {
ui->edit_init_time->setCalendarPopup(true); ui->edit_init_time->setCalendarPopup(true);
QDateTime dt; QDateTime dt;
dt.fromString("2000-01-01 00:00:01", "yyyy-MM-dd hh:mm:ss"); dt.fromString(QStringLiteral("2000-01-01 00:00:01"), QStringLiteral("yyyy-MM-dd hh:mm:ss"));
ui->edit_init_time->setMinimumDateTime(dt); ui->edit_init_time->setMinimumDateTime(dt);
SetConfiguration(); SetConfiguration();

View File

@ -9,13 +9,13 @@
ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureUi) { ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureUi) {
ui->setupUi(this); ui->setupUi(this);
ui->language_combobox->addItem(tr("<System>"), QString("")); ui->language_combobox->addItem(tr("<System>"), QString{});
ui->language_combobox->addItem(tr("English"), QString("en")); ui->language_combobox->addItem(tr("English"), QStringLiteral("en"));
QDirIterator it(":/languages", QDirIterator::NoIteratorFlags); QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags);
while (it.hasNext()) { while (it.hasNext()) {
QString locale = it.next(); QString locale = it.next();
locale.truncate(locale.lastIndexOf('.')); locale.truncate(locale.lastIndexOf(QLatin1Char{'.'}));
locale.remove(0, locale.lastIndexOf('/') + 1); locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1);
QString lang = QLocale::languageToString(QLocale(locale).language()); QString lang = QLocale::languageToString(QLocale(locale).language());
ui->language_combobox->addItem(lang, locale); ui->language_combobox->addItem(lang, locale);
} }
@ -28,7 +28,8 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur
&ConfigureUi::OnLanguageChanged); &ConfigureUi::OnLanguageChanged);
for (const auto& theme : UISettings::themes) { for (const auto& theme : UISettings::themes) {
ui->theme_combobox->addItem(theme.first, theme.second); ui->theme_combobox->addItem(QString::fromUtf8(theme.first),
QString::fromUtf8(theme.second));
} }
SetConfiguration(); SetConfiguration();

View File

@ -80,12 +80,16 @@ void ConfigureWeb::RefreshTelemetryID() {
void ConfigureWeb::OnLoginChanged() { void ConfigureWeb::OnLoginChanged() {
if (ui->edit_username->text().isEmpty() && ui->edit_token->text().isEmpty()) { if (ui->edit_username->text().isEmpty() && ui->edit_token->text().isEmpty()) {
user_verified = true; user_verified = true;
ui->label_username_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
ui->label_token_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16)); const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
ui->label_username_verified->setPixmap(pixmap);
ui->label_token_verified->setPixmap(pixmap);
} else { } else {
user_verified = false; user_verified = false;
ui->label_username_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16));
ui->label_token_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16)); const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
ui->label_username_verified->setPixmap(pixmap);
ui->label_token_verified->setPixmap(pixmap);
} }
} }
@ -103,11 +107,14 @@ void ConfigureWeb::OnLoginVerified() {
ui->button_verify_login->setText(tr("Verify")); ui->button_verify_login->setText(tr("Verify"));
if (verify_watcher.result()) { if (verify_watcher.result()) {
user_verified = true; user_verified = true;
ui->label_username_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16));
ui->label_token_verified->setPixmap(QIcon::fromTheme("checked").pixmap(16)); const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16);
ui->label_username_verified->setPixmap(pixmap);
ui->label_token_verified->setPixmap(pixmap);
} else { } else {
ui->label_username_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16)); const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16);
ui->label_token_verified->setPixmap(QIcon::fromTheme("failed").pixmap(16)); ui->label_username_verified->setPixmap(pixmap);
ui->label_token_verified->setPixmap(pixmap);
QMessageBox::critical( QMessageBox::critical(
this, tr("Verification failed"), this, tr("Verification failed"),
tr("Verification failed. Check that you have entered your username and token " tr("Verification failed. Check that you have entered your username and token "