aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/passworddialog.h
blob: 2329522dddc0c1cca42858cf42c79d86db0f2768 (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
65
// Copyright (C) 2023 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 "checkablemessagebox.h"

#include <QAbstractButton>
#include <QDialog>

#include <memory>
#include <optional>

namespace Utils {

class PasswordDialogPrivate;

class QTCREATOR_UTILS_EXPORT ShowPasswordButton : public QAbstractButton
{
public:
    ShowPasswordButton(QWidget *parent = nullptr);

    void paintEvent(QPaintEvent *e) override;
    void enterEvent(QEnterEvent *e) override;
    void leaveEvent(QEvent *e) override;

    QSize sizeHint() const override;

private:
    bool m_containsMouse{false};
};

class QTCREATOR_UTILS_EXPORT PasswordDialog : public QDialog
{
public:
    PasswordDialog(const QString &title,
                   const QString &prompt,
                   const QString &doNotAskAgainLabel,
                   bool withUsername);
    virtual ~PasswordDialog();

    void setUser(const QString &user);
    QString user() const;

    QString password() const;

    static std::optional<QPair<QString, QString>> getUserAndPassword(
        const QString &title,
        const QString &prompt,
        const QString &doNotAskAgainLabel,
        const QString &userName,
        const CheckableDecider &decider);

    static std::optional<QString> getPassword(const QString &title,
                                              const QString &prompt,
                                              const QString &doNotAskAgainLabel,
                                              const CheckableDecider &decider);

private:
    std::unique_ptr<PasswordDialogPrivate> d;
};

} // namespace Utils