File indexing completed on 2024-12-08 10:59:22

0001 /*
0002     SPDX-FileCopyrightText: 2015 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef PLASMA_NM_PASSWORD_FIELD_H
0008 #define PLASMA_NM_PASSWORD_FIELD_H
0009 
0010 #include <QComboBox>
0011 #include <QLineEdit>
0012 
0013 #include <QVBoxLayout>
0014 
0015 class Q_DECL_EXPORT PasswordField : public QWidget
0016 {
0017     Q_OBJECT
0018     Q_PROPERTY(bool passwordModeEnabled WRITE setPasswordModeEnabled)
0019 public:
0020     enum PasswordOption {
0021         StoreForUser,
0022         StoreForAllUsers,
0023         AlwaysAsk,
0024         NotRequired,
0025     };
0026 
0027     explicit PasswordField(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0028 
0029     void setMaxLength(int maxLength);
0030     void setPasswordModeEnabled(bool passwordMode);
0031     void setPasswordOptionsEnabled(bool enable);
0032     void setPasswordNotSavedEnabled(bool enable);
0033     void setPasswordNotRequiredEnabled(bool enable);
0034 
0035     PasswordOption passwordOption() const;
0036     void setPasswordOption(PasswordOption option);
0037 
0038     void setText(const QString &text);
0039     QString text() const;
0040 
0041 private Q_SLOTS:
0042     void changePasswordOption(int index);
0043     void showToggleEchoModeAction(const QString &text);
0044     void toggleEchoMode();
0045 
0046 Q_SIGNALS:
0047     void textChanged(const QString &text);
0048     void passwordOptionChanged(PasswordField::PasswordOption option);
0049 
0050 private:
0051     PasswordOption m_currentPasswordOption;
0052     QVBoxLayout *const m_layout;
0053     QLineEdit *const m_passwordField;
0054     QComboBox *const m_passwordOptionsMenu;
0055     QAction *m_toggleEchoModeAction = nullptr;
0056 };
0057 
0058 #endif // PLASMA_NM_PASSWORD_FIELD_H