85
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: canotifiers.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <canotifierfilter.h>
|
86
|
19 |
#include <QStringList>
|
85
|
20 |
|
|
21 |
#include "canotifiers.h"
|
|
22 |
#include "caclientnotifierproxy.h"
|
|
23 |
|
|
24 |
CaNotifiers::NotifierHash CaNotifiers::mNotifiers;
|
|
25 |
|
|
26 |
int CaNotifiers::addNotifier(const CaNotifierFilter *notifierFilter,
|
87
|
27 |
CaNotifierPrivate::NotifierType notifierType,
|
|
28 |
const CaClientNotifierProxy *notifierProxy)
|
85
|
29 |
{
|
|
30 |
NotifierKey key = NotifierKey(notifierFilter, notifierType);
|
|
31 |
if (!mNotifiers.contains(key)) {
|
|
32 |
mNotifiers.insert(key, notifierProxy);
|
|
33 |
}
|
|
34 |
return 0;
|
|
35 |
}
|
|
36 |
|
|
37 |
void CaNotifiers::removeNotifier(const CaNotifierFilter *notifierFilter,
|
87
|
38 |
CaNotifierPrivate::NotifierType notifierType)
|
85
|
39 |
{
|
|
40 |
mNotifiers.remove(NotifierKey(notifierFilter, notifierType));
|
|
41 |
}
|
|
42 |
|
|
43 |
void CaNotifiers::Notify(int groupId)
|
|
44 |
{
|
|
45 |
for (NotifierHash::const_iterator i = mNotifiers.constBegin();
|
87
|
46 |
i != mNotifiers.constEnd();
|
|
47 |
++i) {
|
85
|
48 |
const CaNotifierFilter *filter = i.key().first;
|
|
49 |
if (filter->getIds().isEmpty() || filter->getIds().contains(groupId)) {
|
|
50 |
if (i.key().second
|
87
|
51 |
== CaNotifierPrivate::GroupContentChangedNotifierType) {
|
85
|
52 |
i.value()->groupContentChanged(groupId);
|
|
53 |
}
|
|
54 |
}
|
|
55 |
}
|
|
56 |
}
|
|
57 |
|
|
58 |
void CaNotifiers::Notify(const CaEntry &targetEntry,
|
87
|
59 |
ChangeType changeType,
|
|
60 |
QList<int> &parentIds)
|
85
|
61 |
{
|
|
62 |
for (NotifierHash::const_iterator i = mNotifiers.constBegin();
|
87
|
63 |
i != mNotifiers.constEnd();
|
|
64 |
++i) {
|
85
|
65 |
if (isRegisterdForNotification(
|
87
|
66 |
*i.key().first, targetEntry, parentIds)) {
|
85
|
67 |
if (i.key().second
|
87
|
68 |
== CaNotifierPrivate::EntryChangedWithIdNotifierType) {
|
85
|
69 |
i.value()->entryChanged(targetEntry.id(), changeType);
|
|
70 |
} else if (i.key().second
|
87
|
71 |
== CaNotifierPrivate::EntryChangedWithEntryNotifierType) {
|
85
|
72 |
i.value()->entryChanged(targetEntry, changeType);
|
|
73 |
} else if (i.key().second
|
87
|
74 |
== CaNotifierPrivate::EntryTouchedNotifierType) {
|
85
|
75 |
i.value()->entryChanged(targetEntry.id(), changeType);
|
|
76 |
}
|
|
77 |
}
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
bool CaNotifiers::isRegisterdForNotification(
|
|
82 |
const CaNotifierFilter &filter,
|
|
83 |
const CaEntry &entry,
|
|
84 |
const QList<int> &parentIds)
|
|
85 |
{
|
|
86 |
bool ret = true;
|
|
87 |
if (!filter.getIds().isEmpty()) {
|
87
|
88 |
ret = ret && filter.getIds().contains(entry.id());
|
85
|
89 |
}
|
|
90 |
if (filter.getParentId() > 0) {
|
|
91 |
if (entry.id() == filter.getParentId()) {
|
|
92 |
ret = true;
|
|
93 |
} else {
|
|
94 |
ret = ret && parentIds.contains(filter.getParentId());
|
|
95 |
}
|
|
96 |
}
|
|
97 |
if (!filter.getTypeNames().isEmpty()) {
|
|
98 |
ret = ret && filter.getTypeNames().contains(entry.entryTypeName());
|
|
99 |
}
|
|
100 |
if (filter.getEntryRole()) {
|
|
101 |
ret = ret && (filter.getEntryRole().testFlag(entry.role()));
|
|
102 |
}
|
|
103 |
return ret;
|
|
104 |
}
|
|
105 |
|
|
106 |
|