notepad/notepad1/LibSrc/NpdViewerDialog.cpp
branchRCL_3
changeset 48 bf573002ff72
parent 30 d68a4b5d5885
child 60 96907930389d
equal deleted inserted replaced
36:9c5b1510919f 48:bf573002ff72
    48 #include "NpdApi.h"
    48 #include "NpdApi.h"
    49 #include "NpdLib.h"
    49 #include "NpdLib.h"
    50 #include "NpdUtil.h"
    50 #include "NpdUtil.h"
    51 #include "NpdRichTextEditor.h"
    51 #include "NpdRichTextEditor.h"
    52 #include "NpdLibPanic.h"
    52 #include "NpdLibPanic.h"
    53 
       
    54 #include <csxhelp/nmake.hlp.hrh>
    53 #include <csxhelp/nmake.hlp.hrh>
       
    54 
       
    55 // CONSTANTS
       
    56 
       
    57 // when the file length is larger than this value, that need to load by steps 
       
    58 static const TInt KFileLengthNeedLoadBySteps = 1024 * 100;
       
    59 // the time value for interval to start the timer for close the notepad dialog 
       
    60 static const TUint KCloseNotepadDialogInterval = 500000; //microseconds
       
    61 // the time value for delay to start the timer for close the notepad dialog 
       
    62 static const TUint KCloseNotepadDialogDelay = 1; // microseconds
    55 
    63 
    56 // ============================ MEMBER FUNCTIONS ===============================
    64 // ============================ MEMBER FUNCTIONS ===============================
    57 
    65 
    58 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    59 // CNotepadViewerDialog::NewL
    67 // CNotepadViewerDialog::NewL
   115         iNotifier->StopListening();
   123         iNotifier->StopListening();
   116         delete iNotifier;        
   124         delete iNotifier;        
   117         }
   125         }
   118     delete iCenRepSession;
   126     delete iCenRepSession;
   119     iCenRepSession = NULL;
   127     iCenRepSession = NULL;
       
   128     delete iLoadFileAO;
       
   129     iLoadFileAO = NULL;
   120     }
   130     }
   121 
   131 
   122 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   123 // CNotepadViewerDialog::SetFileL
   133 // CNotepadViewerDialog::SetFileL
   124 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   228 //
   238 //
   229 EXPORT_C void CNotepadViewerDialog::LoadFileL()
   239 EXPORT_C void CNotepadViewerDialog::LoadFileL()
   230     {
   240     {
   231     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
   241     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
   232     __ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
   242     __ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
   233     iEditor->SetTextL(NULL);
   243     iEditor->SetTextL(NULL); 
   234     NotepadUtil::LoadFileL( *iCoeEnv, *iFilename, iGuessEncoding,
   244     NotepadUtil::LoadFileL( *iCoeEnv, *iFilename, iGuessEncoding,
   235         iEncoding, *(iEditor->Text()) );
   245         iEncoding, *(iEditor->Text()) );
   236     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength());
   246     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength());
   237     iEditor->HandleTextChangedL();
   247     iEditor->HandleTextChangedL();
   238     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
   248     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
   246 //
   256 //
   247 EXPORT_C void CNotepadViewerDialog::LoadFileL(RFile& aFile)
   257 EXPORT_C void CNotepadViewerDialog::LoadFileL(RFile& aFile)
   248     {
   258     {
   249     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
   259     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
   250     //__ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
   260     //__ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
       
   261    
       
   262     TInt fileSize(0);
       
   263     User::LeaveIfError( aFile.Size( fileSize ) );  
       
   264     if ( fileSize >= KFileLengthNeedLoadBySteps )
       
   265        {
       
   266        LoadFileByStepsL( aFile );
       
   267        return;
       
   268        }
       
   269     
   251     iEditor->SetTextL(NULL);
   270     iEditor->SetTextL(NULL);
   252    TBool error = NotepadUtil::LoadFileL( *iCoeEnv, aFile, iGuessEncoding,
   271     TBool error = NotepadUtil::LoadFileL( *iCoeEnv, aFile, iGuessEncoding,
   253         iEncoding, *(iEditor->Text()) );
   272         iEncoding, *(iEditor->Text()) );
   254     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength()); 
   273     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength()); 
   255     iEditor->HandleTextChangedL();
   274     iEditor->HandleTextChangedL();
   256     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
   275     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
   257     iAutoFinder->SetItemFinderObserverL( this );
   276     iAutoFinder->SetItemFinderObserverL( this );
   258     RefreshTitleL();
   277     RefreshTitleL();
   259     if( error != KErrNone)
   278     if( error != KErrNone)
   260         {
   279         {     
   261         
       
   262         HBufC* text = StringLoader::LoadLC(R_NOTEPAD_QTN_FILE_CORRUPTED);
   280         HBufC* text = StringLoader::LoadLC(R_NOTEPAD_QTN_FILE_CORRUPTED);
   263         CAknErrorNote* mErrorNote;
   281         CAknErrorNote* mErrorNote;
   264         mErrorNote = new (ELeave) CAknErrorNote( ETrue );
   282         mErrorNote = new (ELeave) CAknErrorNote( ETrue );
   265         mErrorNote->ExecuteLD(*text);
   283         mErrorNote->ExecuteLD(*text);
   266         CleanupStack::PopAndDestroy( text );
   284         CleanupStack::PopAndDestroy( text );
   267          
   285          
   268         iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );    
   286         iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );    
   269         if( !iPeriodicTimer->IsActive() )
   287         if( !iPeriodicTimer->IsActive() )
   270             {
   288             {
   271               iPeriodicTimer->Start( 1, 1000000/2, 
   289             iPeriodicTimer->Start( KCloseNotepadDialogDelay, KCloseNotepadDialogInterval, 
   272                                TCallBack( CNotepadViewerDialog::TimerCallbackL, this ) );
   290                            TCallBack( CNotepadViewerDialog::TimerCallbackL, this ) );
   273 	        }
   291             }
   274         }
   292         }
   275     }
   293     }
       
   294 
   276 
   295 
   277 // -----------------------------------------------------------------------------
   296 // -----------------------------------------------------------------------------
   278 // CNotepadViewerDialog::OpenFileL
   297 // CNotepadViewerDialog::OpenFileL
   279 // -----------------------------------------------------------------------------
   298 // -----------------------------------------------------------------------------
   280 //
   299 //
   829                         CEikMenuPaneItem::SData item = aMenuPane->ItemData(ENotepadCmdViewerSave);
   848                         CEikMenuPaneItem::SData item = aMenuPane->ItemData(ENotepadCmdViewerSave);
   830                         aMenuPane->DeleteMenuItem(ENotepadCmdViewerSave);
   849                         aMenuPane->DeleteMenuItem(ENotepadCmdViewerSave);
   831                 	    aMenuPane->AddMenuItemL(item, EFindItemMenuPlaceHolder);
   850                 	    aMenuPane->AddMenuItemL(item, EFindItemMenuPlaceHolder);
   832                         }
   851                         }
   833                     }
   852                     }
   834 
       
   835                 }
   853                 }
   836 
       
   837             iFindMenu->AddItemFindMenuL(iAutoFinder,aMenuPane,EFindItemMenuPlaceHolder,KNullDesC);
   854             iFindMenu->AddItemFindMenuL(iAutoFinder,aMenuPane,EFindItemMenuPlaceHolder,KNullDesC);
   838 
   855             
   839    			if(!FeatureManager::FeatureSupported(KFeatureIdHelp))
   856    			if(!FeatureManager::FeatureSupported(KFeatureIdHelp))
   840 				{
   857 				{
   841 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
   858 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
   842 				}
   859 				}
   843 
   860 
   899 //
   916 //
   900 EXPORT_C void CNotepadViewerDialog::CNotepadViewerDialog_Reserved()
   917 EXPORT_C void CNotepadViewerDialog::CNotepadViewerDialog_Reserved()
   901     {
   918     {
   902     }
   919     }
   903 
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // CNotepadViewerDialog::LoadFileByStepsL 
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 void CNotepadViewerDialog::LoadFileByStepsL(RFile& aFile)
       
   926     {
       
   927     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   928     //__ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
       
   929     iEditor->SetTextL(NULL); 
       
   930     
       
   931     // lanuch the progress bar
       
   932     CleanProgressDialogL();  
       
   933     iProgressDialogLoadfile = new( ELeave ) CAknProgressDialog(
       
   934       reinterpret_cast< CEikDialog** >( &iProgressDialogLoadfile ),
       
   935       EFalse );
       
   936     iProgressDialogLoadfile->SetCallback( this );
       
   937     iProgressDialogLoadfile->ExecuteLD( R_NOTEPAD_LOADFILE_PROGRESS_DIALOG );
       
   938     
       
   939     // start a active object to load file
       
   940     if ( iLoadFileAO ) 
       
   941         {
       
   942         delete iLoadFileAO;
       
   943         iLoadFileAO = NULL;
       
   944         }
       
   945     iLoadFileAO = CNotepadLoadFileAO::NewL( this,  *iCoeEnv, aFile, iGuessEncoding,
       
   946             iEncoding, *(iEditor->Text()) );
       
   947     
       
   948     if ( KErrNone != iLoadFileAO->StartLoadFile() )
       
   949         {
       
   950         ExitDialogOnTimerExpireL();
       
   951         }
       
   952     }
       
   953 
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CNotepadViewerDialog::CleanProgressDialogL()
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 void CNotepadViewerDialog::CleanProgressDialogL()
       
   960     {
       
   961     if ( iProgressDialogLoadfile )
       
   962         {
       
   963         iProgressDialogLoadfile->ProcessFinishedL();
       
   964         iProgressDialogLoadfile = NULL;
       
   965         }
       
   966     }
       
   967 
       
   968 // -----------------------------------------------------------------------------
       
   969 // CNotepadViewerDialog::DialogDismissedL
       
   970 // -----------------------------------------------------------------------------
       
   971 //
       
   972 void CNotepadViewerDialog::DialogDismissedL( TInt aButtonId )
       
   973     {
       
   974     if ( ( EAknSoftkeyCancel == aButtonId ) && iLoadFileAO )
       
   975         {
       
   976         iLoadFileAO->CancelLoadFile();
       
   977         }
       
   978     }
       
   979 
       
   980 // -----------------------------------------------------------------------------
       
   981 // CNotepadViewerDialog::NotifyCompletedL
       
   982 // -----------------------------------------------------------------------------
       
   983 //
       
   984 void CNotepadViewerDialog::NotifyCompletedL( TInt aErrCode )
       
   985     {  
       
   986  
       
   987     // load file is completed for one step
       
   988     if ( KErrStep == aErrCode )
       
   989         {
       
   990         iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength());
       
   991         iEditor->HandleTextChangedL();
       
   992         }
       
   993     // load file is completed 
       
   994     else if ( KErrNone == aErrCode ) 
       
   995         {
       
   996         CleanProgressDialogL(); 
       
   997         iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength());
       
   998         iEditor->HandleTextChangedL();
       
   999         iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
       
  1000         iAutoFinder->SetItemFinderObserverL( this );
       
  1001         RefreshTitleL();
       
  1002         }
       
  1003     // load file cancel
       
  1004     else if ( KErrCancel == aErrCode )
       
  1005         {
       
  1006         ExitDialogOnTimerExpireL();
       
  1007         }
       
  1008     // that occur error during load file
       
  1009     else
       
  1010         {
       
  1011         CleanProgressDialogL(); 
       
  1012         HBufC* text = StringLoader::LoadLC(R_NOTEPAD_QTN_FILE_CORRUPTED);
       
  1013         CAknErrorNote* mErrorNote;
       
  1014         mErrorNote = new (ELeave) CAknErrorNote( ETrue );
       
  1015         mErrorNote->ExecuteLD(*text);
       
  1016         CleanupStack::PopAndDestroy( text );
       
  1017         iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );        
       
  1018         if ( !iPeriodicTimer->IsActive() )
       
  1019             {
       
  1020             iPeriodicTimer->Start( KCloseNotepadDialogDelay, KCloseNotepadDialogInterval, 
       
  1021                                TCallBack( CNotepadViewerDialog::TimerCallbackL, this ) );
       
  1022             }
       
  1023         }
       
  1024   
       
  1025     }
       
  1026         
       
  1027 
   904 // End of File  
  1028 // End of File