File indexing completed on 2024-05-12 16:27:13

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "channelpasswordwidget.h"
0008 #include <KAuthorized>
0009 #include <KLocalizedString>
0010 #include <KPasswordLineEdit>
0011 #include <QHBoxLayout>
0012 #include <QLabel>
0013 
0014 ChannelPasswordWidget::ChannelPasswordWidget(QWidget *parent)
0015     : QWidget(parent)
0016     , mPasswordLineEdit(new KPasswordLineEdit(this))
0017 {
0018     auto mainLayout = new QHBoxLayout(this);
0019     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0020     mainLayout->setContentsMargins({});
0021 
0022     auto label = new QLabel(i18n("Channel Password:"), this);
0023     label->setTextFormat(Qt::PlainText);
0024     label->setObjectName(QStringLiteral("label"));
0025     mainLayout->addWidget(label);
0026 
0027     mPasswordLineEdit->setObjectName(QStringLiteral("mPasswordLineEdit"));
0028     mPasswordLineEdit->setRevealPasswordAvailable(KAuthorized::authorize(QStringLiteral("lineedit_reveal_password")));
0029     mainLayout->addWidget(mPasswordLineEdit);
0030     connect(mPasswordLineEdit, &KPasswordLineEdit::passwordChanged, this, &ChannelPasswordWidget::slotPasswordChanged);
0031 }
0032 
0033 ChannelPasswordWidget::~ChannelPasswordWidget() = default;
0034 
0035 QString ChannelPasswordWidget::password() const
0036 {
0037     return mPasswordLineEdit->password();
0038 }
0039 
0040 void ChannelPasswordWidget::slotPasswordChanged(const QString &str)
0041 {
0042     Q_EMIT updateOkButton(!str.isEmpty());
0043 }
0044 
0045 #include "moc_channelpasswordwidget.cpp"