2018-07-28 12:32:16 -04:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-09-12 01:09:25 -04:00
|
|
|
#include <array>
|
|
|
|
#include <utility>
|
2020-07-20 23:03:49 -04:00
|
|
|
#include <QFileDialog>
|
2018-09-12 01:09:25 -04:00
|
|
|
|
2020-01-25 18:26:07 -05:00
|
|
|
#include <QDirIterator>
|
2018-09-12 01:09:25 -04:00
|
|
|
#include "common/common_types.h"
|
2021-05-25 19:32:56 -04:00
|
|
|
#include "common/fs/path_util.h"
|
2021-04-14 19:07:40 -04:00
|
|
|
#include "common/settings.h"
|
2020-11-27 10:50:48 -05:00
|
|
|
#include "core/core.h"
|
2020-01-23 18:15:51 -05:00
|
|
|
#include "ui_configure_ui.h"
|
|
|
|
#include "yuzu/configuration/configure_ui.h"
|
2019-07-29 16:06:33 -04:00
|
|
|
#include "yuzu/uisettings.h"
|
2018-07-28 12:32:16 -04:00
|
|
|
|
2018-09-12 01:11:25 -04:00
|
|
|
namespace {
|
2019-05-26 00:39:23 -04:00
|
|
|
constexpr std::array default_icon_sizes{
|
2018-09-12 01:11:25 -04:00
|
|
|
std::make_pair(0, QT_TR_NOOP("None")),
|
|
|
|
std::make_pair(32, QT_TR_NOOP("Small (32x32)")),
|
|
|
|
std::make_pair(64, QT_TR_NOOP("Standard (64x64)")),
|
|
|
|
std::make_pair(128, QT_TR_NOOP("Large (128x128)")),
|
|
|
|
std::make_pair(256, QT_TR_NOOP("Full Size (256x256)")),
|
2019-05-26 00:39:23 -04:00
|
|
|
};
|
2018-09-12 01:11:25 -04:00
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
constexpr std::array row_text_names{
|
2020-01-19 15:56:49 -05:00
|
|
|
QT_TR_NOOP("Filename"), QT_TR_NOOP("Filetype"), QT_TR_NOOP("Title ID"),
|
|
|
|
QT_TR_NOOP("Title Name"), QT_TR_NOOP("None"),
|
2019-05-26 00:39:23 -04:00
|
|
|
};
|
2018-09-12 01:11:25 -04:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureUi) {
|
2018-07-28 12:32:16 -04:00
|
|
|
ui->setupUi(this);
|
2020-01-25 18:26:07 -05:00
|
|
|
|
2020-01-25 18:37:48 -05:00
|
|
|
InitializeLanguageComboBox();
|
2018-07-28 12:32:16 -04:00
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
for (const auto& theme : UISettings::themes) {
|
|
|
|
ui->theme_combobox->addItem(QString::fromUtf8(theme.first),
|
|
|
|
QString::fromUtf8(theme.second));
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:06:50 -04:00
|
|
|
InitializeIconSizeComboBox();
|
|
|
|
InitializeRowComboBoxes();
|
|
|
|
|
2019-05-26 00:39:23 -04:00
|
|
|
SetConfiguration();
|
2018-11-03 20:38:39 -04:00
|
|
|
|
|
|
|
// Force game list reload if any of the relevant settings are changed.
|
2021-05-10 10:45:35 -04:00
|
|
|
connect(ui->show_add_ons, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate);
|
2018-11-03 20:38:39 -04:00
|
|
|
connect(ui->icon_size_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2020-01-23 18:15:51 -05:00
|
|
|
&ConfigureUi::RequestGameListUpdate);
|
2018-11-03 20:38:39 -04:00
|
|
|
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2020-01-23 18:15:51 -05:00
|
|
|
&ConfigureUi::RequestGameListUpdate);
|
2018-11-03 20:38:39 -04:00
|
|
|
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2020-01-23 18:15:51 -05:00
|
|
|
&ConfigureUi::RequestGameListUpdate);
|
2020-01-19 15:56:49 -05:00
|
|
|
|
|
|
|
// Update text ComboBoxes after user interaction.
|
|
|
|
connect(ui->row_1_text_combobox, QOverload<int>::of(&QComboBox::activated),
|
2020-08-03 11:28:18 -04:00
|
|
|
[this] { ConfigureUi::UpdateSecondRowComboBox(); });
|
2020-01-19 15:56:49 -05:00
|
|
|
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated),
|
2020-08-03 11:28:18 -04:00
|
|
|
[this] { ConfigureUi::UpdateFirstRowComboBox(); });
|
2020-07-20 23:03:49 -04:00
|
|
|
|
|
|
|
// Set screenshot path to user specification.
|
|
|
|
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
|
2021-05-25 19:32:56 -04:00
|
|
|
auto dir =
|
2020-08-15 08:33:16 -04:00
|
|
|
QFileDialog::getExistingDirectory(this, tr("Select Screenshots Path..."),
|
2021-05-25 19:32:56 -04:00
|
|
|
QString::fromStdString(Common::FS::GetYuzuPathString(
|
|
|
|
Common::FS::YuzuPath::ScreenshotsDir)));
|
|
|
|
if (!dir.isEmpty()) {
|
|
|
|
if (dir.back() != QChar::fromLatin1('/')) {
|
|
|
|
dir.append(QChar::fromLatin1('/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->screenshot_path_edit->setText(dir);
|
2020-07-20 23:11:46 -04:00
|
|
|
}
|
2020-07-20 23:03:49 -04:00
|
|
|
});
|
2018-09-12 01:06:50 -04:00
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
ConfigureUi::~ConfigureUi() = default;
|
2018-09-12 01:06:50 -04:00
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::ApplyConfiguration() {
|
|
|
|
UISettings::values.theme =
|
|
|
|
ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString();
|
2018-11-01 20:27:12 -04:00
|
|
|
UISettings::values.show_add_ons = ui->show_add_ons->isChecked();
|
2018-09-12 01:06:50 -04:00
|
|
|
UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt();
|
|
|
|
UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt();
|
|
|
|
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
|
2020-07-20 23:03:49 -04:00
|
|
|
|
|
|
|
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
|
2021-05-25 19:32:56 -04:00
|
|
|
Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir,
|
2020-08-15 08:33:16 -04:00
|
|
|
ui->screenshot_path_edit->text().toStdString());
|
2021-04-14 19:07:40 -04:00
|
|
|
Core::System::GetInstance().ApplySettings();
|
2018-09-12 01:06:50 -04:00
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::RequestGameListUpdate() {
|
2018-11-03 20:38:39 -04:00
|
|
|
UISettings::values.is_game_list_reload_pending.exchange(true);
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::SetConfiguration() {
|
|
|
|
ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme));
|
2020-01-25 18:26:07 -05:00
|
|
|
ui->language_combobox->setCurrentIndex(
|
|
|
|
ui->language_combobox->findData(UISettings::values.language));
|
2018-11-01 20:27:12 -04:00
|
|
|
ui->show_add_ons->setChecked(UISettings::values.show_add_ons);
|
2018-09-12 01:06:50 -04:00
|
|
|
ui->icon_size_combobox->setCurrentIndex(
|
|
|
|
ui->icon_size_combobox->findData(UISettings::values.icon_size));
|
2020-07-20 23:03:49 -04:00
|
|
|
|
|
|
|
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
|
2021-05-25 19:32:56 -04:00
|
|
|
ui->screenshot_path_edit->setText(QString::fromStdString(
|
|
|
|
Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir)));
|
2018-09-12 01:06:50 -04:00
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::changeEvent(QEvent* event) {
|
2018-09-12 01:11:25 -04:00
|
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
|
|
RetranslateUI();
|
|
|
|
}
|
2018-07-28 12:32:16 -04:00
|
|
|
|
2018-09-12 01:11:25 -04:00
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::RetranslateUI() {
|
2018-09-12 01:11:25 -04:00
|
|
|
ui->retranslateUi(this);
|
|
|
|
|
|
|
|
for (int i = 0; i < ui->icon_size_combobox->count(); i++) {
|
|
|
|
ui->icon_size_combobox->setItemText(i, tr(default_icon_sizes[i].second));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < ui->row_1_text_combobox->count(); i++) {
|
|
|
|
const QString name = tr(row_text_names[i]);
|
|
|
|
|
|
|
|
ui->row_1_text_combobox->setItemText(i, name);
|
|
|
|
ui->row_2_text_combobox->setItemText(i, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 18:37:48 -05:00
|
|
|
void ConfigureUi::InitializeLanguageComboBox() {
|
|
|
|
ui->language_combobox->addItem(tr("<System>"), QString{});
|
|
|
|
ui->language_combobox->addItem(tr("English"), QStringLiteral("en"));
|
|
|
|
QDirIterator it(QStringLiteral(":/languages"), QDirIterator::NoIteratorFlags);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
QString locale = it.next();
|
|
|
|
locale.truncate(locale.lastIndexOf(QLatin1Char{'.'}));
|
|
|
|
locale.remove(0, locale.lastIndexOf(QLatin1Char{'/'}) + 1);
|
|
|
|
const QString lang = QLocale::languageToString(QLocale(locale).language());
|
|
|
|
ui->language_combobox->addItem(lang, locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlike other configuration changes, interface language changes need to be reflected on the
|
|
|
|
// interface immediately. This is done by passing a signal to the main window, and then
|
|
|
|
// retranslating when passing back.
|
|
|
|
connect(ui->language_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ConfigureUi::OnLanguageChanged);
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::InitializeIconSizeComboBox() {
|
2018-07-28 12:32:16 -04:00
|
|
|
for (const auto& size : default_icon_sizes) {
|
2019-05-19 11:16:21 -04:00
|
|
|
ui->icon_size_combobox->addItem(QString::fromUtf8(size.second), size.first);
|
2018-07-28 12:32:16 -04:00
|
|
|
}
|
2018-09-12 01:06:50 -04:00
|
|
|
}
|
2018-07-28 12:32:16 -04:00
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::InitializeRowComboBoxes() {
|
2020-01-19 15:56:49 -05:00
|
|
|
UpdateFirstRowComboBox(true);
|
|
|
|
UpdateSecondRowComboBox(true);
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::UpdateFirstRowComboBox(bool init) {
|
2020-01-19 15:56:49 -05:00
|
|
|
const int currentIndex =
|
|
|
|
init ? UISettings::values.row_1_text_id
|
|
|
|
: ui->row_1_text_combobox->findData(ui->row_1_text_combobox->currentData());
|
2019-05-19 11:16:21 -04:00
|
|
|
|
2020-01-19 15:56:49 -05:00
|
|
|
ui->row_1_text_combobox->clear();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < row_text_names.size(); i++) {
|
|
|
|
const QString row_text_name = QString::fromUtf8(row_text_names[i]);
|
2019-05-19 11:16:21 -04:00
|
|
|
ui->row_1_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
|
2020-01-19 15:56:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->row_1_text_combobox->setCurrentIndex(ui->row_1_text_combobox->findData(currentIndex));
|
|
|
|
|
|
|
|
ui->row_1_text_combobox->removeItem(4); // None
|
|
|
|
ui->row_1_text_combobox->removeItem(
|
|
|
|
ui->row_1_text_combobox->findData(ui->row_2_text_combobox->currentData()));
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:15:51 -05:00
|
|
|
void ConfigureUi::UpdateSecondRowComboBox(bool init) {
|
2020-01-19 15:56:49 -05:00
|
|
|
const int currentIndex =
|
|
|
|
init ? UISettings::values.row_2_text_id
|
|
|
|
: ui->row_2_text_combobox->findData(ui->row_2_text_combobox->currentData());
|
|
|
|
|
|
|
|
ui->row_2_text_combobox->clear();
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < row_text_names.size(); ++i) {
|
|
|
|
const QString row_text_name = QString::fromUtf8(row_text_names[i]);
|
2019-05-19 11:16:21 -04:00
|
|
|
ui->row_2_text_combobox->addItem(row_text_name, QVariant::fromValue(i));
|
2018-07-28 12:32:16 -04:00
|
|
|
}
|
2020-01-19 15:56:49 -05:00
|
|
|
|
|
|
|
ui->row_2_text_combobox->setCurrentIndex(ui->row_2_text_combobox->findData(currentIndex));
|
|
|
|
|
|
|
|
ui->row_2_text_combobox->removeItem(
|
|
|
|
ui->row_2_text_combobox->findData(ui->row_1_text_combobox->currentData()));
|
2018-07-28 12:32:16 -04:00
|
|
|
}
|
2020-01-25 18:26:07 -05:00
|
|
|
|
|
|
|
void ConfigureUi::OnLanguageChanged(int index) {
|
|
|
|
if (index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit LanguageChanged(ui->language_combobox->itemData(index).toString());
|
|
|
|
}
|