|
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 CleanupClosePushL( aList ); |
|
134 for ( TInt cc = 0; cc < iServiceArray.Count(); cc++ ) |
|
135 { |
|
136 User::LeaveIfError( aList.Append( iServiceArray[cc] ) ); |
|
137 } |
|
138 CleanupStack::Pop( &aList ); |
|
139 } |
|
140 |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CDrmLinkSender::CreateAndSendMessageL |
|
144 // Creates to outbox as many MMS messages as there are files to be send. |
|
145 // (other items were commented in a header). |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CDrmLinkSender::CreateAndSendMessageL( |
|
149 TUid aServiceUid, |
|
150 const CMessageData* aMessageData, |
|
151 TBool /*aLaunchEditorEmbedded */) |
|
152 { |
|
153 HBufC8* contentUrl = NULL; |
|
154 |
|
155 if ( !aMessageData || |
|
156 aServiceUid != KDrmLinkSender || |
|
157 iServiceArray.Count() == 0 ) |
|
158 { |
|
159 return; |
|
160 } |
|
161 |
|
162 const CDesCArray& attachmentPaths = aMessageData->AttachmentArray(); |
|
163 const RArray<RFile>& attachments = aMessageData->AttachmentHandleArray(); |
|
164 |
|
165 if ( attachmentPaths.MdcaCount() == 1 ) |
|
166 { |
|
167 contentUrl = DrmContentUrlLC( attachmentPaths.MdcaPoint(0), iCoeEnv.FsSession() ); |
|
168 } |
|
169 else if ( attachments.Count() == 1 ) |
|
170 { |
|
171 contentUrl = DrmContentUrlLC( attachments[0] ); |
|
172 } |
|
173 else |
|
174 { |
|
175 User::Leave( KErrArgument ); |
|
176 return; |
|
177 } |
|
178 |
|
179 CreateMessageAndLaunchEditorL( *contentUrl ); |
|
180 CleanupStack::PopAndDestroy( contentUrl ); |
|
181 } |
|
182 |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CDrmLinkSender::DrmContentUrlLC |
|
186 // |
|
187 // (other items were commented in a header). |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 HBufC8* CDrmLinkSender::DrmContentUrlLC( const TDesC& aFilePath, RFs& aFs ) |
|
191 { |
|
192 RFile file; |
|
193 CleanupClosePushL( file ); |
|
194 |
|
195 TInt err = file.Open( aFs, aFilePath, EFileShareReadersOnly ); |
|
196 if ( err ) |
|
197 { |
|
198 User::LeaveIfError( file.Open( aFs, aFilePath, EFileShareAny ) ); |
|
199 } |
|
200 |
|
201 HBufC8* contentUrl = DrmContentUrlLC( file ); |
|
202 CleanupStack::Pop( contentUrl ); |
|
203 CleanupStack::PopAndDestroy( &file ); |
|
204 CleanupStack::PushL( contentUrl ); |
|
205 return contentUrl; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CDrmLinkSender::DrmContentUrlLC |
|
210 // |
|
211 // (other items were commented in a header). |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 HBufC8* CDrmLinkSender::DrmContentUrlLC( const RFile& aFile ) |
|
215 { |
|
216 HBufC8* contentUrl = NULL; |
|
217 TBuf<KSenduiUrlMaxLen> temp; |
|
218 |
|
219 ContentAccess::CData* content = ContentAccess::CData::NewLC( |
|
220 const_cast<RFile&> (aFile), |
|
221 ContentAccess::KDefaultContentObject, |
|
222 ContentAccess::EPeek ); |
|
223 User::LeaveIfError( content->GetStringAttribute( ContentAccess::EContentURI, temp ) ); |
|
224 CleanupStack::PopAndDestroy( content ); |
|
225 |
|
226 if ( temp.Length() > 0 ) |
|
227 { |
|
228 contentUrl = HBufC8::NewLC( temp.Length() ); |
|
229 contentUrl->Des().Copy( temp ); |
|
230 } |
|
231 else |
|
232 { |
|
233 User::Leave( KErrNotFound ); |
|
234 } |
|
235 |
|
236 return contentUrl; |
|
237 } |
|
238 |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CDrmLinkSender::InitializeServiceL |
|
242 // |
|
243 // (other items were commented in a header). |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CDrmLinkSender::InitializeServiceL() |
|
247 { |
|
248 // Load UI resource file. |
|
249 TFileName resourceFile; |
|
250 TParse* fp = new(ELeave) TParse(); |
|
251 fp->Set( KDrmLinkSenderUiResource, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
252 resourceFile = fp->FullName(); |
|
253 delete fp; |
|
254 fp = NULL; |
|
255 |
|
256 iResourceLoader->OpenL( resourceFile ); |
|
257 |
|
258 CSendingServiceInfo* serviceInfo = CSendingServiceInfo::NewLC(); |
|
259 |
|
260 // Set service type. |
|
261 serviceInfo->SetServiceProviderId( KDrmLinkSender ); |
|
262 serviceInfo->SetServiceId( KDrmLinkSender ); |
|
263 |
|
264 // Read service name from resource |
|
265 HBufC* serviceName = StringLoader::LoadLC( R_DRM_LINK_SENDER_MENU_NAME ); |
|
266 serviceInfo->SetServiceMenuNameL( *serviceName ); |
|
267 |
|
268 CleanupStack::PopAndDestroy( serviceName ); |
|
269 |
|
270 // Sending capabilities doesn't need to set. |
|
271 // Content URL is used for filtering instead of TSendingCapabilities. |
|
272 |
|
273 iServiceArray.Append( serviceInfo ); |
|
274 CleanupStack::Pop( serviceInfo ); |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CDrmLinkSender::CreateMessageAndLaunchEditorL |
|
279 // |
|
280 // (other items were commented in a header). |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 void CDrmLinkSender::CreateMessageAndLaunchEditorL( HBufC8& aContentUrl ) |
|
284 { |
|
285 if (!iClientMtm ) |
|
286 { |
|
287 // Uni client side MTM |
|
288 iClientMtm = iSingleton.ClientMtmRegistryL().NewMtmL( KSenduiMtmUniMessageUid ); |
|
289 } |
|
290 |
|
291 // Get Uni MTM UI and set its context |
|
292 iMtmUi = iSingleton.MtmUiRegistryL().NewMtmUiL( *iClientMtm ); |
|
293 |
|
294 // Create draft entry for the message |
|
295 CMsvEntry* draftEntry = iSingleton.MsvSessionL().GetEntryL( KMsvDraftEntryId ); |
|
296 CleanupStack::PushL( draftEntry ); |
|
297 iClientMtm->SetCurrentEntryL( draftEntry ); //iClientMtm takes ownership |
|
298 CleanupStack::Pop( draftEntry ); |
|
299 |
|
300 // Create the new message |
|
301 TMsvId serviceId = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML( |
|
302 iSingleton.MsvSessionL(), KSenduiMtmUniMessageUid, ETrue); |
|
303 iClientMtm->CreateMessageL( serviceId ); |
|
304 |
|
305 // Set message entry data |
|
306 TMsvEntry entry = iClientMtm->Entry().Entry(); |
|
307 |
|
308 TUniMsvEntry::SetCurrentMessageType( |
|
309 entry, EUniMessageCurrentTypeSms ); |
|
310 TUniMsvEntry::SetMessageTypeLocked( entry, ETrue ); |
|
311 iClientMtm->Entry().ChangeL( entry ); |
|
312 |
|
313 entry.iDate.UniversalTime(); |
|
314 entry.SetVisible( EFalse ); |
|
315 entry.SetAttachment( EFalse ); |
|
316 entry.SetInPreparation( ETrue ); |
|
317 iClientMtm->Entry().ChangeL( entry ); |
|
318 |
|
319 // Add DRM content link to body text |
|
320 AddAttachmentsL(aContentUrl); |
|
321 |
|
322 // Save message. |
|
323 iClientMtm->SaveMessageL(); |
|
324 entry = iClientMtm->Entry().Entry(); |
|
325 iClientMtm->SwitchCurrentEntryL( entry.Id() ); |
|
326 |
|
327 // Launch editor embedded |
|
328 TUint preferences = iMtmUi->Preferences(); |
|
329 preferences |= EMtmUiFlagEditorPreferEmbedded; |
|
330 iMtmUi->SetPreferences( preferences ); |
|
331 |
|
332 // Edit the message. |
|
333 CSendUiOperationWait* waiter = CSendUiOperationWait::NewLC(); |
|
334 CMsvOperation* op = iMtmUi->EditL( waiter->iStatus ); |
|
335 CleanupStack::PushL( op ); |
|
336 |
|
337 waiter->Start( op ); |
|
338 |
|
339 TBuf8<KSendUiProgressStringSize> progressBuf = op->ProgressL(); |
|
340 iMtmUi->DisplayProgressSummary( progressBuf ); |
|
341 |
|
342 CleanupStack::PopAndDestroy( 2 ); // waiter, op |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CDrmLinkSender::AddAttachmentsL |
|
347 // |
|
348 // (other items were commented in a header). |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void CDrmLinkSender::AddAttachmentsL( HBufC8& aContentUrl ) |
|
352 { |
|
353 TInt cleanupItems(0); |
|
354 CMessageData* msgData = CMessageData::NewLC(); |
|
355 cleanupItems++; |
|
356 |
|
357 TPtr8 string(aContentUrl.Des()); |
|
358 CRichText* text = CRichText::NewL( |
|
359 static_cast<CEikonEnv&>( iCoeEnv ).SystemParaFormatLayerL(), |
|
360 static_cast<CEikonEnv&>( iCoeEnv ).SystemCharFormatLayerL() ); |
|
361 CleanupStack::PushL( text ); |
|
362 cleanupItems++; |
|
363 text->Reset(); |
|
364 |
|
365 HBufC16* bufConv = HBufC16::NewLC(string.Length()); |
|
366 cleanupItems++; |
|
367 TPtr16 string16(bufConv->Des()); |
|
368 string16.Copy(string); |
|
369 text->InsertL( 0, string16 ); |
|
370 |
|
371 // Set body text |
|
372 msgData->SetBodyTextL( text ); |
|
373 |
|
374 CArrayPtrFlat<CSendUiAttachment>* attachments = NULL; |
|
375 // Get attachments |
|
376 if ( msgData ) |
|
377 { |
|
378 attachments = CSendUiAttachment::InitAttachmentArrayLCC( |
|
379 msgData->AttachmentArray(), |
|
380 msgData->AttachmentHandleArray(), |
|
381 iCoeEnv.FsSession() ); |
|
382 cleanupItems += 2; |
|
383 } |
|
384 CSendUiAttachment* atta = CSendUiAttachment::NewLC( *text, iCoeEnv.FsSession() ); |
|
385 attachments->AppendL( atta ); |
|
386 CleanupStack::Pop( atta ); |
|
387 |
|
388 TInt attachmentCount = attachments->Count(); |
|
389 TInt i; |
|
390 for ( i = 0; i < attachmentCount ; i++ ) |
|
391 { |
|
392 CSendUiAttachment& attachment = *(attachments->At(i )); |
|
393 AddAttachmentL( &attachment ); |
|
394 } |
|
395 CleanupStack::PopAndDestroy( cleanupItems ); // msgData, text, bufConv, attachments |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // CDrmLinkSender::AddAttachmentL |
|
400 // |
|
401 // (other items were commented in a header). |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CDrmLinkSender::AddAttachmentL( CSendUiAttachment* aAttachment) |
|
405 { |
|
406 CSendUiOperationWait* waiter = CSendUiOperationWait::NewLC(); |
|
407 |
|
408 iClientMtm->AddLinkedAttachmentL( |
|
409 *(aAttachment->Path() ), |
|
410 aAttachment->MimeType(), |
|
411 0, |
|
412 waiter->iStatus ); |
|
413 TBool success = waiter->Start( iClientMtm ); |
|
414 CleanupStack::PopAndDestroy( waiter ); |
|
415 } |
|
416 |
|
417 // ----------------------------------------------------------------------------- |
|
418 // TechnologyType |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 TUid CDrmLinkSender::TechnologyTypeId( ) const |
|
422 { |
|
423 return KNullUid; |
|
424 } |
|
425 |
|
426 // End of File |