Skip to content

Commit

Permalink
Fix translation of FBAboutDialog
Browse files Browse the repository at this point in the history
It needs to react to language change events to behave properly, also to get
the initial language correct.
  • Loading branch information
Vogtinator committed Dec 31, 2022
1 parent 26585bf commit b46ab64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
58 changes: 40 additions & 18 deletions fbaboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QJsonDocument>
#include <QJsonObject>

#include <QEvent>
#include <QIcon>
#include <QDialogButtonBox>
#include <QVBoxLayout>
Expand All @@ -17,41 +18,28 @@
FBAboutDialog::FBAboutDialog(QWidget *parent)
: QDialog(parent)
{
retranslateUi();

QIcon icon{QStringLiteral(":/icons/resources/org.firebird-emus.firebird-emu.png")};
iconLabel.setPixmap(icon.pixmap(icon.actualSize(QSize{64, 64})));

setWindowTitle(tr("About Firebird"));
header.setText(tr("<h3>Firebird %1</h3>"
"<a href='https://github.com/nspire-emus/firebird'>On GitHub</a>").arg(QStringLiteral(STRINGIFY(FB_VERSION))));
header.setTextInteractionFlags(Qt::TextBrowserInteraction);
header.setOpenExternalLinks(true);

update.setText(tr("Checking for update"));
update.setTextInteractionFlags(Qt::TextBrowserInteraction);
update.setOpenExternalLinks(true);

authors.setText(tr( "Authors:<br>"
"Fabian Vogt (<a href='https://github.com/Vogtinator'>Vogtinator</a>)<br>"
"Adrien Bertrand (<a href='https://github.com/adriweb'>Adriweb</a>)<br>"
"Antonio Vasquez (<a href='https://github.com/antoniovazquezblanco'>antoniovazquezblanco</a>)<br>"
"Lionel Debroux (<a href='https://github.com/debrouxl'>debrouxl</a>)<br>"
"Denis Avashurov (<a href='https://github.com/denisps'>denisps</a>)<br>"
"Based on nspire_emu v0.70 by Goplat<br><br>"
"This work is licensed under the GPLv3.<br>"
"To view a copy of this license, visit <a href='https://www.gnu.org/licenses/gpl-3.0.html'>https://www.gnu.org/licenses/gpl-3.0.html</a>"));
authors.setTextInteractionFlags(Qt::TextBrowserInteraction);
authors.setOpenExternalLinks(true);

auto *okButton = new QPushButton(tr("Ok"));
connect(okButton, SIGNAL(clicked(bool)), this, SLOT(close()));
okButton->setDefault(true);
connect(&okButton, SIGNAL(clicked(bool)), this, SLOT(close()));
okButton.setDefault(true);

updateButton.setText(tr("Check for Update"));
updateButton.setAutoDefault(false);
connect(&updateButton, SIGNAL(clicked(bool)), this, SLOT(checkForUpdate()));

auto *buttonBox = new QDialogButtonBox(Qt::Horizontal);
buttonBox->addButton(okButton, QDialogButtonBox::AcceptRole);
buttonBox->addButton(&okButton, QDialogButtonBox::AcceptRole);
buttonBox->addButton(&updateButton, QDialogButtonBox::ActionRole);

auto *layout = new QVBoxLayout;
Expand All @@ -65,6 +53,40 @@ FBAboutDialog::FBAboutDialog(QWidget *parent)
hlayout->addLayout(layout);
}

void FBAboutDialog::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
retranslateUi();

QDialog::changeEvent(event);
}

void FBAboutDialog::retranslateUi()
{
setWindowTitle(tr("About Firebird"));
header.setText(tr("<h3>Firebird %1</h3>"
"<a href='https://github.com/nspire-emus/firebird'>On GitHub</a>").arg(QStringLiteral(STRINGIFY(FB_VERSION))));

authors.setText(tr( "Authors:<br>"
"Fabian Vogt (<a href='https://github.com/Vogtinator'>Vogtinator</a>)<br>"
"Adrien Bertrand (<a href='https://github.com/adriweb'>Adriweb</a>)<br>"
"Antonio Vasquez (<a href='https://github.com/antoniovazquezblanco'>antoniovazquezblanco</a>)<br>"
"Lionel Debroux (<a href='https://github.com/debrouxl'>debrouxl</a>)<br>"
"Denis Avashurov (<a href='https://github.com/denisps'>denisps</a>)<br>"
"Based on nspire_emu v0.70 by Goplat<br><br>"
"This work is licensed under the GPLv3.<br>"
"To view a copy of this license, visit <a href='https://www.gnu.org/licenses/gpl-3.0.html'>https://www.gnu.org/licenses/gpl-3.0.html</a>"));

update.setText(tr("Checking for update"));

okButton.setText(tr("Ok"));
updateButton.setText(tr("Check for Update"));

// If necessary, refresh the status text. Easiest way is to just check again.
if(isVisible() || checkSuccessful)
QTimer::singleShot(0, this, SLOT(checkForUpdate()));
}

void FBAboutDialog::checkForUpdate()
{
updateButton.setDisabled(true);
Expand Down
7 changes: 6 additions & 1 deletion fbaboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public slots:

void setVisible(bool v) override;

protected:
void changeEvent(QEvent* event) override;

private:
void retranslateUi();

bool checkSuccessful = false;

QLabel iconLabel, header, update, authors;
QPushButton updateButton;
QPushButton okButton, updateButton;
QNetworkReply *reply;
QNetworkAccessManager nam;
};
Expand Down

0 comments on commit b46ab64

Please sign in to comment.