2
* Copyright 2014 Canonical Ltd.
4
* This file is part of sync-monitor.
6
* sync-monitor is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* contact-service-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "sync-queue.h"
20
#include "sync-account.h"
22
SyncQueue::SyncQueue()
26
SyncQueue::~SyncQueue()
30
void SyncQueue::push(SyncAccount *account, const QString &serviceName)
32
QSet<QString> services = m_queue.value(account);
33
if (serviceName.isEmpty()) {
34
// empty serviceName means all services
35
services = account->availableServices().toSet();
37
services.insert(serviceName);
39
if (services.isEmpty()) {
40
m_queue.remove(account);
42
m_queue.insert(account, services);
46
bool SyncQueue::contains(SyncAccount *account, const QString &serviceName) const
48
if (serviceName.isEmpty()) {
49
return m_queue.contains(account);
51
QSet<QString> services = m_queue.value(account);
52
return services.contains(serviceName);
56
int SyncQueue::count() const
58
return m_queue.values().size();
61
bool SyncQueue::isEmpty() const
63
return m_queue.isEmpty();
66
QString SyncQueue::popNext(SyncAccount **account)
68
if (m_queue.isEmpty()) {
73
*account = m_queue.keys().first();
74
QSet<QString> services = m_queue.value(* account);
75
QString nextService = *(services.begin());
76
if (services.size() == 1) {
77
m_queue.remove(*account);
79
services.remove(nextService);
80
m_queue.insert(*account, services);
85
SyncAccount *SyncQueue::popNext()
87
SyncAccount *acc = m_queue.keys().first();
92
void SyncQueue::remove(SyncAccount *account, const QString &serviceName)
94
if (serviceName.isEmpty()) {
95
m_queue.remove(account);
97
QSet<QString> services = m_queue.value(account);
98
if (services.contains(serviceName)) {
99
if (services.size() == 1) {
100
m_queue.remove(account);
102
services.remove(serviceName);
103
m_queue.insert(account, services);