aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/checkablemessagebox.h
blob: 297ff22b62308e841a5f2726e96af583398964a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "utils_global.h"

#include <QMap>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE

namespace Utils {

class QTCREATOR_UTILS_EXPORT CheckableDecider
{
public:
    CheckableDecider() = default;
    CheckableDecider(const QString &settingsSubKey);
    CheckableDecider(bool *doNotAskAgain);
    CheckableDecider(const std::function<bool()> &should, const std::function<void()> &doNot)
        : shouldAskAgain(should), doNotAskAgain(doNot)
    {}

    std::function<bool()> shouldAskAgain;
    std::function<void()> doNotAskAgain;
};

class QTCREATOR_UTILS_EXPORT CheckableMessageBox
{
public:
    static QMessageBox::StandardButton question(
        QWidget *parent,
        const QString &title,
        const QString &question,
        const CheckableDecider &decider,
        QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
        QMessageBox::StandardButton defaultButton = QMessageBox::No,
        QMessageBox::StandardButton acceptButton = QMessageBox::Yes,
        QMap<QMessageBox::StandardButton, QString> buttonTextOverrides = {},
        const QString &msg = {});

    static QMessageBox::StandardButton information(
        QWidget *parent,
        const QString &title,
        const QString &text,
        const CheckableDecider &decider,
        QMessageBox::StandardButtons buttons = QMessageBox::Ok,
        QMessageBox::StandardButton defaultButton = QMessageBox::NoButton,
        QMap<QMessageBox::StandardButton, QString> buttonTextOverrides = {},
        const QString &msg = {});

    // Conversion convenience
    static void resetAllDoNotAskAgainQuestions();
    static bool hasSuppressedQuestions();
    static QString msgDoNotAskAgain();
    static QString msgDoNotShowAgain();

    static void initialize(QSettings *settings);
};

} // namespace Utils