2013-10-08 16:09:20 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Felix Geyer <debfx@fobos.de>
|
2018-12-19 23:14:11 -05:00
|
|
|
* Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
|
2013-10-08 16:09:20 -04:00
|
|
|
*
|
|
|
|
* This program is free 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 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_MESSAGEBOX_H
|
|
|
|
#define KEEPASSX_MESSAGEBOX_H
|
|
|
|
|
2019-01-20 09:50:20 -05:00
|
|
|
#include <QMap>
|
2013-10-08 16:09:20 -04:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
class MessageBox
|
|
|
|
{
|
|
|
|
public:
|
2019-01-20 09:50:20 -05:00
|
|
|
enum Button : uint64_t
|
|
|
|
{
|
2018-12-19 23:14:11 -05:00
|
|
|
// Reimplementation of Qt StandardButtons
|
2019-01-20 09:50:20 -05:00
|
|
|
NoButton = 0,
|
|
|
|
Ok = 1 << 1,
|
|
|
|
Open = 1 << 2,
|
|
|
|
Save = 1 << 3,
|
|
|
|
Cancel = 1 << 4,
|
|
|
|
Close = 1 << 5,
|
|
|
|
Discard = 1 << 6,
|
|
|
|
Apply = 1 << 7,
|
|
|
|
Reset = 1 << 8,
|
2018-12-19 23:14:11 -05:00
|
|
|
RestoreDefaults = 1 << 9,
|
2019-01-20 09:50:20 -05:00
|
|
|
Help = 1 << 10,
|
|
|
|
SaveAll = 1 << 11,
|
|
|
|
Yes = 1 << 12,
|
|
|
|
YesToAll = 1 << 13,
|
|
|
|
No = 1 << 14,
|
|
|
|
NoToAll = 1 << 15,
|
|
|
|
Abort = 1 << 16,
|
|
|
|
Retry = 1 << 17,
|
|
|
|
Ignore = 1 << 18,
|
2018-12-19 23:14:11 -05:00
|
|
|
|
|
|
|
// KeePassXC Buttons
|
2019-01-20 09:50:20 -05:00
|
|
|
Overwrite = 1 << 19,
|
|
|
|
Delete = 1 << 20,
|
|
|
|
Move = 1 << 21,
|
|
|
|
Empty = 1 << 22,
|
|
|
|
Remove = 1 << 23,
|
|
|
|
Skip = 1 << 24,
|
|
|
|
Disable = 1 << 25,
|
|
|
|
Merge = 1 << 26,
|
2019-08-30 20:18:41 -04:00
|
|
|
Continue = 1 << 27,
|
2018-12-19 23:14:11 -05:00
|
|
|
|
|
|
|
// Internal loop markers. Update Last when new KeePassXC button is added
|
|
|
|
First = Ok,
|
2019-08-30 20:18:41 -04:00
|
|
|
Last = Continue,
|
2018-12-19 23:14:11 -05:00
|
|
|
};
|
|
|
|
|
2019-01-20 09:50:20 -05:00
|
|
|
enum Action
|
|
|
|
{
|
|
|
|
None = 0,
|
2018-01-25 07:21:05 -05:00
|
|
|
Raise = 1,
|
|
|
|
};
|
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
typedef uint64_t Buttons;
|
|
|
|
|
|
|
|
static void initializeButtonDefs();
|
|
|
|
static void setNextAnswer(Button button);
|
|
|
|
|
|
|
|
static Button critical(QWidget* parent,
|
|
|
|
const QString& title,
|
|
|
|
const QString& text,
|
|
|
|
Buttons buttons = MessageBox::Ok,
|
2019-08-30 20:18:41 -04:00
|
|
|
Button defaultButton = MessageBox::Ok,
|
2019-07-02 04:55:15 -04:00
|
|
|
Action action = MessageBox::None,
|
|
|
|
QCheckBox* checkbox = nullptr);
|
2019-08-30 20:18:41 -04:00
|
|
|
static Button warning(QWidget* parent,
|
|
|
|
const QString& title,
|
|
|
|
const QString& text,
|
|
|
|
Buttons buttons = MessageBox::Ok,
|
|
|
|
Button defaultButton = MessageBox::Ok,
|
|
|
|
Action action = MessageBox::None,
|
|
|
|
QCheckBox* checkbox = nullptr);
|
2018-12-19 23:14:11 -05:00
|
|
|
static Button information(QWidget* parent,
|
|
|
|
const QString& title,
|
|
|
|
const QString& text,
|
|
|
|
Buttons buttons = MessageBox::Ok,
|
2019-08-30 20:18:41 -04:00
|
|
|
Button defaultButton = MessageBox::Ok,
|
2019-07-02 04:55:15 -04:00
|
|
|
Action action = MessageBox::None,
|
|
|
|
QCheckBox* checkbox = nullptr);
|
2018-12-19 23:14:11 -05:00
|
|
|
static Button question(QWidget* parent,
|
|
|
|
const QString& title,
|
|
|
|
const QString& text,
|
2019-08-30 20:18:41 -04:00
|
|
|
Buttons buttons = MessageBox::Yes | MessageBox::Cancel,
|
|
|
|
Button defaultButton = MessageBox::Cancel,
|
2019-07-02 04:55:15 -04:00
|
|
|
Action action = MessageBox::None,
|
|
|
|
QCheckBox* checkbox = nullptr);
|
2013-10-08 16:09:20 -04:00
|
|
|
|
2019-02-21 00:51:23 -05:00
|
|
|
class OverrideParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit OverrideParent(QWindow* newParent);
|
|
|
|
~OverrideParent();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QWindow* m_oldParent;
|
|
|
|
};
|
|
|
|
|
2013-10-08 16:09:20 -04:00
|
|
|
private:
|
2019-02-21 00:51:23 -05:00
|
|
|
static QWindow* m_overrideParent;
|
2018-12-19 23:14:11 -05:00
|
|
|
static Button m_nextAnswer;
|
2019-01-17 00:03:58 -05:00
|
|
|
static QHash<QAbstractButton*, Button> m_addedButtonLookup;
|
2018-12-19 23:14:11 -05:00
|
|
|
static QMap<Button, std::pair<QString, QMessageBox::ButtonRole>> m_buttonDefs;
|
2019-01-20 09:50:20 -05:00
|
|
|
|
2018-12-19 23:14:11 -05:00
|
|
|
static Button messageBox(QWidget* parent,
|
|
|
|
QMessageBox::Icon icon,
|
|
|
|
const QString& title,
|
|
|
|
const QString& text,
|
|
|
|
Buttons buttons = MessageBox::Ok,
|
2018-01-25 07:21:05 -05:00
|
|
|
Button defaultButton = MessageBox::NoButton,
|
2019-07-02 04:55:15 -04:00
|
|
|
Action action = MessageBox::None,
|
|
|
|
QCheckBox* checkbox = nullptr);
|
2018-12-19 23:14:11 -05:00
|
|
|
|
|
|
|
static QString stdButtonText(QMessageBox::StandardButton button);
|
2013-10-08 16:09:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_MESSAGEBOX_H
|