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

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 "createnewserverwidget.h"
0008 #include "common/authenticationloginwidget.h"
0009 #include "common/authenticationoauthwidget.h"
0010 
0011 #include <KLocalizedString>
0012 #include <QVBoxLayout>
0013 
0014 CreateNewServerWidget::CreateNewServerWidget(QWidget *parent)
0015     : QWidget(parent)
0016     , mAuthenticationWidget(new AuthenticationOauthWidget(this))
0017     , mAuthenticationLoginWidget(new AuthenticationLoginWidget(this))
0018 {
0019     // TODO add icon from server
0020     // TODO add info from server ?
0021     auto mainLayout = new QVBoxLayout(this);
0022     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0023     mainLayout->setContentsMargins({});
0024 
0025     mAuthenticationLoginWidget->setObjectName(QStringLiteral("mAuthenticationLoginWidget"));
0026     mAuthenticationWidget->setObjectName(QStringLiteral("mAuthenticationWidget"));
0027     mainLayout->addWidget(mAuthenticationLoginWidget);
0028     mainLayout->addWidget(mAuthenticationWidget);
0029     // TODO add support for two factor ?
0030 
0031     connect(mAuthenticationLoginWidget, &AuthenticationLoginWidget::updateOkButton, this, &CreateNewServerWidget::updateOkButton);
0032     connect(mAuthenticationWidget, &AuthenticationOauthWidget::authentication, this, &CreateNewServerWidget::authentication);
0033 }
0034 
0035 CreateNewServerWidget::~CreateNewServerWidget() = default;
0036 
0037 AccountManager::AccountManagerInfo CreateNewServerWidget::accountInfo()
0038 {
0039     return mAuthenticationLoginWidget->accountInfo();
0040 }
0041 
0042 void CreateNewServerWidget::setAccountInfo(const AccountManager::AccountManagerInfo &accountInfo)
0043 {
0044     mAuthenticationLoginWidget->hide();
0045     mAuthenticationWidget->hide();
0046     for (const auto &info : accountInfo.authenticationInfos) {
0047         if (info.oauthType() == AuthenticationManager::AuthMethodType::Password) {
0048             mAuthenticationLoginWidget->show();
0049             mAuthenticationLoginWidget->setAccountInfo(accountInfo);
0050         } else {
0051             mAuthenticationWidget->show();
0052             mAuthenticationWidget->addAuthenticationMethod(info);
0053         }
0054     }
0055 }
0056 
0057 void CreateNewServerWidget::setExistingAccountName(const QStringList &lst)
0058 {
0059     mAuthenticationLoginWidget->setExistingAccountName(lst);
0060 }
0061 
0062 #include "moc_createnewserverwidget.cpp"