~mardy/online-accounts-api/packaging-1608814

« back to all changes in this revision

Viewing changes to src/lib/OnlineAccounts/manager.cpp

  • Committer: Bileto Bot
  • Author(s): James Henstridge
  • Date: 2016-07-22 05:08:06 UTC
  • mfrom: (21.2.6 oa-all-services)
  • Revision ID: ci-train-bot@canonical.com-20160722050806-jc2jrxrrzs72ikl1
Expose all serviceIds for each account rather than ignoring all but the first. (LP: #1602159)

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
Account *ManagerPrivate::ensureAccount(const AccountInfo &info)
85
85
{
86
86
    if (Q_UNLIKELY(info.id() == 0)) return 0;
 
87
    if (Q_UNLIKELY(info.service().isEmpty())) return 0;
87
88
 
88
 
    QHash<AccountId,AccountData>::iterator i = m_accounts.find(info.id());
 
89
    auto i = m_accounts.find({info.id(), info.service()});
89
90
    if (i == m_accounts.end()) {
90
 
        i = m_accounts.insert(info.id(), AccountData(info));
 
91
        i = m_accounts.insert({info.id(), info.service()}, AccountData(info));
91
92
    }
92
93
 
93
94
    AccountData &accountData = i.value();
130
131
    } else {
131
132
        QList<AccountInfo> accountInfos = reply.argumentAt<0>();
132
133
        Q_FOREACH(const AccountInfo &info, accountInfos) {
133
 
            m_accounts.insert(info.id(), AccountData(info));
 
134
            m_accounts.insert({info.id(), info.service()}, AccountData(info));
134
135
        }
135
136
    }
136
137
    m_getAccountsCall->deleteLater();
154
155
         * we remove it from our list so that we won't return it to the client
155
156
         * anymore.
156
157
         */
157
 
        m_accounts.remove(info.id());
 
158
        m_accounts.remove({info.id(), service});
158
159
    }
159
160
 
160
161
    /* No need to handle the Update change type: ensureAccount already updates
198
199
    Q_D(Manager);
199
200
 
200
201
    QList<Account*> result;
201
 
    for (QHash<AccountId,AccountData>::iterator i = d->m_accounts.begin();
202
 
         i != d->m_accounts.end(); i++) {
 
202
    for (auto i = d->m_accounts.begin(); i != d->m_accounts.end(); i++) {
203
203
        AccountData &accountData = i.value();
204
204
        if (!service.isEmpty() && accountData.info.service() != service) continue;
205
205
 
216
216
 
217
217
Account *Manager::account(AccountId accountId)
218
218
{
 
219
    return account(accountId, QString());
 
220
}
 
221
 
 
222
Account *Manager::account(AccountId accountId, const QString &serviceId)
 
223
{
219
224
    Q_D(Manager);
220
225
 
221
 
    QHash<AccountId,AccountData>::iterator i = d->m_accounts.find(accountId);
222
 
    if (Q_UNLIKELY(i == d->m_accounts.end())) return 0;
 
226
    decltype(d->m_accounts)::iterator i;
 
227
    if (serviceId.isEmpty()) {
 
228
        // Any non-empty service ID will sort after the empty string
 
229
        i = d->m_accounts.lowerBound({accountId, QString()});
 
230
        if (Q_UNLIKELY(i == d->m_accounts.end() ||
 
231
                       i.key().first != accountId)) {
 
232
            return 0;
 
233
        }
 
234
    } else {
 
235
        i = d->m_accounts.find({accountId, serviceId});
 
236
        if (Q_UNLIKELY(i == d->m_accounts.end())) return 0;
 
237
    }
223
238
 
224
239
    AccountData &accountData = i.value();
225
240
    if (!accountData.account) {