|
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 "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: Implementation of core part of Notepad Dialogs. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <aknappui.h> |
|
21 #include <AknForm.h> |
|
22 #include <akntitle.h> |
|
23 |
|
24 #include <NpdLib.rsg> |
|
25 #include <AknQueryDialog.h> |
|
26 |
|
27 #include <eikmenup.h> |
|
28 |
|
29 #include <eikproc.h> |
|
30 #include <txtetext.h> |
|
31 #include <sendui.h> |
|
32 #include <SenduiMtmUids.h> |
|
33 #include <SendUiConsts.h> |
|
34 #include <Sendnorm.rsg> |
|
35 #include <s32file.h> |
|
36 #include <txtrich.h> |
|
37 #include <featmgr.h> |
|
38 #include <hlplch.h> |
|
39 |
|
40 #include <MsgAttachmentUtils.h> |
|
41 #include <apparc.h> |
|
42 #include <CMessageData.h> |
|
43 #include <smut.h> |
|
44 #include <bautils.h> |
|
45 #include <mmsconst.h> |
|
46 #include <miutset.h> |
|
47 #include "NpdLib.hrh" |
|
48 #include "NpdLib.h" |
|
49 #include "NpdDialogBase.h" |
|
50 #include "NpdUtil.h" |
|
51 #include "NpdModel_platsec.h" |
|
52 #include "NpdEdwin.h" |
|
53 #include "NpdRichTextEditor.h" |
|
54 #include "NpdListBox.h" |
|
55 #include "NpdEdwinLines.h" |
|
56 #include "NpdLibPanic.h" |
|
57 #include "NpdListDialog.h" |
|
58 #include "NpdTemplateListBox.h" |
|
59 |
|
60 // CONSTANTS |
|
61 _LIT(KNotepadFileExtension, ".txt"); |
|
62 #ifdef _DEBUG |
|
63 static const TInt KDefaultMemoNameMaxlength(128); |
|
64 #endif |
|
65 static const TInt KSentMemoMaxNameLength(20); |
|
66 |
|
67 // ============================ MEMBER FUNCTIONS =============================== |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CNotepadDialogBase::~CNotepadDialogBase |
|
71 // Destructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CNotepadDialogBase::~CNotepadDialogBase() |
|
75 { |
|
76 if ( IsModeless() ) |
|
77 { |
|
78 iEikonEnv->EikAppUi()->RemoveFromStack(this); |
|
79 } |
|
80 if ( iSavedTitle && iTitlePane && |
|
81 !iAvkonAppUi->IsAppShutterRunning() && |
|
82 *(iTitlePane->Text()) == *iTitle && |
|
83 ( iTitlePane->Text() == NULL || |
|
84 *(iTitlePane->Text()) != *iSavedTitle ) ) |
|
85 { |
|
86 iTitlePane->SetText(iSavedTitle); |
|
87 // Ownership of iSavedTitle is transfered to iTitlePane |
|
88 // |
|
89 iSavedTitle = NULL; |
|
90 } |
|
91 delete iSavedTitle; |
|
92 delete iTitle; // own |
|
93 |
|
94 if ( iSelfPtr ) |
|
95 { |
|
96 *iSelfPtr = NULL; |
|
97 } |
|
98 |
|
99 if ( iCreateFile ) |
|
100 { |
|
101 delete iCreateFile; |
|
102 iCreateFile = NULL; |
|
103 } |
|
104 FeatureManager::UnInitializeLib(); |
|
105 |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CNotepadDialogBase::ExecuteLD |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 EXPORT_C TInt CNotepadDialogBase::ExecuteLD() |
|
113 { |
|
114 return CAknDialog::ExecuteLD(iResId); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CNotepadDialogBase::ConstructL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CNotepadDialogBase::ConstructL(TResourceReader& aReader) |
|
122 { |
|
123 FeatureManager::InitializeLibL(); |
|
124 CAknDialog::ConstructL(aReader.ReadInt32()); // LLINK menubar |
|
125 iResId = aReader.ReadInt32(); // LLINK dialog |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CNotepadDialogBase::SetTitleL |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CNotepadDialogBase::SetTitleL( const TDesC* aTitle ) |
|
133 { |
|
134 if ( aTitle ) |
|
135 { |
|
136 delete iTitle; |
|
137 iTitle = NULL; |
|
138 iTitle = aTitle->AllocL(); |
|
139 } |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CNotepadDialogBase::ExecuteConfirmationQueryL |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TBool CNotepadDialogBase::ExecuteConfirmationQueryL( TInt aPromptResId ) |
|
147 { |
|
148 HBufC* prompt = iCoeEnv->AllocReadResourceLC( aPromptResId ); |
|
149 TInt isConfirmed( ExecuteConfirmationQueryL(prompt) ); |
|
150 CleanupStack::PopAndDestroy(); // prompt |
|
151 return isConfirmed; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CNotepadDialogBase::ExecuteConfirmationQueryL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 TBool CNotepadDialogBase::ExecuteConfirmationQueryL( TDesC* aPrompt ) |
|
159 { |
|
160 CAknQueryDialog* queryDialog = CAknQueryDialog::NewL(); |
|
161 return queryDialog->ExecuteLD(R_NOTEPAD_DELETE_QUERY, |
|
162 *aPrompt); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CNotepadDialogBase::SendAsL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CNotepadDialogBase::SendAsL( |
|
170 CSendUi& aSendUi, |
|
171 TInt aCommandId, |
|
172 const TDesC* aDesC, |
|
173 const CPlainText* aPlainText, |
|
174 const TDesC* aFileName ) |
|
175 { |
|
176 __ASSERT_DEBUG( aDesC || aPlainText, |
|
177 Panic(ENotepadLibraryPanicInvalidArgument) ); |
|
178 |
|
179 TPtrC ptr; |
|
180 if ( !aDesC ) |
|
181 { |
|
182 ptr.Set(aPlainText->Read(0, aPlainText->DocumentLength())); |
|
183 aDesC = &ptr; |
|
184 } |
|
185 TUid serviceUid = aSendUi.ShowSendQueryL(); |
|
186 |
|
187 if(serviceUid.iUid == 0) |
|
188 return; |
|
189 TSendingCapabilities capa; |
|
190 aSendUi.ServiceCapabilitiesL( serviceUid, capa ); |
|
191 |
|
192 CMessageData* messageData = CMessageData::NewL(); |
|
193 CleanupStack::PushL( messageData ); |
|
194 CTemporaryFiles* files |
|
195 = new(ELeave) CTemporaryFiles(1, *iEikonEnv); |
|
196 CleanupStack::PushL(files); |
|
197 if ( IsTemplates() ) |
|
198 { |
|
199 // send as attachment |
|
200 // |
|
201 if ( aFileName ) |
|
202 { |
|
203 SendFileAsAttachmentL( aSendUi, aCommandId, *aFileName ); |
|
204 } |
|
205 else |
|
206 { |
|
207 if ( aPlainText ) // editor mode |
|
208 { |
|
209 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
210 { |
|
211 messageData->SetBodyTextL(reinterpret_cast<const CRichText*>(aPlainText)); |
|
212 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
213 } |
|
214 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
215 { |
|
216 files->AppendL(*aPlainText); |
|
217 TPtrC16 filename = (*files)[0]; |
|
218 messageData->AppendAttachmentL( filename ); |
|
219 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
220 } |
|
221 else |
|
222 { |
|
223 } |
|
224 } |
|
225 else // List mode |
|
226 { |
|
227 CPlainText* text = CPlainText::NewL(CEditableText::EFlatStorage); |
|
228 CleanupStack::PushL(text); |
|
229 text->InsertL(0, *aDesC); |
|
230 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
231 { |
|
232 messageData->SetBodyTextL(reinterpret_cast<CRichText*>(text)); |
|
233 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
234 } |
|
235 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
236 { |
|
237 files->AppendL(*text); |
|
238 TPtrC16 filename = (*files)[0]; |
|
239 messageData->AppendAttachmentL( filename ); |
|
240 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
241 } |
|
242 else |
|
243 { |
|
244 } |
|
245 CleanupStack::PopAndDestroy(); // text |
|
246 } |
|
247 } |
|
248 } |
|
249 else |
|
250 { |
|
251 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
252 { |
|
253 // send as body |
|
254 CRichText* text = CRichText::NewL( |
|
255 iEikonEnv->SystemParaFormatLayerL(), |
|
256 iEikonEnv->SystemCharFormatLayerL(), CEditableText::EFlatStorage); |
|
257 CleanupStack::PushL(text); |
|
258 text->InsertL(0, *aDesC); |
|
259 messageData->SetBodyTextL( text ); |
|
260 CleanupStack::PopAndDestroy(); // text |
|
261 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
262 } |
|
263 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
264 { |
|
265 CPlainText* text = CPlainText::NewL(CEditableText::EFlatStorage); |
|
266 CleanupStack::PushL(text); |
|
267 text->InsertL(0, *aDesC); |
|
268 files->AppendL(*text); |
|
269 TPtrC16 filename = (*files)[0]; |
|
270 messageData->AppendAttachmentL( filename ); |
|
271 CleanupStack::PopAndDestroy(); // text |
|
272 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
273 } |
|
274 else |
|
275 { |
|
276 } |
|
277 } |
|
278 CleanupStack::PopAndDestroy(2); // files, messageData |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CNotepadDialogBase::SendAsL |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CNotepadDialogBase::SendAsL( |
|
286 CSendUi& aSendUi, |
|
287 TInt aCommandId, |
|
288 TBool aFileExist, |
|
289 const TDesC* aDesC, |
|
290 const CPlainText* aPlainText ) |
|
291 { |
|
292 __ASSERT_DEBUG( aDesC || aPlainText, |
|
293 Panic(ENotepadLibraryPanicInvalidArgument) ); |
|
294 TPtrC ptr; |
|
295 if ( !aDesC ) |
|
296 { |
|
297 ptr.Set(aPlainText->Read(0, aPlainText->DocumentLength())); |
|
298 aDesC = &ptr; |
|
299 } |
|
300 // One service to dim |
|
301 CArrayFixFlat<TUid>* servicesToDim = new(ELeave) CArrayFixFlat<TUid>(1); |
|
302 CleanupStack::PushL( servicesToDim ); |
|
303 // Audio message supports only sending amr -files |
|
304 servicesToDim->AppendL(KSenduiMtmAudioMessageUid); |
|
305 servicesToDim->AppendL( KMmsDirectUpload ); |
|
306 servicesToDim->AppendL( KMmsIndirectUpload ); |
|
307 |
|
308 |
|
309 TUid serviceUid = aSendUi.ShowSendQueryL(NULL, KCapabilitiesForAllServices, servicesToDim, KNullDesC); |
|
310 CleanupStack::PopAndDestroy(); //servicesToDim |
|
311 if(serviceUid.iUid == 0) |
|
312 return; |
|
313 |
|
314 TSendingCapabilities capa; |
|
315 aSendUi.ServiceCapabilitiesL( serviceUid, capa ); |
|
316 |
|
317 CTemporaryFiles* files |
|
318 = new(ELeave) CTemporaryFiles(1, *iEikonEnv); |
|
319 CleanupStack::PushL(files); |
|
320 CMessageData* messageData = CMessageData::NewL(); |
|
321 CleanupStack::PushL( messageData ); |
|
322 RFs& fileSession = iEikonEnv->FsSession(); |
|
323 User::LeaveIfError(fileSession.ShareProtected()); |
|
324 RFile file; |
|
325 if ( IsTemplates() ) |
|
326 { |
|
327 // send as attachment |
|
328 // |
|
329 if ( aFileExist ) |
|
330 { |
|
331 SendFileAsAttachmentL( aSendUi, aCommandId, iFile ); |
|
332 } |
|
333 else |
|
334 { |
|
335 if ( aPlainText ) // editor mode |
|
336 { |
|
337 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
338 { |
|
339 CRichText* text = |
|
340 CRichText::NewL( CEikonEnv::Static()->SystemParaFormatLayerL(), |
|
341 CEikonEnv::Static()->SystemCharFormatLayerL() ); |
|
342 CleanupStack::PushL( text ); |
|
343 text->InsertL( 0, aPlainText->Read( 0 ) ); |
|
344 messageData->SetBodyTextL( text ); |
|
345 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
346 CleanupStack::PopAndDestroy(); // text |
|
347 } |
|
348 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
349 { |
|
350 files->AppendL(*aPlainText); |
|
351 TPtrC16 filename = (*files)[0]; |
|
352 User::LeaveIfError( file.Open( fileSession, filename, EFileRead ) ); |
|
353 CleanupClosePushL(file); |
|
354 messageData->AppendAttachmentHandleL( file ); |
|
355 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
356 CleanupStack::PopAndDestroy(); // text |
|
357 } |
|
358 else |
|
359 { |
|
360 } |
|
361 } |
|
362 else // List mode |
|
363 { |
|
364 CRichText* text = |
|
365 CRichText::NewL( CEikonEnv::Static()->SystemParaFormatLayerL(), |
|
366 CEikonEnv::Static()->SystemCharFormatLayerL() ); |
|
367 CleanupStack::PushL(text); |
|
368 text->InsertL(0, *aDesC); |
|
369 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
370 { |
|
371 messageData->SetBodyTextL( text ); |
|
372 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
373 } |
|
374 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
375 { |
|
376 files->AppendL(*text); |
|
377 TPtrC16 filename = (*files)[0]; |
|
378 User::LeaveIfError( file.Open( fileSession, filename, EFileRead ) ); |
|
379 CleanupClosePushL(file); |
|
380 messageData->AppendAttachmentHandleL( file ); |
|
381 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
382 CleanupStack::PopAndDestroy(); // file |
|
383 } |
|
384 else |
|
385 { |
|
386 } |
|
387 CleanupStack::PopAndDestroy(); // text |
|
388 } |
|
389 } |
|
390 } |
|
391 else |
|
392 { |
|
393 if(capa.iFlags & TSendingCapabilities::ESupportsBodyText ) |
|
394 { |
|
395 // send as body |
|
396 CRichText* text = CRichText::NewL( |
|
397 iEikonEnv->SystemParaFormatLayerL(), |
|
398 iEikonEnv->SystemCharFormatLayerL(), CEditableText::EFlatStorage); |
|
399 CleanupStack::PushL(text); |
|
400 text->InsertL(0, *aDesC); |
|
401 messageData->SetBodyTextL( text ); |
|
402 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
403 CleanupStack::PopAndDestroy(); // text |
|
404 } |
|
405 else if( capa.iFlags & TSendingCapabilities::ESupportsAttachments ) |
|
406 { |
|
407 CPlainText* text = CPlainText::NewL(CEditableText::EFlatStorage); |
|
408 CleanupStack::PushL(text); |
|
409 text->InsertL(0, *aDesC); |
|
410 files->AppendL(*text); |
|
411 TPtrC16 filename = (*files)[0]; |
|
412 User::LeaveIfError( file.Open( fileSession, filename, EFileRead ) ); |
|
413 CleanupClosePushL(file); |
|
414 messageData->AppendAttachmentHandleL( file ); |
|
415 aSendUi.CreateAndSendMessageL( serviceUid, messageData ); |
|
416 CleanupStack::PopAndDestroy(2); // file, text |
|
417 } |
|
418 else |
|
419 { |
|
420 } |
|
421 } |
|
422 CleanupStack::PopAndDestroy(2); // messageData, files |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CNotepadDialogBase::SendByKeysL |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 TUid CNotepadDialogBase::SendByKeysL( |
|
430 CSendUi& aSendUi, |
|
431 TInt aCommandId, |
|
432 CNotepadModel& aModel, |
|
433 const RArray<TInt>& aKeys ) |
|
434 { |
|
435 CArrayFix<TUid>* servicesToDim = new(ELeave) CArrayFixFlat<TUid>(3); |
|
436 CleanupStack::PushL( servicesToDim ); |
|
437 |
|
438 if(aKeys.Count() > 1) |
|
439 { |
|
440 servicesToDim->AppendL( KSenduiMtmPostcardUid ); |
|
441 } |
|
442 |
|
443 servicesToDim->AppendL(KSenduiMtmAudioMessageUid); |
|
444 TUid serviceUid = aSendUi.ShowSendQueryL( NULL, KCapabilitiesForAllServices, servicesToDim ); |
|
445 CleanupStack::PopAndDestroy( servicesToDim ); |
|
446 if(serviceUid.iUid == 0) |
|
447 return serviceUid; |
|
448 |
|
449 if ( iCreateFile ) |
|
450 { |
|
451 delete iCreateFile; |
|
452 iCreateFile = NULL; |
|
453 } |
|
454 iCreateFile = CNotepadDialogBase::CCreateAndAppendFiles::NewL( |
|
455 aSendUi, aCommandId, aModel, aKeys, *iEikonEnv, iBaseFlags, this, serviceUid); |
|
456 iCreateFile->ShowProgressBarL(); |
|
457 iCreateFile->StartAttachingL(); |
|
458 return serviceUid; |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // CNotepadDialogBase::RefreshTitleL |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 void CNotepadDialogBase::RefreshTitleL() |
|
466 { |
|
467 if ( iTitlePane && iTitle ) |
|
468 { |
|
469 iTitlePane->SetTextL(*iTitle); |
|
470 } |
|
471 } |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CNotepadDialogBase::InsertSendMenuItemAfterL |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 void CNotepadDialogBase::InsertSendMenuItemAfterL( |
|
478 CSendUi& aSendUi, |
|
479 CEikMenuPane& aMenuPane, |
|
480 TInt aCommandId ) |
|
481 { |
|
482 TInt index(0); |
|
483 aMenuPane.ItemAndPos( aCommandId, index ); |
|
484 aSendUi.AddSendMenuItemL( aMenuPane, index+1, ENotepadCmdSend/*, TSendingCapabilities()*/ ); |
|
485 aMenuPane.SetItemSpecific(ENotepadCmdSend, ETrue); |
|
486 } |
|
487 |
|
488 // ----------------------------------------------------------------------------- |
|
489 // CNotepadDialogBase::ActivateL |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 void CNotepadDialogBase::ActivateL() |
|
493 { |
|
494 // we set PriorityDefault if Modeless (for EditByKeyL). |
|
495 if ( IsModeless() ) |
|
496 { |
|
497 iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityDefault); |
|
498 } |
|
499 iTitlePane = |
|
500 STATIC_CAST(CAknTitlePane*, |
|
501 (((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane()) |
|
502 ->ControlL(TUid::Uid(EEikStatusPaneUidTitle))); |
|
503 delete iSavedTitle; |
|
504 iSavedTitle = NULL; |
|
505 if ( iTitle && ( *(iTitlePane->Text()) != *iTitle ) ) |
|
506 { |
|
507 iSavedTitle = iTitlePane->Text()->AllocL(); |
|
508 RefreshTitleL(); |
|
509 } |
|
510 CAknDialog::ActivateL(); |
|
511 } |
|
512 |
|
513 // ----------------------------------------------------------------------------- |
|
514 // CNotepadDialogBase::ProcessCommandL |
|
515 // ----------------------------------------------------------------------------- |
|
516 // |
|
517 void CNotepadDialogBase::ProcessCommandL(TInt aCommandId) |
|
518 { |
|
519 switch (aCommandId) |
|
520 { |
|
521 |
|
522 case EAknCmdHelp: |
|
523 { |
|
524 if(FeatureManager::FeatureSupported(KFeatureIdHelp)) |
|
525 { |
|
526 HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), iEikonEnv->EikAppUi()->AppHelpContextL ()); |
|
527 } |
|
528 break; |
|
529 } |
|
530 |
|
531 case EAknCmdExit: |
|
532 iAvkonAppUi->ProcessCommandL(EAknCmdExit); |
|
533 break; |
|
534 default: |
|
535 CAknDialog::ProcessCommandL(aCommandId); |
|
536 break; |
|
537 } |
|
538 } |
|
539 |
|
540 // ----------------------------------------------------------------------------- |
|
541 // CNotepadDialogBase::CreateCustomControlL |
|
542 // from MEikDialogPageObserver |
|
543 // ----------------------------------------------------------------------------- |
|
544 // |
|
545 SEikControlInfo CNotepadDialogBase::CreateCustomControlL(TInt aControlType) |
|
546 { |
|
547 CCoeControl *control = NULL; |
|
548 SEikControlInfo info = {control,0,0}; |
|
549 switch ( aControlType ) |
|
550 { |
|
551 case ENotepadCtEdwin: |
|
552 info.iControl = new(ELeave) CNotepadEdwin(); |
|
553 ((CNotepadEdwin*)info.iControl)->SetSkinBackgroundControlContextL(NULL); |
|
554 break; |
|
555 case ENotepadCtRichTextEditor: |
|
556 info.iControl = new(ELeave) CNotepadRichTextEditor(); |
|
557 ((CNotepadRichTextEditor*)info.iControl)->SetSkinBackgroundControlContextL(NULL); |
|
558 break; |
|
559 case ENotepadCtEdwinLines: |
|
560 info.iControl = new(ELeave) CNotepadEdwinLines(this); |
|
561 break; |
|
562 case ENotepadCtListBox: |
|
563 { |
|
564 CNotepadListBox* listbox = new(ELeave) CNotepadListBox(*this); |
|
565 CleanupStack::PushL(listbox); |
|
566 listbox->LoadMarginsL(); |
|
567 info.iControl = listbox; |
|
568 CleanupStack::Pop(); |
|
569 } |
|
570 break; |
|
571 case ENotepadCtTemplateListBox: |
|
572 { |
|
573 CNotepadTemplateListBox* templateListbox = new(ELeave) CNotepadTemplateListBox( *this ); |
|
574 info.iControl = templateListbox; |
|
575 } |
|
576 break; |
|
577 default: |
|
578 break; |
|
579 } |
|
580 return info; |
|
581 } |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CNotepadDialogBase::SendFileAsAttachmentL |
|
585 // ----------------------------------------------------------------------------- |
|
586 // |
|
587 void CNotepadDialogBase::SendFileAsAttachmentL( |
|
588 CSendUi& aSendUi, |
|
589 TInt /*aCommandId*/, |
|
590 const TDesC& aFileName ) |
|
591 { |
|
592 CMessageData* messageData = CMessageData::NewL(); |
|
593 CleanupStack::PushL( messageData ); |
|
594 messageData->AppendAttachmentL( aFileName ); |
|
595 aSendUi.ShowQueryAndSendL( messageData ); |
|
596 CleanupStack::PopAndDestroy(); // messageData |
|
597 } |
|
598 |
|
599 // ----------------------------------------------------------------------------- |
|
600 // CNotepadDialogBase::SendFileAsAttachmentL |
|
601 // ----------------------------------------------------------------------------- |
|
602 // |
|
603 void CNotepadDialogBase::SendFileAsAttachmentL( |
|
604 CSendUi& aSendUi, |
|
605 TInt /*aCommandId*/, |
|
606 RFile& aFile ) |
|
607 { |
|
608 CMessageData* messageData = CMessageData::NewL(); |
|
609 CleanupStack::PushL( messageData ); |
|
610 messageData->AppendAttachmentHandleL( aFile ); |
|
611 aSendUi.ShowQueryAndSendL( messageData ); |
|
612 CleanupStack::PopAndDestroy(); // messageData |
|
613 } |
|
614 |
|
615 // ----------------------------------------------------------------------------- |
|
616 // CNotepadDialogBase::CleanupSendUiFlag |
|
617 // ----------------------------------------------------------------------------- |
|
618 // |
|
619 void CNotepadDialogBase::CleanupSendUiFlag(TAny *aSelf) |
|
620 { |
|
621 CNotepadDialogBase* self = STATIC_CAST(CNotepadDialogBase*, aSelf); |
|
622 self->iBaseFlags &= ~ENotepadSendUiRunning; |
|
623 } |
|
624 |
|
625 // ----------------------------------------------------------------------------- |
|
626 // CNotepadDialogBase::SetFileHandleL |
|
627 // ----------------------------------------------------------------------------- |
|
628 // |
|
629 void CNotepadDialogBase::SetFileHandleL(RFile& aFile) |
|
630 { |
|
631 iFile = aFile; |
|
632 } |
|
633 |
|
634 // ----------------------------------------------------------------------------- |
|
635 // CNotepadDialogBase::CNotepadDialogBase_Reserved |
|
636 // Reserved API. |
|
637 // ----------------------------------------------------------------------------- |
|
638 // |
|
639 EXPORT_C void CNotepadDialogBase::CNotepadDialogBase_Reserved() |
|
640 { |
|
641 } |
|
642 |
|
643 |
|
644 // ----------------------------------------------------------------------------- |
|
645 // CNotepadDialogBase::CTemporaryFiles::CTemporaryFiles |
|
646 // ----------------------------------------------------------------------------- |
|
647 // |
|
648 CNotepadDialogBase::CTemporaryFiles::CTemporaryFiles( |
|
649 TInt aGranularity, |
|
650 CEikonEnv& aEikonEnv ) |
|
651 :CDesC16ArrayFlat(aGranularity), iEnv(aEikonEnv) |
|
652 { |
|
653 } |
|
654 |
|
655 // ----------------------------------------------------------------------------- |
|
656 // CNotepadDialogBase::CTemporaryFiles::AppendL |
|
657 // |
|
658 // if you need some code conversion.... |
|
659 // CPlainText::TImportExportParam param; |
|
660 // param.iForeignEncoding = KCharacterSetIdentifierUtf8; // target encoding |
|
661 // CPlainText::TImportExportResult result; |
|
662 // text->ExportTextL(0, stream, param, result); |
|
663 // ----------------------------------------------------------------------------- |
|
664 // |
|
665 void CNotepadDialogBase::CTemporaryFiles::AppendL(const CPlainText& aText) |
|
666 { |
|
667 TPtrC buf = aText.Read(0); |
|
668 iSendFileName.FillZ(); |
|
669 NotepadUtil::LeaveIfCriticalLevelL(iEnv, buf.Size()); |
|
670 TFileName fileName; |
|
671 TFileName path; |
|
672 _LIT(KDrive, "C:"); |
|
673 iEnv.FsSession().PrivatePath(path); |
|
674 iEnv.FsSession().CreatePrivatePath(KDefaultDrive); |
|
675 MsgAttachmentUtils::GetFileNameFromBuffer( |
|
676 fileName, buf, |
|
677 KSentMemoMaxNameLength + |
|
678 KNotepadFileExtension().Length(), |
|
679 &KNotepadFileExtension ); |
|
680 if ( fileName.Length() == 0 ) |
|
681 { |
|
682 __ASSERT_DEBUG( KDefaultMemoNameMaxlength + |
|
683 KNotepadFileExtension().Length() < fileName.MaxLength(), |
|
684 User::Invariant() ); |
|
685 iEnv.ReadResourceL(fileName, R_NOTEPAD_DEFAULT_DOCUMENT_NAME); |
|
686 fileName.Append(KNotepadFileExtension); |
|
687 } |
|
688 // If SYMBIAN_REMOVE_UI_FRAMEWORKS_V1 is defined. |
|
689 fileName.Insert(0, path); |
|
690 fileName.Insert(0, KDrive); |
|
691 CApaApplication::GenerateFileName(iEnv.FsSession(), fileName); |
|
692 CDesC16ArrayFlat::AppendL(fileName); |
|
693 RFile file; |
|
694 BaflUtils::DeleteFile( iEnv.FsSession(), fileName ); |
|
695 User::LeaveIfError( file.Create( iEnv.FsSession(), |
|
696 fileName, EFileWrite ) ); |
|
697 iSendFileName.Copy(fileName); |
|
698 CleanupClosePushL(file); |
|
699 RFileWriteStream stream(file); |
|
700 CleanupClosePushL(stream); |
|
701 stream.WriteUint16L(CEditableText::EByteOrderMark); |
|
702 aText.ExportTextL( 0, stream, |
|
703 CPlainText::EOrganiseByParagraph ); |
|
704 CleanupStack::PopAndDestroy(2); // stream, file |
|
705 } |
|
706 |
|
707 // ----------------------------------------------------------------------------- |
|
708 // CNotepadDialogBase::CTemporaryFiles::~CTemporaryFiles |
|
709 // ----------------------------------------------------------------------------- |
|
710 CNotepadDialogBase::CTemporaryFiles::~CTemporaryFiles() |
|
711 { |
|
712 for (TInt i(MdcaCount() - 1); i >= 0; i--) |
|
713 { |
|
714 iEnv.FsSession().Delete(MdcaPoint(i)); |
|
715 } |
|
716 } |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CNotepadDialogBase::CCreateAndAppendFiles* |
|
720 // CNotepadDialogBase::CCreateAndAppendFiles::NewL |
|
721 // ----------------------------------------------------------------------------- |
|
722 // |
|
723 CNotepadDialogBase::CCreateAndAppendFiles* |
|
724 CNotepadDialogBase::CCreateAndAppendFiles::NewL( |
|
725 CSendUi& aSendAppUi, |
|
726 TInt aCommandId, |
|
727 CNotepadModel& aModel, |
|
728 RArray<TInt> aKeys, |
|
729 CEikonEnv& aEikonEnv, |
|
730 TInt& aBaseFlags, |
|
731 CNotepadDialogBase* aNpdDlgBase,TUid aServiceUId) |
|
732 { |
|
733 CCreateAndAppendFiles* self = |
|
734 new(ELeave) CCreateAndAppendFiles( aSendAppUi, aCommandId, aModel, /*aKeys,*/ aEikonEnv, aBaseFlags, aNpdDlgBase, aServiceUId ); |
|
735 CleanupStack::PushL(self); |
|
736 self->ConstructL(aKeys); |
|
737 CleanupStack::Pop(); // self |
|
738 return self; |
|
739 } |
|
740 |
|
741 // ----------------------------------------------------------------------------- |
|
742 // CNotepadDialogBase::CCreateAndAppendFiles::CCreateAndAppendFiles |
|
743 // ----------------------------------------------------------------------------- |
|
744 |
|
745 CNotepadDialogBase::CCreateAndAppendFiles::CCreateAndAppendFiles( |
|
746 CSendUi& aSendAppUi, |
|
747 TInt aCommandId, |
|
748 CNotepadModel& aModel, |
|
749 /*RArray<TInt> aKeys,*/ |
|
750 CEikonEnv& aEikonEnv, |
|
751 TInt& aBaseFlags, |
|
752 CNotepadDialogBase* aNpdDlgBase, TUid aServiceUId) |
|
753 :CActive(CActive::EPriorityLow), iSendAppUi(aSendAppUi), iCommandId(aCommandId), |
|
754 iModel(aModel), iEnv(aEikonEnv), iBaseFlags(aBaseFlags)//, iNpdDlgBase(aNpdDlgBase) |
|
755 { |
|
756 |
|
757 |
|
758 iListDialog = STATIC_CAST(CNotepadListDialog*, aNpdDlgBase ); |
|
759 iServiceUId = aServiceUId; |
|
760 CActiveScheduler::Add(this); |
|
761 } |
|
762 |
|
763 // ----------------------------------------------------------------------------- |
|
764 // CNotepadDialogBase::CCreateAndAppendFiles::ConstructL |
|
765 // ----------------------------------------------------------------------------- |
|
766 |
|
767 void CNotepadDialogBase::CCreateAndAppendFiles::ConstructL(RArray<TInt> aKeys) |
|
768 { |
|
769 |
|
770 for (TInt i=0; i < aKeys.Count(); i++ ) |
|
771 { |
|
772 iKeys.Append(aKeys[i]); |
|
773 } |
|
774 |
|
775 array = new (ELeave) CArrayFixFlat<RFile>(10); |
|
776 |
|
777 for (TInt i=0; i < aKeys.Count(); i++ ) |
|
778 { |
|
779 array->AppendL(ifile1); |
|
780 |
|
781 } |
|
782 |
|
783 iCount = 0; |
|
784 iTotalCount = iKeys.Count(); |
|
785 iFiles = new(ELeave) CTemporaryFiles(iTotalCount+1, iEnv); |
|
786 iText = CPlainText::NewL(CEditableText::EFlatStorage); |
|
787 imessageData = CMessageData::NewL(); |
|
788 User::LeaveIfError(iFs.Connect()); |
|
789 User::LeaveIfError(iFs.ShareProtected()); |
|
790 iCanceled = EFalse; |
|
791 |
|
792 } |
|
793 |
|
794 |
|
795 // ----------------------------------------------------------------------------- |
|
796 // CNotepadDialogBase::CCreateAndAppendFiles::~CCreateAndAppendFiles |
|
797 // ----------------------------------------------------------------------------- |
|
798 |
|
799 CNotepadDialogBase::CCreateAndAppendFiles::~CCreateAndAppendFiles() |
|
800 { |
|
801 Cancel(); |
|
802 //EndProgressDialog(); |
|
803 if(iFiles) |
|
804 { |
|
805 delete iFiles; |
|
806 iFiles =NULL; |
|
807 } |
|
808 |
|
809 if(iText) |
|
810 { |
|
811 delete iText; |
|
812 iText =NULL; |
|
813 } |
|
814 |
|
815 if(imessageData) |
|
816 { |
|
817 |
|
818 delete imessageData; |
|
819 imessageData =NULL; |
|
820 } |
|
821 |
|
822 if(array) |
|
823 { |
|
824 array->Reset(); |
|
825 |
|
826 delete array; |
|
827 array =NULL; |
|
828 } |
|
829 if(iProgressBar) |
|
830 { |
|
831 |
|
832 delete iProgressBar; |
|
833 iProgressBar = NULL; |
|
834 } |
|
835 iKeys.Close(); |
|
836 |
|
837 } |
|
838 |
|
839 // ----------------------------------------------------------------------------- |
|
840 // CNotepadDialogBase::CCreateAndAppendFiles::ShowProgressBarL |
|
841 // ----------------------------------------------------------------------------- |
|
842 |
|
843 void CNotepadDialogBase::CCreateAndAppendFiles::ShowProgressBarL() |
|
844 { |
|
845 iProgressBar = new (ELeave)CAknProgressDialog( REINTERPRET_CAST(CEikDialog** , &iProgressBar), EFalse); |
|
846 iProgressBar->PrepareLC(R_SEND_NOTEPAD_NOTE); |
|
847 iProgressBar->RunLD(); |
|
848 iProgressBar->SetCallback(this); |
|
849 } |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // CNotepadDialogBase::CCreateAndAppendFiles::EndProgressDialog |
|
853 // ----------------------------------------------------------------------------- |
|
854 |
|
855 void CNotepadDialogBase::CCreateAndAppendFiles::EndProgressDialog() |
|
856 { |
|
857 //Stop displaying progress bar and destroy the progress bar pointer |
|
858 if(iProgressBar) |
|
859 { |
|
860 TRAP_IGNORE( iProgressBar->ProcessFinishedL() ); |
|
861 delete iProgressBar; |
|
862 iProgressBar = NULL; |
|
863 } |
|
864 } |
|
865 |
|
866 |
|
867 // ----------------------------------------------------------------------------- |
|
868 // CNotepadDialogBase::CCreateAndAppendFiles::StartAttachingL |
|
869 // ----------------------------------------------------------------------------- |
|
870 |
|
871 void CNotepadDialogBase::CCreateAndAppendFiles::StartAttachingL() |
|
872 { |
|
873 iStatus = KRequestPending; |
|
874 if( iCount < iTotalCount ) |
|
875 iAttaching = ETrue; |
|
876 else |
|
877 iAttaching = EFalse; |
|
878 |
|
879 |
|
880 if( iAttaching ) |
|
881 { |
|
882 TInt tempInt = iKeys[iCount]; |
|
883 HBufC* buf = iModel.ContentByKeyL(tempInt); |
|
884 |
|
885 CleanupStack::PushL(buf); |
|
886 iText->Reset(); |
|
887 iText->InsertL(0, *buf); |
|
888 iFiles->AppendL(*iText); |
|
889 |
|
890 User::LeaveIfError( array->At(iCount).Open( iFs, iFiles->iSendFileName, EFileRead ) ); |
|
891 imessageData->AppendAttachmentHandleL( array->At(iCount)); |
|
892 |
|
893 iCount++; |
|
894 CleanupStack::PopAndDestroy(); // buf |
|
895 } |
|
896 SetActive(); |
|
897 TRequestStatus* status = &iStatus; |
|
898 User::RequestComplete(status,KErrNone); |
|
899 } |
|
900 |
|
901 // ----------------------------------------------------------------------------- |
|
902 // CNotepadDialogBase::CCreateAndAppendFiles::DialogDismissedL |
|
903 // ----------------------------------------------------------------------------- |
|
904 // |
|
905 void CNotepadDialogBase::CCreateAndAppendFiles::DialogDismissedL(TInt /*aButtonId*/) |
|
906 |
|
907 { |
|
908 if( iCount < iTotalCount ) |
|
909 { |
|
910 iAttaching = EFalse; |
|
911 iCanceled = ETrue; |
|
912 } |
|
913 } |
|
914 // ----------------------------------------------------------------------------- |
|
915 // CNotepadDialogBase::CCreateAndAppendFiles::RunL |
|
916 // ----------------------------------------------------------------------------- |
|
917 |
|
918 void CNotepadDialogBase::CCreateAndAppendFiles::RunL() |
|
919 { |
|
920 switch(iAttaching) |
|
921 { |
|
922 case ETrue: |
|
923 StartAttachingL(); |
|
924 break; |
|
925 case EFalse: |
|
926 if (iProgressBar) |
|
927 { |
|
928 EndProgressDialog(); |
|
929 } |
|
930 if(!iCanceled) |
|
931 { |
|
932 iSendAppUi.CreateAndSendMessageL( iServiceUId, imessageData ); |
|
933 } |
|
934 |
|
935 iListDialog->ClearSaveOrMarkedListItemsL(!iCanceled ); |
|
936 iCanceled = EFalse; |
|
937 |
|
938 if(iFiles) |
|
939 { |
|
940 delete iFiles; |
|
941 iFiles =NULL; |
|
942 } |
|
943 |
|
944 if(iText) |
|
945 { |
|
946 delete iText; |
|
947 iText =NULL; |
|
948 } |
|
949 |
|
950 if(imessageData) |
|
951 { |
|
952 |
|
953 delete imessageData; |
|
954 imessageData =NULL; |
|
955 } |
|
956 |
|
957 if(array) |
|
958 { |
|
959 array->Reset(); |
|
960 |
|
961 delete array; |
|
962 array =NULL; |
|
963 } |
|
964 |
|
965 |
|
966 iKeys.Close(); |
|
967 |
|
968 iFs.Close(); |
|
969 |
|
970 RFs fs; |
|
971 User::LeaveIfError(fs.Connect()); |
|
972 CleanupClosePushL(fs); |
|
973 CFileMan* fileMan = CFileMan::NewL(fs); |
|
974 CleanupStack::PushL( fileMan ); |
|
975 |
|
976 TFileName path; |
|
977 fs.PrivatePath(path); |
|
978 fs.CreatePrivatePath(KDefaultDrive); |
|
979 |
|
980 path.Append(_L("*.*")); |
|
981 TInt errorcode = fileMan->Delete( path, 0 ); |
|
982 |
|
983 CleanupStack::PopAndDestroy( fileMan ); |
|
984 CleanupStack::PopAndDestroy(); |
|
985 |
|
986 |
|
987 break; |
|
988 } |
|
989 } |
|
990 |
|
991 // ----------------------------------------------------------------------------- |
|
992 // CNotepadDialogBase::CCreateAndAppendFiles::DoCancel |
|
993 // ----------------------------------------------------------------------------- |
|
994 |
|
995 void CNotepadDialogBase::CCreateAndAppendFiles::DoCancel() |
|
996 { |
|
997 if (iProgressBar) |
|
998 { |
|
999 EndProgressDialog(); |
|
1000 } |
|
1001 |
|
1002 } |
|
1003 // End of File |