|
1 /* |
|
2 * Copyright (c) 2003-2005 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: Observes storage events and reacts according to settings |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CCAStorageObserver.h" |
|
20 #include "PrivateEngineDefinitions.h" |
|
21 #include "PublicEngineDefinitions.h" |
|
22 #include "ImpsCSPAllErrors.h" |
|
23 #include "CAUtils.h" |
|
24 |
|
25 #include "MCASettings.h" |
|
26 #include "MCAStoredContacts.h" |
|
27 #include "MCAStoredContact.h" |
|
28 #include "MCASettings.h" |
|
29 #include "MCABlocking.h" |
|
30 |
|
31 #include "ChatDebugPrint.h" |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 // Two-phased constructor. |
|
36 CCAStorageObserver* CCAStorageObserver::NewL( MCASettings& aApplicationSettings, |
|
37 MCAStoredContacts& aContactStorage, |
|
38 MCAPresence& aPresenceHandler, |
|
39 MCABlocking& aBlockingManager ) |
|
40 { |
|
41 CCAStorageObserver* self = new ( ELeave ) CCAStorageObserver( |
|
42 aApplicationSettings, |
|
43 aContactStorage, |
|
44 aPresenceHandler, |
|
45 aBlockingManager ); |
|
46 |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 |
|
51 return self; |
|
52 } |
|
53 |
|
54 |
|
55 // Destructor |
|
56 CCAStorageObserver::~CCAStorageObserver() |
|
57 { |
|
58 iContactStorage.RemoveObserver( this ); |
|
59 delete iLastUserId; |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------- |
|
64 // CCAStorageObserver::HandleDelete |
|
65 // (other items were commented in a header). |
|
66 // --------------------------------------------------------- |
|
67 // |
|
68 void CCAStorageObserver::HandleContactDelete( const TDesC& aId ) |
|
69 { |
|
70 CHAT_DP_TXT( "CCAStorageObserver::HandleDelete" ); |
|
71 // find also the "soon-to-be-deleted" contacts |
|
72 IMHandleDelete( aId ); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CCAStorageObserver::HandleAddition |
|
77 // (other items were commented in a header). |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CCAStorageObserver::HandleAddition( MCAContactList& /*aList*/, MCAStoredContact& aContact ) |
|
81 { |
|
82 CHAT_DP_TXT( "CCAStorageObserver::HandleAddition" ); |
|
83 IMHandleAddition( aContact ); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // CCAStorageObserver::HandleChange |
|
88 // (other items were commented in a header). |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 void CCAStorageObserver::HandleChange( |
|
92 MCAContactList* /* aList */, |
|
93 MCAStoredContact* /* aId */, |
|
94 TStorageManagerGlobals::TCAObserverEventType /*aEventType*/, |
|
95 TBool /*aUserIdChanged*/ ) |
|
96 { |
|
97 // nothing to do |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // CCAStorageObserver::HandleBackupRestoreEvent |
|
102 // (other items were commented in a header). |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 void CCAStorageObserver::HandleBackupRestoreEvent( |
|
106 const TStorageManagerGlobals::TCAObserverEventType /*aEventType*/ ) |
|
107 { |
|
108 } |
|
109 |
|
110 // Symbian OS default constructor can leave. |
|
111 void CCAStorageObserver::ConstructL() |
|
112 { |
|
113 iContactStorage.AddObserverL( this ); |
|
114 } |
|
115 |
|
116 // C++ default constructor can NOT contain any code, that |
|
117 // might leave. |
|
118 // |
|
119 CCAStorageObserver::CCAStorageObserver( MCASettings& aApplicationSettings, |
|
120 MCAStoredContacts& aContactStorage, |
|
121 MCAPresence& aPresenceHandler, |
|
122 MCABlocking& aBlockingManager ) |
|
123 : iApplicationSettings( aApplicationSettings ), |
|
124 iContactStorage( aContactStorage ), |
|
125 iPresenceHandler( aPresenceHandler ), |
|
126 iBlockingManager( aBlockingManager ) |
|
127 { |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CCAStorageObserver::IMHandleDelete |
|
132 // (other items were commented in a header). |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CCAStorageObserver::IMHandleDelete( const TDesC& aUserId ) |
|
136 { |
|
137 TInt err( KErrNone ); |
|
138 |
|
139 if ( iApplicationSettings.Value( MCASettings::EReceiveIMessages ) |
|
140 == MCASettings::EFriends ) |
|
141 { |
|
142 TRAP( err, DoBlockingManagerDeleteL( aUserId ) ); |
|
143 HandleError( err ); |
|
144 } |
|
145 } |
|
146 |
|
147 // --------------------------------------------------------- |
|
148 // CCAStorageObserver::DoBlockingManagerDeleteL |
|
149 // (other items were commented in a header). |
|
150 // --------------------------------------------------------- |
|
151 // |
|
152 void CCAStorageObserver::DoBlockingManagerDeleteL( const TDesC& aUserId ) |
|
153 { |
|
154 // granularity of one because only one item appended to array |
|
155 CDesCArrayFlat* arr = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
156 CleanupStack::PushL( arr ); |
|
157 arr->AppendL( aUserId ); |
|
158 |
|
159 // remove from the grant list, according to strategy |
|
160 TInt err( iBlockingManager.RemoveL( NULL, arr ) ); |
|
161 if ( err != KErrNone ) |
|
162 { |
|
163 HandleError( err ); |
|
164 } |
|
165 |
|
166 CleanupStack::PopAndDestroy( arr ); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------- |
|
170 // CCAStorageObserver::IMHandleAddition |
|
171 // (other items were commented in a header). |
|
172 // --------------------------------------------------------- |
|
173 // |
|
174 void CCAStorageObserver::IMHandleAddition( MCAStoredContact& aContact ) |
|
175 { |
|
176 TInt err( KErrNone ); |
|
177 |
|
178 if ( iApplicationSettings.Value( MCASettings::EReceiveIMessages ) |
|
179 == MCASettings::EFriends ) |
|
180 { |
|
181 TRAP( err, DoBlockingManagerAdditionL( aContact.UserId() ) ); |
|
182 HandleError( err ); |
|
183 } |
|
184 DoUpdateContactStatus( aContact ); |
|
185 } |
|
186 |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CCAStorageObserver::DoBlockingManagerAdditionL |
|
190 // (other items were commented in a header). |
|
191 // --------------------------------------------------------- |
|
192 // |
|
193 void CCAStorageObserver::DoBlockingManagerAdditionL( const TDesC& aUserId ) |
|
194 { |
|
195 // granularity of one because only one item appended to array |
|
196 CDesCArrayFlat* arr = new ( ELeave ) CDesCArrayFlat( 1 ); |
|
197 CleanupStack::PushL( arr ); |
|
198 arr->AppendL( aUserId ); |
|
199 |
|
200 // insert into the grant list, according to strategy |
|
201 iBlockingManager.InsertL( NULL, arr ); |
|
202 CleanupStack::PopAndDestroy( arr ); |
|
203 |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------- |
|
207 // CCAStorageObserver::DoUpdateContactStatus |
|
208 // (other items were commented in a header). |
|
209 // --------------------------------------------------------- |
|
210 // |
|
211 void CCAStorageObserver::DoUpdateContactStatus( MCAStoredContact& aContact ) |
|
212 { |
|
213 TPtrC wvid( aContact.UserId() ); |
|
214 |
|
215 // update the blocking status.. |
|
216 TBool blocked( EFalse ); |
|
217 const CDesCArray* blockList = iBlockingManager.BlockedList(); |
|
218 if ( blockList ) |
|
219 { |
|
220 // do a case-insensitive search |
|
221 TInt count( blockList->Count() ); |
|
222 for ( TInt i( 0 ); ( i < count ) && !blocked ; ++i ) |
|
223 { |
|
224 // (*blockList)[i].CompareC( wvid, KCollationLevel, NULL ) |
|
225 if ( CAUtils::NeutralCompare( ( *blockList )[i], wvid ) == 0 ) |
|
226 { |
|
227 blocked = ETrue; |
|
228 } |
|
229 } |
|
230 } |
|
231 aContact.SetBlocked( blocked ); |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CCAStorageObserver::HandleError |
|
236 // (other items were commented in a header). |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 void CCAStorageObserver::HandleError( TInt aError ) |
|
240 { |
|
241 CHAT_DP( D_CHAT_LIT( "CCAStorageObserver::HandleError, aError = %d" ), |
|
242 aError ); |
|
243 if ( ( aError > Imps_ERROR_BASE ) && ( aError < KErrNone ) ) |
|
244 { |
|
245 // propagate system errors to current active scheduler, |
|
246 // it should show a note |
|
247 CActiveScheduler::Current()->Error( aError ); |
|
248 } |
|
249 |
|
250 // imps errors are ignored at the moment as we don't have any |
|
251 // notes specified for them |
|
252 } |
|
253 |
|
254 |
|
255 // End of File |