1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat(gui, setpassworddialog): Added buttons translation

Fix #3479.
This commit is contained in:
Diadlo 2016-07-30 12:10:49 +03:00
parent a556762c54
commit 58e503bb14
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
2 changed files with 35 additions and 22 deletions

View File

@ -19,6 +19,8 @@
#include "setpassworddialog.h" #include "setpassworddialog.h"
#include "ui_setpassworddialog.h" #include "ui_setpassworddialog.h"
#include <QApplication>
#include <QPushButton> #include <QPushButton>
const double SetPasswordDialog::reasonablePasswordLength = 8.; const double SetPasswordDialog::reasonablePasswordLength = 8.;
@ -34,7 +36,11 @@ SetPasswordDialog::SetPasswordDialog(QString body, QString extraButton, QWidget*
connect(ui->repasswordlineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPasswordEdit())); connect(ui->repasswordlineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPasswordEdit()));
ui->body->setText(body + "\n\n"); ui->body->setText(body + "\n\n");
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); QPushButton *ok = ui->buttonBox->button(QDialogButtonBox::Ok);
ok->setEnabled(false);
ok->setText(QApplication::tr("Ok"));
QPushButton *cancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
cancel->setText(QApplication::tr("Cancel"));
if (!extraButton.isEmpty()) if (!extraButton.isEmpty())
{ {

View File

@ -22,6 +22,7 @@
#include "widget.h" #include "widget.h"
#include "src/nexus.h" #include "src/nexus.h"
#include <assert.h> #include <assert.h>
#include <QApplication>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QDialogButtonBox> #include <QDialogButtonBox>
@ -199,7 +200,7 @@ void GUI::showError(const QString& title, const QString& msg)
} }
/** /**
@brief Asks the user a question with Ok/Cansel or Yes/No buttons. @brief Asks the user a question with Ok/Cancel or Yes/No buttons.
@param title Title of question window. @param title Title of question window.
@param msg Text in question window. @param msg Text in question window.
@param defaultAns If is true, default was positive answer. Negative otherwise. @param defaultAns If is true, default was positive answer. Negative otherwise.
@ -335,7 +336,7 @@ void GUI::_setWindowTitle(const QString& title)
if (title.isEmpty()) if (title.isEmpty())
getMainWidget()->setWindowTitle("qTox"); getMainWidget()->setWindowTitle("qTox");
else else
getMainWidget()->setWindowTitle("qTox - " +title); getMainWidget()->setWindowTitle("qTox - " + title);
} }
void GUI::_reloadTheme() void GUI::_reloadTheme()
@ -345,17 +346,23 @@ void GUI::_reloadTheme()
void GUI::_showInfo(const QString& title, const QString& msg) void GUI::_showInfo(const QString& title, const QString& msg)
{ {
QMessageBox::information(getMainWidget(), title, msg); QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok, getMainWidget());
messageBox.setButtonText(QMessageBox::Ok, QApplication::tr("Ok"));
messageBox.exec();
} }
void GUI::_showWarning(const QString& title, const QString& msg) void GUI::_showWarning(const QString& title, const QString& msg)
{ {
QMessageBox::warning(getMainWidget(), title, msg); QMessageBox messageBox(QMessageBox::Warning, title, msg, QMessageBox::Ok, getMainWidget());
messageBox.setButtonText(QMessageBox::Ok, QApplication::tr("Ok"));
messageBox.exec();
} }
void GUI::_showError(const QString& title, const QString& msg) void GUI::_showError(const QString& title, const QString& msg)
{ {
QMessageBox::critical(getMainWidget(), title, msg); QMessageBox messageBox(QMessageBox::Critical, title, msg, QMessageBox::Ok, getMainWidget());
messageBox.setButtonText(QMessageBox::Ok, QApplication::tr("Ok"));
messageBox.exec();
} }
void GUI::_showUpdateDownloadProgress() void GUI::_showUpdateDownloadProgress()
@ -367,23 +374,18 @@ bool GUI::_askQuestion(const QString& title, const QString& msg,
bool defaultAns, bool warning, bool defaultAns, bool warning,
bool yesno) bool yesno)
{ {
QMessageBox::StandardButton positiveButton = yesno ? QMessageBox::Yes : QMessageBox::Ok; QString positiveButton = yesno ? QApplication::tr("Yes") : QApplication::tr("Ok");
QMessageBox::StandardButton negativeButton = yesno ? QMessageBox::No : QMessageBox::Cancel; QString negativeButton = yesno ? QApplication::tr("No") : QApplication::tr("Cancel");
QMessageBox::StandardButton defButton = defaultAns ? positiveButton : negativeButton; return _askQuestion(title, msg, positiveButton, negativeButton, defaultAns, warning);
if (warning)
return QMessageBox::warning(getMainWidget(), title, msg, positiveButton | negativeButton, defButton) == positiveButton;
else
return QMessageBox::question(getMainWidget(), title, msg, positiveButton | negativeButton, defButton) == positiveButton;
} }
bool GUI::_askQuestion(const QString& title, const QString& msg, bool GUI::_askQuestion(const QString& title, const QString& msg,
const QString& button1, const QString& button2, const QString& button1, const QString& button2,
bool defaultAns, bool warning) bool defaultAns, bool warning)
{ {
QMessageBox box(warning ? QMessageBox::Warning : QMessageBox::Question, QMessageBox::Icon icon = warning ? QMessageBox::Warning : QMessageBox::Question;
title, msg, QMessageBox::NoButton, getMainWidget()); QMessageBox box(icon, title, msg, QMessageBox::NoButton, getMainWidget());
QPushButton* pushButton1 = box.addButton(button1, QMessageBox::AcceptRole); QPushButton* pushButton1 = box.addButton(button1, QMessageBox::AcceptRole);
QPushButton* pushButton2 = box.addButton(button2, QMessageBox::RejectRole); QPushButton* pushButton2 = box.addButton(button2, QMessageBox::RejectRole);
box.setDefaultButton(defaultAns ? pushButton1 : pushButton2); box.setDefaultButton(defaultAns ? pushButton1 : pushButton2);
@ -429,14 +431,20 @@ QString GUI::_passwordDialog(const QString& cancel, const QString& body)
{ {
ok->setAutoDefault(false); ok->setAutoDefault(false);
ok->setDefault(false); ok->setDefault(false);
ok->setText(QApplication::tr("Ok"));
cancel->setAutoDefault(true); cancel->setAutoDefault(true);
cancel->setDefault(true); cancel->setDefault(true);
cancel->setText(QApplication::tr("Cancel"));
} }
else else
{
qWarning() << "PasswordDialog: Missing button!"; qWarning() << "PasswordDialog: Missing button!";
} }
}
else else
{
qWarning() << "PasswordDialog: No QDialogButtonBox!"; qWarning() << "PasswordDialog: No QDialogButtonBox!";
}
// using similar code, set QLabels to wrap // using similar code, set QLabels to wrap
for (auto* label : dialog.findChildren<QLabel*>()) for (auto* label : dialog.findChildren<QLabel*>())
@ -447,12 +455,11 @@ QString GUI::_passwordDialog(const QString& cancel, const QString& body)
int val = dialog.exec(); int val = dialog.exec();
if (val == QDialog::Accepted) if (val == QDialog::Accepted)
return QString(); return QString();
else
{
ret = dialog.textValue(); ret = dialog.textValue();
if (!ret.isEmpty()) if (!ret.isEmpty())
return ret; return ret;
}
dialog.setTextValue(""); dialog.setTextValue("");
dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:")); dialog.setLabelText(body + "\n\n" + tr("You must enter a non-empty password:"));
} }