File indexing completed on 2025-01-12 04:34:09

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 "administratorcustomuserstatuscreatewidget.h"
0008 #include "misc/statuscombobox.h"
0009 #include <KLocalizedString>
0010 #include <QFormLayout>
0011 #include <QLineEdit>
0012 
0013 AdministratorCustomUserStatusCreateWidget::AdministratorCustomUserStatusCreateWidget(QWidget *parent)
0014     : QWidget(parent)
0015     , mName(new QLineEdit(this))
0016     , mStatusCombobox(new StatusCombobox(this))
0017 {
0018     auto mainLayout = new QFormLayout(this);
0019     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0020     mainLayout->setContentsMargins({});
0021 
0022     mName->setObjectName(QStringLiteral("mName"));
0023     mName->setClearButtonEnabled(true);
0024     mStatusCombobox->setObjectName(QStringLiteral("mStatusCombobox"));
0025     mStatusCombobox->setUseOnlyStandardStatus();
0026 
0027     mainLayout->addRow(i18n("Name:"), mName);
0028     mainLayout->addRow(i18n("Status:"), mStatusCombobox);
0029     connect(mName, &QLineEdit::textChanged, this, &AdministratorCustomUserStatusCreateWidget::slotCheckValues);
0030     connect(mStatusCombobox, &StatusCombobox::activated, this, &AdministratorCustomUserStatusCreateWidget::slotCheckValues);
0031 }
0032 
0033 AdministratorCustomUserStatusCreateWidget::~AdministratorCustomUserStatusCreateWidget() = default;
0034 
0035 void AdministratorCustomUserStatusCreateWidget::slotCheckValues()
0036 {
0037     Q_EMIT updateOkButton(!mName->text().trimmed().isEmpty() && (mStatusCombobox->status() != User::PresenceStatus::Unknown));
0038 }
0039 
0040 AdministratorCustomUserStatusCreateWidget::UserStatusInfo AdministratorCustomUserStatusCreateWidget::userStatusInfo() const
0041 {
0042     AdministratorCustomUserStatusCreateWidget::UserStatusInfo info;
0043     info.name = mName->text();
0044     info.statusType = mStatusCombobox->status();
0045     return info;
0046 }
0047 
0048 void AdministratorCustomUserStatusCreateWidget::setUserStatusInfo(const AdministratorCustomUserStatusCreateWidget::UserStatusInfo &info)
0049 {
0050     mName->setText(info.name);
0051     mStatusCombobox->setStatus(info.statusType);
0052 }
0053 
0054 #include "moc_administratorcustomuserstatuscreatewidget.cpp"