File indexing completed on 2024-11-17 04:45:07

0001 /*
0002     SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "passwordrequester.h"
0008 #include "imapresourcebase.h"
0009 #include "settings.h"
0010 #include <config-imap.h>
0011 
0012 #include "gmailpasswordrequester.h"
0013 #include "settingspasswordrequester.h"
0014 
0015 PasswordRequester::PasswordRequester(ImapResourceBase *resource, QObject *parent)
0016     : PasswordRequesterInterface(parent)
0017     , mResource(resource)
0018 {
0019 }
0020 
0021 PasswordRequester::~PasswordRequester() = default;
0022 
0023 PasswordRequesterInterface *PasswordRequester::requesterImpl()
0024 {
0025     const bool isXOAuth = mResource->settings()->authentication() == MailTransport::Transport::EnumAuthenticationType::XOAUTH2;
0026     if (!mImpl || (isXOAuth != !!qobject_cast<GmailPasswordRequester *>(mImpl))) {
0027         if (mImpl) {
0028             mImpl->disconnect(this);
0029             mImpl->deleteLater();
0030         }
0031         if (isXOAuth) {
0032             mImpl = new GmailPasswordRequester(mResource, this);
0033         } else {
0034             mImpl = new SettingsPasswordRequester(mResource, this);
0035         }
0036         connect(mImpl, &PasswordRequesterInterface::done, this, &PasswordRequesterInterface::done);
0037     }
0038 
0039     return mImpl;
0040 }
0041 
0042 void PasswordRequester::cancelPasswordRequests()
0043 {
0044     requesterImpl()->cancelPasswordRequests();
0045 }
0046 
0047 void PasswordRequester::requestPassword(RequestType request, const QString &serverError)
0048 {
0049     requesterImpl()->requestPassword(request, serverError);
0050 }
0051 
0052 #include "moc_passwordrequester.cpp"