~seb128/sync-monitor/synchronization-typo

« back to all changes in this revision

Viewing changes to src/sync-queue.cpp

  • Committer: CI bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2014-04-09 06:46:43 UTC
  • mfrom: (17.1.46 initial-release)
  • Revision ID: ps-jenkins@lists.canonical.com-20140409064643-bidc0po4gfxj6vol
Updated package version. Fixes: 1302159, 1302160, 1302171

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2014 Canonical Ltd.
3
 
 *
4
 
 * This file is part of sync-monitor.
5
 
 *
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.
9
 
 *
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.
14
 
 *
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/>.
17
 
 */
18
 
 
19
 
#include "sync-queue.h"
20
 
#include "sync-account.h"
21
 
 
22
 
SyncQueue::SyncQueue()
23
 
{
24
 
}
25
 
 
26
 
SyncQueue::~SyncQueue()
27
 
{
28
 
}
29
 
 
30
 
void SyncQueue::push(SyncAccount *account, const QString &serviceName)
31
 
{
32
 
    QSet<QString> services = m_queue.value(account);
33
 
    if (serviceName.isEmpty()) {
34
 
        // empty serviceName means all services
35
 
        services = account->availableServices().toSet();
36
 
    } else {
37
 
        services.insert(serviceName);
38
 
    }
39
 
    if (services.isEmpty()) {
40
 
        m_queue.remove(account);
41
 
    } else {
42
 
        m_queue.insert(account, services);
43
 
    }
44
 
}
45
 
 
46
 
bool SyncQueue::contains(SyncAccount *account, const QString &serviceName) const
47
 
{
48
 
    if (serviceName.isEmpty()) {
49
 
        return m_queue.contains(account);
50
 
    } else {
51
 
        QSet<QString> services = m_queue.value(account);
52
 
        return services.contains(serviceName);
53
 
    }
54
 
}
55
 
 
56
 
int SyncQueue::count() const
57
 
{
58
 
    return m_queue.values().size();
59
 
}
60
 
 
61
 
bool SyncQueue::isEmpty() const
62
 
{
63
 
    return m_queue.isEmpty();
64
 
}
65
 
 
66
 
QString SyncQueue::popNext(SyncAccount **account)
67
 
{
68
 
    if (m_queue.isEmpty()) {
69
 
        *account = 0;
70
 
        return QString();
71
 
    }
72
 
 
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);
78
 
    } else {
79
 
        services.remove(nextService);
80
 
        m_queue.insert(*account, services);
81
 
    }
82
 
    return nextService;
83
 
}
84
 
 
85
 
SyncAccount *SyncQueue::popNext()
86
 
{
87
 
    SyncAccount *acc = m_queue.keys().first();
88
 
    m_queue.remove(acc);
89
 
    return acc;
90
 
}
91
 
 
92
 
void SyncQueue::remove(SyncAccount *account, const QString &serviceName)
93
 
{
94
 
    if (serviceName.isEmpty()) {
95
 
        m_queue.remove(account);
96
 
    } else {
97
 
        QSet<QString> services = m_queue.value(account);
98
 
        if (services.contains(serviceName)) {
99
 
            if (services.size() == 1) {
100
 
                m_queue.remove(account);
101
 
            } else {
102
 
                services.remove(serviceName);
103
 
                m_queue.insert(account, services);
104
 
            }
105
 
        }
106
 
    }
107
 
}