File indexing completed on 2024-12-01 08:10:06

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 "plasmanm_editor_export.h"
0011 
0012 #include <QComboBox>
0013 #include <QLineEdit>
0014 
0015 #include <QVBoxLayout>
0016 
0017 class PLASMANM_EDITOR_EXPORT PasswordField : public QWidget
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(bool passwordModeEnabled WRITE setPasswordModeEnabled)
0021 public:
0022     enum PasswordOption {
0023         StoreForUser,
0024         StoreForAllUsers,
0025         AlwaysAsk,
0026         NotRequired,
0027     };
0028 
0029     explicit PasswordField(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
0030 
0031     void setMaxLength(int maxLength);
0032     void setPasswordModeEnabled(bool passwordMode);
0033     void setPasswordOptionsEnabled(bool enable);
0034     void setPasswordNotSavedEnabled(bool enable);
0035     void setPasswordNotRequiredEnabled(bool enable);
0036 
0037     PasswordOption passwordOption() const;
0038     void setPasswordOption(PasswordOption option);
0039 
0040     void setText(const QString &text);
0041     QString text() const;
0042 
0043 private Q_SLOTS:
0044     void changePasswordOption(int index);
0045     void showToggleEchoModeAction(const QString &text);
0046     void toggleEchoMode();
0047 
0048 Q_SIGNALS:
0049     void textChanged(const QString &text);
0050     void passwordOptionChanged(PasswordField::PasswordOption option);
0051 
0052 private:
0053     PasswordOption m_currentPasswordOption;
0054     QVBoxLayout *const m_layout;
0055     QLineEdit *const m_passwordField;
0056     QComboBox *const m_passwordOptionsMenu;
0057     QAction *m_toggleEchoModeAction = nullptr;
0058 };
0059 
0060 #endif // PLASMA_NM_PASSWORD_FIELD_H