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

Make askQuestion more flexible, defaulting to Yes/No

This commit is contained in:
TheLastProject 2015-02-20 16:36:35 +01:00
parent 5b6e2d5ecc
commit 7202b18079
4 changed files with 21 additions and 21 deletions

View File

@ -114,8 +114,8 @@ bool PrivacyForm::setChatLogsPassword()
}
else
{
if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\n\nIf you don't care about the old history, you may click Ok to delete it and use the password you just entered.\nOtherwise, hit cancel to try again.", "This happens when enabling encryption after previously \"Disabling History\""), false, true))
if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("Are you absolutely sure you want to lose the unused encrypted chat history?", "secondary popup"), false, true))
if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("There is currently an unused encrypted chat history, but the password you just entered doesn't match.\n\nIf you don't care about the old history, you may click Ok to delete it and use the password you just entered.\nOtherwise, hit cancel to try again.", "This happens when enabling encryption after previously \"Disabling History\""), false, true, false))
if (GUI::askQuestion(tr("Old encrypted chat history", "popup title"), tr("Are you absolutely sure you want to lose the unused encrypted chat history?", "secondary popup")))
haveEncHist = false; // logically this is really just a `break`, but conceptually this is more accurate
}
} while (haveEncHist);

View File

@ -113,11 +113,12 @@ void GUI::showError(const QString& title, const QString& msg)
}
bool GUI::askQuestion(const QString& title, const QString& msg,
bool defaultAns, bool warning)
bool defaultAns, bool warning,
bool yesno)
{
if (QThread::currentThread() == qApp->thread())
{
return getInstance()._askQuestion(title, msg, defaultAns, warning);
return getInstance()._askQuestion(title, msg, defaultAns, warning, yesno);
}
else
{
@ -125,7 +126,8 @@ bool GUI::askQuestion(const QString& title, const QString& msg,
QMetaObject::invokeMethod(&getInstance(), "_askQuestion", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, ret),
Q_ARG(const QString&, title), Q_ARG(const QString&, msg),
Q_ARG(bool, defaultAns), Q_ARG(bool, warning));
Q_ARG(bool, defaultAns), Q_ARG(bool, warning),
Q_ARG(bool, yesno));
return ret;
}
}
@ -211,22 +213,18 @@ void GUI::_showError(const QString& title, const QString& msg)
}
bool GUI::_askQuestion(const QString& title, const QString& msg,
bool defaultAns, bool warning)
bool defaultAns, bool warning,
bool yesno)
{
QMessageBox::StandardButton positiveButton = yesno ? QMessageBox::Yes : QMessageBox::Ok;
QMessageBox::StandardButton negativeButton = yesno ? QMessageBox::No : QMessageBox::Cancel;
QMessageBox::StandardButton defButton = defaultAns ? positiveButton : negativeButton;
if (warning)
{
QMessageBox::StandardButton def = QMessageBox::Cancel;
if (defaultAns)
def = QMessageBox::Ok;
return QMessageBox::warning(getMainWidget(), title, msg, QMessageBox::Ok | QMessageBox::Cancel, def) == QMessageBox::Ok;
}
return QMessageBox::warning(getMainWidget(), title, msg, positiveButton | negativeButton, defButton) == positiveButton;
else
{
QMessageBox::StandardButton def = QMessageBox::No;
if (defaultAns)
def = QMessageBox::Yes;
return QMessageBox::question(getMainWidget(), title, msg, QMessageBox::Yes | QMessageBox::No, def) == QMessageBox::Yes;
}
return QMessageBox::question(getMainWidget(), title, msg, positiveButton | negativeButton, defButton) == positiveButton;
}
QString GUI::_itemInputDialog(QWidget * parent, const QString & title,

View File

@ -33,7 +33,8 @@ public:
/// If warning is true, we will use a special warning style.
/// Returns the answer.
static bool askQuestion(const QString& title, const QString& msg,
bool defaultAns = false, bool warning = true);
bool defaultAns = false, bool warning = true,
bool yesno = true);
/// Asks the user to input text and returns the answer.
/// The interface is equivalent to QInputDialog::getItem()
static QString itemInputDialog(QWidget * parent, const QString & title,
@ -63,7 +64,8 @@ private slots:
void _showWarning(const QString& title, const QString& msg);
void _showError(const QString& title, const QString& msg);
bool _askQuestion(const QString& title, const QString& msg,
bool defaultAns = false, bool warning = true);
bool defaultAns = false, bool warning = true,
bool yesno = true);
QString _itemInputDialog(QWidget * parent, const QString & title,
const QString & label, const QStringList & items,
int current = 0, bool editable = true, bool * ok = 0,

View File

@ -502,7 +502,7 @@ bool Widget::confirmExecutableOpen(const QFileInfo file)
{
if (file.isExecutable())
{
if(!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text"), false, false))
if(!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text")))
{
return false;
}