diff --git a/qtox.pro b/qtox.pro index 7211d468d..6cf51185e 100644 --- a/qtox.pro +++ b/qtox.pro @@ -163,8 +163,7 @@ HEADERS += src/widget/form/addfriendform.h \ src/autoupdate.h \ src/misc/serialize.h \ src/widget/form/settings/advancedform.h \ - src/audio.h \ - src/widget/form/checkcontinue.h + src/audio.h SOURCES += \ src/widget/form/addfriendform.cpp \ @@ -231,8 +230,7 @@ SOURCES += \ src/autoupdate.cpp \ src/misc/serialize.cpp \ src/widget/form/settings/advancedform.cpp \ - src/audio.cpp \ - src/widget/form/checkcontinue.cpp + src/audio.cpp contains(DEFINES, QTOX_PLATFORM_EXT) { HEADERS += src/platform/timer.h diff --git a/src/autoupdate.cpp b/src/autoupdate.cpp index 8c2a2ef02..a36e4c63d 100644 --- a/src/autoupdate.cpp +++ b/src/autoupdate.cpp @@ -427,8 +427,8 @@ void AutoUpdater::checkUpdatesAsyncInteractiveWorker() if (!isUpdateAvailable()) return; - if (Widget::getInstance()->askMsgboxQuestion(QObject::tr("Update", "The title of a message box"), - QObject::tr("An update is available, do you want to download it now?\nIt will be installed when qTox restarts."))) + if (Widget::getInstance()->askQuestion(QObject::tr("Update", "The title of a message box"), + QObject::tr("An update is available, do you want to download it now?\nIt will be installed when qTox restarts."), false)) { downloadUpdate(); } diff --git a/src/widget/form/checkcontinue.cpp b/src/widget/form/checkcontinue.cpp deleted file mode 100644 index d42afb327..000000000 --- a/src/widget/form/checkcontinue.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - Copyright (C) 2014 by Project Tox - - This file is part of qTox, a Qt-based graphical interface for Tox. - - This program is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - See the COPYING file for more details. -*/ - -#include - -bool checkContinue(const QString& title, const QString& msg, QWidget* parent = nullptr) -{ - QMessageBox::StandardButton resp = QMessageBox::question(parent, title, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - return resp == QMessageBox::Yes; -} diff --git a/src/widget/form/checkcontinue.h b/src/widget/form/checkcontinue.h deleted file mode 100644 index 46c182bfa..000000000 --- a/src/widget/form/checkcontinue.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - Copyright (C) 2014 by Project Tox - - This file is part of qTox, a Qt-based graphical interface for Tox. - - This program is libre software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - See the COPYING file for more details. -*/ - -#ifndef CHECKCONTINUE_H -#define CHECKCONTINUE_H - -bool checkContinue(const QString& title, const QString& msg, QWidget* parent = nullptr); - -#endif diff --git a/src/widget/form/settings/identityform.cpp b/src/widget/form/settings/identityform.cpp index 3690f6ab6..852798377 100644 --- a/src/widget/form/settings/identityform.cpp +++ b/src/widget/form/settings/identityform.cpp @@ -20,7 +20,6 @@ #include "src/widget/form/settingswidget.h" #include "src/misc/settings.h" #include "src/widget/croppinglabel.h" -#include "src/widget/form/checkcontinue.h" #include "src/widget/widget.h" #include "src/historykeeper.h" #include "src/misc/style.h" @@ -148,8 +147,8 @@ void IdentityForm::onRenameClicked() name = Core::sanitize(name); QDir dir(Settings::getSettingsDirPath()); QString file = dir.filePath(name+Core::TOX_EXT); - if (!QFile::exists(file) || checkContinue(tr("Profile already exists", "rename confirm title"), - tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur)), this) + if (!QFile::exists(file) || Widget::getInstance()->askQuestion(tr("Profile already exists", "rename confirm title"), + tr("A profile named \"%1\" already exists. Do you want to erase it?", "rename confirm text").arg(cur))) { QFile::rename(dir.filePath(cur+Core::TOX_EXT), file); bodyUI->profiles->setItemText(bodyUI->profiles->currentIndex(), name); @@ -172,8 +171,6 @@ void IdentityForm::onExportClicked() if (QFile::exists(path)) { // should we popup a warning? - // if (!checkContinue(tr("Overwriting a file"), tr("Are you sure you want to overwrite %1?").arg(path)), this) - // return; success = QFile::remove(path); if (!success) { @@ -195,8 +192,8 @@ void IdentityForm::onDeleteClicked() } else { - if (checkContinue(tr("Deletion imminent!","deletion confirmation title"), - tr("Are you sure you want to delete this profile?","deletion confirmation text"), this)) + if (Widget::getInstance()->askQuestion(tr("Deletion imminent!","deletion confirmation title"), + tr("Are you sure you want to delete this profile?","deletion confirmation text"))) { QString profile = bodyUI->profiles->currentText(); QDir dir(Settings::getSettingsDirPath()); @@ -234,8 +231,8 @@ void IdentityForm::onImportClicked() QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT); - if (QFileInfo(profilePath).exists() && !checkContinue(tr("Profile already exists", "import confirm title"), - tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile), this)) + if (QFileInfo(profilePath).exists() && !Widget::getInstance()->askQuestion(tr("Profile already exists", "import confirm title"), + tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile))) return; QFile::copy(path, profilePath); diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index eb838dcff..64af76b2e 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -22,7 +22,6 @@ #include "src/core.h" #include "src/widget/widget.h" #include "src/widget/form/setpassworddialog.h" -#include "src/widget/form/checkcontinue.h" #include #include #include @@ -122,7 +121,7 @@ void PrivacyForm::onEncryptLogsUpdated() } else { - if (checkContinue(tr("Old encrypted chat logs", "title"), tr("Would you like to un-encrypt your chat logs?\nOtherwise they will be deleted."))) + if (Widget::getInstance()->askQuestion(tr("Old encrypted chat logs", "title"), tr("Would you like to un-encrypt your chat logs?\nOtherwise they will be deleted."), false)) { QList oldMessages = HistoryKeeper::exportMessagesDeleteFile(true); core->clearPassword(Core::ptHistory); diff --git a/src/widget/toxsave.cpp b/src/widget/toxsave.cpp index f9ef24a9e..9d14879db 100644 --- a/src/widget/toxsave.cpp +++ b/src/widget/toxsave.cpp @@ -18,7 +18,6 @@ #include "widget.h" #include "src/core.h" #include "src/misc/settings.h" -#include "src/widget/form/checkcontinue.h" #include #include #include @@ -62,7 +61,7 @@ void handleToxSave(const QString& path) QString profilePath = QDir(Settings::getSettingsDirPath()).filePath(profile + Core::TOX_EXT); - if (QFileInfo(profilePath).exists() && !checkContinue(QObject::tr("Profile already exists", "import confirm title"), + if (QFileInfo(profilePath).exists() && !Widget::getInstance()->askQuestion(QObject::tr("Profile already exists", "import confirm title"), QObject::tr("A profile named \"%1\" already exists. Do you want to erase it?", "import confirm text").arg(profile))) return; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 77f20f6a2..3fa740cc8 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1186,21 +1186,17 @@ void Widget::onSplitterMoved(int pos, int index) saveSplitterGeometry(); } -QMessageBox::StandardButton Widget::showWarningMsgBox(const QString& title, const QString& msg, QMessageBox::StandardButtons buttons) +void Widget::showWarningMsgBox(const QString& title, const QString& msg) { // We can only display widgets from the GUI thread if (QThread::currentThread() != qApp->thread()) { - QMessageBox::StandardButton ret; QMetaObject::invokeMethod(this, "showWarningMsgBox", Qt::BlockingQueuedConnection, - Q_RETURN_ARG(QMessageBox::StandardButton, ret), - Q_ARG(const QString&, title), Q_ARG(const QString&, msg), - Q_ARG(QMessageBox::StandardButtons, buttons)); - return ret; + Q_ARG(const QString&, title), Q_ARG(const QString&, msg)); } else { - return QMessageBox::warning(this, title, msg, buttons); + QMessageBox::warning(this, title, msg); } } @@ -1219,7 +1215,7 @@ void Widget::setEnabledThreadsafe(bool enabled) } } -bool Widget::askMsgboxQuestion(const QString& title, const QString& msg) +bool Widget::askQuestion(const QString& title, const QString& msg, bool warning) { // We can only display widgets from the GUI thread if (QThread::currentThread() != qApp->thread()) @@ -1227,12 +1223,15 @@ bool Widget::askMsgboxQuestion(const QString& title, const QString& msg) bool ret; QMetaObject::invokeMethod(this, "askMsgboxQuestion", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, ret), - Q_ARG(const QString&, title), Q_ARG(const QString&, msg)); + Q_ARG(const QString&, title), Q_ARG(const QString&, msg), Q_ARG(bool, warning)); return ret; } else { - return QMessageBox::question(this, title, msg) == QMessageBox::StandardButton::Yes; + if (warning) + return QMessageBox::warning(this, title, msg, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::StandardButton::Ok; + else + return QMessageBox::question(this, title, msg) == QMessageBox::StandardButton::Yes; } } diff --git a/src/widget/widget.h b/src/widget/widget.h index 272ff2f79..f061f1b23 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -64,10 +64,9 @@ public: void clearContactsList(); void setTranslation(); void updateTrayIcon(); - Q_INVOKABLE QMessageBox::StandardButton showWarningMsgBox(const QString& title, const QString& msg, - QMessageBox::StandardButtons buttonss = QMessageBox::Ok); + Q_INVOKABLE void showWarningMsgBox(const QString& title, const QString& msg); Q_INVOKABLE void setEnabledThreadsafe(bool enabled); - Q_INVOKABLE bool askMsgboxQuestion(const QString& title, const QString& msg); + Q_INVOKABLE bool askQuestion(const QString& title, const QString& msg, bool warning = true); Q_INVOKABLE QString passwordDialog(const QString& cancel, const QString& body); // hooray for threading hacks ~Widget();