Port yuzu-emu/yuzu#2457: "yuzu/{about_dialog, main}: Specify string conversions explicitly for SCM-related info" (#4774)

* yuzu/about_dialog: Specify string conversions explicitly

Specifies the conversions explicitly to avoid implicit conversions from
const char* to QString. This makes it easier to disable implicit QString
conversions in the future.

In this case, the implicit conversion was technically wrong as well. The
implicit conversion treats the input strings as ASCII characters. This
would result in an incorrect conversion being performed in the rare case
a branch name was created with a non-ASCII Unicode character, likely
resulting in junk being displayed.

* yuzu/main: Move window title updating logic to its own function

For similar reasons to the previous change, we move this to a single
function, so we don't need to duplicate the conversion logic in several
places within main.cpp.
This commit is contained in:
Tobias 2019-08-10 11:01:18 +02:00 committed by Ben
parent 0269cb6e67
commit d80edd99d7
3 changed files with 14 additions and 12 deletions

View file

@ -11,10 +11,10 @@ AboutDialog::AboutDialog(QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(new Ui::AboutDialog) { ui(new Ui::AboutDialog) {
ui->setupUi(this); ui->setupUi(this);
ui->labelLogo->setPixmap(QIcon::fromTheme("citra").pixmap(200)); ui->labelLogo->setPixmap(QIcon::fromTheme(QStringLiteral("citra")).pixmap(200));
ui->labelBuildInfo->setText( ui->labelBuildInfo->setText(ui->labelBuildInfo->text().arg(
ui->labelBuildInfo->text().arg(Common::g_build_fullname, Common::g_scm_branch, QString::fromUtf8(Common::g_build_fullname), QString::fromUtf8(Common::g_scm_branch),
Common::g_scm_desc, QString(Common::g_build_date).left(10))); QString::fromUtf8(Common::g_scm_desc), QString::fromUtf8(Common::g_build_date).left(10)));
} }
AboutDialog::~AboutDialog() = default; AboutDialog::~AboutDialog() = default;

View file

@ -158,9 +158,9 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
ConnectMenuEvents(); ConnectMenuEvents();
ConnectWidgetEvents(); ConnectWidgetEvents();
SetupUIStrings();
LOG_INFO(Frontend, "Citra Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch, LOG_INFO(Frontend, "Citra Version: {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch,
Common::g_scm_desc); Common::g_scm_desc);
UpdateWindowTitle();
show(); show();
@ -797,7 +797,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
std::string title; std::string title;
system.GetAppLoader().ReadTitle(title); system.GetAppLoader().ReadTitle(title);
game_title = QString::fromStdString(title); game_title = QString::fromStdString(title);
SetupUIStrings(); UpdateWindowTitle();
game_path = filename; game_path = filename;
@ -927,7 +927,7 @@ void GMainWindow::ShutdownGame() {
} }
game_title.clear(); game_title.clear();
SetupUIStrings(); UpdateWindowTitle();
game_path.clear(); game_path.clear();
} }
@ -1813,7 +1813,7 @@ void GMainWindow::OnLanguageChanged(const QString& locale) {
LoadTranslation(); LoadTranslation();
ui.retranslateUi(this); ui.retranslateUi(this);
RetranslateStatusBar(); RetranslateStatusBar();
SetupUIStrings(); UpdateWindowTitle();
if (emulation_running) if (emulation_running)
ui.action_Start->setText(tr("Continue")); ui.action_Start->setText(tr("Continue"));
@ -1826,11 +1826,13 @@ void GMainWindow::OnMoviePlaybackCompleted() {
ui.action_Stop_Recording_Playback->setEnabled(false); ui.action_Stop_Recording_Playback->setEnabled(false);
} }
void GMainWindow::SetupUIStrings() { void GMainWindow::UpdateWindowTitle() {
const QString full_name = QString::fromUtf8(Common::g_build_fullname);
if (game_title.isEmpty()) { if (game_title.isEmpty()) {
setWindowTitle(tr("Citra %1").arg(Common::g_build_fullname)); setWindowTitle(tr("Citra %1").arg(full_name));
} else { } else {
setWindowTitle(tr("Citra %1| %2").arg(Common::g_build_fullname, game_title)); setWindowTitle(tr("Citra %1| %2").arg(full_name, game_title));
} }
} }

View file

@ -197,7 +197,7 @@ private:
Q_INVOKABLE void OnMoviePlaybackCompleted(); Q_INVOKABLE void OnMoviePlaybackCompleted();
void UpdateStatusBar(); void UpdateStatusBar();
void LoadTranslation(); void LoadTranslation();
void SetupUIStrings(); void UpdateWindowTitle();
void RetranslateStatusBar(); void RetranslateStatusBar();
void InstallCIA(QStringList filepaths); void InstallCIA(QStringList filepaths);