|
1 /* |
|
2 * Copyright (c) 2002-2006 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 DRM link sender service. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <eikenv.h> |
|
22 #include <CSendingServiceInfo.h> |
|
23 #include <SendUiConsts.h> |
|
24 #include <CMessageData.h> |
|
25 #include <senduisingleton.h> |
|
26 #include <smsclnt.h> |
|
27 #include <mtclreg.h> // CClientMtmRegistry |
|
28 #include <msvids.h> |
|
29 #include <StringLoader.h> |
|
30 #include <coemain.h> |
|
31 #include <mtmuidef.hrh> |
|
32 #include <mtuireg.h> // MTM UI registery |
|
33 #include <DrmLinkSenderUi.rsg> |
|
34 #include <muiumsvuiserviceutilitiesinternal.h> |
|
35 #include <s32mem.h> |
|
36 #include <f32file.h> |
|
37 #include <data_caging_path_literals.hrh> |
|
38 #include <caf/caf.h> |
|
39 #include <unieditorconsts.h> |
|
40 #include <unimsventry.h> |
|
41 |
|
42 #include "DrmLinkSender.h" |
|
43 #include <TSendingCapabilities.h> |
|
44 #include "SendUiOperationWait.h" |
|
45 |
|
46 // CONSTANTS |
|
47 _LIT( KDrmLinkSenderUiResource, "DrmLinkSenderUi.rsc"); |
|
48 //const TInt KDLSRichTextStoreGranularity = 512; // Removal of Warning: #177-D |
|
49 // The string is defined in another .cpp too -> should be moved to a .h file |
|
50 const TInt KSendUiProgressStringSize = 256; |
|
51 const TInt KSenduiUrlMaxLen = 1024; |
|
52 |
|
53 |
|
54 // ============================ MEMBER FUNCTIONS =============================== |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CDrmLinkSender::CDrmLinkSender |
|
58 // C++ default constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 |
|
63 CDrmLinkSender::CDrmLinkSender( CCoeEnv& aCoeEnv, CSendUiSingleton& aSingleton ) : |
|
64 CSendingService( aCoeEnv, aSingleton ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CDrmLinkSender::ConstructL |
|
70 // Symbian 2nd phase constructor can leave. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CDrmLinkSender::ConstructL( ) |
|
74 { |
|
75 iResourceLoader = new(ELeave)RConeResourceLoader( iCoeEnv ); |
|
76 |
|
77 InitializeServiceL(); |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CDrmLinkSender::NewL |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CDrmLinkSender* CDrmLinkSender::NewL( TSendingServiceParams* aParams ) |
|
86 { |
|
87 CDrmLinkSender* self = new(ELeave) CDrmLinkSender( aParams->iCoeEnv, aParams->iSingleton ); |
|
88 |
|
89 CleanupStack::PushL(self); |
|
90 self->ConstructL(); |
|
91 CleanupStack::Pop(self); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 // Destructor |
|
97 CDrmLinkSender::~CDrmLinkSender() |
|
98 { |
|
99 // Unload UI resource file. |
|
100 if ( iResourceLoader ) |
|
101 { |
|
102 iResourceLoader->Close(); |
|
103 delete iResourceLoader; |
|
104 } |
|
105 iServiceArray.ResetAndDestroy(); |
|
106 iServiceArray.Close(); |
|
107 delete iClientMtm; |
|
108 delete iMtmUi; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CDrmLinkSender::ServiceProviderId |
|
114 // Returns the id of the service provider. |
|
115 // (other items were commented in a header). |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 TUid CDrmLinkSender::ServiceProviderId() const |
|
119 { |
|
120 return KDrmLinkSender; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CDrmLinkSender::PopulateServicesListL |
|
125 // Populates given list with the services provided by this plugin. |
|
126 // The ownership of the pointed objects remains. |
|
127 // (other items were commented in a header). |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CDrmLinkSender::PopulateServicesListL( |
|
131 RPointerArray<CSendingServiceInfo>& aList ) |
|
132 { |
|
133 for ( TInt cc = 0; cc < iServiceArray.Count(); cc++ ) |
|
134 { |
|
135 User::LeaveIfError( aList.Append( iServiceArray[cc] ) ); |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CDrmLinkSender::CreateAndSendMessageL |
|
142 // Creates to outbox as many MMS messages as there are files to be send. |
|
143 // (other items were commented in a header). |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CDrmLinkSender::CreateAndSendMessageL( |
|
147 TUid aServiceUid, |
|
148 const CMessageData* aMessageData, |
|
149 TBool /*aLaunchEditorEmbedded */) |
|
150 { |
|
151 HBufC8* contentUrl = NULL; |
|
152 |
|
153 if ( !aMessageData || |
|
154 aServiceUid != KDrmLinkSender || |
|
155 iServiceArray.Count() == 0 ) |
|
156 { |
|
157 return; |
|
158 } |
|
159 |
|
160 const CDesCArray& attachmentPaths = aMessageData->AttachmentArray(); |
|
161 const RArray<RFile>& attachments = aMessageData->AttachmentHandleArray(); |
|
162 |
|
163 if ( attachmentPaths.MdcaCount() == 1 ) |
|
164 { |
|
165 contentUrl = DrmContentUrlLC( attachmentPaths.MdcaPoint(0), iCoeEnv.FsSession() ); |
|
166 } |
|
167 else if ( attachments.Count() == 1 ) |
|
168 { |
|
169 contentUrl = DrmContentUrlLC( attachments[0] ); |
|
170 } |
|
171 else |
|
172 { |
|
173 User::Leave( KErrArgument ); |
|
174 return; |
|
175 } |
|
176 |
|
177 CreateMessageAndLaunchEditorL( *contentUrl ); |
|
178 CleanupStack::PopAndDestroy( contentUrl ); |
|
179 } |
|
180 |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CDrmLinkSender::DrmContentUrlLC |
|
184 // |
|
185 // (other items were commented in a header). |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 HBufC8* CDrmLinkSender::DrmContentUrlLC( const TDesC& aFilePath, RFs& aFs ) |
|
189 { |
|
190 RFile file; |
|
191 CleanupClosePushL( file ); |
|
192 |
|
193 TInt err = file.Open( aFs, aFilePath, EFileShareReadersOnly ); |
|
194 if ( err ) |
|
195 { |
|
196 User::LeaveIfError( file.Open( aFs, aFilePath, EFileShareAny ) ); |
|
197 } |
|
198 |
|
199 HBufC8* contentUrl = DrmContentUrlLC( file ); |
|
200 CleanupStack::Pop( contentUrl ); |
|
201 CleanupStack::PopAndDestroy( &file ); |
|
202 CleanupStack::PushL( contentUrl ); |
|
203 return contentUrl; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CDrmLinkSender::DrmContentUrlLC |
|
208 // |
|
209 // (other items were commented in a header). |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 HBufC8* CDrmLinkSender::DrmContentUrlLC( const RFile& aFile ) |
|
213 { |
|
214 HBufC8* contentUrl = NULL; |
|
215 TBuf<KSenduiUrlMaxLen> temp; |
|
216 |
|
217 ContentAccess::CData* content = ContentAccess::CData::NewLC( |
|
218 const_cast<RFile&> (aFile), |
|
219 ContentAccess::KDefaultContentObject, |
|
220 ContentAccess::EPeek ); |
|
221 User::LeaveIfError( content->GetStringAttribute( ContentAccess::EContentURI, temp ) ); |
|
222 CleanupStack::PopAndDestroy( content ); |
|
223 |
|
224 if ( temp.Length() > 0 ) |
|
225 { |
|
226 contentUrl = HBufC8::NewLC( temp.Length() ); |
|
227 contentUrl->Des().Copy( temp ); |
|
228 } |
|
229 else |
|
230 { |
|
231 User::Leave( KErrNotFound ); |
|
232 } |
|
233 |
|
234 return contentUrl; |
|
235 } |
|
236 |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CDrmLinkSender::InitializeServiceL |
|
240 // |
|
241 // (other items were commented in a header). |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CDrmLinkSender::InitializeServiceL() |
|
245 { |
|
246 // Load UI resource file. |
|
247 TFileName resourceFile; |
|
248 TParse* fp = new(ELeave) TParse(); |
|
249 fp->Set( KDrmLinkSenderUiResource, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
250 resourceFile = fp->FullName(); |
|
251 delete fp; |
|
252 fp = NULL; |
|
253 |
|
254 iResourceLoader->OpenL( resourceFile ); |
|
255 |
|
256 CSendingServiceInfo* serviceInfo = CSendingServiceInfo::NewLC(); |
|
257 |
|
258 // Set service type. |
|
259 serviceInfo->SetServiceProviderId( KDrmLinkSender ); |
|
260 serviceInfo->SetServiceId( KDrmLinkSender ); |
|
261 |
|
262 // Read service name from resource |
|
263 HBufC* serviceName = StringLoader::LoadLC( R_DRM_LINK_SENDER_MENU_NAME ); |
|
264 serviceInfo->SetServiceMenuNameL( *serviceName ); |
|
265 |
|
266 CleanupStack::PopAndDestroy( serviceName ); |
|
267 |
|
268 // Sending capabilities doesn't need to set. |
|
269 // Content URL is used for filtering instead of TSendingCapabilities. |
|
270 |
|
271 iServiceArray.Append( serviceInfo ); |
|
272 CleanupStack::Pop( serviceInfo ); |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CDrmLinkSender::CreateMessageAndLaunchEditorL |
|
277 // |
|
278 // (other items were commented in a header). |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CDrmLinkSender::CreateMessageAndLaunchEditorL( HBufC8& aContentUrl ) |
|
282 { |
|
283 if (!iClientMtm ) |
|
284 { |
|
285 // Uni client side MTM |
|
286 iClientMtm = iSingleton.ClientMtmRegistryL().NewMtmL( KSenduiMtmUniMessageUid ); |
|
287 } |
|
288 |
|
289 // Get Uni MTM UI and set its context |
|
290 iMtmUi = iSingleton.MtmUiRegistryL().NewMtmUiL( *iClientMtm ); |
|
291 |
|
292 // Create draft entry for the message |
|
293 CMsvEntry* draftEntry = iSingleton.MsvSessionL().GetEntryL( KMsvDraftEntryId ); |
|
294 CleanupStack::PushL( draftEntry ); |
|
295 iClientMtm->SetCurrentEntryL( draftEntry ); //iClientMtm takes ownership |
|
296 CleanupStack::Pop( draftEntry ); |
|
297 |
|
298 // Create the new message |
|
299 TMsvId serviceId = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML( |
|
300 iSingleton.MsvSessionL(), KSenduiMtmUniMessageUid, ETrue); |
|
301 iClientMtm->CreateMessageL( serviceId ); |
|
302 |
|
303 // Set message entry data |
|
304 TMsvEntry entry = iClientMtm->Entry().Entry(); |
|
305 |
|
306 TUniMsvEntry::SetCurrentMessageType( |
|
307 entry, EUniMessageCurrentTypeSms ); |
|
308 TUniMsvEntry::SetMessageTypeLocked( entry, ETrue ); |
|
309 iClientMtm->Entry().ChangeL( entry ); |
|
310 |
|
311 entry.iDate.UniversalTime(); |
|
312 entry.SetVisible( EFalse ); |
|
313 entry.SetAttachment( EFalse ); |
|
314 entry.SetInPreparation( ETrue ); |
|
315 iClientMtm->Entry().ChangeL( entry ); |
|
316 |
|
317 // Add DRM content link to body text |
|
318 AddAttachmentsL(aContentUrl); |
|
319 |
|
320 // Save message. |
|
321 iClientMtm->SaveMessageL(); |
|
322 entry = iClientMtm->Entry().Entry(); |
|
323 iClientMtm->SwitchCurrentEntryL( entry.Id() ); |
|
324 |
|
325 // Launch editor embedded |
|
326 TUint preferences = iMtmUi->Preferences(); |
|
327 preferences |= EMtmUiFlagEditorPreferEmbedded; |
|
328 iMtmUi->SetPreferences( preferences ); |
|
329 |
|
330 // Edit the message. |
|
331 CSendUiOperationWait* waiter = CSendUiOperationWait::NewLC(); |
|
332 CMsvOperation* op = iMtmUi->EditL( waiter->iStatus ); |
|
333 CleanupStack::PushL( op ); |
|
334 |
|
335 waiter->Start( op ); |
|
336 |
|
337 TBuf8<KSendUiProgressStringSize> progressBuf = op->ProgressL(); |
|
338 iMtmUi->DisplayProgressSummary( progressBuf ); |
|
339 |
|
340 CleanupStack::PopAndDestroy( 2 ); // waiter, op |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CDrmLinkSender::AddAttachmentsL |
|
345 // |
|
346 // (other items were commented in a header). |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CDrmLinkSender::AddAttachmentsL( HBufC8& aContentUrl ) |
|
350 { |
|
351 TInt cleanupItems(0); |
|
352 CMessageData* msgData = CMessageData::NewLC(); |
|
353 cleanupItems++; |
|
354 |
|
355 TPtr8 string(aContentUrl.Des()); |
|
356 CRichText* text = CRichText::NewL( |
|
357 static_cast<CEikonEnv&>( iCoeEnv ).SystemParaFormatLayerL(), |
|
358 static_cast<CEikonEnv&>( iCoeEnv ).SystemCharFormatLayerL() ); |
|
359 CleanupStack::PushL( text ); |
|
360 cleanupItems++; |
|
361 text->Reset(); |
|
362 |
|
363 HBufC16* bufConv = HBufC16::NewLC(string.Length()); |
|
364 cleanupItems++; |
|
365 TPtr16 string16(bufConv->Des()); |
|
366 string16.Copy(string); |
|
367 text->InsertL( 0, string16 ); |
|
368 |
|
369 // Set body text |
|
370 msgData->SetBodyTextL( text ); |
|
371 |
|
372 CArrayPtrFlat<CSendUiAttachment>* attachments = NULL; |
|
373 // Get attachments |
|
374 if ( msgData ) |
|
375 { |
|
376 attachments = CSendUiAttachment::InitAttachmentArrayLCC( |
|
377 msgData->AttachmentArray(), |
|
378 msgData->AttachmentHandleArray(), |
|
379 iCoeEnv.FsSession() ); |
|
380 cleanupItems += 2; |
|
381 } |
|
382 CSendUiAttachment* atta = CSendUiAttachment::NewLC( *text, iCoeEnv.FsSession() ); |
|
383 attachments->AppendL( atta ); |
|
384 CleanupStack::Pop( atta ); |
|
385 |
|
386 TInt attachmentCount = attachments->Count(); |
|
387 TInt i; |
|
388 for ( i = 0; i < attachmentCount ; i++ ) |
|
389 { |
|
390 CSendUiAttachment& attachment = *(attachments->At(i )); |
|
391 AddAttachmentL( &attachment ); |
|
392 } |
|
393 CleanupStack::PopAndDestroy( cleanupItems ); // msgData, text, bufConv, attachments |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CDrmLinkSender::AddAttachmentL |
|
398 // |
|
399 // (other items were commented in a header). |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 void CDrmLinkSender::AddAttachmentL( CSendUiAttachment* aAttachment) |
|
403 { |
|
404 CSendUiOperationWait* waiter = CSendUiOperationWait::NewLC(); |
|
405 |
|
406 iClientMtm->AddLinkedAttachmentL( |
|
407 *(aAttachment->Path() ), |
|
408 aAttachment->MimeType(), |
|
409 0, |
|
410 waiter->iStatus ); |
|
411 TBool success = waiter->Start( iClientMtm ); |
|
412 CleanupStack::PopAndDestroy( waiter ); |
|
413 } |
|
414 |
|
415 // ----------------------------------------------------------------------------- |
|
416 // TechnologyType |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 TUid CDrmLinkSender::TechnologyTypeId( ) const |
|
420 { |
|
421 return KNullUid; |
|
422 } |
|
423 |
|
424 // End of File |