|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * Provides methods for retrieving the log db data. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "MMSMTMLogData.h" |
|
24 #include "CMsgDeliveryItem.h" |
|
25 #include <logview.h> |
|
26 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
27 #include <logwrap.h> // KLogMaxRemotePartyLength |
|
28 #else |
|
29 #include <logwrap.h> // klogmaxremotepartylength |
|
30 #include <logwraplimits.h> // klogmaxremotepartylength |
|
31 #include <logengdurations.h> |
|
32 #endif |
|
33 #include <mmsclient.h> |
|
34 #include <mmsgenutils.h> |
|
35 #include <cntdb.h> |
|
36 #include <LogsApiConsts.h> // klogsmsgreadtext |
|
37 |
|
38 // CONSTANTS |
|
39 |
|
40 // MACROS |
|
41 |
|
42 // LOCAL CONSTANTS AND MACROS |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 |
|
46 // LOCAL FUNCTION PROTOTYPES |
|
47 |
|
48 // ==================== LOCAL FUNCTIONS ==================== |
|
49 |
|
50 |
|
51 // ================= MEMBER FUNCTIONS ======================= |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CMmsMTMLogData::CMmsMTMLogData |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CMmsMTMLogData::CMmsMTMLogData() : CActive( EPriorityStandard ) |
|
61 { |
|
62 iEventStatusRead.Copy( KLogsMsgReadText ); |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CMmsMTMLogData::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CMmsMTMLogData::ConstructL(MMmsMtmDeliveryDataContainer* aContainer, const TMmsMsvEntry& aEntry ) |
|
72 { |
|
73 iFs = new (ELeave) RFs; |
|
74 User::LeaveIfError( iFs->Connect() ); |
|
75 |
|
76 iLogClient = CLogClient::NewL( *iFs ); |
|
77 iEventView = CLogViewEvent::NewL( *iLogClient); |
|
78 iFilterList = new ( ELeave ) CLogFilterList; |
|
79 iParent = aContainer; |
|
80 iLoopCounter = 0; |
|
81 iEntry = aEntry; |
|
82 iState = ENone; |
|
83 iDataArray = new(ELeave) CArrayPtrFlat<CMsgDeliveryItem>(64); |
|
84 iLogClient->GetString( iEventStatusPendingTxt, R_LOG_DEL_PENDING ); |
|
85 iLogClient->GetString( iEventStatusSentTxt, R_LOG_DEL_SENT ); |
|
86 iLogClient->GetString( iEventStatusFailedTxt, R_LOG_DEL_FAILED ); |
|
87 iLogClient->GetString( iEventStatusNoDeliveryTxt, R_LOG_DEL_NONE ); |
|
88 iLogClient->GetString( iEventStatusDeliveredTxt, R_LOG_DEL_DONE ); |
|
89 iLogClient->GetString( iEventStatusNotSentTxt, R_LOG_DEL_NOT_SENT ); |
|
90 // See read status creation in construction |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CMmsMTMLogData::CMmsMTMLogData |
|
95 // Destructor |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CMmsMTMLogData::~CMmsMTMLogData() |
|
99 { |
|
100 Cancel(); |
|
101 |
|
102 if( iFilterList ) |
|
103 { |
|
104 iFilterList->ResetAndDestroy(); |
|
105 delete iFilterList; |
|
106 iFilterList = NULL; |
|
107 } |
|
108 if (iEventView) |
|
109 { |
|
110 delete iEventView; |
|
111 iEventView = NULL; |
|
112 } |
|
113 if (iLogClient) |
|
114 { |
|
115 delete iLogClient; |
|
116 iLogClient = NULL; |
|
117 } |
|
118 |
|
119 if (iFs) |
|
120 { |
|
121 iFs->Close(); |
|
122 delete iFs; |
|
123 } |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CMmsMTMLogData::NewL |
|
128 // Two-phased constructor. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CMmsMTMLogData* CMmsMTMLogData::NewL(MMmsMtmDeliveryDataContainer* aContainer, const TMmsMsvEntry& aEntry ) |
|
132 { |
|
133 CMmsMTMLogData* self = new( ELeave ) CMmsMTMLogData( ); |
|
134 |
|
135 CleanupStack::PushL( self ); |
|
136 self->ConstructL(aContainer, aEntry); |
|
137 CleanupStack::Pop(); |
|
138 |
|
139 return self; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // CMmsMTMLogData::DeliveryDataL |
|
144 // Creates the necessary Log filters and starts the log db query. |
|
145 // --------------------------------------------------------- |
|
146 // |
|
147 TBool CMmsMTMLogData::DeliveryDataL(const CMmsClientMtm* aMmsClient) |
|
148 { |
|
149 // Check for NULL. If NULL, return false (= no data found) |
|
150 if (!aMmsClient) |
|
151 { |
|
152 return EFalse; |
|
153 } |
|
154 |
|
155 MtmRecipientsToArrayL( *aMmsClient ); |
|
156 |
|
157 iState = EInit; |
|
158 const CMsvRecipientList& recipients = aMmsClient->AddresseeList(); |
|
159 TInt recipientCount = recipients.Count(); |
|
160 |
|
161 Cancel(); |
|
162 |
|
163 TTime sendingDate = aMmsClient->SendingDate(); |
|
164 for (TInt i = 0; i < recipientCount ; i++) |
|
165 { |
|
166 TPtrC number = TMmsGenUtils::PureAddress( recipients[i] ); |
|
167 |
|
168 CLogFilter* filter = CLogFilter::NewL(); |
|
169 CleanupStack::PushL( filter ); |
|
170 |
|
171 filter->SetEventType(KLogMmsEventTypeUid); |
|
172 filter->SetStartTime(sendingDate); |
|
173 filter->SetDurationType(KLogDurationNone); |
|
174 if ( TMmsGenUtils::IsValidMMSPhoneAddress( number, ETrue ) ) |
|
175 { |
|
176 filter->SetNumber( number.Left( Min( number.Length(), KLogMaxRemotePartyLength ) ) ); |
|
177 } |
|
178 else |
|
179 { |
|
180 filter->SetRemoteParty( number.Left( Min( number.Length(), KLogMaxRemotePartyLength ) ) ); |
|
181 } |
|
182 |
|
183 iFilterList->AppendL(filter); |
|
184 CleanupStack::Pop( filter ); |
|
185 } |
|
186 |
|
187 //Using SetFilterParseFilterByFilterL as it works for combination of RemoteParty and Number |
|
188 if ( !iEventView->SetFilterParseFilterByFilterL( *iFilterList, iStatus ) ) // something found with these filters, start the active object |
|
189 { |
|
190 iState = EFinalize; |
|
191 iStatus = KRequestPending; |
|
192 TRequestStatus* pStatus = &iStatus; |
|
193 User::RequestComplete( pStatus, KErrNone ); |
|
194 } |
|
195 SetActive(); |
|
196 return ETrue; |
|
197 |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------- |
|
201 // CMmsMTMLogData::DoCancel |
|
202 // Cancels the active object, from CActive |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 void CMmsMTMLogData::DoCancel() |
|
206 { |
|
207 iLogClient->Cancel(); |
|
208 iEventView->Cancel(); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CMmsMTMLogData::RunL |
|
213 // From CActive |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CMmsMTMLogData::RunL() |
|
217 { |
|
218 Cancel(); |
|
219 if (iStatus == KErrNone) |
|
220 { |
|
221 if (iState == EInit) // init phase finished |
|
222 { |
|
223 FetchItemL(); |
|
224 } |
|
225 else if (iState == EReading) // reading ongoing |
|
226 { |
|
227 CopyItemL(); |
|
228 } |
|
229 else if (iState == EFinalize) // reading ongoing |
|
230 { |
|
231 SendDataL(); |
|
232 } |
|
233 } |
|
234 |
|
235 if (iState != EFinished) |
|
236 { |
|
237 SetActive(); |
|
238 } |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------- |
|
242 // CMmsMTMLogData::RunError |
|
243 // Handles the error, if necessary. From CActive |
|
244 // --------------------------------------------------------- |
|
245 // |
|
246 TInt CMmsMTMLogData::RunError(TInt aError) |
|
247 { |
|
248 return aError; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CMmsMTMLogData::SendData |
|
253 // Callback method. After finished with filling the data array, |
|
254 // sends it back to the MMmsMtmDeliveryDataContainer (implemented in laucher class) |
|
255 // --------------------------------------------------------- |
|
256 // |
|
257 void CMmsMTMLogData::SendDataL() |
|
258 { |
|
259 iState = EFinished; |
|
260 iDataArray->Compress(); |
|
261 iParent->SetDataArrayL(iDataArray); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------- |
|
265 // CMmsMTMLogData::AddToArray |
|
266 // Converts the CLogEvent to CMsgDeliveryItem and adds it to the data array |
|
267 // --------------------------------------------------------- |
|
268 // |
|
269 void CMmsMTMLogData::AddToArrayL(CLogEvent* aEvent) |
|
270 { |
|
271 // Check for NULL. If null, exit |
|
272 if (!aEvent) |
|
273 { |
|
274 return; |
|
275 } |
|
276 // copy the data from the CLogEvent to CMsgDeliveryItem, |
|
277 // which will eventually be stored into the array |
|
278 CMsgDeliveryItem* item = CMsgDeliveryItem::NewL(); |
|
279 CleanupStack::PushL( item ); |
|
280 |
|
281 item->SetNumberL(aEvent->Number()); |
|
282 item->SetRecipientL(aEvent->RemoteParty()); |
|
283 item->SetTime(aEvent->Time()); |
|
284 |
|
285 if (aEvent->Status().Compare(iEventStatusPendingTxt) == 0) // msg item only supports three statuses, so theres some mapping to do. |
|
286 { |
|
287 item->SetStatus(CMsgDeliveryItem::EPending); |
|
288 } |
|
289 else if (aEvent->Status().CompareF(iEventStatusSentTxt) == 0) |
|
290 { |
|
291 item->SetStatus(CMsgDeliveryItem::EPending); |
|
292 } |
|
293 else if (aEvent->Status().CompareF(iEventStatusFailedTxt) == 0) |
|
294 { |
|
295 item->SetStatus(CMsgDeliveryItem::EFailed); |
|
296 } |
|
297 else if (aEvent->Status().CompareF(iEventStatusNoDeliveryTxt) == 0) |
|
298 { |
|
299 item->SetStatus(CMsgDeliveryItem::EFailed); |
|
300 } |
|
301 else if (aEvent->Status().CompareF(iEventStatusDeliveredTxt) == 0) |
|
302 { |
|
303 item->SetStatus(CMsgDeliveryItem::EDelivered); |
|
304 } |
|
305 else if (aEvent->Status().CompareF(iEventStatusRead) == 0) |
|
306 { |
|
307 item->SetStatus(CMsgDeliveryItem::ERead); |
|
308 } |
|
309 else if (aEvent->Status().CompareF(iEventStatusNotSentTxt) == 0) |
|
310 { |
|
311 item->SetStatus(CMsgDeliveryItem::EFailed); |
|
312 } |
|
313 else |
|
314 { |
|
315 item->SetStatus(CMsgDeliveryItem::ENone); |
|
316 } |
|
317 |
|
318 iDataArray->InsertL( iInsertedCount, item, 1 ); // add the item to the array |
|
319 iInsertedCount++; |
|
320 TPtrC recip = aEvent->RemoteParty(); |
|
321 DeleteRecipent( recip, EFalse, iInsertedCount ); |
|
322 CleanupStack::Pop( item ); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // CMmsMTMLogData::FetchItem |
|
327 // Starts to fetch the next CLogEvent from the CLogViewEvent |
|
328 // --------------------------------------------------------- |
|
329 // |
|
330 void CMmsMTMLogData::FetchItemL() |
|
331 { |
|
332 iState = EReading; |
|
333 if (iLoopCounter == 0) // the first one needs(?) to be fecthed differently |
|
334 { |
|
335 iEventView->FirstL(iStatus); |
|
336 } |
|
337 else |
|
338 { |
|
339 iEventView->NextL(iStatus); |
|
340 } |
|
341 } |
|
342 // --------------------------------------------------------- |
|
343 // CMmsMTMLogData::CopyItem |
|
344 // Copies the next CLogEvent from the CLogViewEvent |
|
345 // --------------------------------------------------------- |
|
346 // |
|
347 void CMmsMTMLogData::CopyItemL() |
|
348 { |
|
349 CLogEvent* event = CLogEvent::NewL(); |
|
350 CleanupStack::PushL(event); |
|
351 event->CopyL(iEventView->Event()); |
|
352 iLoopCounter++; |
|
353 |
|
354 TLogLink event_id = event->Link(); |
|
355 TMsvId message_id = iEntry.Id(); |
|
356 |
|
357 if (event_id == message_id) // check the message id from the event |
|
358 { |
|
359 AddToArrayL(event); |
|
360 } |
|
361 |
|
362 CleanupStack::PopAndDestroy(event); |
|
363 |
|
364 if (iLoopCounter >= iEventView->CountL()) // all the log events are now handled |
|
365 { |
|
366 iState = EFinalize; |
|
367 iStatus = KRequestPending; |
|
368 TRequestStatus* pStatus = &iStatus; |
|
369 User::RequestComplete( pStatus, KErrNone ); |
|
370 } |
|
371 |
|
372 else // still some log events left, continue fetching them one by one |
|
373 { |
|
374 FetchItemL(); |
|
375 } |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------- |
|
379 // CMmsMTMLogData::MtmRecipientsToArrayL |
|
380 // CLogViewEvent::SetFilterL() didn't start async operation. |
|
381 // Just copy recipients into 'destination'. |
|
382 // Calling this function means showing 'unavailable' status |
|
383 // --------------------------------------------------------- |
|
384 // |
|
385 void CMmsMTMLogData::MtmRecipientsToArrayL( const CMmsClientMtm& aMmsClient ) |
|
386 { |
|
387 const CMsvRecipientList& recipients = aMmsClient.AddresseeList(); |
|
388 TInt recipientCount = recipients.Count(); |
|
389 |
|
390 TTime sendingDate = aMmsClient.SendingDate(); |
|
391 |
|
392 HBufC* aliasBuf = HBufC::NewLC( KLogMaxRemotePartyLength ); |
|
393 TPtr aliasPtr = aliasBuf->Des(); |
|
394 |
|
395 for (TInt i = 0; i < recipientCount ; i++) |
|
396 { |
|
397 TPtrC recip = TMmsGenUtils::PureAddress( recipients[i] ); |
|
398 TBool isNumber = TMmsGenUtils::IsValidMMSPhoneAddress( recip, ETrue ); |
|
399 |
|
400 CMsgDeliveryItem* item = CMsgDeliveryItem::NewL(); |
|
401 CleanupStack::PushL( item ); |
|
402 |
|
403 item->SetStatus( CMsgDeliveryItem::ENone ); |
|
404 item->SetTime( sendingDate ); |
|
405 |
|
406 if ( isNumber ) |
|
407 { |
|
408 item->SetNumberL( recip ); |
|
409 item->SetRecipientL( recip ); |
|
410 |
|
411 // get alias too |
|
412 TInt error = TMmsGenUtils::GetAlias( |
|
413 recip, |
|
414 aliasPtr, |
|
415 KLogMaxRemotePartyLength, |
|
416 *iFs ); |
|
417 if ( error == KErrNone && aliasPtr.Length() > 0 ) |
|
418 { |
|
419 item->SetRecipientL( aliasPtr ); |
|
420 aliasPtr.Zero(); |
|
421 } |
|
422 else |
|
423 { |
|
424 // recipient must be there |
|
425 } |
|
426 } |
|
427 else |
|
428 { |
|
429 item->SetRecipientL( recip ); |
|
430 } |
|
431 |
|
432 iDataArray->AppendL(item); // add the item to the array |
|
433 CleanupStack::Pop( item ); |
|
434 } |
|
435 CleanupStack::PopAndDestroy( aliasBuf ); |
|
436 } |
|
437 |
|
438 |
|
439 // --------------------------------------------------------- |
|
440 // CMmsMTMLogData::DeleteRecipent |
|
441 // Checks whether given recipient is already in the iDataArray |
|
442 // --------------------------------------------------------- |
|
443 // |
|
444 void CMmsMTMLogData::DeleteRecipent( TDesC& aRecipient, |
|
445 TBool aType, |
|
446 TInt aInitialIndex ) |
|
447 { |
|
448 TInt count = iDataArray->Count( ); |
|
449 for( TInt i = aInitialIndex; i < count ; i++ ) |
|
450 { |
|
451 CMsgDeliveryItem* item = iDataArray->At(i); |
|
452 if ( item ) |
|
453 { |
|
454 TPtrC recip; |
|
455 if ( aType ) |
|
456 { |
|
457 recip.Set( item->GetNumber() ); |
|
458 } |
|
459 else |
|
460 { |
|
461 recip.Set( item->GetRecipient() ); |
|
462 } |
|
463 if ( !recip.CompareF( aRecipient ) ) |
|
464 { |
|
465 delete item; |
|
466 iDataArray->Delete( i ); |
|
467 break; |
|
468 } |
|
469 } |
|
470 } |
|
471 } |
|
472 |
|
473 |
|
474 |