|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Provides MMS indirect upload service. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <CSendingServiceInfo.h> |
|
24 #include <SendUiConsts.h> |
|
25 #include <CMessageData.h> |
|
26 #include <senduisingleton.h> |
|
27 #include <MmsConst.h> |
|
28 #include <bautils.h> // BaflUtils |
|
29 #include <barsc.h> // RResourceFile |
|
30 #include <f32file.h> // TParse |
|
31 #include <TSendingCapabilities.h> |
|
32 #include <SenduiMtmUids.h> |
|
33 |
|
34 #include "CMmsIndirectUpload.h" |
|
35 #include "SendUiOperationWait.h" |
|
36 #include "SendUiFileRightsEngine.h" |
|
37 #include "CSendUiAttachment.h" |
|
38 |
|
39 #include <data_caging_path_literals.hrh> |
|
40 |
|
41 // CONSTANTS |
|
42 const TInt KMaxMmsUploadServiceCount = 4; |
|
43 const TInt KMmsIndirectUploadService = 2; |
|
44 const TInt KMaxServiceAddressLength = 512; |
|
45 const TInt KMaxServiceNameLength = 128; |
|
46 const TInt KMaxServiceMenuNameLength = 128; |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CMmsIndirectUpload::CMmsIndirectUpload |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CMmsIndirectUpload::CMmsIndirectUpload( CCoeEnv& aCoeEnv, CSendUiSingleton& aSingleton ) |
|
57 : CSendingService( aCoeEnv, aSingleton ) |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CMmsIndirectUpload::ConstructL |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CMmsIndirectUpload::ConstructL() |
|
67 { |
|
68 ReadServiceDataL(); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CMmsIndirectUpload::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CMmsIndirectUpload* CMmsIndirectUpload::NewL( TSendingServiceParams* aParams ) |
|
77 { |
|
78 CMmsIndirectUpload* self = new(ELeave) CMmsIndirectUpload( aParams->iCoeEnv, aParams->iSingleton ); |
|
79 |
|
80 CleanupStack::PushL(self); |
|
81 self->ConstructL(); |
|
82 CleanupStack::Pop(self); |
|
83 |
|
84 return self; |
|
85 } |
|
86 |
|
87 // Destructor |
|
88 CMmsIndirectUpload::~CMmsIndirectUpload() |
|
89 { |
|
90 iServiceArray.ResetAndDestroy(); |
|
91 iServiceArray.Close(); |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------- |
|
96 // CMmsIndirectUpload::ServiceProviderId |
|
97 // Returns the id of the service provider. |
|
98 // (other items were commented in a header). |
|
99 // --------------------------------------------------------- |
|
100 // |
|
101 TUid CMmsIndirectUpload::ServiceProviderId() const |
|
102 { |
|
103 return KMmsIndirectUpload; |
|
104 } |
|
105 |
|
106 TUid CMmsIndirectUpload::TechnologyTypeId( ) const |
|
107 { |
|
108 return TUid::Uid( KSenduiTechnologyMmsUidValue ); |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CMmsIndirectUpload::CreateAndSendMessageL |
|
113 // Creates message to be sent and opens MMS editor. |
|
114 // (other items were commented in a header). |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CMmsIndirectUpload::CreateAndSendMessageL( |
|
118 TUid aServiceUid, |
|
119 const CMessageData* aMessageData, |
|
120 TBool /*aLaunchEditorEmbedded */) |
|
121 { |
|
122 TInt i = 0; |
|
123 |
|
124 RSendAs sendAsSession; |
|
125 User::LeaveIfError( sendAsSession.Connect() ); |
|
126 TInt cleanupItems(0); |
|
127 CleanupClosePushL( sendAsSession ); |
|
128 cleanupItems++; |
|
129 if ( !CheckMmsServiceAvailabilityL( sendAsSession ) ) |
|
130 { |
|
131 CleanupStack::PopAndDestroy( &sendAsSession ); // sendAsSession |
|
132 return; |
|
133 } |
|
134 |
|
135 RSendAsMessage sendAsMessage; |
|
136 CleanupClosePushL( sendAsMessage ); |
|
137 cleanupItems++; |
|
138 sendAsMessage.CreateL( sendAsSession, KSenduiMtmUniMessageUid ); |
|
139 // BIO type identifies MMS message as upload message. |
|
140 sendAsMessage.SetBioTypeL( KUidMsgSubTypeMmsUpload ); |
|
141 |
|
142 // Set service address |
|
143 for ( i=0; i < iServiceArray.Count(); i++) |
|
144 { |
|
145 if ( (*iServiceArray[i]).ServiceId() == aServiceUid) |
|
146 { |
|
147 TPtrC address = (*iServiceArray[i]).ServiceAddress(); |
|
148 |
|
149 if ( address != KNullDesC ) |
|
150 { |
|
151 sendAsMessage.AddRecipientL( |
|
152 address, |
|
153 (*iServiceArray[i]).ServiceName(), |
|
154 RSendAsMessage::ESendAsRecipientTo ); |
|
155 } |
|
156 else |
|
157 { |
|
158 User::Leave( KErrNotFound ); |
|
159 } |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 CArrayPtrFlat<CSendUiAttachment>* attachments(NULL); |
|
165 |
|
166 // Get attachments |
|
167 if ( aMessageData ) |
|
168 { |
|
169 attachments = CSendUiAttachment::InitAttachmentArrayLCC( |
|
170 aMessageData->AttachmentArray(), |
|
171 aMessageData->AttachmentHandleArray(), |
|
172 iCoeEnv.FsSession() ); |
|
173 cleanupItems += 2; |
|
174 } |
|
175 if ( aMessageData ) |
|
176 { |
|
177 if ( !ValidateAttachmentsL( attachments ) ) |
|
178 { |
|
179 // attachments, sendAsMessage, sendAsSession |
|
180 CleanupStack::PopAndDestroy( cleanupItems, &sendAsSession ); |
|
181 return; |
|
182 } |
|
183 |
|
184 const CRichText* bodyText = aMessageData->BodyText(); |
|
185 if ( bodyText->DocumentLength() > 0 ) |
|
186 { |
|
187 CSendUiAttachment* atta = CSendUiAttachment::NewLC( *bodyText, iCoeEnv.FsSession() ); |
|
188 attachments->AppendL( atta ); |
|
189 CleanupStack::Pop( atta ); |
|
190 } |
|
191 |
|
192 for ( i = 0; i < attachments->Count(); i++ ) |
|
193 { |
|
194 CSendUiOperationWait* waiter = CSendUiOperationWait::NewLC(); |
|
195 CSendUiAttachment& attachmentPacket = *(attachments->At(i)); |
|
196 |
|
197 if ( attachmentPacket.Type() == CSendUiAttachment::EAttachmentPath ) |
|
198 { |
|
199 sendAsMessage.AddAttachment( |
|
200 *(attachmentPacket.Path()), |
|
201 attachmentPacket.MimeType(), |
|
202 waiter->iStatus ); |
|
203 } |
|
204 else |
|
205 { |
|
206 RFile attachment; |
|
207 attachment.Duplicate( *(attachmentPacket.Handle()) ); |
|
208 sendAsMessage.AddAttachment( |
|
209 attachment, |
|
210 attachmentPacket.MimeType(), |
|
211 waiter->iStatus ); |
|
212 } |
|
213 |
|
214 waiter->Start( (CActive*)NULL ); |
|
215 CleanupStack::PopAndDestroy( waiter ); |
|
216 } |
|
217 |
|
218 } |
|
219 TInt attachmentCount( 0 ); |
|
220 if ( attachments ) |
|
221 { |
|
222 attachmentCount = attachments->Count(); |
|
223 CleanupStack::PopAndDestroy( 2, attachments ); |
|
224 cleanupItems -= 2; |
|
225 } |
|
226 |
|
227 if ( attachmentCount > 0 ) |
|
228 { |
|
229 sendAsMessage.LaunchEditorAndCloseL(); // sendAsMessage is closed |
|
230 CleanupStack::Pop( &sendAsMessage ); |
|
231 } |
|
232 else |
|
233 { |
|
234 CleanupStack::PopAndDestroy( &sendAsMessage); // sendAsMessage |
|
235 } |
|
236 cleanupItems--; |
|
237 CleanupStack::PopAndDestroy( cleanupItems, &sendAsSession ); |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CMmsIndirectUpload::ValidateAttachmentsL |
|
242 // Validates attachments for sending. DRM protection and MMS validity are |
|
243 // checked. DRM query and error note is shown if needed. Return value of |
|
244 // attachment arrays contains valid attachments. |
|
245 // (other items were commented in a header). |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 TBool CMmsIndirectUpload::ValidateAttachmentsL( CArrayPtrFlat<CSendUiAttachment>* aAttachments ) |
|
249 { |
|
250 TBool continueSending( ETrue ); |
|
251 |
|
252 |
|
253 // Validate attachments and show query and error note if needed. |
|
254 if ( aAttachments->Count() > 0 ) |
|
255 { |
|
256 CSendUiFileRightsEngine* fileRightsEngine = |
|
257 CSendUiFileRightsEngine::NewLC( iCoeEnv.FsSession() ); |
|
258 |
|
259 fileRightsEngine->ConfirmDrmFileRightsL( aAttachments ); |
|
260 fileRightsEngine->ConfirmMmsValidityL( aAttachments ); |
|
261 |
|
262 continueSending = fileRightsEngine->ShowDrmAndMmsInfoL( KMmsIndirectUpload ); |
|
263 |
|
264 CleanupStack::PopAndDestroy( fileRightsEngine ); |
|
265 } |
|
266 return continueSending; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CMmsIndirectUpload::PopulateServicesListL |
|
271 // Populates given list with the services provided by this plugin. |
|
272 // The ownership of the pointed objects remains. |
|
273 // (other items were commented in a header). |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CMmsIndirectUpload::PopulateServicesListL( |
|
277 RPointerArray<CSendingServiceInfo>& aList ) |
|
278 { |
|
279 for ( TInt cc = 0; cc < iServiceArray.Count(); cc++ ) |
|
280 { |
|
281 User::LeaveIfError( aList.Append( iServiceArray[cc] ) ); |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CMmsIndirectUpload::ReadServiceDataL |
|
287 // Reads service names from resource file and addresses from shared data or |
|
288 // central repository. |
|
289 // (other items were commented in a header). |
|
290 // ----------------------------------------------------------------------------- |
|
291 // |
|
292 void CMmsIndirectUpload::ReadServiceDataL() |
|
293 { |
|
294 // Read the maximum MMS message size (bytes). |
|
295 TInt maxMsgSize = 0; |
|
296 CRepository* mmsRepository = CRepository::NewL( KCRUidMmsEngine ); |
|
297 mmsRepository->Get( KMmsEngineMaximumSendSize, maxMsgSize ); |
|
298 delete mmsRepository; |
|
299 |
|
300 CRepository* senduiRepository = CRepository::NewLC( KCRUidSendUi ); |
|
301 TInt i = 0; |
|
302 // Go through services and get settings for indirect upload services. |
|
303 // There can be 0-4 indirect upload services configured. |
|
304 for ( i = 0; i < KMaxMmsUploadServiceCount; i++) |
|
305 { |
|
306 TInt serviceType = 0; |
|
307 TInt err = senduiRepository->Get( KSUMmsUploadType1 + i , serviceType ); |
|
308 |
|
309 // Get settings and store those to service array. |
|
310 if ( !err && serviceType == KMmsIndirectUploadService ) |
|
311 { |
|
312 CSendingServiceInfo* serviceInfo = CSendingServiceInfo::NewL(); |
|
313 CleanupStack::PushL( serviceInfo ); |
|
314 |
|
315 HBufC* serviceAddress = HBufC::NewLC( KMaxServiceAddressLength ); |
|
316 TPtr serviceAddressPtr = serviceAddress->Des(); |
|
317 User::LeaveIfError( senduiRepository->Get( KSUMmsUploadAddress1 + i , serviceAddressPtr ) ); |
|
318 serviceInfo->SetServiceAddressL( serviceAddressPtr ); |
|
319 CleanupStack::PopAndDestroy( serviceAddress ); |
|
320 |
|
321 HBufC* serviceName = HBufC::NewLC( KMaxServiceNameLength ); |
|
322 TPtr serviceNamePtr = serviceName->Des(); |
|
323 User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceName1 + i , serviceNamePtr ) ); |
|
324 serviceInfo->SetServiceNameL( serviceNamePtr ); |
|
325 CleanupStack::PopAndDestroy( serviceName ); |
|
326 |
|
327 HBufC* serviceMenuName = HBufC::NewLC( KMaxServiceMenuNameLength ); |
|
328 TPtr serviceMenuNamePtr = serviceMenuName->Des(); |
|
329 User::LeaveIfError( senduiRepository->Get( KSUMmsUploadServiceMenuName1 + i , serviceMenuNamePtr ) ); |
|
330 serviceInfo->SetServiceMenuNameL( serviceMenuNamePtr ); |
|
331 CleanupStack::PopAndDestroy( serviceMenuName ); |
|
332 |
|
333 // Set service type. |
|
334 serviceInfo->SetServiceProviderId( KMmsIndirectUpload ); |
|
335 |
|
336 // Set sending capabilities. |
|
337 TSendingCapabilities capabilities = |
|
338 TSendingCapabilities( 0, KMaxTInt, |
|
339 TSendingCapabilities::ESupportsAttachments ); |
|
340 |
|
341 serviceInfo->SetServiceCapabilities( capabilities ); |
|
342 |
|
343 TUid serviceId = KNullUid; |
|
344 switch ( i ) |
|
345 { |
|
346 case 0: |
|
347 { |
|
348 serviceId = KMmsUploadService1Id; |
|
349 break; |
|
350 } |
|
351 case 1: |
|
352 { |
|
353 serviceId = KMmsUploadService2Id; |
|
354 break; |
|
355 } |
|
356 case 2: |
|
357 { |
|
358 serviceId = KMmsUploadService3Id; |
|
359 break; |
|
360 } |
|
361 case 3: |
|
362 { |
|
363 serviceId = KMmsUploadService4Id; |
|
364 break; |
|
365 } |
|
366 default: |
|
367 break; |
|
368 } |
|
369 serviceInfo->SetServiceId( serviceId ); |
|
370 |
|
371 iServiceArray.Append( serviceInfo ); |
|
372 CleanupStack::Pop( serviceInfo ); |
|
373 } |
|
374 } |
|
375 |
|
376 CleanupStack::PopAndDestroy( senduiRepository ); |
|
377 } |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CMmsIndirectUpload::CheckMmsServiceAvailabilityL |
|
381 // Checks MMS service availability. |
|
382 // (other items were commented in a header). |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 TBool CMmsIndirectUpload::CheckMmsServiceAvailabilityL( |
|
386 RSendAs& aSendAsSession ) |
|
387 { |
|
388 TInt i = 0; |
|
389 |
|
390 CSendAsMessageTypes* msgTypes = CSendAsMessageTypes::NewL(); |
|
391 CleanupStack::PushL( msgTypes ); |
|
392 |
|
393 aSendAsSession.FilteredMessageTypesL( *msgTypes ); |
|
394 |
|
395 for ( i = 0; i < msgTypes->Count(); i++ ) |
|
396 { |
|
397 if ( msgTypes->MessageTypeUid( i ) == KSenduiMtmMmsUid ) |
|
398 { |
|
399 CleanupStack::PopAndDestroy( msgTypes ); |
|
400 return ETrue; |
|
401 } |
|
402 } |
|
403 |
|
404 return EFalse; |
|
405 } |
|
406 |
|
407 // End of File |