24 #include <QApplication>
25 #include <QCoreApplication>
27 #include <QDialogButtonBox>
28 #include <QInputDialog>
30 #include <QMessageBox>
31 #include <QPushButton>
49 assert(QThread::currentThread() == qApp->thread());
71 if (QThread::currentThread() == qApp->thread()) {
74 QMetaObject::invokeMethod(&
getInstance(),
"_setEnabled", Qt::BlockingQueuedConnection,
87 if (QThread::currentThread() == qApp->thread()) {
90 QMetaObject::invokeMethod(&
getInstance(),
"_setWindowTitle", Qt::BlockingQueuedConnection,
91 Q_ARG(
const QString&, title));
103 if (QThread::currentThread() == qApp->thread()) {
106 QMetaObject::invokeMethod(&
getInstance(),
"themeReload", Qt::BlockingQueuedConnection);
117 if (QThread::currentThread() == qApp->thread()) {
120 QMetaObject::invokeMethod(&
getInstance(),
"_showInfo", Qt::BlockingQueuedConnection,
121 Q_ARG(
const QString&, title), Q_ARG(
const QString&, msg));
132 if (QThread::currentThread() == qApp->thread()) {
135 QMetaObject::invokeMethod(&
getInstance(),
"_showWarning", Qt::BlockingQueuedConnection,
136 Q_ARG(
const QString&, title), Q_ARG(
const QString&, msg));
147 if (QThread::currentThread() == qApp->thread()) {
151 QMessageBox::critical(
nullptr, title, msg);
155 QMetaObject::invokeMethod(&
getInstance(),
"_showError", Qt::BlockingQueuedConnection,
156 Q_ARG(
const QString&, title), Q_ARG(
const QString&, msg));
169 bool GUI::askQuestion(
const QString& title,
const QString& msg,
bool defaultAns,
bool warning,
bool yesno)
171 if (QThread::currentThread() == qApp->thread()) {
175 QMetaObject::invokeMethod(&
getInstance(),
"_askQuestion", Qt::BlockingQueuedConnection,
176 Q_RETURN_ARG(
bool, ret), Q_ARG(
const QString&, title),
177 Q_ARG(
const QString&, msg), Q_ARG(
bool, defaultAns),
178 Q_ARG(
bool, warning), Q_ARG(
bool, yesno));
196 const QString& button2,
bool defaultAns,
bool warning)
198 if (QThread::currentThread() == qApp->thread()) {
202 QMetaObject::invokeMethod(&
getInstance(),
"_askQuestion", Qt::BlockingQueuedConnection,
203 Q_RETURN_ARG(
bool, ret), Q_ARG(
const QString&, title),
204 Q_ARG(
const QString&, msg), Q_ARG(
bool, defaultAns),
205 Q_ARG(
bool, warning));
216 w->setEnabled(state);
225 w->setWindowTitle(
"qTox");
227 w->setWindowTitle(title +
" - qTox");
232 QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok,
getMainWidget());
233 messageBox.setButtonText(QMessageBox::Ok, QApplication::tr(
"Ok"));
239 QMessageBox messageBox(QMessageBox::Warning, title, msg, QMessageBox::Ok,
getMainWidget());
240 messageBox.setButtonText(QMessageBox::Ok, QApplication::tr(
"Ok"));
246 QMessageBox messageBox(QMessageBox::Critical, title, msg, QMessageBox::Ok,
getMainWidget());
247 messageBox.setButtonText(QMessageBox::Ok, QApplication::tr(
"Ok"));
254 QString positiveButton = yesno ? QApplication::tr(
"Yes") : QApplication::tr(
"Ok");
255 QString negativeButton = yesno ? QApplication::tr(
"No") : QApplication::tr(
"Cancel");
257 return _askQuestion(title, msg, positiveButton, negativeButton, defaultAns, warning);
261 const QString& button2,
bool defaultAns,
bool warning)
263 QMessageBox::Icon icon = warning ? QMessageBox::Warning : QMessageBox::Question;
264 QMessageBox box(icon, title, msg, QMessageBox::NoButton,
getMainWidget());
265 QPushButton* pushButton1 = box.addButton(button1, QMessageBox::AcceptRole);
266 QPushButton* pushButton2 = box.addButton(button2, QMessageBox::RejectRole);
267 box.setDefaultButton(defaultAns ? pushButton1 : pushButton2);
268 box.setEscapeButton(pushButton2);
271 return box.clickedButton() == pushButton1;
282 QWidget* maingui{
nullptr};