Changeset View
Changeset View
Standalone View
Standalone View
src/kaccountsmanager.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 55 | { | |||
---|---|---|---|---|---|
80 | 80 | | |||
81 | // No accounts at all or no new account(s). | 81 | // No accounts at all or no new account(s). | ||
82 | qCDebug(GDRIVE) << "No new account created."; | 82 | qCDebug(GDRIVE) << "No new account created."; | ||
83 | return AccountPtr(new Account()); | 83 | return AccountPtr(new Account()); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | AccountPtr KAccountsManager::refreshAccount(const AccountPtr &account) | 86 | AccountPtr KAccountsManager::refreshAccount(const AccountPtr &account) | ||
87 | { | 87 | { | ||
88 | Q_UNUSED(account) | 88 | QString accountName = account->accountName(); | ||
elvisangelaccio: `const` | |||||
89 | qCWarning(GDRIVE) << Q_FUNC_INFO << "not implemented."; | 89 | for (auto it = m_accounts.constBegin(); it != m_accounts.constEnd(); ++it) { | ||
90 | if (it.value()->accountName() != accountName) { | ||||
91 | continue; | ||||
92 | } | ||||
93 | | ||||
94 | const auto id = it.key(); | ||||
95 | qCDebug(GDRIVE) << "Refreshing" << accountName; | ||||
96 | auto gapiAccount = getAccountCredentials(id, accountName); | ||||
97 | m_accounts.insert(id, gapiAccount); | ||||
98 | return gapiAccount; | ||||
99 | } | ||||
100 | | ||||
90 | return {}; | 101 | return {}; | ||
91 | } | 102 | } | ||
92 | 103 | | |||
93 | void KAccountsManager::removeAccount(const QString &accountName) | 104 | void KAccountsManager::removeAccount(const QString &accountName) | ||
94 | { | 105 | { | ||
95 | if (!accounts().contains(accountName)) { | 106 | if (!accounts().contains(accountName)) { | ||
96 | return; | 107 | return; | ||
97 | } | 108 | } | ||
Show All 40 Lines | 144 | for (const auto id : enabledIDs) { | |||
138 | qCDebug(GDRIVE) << "Found google-provided account:" << account->displayName(); | 149 | qCDebug(GDRIVE) << "Found google-provided account:" << account->displayName(); | ||
139 | const auto services = account->enabledServices(); | 150 | const auto services = account->enabledServices(); | ||
140 | for (const auto &service : services) { | 151 | for (const auto &service : services) { | ||
141 | if (service.name() != QLatin1String("google-drive")) { | 152 | if (service.name() != QLatin1String("google-drive")) { | ||
142 | continue; | 153 | continue; | ||
143 | } | 154 | } | ||
144 | qCDebug(GDRIVE) << account->displayName() << "supports gdrive!"; | 155 | qCDebug(GDRIVE) << account->displayName() << "supports gdrive!"; | ||
145 | 156 | | |||
157 | auto gapiAccount = getAccountCredentials(id, account->displayName()); | ||||
158 | m_accounts.insert(id, gapiAccount); | ||||
159 | } | ||||
160 | } | ||||
161 | } | ||||
162 | | ||||
163 | AccountPtr KAccountsManager::getAccountCredentials(Accounts::AccountId id, QString displayName) | ||||
164 | { | ||||
146 | auto job = new GetCredentialsJob(id, nullptr); | 165 | auto job = new GetCredentialsJob(id, nullptr); | ||
147 | job->exec(); | 166 | job->exec(); | ||
148 | 167 | | |||
149 | auto gapiAccount = AccountPtr(new Account(account->displayName(), | 168 | auto gapiAccount = AccountPtr(new Account(displayName, | ||
150 | job->credentialsData().value(QStringLiteral("AccessToken")).toString(), | 169 | job->credentialsData().value(QStringLiteral("AccessToken")).toString(), | ||
151 | job->credentialsData().value(QStringLiteral("RefreshToken")).toString())); | 170 | job->credentialsData().value(QStringLiteral("RefreshToken")).toString())); | ||
152 | 171 | | |||
153 | const auto scopes = job->credentialsData().value(QStringLiteral("Scope")).toStringList(); | 172 | const auto scopes = job->credentialsData().value(QStringLiteral("Scope")).toStringList(); | ||
154 | for (const auto &scope : scopes) { | 173 | for (const auto &scope : scopes) { | ||
155 | gapiAccount->addScope(QUrl::fromUserInput(scope)); | 174 | gapiAccount->addScope(QUrl::fromUserInput(scope)); | ||
156 | } | 175 | } | ||
157 | 176 | | |||
158 | m_accounts.insert(id, gapiAccount); | 177 | qCDebug(GDRIVE) << "Got account credentials for:" << gapiAccount->accountName() << ", accessToken:" << gapiAccount->accessToken() << ", refreshToken:" << gapiAccount->refreshToken(); | ||
159 | } | 178 | | ||
160 | } | 179 | return gapiAccount; | ||
161 | } | 180 | } |
const