notepad/notepad1/LibSrc/NpdDialogBase.cpp
branchRCL_3
changeset 66 bd7edf625bdd
child 67 1539a383d7b6
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
       
     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 	
       
   486     if ( IsNoteListDialog() )
       
   487         {
       
   488         aMenuPane.SetItemSpecific( ENotepadCmdSend, ETrue );
       
   489         }	
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CNotepadDialogBase::ActivateL
       
   494 // -----------------------------------------------------------------------------
       
   495 //
       
   496 void CNotepadDialogBase::ActivateL()
       
   497     {
       
   498     // we set PriorityDefault if Modeless (for EditByKeyL).
       
   499     if ( IsModeless() )
       
   500         {
       
   501         iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityDefault);
       
   502         }
       
   503     iTitlePane = 
       
   504         STATIC_CAST(CAknTitlePane*, 
       
   505             (((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane())
       
   506                 ->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
       
   507     delete iSavedTitle;
       
   508     iSavedTitle = NULL;
       
   509     if ( iTitle && ( *(iTitlePane->Text()) != *iTitle ) )
       
   510         {
       
   511         iSavedTitle = iTitlePane->Text()->AllocL();
       
   512         RefreshTitleL();
       
   513         }
       
   514     CAknDialog::ActivateL();
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CNotepadDialogBase::ProcessCommandL
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 void CNotepadDialogBase::ProcessCommandL(TInt aCommandId)
       
   522     {
       
   523     switch (aCommandId)
       
   524         {
       
   525 
       
   526         case EAknCmdHelp:
       
   527             {
       
   528 			if(FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   529 				{
       
   530 		 		HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), iEikonEnv->EikAppUi()->AppHelpContextL ());	     
       
   531 				}	
       
   532             break;
       
   533             }
       
   534 
       
   535         case EAknCmdExit:
       
   536             iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   537             break;
       
   538         default:
       
   539             CAknDialog::ProcessCommandL(aCommandId);
       
   540             break;
       
   541         }    
       
   542     }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // CNotepadDialogBase::CreateCustomControlL
       
   546 // from MEikDialogPageObserver
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 SEikControlInfo CNotepadDialogBase::CreateCustomControlL(TInt aControlType)
       
   550     {
       
   551     CCoeControl *control = NULL;
       
   552     SEikControlInfo info = {control,0,0};
       
   553     switch ( aControlType )
       
   554         {
       
   555         case ENotepadCtEdwin:
       
   556             info.iControl = new(ELeave) CNotepadEdwin();
       
   557 			((CNotepadEdwin*)info.iControl)->SetSkinBackgroundControlContextL(NULL);
       
   558             break;
       
   559         case ENotepadCtRichTextEditor:
       
   560         	info.iControl = new(ELeave) CNotepadRichTextEditor();
       
   561         	((CNotepadRichTextEditor*)info.iControl)->SetSkinBackgroundControlContextL(NULL);
       
   562         	break;
       
   563         case ENotepadCtEdwinLines:
       
   564             info.iControl = new(ELeave) CNotepadEdwinLines(this);
       
   565             break;
       
   566         case ENotepadCtListBox:
       
   567             {
       
   568             CNotepadListBox* listbox = new(ELeave) CNotepadListBox(*this);
       
   569             CleanupStack::PushL(listbox);
       
   570             listbox->LoadMarginsL();
       
   571             info.iControl = listbox;
       
   572             CleanupStack::Pop();
       
   573             }
       
   574             break;
       
   575         case ENotepadCtTemplateListBox:
       
   576             {
       
   577             CNotepadTemplateListBox* templateListbox = new(ELeave) CNotepadTemplateListBox( *this );
       
   578             info.iControl = templateListbox;
       
   579             }
       
   580             break;
       
   581         default:
       
   582             break;
       
   583         }
       
   584     return info;
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CNotepadDialogBase::SendFileAsAttachmentL
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 void CNotepadDialogBase::SendFileAsAttachmentL(
       
   592     CSendUi& aSendUi,
       
   593     TInt /*aCommandId*/, 
       
   594     const TDesC& aFileName )
       
   595     {
       
   596     CMessageData* messageData = CMessageData::NewL();
       
   597 	CleanupStack::PushL( messageData );
       
   598 	messageData->AppendAttachmentL( aFileName );
       
   599 	aSendUi.ShowQueryAndSendL( messageData );
       
   600 	CleanupStack::PopAndDestroy(); // messageData
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CNotepadDialogBase::SendFileAsAttachmentL
       
   605 // -----------------------------------------------------------------------------
       
   606 //
       
   607 void CNotepadDialogBase::SendFileAsAttachmentL(
       
   608     CSendUi& aSendUi,
       
   609     TInt /*aCommandId*/, 
       
   610     RFile& aFile )
       
   611     {
       
   612     CMessageData* messageData = CMessageData::NewL();
       
   613 	CleanupStack::PushL( messageData );
       
   614 	messageData->AppendAttachmentHandleL( aFile );
       
   615 	aSendUi.ShowQueryAndSendL( messageData );
       
   616 	CleanupStack::PopAndDestroy(); // messageData
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CNotepadDialogBase::CleanupSendUiFlag
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 void CNotepadDialogBase::CleanupSendUiFlag(TAny *aSelf)
       
   624     {
       
   625     CNotepadDialogBase* self = STATIC_CAST(CNotepadDialogBase*, aSelf);
       
   626     self->iBaseFlags &= ~ENotepadSendUiRunning;
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CNotepadDialogBase::SetFileHandleL
       
   631 // -----------------------------------------------------------------------------
       
   632 //
       
   633 void CNotepadDialogBase::SetFileHandleL(RFile& aFile)
       
   634 	{
       
   635 	iFile = aFile;
       
   636 	}
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CNotepadDialogBase::CNotepadDialogBase_Reserved
       
   640 // Reserved API.
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 EXPORT_C void CNotepadDialogBase::CNotepadDialogBase_Reserved()
       
   644     {
       
   645     }
       
   646 
       
   647 
       
   648 // -----------------------------------------------------------------------------
       
   649 // CNotepadDialogBase::CTemporaryFiles::CTemporaryFiles
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 CNotepadDialogBase::CTemporaryFiles::CTemporaryFiles(
       
   653     TInt aGranularity,
       
   654     CEikonEnv& aEikonEnv )
       
   655     :CDesC16ArrayFlat(aGranularity), iEnv(aEikonEnv)
       
   656     {
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CNotepadDialogBase::CTemporaryFiles::AppendL
       
   661 //
       
   662 // if you need some code conversion....
       
   663 // CPlainText::TImportExportParam param;
       
   664 // param.iForeignEncoding = KCharacterSetIdentifierUtf8; // target encoding
       
   665 // CPlainText::TImportExportResult result;
       
   666 // text->ExportTextL(0, stream, param, result);
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 void CNotepadDialogBase::CTemporaryFiles::AppendL(const CPlainText& aText)
       
   670     {
       
   671     TPtrC buf = aText.Read(0);
       
   672     iSendFileName.FillZ();
       
   673     NotepadUtil::LeaveIfCriticalLevelL(iEnv, buf.Size());
       
   674     TFileName fileName;
       
   675     TFileName path;
       
   676     _LIT(KDrive, "C:");
       
   677     iEnv.FsSession().PrivatePath(path);
       
   678    	iEnv.FsSession().CreatePrivatePath(KDefaultDrive);
       
   679     MsgAttachmentUtils::GetFileNameFromBuffer(
       
   680         fileName, buf, 
       
   681         KSentMemoMaxNameLength + 
       
   682             KNotepadFileExtension().Length(), 
       
   683         &KNotepadFileExtension );
       
   684     if ( fileName.Length() == 0 ) 
       
   685         {
       
   686         __ASSERT_DEBUG( KDefaultMemoNameMaxlength + 
       
   687             KNotepadFileExtension().Length() < fileName.MaxLength(),
       
   688             User::Invariant() );
       
   689         iEnv.ReadResourceL(fileName, R_NOTEPAD_DEFAULT_DOCUMENT_NAME);
       
   690         fileName.Append(KNotepadFileExtension);
       
   691         }
       
   692     // If SYMBIAN_REMOVE_UI_FRAMEWORKS_V1 is defined.
       
   693     fileName.Insert(0, path);
       
   694     fileName.Insert(0, KDrive);
       
   695     CApaApplication::GenerateFileName(iEnv.FsSession(), fileName);
       
   696     CDesC16ArrayFlat::AppendL(fileName);
       
   697     RFile file;
       
   698     BaflUtils::DeleteFile( iEnv.FsSession(), fileName );
       
   699     User::LeaveIfError( file.Create( iEnv.FsSession(), 
       
   700         fileName, EFileWrite ) );
       
   701     iSendFileName.Copy(fileName);
       
   702     CleanupClosePushL(file);
       
   703     RFileWriteStream stream(file);
       
   704     CleanupClosePushL(stream);
       
   705     stream.WriteUint16L(CEditableText::EByteOrderMark);
       
   706     aText.ExportTextL( 0, stream, 
       
   707         CPlainText::EOrganiseByParagraph );
       
   708     CleanupStack::PopAndDestroy(2); // stream, file
       
   709     }
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CNotepadDialogBase::CTemporaryFiles::~CTemporaryFiles
       
   713 // -----------------------------------------------------------------------------
       
   714 CNotepadDialogBase::CTemporaryFiles::~CTemporaryFiles()
       
   715     {
       
   716     for (TInt i(MdcaCount() - 1); i >= 0; i--)
       
   717         {
       
   718         iEnv.FsSession().Delete(MdcaPoint(i));
       
   719         }
       
   720     }
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CNotepadDialogBase::CCreateAndAppendFiles* 
       
   724 //	CNotepadDialogBase::CCreateAndAppendFiles::NewL
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 CNotepadDialogBase::CCreateAndAppendFiles* 
       
   728 	CNotepadDialogBase::CCreateAndAppendFiles::NewL(
       
   729 	CSendUi& aSendAppUi, 
       
   730 	TInt aCommandId, 
       
   731 	CNotepadModel& aModel,
       
   732 	RArray<TInt> aKeys,
       
   733 	CEikonEnv& aEikonEnv,
       
   734 	TInt& aBaseFlags,
       
   735 	CNotepadDialogBase* aNpdDlgBase,TUid aServiceUId)
       
   736 	{
       
   737     CCreateAndAppendFiles* self = 
       
   738         new(ELeave) CCreateAndAppendFiles( aSendAppUi, aCommandId, aModel, /*aKeys,*/ aEikonEnv, aBaseFlags, aNpdDlgBase, aServiceUId );
       
   739 	CleanupStack::PushL(self);
       
   740     self->ConstructL(aKeys);
       
   741     CleanupStack::Pop(); // self
       
   742     return self; 
       
   743 	}
       
   744 	
       
   745 // -----------------------------------------------------------------------------
       
   746 // CNotepadDialogBase::CCreateAndAppendFiles::CCreateAndAppendFiles
       
   747 // -----------------------------------------------------------------------------
       
   748 
       
   749 CNotepadDialogBase::CCreateAndAppendFiles::CCreateAndAppendFiles(
       
   750 	CSendUi& aSendAppUi, 
       
   751 	TInt aCommandId,
       
   752 	CNotepadModel& aModel,
       
   753     /*RArray<TInt> aKeys,*/
       
   754 	CEikonEnv& aEikonEnv,
       
   755 	TInt& aBaseFlags,
       
   756 	CNotepadDialogBase* aNpdDlgBase, TUid aServiceUId)
       
   757 	:CActive(CActive::EPriorityLow), iSendAppUi(aSendAppUi), iCommandId(aCommandId),
       
   758 	iModel(aModel), iEnv(aEikonEnv), iBaseFlags(aBaseFlags)//, iNpdDlgBase(aNpdDlgBase)
       
   759 	{
       
   760 
       
   761 	
       
   762 	iListDialog = STATIC_CAST(CNotepadListDialog*, aNpdDlgBase );
       
   763  	iServiceUId = aServiceUId;
       
   764     CActiveScheduler::Add(this);
       
   765 	}
       
   766 
       
   767 // -----------------------------------------------------------------------------
       
   768 // CNotepadDialogBase::CCreateAndAppendFiles::ConstructL
       
   769 // -----------------------------------------------------------------------------
       
   770 
       
   771 void CNotepadDialogBase::CCreateAndAppendFiles::ConstructL(RArray<TInt> aKeys)
       
   772 	{
       
   773 
       
   774 	for (TInt i=0; i < aKeys.Count(); i++ )
       
   775 		{
       
   776 		iKeys.Append(aKeys[i]);
       
   777 		}
       
   778 	
       
   779 	array = new (ELeave) CArrayFixFlat<RFile>(10);
       
   780 	
       
   781 	for (TInt i=0; i < aKeys.Count(); i++ )
       
   782 	{
       
   783 		array->AppendL(ifile1);
       
   784 		
       
   785 	}
       
   786 	
       
   787 	iCount = 0;
       
   788 	iTotalCount = iKeys.Count();
       
   789     iFiles = new(ELeave) CTemporaryFiles(iTotalCount+1, iEnv);
       
   790     iText = CPlainText::NewL(CEditableText::EFlatStorage);
       
   791     imessageData = CMessageData::NewL();
       
   792     User::LeaveIfError(iFs.Connect());
       
   793 	User::LeaveIfError(iFs.ShareProtected());
       
   794 	iCanceled = EFalse;
       
   795 
       
   796 	}
       
   797 	
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CNotepadDialogBase::CCreateAndAppendFiles::~CCreateAndAppendFiles
       
   801 // -----------------------------------------------------------------------------
       
   802 
       
   803 CNotepadDialogBase::CCreateAndAppendFiles::~CCreateAndAppendFiles()
       
   804 	{
       
   805     Cancel();
       
   806 	//EndProgressDialog();
       
   807 	if(iFiles)		
       
   808 		{
       
   809 		delete iFiles;
       
   810 	 	iFiles =NULL;
       
   811 		}
       
   812 	
       
   813 	if(iText)
       
   814 		{
       
   815 		delete iText;
       
   816 		iText =NULL;
       
   817 		}
       
   818 	
       
   819 	if(imessageData)
       
   820 		{
       
   821 		
       
   822 		delete imessageData;
       
   823 		imessageData =NULL;	
       
   824 		}
       
   825 	
       
   826 	if(array)
       
   827 		{
       
   828 		array->Reset();
       
   829 
       
   830 		delete array;
       
   831 		array =NULL;
       
   832 		}
       
   833 	if(iProgressBar)
       
   834 		{
       
   835 		
       
   836 		delete iProgressBar;
       
   837 		iProgressBar = NULL;
       
   838 		}
       
   839 	iKeys.Close();
       
   840 
       
   841 	}
       
   842 	
       
   843 // -----------------------------------------------------------------------------
       
   844 // CNotepadDialogBase::CCreateAndAppendFiles::ShowProgressBarL
       
   845 // -----------------------------------------------------------------------------
       
   846 
       
   847 void CNotepadDialogBase::CCreateAndAppendFiles::ShowProgressBarL() 
       
   848 	{ 
       
   849     iProgressBar = new (ELeave)CAknProgressDialog( REINTERPRET_CAST(CEikDialog** , &iProgressBar), EFalse); 
       
   850     iProgressBar->PrepareLC(R_SEND_NOTEPAD_NOTE); 
       
   851     iProgressBar->RunLD();
       
   852     iProgressBar->SetCallback(this);   
       
   853 	} 
       
   854 
       
   855 // -----------------------------------------------------------------------------
       
   856 // CNotepadDialogBase::CCreateAndAppendFiles::EndProgressDialog
       
   857 // -----------------------------------------------------------------------------
       
   858 
       
   859 void CNotepadDialogBase::CCreateAndAppendFiles::EndProgressDialog() 
       
   860 	{
       
   861     //Stop displaying progress bar and destroy the progress bar pointer 
       
   862     if(iProgressBar) 
       
   863 		{ 
       
   864         TRAP_IGNORE( iProgressBar->ProcessFinishedL() );
       
   865         delete iProgressBar; 
       
   866         iProgressBar = NULL; 
       
   867         } 
       
   868 	}
       
   869 
       
   870 
       
   871 // -----------------------------------------------------------------------------
       
   872 // CNotepadDialogBase::CCreateAndAppendFiles::StartAttachingL
       
   873 // -----------------------------------------------------------------------------
       
   874 
       
   875 void CNotepadDialogBase::CCreateAndAppendFiles::StartAttachingL()
       
   876     {
       
   877 	if( iCount < iTotalCount )
       
   878 		iAttaching = ETrue;
       
   879 	else
       
   880 		iAttaching = EFalse;
       
   881 	
       
   882 	
       
   883 	if( iAttaching )
       
   884 		{
       
   885         TInt tempInt = iKeys[iCount];
       
   886         HBufC* buf = iModel.ContentByKeyL(tempInt);
       
   887 		
       
   888         CleanupStack::PushL(buf);
       
   889         iText->Reset();
       
   890 
       
   891         TRAPD( err, iText->InsertL( 0, *buf ) );
       
   892     
       
   893         if( err != KErrNone )
       
   894             {
       
   895             Cancel();
       
   896             
       
   897             if ( iProgressBar )
       
   898                 {
       
   899                 EndProgressDialog();
       
   900                 }
       
   901             // release the member in advance to avoid memory-consumed erupted when endless send Notes by Messaging.			
       
   902             ReleaseMemory();		  	
       
   903         
       
   904             User::LeaveIfError( err );
       
   905             }
       
   906         
       
   907         iFiles->AppendL(*iText);
       
   908  
       
   909         User::LeaveIfError( array->At(iCount).Open( iFs, iFiles->iSendFileName, EFileRead ) );
       
   910         imessageData->AppendAttachmentHandleL( array->At(iCount));
       
   911 		
       
   912         iCount++;
       
   913     
       
   914         CleanupStack::PopAndDestroy(); // buf
       
   915         }
       
   916 	
       
   917 	iStatus = KRequestPending;
       
   918 	SetActive();
       
   919 	TRequestStatus* status = &iStatus;
       
   920 	User::RequestComplete(status,KErrNone);
       
   921 	}
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // CNotepadDialogBase::CCreateAndAppendFiles::DialogDismissedL
       
   925 // -----------------------------------------------------------------------------
       
   926 //
       
   927 void CNotepadDialogBase::CCreateAndAppendFiles::DialogDismissedL(TInt /*aButtonId*/)
       
   928     
       
   929     {
       
   930     if( iCount < iTotalCount )
       
   931 	    {
       
   932 	    iAttaching = EFalse;
       
   933     	iCanceled = ETrue;	
       
   934 	    }
       
   935     }
       
   936 // -----------------------------------------------------------------------------
       
   937 // CNotepadDialogBase::CCreateAndAppendFiles::RunL
       
   938 // -----------------------------------------------------------------------------
       
   939 
       
   940 void CNotepadDialogBase::CCreateAndAppendFiles::RunL()
       
   941 	{
       
   942 	switch(iAttaching)
       
   943 		{
       
   944 		case ETrue:
       
   945 			StartAttachingL();
       
   946 			break;
       
   947 		case EFalse:
       
   948 			if (iProgressBar)
       
   949 				{
       
   950 				EndProgressDialog();
       
   951 				}
       
   952 			if(!iCanceled)
       
   953 				{
       
   954 			       iSendAppUi.CreateAndSendMessageL( iServiceUId, imessageData ); 
       
   955 			    }
       
   956 			    
       
   957 			iListDialog->ClearSaveOrMarkedListItemsL(!iCanceled );   
       
   958 			iCanceled = EFalse;
       
   959 			
       
   960 			// release the member in advance in case of memory-consumed erupted when endless send Notes by Messaging.	
       
   961 			ReleaseMemory();
       
   962 			
       
   963 			RFs fs;
       
   964 			User::LeaveIfError(fs.Connect());
       
   965 			CleanupClosePushL(fs);
       
   966 		    CFileMan* fileMan = CFileMan::NewL(fs);
       
   967 		    CleanupStack::PushL( fileMan );
       
   968 
       
   969 			TFileName path;
       
   970 			fs.PrivatePath(path);
       
   971 		   	fs.CreatePrivatePath(KDefaultDrive);
       
   972 		   	
       
   973 		   	path.Append(_L("*.*"));
       
   974 		   	TInt errorcode = fileMan->Delete( path, 0 );
       
   975 
       
   976 		  	CleanupStack::PopAndDestroy( fileMan );
       
   977 		  	CleanupStack::PopAndDestroy();
       
   978 		  	
       
   979   			
       
   980 			break;
       
   981 		}
       
   982 	}
       
   983 
       
   984 // -----------------------------------------------------------------------------
       
   985 // CNotepadDialogBase::CCreateAndAppendFiles::DoCancel
       
   986 // -----------------------------------------------------------------------------
       
   987 
       
   988 void CNotepadDialogBase::CCreateAndAppendFiles::DoCancel()
       
   989 	{
       
   990 	if (iProgressBar)
       
   991 		{
       
   992 		EndProgressDialog();
       
   993 		}
       
   994 
       
   995 	}
       
   996 
       
   997 // -----------------------------------------------------------------------------
       
   998 // CNotepadDialogBase::CCreateAndAppendFiles::PrepareToClose
       
   999 // -----------------------------------------------------------------------------
       
  1000 void CNotepadDialogBase::CCreateAndAppendFiles::ReleaseMemory()
       
  1001     {
       
  1002     if( iFiles )		
       
  1003         {
       
  1004         delete iFiles;
       
  1005         iFiles = NULL;
       
  1006         }
       
  1007 
       
  1008     if( iText )
       
  1009         {
       
  1010         delete iText;
       
  1011         iText = NULL;
       
  1012         }
       
  1013 
       
  1014     if( imessageData )
       
  1015         {	
       
  1016         delete imessageData;
       
  1017         imessageData = NULL;	
       
  1018         }
       
  1019 
       
  1020     if( array )
       
  1021         {
       
  1022         array->Reset();
       
  1023 
       
  1024         delete array;
       
  1025         array = NULL;
       
  1026         }
       
  1027 
       
  1028     iKeys.Close();
       
  1029     iFs.Close();	
       
  1030     }
       
  1031 
       
  1032 // End of File