commonuis/CommonUi/src/DocNotepadHandler.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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 text data handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "DocNotepadHandler.h"
       
    22 #include "DocSaver.h"
       
    23 
       
    24 #include "CommonUiNpdApiLoader.h"
       
    25 
       
    26 // CONSTANTS
       
    27 // Path and filename of wrapper dll.
       
    28 _LIT( KCommonUiNpdApiLoaderName, "z:\\sys\\bin\\commonuinpdapiloader.dll" );
       
    29 // Entry point for dynamically loaded dlls.
       
    30 const TInt KNpdApiDllEntryPoint = 1;
       
    31 
       
    32 // TYPE DEFINITIONS
       
    33 typedef TAny* (*NpdApiL)();
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // Two-phased constructor. 
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CDocNotepadHandler* CDocNotepadHandler::NewL(
       
    42     const TDataType& aDataType,
       
    43     const TUid& aUid,
       
    44     CDocumentHandler* aDocDispatcher )
       
    45     {
       
    46     CDocNotepadHandler *self = 
       
    47         CDocNotepadHandler::NewLC( aDataType, 
       
    48                                    aUid, aDocDispatcher );
       
    49     CleanupStack::Pop();
       
    50     return self;
       
    51     }
       
    52     
       
    53 // -----------------------------------------------------------------------------
       
    54 // Two-phased constructor. Leaves the contructed instance in to the 
       
    55 // clean up stack.
       
    56 // -----------------------------------------------------------------------------
       
    57 CDocNotepadHandler* CDocNotepadHandler::NewLC(
       
    58     const TDataType& aDataType,
       
    59     const TUid& aUid,
       
    60     CDocumentHandler* aDocDispatcher )
       
    61     {
       
    62     CDocNotepadHandler *self = 
       
    63         new( ELeave ) CDocNotepadHandler( aDataType, aUid, 
       
    64                                           aDocDispatcher, EDocOpenAndSave );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     return self;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // Epoc constructor    
       
    72 // -----------------------------------------------------------------------------
       
    73 void CDocNotepadHandler::ConstructL()
       
    74     {
       
    75     BaseConstructL();    
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------    
       
    79 // Destructor
       
    80 // -----------------------------------------------------------------------------
       
    81 CDocNotepadHandler::~CDocNotepadHandler()
       
    82     {
       
    83     delete iNpdApi;
       
    84     if( iNpdDllLoaded )
       
    85         {
       
    86         iNpdDll.Close();
       
    87         }
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // Constructor
       
    92 // -----------------------------------------------------------------------------
       
    93 CDocNotepadHandler::CDocNotepadHandler(
       
    94     const TDataType& aDataType,
       
    95     const TUid& aUid,
       
    96     CDocumentHandler* aDocDispatcher,
       
    97     TDocServiceMode aServiceMode ) : 
       
    98     CDocDefaultHandler( aDataType, aUid, aDocDispatcher, aServiceMode )
       
    99     {
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // TInt CDocNotepadHandler::CopyOrMoveL(..)
       
   105 // Copy the text file content to Notepad's storage.
       
   106 // -----------------------------------------------------------------------------    
       
   107 TInt CDocNotepadHandler::CopyOrMoveL( const TUint )
       
   108     {
       
   109     TInt error = KErrNone;
       
   110    	if( !iNpdDllLoaded )
       
   111         {
       
   112         LoadNpdApiL();
       
   113         }    
       
   114     iNpdApi->SaveFileAsMemoL( iSourceFile );
       
   115     
       
   116     // If this was MoveL-function, then we have to delete source file
       
   117     if (DocOperation() == EDocMove || DocOperation() == EDocSilentMove)
       
   118         { 
       
   119         error = iFileManager->Delete(iSourceFile, ETrue);        
       
   120         }
       
   121 
       
   122     // skip note if silentmove
       
   123     if (DocOperation() != EDocSilentMove)
       
   124         {
       
   125         AddResourcesL();
       
   126         HBufC* text;        
       
   127         text = StringLoader::LoadLC( 
       
   128             R_DOCUMENT_HANDLER_FILE_SAVED_TO, 
       
   129             this->iAppInfo.iCaption );                
       
   130         CDocSaver::ConfNoteL( text->Des(), ETrue );
       
   131         CleanupStack::PopAndDestroy(); // text
       
   132         RemoveResources();
       
   133         }
       
   134 
       
   135     HandleServerAppExit(0);
       
   136     return SetAndReturnStatus( error );
       
   137     }
       
   138     
       
   139 // -----------------------------------------------------------------------------
       
   140 // TInt CDocNotepadHandler::CopyHandleL(..)
       
   141 // Copy the text file content to Notepad's storage.
       
   142 // -----------------------------------------------------------------------------
       
   143 TInt CDocNotepadHandler::CopyHandleL( const RFile& aSourceFile, const TUint )
       
   144     {
       
   145     TInt error = KErrNone;
       
   146 	if( !iNpdDllLoaded )
       
   147         {
       
   148         LoadNpdApiL();
       
   149         }
       
   150     iNpdApi->SaveFileAsMemoL( aSourceFile );
       
   151             
       
   152     AddResourcesL();
       
   153     HBufC* text;        
       
   154     text = StringLoader::LoadLC( 
       
   155         R_DOCUMENT_HANDLER_FILE_SAVED_TO, 
       
   156         this->iAppInfo.iCaption );                                
       
   157     CDocSaver::ConfNoteL( text->Des(), ETrue );
       
   158     CleanupStack::PopAndDestroy(); // text
       
   159     RemoveResources();
       
   160     
       
   161     HandleServerAppExit(0);
       
   162     return SetAndReturnStatus( error );
       
   163     }    
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // TInt CDocNotepadHandler::LoadNpdApiL
       
   167 // Load Notepad Api.
       
   168 // -----------------------------------------------------------------------------
       
   169 void CDocNotepadHandler::LoadNpdApiL()
       
   170 	{	
       
   171 	// Memo saving dll loading.
       
   172     if( !iNpdDllLoaded )
       
   173         {        
       
   174         if( iNpdDll.Load( KCommonUiNpdApiLoaderName ) == KErrNone )
       
   175             {         
       
   176             iNpdDllLoaded = ETrue;
       
   177             // Request the entry function
       
   178             NpdApiL npdApi = (NpdApiL) iNpdDll.Lookup( KNpdApiDllEntryPoint );
       
   179             if( npdApi )
       
   180                 {                
       
   181                 // Create the class
       
   182                 iNpdApi = (CCommonUiNpdApiLoader*) (*npdApi)();
       
   183                 }
       
   184             }
       
   185         }
       
   186     // The wrapper failed to load.
       
   187     if ( !iNpdApi )
       
   188         {
       
   189         User::Leave( KErrNotFound );
       
   190         }    
       
   191 	}
       
   192 
       
   193 //  End of File