|
1 /* |
|
2 * Copyright (c) 2002 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 * Defines methods for CMceLogPbkMatcher |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
23 #include <logfilterandeventconstants.hrh> |
|
24 #include <logengevents.h> |
|
25 #endif |
|
26 #include <e32base.h> |
|
27 #include <CPbkContactEngine.h> |
|
28 #include <CPbkContactItem.h> |
|
29 #include <CPbkFieldsInfo.h> |
|
30 #include <logview.h> |
|
31 #include <logcli.h> |
|
32 |
|
33 #include "MceLogPbkMatcher.h" |
|
34 #include "MceLogPbkMatcherObserver.h" |
|
35 #include "MceLogEngine.hrh" |
|
36 |
|
37 #include "CPhoneNumberMatcher.h" |
|
38 #include <LogsApiConsts.h> |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 |
|
45 CMceLogPbkMatcher::CMceLogPbkMatcher( |
|
46 RFs& aFsSession, |
|
47 MMceLogPbkMatcherObserver* aObserver) |
|
48 : CActive( EPriorityHigh ), |
|
49 iFsSession( aFsSession ), |
|
50 iObserver( aObserver ) |
|
51 { |
|
52 } |
|
53 |
|
54 |
|
55 CMceLogPbkMatcher* CMceLogPbkMatcher::NewL( |
|
56 RFs& aFsSession, |
|
57 MMceLogPbkMatcherObserver* aObserver ) |
|
58 { |
|
59 CMceLogPbkMatcher* self = new ( ELeave ) CMceLogPbkMatcher( |
|
60 aFsSession, |
|
61 aObserver ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(); |
|
65 return self; |
|
66 } |
|
67 |
|
68 void CMceLogPbkMatcher::ConstructL() |
|
69 { |
|
70 iReaderState = ECreated; |
|
71 iLogClient = CLogClient::NewL( iFsSession ); |
|
72 iLogViewEvent = CLogViewEvent::NewL( *iLogClient, *this ); |
|
73 iEvent = CLogEvent::NewL(); |
|
74 SetFiltersL(); |
|
75 CActiveScheduler::Add( this ); |
|
76 iPbkS60Matcher = CPhoneNumberMatcher::NewL( iFsSession ); |
|
77 } |
|
78 |
|
79 |
|
80 CMceLogPbkMatcher::~CMceLogPbkMatcher() |
|
81 { |
|
82 Cancel(); |
|
83 delete iPbkS60Matcher; |
|
84 delete iLogViewEvent; |
|
85 delete iLogClient; |
|
86 delete iEvent; |
|
87 if( iFilterList ) |
|
88 { |
|
89 iFilterList->ResetAndDestroy(); |
|
90 delete iFilterList; |
|
91 } |
|
92 } |
|
93 |
|
94 void CMceLogPbkMatcher::StartL() |
|
95 { |
|
96 Cancel(); |
|
97 |
|
98 if ( iReaderState == ECreated || iReaderState == EOpeningDefaultMatchStores ) |
|
99 { |
|
100 iPbkS60Matcher->OpenDefaultMatchStoresL( iStatus ); |
|
101 iReaderState = EOpeningDefaultMatchStores; |
|
102 SetActive(); |
|
103 } |
|
104 else |
|
105 { |
|
106 SetFiltersToLogsL(); |
|
107 } |
|
108 } |
|
109 |
|
110 void CMceLogPbkMatcher::SetFiltersToLogsL() |
|
111 { |
|
112 TBool rc = ( EFalse ); |
|
113 iReaderState = EFilteringEvent; |
|
114 |
|
115 TRAPD( err, ( rc = iLogViewEvent->SetFilterL( *iFilterList, iStatus ) ) ); |
|
116 if( err ) |
|
117 { |
|
118 if( err == KErrAccessDenied ) // backup active |
|
119 { |
|
120 return; |
|
121 } |
|
122 else |
|
123 { |
|
124 User::Leave( err ); |
|
125 } |
|
126 } |
|
127 |
|
128 if( rc ) |
|
129 { |
|
130 SetActive(); |
|
131 } |
|
132 } |
|
133 |
|
134 |
|
135 void CMceLogPbkMatcher::SetFiltersL() |
|
136 { |
|
137 if( iFilterList ) |
|
138 { |
|
139 iFilterList->ResetAndDestroy(); |
|
140 delete iFilterList; |
|
141 iFilterList = NULL; |
|
142 } |
|
143 iFilterList = new ( ELeave ) CLogFilterList(); |
|
144 |
|
145 /// Event type: SMS |
|
146 iFilterList->AppendL( SetOneFilterLC( KLogShortMessageEventTypeUid ) ); |
|
147 CleanupStack::Pop(); // filter set in SetOneFilterLC |
|
148 |
|
149 /// Event type: MMS |
|
150 iFilterList->AppendL( SetOneFilterLC( KLogsEngMmsEventTypeUid ) ); |
|
151 CleanupStack::Pop(); |
|
152 |
|
153 // Set filter with empty remote party |
|
154 CLogFilter* filter = CLogFilter::NewL(); |
|
155 CleanupStack::PushL( filter ); |
|
156 filter->SetNullFields( ELogRemotePartyField ); |
|
157 iFilterList->AppendL( filter ); |
|
158 CleanupStack::Pop(); // filter |
|
159 } |
|
160 |
|
161 |
|
162 CLogFilter* CMceLogPbkMatcher::SetOneFilterLC( TUid aFilterType ) |
|
163 { |
|
164 CLogFilter* filter = CLogFilter::NewL(); |
|
165 CleanupStack::PushL( filter ); |
|
166 filter->SetEventType( aFilterType ); // certain type; |
|
167 filter->SetFlags( KLogEventContactSearched ); // no flag or remoteparty |
|
168 filter->SetFlags( KLogEventRead ); // event has not been cleared |
|
169 filter->SetNullFields( ELogFlagsField | ELogRemotePartyField ); |
|
170 return filter; |
|
171 } |
|
172 |
|
173 |
|
174 |
|
175 void CMceLogPbkMatcher::DoCancel() |
|
176 { |
|
177 iPbkS60Matcher->CancelOperation(); |
|
178 iLogClient->Cancel(); |
|
179 iLogViewEvent->Cancel(); |
|
180 } |
|
181 |
|
182 |
|
183 TBool CMceLogPbkMatcher::GetRemotePartyL() |
|
184 { |
|
185 TBool result (EFalse ); |
|
186 if( iPbkS60Matcher->MatchCountL( iEvent->Number()) == 1 ) |
|
187 { |
|
188 result = ETrue; |
|
189 } |
|
190 return result; |
|
191 } |
|
192 |
|
193 void CMceLogPbkMatcher::RunL() |
|
194 { |
|
195 |
|
196 if( iStatus == KErrNone ) |
|
197 { |
|
198 switch( iReaderState ) |
|
199 { |
|
200 case EOpeningDefaultMatchStores: |
|
201 // now stores are open, continue with filtering |
|
202 SetFiltersToLogsL(); |
|
203 break; |
|
204 case EFilteringEvent: |
|
205 if( iLogViewEvent->FirstL( iStatus ) ) |
|
206 { |
|
207 iReaderState = EReadingEvent; |
|
208 SetActive(); |
|
209 } |
|
210 else if( iObserver ) |
|
211 { |
|
212 // iObserver->PbkMatchingDoneL(); |
|
213 } |
|
214 |
|
215 break; |
|
216 |
|
217 case EReadingEvent: |
|
218 |
|
219 iEvent->CopyL( iLogViewEvent->Event() ); |
|
220 iEvent->SetFlags( KLogEventContactSearched ); |
|
221 if( GetRemotePartyL() ) |
|
222 { |
|
223 iEvent->SetRemoteParty( iPbkS60Matcher->GetUniqueName() ); |
|
224 } |
|
225 iReaderState = EUpdatingEvent; |
|
226 iLogClient->ChangeEvent( *iEvent, iStatus ); |
|
227 SetActive(); |
|
228 break; |
|
229 |
|
230 case EUpdatingEvent: |
|
231 |
|
232 if( iLogViewEvent->FirstL( iStatus ) ) |
|
233 { |
|
234 iReaderState = EReadingEvent; |
|
235 SetActive(); |
|
236 } |
|
237 |
|
238 else if( iObserver ) |
|
239 { |
|
240 // iObserver->PbkMatchingDoneL(); |
|
241 } |
|
242 |
|
243 break; |
|
244 |
|
245 default: |
|
246 break; |
|
247 |
|
248 } |
|
249 } |
|
250 else if ( iReaderState == EOpeningDefaultMatchStores ) |
|
251 { |
|
252 iReaderState = ECreated; |
|
253 } |
|
254 } |
|
255 |
|
256 TInt CMceLogPbkMatcher::RunError(TInt aError) |
|
257 { |
|
258 if( aError == KErrAccessDenied || aError == KErrInUse ) // backup active |
|
259 { |
|
260 return KErrNone; |
|
261 } |
|
262 else |
|
263 { |
|
264 return aError; |
|
265 } |
|
266 } |
|
267 |
|
268 void CMceLogPbkMatcher::HandleLogViewChangeEventAddedL( |
|
269 TLogId /*aId*/, |
|
270 TInt /*aViewIndex*/, |
|
271 TInt /*aChangeIndex*/, |
|
272 TInt /*aTotalChangeCount*/) |
|
273 { |
|
274 StartL(); |
|
275 } |
|
276 |
|
277 void CMceLogPbkMatcher::HandleLogViewChangeEventChangedL( |
|
278 TLogId /*aId*/, |
|
279 TInt /*aViewIndex*/, |
|
280 TInt /*aChangeIndex*/, |
|
281 TInt /*aTotalChangeCount*/) |
|
282 { |
|
283 StartL(); |
|
284 } |
|
285 |
|
286 void CMceLogPbkMatcher::HandleLogViewChangeEventDeletedL( |
|
287 TLogId /*aId*/, |
|
288 TInt /*aViewIndex*/, |
|
289 TInt /*aChangeIndex*/, |
|
290 TInt /*aTotalChangeCount*/) |
|
291 { |
|
292 StartL(); |
|
293 } |
|
294 |
|
295 |
|
296 // End of File |
|
297 |