|
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: . |
|
15 * |
|
16 */ |
|
17 |
|
18 // CLASS HEADER |
|
19 #include "spbcontactstorelistener.h" |
|
20 |
|
21 // INCLUDES |
|
22 #include <CPbk2StoreManager.h> |
|
23 #include <CPbk2ApplicationServices.h> |
|
24 #include <CPbk2StoreManager.h> |
|
25 #include "spbcontent.h" |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // CSpbContactStoreListener::NewL |
|
29 // ---------------------------------------------------------------------------- |
|
30 // |
|
31 CSpbContactStoreListener* CSpbContactStoreListener::NewL( |
|
32 CPbk2StoreManager& aStoreManager, |
|
33 RPointerArray<CSpbContent>& aContentCache ) |
|
34 { |
|
35 CSpbContactStoreListener* self = |
|
36 new (ELeave) CSpbContactStoreListener( aStoreManager, aContentCache ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CSpbContactStoreListener::~CSpbContactStoreListener |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CSpbContactStoreListener::~CSpbContactStoreListener() |
|
48 { |
|
49 iStoreManager.DeregisterStoreEvents( *this ); |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CSpbContactStoreListener::CSpbContactStoreListener |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 inline CSpbContactStoreListener::CSpbContactStoreListener( |
|
57 CPbk2StoreManager& aStoreManager, |
|
58 RPointerArray<CSpbContent>& aContentCache ) : |
|
59 iStoreManager( aStoreManager ), |
|
60 iContentCache(aContentCache) |
|
61 { |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CSpbContactStoreListener::ConstructL |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 inline void CSpbContactStoreListener::ConstructL() |
|
69 { |
|
70 iStoreManager.RegisterStoreEventsL( *this ); |
|
71 } |
|
72 |
|
73 // -------------------------------------------------------------------------- |
|
74 // CSpbContactStoreListener::StoreReady |
|
75 // -------------------------------------------------------------------------- |
|
76 // |
|
77 void CSpbContactStoreListener::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
78 { |
|
79 // do nothing |
|
80 } |
|
81 |
|
82 // -------------------------------------------------------------------------- |
|
83 // CSpbContactStoreListener::StoreUnavailable |
|
84 // -------------------------------------------------------------------------- |
|
85 // |
|
86 void CSpbContactStoreListener::StoreUnavailable( MVPbkContactStore& /*aContactStore*/, |
|
87 TInt /*aReason*/ ) |
|
88 { |
|
89 // do nothing |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CSpbContactStoreListener::HandleStoreEventL |
|
94 // -------------------------------------------------------------------------- |
|
95 // |
|
96 void CSpbContactStoreListener::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/, |
|
97 TVPbkContactStoreEvent aStoreEvent ) |
|
98 { |
|
99 /// contact has changed, check if the number needs to be reloaded |
|
100 if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactChanged ) |
|
101 { |
|
102 CSpbContent* content = ContentByLink( *aStoreEvent.iContactLink ); |
|
103 if( content ) |
|
104 { |
|
105 content->RefreshNumberL(); |
|
106 } |
|
107 } |
|
108 else if( aStoreEvent.iEventType == TVPbkContactStoreEvent::EContactDeleted ) |
|
109 { |
|
110 DeleteContentByLink( *aStoreEvent.iContactLink ); |
|
111 } |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CSpbContactStoreListener::ContentByLink |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 CSpbContent* CSpbContactStoreListener::ContentByLink( |
|
119 const MVPbkContactLink& aLink ) |
|
120 { |
|
121 const TInt count( iContentCache.Count() ); |
|
122 for( TInt i = 0 ; i < count ; ++i ) |
|
123 { |
|
124 CSpbContent* content = iContentCache[i]; |
|
125 if( content->Match( aLink ) ) |
|
126 { |
|
127 return content; |
|
128 } |
|
129 } |
|
130 return NULL; |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // CSpbContactStoreListener::DeleteContentByLink |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 void CSpbContactStoreListener::DeleteContentByLink( |
|
138 const MVPbkContactLink& aLink ) |
|
139 { |
|
140 const TInt count = iContentCache.Count(); |
|
141 for( TInt i = 0 ; i < count ; ++i ) |
|
142 { |
|
143 CSpbContent* content = iContentCache[i]; |
|
144 if( content->Match( aLink ) ) |
|
145 { |
|
146 delete content; |
|
147 iContentCache.Remove( i ); |
|
148 break; // only one content for each contact |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 // End of file |