File indexing completed on 2024-04-28 05:19:53
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Daniel Vrátil <dvratil@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "fakeaccountstorage.h" 0008 #include "account.h" 0009 0010 #include <QDateTime> 0011 #include <QUuid> 0012 0013 using namespace KGAPI2; 0014 0015 FakeAccountStorage::FakeAccountStorage() 0016 { 0017 } 0018 0019 void FakeAccountStorage::open(const std::function<void(bool)> &callback) 0020 { 0021 callback(true); 0022 } 0023 0024 bool FakeAccountStorage::opened() const 0025 { 0026 return true; 0027 } 0028 0029 AccountPtr FakeAccountStorage::getAccount(const QString &apiKey, const QString &accountName) 0030 { 0031 return mStore.value(apiKey + accountName, {}); 0032 } 0033 0034 bool FakeAccountStorage::storeAccount(const QString &apiKey, const KGAPI2::AccountPtr &account) 0035 { 0036 mStore[apiKey + account->accountName()] = account; 0037 return true; 0038 } 0039 0040 void FakeAccountStorage::removeAccount(const QString &apiKey, const QString &accountName) 0041 { 0042 mStore.remove(apiKey + accountName); 0043 } 0044 0045 AccountPtr FakeAccountStorage::generateAccount(const QString &apiKey, const QString &accountName, const QList<QUrl> &scopes) 0046 { 0047 const auto acc = AccountPtr::create(accountName, QUuid::createUuid().toString(), QUuid::createUuid().toString(), scopes); 0048 acc->setExpireDateTime(QDateTime::currentDateTime().addDays(1)); 0049 storeAccount(apiKey, acc); 0050 return acc; 0051 } 0052 0053 FakeAccountStorageFactory::FakeAccountStorageFactory() 0054 { 0055 mStore = new FakeAccountStorage(); 0056 sFactory = this; 0057 } 0058 0059 FakeAccountStorageFactory::~FakeAccountStorageFactory() 0060 { 0061 delete mStore; 0062 sFactory = nullptr; 0063 } 0064 0065 KGAPI2::AccountStorage *FakeAccountStorageFactory::create() const 0066 { 0067 return mStore; 0068 } 0069 0070 FakeAccountStorage *FakeAccountStorageFactory::fakeStore() const 0071 { 0072 return mStore; 0073 }