|
1 /* |
|
2 * Copyright (c) 2006-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: Harvester image plugin |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <smsclnt.h> |
|
21 #include <smuthdr.h> |
|
22 #include <smsclnt.h> |
|
23 #include <smut.h> |
|
24 #include <gsmuelem.h> |
|
25 #include <msventry.h> |
|
26 #include <msvuids.h> |
|
27 #include <mmsconst.h> |
|
28 #include <mtclreg.h> |
|
29 #include <mmsclient.h> |
|
30 #include <mdetextproperty.h> |
|
31 |
|
32 #include "harvestermessageplugin.h" |
|
33 #include "harvesterlog.h" |
|
34 #include "mdsutils.h" |
|
35 #include "mdeobjectdef.h" |
|
36 |
|
37 #ifdef _DEBUG |
|
38 _LIT( KMsgHarvesterMsvPanic, "Message harvester: Message server terminated" ); |
|
39 #endif |
|
40 _LIT( KSemicolonSpace, "; " ); |
|
41 _LIT( KCharSpace, " " ); |
|
42 _LIT( KCharLeftAddressIterator, "<" ); |
|
43 _LIT( KCharRightAddressIterator, ">" ); |
|
44 |
|
45 /** |
|
46 * Default constructor |
|
47 */ |
|
48 CHarvesterMessagePlugin::CHarvesterMessagePlugin() : CHarvesterPlugin() |
|
49 , iItemType(NULL, 0) |
|
50 , iSubject(NULL, 0) |
|
51 { |
|
52 } |
|
53 |
|
54 /** |
|
55 * Construction |
|
56 * @return Harvester image plugin |
|
57 */ |
|
58 CHarvesterMessagePlugin* CHarvesterMessagePlugin::NewL() |
|
59 { |
|
60 WRITELOG("CHarvesterMessagePlugin::NewL()"); |
|
61 CHarvesterMessagePlugin* self = new(ELeave) CHarvesterMessagePlugin(); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 /** |
|
70 * Destruction |
|
71 */ |
|
72 CHarvesterMessagePlugin::~CHarvesterMessagePlugin() |
|
73 { |
|
74 WRITELOG("CHarvesterMessagePlugin::~CHarvesterMessagePlugin()"); |
|
75 delete iMmsMtm; |
|
76 delete iSmsMtm; |
|
77 delete iMtmReg; |
|
78 delete iMsvSession; |
|
79 } |
|
80 |
|
81 /** |
|
82 * 2nd phase constructor |
|
83 */ |
|
84 void CHarvesterMessagePlugin::ConstructL() |
|
85 { |
|
86 WRITELOG("CHarvesterMessagePlugin::ConstructL()"); |
|
87 if ( iMsvSession ) |
|
88 { |
|
89 delete iMsvSession; |
|
90 iMsvSession = NULL; |
|
91 } |
|
92 iMsvSession = CMsvSession::OpenSyncL( *this ); |
|
93 |
|
94 iMtmReg = CClientMtmRegistry::NewL( *iMsvSession ); |
|
95 iMmsMtm = static_cast<CMmsClientMtm*> |
|
96 ( iMtmReg->NewMtmL( KUidMsgTypeMultimedia ) ); |
|
97 iSmsMtm = static_cast<CSmsClientMtm*> |
|
98 ( iMtmReg->NewMtmL( KUidMsgTypeSMS ) ); |
|
99 |
|
100 } |
|
101 |
|
102 void CHarvesterMessagePlugin::HarvestL( CHarvesterData* aHD ) |
|
103 { |
|
104 CMdEObject& mdeObject = aHD->MdeObject(); |
|
105 mdeObject.SetMediaId( 0 ); |
|
106 |
|
107 TRAPD( error, GatherDataL( mdeObject ) ); |
|
108 if ( error != KErrNone ) |
|
109 { |
|
110 WRITELOG1( "CHarvesterMessagePlugin::HarvestSingleFileL() - TRAP error: %d", error ); |
|
111 TInt convertedError = KErrNone; |
|
112 MdsUtils::ConvertTrapError( error, convertedError ); |
|
113 aHD->SetErrorCode( convertedError ); |
|
114 return; |
|
115 } |
|
116 |
|
117 #ifdef _DEBUG |
|
118 TRAP(error, SetPropertiesL( *aHD )); |
|
119 |
|
120 if ( error != KErrNone ) |
|
121 { |
|
122 WRITELOG1( "CHarvesterMessagePlugin::HarvestSingleFileL() - Handling object failed: %d", error ); |
|
123 } |
|
124 #else |
|
125 TRAP_IGNORE( SetPropertiesL( *aHD ) ); |
|
126 #endif |
|
127 |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // CHarvesterMessagePlugin::GatherDataL |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CHarvesterMessagePlugin::GatherDataL( CMdEObject& aMetadataObject ) |
|
135 { |
|
136 |
|
137 WRITELOG( "CHarvesterMessagePlugin::GatherDataL enter" ); |
|
138 const TChar KPoint( '.' ); |
|
139 |
|
140 const TDesC& uri = aMetadataObject.Uri(); |
|
141 const TInt i = uri.Locate( KPoint ); |
|
142 TMsvId msgId( 0 ); |
|
143 |
|
144 TLex lex( uri.Left( i ) ); |
|
145 lex.Val( msgId ); |
|
146 WRITELOG1( "msgId: %d", msgId ); |
|
147 |
|
148 TMsvId service = 0; |
|
149 TMsvEntry tEntry; |
|
150 TInt err = iMsvSession->GetEntry( msgId, service, tEntry ); |
|
151 User::LeaveIfError( err ); |
|
152 |
|
153 CBaseMtm* actMtm( iSmsMtm ); |
|
154 |
|
155 WRITELOG1( "tEntry.iMtm.iUid: %d", tEntry.iMtm.iUid ); |
|
156 |
|
157 |
|
158 if ( tEntry.iMtm.iUid == KUidMsgTypeMultimedia.iUid ) |
|
159 { |
|
160 WRITELOG( "MMS MESSAGE" ); |
|
161 actMtm = iMmsMtm; |
|
162 } |
|
163 actMtm->SwitchCurrentEntryL( msgId ); |
|
164 actMtm->LoadMessageL(); |
|
165 |
|
166 tEntry = actMtm->Entry().Entry(); |
|
167 |
|
168 WRITELOG1( "tEntry.iMtm.iUid: %d", tEntry.iMtm.iUid ); |
|
169 |
|
170 TMsvId parentId = tEntry.Parent(); |
|
171 |
|
172 WRITELOG1( "parentId: %d", parentId ); |
|
173 |
|
174 iSize = (TUint)tEntry.iSize; |
|
175 |
|
176 WRITELOG1( "size: %d", iSize ); |
|
177 |
|
178 iDate = tEntry.iDate; |
|
179 |
|
180 #ifdef _DEBUG |
|
181 WRITELOG1( "date.DaysInMonth: %d", iDate.DaysInMonth() ); |
|
182 #endif |
|
183 |
|
184 delete iFromOrTo; |
|
185 iFromOrTo = NULL; |
|
186 |
|
187 if ( KMsvSentEntryId == parentId ) // sent |
|
188 { |
|
189 iIncoming = EFalse; |
|
190 const CDesCArray& array = static_cast<const CDesCArray&>( |
|
191 actMtm->AddresseeList().RecipientList() ); |
|
192 TInt count( array.Count() ); |
|
193 TInt maxLength( 0 ); |
|
194 |
|
195 for ( TInt i( 0 ); i < count; ++i ) |
|
196 { |
|
197 maxLength += array[i].Length(); |
|
198 } |
|
199 WRITELOG1( "maxLength: %d", maxLength ); |
|
200 |
|
201 iFromOrTo = HBufC::NewL( maxLength + 3 * count ); |
|
202 TPtr desReceipients( iFromOrTo->Des() ) ; |
|
203 |
|
204 for ( TInt i( 0 ); i < count; ++i ) |
|
205 { |
|
206 desReceipients.Append( array[i] ); |
|
207 desReceipients.Append( KSemicolonSpace ); |
|
208 } |
|
209 count = desReceipients.Length(); |
|
210 WRITELOG1("count: %d", count ); |
|
211 |
|
212 if ( count ) |
|
213 { |
|
214 desReceipients.Delete( count - 2, 2 ); |
|
215 } |
|
216 } |
|
217 else // KMsvGlobalInBoxIndexEntryId received |
|
218 { |
|
219 iIncoming = ETrue; |
|
220 WRITELOG( "Got incoming" ); |
|
221 |
|
222 HBufC* senderNumber = NULL; |
|
223 if ( tEntry.iMtm.iUid == KUidMsgTypeMultimedia.iUid ) |
|
224 { |
|
225 senderNumber = iMmsMtm->Sender().AllocLC(); |
|
226 } |
|
227 else |
|
228 { |
|
229 senderNumber= iSmsMtm->SmsHeader().FromAddress().AllocLC(); |
|
230 } |
|
231 |
|
232 TInt senderLength = senderNumber->Length(); |
|
233 if ( senderLength > 0 ) |
|
234 { |
|
235 // Check if we have an alias |
|
236 if ( senderNumber->Compare( tEntry.iDetails ) ) |
|
237 { |
|
238 // Additional space for chars: '<' '>' ',' |
|
239 senderLength += KCharSpace.iTypeLength + |
|
240 KCharLeftAddressIterator.iTypeLength + |
|
241 KCharRightAddressIterator.iTypeLength; |
|
242 |
|
243 iFromOrTo = HBufC::NewL( tEntry.iDetails.Length() + senderLength ); |
|
244 TPtr fromTextPtr = iFromOrTo->Des(); |
|
245 fromTextPtr.Append( tEntry.iDetails ); |
|
246 fromTextPtr.Append( KCharSpace ); |
|
247 fromTextPtr.Append( KCharLeftAddressIterator ); |
|
248 fromTextPtr.Append( *senderNumber ); |
|
249 fromTextPtr.Append( KCharRightAddressIterator ); |
|
250 } |
|
251 else |
|
252 { |
|
253 iFromOrTo = senderNumber->AllocL(); |
|
254 } |
|
255 } |
|
256 else |
|
257 { |
|
258 iFromOrTo = senderNumber->AllocL(); |
|
259 } |
|
260 |
|
261 CleanupStack::PopAndDestroy( senderNumber ); |
|
262 } |
|
263 |
|
264 // Set subject - MMS has subject but SMS doesn't have one |
|
265 if ( tEntry.iMtm.iUid == KUidMsgTypeMultimedia.iUid ) |
|
266 { |
|
267 iItemType.Set( MdeConstants::Message::KMMSItemType ); |
|
268 iSubject.Set( iMmsMtm->SubjectL() ); |
|
269 } |
|
270 else |
|
271 { |
|
272 iItemType.Set( MdeConstants::Message::KSMSItemType ); |
|
273 iSubject.Set( KNullDesC ); |
|
274 } |
|
275 |
|
276 WRITELOG1( "fromOrTo: %S", iFromOrTo ); |
|
277 WRITELOG1( "incoming: %b", iIncoming ); |
|
278 |
|
279 WRITELOG( "CHarvesterMessagePlugin::GatherDataL return" ); |
|
280 return KErrNone; |
|
281 } |
|
282 |
|
283 void CHarvesterMessagePlugin::SetPropertiesL( CHarvesterData& aHD ) |
|
284 { |
|
285 WRITELOG( "CHarvesterMessagePlugin::SetPropertiesL enter" ); |
|
286 CMdEObject& aMetadataObject = aHD.MdeObject(); |
|
287 |
|
288 CMdEObjectDef& messageObjectDef = aMetadataObject.Def(); |
|
289 |
|
290 CMdEPropertyDef& creationTimeDef = messageObjectDef.GetPropertyDefL( |
|
291 MdeConstants::Object::KCreationDateProperty ) ; |
|
292 |
|
293 CMdEPropertyDef& lastModTimeDef = messageObjectDef.GetPropertyDefL( |
|
294 MdeConstants::Object::KLastModifiedDateProperty ) ; |
|
295 |
|
296 CMdEPropertyDef& sizeDef = messageObjectDef.GetPropertyDefL( |
|
297 MdeConstants::Object::KSizeProperty ) ; |
|
298 |
|
299 CMdEPropertyDef& receivedDef = messageObjectDef.GetPropertyDefL( |
|
300 MdeConstants::Message::KReceivedProperty ) ; |
|
301 |
|
302 CMdEPropertyDef& textDef = iIncoming |
|
303 ? messageObjectDef.GetPropertyDefL( MdeConstants::Message::KSenderProperty ) |
|
304 : messageObjectDef.GetPropertyDefL( MdeConstants::Message::KToWhomProperty ); |
|
305 |
|
306 CMdEPropertyDef& ItemtypeDef = messageObjectDef.GetPropertyDefL( |
|
307 MdeConstants::Object::KItemTypeProperty ); |
|
308 |
|
309 CMdEPropertyDef& offSetDef = messageObjectDef.GetPropertyDefL( |
|
310 MdeConstants::Object::KTimeOffsetProperty ); |
|
311 |
|
312 CMdEPropertyDef& titleDef = messageObjectDef.GetPropertyDefL( |
|
313 MdeConstants::Object::KTitleProperty ); |
|
314 |
|
315 TTimeIntervalSeconds timeOffset = User::UTCOffset(); |
|
316 TTime now; |
|
317 now.HomeTime(); |
|
318 |
|
319 if ( EHarvesterAdd == aHD.EventType() ) |
|
320 { |
|
321 aMetadataObject.AddTimePropertyL( creationTimeDef, now ); |
|
322 aMetadataObject.AddTimePropertyL( lastModTimeDef, iDate ); |
|
323 aMetadataObject.AddBoolPropertyL( receivedDef, iIncoming ); |
|
324 if (iFromOrTo && iFromOrTo->Length()) |
|
325 { |
|
326 aMetadataObject.AddTextPropertyL( textDef, *iFromOrTo ); |
|
327 } |
|
328 aMetadataObject.AddTextPropertyL( ItemtypeDef, iItemType ); |
|
329 aMetadataObject.AddUint32PropertyL( sizeDef, iSize ); |
|
330 aMetadataObject.AddInt16PropertyL( offSetDef, timeOffset.Int() / 60 ); |
|
331 |
|
332 CMdEProperty* prop = NULL; |
|
333 TInt index = aMetadataObject.Property( titleDef, prop ); |
|
334 |
|
335 if (iSubject.Length()) |
|
336 { |
|
337 if( prop ) |
|
338 { |
|
339 prop->SetTextValueL( iSubject ); |
|
340 } |
|
341 else |
|
342 { |
|
343 aMetadataObject.AddTextPropertyL( titleDef, iSubject ); |
|
344 } |
|
345 } |
|
346 else |
|
347 { |
|
348 if (iFromOrTo && iFromOrTo->Length()) |
|
349 { |
|
350 if( prop ) |
|
351 { |
|
352 prop->SetTextValueL( *iFromOrTo ); |
|
353 } |
|
354 else |
|
355 { |
|
356 aMetadataObject.AddTextPropertyL( titleDef, *iFromOrTo ); |
|
357 } |
|
358 } |
|
359 } |
|
360 } |
|
361 else |
|
362 { |
|
363 CMdEProperty* prop = NULL; |
|
364 TInt index = aMetadataObject.Property( textDef, prop ); |
|
365 if (iFromOrTo && iFromOrTo->Length()) |
|
366 { |
|
367 if (prop) |
|
368 { |
|
369 prop->SetTextValueL( *iFromOrTo ); |
|
370 } |
|
371 else |
|
372 { |
|
373 aMetadataObject.AddTextPropertyL( textDef, *iFromOrTo ); |
|
374 } |
|
375 } |
|
376 else if (index >= 0) |
|
377 { |
|
378 aMetadataObject.RemoveProperty(index); |
|
379 } |
|
380 |
|
381 aMetadataObject.Property( sizeDef, prop ); |
|
382 static_cast<CMdEUint32Property *>(prop)->SetValueL( iSize ); |
|
383 |
|
384 aMetadataObject.Property( lastModTimeDef, prop ); |
|
385 static_cast <CMdETimeProperty *>(prop)->SetValueL( iDate ); |
|
386 } |
|
387 |
|
388 iStatus = KErrNone; |
|
389 WRITELOG( "CHarvesterMessagePlugin::SetPropertiesL return" ); |
|
390 } |
|
391 |
|
392 // ----------------------------------------------------------------------------- |
|
393 // CHarvesterMessagePlugin::HandleSessionEventL |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void CHarvesterMessagePlugin::HandleSessionEventL( TMsvSessionEvent aEvent, |
|
397 TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/ ) |
|
398 { |
|
399 WRITELOG( "CHarvesterMessagePlugin::HandleSessionEventL enter" ); |
|
400 |
|
401 switch ( aEvent ) |
|
402 { |
|
403 case EMsvGeneralError: // not used after v5 |
|
404 case EMsvServerFailedToStart: |
|
405 case EMsvServerTerminated: |
|
406 { |
|
407 __ASSERT_DEBUG( EFalse, User::Panic( KMsgHarvesterMsvPanic, KErrServerTerminated )); |
|
408 break; |
|
409 } |
|
410 case EMsvEntriesCreated: |
|
411 case EMsvEntriesChanged: |
|
412 case EMsvEntriesDeleted: |
|
413 case EMsvEntriesMoved: |
|
414 case EMsvMtmGroupInstalled: |
|
415 case EMsvMtmGroupDeInstalled: |
|
416 case EMsvServerReady: |
|
417 case EMsvCorruptedIndexRebuilt: |
|
418 case EMsvMediaChanged: |
|
419 case EMsvMediaUnavailable: |
|
420 case EMsvMediaAvailable: |
|
421 case EMsvMediaIncorrect: |
|
422 case EMsvCorruptedIndexRebuilding: |
|
423 case EMsvCloseSession: |
|
424 default: |
|
425 { |
|
426 break; |
|
427 } |
|
428 } |
|
429 WRITELOG( "CHarvesterMessagePlugin::HandleSessionEventL return" ); |
|
430 } |