File indexing completed on 2024-12-08 12:52:51
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "removeaccountjob.h" 0008 0009 #include "core.h" 0010 #include <Accounts/Manager> 0011 #include <QDebug> 0012 #include <SignOn/Identity> 0013 0014 namespace KAccounts 0015 { 0016 0017 class RemoveAccountJob::Private 0018 { 0019 public: 0020 Private() 0021 { 0022 } 0023 QString accountId; 0024 }; 0025 0026 RemoveAccountJob::RemoveAccountJob(QObject *parent) 0027 : KJob(parent) 0028 , d(new Private) 0029 { 0030 } 0031 0032 RemoveAccountJob::~RemoveAccountJob() 0033 { 0034 delete d; 0035 } 0036 0037 QString RemoveAccountJob::accountId() const 0038 { 0039 return d->accountId; 0040 } 0041 0042 void RemoveAccountJob::setAccountId(const QString &accountId) 0043 { 0044 d->accountId = accountId; 0045 Q_EMIT accountIdChanged(); 0046 } 0047 0048 void RemoveAccountJob::start() 0049 { 0050 Accounts::Manager *accountsManager = KAccounts::accountsManager(); 0051 if (accountsManager) { 0052 Accounts::Account *account = accountsManager->account(d->accountId.toInt()); 0053 if (account) { 0054 // We can't depend on Accounts::Account::synced, as that doesn't necessarily get fired when 0055 // asking for the account to be removed... 0056 connect(accountsManager, &Accounts::Manager::accountRemoved, this, [this](Accounts::AccountId id) { 0057 if (id == d->accountId.toUInt()) { 0058 emitResult(); 0059 } 0060 }); 0061 SignOn::Identity *identity = SignOn::Identity::existingIdentity(account->credentialsId(), this); 0062 if (identity) { 0063 identity->remove(); 0064 identity->deleteLater(); 0065 } 0066 account->remove(); 0067 account->sync(); 0068 } else { 0069 qWarning() << "No account found with the ID" << d->accountId; 0070 emitResult(); 0071 } 0072 } else { 0073 qWarning() << "No accounts manager, this is not awesome."; 0074 emitResult(); 0075 } 0076 } 0077 0078 };