|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 // System includes |
|
22 #include <eikdef.h> |
|
23 #include <eikenv.h> |
|
24 #include <sendui.h> |
|
25 #include <CMessageData.h> |
|
26 #include <TSendingCapabilities.h> |
|
27 #include <SenduiMtmUids.h> |
|
28 #include <msgbiouids.h> |
|
29 #include <txtrich.h> |
|
30 #include <smut.h> |
|
31 |
|
32 // User includes |
|
33 #include "BrowserAppUi.h" |
|
34 #include "BrowserUtil.h" |
|
35 #include "BrowserDialogs.h" |
|
36 #include "BrowserBmOTABinSender.h" |
|
37 |
|
38 |
|
39 // MACROS |
|
40 |
|
41 #ifndef _BOOKMARK_SENT_ASCII |
|
42 // Calculates the byte size of 16bits (a) |
|
43 #define TUINT16_LEN(a) ( sizeof(a) / sizeof(TUint16) ) |
|
44 #endif |
|
45 |
|
46 // ================= LOCAL CONSTANTS ======================= |
|
47 |
|
48 /// Granularity of the bookmark list. |
|
49 LOCAL_C const TInt KGranularity = 1; |
|
50 |
|
51 /// Attachment file name. |
|
52 _LIT( KAttachmentFilename, "c:\\system\\temp\\Bookmark.txt"); |
|
53 |
|
54 #ifndef _BOOKMARK_SENT_ASCII |
|
55 // Binary encoded BM data. See OTA spec |
|
56 static const TUint16 Kch_lstart[] = { 0x00, 0x01, 0x00, 0x45 }; |
|
57 static const TUint16 Kch_lend[] = { 0x01 }; |
|
58 static const TUint16 Kch_start[] = { 0xC6,0x7F,0x01,0x87,0x15,0x11,0x03 }; |
|
59 static const TUint16 Kch_mid[] = { 0x00,0x01,0x87,0x17,0x11,0x03 }; |
|
60 static const TUint16 Kch_end[] = { 0x00,0x01,0x01 }; |
|
61 #endif // _BOOKMARK_SENT_ASCII |
|
62 |
|
63 |
|
64 // ================= MEMBER FUNCTIONS ======================= |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CBookmarkOTAItem::CBookmarkOTAItem |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CBookmarkOTAItem::CBookmarkOTAItem() |
|
71 { |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CBookmarkOTAItem::~CBookmarkOTAItem |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CBookmarkOTAItem::~CBookmarkOTAItem() |
|
79 { |
|
80 delete iBookmark; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CBookmarkOTAItem::NewL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CBookmarkOTAItem* CBookmarkOTAItem::NewL( const TDesC& aUrl, const TDesC& aTitle ) |
|
88 { |
|
89 CBookmarkOTAItem *item = new (ELeave) CBookmarkOTAItem(); |
|
90 CleanupStack::PushL( item ); |
|
91 |
|
92 item->ConstructL( aUrl, aTitle ); |
|
93 |
|
94 CleanupStack::Pop(); // item |
|
95 |
|
96 return item; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CBookmarkOTAItem::ConstructL |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CBookmarkOTAItem::ConstructL( const TDesC& aUrl, |
|
104 #ifdef _BOOKMARK_SENT_ASCII |
|
105 const TDesC& /*aTitle*/ ) |
|
106 #else // _BOOKMARK_SENT_ASCII |
|
107 const TDesC& aTitle ) |
|
108 #endif // _BOOKMARK_SENT_ASCII |
|
109 |
|
110 { |
|
111 #ifdef _BOOKMARK_SENT_ASCII |
|
112 iBookmark = aUrl.AllocL(); |
|
113 #else // _BOOKMARK_SENT_ASCII |
|
114 TInt length = TUINT16_LEN( Kch_start ) + |
|
115 TUINT16_LEN( Kch_mid ) + |
|
116 TUINT16_LEN( Kch_end ); |
|
117 |
|
118 // calculate full length of BOOKMARK |
|
119 length += aTitle.Length() + aUrl.Length(); |
|
120 |
|
121 iBookmark = HBufC::NewL( length ); |
|
122 |
|
123 TPtrC start( Kch_start, TUINT16_LEN(Kch_start) ); |
|
124 TPtrC mid( Kch_mid, TUINT16_LEN(Kch_mid) ); |
|
125 TPtrC end( Kch_end, TUINT16_LEN(Kch_end) ); |
|
126 |
|
127 iBookmark->Des().Append( start ); |
|
128 iBookmark->Des().Append( aTitle ); |
|
129 iBookmark->Des().Append( mid ); |
|
130 iBookmark->Des().Append( aUrl ); |
|
131 iBookmark->Des().Append( end ); |
|
132 |
|
133 #endif // _BOOKMARK_SENT_ASCII |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CWmlBrowserBmOTABinSender::NewL |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 CWmlBrowserBmOTABinSender* CWmlBrowserBmOTABinSender::NewL() |
|
141 { |
|
142 CWmlBrowserBmOTABinSender* sender = new (ELeave) |
|
143 CWmlBrowserBmOTABinSender(); |
|
144 CleanupStack::PushL( sender ); |
|
145 |
|
146 sender->ConstructL(); |
|
147 |
|
148 CleanupStack::Pop(); // sender |
|
149 |
|
150 return sender; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CWmlBrowserBmOTABinSender::~CWmlBrowserBmOTABinSender |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 CWmlBrowserBmOTABinSender::~CWmlBrowserBmOTABinSender() |
|
158 { |
|
159 ResetAndDestroy(); |
|
160 delete iSendUi; |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CWmlBrowserBmOTABinSender::ResetAndDestroy |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CWmlBrowserBmOTABinSender::ResetAndDestroy() |
|
168 { |
|
169 iBookmarks.ResetAndDestroy(); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CWmlBrowserBmOTABinSender::AppendL |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CWmlBrowserBmOTABinSender::AppendL( const TText *aUrl, |
|
177 const TText *aTitle ) |
|
178 { |
|
179 __ASSERT_DEBUG( (aUrl != NULL), Util::Panic( Util::EUninitializedData ) ); |
|
180 TPtrC tempUrl( aUrl ); |
|
181 CBookmarkOTAItem *item = NULL; |
|
182 |
|
183 if( !aTitle ) |
|
184 { |
|
185 _LIT( KEmptyText, "" ); |
|
186 |
|
187 item = CBookmarkOTAItem::NewL( tempUrl, (TDesC&)KEmptyText ); |
|
188 } |
|
189 else |
|
190 { |
|
191 TPtrC tempTitle( aTitle ); |
|
192 |
|
193 item = CBookmarkOTAItem::NewL( tempUrl, tempTitle ); |
|
194 } |
|
195 |
|
196 CleanupStack::PushL( item ); |
|
197 |
|
198 iBookmarks.AppendL( item ); |
|
199 |
|
200 CleanupStack::Pop(); // item |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CWmlBrowserBmOTABinSender::AppendL |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void CWmlBrowserBmOTABinSender::AppendL( const TDesC& aUrl, const TDesC& aTitle ) |
|
208 { |
|
209 CBookmarkOTAItem *item = CBookmarkOTAItem::NewL( aUrl, aTitle ); |
|
210 CleanupStack::PushL( item ); |
|
211 |
|
212 iBookmarks.AppendL( item ); |
|
213 |
|
214 CleanupStack::Pop(); // item |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CWmlBrowserBmOTABinSender::SendAddressL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CWmlBrowserBmOTABinSender::SendAddressL( ) |
|
222 { |
|
223 CMessageData* msgData = CMessageData::NewLC();//Cl St: 1 |
|
224 __ASSERT_DEBUG( iBookmarks.Length(), |
|
225 Util::Panic( Util::EUninitializedData ) ); |
|
226 |
|
227 // sending error indicator |
|
228 // used with CreateAndSendMessageL() |
|
229 // to free up allocated memory |
|
230 // and than leave at the and of |
|
231 // this function |
|
232 TInt error = KErrNone; |
|
233 |
|
234 // calculate full length of OTA message |
|
235 TInt length = 0; |
|
236 |
|
237 TSendingCapabilities capa; |
|
238 CArrayFixFlat<TUid>* servicesToDim = new(ELeave) CArrayFixFlat<TUid>( 2 ); |
|
239 CleanupStack::PushL( servicesToDim ); |
|
240 servicesToDim->AppendL( KSenduiMtmAudioMessageUid ); |
|
241 // service: audio message to dim |
|
242 servicesToDim->AppendL( KSenduiMtmPostcardUid ); |
|
243 // service: postcard to dim |
|
244 TUid service = iSendUi->ShowSendQueryL(NULL, capa, servicesToDim, KNullDesC); |
|
245 iSendUi->ServiceCapabilitiesL( service, capa ); |
|
246 |
|
247 CleanupStack::PopAndDestroy(); // destroy serviceToDim |
|
248 |
|
249 #ifndef _BOOKMARK_SENT_ASCII |
|
250 length += TUINT16_LEN( Kch_lstart ) + TUINT16_LEN( Kch_lend ); |
|
251 #endif // _BOOKMARK_SENT_ASCII |
|
252 |
|
253 for( TInt index = 0; index < iBookmarks.Count(); ++index ) |
|
254 { |
|
255 length += iBookmarks[index]->iBookmark->Length(); |
|
256 } |
|
257 |
|
258 #ifdef _BOOKMARK_SENT_ASCII |
|
259 // +1 '\n' per bookmarks |
|
260 // no need '\n' after the last one |
|
261 length += iBookmarks.Count() - 1; |
|
262 #endif // _BOOKMARK_SENT_ASCII |
|
263 |
|
264 // body contains the binary sequence |
|
265 HBufC* body = HBufC::NewLC( length ); |
|
266 |
|
267 #ifndef _BOOKMARK_SENT_ASCII |
|
268 TPtrC lstart( Kch_lstart, TUINT16_LEN( Kch_lstart ) ); |
|
269 TPtrC lend( Kch_lend, TUINT16_LEN( Kch_lend ) ); |
|
270 // body starts with CHARACTERISTIC-LIST |
|
271 body->Des().Append( lstart ); |
|
272 #endif // _BOOKMARK_SENT_ASCII |
|
273 |
|
274 for( TInt index2 = 0; index2 < iBookmarks.Count(); ++index2 ) |
|
275 { |
|
276 // Append CHARACTERISTIC to CHARACTERISTIC-LIST |
|
277 body->Des().Append( iBookmarks[index2]->iBookmark->Des().Ptr(), |
|
278 iBookmarks[index2]->iBookmark->Length() ); |
|
279 |
|
280 #ifdef _BOOKMARK_SENT_ASCII |
|
281 // append '\n' after ever bookmark except the last one |
|
282 if( index2 < iBookmarks.Count() - 1 ) |
|
283 { |
|
284 _LIT( KNewLine, "\n" ); |
|
285 body->Des().Append( KNewLine ); |
|
286 } |
|
287 #endif // _BOOKMARK_SENT_ASCII |
|
288 } |
|
289 |
|
290 #ifndef _BOOKMARK_SENT_ASCII |
|
291 // CHARACTERISTIC-LIST termination |
|
292 body->Des().Append( lend ); |
|
293 #endif // _BOOKMARK_SENT_ASCII |
|
294 |
|
295 if ( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
296 { |
|
297 // connect to file session |
|
298 RFs fsSession; |
|
299 User::LeaveIfError( fsSession.Connect() ); |
|
300 CleanupClosePushL<RFs>( fsSession ); |
|
301 CFileMan* fman = CFileMan::NewL( fsSession ); |
|
302 CleanupStack::PushL( fman ); |
|
303 // try to avoid inserting any 'leave' code |
|
304 // between WriteMessageBodyIntoFile() |
|
305 // and CreateAndSendMessageL, or |
|
306 // you have to take care of deleting |
|
307 // temporary file |
|
308 error = WriteMessageBodyIntoFileL( fsSession, *body ); |
|
309 |
|
310 if( error == KErrNone ) |
|
311 { |
|
312 // send attachment |
|
313 // this function has to be trapped |
|
314 // because I have to be sure that the |
|
315 // temproray file is removed! |
|
316 msgData->AppendAttachmentL( KAttachmentFilename ); |
|
317 TRAP( error, iSendUi->CreateAndSendMessageL( service, |
|
318 msgData ) ); |
|
319 } |
|
320 // delete temporary file |
|
321 fman->Delete( KAttachmentFilename ); |
|
322 // close file session |
|
323 fsSession.Close(); |
|
324 |
|
325 CleanupStack::PopAndDestroy( 2 ); // fsSession, fman |
|
326 } |
|
327 else if ( capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
328 { |
|
329 CRichText* text = |
|
330 CRichText::NewL(CEikonEnv::Static()->SystemParaFormatLayerL(), |
|
331 CEikonEnv::Static()->SystemCharFormatLayerL()); |
|
332 CleanupStack::PushL(text); |
|
333 text->InsertL(0, *body); |
|
334 msgData->SetBodyTextL( text ); |
|
335 CleanupStack::PopAndDestroy(text ); |
|
336 |
|
337 #ifdef _BOOKMARK_SENT_ASCII |
|
338 TRAP( error, iSendUi->CreateAndSendMessageL( service, msgData ) ); |
|
339 #else |
|
340 TRAP( error, iSendUi->CreateAndSendMessageL( service, |
|
341 msgData, |
|
342 KMsgBioUidWmlBrSettings ) ); |
|
343 #endif // _BOOKMARK_SENT_ASCII |
|
344 } |
|
345 |
|
346 ResetAndDestroy(); |
|
347 |
|
348 CleanupStack::PopAndDestroy( 2 ); // body, msgData |
|
349 |
|
350 // if any error occured during sending process |
|
351 User::LeaveIfError( error ); |
|
352 } |
|
353 |
|
354 |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 // CWmlBrowserBmOTABinSender::SendOPMLFileL |
|
358 // --------------------------------------------------------------------------- |
|
359 // |
|
360 void CWmlBrowserBmOTABinSender::SendOPMLFileL(const TDesC& aOPMLFileName) |
|
361 { |
|
362 CMessageData* msgData = CMessageData::NewLC(); |
|
363 |
|
364 // sending error indicator |
|
365 // used with CreateAndSendMessageL() |
|
366 // to free up allocated memory |
|
367 // and than leave at the and of |
|
368 // this function |
|
369 TInt error = KErrNone; |
|
370 |
|
371 TSendingCapabilities capa; |
|
372 |
|
373 CArrayFixFlat<TUid>* servicesToDim = new(ELeave) CArrayFixFlat<TUid>( 2 ); |
|
374 CleanupStack::PushL( servicesToDim ); |
|
375 servicesToDim->AppendL( KSenduiMtmAudioMessageUid ); |
|
376 // service: audio message to dim |
|
377 servicesToDim->AppendL( KSenduiMtmPostcardUid ); |
|
378 // service: postcard to dim |
|
379 TUid service = iSendUi->ShowSendQueryL(NULL, capa, servicesToDim, KNullDesC); |
|
380 iSendUi->ServiceCapabilitiesL( service, capa ); |
|
381 |
|
382 CleanupStack::PopAndDestroy(); // destroy serviceToDim |
|
383 |
|
384 // body contains the binary sequence |
|
385 //HBufC* body = HBufC::NewLC( aOPMLFileName.Length() ); |
|
386 //body->Des().Copy( aOPMLFileName ); |
|
387 |
|
388 if ( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
389 { |
|
390 // connect to file session |
|
391 RFs fsSession; |
|
392 User::LeaveIfError( fsSession.Connect() ); |
|
393 CleanupClosePushL<RFs>( fsSession ); |
|
394 CFileMan* fman = CFileMan::NewL( fsSession ); |
|
395 CleanupStack::PushL( fman ); |
|
396 |
|
397 // between WriteMessageBodyIntoFile() |
|
398 // and CreateAndSendMessageL, or |
|
399 // you have to take care of deleting |
|
400 // temporary file |
|
401 //error = WriteMessageBodyIntoFileL( fsSession, *body ); |
|
402 |
|
403 // send attachment |
|
404 // this function has to be trapped |
|
405 // because I have to be sure that the |
|
406 // temproray file is removed! |
|
407 msgData->AppendAttachmentL( aOPMLFileName ); |
|
408 TRAP( error, iSendUi->CreateAndSendMessageL( service, |
|
409 msgData ) ); |
|
410 // delete temporary file |
|
411 fman->Delete( aOPMLFileName ); |
|
412 // close file session |
|
413 fsSession.Close(); |
|
414 |
|
415 CleanupStack::PopAndDestroy( 2 ); // fsSession, fman |
|
416 } |
|
417 |
|
418 CleanupStack::PopAndDestroy( 1 ); // msgData |
|
419 |
|
420 // if any error occured during sending process |
|
421 User::LeaveIfError( error ); |
|
422 } |
|
423 // --------------------------------------------------------------------------- |
|
424 // CWmlBrowserBmOTABinSender::ConstructL |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CWmlBrowserBmOTABinSender::ConstructL() |
|
428 { |
|
429 iSendUi = CSendUi::NewL(); |
|
430 } |
|
431 |
|
432 // --------------------------------------------------------------------------- |
|
433 // CWmlBrowserBmOTABinSender::CWmlBrowserBmOTABinSender |
|
434 // --------------------------------------------------------------------------- |
|
435 // |
|
436 CWmlBrowserBmOTABinSender::CWmlBrowserBmOTABinSender() |
|
437 : iBookmarks( KGranularity ) |
|
438 { |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CWmlBrowserBmOTABinSender::WriteMessageBodyIntoFileL |
|
443 // |
|
444 // This function leaves only if the file creating failed. |
|
445 // Do not need to be trapped to delete file. |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 TInt CWmlBrowserBmOTABinSender::WriteMessageBodyIntoFileL( RFs &fs, |
|
449 TDesC& aBody ) |
|
450 { |
|
451 TInt result; |
|
452 RFile otaFile; |
|
453 TFileName filename( KAttachmentFilename ); |
|
454 |
|
455 if( (result = otaFile.Replace( fs, filename, EFileShareExclusive)) == |
|
456 KErrNone ) |
|
457 { |
|
458 |
|
459 #ifdef _BOOKMARK_SENT_ASCII |
|
460 HBufC8 *tempBody = HBufC8::NewL( aBody.Length() ); |
|
461 // convert 16bits -> 8bits |
|
462 tempBody->Des().Copy( aBody ); |
|
463 |
|
464 // write message into file |
|
465 result = otaFile.Write( *tempBody ); |
|
466 #else // _BOOKMARK_SENT_ASCII |
|
467 // put 16bits binary data to 8bits (double byte -> two byte) |
|
468 TPtrC8 tempBody( (TUint8*)aBody.Ptr(), aBody.Length() * 2 ); |
|
469 |
|
470 // write message into file |
|
471 result = otaFile.Write( tempBody ); |
|
472 #endif // _BOOKMARK_SENT_ASCII |
|
473 |
|
474 otaFile.Close(); |
|
475 } |
|
476 |
|
477 return result; |
|
478 } |
|
479 |
|
480 // End of File |
|
481 |