File: enterpassworddialog.h

package info (click to toggle)
martchus-qtutilities 6.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 780 kB
  • sloc: cpp: 5,908; xml: 37; sh: 25; ansic: 12; makefile: 12
file content (104 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download | duplicates (2)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef DIALOGS_ENTERPASSWORDDIALOG_H
#define DIALOGS_ENTERPASSWORDDIALOG_H

#include "../global.h"

#include <QDialog>

#include <memory>

namespace QtUtilities {

namespace Ui {
class EnterPasswordDialog;
}

class QT_UTILITIES_EXPORT EnterPasswordDialog : public QDialog {
    Q_OBJECT
    Q_PROPERTY(QString userName READ userName)
    Q_PROPERTY(QString password READ password)
    Q_PROPERTY(QString description READ description WRITE setDescription)
    Q_PROPERTY(bool promtForUserName READ promtForUserName WRITE setPromptForUserName)
    Q_PROPERTY(bool isVerificationRequired READ isVerificationRequired WRITE setVerificationRequired)
    Q_PROPERTY(bool isPasswordRequired READ isPasswordRequired WRITE setPasswordRequired)
    Q_PROPERTY(QString instruction READ instruction WRITE setInstruction)
    Q_PROPERTY(bool isCapslockPressed READ isCapslockPressed)

public:
    explicit EnterPasswordDialog(QWidget *parent = nullptr);
    ~EnterPasswordDialog() override;
    const QString &userName() const;
    const QString &password() const;
    QString description() const;
    void setDescription(const QString &description = QString());
    bool promtForUserName() const;
    void setPromptForUserName(bool prompt);
    bool isVerificationRequired() const;
    void setVerificationRequired(bool value);
    bool isPasswordRequired() const;
    void setPasswordRequired(bool value);
    const QString &instruction() const;
    void setInstruction(const QString &value);
    static bool isCapslockPressed();

protected:
    bool event(QEvent *event) override;
    bool eventFilter(QObject *sender, QEvent *event) override;

private Q_SLOTS:
    void updateShowPassword();
    void confirm();
    void abort();

private:
    std::unique_ptr<Ui::EnterPasswordDialog> m_ui;
    QString m_userName;
    QString m_password;
    QString m_instruction;
    bool m_capslockPressed;
};

/*!
 * \brief Returns the entered user name.
 */
inline const QString &EnterPasswordDialog::userName() const
{
    return m_userName;
}

/*!
 * \brief Returns the entered password.
 */
inline const QString &EnterPasswordDialog::password() const
{
    return m_password;
}

/*!
 * \brief Returns the instruction text.
 *
 * The instruction text is displayed at the top of the dialog.
 * If the instruction text is empty the default text "Enter the new password"
 * or "Enter the password" (depending on whether the verification is required or
 * not) displayed.
 *
 * \sa EnterPasswordDialog::setInstruction()
 */
inline const QString &EnterPasswordDialog::instruction() const
{
    return m_instruction;
}

/*!
 * \brief Clears all results and sets the dialog status to QDialog::Rejected.
 *
 * This private slot is called when m_ui->abortPushButton is clicked.
 */
inline void EnterPasswordDialog::abort()
{
    m_password.clear();
    done(QDialog::Rejected);
}
} // namespace QtUtilities

#endif // DIALOGS_ENTERPASSWORDDIALOG_H