commonuis/CommonUi/src/DocDefaultHandler.cpp
changeset 0 2f259fa3e83a
child 18 fcdfafb36fe7
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:  Default Epoc-style content handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h>                // For NearestLanguageFile(..)
       
    20 #include <eikdoc.h>                 // CEikDocument
       
    21 #include <AknQueryDialog.h>         // CAknQueryDialog
       
    22 #include <StringLoader.h>           // For loading resource strings
       
    23 #include <stringresourcereader.h>   // CStringResourceReader
       
    24 #include <sysutil.h>                // For FFSSpaceBelowCriticalLevelL(..)
       
    25 #include <uri16.h>                  // For url handling.
       
    26 
       
    27 #include <avkon.rsg>                // Avkon ids
       
    28 #include <documenthandlerui.rsg>    // Resource ids
       
    29 
       
    30 #include "DocDefaultHandler.h"      // Class decration
       
    31 #include "DocSaver.h"               // Saver util
       
    32 #include "DocConstants.h"           // Documenthandler constants
       
    33 #include "DocResourceFile.h"        // CDocResourceFile
       
    34 
       
    35 #include <AiwGenericParam.h>        // Generic parameters
       
    36 
       
    37 #ifdef RD_MULTIPLE_DRIVE
       
    38 #include <CAknMemorySelectionDialogMultiDrive.h>
       
    39 #include <driveinfo.h>      //DriveInfo
       
    40 #include <AknCommonDialogsDynMem.h>
       
    41 #include <coemain.h>
       
    42 #include <rsfwmountman.h>
       
    43 #else
       
    44 #include "CAknMemorySelectionDialog.h" // CAknMemorySelectionDialog
       
    45 #endif
       
    46 
       
    47 #include "pathinfo.h"               // PathInfo
       
    48 #include <featmgr.h>                // FeatureManager
       
    49 
       
    50 #ifdef RD_CONTENTNOTIFICATION
       
    51 #include <contentnotification.hrh>
       
    52 #include <contentcreatedevent.h>
       
    53 #include <contentnotification.h>
       
    54 #endif
       
    55 
       
    56 #ifdef ENABLE_DRM
       
    57 #include <caf/caf.h>
       
    58 #include <Oma2Agent.h>
       
    59 #include <DcfEntry.h>               // CDcfEntry 
       
    60 #include <DcfRep.h>                 // CDcfRep
       
    61 #endif 
       
    62 
       
    63 #ifdef __KEEP_DRM_CONTENT_ON_PHONE
       
    64 #include <oem/distributablechecker.h>
       
    65 #endif
       
    66 
       
    67 #include <f32file.h>
       
    68 
       
    69 using namespace ContentAccess;
       
    70 _LIT( KFSName, "Fat" );
       
    71 
       
    72 // ================= LOCAL FUNCTIONS ========================
       
    73 LOCAL_C inline TBool NeedsToReplaceDcf2Extension( TDes& aFileName )
       
    74     {
       
    75     TParsePtrC ptr( aFileName );
       
    76     if ( ptr.ExtPresent() )
       
    77         {
       
    78         TPtrC ext( ptr.Ext() );
       
    79         if( !KOma2DcfExtensionAudio().CompareF( ext ) ||
       
    80             !KOma2DcfExtensionVideo().CompareF( ext ) ||
       
    81             !KOma2DcfExtension().CompareF( ext ) )
       
    82             {
       
    83             // no need to replace extension.
       
    84             return EFalse;
       
    85             }
       
    86         }
       
    87     return ETrue;
       
    88     }
       
    89 
       
    90 // ================= MEMBER FUNCTIONS =======================
       
    91 
       
    92 // C++ default constructor can NOT contain any code, that
       
    93 // might leave.
       
    94 //
       
    95 CDocDefaultHandler::CDocDefaultHandler(    
       
    96     const TDataType& aDataType,
       
    97     const TUid& aUid,
       
    98     CDocumentHandler* aDocDispatcher,
       
    99     TDocServiceMode aServiceMode ) : 
       
   100         iApaLs( aDocDispatcher->ApaLs() ),
       
   101         iDataType( aDataType ),
       
   102         iDocDispatcher( aDocDispatcher ),
       
   103         iFileManager( NULL ),
       
   104         iSavedAsTemp( EFalse ),
       
   105         iServiceMode( aServiceMode ),
       
   106         iStatus( KErrNone ),
       
   107         iUid( aUid ),
       
   108         iOpenService( NULL ),
       
   109         iMMCSaveAllowed ( ETrue )
       
   110     {
       
   111     }
       
   112     
       
   113 // Destructor  
       
   114 //
       
   115 CDocDefaultHandler::~CDocDefaultHandler()
       
   116     {
       
   117     #ifdef _DEBUG        
       
   118     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::~CDocDefaultHandler"));
       
   119     #endif      
       
   120       
       
   121     iFs.Close();        // Close sessions
       
   122     
       
   123     if ( iOpenService )
       
   124     {
       
   125         delete iOpenService;
       
   126     }                            
       
   127 
       
   128     delete iFileManager; // Delete members  
       
   129     delete iAiwParams;
       
   130     delete iOutAiwParams;
       
   131     delete iMimeExtensions;
       
   132     delete iExtensions;
       
   133     delete iIdle;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // Two-phased constructor. 
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 CDocDefaultHandler* CDocDefaultHandler::NewL(
       
   141     const TDataType& aDataType,
       
   142     const TUid& aUid,
       
   143     CDocumentHandler* aDocDispatcher,
       
   144     TDocServiceMode aServiceMode )
       
   145     {
       
   146     CDocDefaultHandler * self = NewLC( aDataType, aUid, 
       
   147                                        aDocDispatcher, aServiceMode );
       
   148     CleanupStack::Pop();
       
   149     return self;
       
   150     }
       
   151     
       
   152 // ---------------------------------------------------------
       
   153 // Two-phased constructor. Leaves the contructed instance in to the 
       
   154 // clean up stack.
       
   155 // ---------------------------------------------------------
       
   156 //
       
   157 CDocDefaultHandler* CDocDefaultHandler::NewLC(
       
   158     const TDataType& aDataType,
       
   159     const TUid& aUid,
       
   160     CDocumentHandler* aDocDispatcher,
       
   161     TDocServiceMode aServiceMode )
       
   162     {
       
   163     CDocDefaultHandler* self = 
       
   164         new ( ELeave ) CDocDefaultHandler( aDataType, aUid, 
       
   165                                            aDocDispatcher, aServiceMode );
       
   166     CleanupStack::PushL( self );
       
   167     self->BaseConstructL();
       
   168     return self;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // Epoc contructor
       
   173 // ---------------------------------------------------------
       
   174 //  
       
   175 void CDocDefaultHandler::BaseConstructL()
       
   176     {       
       
   177     User::LeaveIfError( iFs.Connect() ); // Connect to servers                      
       
   178     iFileManager = CFileMan::NewL( iFs );// Construct a filemanager   
       
   179     PopulateAppInfo();    
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------
       
   183 // CDocDefaultHandler::SaveTempFileL()
       
   184 // Save the content to the correct directory. 
       
   185 // This method is used from CDocumentHandler::SaveTempFileL() 
       
   186 // and CDocumentHandler::SaveL()
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 TInt CDocDefaultHandler::SaveTempFileL( 
       
   190     const TDesC8& aContent, 
       
   191     const TUint aAttr,
       
   192     TDes& aFileName)
       
   193     {
       
   194     #ifdef _DEBUG        
       
   195     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveTempFileL(aContent, aAttr, aFileName) Called"));
       
   196     #endif 
       
   197 
       
   198     TInt error = KErrNone;              // Error code
       
   199 
       
   200     if ( aContent.Size() == 0 )         // Check if there is anything to save.
       
   201         {
       
   202         return SetAndReturnStatus( KNullContent );  
       
   203         }
       
   204 
       
   205     error = SaveChecksL(aContent);
       
   206     
       
   207     #ifdef _DEBUG        
       
   208     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveTempFileL: error=%d after filename checks."), error);
       
   209     #endif 
       
   210     if ( error == KErrNone )
       
   211         {              
       
   212         #ifdef _DEBUG        
       
   213         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveTempFileL: Trying to save the file..."));
       
   214         #endif 
       
   215         iFs.MkDirAll( iDestFile );
       
   216         
       
   217         RFile tempfile;
       
   218         User::LeaveIfError( tempfile.Replace( iFs, iDestFile, EFileShareAny | EFileWrite) );   
       
   219         
       
   220         HBufC* waitNoteText = HBufC::NewLC( KDocWaitNoteMaxLen );
       
   221         TPtr waitNoteTextPtr = waitNoteText->Des();  
       
   222         WaitNoteTextL( waitNoteTextPtr );              
       
   223         
       
   224         CDocAsyncSaver* asyncSaver = CDocAsyncSaver::NewLC();
       
   225         AddResourcesL();
       
   226         asyncSaver->WriteToFileL(
       
   227             aContent, 
       
   228             tempfile, 
       
   229             waitNoteTextPtr );
       
   230         RemoveResources();
       
   231         User::LeaveIfError( asyncSaver->Status().Int() );
       
   232         CleanupStack::PopAndDestroy( 2 ); // asyncSaver, waitNoteTextPtr
       
   233 
       
   234         User::LeaveIfError( tempfile.SetAtt( aAttr, 0 ) );
       
   235         tempfile.Close();
       
   236         
       
   237         // Put filename to aFileName
       
   238         aFileName.Copy(iDestFile);
       
   239 
       
   240         #ifdef _DEBUG        
       
   241         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveTempFileL: File %S saved and closed!"), &iDestFile);
       
   242         #endif 
       
   243         }
       
   244 
       
   245     return SetAndReturnStatus( error );
       
   246 
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CDocDefaultHandler::SaveChecksL()
       
   251 // This method is called from SaveTempFileL.
       
   252 // Check disk space for file and generate filename.
       
   253 // ---------------------------------------------------------
       
   254 //
       
   255 TInt CDocDefaultHandler::SaveChecksL(const TDesC8& aContent)
       
   256     {
       
   257     TInt error = KErrNone;   
       
   258     if (GenerateFileNameL( iUid, iDestFile, iDataType, aContent.Length() ) == KErrCancel)
       
   259         {
       
   260         return KUserCancel;
       
   261         }
       
   262         
       
   263     CheckDiskspaceL( aContent.Size() ); // Leave if not enough space to save.
       
   264     TBool done = EFalse;                // Try saving until done    
       
   265     do
       
   266         {
       
   267         TBool valid  = iFs.IsValidName( iDestFile );
       
   268         TBool exists = BaflUtils::FileExists( iFs, iDestFile );
       
   269 
       
   270         #ifdef _DEBUG        
       
   271         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveChecksL: Filename valid=%d"), valid);
       
   272         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SaveChecksL: Filename exists=%d"), exists);
       
   273         #endif 
       
   274 
       
   275         // If filename allready exists, generate new name without asking user 
       
   276         if ( exists || !valid )
       
   277             {
       
   278             GenerateTempFileNameL( iDestFile ,MaxNameLen() );
       
   279             }
       
   280         else
       
   281             {
       
   282             if ( error == KErrNone )
       
   283                 {
       
   284                 done = ETrue;
       
   285                 }
       
   286             else
       
   287                 {
       
   288                 User::Leave( SetAndReturnStatus( error ) );
       
   289                 }
       
   290             } // else
       
   291         }
       
   292     while ( !done ); 
       
   293     
       
   294     // If file is saved to temp place, DocumentHandler is responsible of deleting this file.
       
   295     if ( iSavedAsTemp ) 
       
   296         {
       
   297         iDocDispatcher->SetTempFile(iDestFile);
       
   298         }
       
   299 
       
   300     return error;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------    
       
   304 // CDocDefaultHandler::CopyChecksAndQueriesL()   
       
   305 // This method is called from CopyOrMoveL and CopyHandleL. 
       
   306 // Check disk space for file, generate filename and
       
   307 // and show save as query to user.
       
   308 // ---------------------------------------------------------    
       
   309 //
       
   310 TInt CDocDefaultHandler::CopyChecksAndQueriesL(TInt aDataSize)
       
   311     {
       
   312     TInt error = KErrNone;      // Error code
       
   313     
       
   314     #ifdef _DEBUG      
       
   315     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CopyChecksAndQueriesL: Enter, aDataSize = %d"), aDataSize);
       
   316     #endif
       
   317     
       
   318     if (GenerateFileNameL( iUid, iDestFile, iDataType, aDataSize) == KErrCancel)
       
   319         {
       
   320         return KUserCancel;
       
   321         }
       
   322     CheckDiskspaceL( aDataSize ); // Leave if not enough space to save.
       
   323     
       
   324     // Make destination directories
       
   325     error = iFs.MkDirAll( iDestFile );
       
   326     if ( error != KErrAlreadyExists && error != KErrNone )
       
   327         {
       
   328         User::Leave( error );   // Something unexpected happend
       
   329         }
       
   330     TBool done = EFalse;        // Try until done    
       
   331     do 
       
   332         {
       
   333         TBool valid  = iFs.IsValidName( iDestFile );
       
   334         TBool exists = BaflUtils::FileExists( iFs, iDestFile );
       
   335 
       
   336         #ifdef _DEBUG      
       
   337         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CopyChecksAndQueriesL: Filename = %S"), &iDestFile);
       
   338         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CopyChecksAndQueriesL: Filename valid=%d"), valid);
       
   339         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CopyChecksAndQueriesL: Filename exists=%d"), exists);
       
   340         #endif 
       
   341 
       
   342         // If filename allready exists, generate new name without asking 
       
   343         // user in case of SilentMove
       
   344         if ( (DocOperation() == EDocSilentMove) &&
       
   345              (exists || !valid) )
       
   346             {
       
   347             GenerateTempFileNameL( iDestFile ,MaxNameLen() );
       
   348             }
       
   349         else if ( !valid || (exists && !iSavedAsTemp) )
       
   350             {
       
   351             switch ( SaveAsQueryL( iDestFile ) )
       
   352                 {
       
   353                 case EDocFileCancelWrite:
       
   354                     done = ETrue;  
       
   355                     iDestFile.Zero();
       
   356                     error = KUserCancel;
       
   357                     HandleServerAppExit(0);
       
   358                     break;
       
   359                 case EDocFileOverWrite:
       
   360                     done = ETrue;
       
   361                     error = KErrNone;
       
   362                     break;
       
   363                 case EDocFileRenameNew:  
       
   364                     CheckFileNameExtensionL( iDestFile, iDataType );
       
   365                     break;
       
   366                 default:
       
   367                     User::Leave( SetAndReturnStatus( KErrUnknown ) );
       
   368                 } // switch
       
   369             } // if
       
   370         else  // if
       
   371             {
       
   372              done = ETrue;
       
   373              error = KErrNone;
       
   374             }
       
   375         } while ( !done );// while
       
   376     
       
   377     // If file is saved to temp place, DocumentHandler is responsible of deleting this file.
       
   378     if ( iSavedAsTemp ) 
       
   379         {
       
   380         iDocDispatcher->SetTempFile(iDestFile);
       
   381         }
       
   382         
       
   383     #ifdef _DEBUG      
       
   384     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CopyChecksAndQueriesL: Finished, error = %d"), error);
       
   385     #endif
       
   386         
       
   387     return error;
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------    
       
   391 // CDocDefaultHandler::CopyOrMoveL()    
       
   392 // Copy/Move file to the correct directory. DocOperation() 
       
   393 // tells what we do (copy/move/silentmove)
       
   394 // --------------------------------------------------------- 
       
   395 //   
       
   396 TInt CDocDefaultHandler::CopyOrMoveL( const TUint aAttr )
       
   397     {
       
   398     TInt error = KErrNone;      // Error code
       
   399     TEntry fileEntry;           // File entry
       
   400     
       
   401     IsMMCSaveAllowedL(iSourceFile);
       
   402     
       
   403     User::LeaveIfError( iFs.Entry( iSourceFile, fileEntry ) );
       
   404 
       
   405     error = CopyChecksAndQueriesL(fileEntry.iSize);
       
   406 
       
   407     if ( error == KErrNone )
       
   408         {             
       
   409         HBufC* waitNoteText = HBufC::NewLC( KDocWaitNoteMaxLen );
       
   410         TPtr waitNoteTextPtr = waitNoteText->Des();  
       
   411       
       
   412         CDocAsyncSaver* asyncSaver = CDocAsyncSaver::NewLC();
       
   413 		if (DocOperation() == EDocSilentMove)    
       
   414             {
       
   415             asyncSaver->MoveFileL(
       
   416                 iFileManager,
       
   417                 iSourceFile, 
       
   418                 iDestFile, 
       
   419                 ETrue,                 
       
   420                 waitNoteTextPtr,
       
   421                 ETrue );
       
   422             }
       
   423 		else 
       
   424 			{
       
   425 			WaitNoteTextL( waitNoteTextPtr );                
       
   426 			// This function is called either from MoveL or CopyL or SilentMoveL
       
   427 			if (DocOperation() == EDocMove)
       
   428     			{
       
   429            	 	AddResourcesL();
       
   430            	 	asyncSaver->MoveFileL(
       
   431            		   iFileManager,
       
   432            	 	   iSourceFile, 
       
   433        			   iDestFile, 
       
   434        			   ETrue,                
       
   435    		    	   waitNoteTextPtr,
       
   436           	 	   EFalse );
       
   437            	 	RemoveResources();
       
   438     			}
       
   439    		 	else
       
   440    		 		{
       
   441    		 		AddResourcesL();
       
   442             	asyncSaver->CopyFileL(
       
   443        		 		iFileManager,
       
   444        		 		iSourceFile, 
       
   445        		 		iDestFile, 
       
   446            			ETrue,                 
       
   447            	 		waitNoteTextPtr );
       
   448            		 RemoveResources();
       
   449            		 }
       
   450 			}
       
   451     
       
   452         error = asyncSaver->Status().Int();   
       
   453         User::LeaveIfError( error );
       
   454         User::LeaveIfError( iFileManager->Attribs( iDestFile, aAttr, 0, TTime( 0 ), 0 ) );
       
   455         if(asyncSaver->ShowDialog() && IsConfNoteAllowed())
       
   456             {
       
   457             HBufC* confNoteText = HBufC::NewLC( KDocConfNoteMaxLen );
       
   458             TPtr confNoteTextPtr = confNoteText->Des();  
       
   459             ConfirmationNoteTextL( confNoteTextPtr );  
       
   460             CDocSaver::ConfNoteL( confNoteTextPtr, ETrue );
       
   461             CleanupStack::PopAndDestroy( 1 ); // confNoteTextPtr
       
   462             }
       
   463         
       
   464         CleanupStack::PopAndDestroy( 2 ); // asyncSaver, waitNoteTextPtr
       
   465           
       
   466         // Notify MediaGallery that its content may have been changed
       
   467         TRAP_IGNORE(UpdateMediaGalleryIfNeededL());
       
   468     
       
   469         // Notify DCFRepository about new file
       
   470         // DcfRepository leaves if file is not-DRM file, so this call needs to be TRAPPED
       
   471         TRAP_IGNORE(UpdateDCFRepositoryL());
       
   472         }
       
   473 
       
   474     return SetAndReturnStatus( error );
       
   475     }
       
   476     
       
   477 // ---------------------------------------------------------    
       
   478 // CDocDefaultHandler::CopyHandleL()    
       
   479 // Copy file to the correct directory. 
       
   480 // --------------------------------------------------------- 
       
   481 //   
       
   482 TInt CDocDefaultHandler::CopyHandleL( const RFile& aSourceFile, const TUint aAttr )
       
   483     {
       
   484     TInt error = KErrNone;      // Error code    
       
   485     TInt fileSize;
       
   486     
       
   487     IsMMCSaveAllowedL(aSourceFile);
       
   488     
       
   489     User::LeaveIfError( aSourceFile.Size(fileSize) );
       
   490 
       
   491     error = CopyChecksAndQueriesL(fileSize);
       
   492 
       
   493     if ( error == KErrNone )
       
   494         {
       
   495         HBufC* waitNoteText = HBufC::NewLC( KDocWaitNoteMaxLen );
       
   496         TPtr waitNoteTextPtr = waitNoteText->Des();  
       
   497         WaitNoteTextL( waitNoteTextPtr );              
       
   498 
       
   499         CDocAsyncSaver* asyncSaver = CDocAsyncSaver::NewLC();
       
   500 
       
   501         AddResourcesL();
       
   502         asyncSaver->CopyFileL(
       
   503             iFileManager, 
       
   504             aSourceFile, 
       
   505             iDestFile, 
       
   506             ETrue, 
       
   507             waitNoteTextPtr );
       
   508         RemoveResources();
       
   509 
       
   510         error = asyncSaver->Status().Int();   
       
   511         User::LeaveIfError( error );
       
   512         User::LeaveIfError( iFileManager->Attribs( iDestFile, aAttr, 0, TTime( 0 ), 0 ) );       
       
   513         if(asyncSaver->ShowDialog() && IsConfNoteAllowed())
       
   514             {
       
   515             HBufC* confNoteText = HBufC::NewLC( KDocConfNoteMaxLen );
       
   516             TPtr confNoteTextPtr = confNoteText->Des();  
       
   517             ConfirmationNoteTextL( confNoteTextPtr );
       
   518             CDocSaver::ConfNoteL( confNoteTextPtr, ETrue );
       
   519             CleanupStack::PopAndDestroy( 1 ); // confNoteTextPtr
       
   520             }
       
   521         
       
   522         CleanupStack::PopAndDestroy( 2 ); // asyncSaver, waitNoteTextPtr
       
   523         
       
   524         // Notify MediaGallery that its content may have been changed
       
   525         TRAP_IGNORE(UpdateMediaGalleryIfNeededL());
       
   526     
       
   527         // Notify DCFRepository about new file
       
   528         // DcfRepository leaves if file is not-DRM file, so this call needs to be TRAPPED
       
   529         TRAP_IGNORE(UpdateDCFRepositoryL());
       
   530         }
       
   531 
       
   532     return SetAndReturnStatus( error );
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------
       
   536 // CDocDefaultHandler::SetSrcFileName()
       
   537 // Check the name and sets iSourceFile if ok.
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 TInt CDocDefaultHandler::SetSrcFileName( const TDesC& aFileName )
       
   541     {
       
   542     __ASSERT_DEBUG( 
       
   543         aFileName.Length() <= KMaxFileName,
       
   544         User::Panic( _L( "DocDefaultHandler" ), KErrBadName ) );
       
   545 
       
   546     if ( !iFs.IsValidName( aFileName ) )
       
   547         return SetAndReturnStatus( KErrBadName );
       
   548         
       
   549     iSourceFile = aFileName;
       
   550     return SetAndReturnStatus( KErrNone );
       
   551     }
       
   552 
       
   553 // ---------------------------------------------------------
       
   554 // CDocDefaultHandler::SetDestName()
       
   555 // Check the name and set iDestFile.
       
   556 // ---------------------------------------------------------
       
   557 //    
       
   558 TInt CDocDefaultHandler::SetDestName( const TDesC &aFilename )
       
   559     {
       
   560     TParse parse;
       
   561 
       
   562     parse.Set( aFilename, NULL, NULL );
       
   563     // drop possible drive letter and path.
       
   564     iDestFile.Copy( parse.NameAndExt() );        
       
   565 
       
   566     #ifdef _DEBUG        
       
   567     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SetDestName : iDestFile=%S"), &iDestFile);
       
   568     #endif 
       
   569 
       
   570     return SetAndReturnStatus( KErrNone );
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------
       
   574 // CDocDefaultHandler::SetRootPath()
       
   575 // Set root path of File which should be used.
       
   576 // ---------------------------------------------------------
       
   577 //    
       
   578 TInt CDocDefaultHandler::SetRootPath( const TDesC& aRootPath )
       
   579     {
       
   580     #ifdef _DEBUG        
       
   581     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SetRootPath : aRootPath=%S"), &aRootPath);
       
   582     #endif  
       
   583    
       
   584     TChar rootChar = aRootPath[0];
       
   585     TDriveList driveList; 
       
   586     TBool invalidRootPath = ETrue;
       
   587 
       
   588     if( iFs.DriveList( driveList ) == KErrNone )
       
   589         {
       
   590         for ( TInt i = 0; i < driveList.Length(); i++ )
       
   591             {
       
   592             TDriveInfo info;  
       
   593             if ( iFs.Drive( info, i ) == KErrNone &&
       
   594                  info.iType != EMediaNotPresent )
       
   595                 {
       
   596                 TChar driveChar;
       
   597                 RFs::DriveToChar( i, driveChar );
       
   598                 if ( driveChar == rootChar)
       
   599                     {
       
   600                 	invalidRootPath = EFalse;
       
   601                 	break;
       
   602                     }  
       
   603                 }
       
   604             }
       
   605         }
       
   606       
       
   607     if( !invalidRootPath )
       
   608         {
       
   609     	iRootPath.Copy( aRootPath ); 
       
   610     	return SetAndReturnStatus( KErrNone );
       
   611     	}
       
   612     else
       
   613         {
       
   614     	return KNotInitialized; 
       
   615     	}
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------
       
   619 // CDocDefaultHandler::AddToParamListL()
       
   620 // Add parameters (gives as parameter) to iAiwParams
       
   621 // ---------------------------------------------------------
       
   622 //    
       
   623 void CDocDefaultHandler::AddToParamListL(const CAiwGenericParamList& aParams)
       
   624     {
       
   625     // Clear previous parameters.
       
   626     if (!iAiwParams)
       
   627         {
       
   628         iAiwParams = CAiwGenericParamList::NewL();
       
   629         }
       
   630     iAiwParams->AppendL( aParams ); 
       
   631     }
       
   632 
       
   633 // ---------------------------------------------------------
       
   634 // CDocDefaultHandler::OutputParamsL()
       
   635 // Is this method needed?
       
   636 // ---------------------------------------------------------
       
   637 //    
       
   638 const CAiwGenericParamList* CDocDefaultHandler::OutputParamsL()
       
   639     { 
       
   640 /* TODO: How to get outputparams, or is these even needed?    
       
   641     if (iStore && iDictionary)
       
   642         {       
       
   643         delete iOutAiwParams;
       
   644         iOutAiwParams = NULL;
       
   645         iOutAiwParams = CAiwGenericParamList::NewL();
       
   646 
       
   647         RStoreReadStream stream;
       
   648         TStreamId id = iDictionary->At(KUidEmbedOutputStream);
       
   649 
       
   650         stream.OpenLC(*iStore, id);
       
   651         iOutAiwParams->InternalizeL(stream);
       
   652         CleanupStack::PopAndDestroy();  // stream
       
   653         }
       
   654 */
       
   655     return iOutAiwParams;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------
       
   659 // CDocDefaultHandler::SetDataType()
       
   660 // Set the data type (iDataType)
       
   661 // ---------------------------------------------------------
       
   662 //    
       
   663 void CDocDefaultHandler::SetDataType( const TDataType& aDataType )
       
   664     {
       
   665     iDataType = aDataType;
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------
       
   669 // CDocDefaultHandler::OpenFileEmbeddedL()
       
   670 // Calls Avkon Open File Service with file handle which should
       
   671 // be opened. Also UID of application which should be launched 
       
   672 // and iAiwParams is given as parameter. 
       
   673 // ---------------------------------------------------------
       
   674 //        
       
   675 TInt CDocDefaultHandler::OpenFileEmbeddedL(RFile& aFileHandle )
       
   676     {
       
   677     #ifdef _DEBUG        
       
   678     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::OpenFileEmbeddedL(aFileHandle) Called"));
       
   679     #endif 
       
   680 
       
   681     if ( iOpenService )
       
   682         {
       
   683         delete iOpenService;
       
   684         iOpenService = NULL;
       
   685         }
       
   686     
       
   687     iOpenService = CAknOpenFileService::NewL(iUid, aFileHandle, this, iAiwParams);
       
   688 
       
   689     #ifdef _DEBUG        
       
   690     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::OpenFileEmbeddedL: Returns")) ;
       
   691     #endif 
       
   692     return SetAndReturnStatus( KErrNone );  // If we're still here, everything is ok.
       
   693     } 
       
   694     
       
   695 // ---------------------------------------------------------
       
   696 // CDocDefaultHandler::OpenFileL( )
       
   697 // Calls RApaLsSession::StartDocument with file handle which 
       
   698 // should be launched on standalone. 
       
   699 // ---------------------------------------------------------
       
   700 //        
       
   701 TInt CDocDefaultHandler::OpenFileL(RFile& aFileHandle )
       
   702     {
       
   703     TThreadId id;
       
   704 
       
   705     User::LeaveIfError( iApaLs->StartDocument( aFileHandle, iDataType, id ) );
       
   706 
       
   707     // If client try to open embedded, but handler application supports only 
       
   708     // stand-alone open, then we need to notify exit instantly to avoid problems.
       
   709     if (DocOperation() == EDocOpenFileEmb)
       
   710         {
       
   711         if ( !iIdle )
       
   712             {
       
   713             iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
   714             }
       
   715 
       
   716         if ( !iIdle->IsActive() )
       
   717             {
       
   718             iIdle->Start( TCallBack( IdleNotifyServerAppExit, this ) );
       
   719             }
       
   720         }
       
   721     
       
   722     return SetAndReturnStatus( KErrNone );  // If we're still here, everything is ok.
       
   723     }
       
   724 
       
   725 // ---------------------------------------------------------
       
   726 // CDocDefaultHandler::IdleNotifyServerAppExit( )
       
   727 // Used for notifying server app exit with CIdle when
       
   728 // OpenFileEmbedded operation has actually opened stand-alone.
       
   729 // ---------------------------------------------------------
       
   730 //
       
   731 TInt CDocDefaultHandler::IdleNotifyServerAppExit( TAny* aParam )
       
   732     {
       
   733     static_cast<CDocDefaultHandler*>( aParam )->HandleServerAppExit(0);
       
   734     return EFalse;
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------
       
   738 // CDocDefaultHandler::HandleServerAppExit()
       
   739 // Delegates the exit signal to the listener registered for
       
   740 // DocumentHandler. Tries to delete temporary file. If it
       
   741 // fail we'll try again in the destructor.
       
   742 // ---------------------------------------------------------
       
   743 //    
       
   744 void CDocDefaultHandler::HandleServerAppExit( TInt aReason )
       
   745     {
       
   746     #ifdef _DEBUG        
       
   747     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::HandleServerAppExit : Exit notified."));
       
   748     #endif 
       
   749 
       
   750     if ( iExitNotified )
       
   751         return;
       
   752     
       
   753     if ( iDocDispatcher->ServerAppExitObserver() )
       
   754         {
       
   755          #ifdef _DEBUG        
       
   756          RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::HandleServerAppExit : Exit notification forwarded."));
       
   757         #endif 
       
   758         iDocDispatcher->ServerAppExitObserver()->HandleServerAppExit( aReason );
       
   759         }
       
   760         
       
   761     // We should base call in case of EAknCmdExit (to close client application)
       
   762     if (aReason == EAknCmdExit)
       
   763         {
       
   764         MAknServerAppExitObserver::HandleServerAppExit(aReason);
       
   765         }
       
   766         
       
   767     iExitNotified = ETrue;   
       
   768     SetAndReturnStatus( KErrNone );
       
   769     } 
       
   770 // ---------------------------------------------------------
       
   771 // CDocDefaultHandler::CanBeSavedToMmcL()
       
   772 // Check if there is possibility to save data to MMC
       
   773 // ---------------------------------------------------------
       
   774 //    
       
   775 TBool CDocDefaultHandler::CanBeSavedToMmcL()
       
   776     {       
       
   777     TBool retval = ETrue;
       
   778     TResourceReader reader;
       
   779     CDesCArrayFlat *exArr;
       
   780 
       
   781     #ifdef _DEBUG        
       
   782     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : Enter "));
       
   783     #endif 
       
   784 
       
   785     // Check if MMC feature is supported.
       
   786     if (!FeatureManager::FeatureSupported( KFeatureIdMmc ) )
       
   787         {
       
   788         return EFalse;
       
   789         }
       
   790 
       
   791     // Check if there is MMC card inserted & ok.
       
   792     if( !IsMMCLocked() ) // Request when unlocked.
       
   793         {            
       
   794         TDriveUnit unit(PathInfo::MemoryCardRootPath());
       
   795         TInt drive( unit );
       
   796         TVolumeInfo volumeInfo;
       
   797         TInt error(iFs.Volume(volumeInfo, drive));
       
   798         if ( error != KErrNone )
       
   799             {
       
   800             return EFalse;
       
   801             }
       
   802         }
       
   803         
       
   804     // It is not allowed to saving DRM protected file to MMC if this
       
   805     // feature flag is defined.
       
   806     #ifdef __KEEP_DRM_CONTENT_ON_PHONE
       
   807     #ifdef _DEBUG        
       
   808     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : (KEEP_DRM) Let's check if MMC save allowed."));
       
   809     #endif 
       
   810     if (!iMMCSaveAllowed)
       
   811         {
       
   812         #ifdef _DEBUG        
       
   813         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : (KEEP_DRM) iMMCSaveAllowed = EFalse"));
       
   814         #endif 
       
   815         return EFalse;
       
   816         }
       
   817     #endif
       
   818 
       
   819     // Check if this MIME type is listed as an exception which is never saved to MMC
       
   820     // card.
       
   821     CreateDocResourceReaderLC(reader, R_DOCUMENT_HANDLER_EXCEPTION_TYPES_LIST);
       
   822     exArr = reader.ReadDesCArrayL();    
       
   823     if (exArr)
       
   824         {
       
   825         TInt posTmp;
       
   826         if (exArr->Find(iDataType.Des(), posTmp) == 0)
       
   827             {
       
   828             retval = EFalse;
       
   829             }
       
   830         delete exArr;   
       
   831         }
       
   832     CleanupStack::PopAndDestroy(); // reader
       
   833 
       
   834     #ifdef _DEBUG        
       
   835     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : Finished and returns %d"), retval);
       
   836     #endif 
       
   837     return retval;
       
   838     }
       
   839 
       
   840 // ---------------------------------------------------------
       
   841 // CDocDefaultHandler::Status()
       
   842 // Get the iStatus
       
   843 // ---------------------------------------------------------
       
   844 //        
       
   845 TInt CDocDefaultHandler::Status() const
       
   846     {
       
   847     return iStatus;
       
   848     }
       
   849     
       
   850 // ---------------------------------------------------------
       
   851 // CDocDefaultHandler::GetPath()
       
   852 // Return the path where the content was saved/copied
       
   853 // ---------------------------------------------------------
       
   854 //        
       
   855 void CDocDefaultHandler::GetPath( TDes& aPath ) const
       
   856     {
       
   857     aPath.Copy( iDestFile );
       
   858     }
       
   859 
       
   860 // ---------------------------------------------------------
       
   861 // CDocDefaultHandler::CanOpen()
       
   862 // Is the handler capable of opening the mime type
       
   863 // ---------------------------------------------------------
       
   864 //         
       
   865 TBool CDocDefaultHandler::CanOpen() const 
       
   866     {
       
   867     return ( iServiceMode == EDocOpenOnly || iServiceMode == EDocOpenAndSave );
       
   868     }
       
   869     
       
   870 // ---------------------------------------------------------
       
   871 // CDocDefaultHandler::CanSave()
       
   872 // Is the handler capable of saving the mime type
       
   873 // ---------------------------------------------------------
       
   874 //        
       
   875 TBool CDocDefaultHandler::CanSave() const
       
   876     {
       
   877     return ( iServiceMode == EDocSaveOnly || iServiceMode == EDocOpenAndSave );
       
   878     }
       
   879 
       
   880 // ---------------------------------------------------------
       
   881 // CDocDefaultHandler::IsViewerOperation
       
   882 // Is the operation viewing (ETrue) or saving (EFalse) operation
       
   883 // ---------------------------------------------------------
       
   884 // 
       
   885 TBool CDocDefaultHandler::IsViewerOperation( TDocOperation aOperation )
       
   886     {
       
   887     switch ( aOperation )
       
   888         {
       
   889         case EDocOpenFile:
       
   890         case EDocOpenFileEmb:
       
   891             return ETrue;
       
   892         case EDocCopy:  
       
   893         case EDocMove:
       
   894         case EDocSilentMove:
       
   895         case EDocSave:
       
   896         case EDocSaveAs:
       
   897         case EDocSaveTemp:
       
   898             return EFalse;
       
   899         default:
       
   900             break;
       
   901         }
       
   902     return EFalse;
       
   903     }
       
   904 
       
   905 // ---------------------------------------------------------
       
   906 // CDocDefaultHandler::IsConfNoteAllowed()
       
   907 // Are we allowed to show confirmation note. In case of 
       
   908 // SilentMove and viewer operation we are not allowed to
       
   909 // show this note.
       
   910 // ---------------------------------------------------------
       
   911 // 
       
   912 TBool CDocDefaultHandler::IsConfNoteAllowed()
       
   913     {
       
   914     if (DocOperation() == EDocSilentMove || DocOperation() == EDocSaveTemp)
       
   915         {
       
   916         return EFalse;
       
   917         }
       
   918     else 
       
   919         {
       
   920         return ( !IsViewerOperation( DocOperation() ) );
       
   921         }
       
   922     }
       
   923 
       
   924 // ---------------------------------------------------------
       
   925 // CDocDefaultHandler::HideFileExtension()
       
   926 // Should we hide file extension. This should be overriden
       
   927 // in derived handlers if needed.
       
   928 // ---------------------------------------------------------
       
   929 // 
       
   930 TBool CDocDefaultHandler::HideFileExtension()
       
   931     {
       
   932     return EFalse;
       
   933     }
       
   934 #ifdef RD_MULTIPLE_DRIVE
       
   935 // ---------------------------------------------------------
       
   936 // CDocDefaultHandler::CanOnlyBeSavedToPhoneMemory()
       
   937 // check to see if the content can only be saved to Phone memory
       
   938 // ---------------------------------------------------------
       
   939 //
       
   940 TBool CDocDefaultHandler::CanOnlyBeSavedToPhoneMemoryL()
       
   941 	{
       
   942 	TBool retval = EFalse;
       
   943 	CDesCArrayFlat *exArr;
       
   944 	TResourceReader reader;
       
   945 	// It is not allowed to saving DRM protected file to MMC if this
       
   946     // feature flag is defined.
       
   947     #ifdef __KEEP_DRM_CONTENT_ON_PHONE
       
   948     #ifdef _DEBUG        
       
   949     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : (KEEP_DRM) Let's check if MMC save allowed."));
       
   950     #endif 
       
   951     if (!iMMCSaveAllowed)
       
   952         {
       
   953         #ifdef _DEBUG        
       
   954         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CanBeSavedToMmcL : (KEEP_DRM) iMMCSaveAllowed = EFalse"));
       
   955         #endif 
       
   956         return ETrue;
       
   957         }
       
   958     #endif
       
   959 
       
   960     // Check if this MIME type is listed as an exception which is never saved to MMC
       
   961     // card.
       
   962     CreateDocResourceReaderLC(reader, R_DOCUMENT_HANDLER_EXCEPTION_TYPES_LIST);
       
   963     exArr = reader.ReadDesCArrayL();    
       
   964     if (exArr)
       
   965         {
       
   966         TInt posTmp;
       
   967         if (exArr->Find(iDataType.Des(), posTmp) == 0)
       
   968             {
       
   969             retval = ETrue;
       
   970             }
       
   971         delete exArr;   
       
   972         }
       
   973     CleanupStack::PopAndDestroy(); // reader
       
   974     return retval;
       
   975 	}
       
   976 #endif
       
   977 
       
   978 #ifdef RD_MULTIPLE_DRIVE 
       
   979 // ---------------------------------------------------------
       
   980 // CDocDefaultHandler::GetSystemDrivesCount()
       
   981 // This should not be called when RD_MULTIPLE_DRIVE flag is diabled
       
   982 // ---------------------------------------------------------
       
   983 // 
       
   984 TInt CDocDefaultHandler::GetAvailableDrivesCountL()
       
   985 	{
       
   986 	TDriveList driveList;
       
   987 	TInt driveCount;
       
   988 	User::LeaveIfError(
       
   989 			DriveInfo::GetUserVisibleDrives(
       
   990 				iFs,
       
   991 	            driveList,
       
   992 	            driveCount ) );
       
   993 	
       
   994 	TInt driveListLen(driveList.Length());
       
   995 	TDriveNumber driveNumber;
       
   996 	driveCount=0;
       
   997 	TInt defaultPhoneMem( KErrNotFound );
       
   998     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, defaultPhoneMem );
       
   999 
       
  1000 	for( TInt i( 0 ); i < driveListLen; ++i )
       
  1001 		{
       
  1002 	    if ( driveList[ i ] ) // Non zero items are valid drives
       
  1003 	    	{
       
  1004 	    	driveNumber=TDriveNumber(i);
       
  1005 	    	if( defaultPhoneMem == driveNumber)
       
  1006 	    		driveCount++;
       
  1007 	    	else if(IsDriveAvailableL(driveNumber))
       
  1008 	    		driveCount++;
       
  1009 	       	}
       
  1010 	    }
       
  1011 	return driveCount;
       
  1012 	}
       
  1013 #endif
       
  1014 
       
  1015 #ifdef RD_MULTIPLE_DRIVE 
       
  1016 // ---------------------------------------------------------
       
  1017 // CDocDefaultHandler::IsDriveAvailable( const TDriveNumber & aDriveNumber)
       
  1018 // check drive availability ie is it available for user read/write operations
       
  1019 // This should not be called when RD_MULTIPLE_DRIVE flag is diabled
       
  1020 // ---------------------------------------------------------
       
  1021 // 
       
  1022 TBool CDocDefaultHandler::IsDriveAvailableL(const TInt & aDriveNumber)
       
  1023 	{
       
  1024 
       
  1025 	 TInt error;
       
  1026 	 TUint status=0;
       
  1027 	 TDriveInfo driveInfo;
       
  1028 	 TVolumeInfo volumeInfo;
       
  1029 	 error = DriveInfo::GetDriveStatus( iFs, aDriveNumber, status );
       
  1030 	 if( error )
       
  1031 		 {
       
  1032 	     return EFalse;
       
  1033 	     }
       
  1034 	 TFullName fsName;
       
  1035 	 error = iFs.FileSystemName( fsName, aDriveNumber );
       
  1036 	 if(error)
       
  1037 		 {
       
  1038 		 return EFalse;
       
  1039 		 }
       
  1040 	 // if not mounted, try to mount it.
       
  1041 	 if( fsName.Length() == 0 )
       
  1042 		 {
       
  1043 		 error = iFs.MountFileSystem( KFSName,aDriveNumber );
       
  1044 		 switch( error )
       
  1045 		 	{
       
  1046 	        case KErrNone:
       
  1047 	        case KErrLocked:
       
  1048 	        	{
       
  1049 	        	break;
       
  1050 	        	}
       
  1051 	        default:
       
  1052 		        {
       
  1053 		        return EFalse;
       
  1054 		        }
       
  1055 		    }
       
  1056 	     }
       
  1057 	 error = iFs.Drive( driveInfo, aDriveNumber );
       
  1058     if( error && ( error != KErrLocked ) )
       
  1059 		 {
       
  1060 	     return EFalse;
       
  1061 	     }
       
  1062 	 error = iFs.Volume( volumeInfo, aDriveNumber );
       
  1063     if( error && ( error != KErrLocked  ) ) // if memory card locked, don't return false
       
  1064 		 {
       
  1065 	     return EFalse;
       
  1066 		 }
       
  1067 	 if( driveInfo.iDriveAtt & KDriveAttRemote )
       
  1068 		 {
       
  1069 		 /*TChar driveLetter;
       
  1070 		 iFs.DriveToChar( aDriveNumber, driveLetter );
       
  1071 		 //This statement migth cause leave.. to be solve
       
  1072          CRsfwMountMan* mountMgr = CRsfwMountMan::NewL( 0, NULL );
       
  1073          CleanupStack::PushL( mountMgr );
       
  1074 		 TRsfwMountInfo mountInfo;
       
  1075 		 error = mountMgr->GetMountInfo( driveLetter, mountInfo );
       
  1076 		 CleanupStack::PopAndDestroy( mountMgr );
       
  1077 		 if( error )
       
  1078 			 {
       
  1079 		 	 return EFalse;
       
  1080 			 }*/
       
  1081 		 /* Always return EFlase for Remote drives*/
       
  1082 		 return EFalse;
       
  1083 		 }
       
  1084 	 return ETrue;
       
  1085 	}
       
  1086 #endif
       
  1087 // ---------------------------------------------------------
       
  1088 // CDocDefaultHandler::GetDataDirL( 
       
  1089 // Get the data directory for the mime type. Directory is
       
  1090 // saved finally to aPath.
       
  1091 // ---------------------------------------------------------
       
  1092 //        
       
  1093 TInt CDocDefaultHandler::GetDataDirL( 
       
  1094     const TDataType& aDataType, 
       
  1095     const TUid& /*aUid*/, 
       
  1096     TDes& aPath,
       
  1097     TInt aDataSize)
       
  1098     {    
       
  1099     TFileName path;                     // The path
       
  1100     TFileName folder;
       
  1101     
       
  1102     #ifdef _DEBUG        
       
  1103     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GetDataDirL : Enter "));
       
  1104     #endif 
       
  1105     
       
  1106     if ( DocOperation() == EDocSaveTemp )
       
  1107         {
       
  1108         User::LeaveIfError( SetTemporaryPathL( aDataSize, path, ETrue ) );
       
  1109         
       
  1110         // DocumentHandler will take care deleting this file
       
  1111         iSavedAsTemp = ETrue;
       
  1112         }
       
  1113     else if ( !IsViewerOperation( DocOperation() ) )
       
  1114         {
       
  1115         if (DocOperation() == EDocSilentMove)
       
  1116             {
       
  1117             TParsePtrC parse(iRootPath);
       
  1118             // If we try to save to MMC, let's check that it is allowed.
       
  1119             if( parse.Drive().CompareF( PathInfo::MemoryCardRootPath().Left(2) ) == 0 )
       
  1120                 {
       
  1121                 if ( !CanBeSavedToMmcL() )
       
  1122                     {
       
  1123                     #ifdef _DEBUG        
       
  1124                     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GetDataDir: Return ERROR, we are not allowed to save to MMC."));
       
  1125                     #endif 
       
  1126                     return KErrCancel;
       
  1127                     }
       
  1128                 }
       
  1129             path.Copy( iRootPath );
       
  1130             }
       
  1131 #ifdef RD_MULTIPLE_DRIVE 
       
  1132         else if( (!CanOnlyBeSavedToPhoneMemoryL())&&(1 < GetAvailableDrivesCountL()) )
       
  1133         	{
       
  1134         	TFileName defaultFolder;
       
  1135             CAknMemorySelectionDialogMultiDrive* dlg =NULL;
       
  1136 			// Remote drives are not shown in the list of available drives.. FIX for error ANAE-76S7KX
       
  1137 	        dlg = CAknMemorySelectionDialogMultiDrive::NewL(ECFDDialogTypeBrowse,0,EFalse, 
       
  1138 	        			AknCommonDialogsDynMem::EMemoryTypePhone | AknCommonDialogsDynMem::EMemoryTypeInternalMassStorage | AknCommonDialogsDynMem::EMemoryTypeMMCExternal);
       
  1139 		    CleanupStack::PushL( dlg );
       
  1140 			TDriveNumber driveNumber;
       
  1141 		    TBool result(dlg->ExecuteL(driveNumber,&path,&defaultFolder));// driveNumber );
       
  1142 			CleanupStack::PopAndDestroy( dlg );
       
  1143 			if (!result)
       
  1144 				{
       
  1145 		        SetAndReturnStatus( KErrCancel );
       
  1146 		        return KErrCancel;
       
  1147 		        }
       
  1148            }
       
  1149 #else  
       
  1150         else if ( CanBeSavedToMmcL() )
       
  1151             {
       
  1152             CAknMemorySelectionDialog::TMemory mem( CAknMemorySelectionDialog::EPhoneMemory);
       
  1153             AddResourcesL();
       
  1154             TFileName defaultFolder;
       
  1155             CAknMemorySelectionDialog* memoryDialog = CAknMemorySelectionDialog::NewL(
       
  1156                                                             ECFDDialogTypeSave,
       
  1157                                                             R_DOCHANDLER_MEMORY_SELECTION_DIALOG,
       
  1158                                                             EFalse );
       
  1159             CleanupStack::PushL( memoryDialog );    
       
  1160             
       
  1161             TBool result( memoryDialog->ExecuteL( mem, &path, &defaultFolder ) );
       
  1162             if (!result)
       
  1163                 {
       
  1164                 RemoveResources();
       
  1165                 CleanupStack::PopAndDestroy();  // memoryDialog
       
  1166                 SetAndReturnStatus( KErrCancel );
       
  1167                 return KErrCancel;
       
  1168                 }
       
  1169 
       
  1170             CleanupStack::PopAndDestroy();  // memoryDialog
       
  1171 
       
  1172             RemoveResources();
       
  1173             }
       
  1174         #endif
       
  1175         else 
       
  1176             {
       
  1177             path.Copy( PathInfo::PhoneMemoryRootPath() );
       
  1178             }
       
  1179 
       
  1180 		if ( iUid.iUid == 0 ) // Data type not supported
       
  1181 			{
       
  1182 			folder.Copy( PathInfo::OthersPath() );
       
  1183             }	
       
  1184 		else // Data type supported
       
  1185 			{						
       
  1186 			iMediaGalleryData = GetDefaultFolderForDataTypeL( aDataType, folder );       		
       
  1187         	if ( !iMediaGalleryData ) // Non-gallery files
       
  1188             	{                                    	
       
  1189             	if ( IsInstallerData() ) // Installable files.
       
  1190                 	{
       
  1191                 	folder.Copy( PathInfo::InstallsPath() );
       
  1192                 	}
       
  1193             	else              		// Other supported non-gallery files.
       
  1194                 	{
       
  1195                 	folder.Copy( PathInfo::OthersPath() );                    	
       
  1196                	 	}
       
  1197             	}
       
  1198             }
       
  1199         }
       
  1200     else
       
  1201         {
       
  1202         // do nothing
       
  1203         }
       
  1204 
       
  1205     if ( DocOperation() != EDocSaveTemp )
       
  1206         {
       
  1207         if (( folder.Length() == 0 ) || ( path.Length() == 0 ))
       
  1208             {
       
  1209             User::LeaveIfError(SetTemporaryPathL(aDataSize, path, EFalse));
       
  1210 
       
  1211             // DocumentHandler will take care deleting this file
       
  1212             iSavedAsTemp = ETrue;
       
  1213             }        
       
  1214         else
       
  1215             {
       
  1216             path.Append( folder );      
       
  1217             }
       
  1218         }
       
  1219     
       
  1220     TParsePtr parse( path );
       
  1221     if ( parse.NamePresent() )                  // There is no '\' in the end.
       
  1222         {
       
  1223         path.Append( _L( "\\" ) );              // Append it. We need it!
       
  1224         }
       
  1225 
       
  1226     aPath.Copy( path );
       
  1227     return SetAndReturnStatus( KErrNone );
       
  1228     }
       
  1229 
       
  1230 // ---------------------------------------------------------
       
  1231 // CDocDefaultHandler::QueryRenameL()
       
  1232 // Ask from the user if he wants to rename aName
       
  1233 // ---------------------------------------------------------
       
  1234 //      
       
  1235 TBool CDocDefaultHandler::QueryRenameL( const TDesC& aName )
       
  1236     {
       
  1237     TParsePtrC parse( aName );
       
  1238 
       
  1239     return RunQueryDialogL( R_DOCHANDLER_RENAME_QUERY,
       
  1240                             R_DOCUMENT_HANDLER_NAME_IN_USE_TEXT,
       
  1241                             HideFileExtension() ? 
       
  1242                             parse.Name(): 
       
  1243                             parse.NameAndExt() );
       
  1244     }
       
  1245 
       
  1246 // ---------------------------------------------------------
       
  1247 // CDocDefaultHandler::QueryOverWriteL()
       
  1248 // Ask from the user if he wants to overwrite aName
       
  1249 // ---------------------------------------------------------
       
  1250 //      
       
  1251 TBool CDocDefaultHandler::QueryOverWriteL( const TDesC& aName )
       
  1252     {
       
  1253     TParsePtrC parse( aName );
       
  1254     
       
  1255     return RunQueryDialogL( R_DOCHANDLER_OVERWRITE_QUERY,
       
  1256                             R_DOCUMENT_HANDLER_OVERWRITE_TEXT,
       
  1257                             HideFileExtension() ? 
       
  1258                             parse.Name(): 
       
  1259                             parse.NameAndExt() );
       
  1260     }
       
  1261 
       
  1262 // ---------------------------------------------------------
       
  1263 // CDocDefaultHandler::QueryNewNameL()
       
  1264 // Ask a new name for aName from the user.
       
  1265 // ---------------------------------------------------------
       
  1266 //      
       
  1267 TBool CDocDefaultHandler::QueryNewNameL( TFileName& aName, const TInt aMaxLen )
       
  1268     {
       
  1269     TBool cancel( EFalse );
       
  1270     TBool valid( EFalse );
       
  1271     CApaApplication::GenerateFileName( iFs, aName );
       
  1272     TParsePtr parse( aName );
       
  1273     HBufC* extension = HBufC::NewLC( parse.Ext().Length() );
       
  1274     extension->Des().Copy( parse.Ext() );
       
  1275     TFileName name;
       
  1276 
       
  1277     do 
       
  1278         {
       
  1279         if ( HideFileExtension() )
       
  1280             name.Copy( parse.Name() );
       
  1281         else
       
  1282             name.Copy( parse.NameAndExt() );
       
  1283         TInt len = Min( KMaxFileName - KLengthOfFileExtension - parse.DriveAndPath().Length(), 
       
  1284                         aMaxLen);
       
  1285         if ( HideFileExtension() )
       
  1286             {
       
  1287             len -= extension->Des().Length();
       
  1288             }
       
  1289         if ( len <= 0 )
       
  1290             User::Leave( KErrUnknown );
       
  1291 
       
  1292         if (name.Length() > len)
       
  1293             {
       
  1294             if ( HideFileExtension() )
       
  1295                 {
       
  1296                 name.SetLength( len );              
       
  1297                 }
       
  1298             else
       
  1299                 {
       
  1300                 name.SetLength( len - extension->Des().Length() );
       
  1301                 name.Append( *extension );
       
  1302                 }
       
  1303             }
       
  1304 
       
  1305         CAknTextQueryDialog* dlg = new( ELeave ) CAknTextQueryDialog( name );
       
  1306         dlg->SetMaxLength( len );    
       
  1307         if ( dlg->ExecuteLD( R_DOCHANDLER_NAME_QUERY_DIALOG ) ) 
       
  1308             {          
       
  1309             valid = iFs.IsValidName( name ) ;
       
  1310             if ( !valid )
       
  1311                 {
       
  1312                 CAknNoteDialog* note = new (ELeave) CAknNoteDialog(CAknNoteDialog::ENoTone, CAknNoteDialog::ELongTimeout);
       
  1313                 HBufC* noteText = NULL;
       
  1314                 noteText = StringLoader::LoadLC( R_DOCUMENT_HANDLER_ILLEGAL_CHARACTERS );
       
  1315                 note->PrepareLC( R_DOCUMENT_HANDLER_INFO_NOTE );
       
  1316                 note->SetTextPluralityL(EFalse);
       
  1317                 note->SetTextL( *noteText );
       
  1318                 note->RunLD();
       
  1319                 CleanupStack::PopAndDestroy(noteText);
       
  1320                 cancel = EFalse;
       
  1321                 }
       
  1322             else
       
  1323                 {
       
  1324                 aName.Copy( parse.DriveAndPath() );
       
  1325                 aName.Append( name );  
       
  1326                 if ( HideFileExtension() )
       
  1327                     aName.Append( extension->Des() );        
       
  1328                 cancel = EFalse;        
       
  1329                 }
       
  1330             }
       
  1331         else
       
  1332             {
       
  1333             cancel = ETrue;
       
  1334             }    
       
  1335         }
       
  1336         while ( !valid && !cancel );
       
  1337     CleanupStack::PopAndDestroy(); // extension
       
  1338     return !cancel;
       
  1339     }
       
  1340 
       
  1341 // ---------------------------------------------------------
       
  1342 // CDocDefaultHandler::GenerateTempFileNameL()
       
  1343 // Creates a new name (based on existing name) without asking anything from user.
       
  1344 // ---------------------------------------------------------
       
  1345 //      
       
  1346 void CDocDefaultHandler::GenerateTempFileNameL( TFileName& aName, const TInt aMaxLen )
       
  1347     {
       
  1348     TBool valid( EFalse );
       
  1349     CApaApplication::GenerateFileName( iFs, aName );
       
  1350     TParsePtr parse( aName );
       
  1351     HBufC* extension = HBufC::NewLC( parse.Ext().Length() );
       
  1352     extension->Des().Copy( parse.Ext() );
       
  1353     TFileName name;
       
  1354 
       
  1355     if ( HideFileExtension() )
       
  1356         name.Copy( parse.Name() );
       
  1357     else
       
  1358         name.Copy( parse.NameAndExt() );
       
  1359         
       
  1360     TInt len = Min( KMaxFileName - KLengthOfFileExtension - parse.DriveAndPath().Length(), aMaxLen);
       
  1361     if ( HideFileExtension() )
       
  1362         {
       
  1363         len -= extension->Des().Length();
       
  1364         }
       
  1365     if ( len <= 0 )
       
  1366         User::Leave( KErrUnknown );
       
  1367 
       
  1368     if (name.Length() > len)
       
  1369         {
       
  1370         if ( HideFileExtension() )
       
  1371             {
       
  1372             name.SetLength( len );              
       
  1373             }
       
  1374         else
       
  1375             {
       
  1376             name.SetLength( len - extension->Des().Length() );
       
  1377             name.Append( *extension );
       
  1378             }
       
  1379         }
       
  1380       
       
  1381     valid = iFs.IsValidName( name ) ;
       
  1382         
       
  1383     if ( !valid )
       
  1384         {
       
  1385         User::Leave( KErrUnknown );
       
  1386         }
       
  1387     else
       
  1388         {
       
  1389         aName.Copy( parse.DriveAndPath() );
       
  1390         aName.Append( name );  
       
  1391         if ( HideFileExtension() )
       
  1392             aName.Append( extension->Des() );           
       
  1393         }
       
  1394 
       
  1395     CleanupStack::PopAndDestroy(); // extension
       
  1396     }
       
  1397 
       
  1398 // ---------------------------------------------------------
       
  1399 // TCDocDefaultHandler::SaveAsQueryL()
       
  1400 // Run "save as" dialog chain.
       
  1401 // ---------------------------------------------------------
       
  1402 //      
       
  1403 TDocSaveAsResult CDocDefaultHandler::SaveAsQueryL( TFileName& aPath )
       
  1404     {    
       
  1405     AddResourcesL();
       
  1406     TDocSaveAsResult response = EDocFileCancelWrite;   
       
  1407 
       
  1408     TParsePtr parse( aPath );
       
  1409     
       
  1410     if ( IsFileWritableL( aPath ) )         // If the file is writable.
       
  1411         {                                   // If the user wants to overwrite.
       
  1412         if ( QueryOverWriteL( parse.NameAndExt() ) )
       
  1413             {
       
  1414             response = EDocFileOverWrite;   // Overwrite, please.
       
  1415             }
       
  1416         else
       
  1417             {
       
  1418             response = EDocFileRenameNew;   // Rename please.
       
  1419             }
       
  1420         }
       
  1421     else                                    // If the file is not writable.
       
  1422         {                                   // Ask if the user wants to rename.
       
  1423         if ( QueryRenameL( parse.NameAndExt() ) )
       
  1424             {
       
  1425             response = EDocFileRenameNew;   // Rename, please.
       
  1426             }
       
  1427         else
       
  1428             {
       
  1429             response = EDocFileCancelWrite; // User cancelled.
       
  1430             }
       
  1431         }
       
  1432     if ( response == EDocFileRenameNew )    // Ask the user to rename the file.
       
  1433         {
       
  1434         if ( !QueryNewNameL( aPath, MaxNameLen() ) )      // Run rename dialog.
       
  1435             {
       
  1436             response = EDocFileCancelWrite; // User cancelled.           
       
  1437             }
       
  1438         }       
       
  1439     RemoveResources();
       
  1440     return response;
       
  1441     }
       
  1442 
       
  1443 // ---------------------------------------------------------
       
  1444 // CDocDefaultHandler::RunQueryDialogL()
       
  1445 // Run CAknQueryDialog with given resources. 
       
  1446 // ---------------------------------------------------------
       
  1447 //         
       
  1448 TInt CDocDefaultHandler::RunQueryDialogL(
       
  1449     TInt aDialogTypeResID,
       
  1450     TInt aStringResID,
       
  1451     const TDesC& aFileName )
       
  1452     {
       
  1453     TInt response;
       
  1454     HBufC* promptPtr = NULL;
       
  1455     promptPtr = StringLoader::LoadL( aStringResID, aFileName );
       
  1456     CleanupStack::PushL( promptPtr );
       
  1457     TPtrC prompt( promptPtr->Des() );
       
  1458     CAknQueryDialog* dlg = CAknQueryDialog::NewL( );
       
  1459     dlg->SetPromptL(prompt);
       
  1460     dlg->PrepareLC(aDialogTypeResID);    
       
  1461     response = dlg->RunLD();
       
  1462     CleanupStack::PopAndDestroy(); // promptPtr
       
  1463     return response;
       
  1464     }
       
  1465     
       
  1466 // ---------------------------------------------------------
       
  1467 // CDocDefaultHandler::GenerateFileNameL()
       
  1468 // Try to generate a file name.
       
  1469 // 1. Try to find the handler app's default document name.
       
  1470 // 2. If failed, try to load DocHandler's document name. ("unnamed")
       
  1471 // 3. If still failed, use a hardcoded name
       
  1472 // ---------------------------------------------------------
       
  1473 //           
       
  1474 TInt CDocDefaultHandler::GenerateFileNameL( 
       
  1475     const TUid& aUid, 
       
  1476     TDes& aFileName, 
       
  1477     const TDataType& aDataType,
       
  1478     TInt aDataSize)
       
  1479     {
       
  1480     #ifdef _DEBUG        
       
  1481     TPtrC mimetype = aDataType.Des();        
       
  1482     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GenerateFileNameL( %x, %S, %S ) Called"), aUid.iUid, &aFileName, &mimetype);
       
  1483     #endif 
       
  1484 
       
  1485     TFileName path;
       
  1486     TParsePtr parse( aFileName );
       
  1487 
       
  1488     if ( parse.NamePresent() )
       
  1489         {
       
  1490             aFileName.Copy( parse.NameAndExt() );
       
  1491         }
       
  1492     else
       
  1493         {
       
  1494         TFileName resFileName;        
       
  1495 
       
  1496         // Find an application's resource file
       
  1497         if ( iAppInfo.iFullName.Length() > 0 )
       
  1498             {                                       
       
  1499             TParsePtr appParse( iAppInfo.iFullName );
       
  1500             resFileName.Copy( resourceaApps );       //"\resource\apps\" 
       
  1501             resFileName.Append( appParse.Name() );   //"\resource\apps\ap"
       
  1502             resFileName.Append( resExt );            //"\resource\apps\ap.rsc"
       
  1503             
       
  1504             CStringResourceReader* reader = NULL;
       
  1505             TRAPD( 
       
  1506                 error, 
       
  1507                 ( reader = CStringResourceReader::NewL( resFileName ) ) );
       
  1508             if ( error == KErrNone )
       
  1509                 {
       
  1510                 CleanupStack::PushL( reader );       // This is needed, it can leave!
       
  1511                 aFileName = reader->ReadResourceString( EDefaultNameResourceOffset );
       
  1512                 CleanupStack::PopAndDestroy();       // reader
       
  1513                 }
       
  1514             } 
       
  1515 
       
  1516         // Use the docHandler's (fall back) doc name            
       
  1517         if ( aFileName == errorStr || aFileName.Length() == 0 ) 
       
  1518             {                                                   
       
  1519             resFileName.Copy( KDocResourceFileName );
       
  1520             CStringResourceReader* reader = NULL;
       
  1521             TRAPD( 
       
  1522                 error, 
       
  1523                 ( reader = CStringResourceReader::NewL( resFileName ) ) );
       
  1524             if ( error == KErrNone )
       
  1525                 {
       
  1526                 __ASSERT_DEBUG (
       
  1527                     reader,
       
  1528                     User::Panic( _L( "DocDefaultHandler" ), KErrNoMemory ) );
       
  1529                 CleanupStack::PushL( reader );      // This is needed, it can leave!
       
  1530                 aFileName = reader->ReadResourceString( EDefaultNameResourceOffset );
       
  1531                 CleanupStack::PopAndDestroy();      // reader
       
  1532                 }
       
  1533             }
       
  1534         
       
  1535         if ( aFileName == errorStr || aFileName.Length() == 0 )
       
  1536             {
       
  1537             #ifdef _DEBUG        
       
  1538             User::Panic( _L( "DocumentHandler: CDocDefaultHandler::GenerateFileNameL: resource problem" ), KErrUnknown );
       
  1539             #endif 
       
  1540             aFileName.Copy( KDocFallBackName );
       
  1541             }
       
  1542         }
       
  1543 
       
  1544     CheckFileNameExtensionL( aFileName, aDataType );
       
  1545     if (GetDataDirL( iDataType, aUid, path, aDataSize ) == KErrCancel)
       
  1546         {
       
  1547         return KErrCancel;  
       
  1548         }
       
  1549     aFileName.Insert( 0, path );
       
  1550     
       
  1551     #ifdef _DEBUG        
       
  1552     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GenerateFileNameL exit, aFileName=\"%S\""), &aFileName);
       
  1553     #endif 
       
  1554 
       
  1555     return KErrNone;
       
  1556     }
       
  1557     
       
  1558 // ---------------------------------------------------------
       
  1559 // CDocDefaultHandler::CheckDiskspaceL()
       
  1560 // Always leave if no space left on flash
       
  1561 // ---------------------------------------------------------
       
  1562 //      
       
  1563 void CDocDefaultHandler::CheckDiskspaceL( TInt aBytes )
       
  1564     {
       
  1565     // If MoveL command used, we do not need any more space because
       
  1566     // Symbian API renames the file -> we can skip this check
       
  1567     if (DocOperation() == EDocMove || DocOperation() == EDocSilentMove)
       
  1568         {
       
  1569         return;
       
  1570         }
       
  1571 
       
  1572     if (iDestFile.FindF( PathInfo::PhoneMemoryRootPath() ) != KErrNotFound)
       
  1573         {
       
  1574         #ifdef _DEBUG        
       
  1575         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckDiskspaceL: Disk Space checked"));
       
  1576         #endif 
       
  1577         if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aBytes ) )
       
  1578             {
       
  1579             #ifdef _DEBUG        
       
  1580             RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckDiskspaceL: Leave with KErrDiskFull"));
       
  1581             #endif 
       
  1582             User::Leave( KErrDiskFull );
       
  1583             }
       
  1584         }
       
  1585     }
       
  1586 
       
  1587 // ---------------------------------------------------------
       
  1588 // CDocDefaultHandler::ReplaceExtension()
       
  1589 // Replace current extension at aName with extension given (eExt).
       
  1590 // ---------------------------------------------------------
       
  1591 //      
       
  1592 void CDocDefaultHandler::ReplaceExtension( TDes& aName, const TDesC& aExt )
       
  1593     {
       
  1594     #ifdef _DEBUG        
       
  1595     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::ReplaceExtension: Enter, aName =%S, aExt=%S"),&aName, &aExt);
       
  1596     #endif 
       
  1597     
       
  1598     TInt dotPos = aName.LocateReverse( '.' );
       
  1599     if ( dotPos != KErrNotFound )
       
  1600        {
       
  1601        aName.Delete( dotPos, aName.Length()- dotPos );
       
  1602        }
       
  1603     aName.Append( aExt );
       
  1604     }
       
  1605 
       
  1606 // ---------------------------------------------------------
       
  1607 // CDocDefaultHandler::AddRecourcesL()
       
  1608 // Calls CDocResourceFile::AddLC()
       
  1609 // ---------------------------------------------------------
       
  1610 //      
       
  1611 void CDocDefaultHandler::AddResourcesL()
       
  1612     {
       
  1613     CDocResourceFile::AddLC( KDocResourceFileName, iFs );
       
  1614     }
       
  1615 
       
  1616 // ---------------------------------------------------------
       
  1617 // CDocDefaultHandler::RemoveRecources()
       
  1618 // Calls CDocResourceFile::Remove()
       
  1619 // ---------------------------------------------------------
       
  1620 //  
       
  1621 void CDocDefaultHandler::RemoveResources()
       
  1622     {
       
  1623     CDocResourceFile::Remove();
       
  1624     }
       
  1625 
       
  1626 // ---------------------------------------------------------
       
  1627 // CDocDefaultHandler::CheckFileNameExtensionL()
       
  1628 // We should not have to do this. But some recognizers
       
  1629 // don't work as expected and for example browser may suggest wrong file
       
  1630 // extensions (such as .asp). 
       
  1631 // ---------------------------------------------------------
       
  1632 //       
       
  1633 void CDocDefaultHandler::CheckFileNameExtensionL(
       
  1634     TDes &aFileName,
       
  1635     const TDataType& aDataType )
       
  1636     {
       
  1637     #ifdef _DEBUG        
       
  1638     TPtrC mimetype = aDataType.Des();        
       
  1639     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckFileNameExtensionL: Enter, aFileName =%S, aDataType =%S"), &aFileName, &mimetype);
       
  1640     #endif 
       
  1641     
       
  1642     // Jad files should always have jad extension even proctected.
       
  1643     if ( aDataType.Des().FindF( KDocMimeJad ) != KErrNotFound )
       
  1644     	{
       
  1645     	// change extension to .jad
       
  1646     	TBuf<6> ext;
       
  1647         ext.Copy( KDocExtJad );         
       
  1648         ReplaceExtension( aFileName, ext );                    
       
  1649         return;            
       
  1650     	}
       
  1651     	
       
  1652     // If we have iSourceFile available, we check first that is file DCF file. 
       
  1653     // If it is, then we will use dcf file extensions, which override all other extensions.
       
  1654     if (iSourceFile.Length() > 0)
       
  1655         {
       
  1656         TInt ret = EFalse;
       
  1657         TBuf<6> ext;
       
  1658 
       
  1659 		CContent* content = NULL;
       
  1660         TRAPD(err,content = CContent::NewL( iSourceFile ));
       
  1661 
       
  1662 		if(err == KErrNone)
       
  1663 			{	
       
  1664 			CleanupStack::PushL(content);
       
  1665 			content->GetAttribute( ContentAccess::EIsProtected, ret  );
       
  1666 			if ( ret )
       
  1667 				{
       
  1668 				content->GetAttribute( EFileType, ret );
       
  1669             
       
  1670 				#ifdef _DEBUG             
       
  1671 				RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckFileNameExtensionL: GetAttribute called, ret =%d"), ret);
       
  1672 				#endif 
       
  1673     
       
  1674 				if ( ret == EOma1Dcf )
       
  1675 					{
       
  1676 					// change extension to .dcf
       
  1677 					ext.Copy( KOma1DcfExtension );         
       
  1678 					ReplaceExtension( aFileName, ext );            
       
  1679 					CleanupStack::PopAndDestroy();  // content
       
  1680 					return;            
       
  1681 					}
       
  1682 				else if ( ret == EOma2Dcf )
       
  1683 	                {
       
  1684 		            // change extension to .odf if not already .o4a, .o4v or .odf
       
  1685 			        ext.Copy( KOma2DcfExtension );
       
  1686 				    if ( NeedsToReplaceDcf2Extension( aFileName ) )
       
  1687 					    {
       
  1688 						ReplaceExtension( aFileName, ext );
       
  1689 	                    }
       
  1690 		            CleanupStack::PopAndDestroy();  // content
       
  1691 			        return;            
       
  1692 				    }
       
  1693 				}
       
  1694 			CleanupStack::PopAndDestroy();  // content
       
  1695 			}
       
  1696         }
       
  1697 
       
  1698     //if mime type=oma 2 dcf check extension separately
       
  1699     if ( aDataType.Des8().FindF( KOma2DcfContentType ) != KErrNotFound )
       
  1700         {
       
  1701         if ( NeedsToReplaceDcf2Extension( aFileName ) )
       
  1702             {
       
  1703             ReplaceExtension( aFileName, KOma2DcfExtension() );
       
  1704             }
       
  1705         }
       
  1706     else
       
  1707         {
       
  1708         if (!iMimeExtensions)
       
  1709             {
       
  1710             TResourceReader reader; 
       
  1711 
       
  1712             CreateDocResourceReaderLC(reader, R_EXTENSION_GUARANTEED_MIME_TYPES);
       
  1713             iMimeExtensions = reader.ReadDesCArrayL();  
       
  1714             CleanupStack::PopAndDestroy();  // reader
       
  1715 
       
  1716             CreateDocResourceReaderLC(reader, R_EXTENSION_GUARANTEED_EXTENSIONS);
       
  1717             iExtensions = reader.ReadDesCArrayL();  
       
  1718             CleanupStack::PopAndDestroy();  // reader
       
  1719             }   
       
  1720 
       
  1721         TInt position;
       
  1722         TFileName mimeType;
       
  1723         mimeType.Copy(aDataType.Des8());
       
  1724         if (!iMimeExtensions->Find(mimeType, position))
       
  1725             {
       
  1726         #ifdef _DEBUG             
       
  1727             RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckFileNameExtensionL: Founded from mapping table."));
       
  1728         #endif 
       
  1729             TBuf<6> ext = iExtensions->MdcaPoint( position );
       
  1730             ext.Insert(0, _L("."));
       
  1731             ReplaceExtension( aFileName, ext );
       
  1732             }
       
  1733         }
       
  1734     #ifdef _DEBUG             
       
  1735     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::CheckFileNameExtensionL: Finished"));
       
  1736     #endif          
       
  1737     }
       
  1738 
       
  1739 // ---------------------------------------------------------
       
  1740 // CDocDefaultHandler::IsFileInUse()
       
  1741 // Try to open file for writing. If it fails return EFalse. 
       
  1742 // If it succeeds close the file and return ETrue?
       
  1743 // ---------------------------------------------------------
       
  1744 //       
       
  1745 TBool CDocDefaultHandler::IsFileInUse( const TDesC& aFileName )
       
  1746     {
       
  1747     RFile file;
       
  1748     TInt error;
       
  1749     TBool retValue = EFalse;
       
  1750     error = file.Open( iFs, aFileName, EFileWrite );
       
  1751     if ( error == KErrInUse || error == KErrLocked )
       
  1752         {
       
  1753         retValue = ETrue;
       
  1754         }
       
  1755     file.Close();
       
  1756     return retValue;
       
  1757     }
       
  1758 
       
  1759 // ---------------------------------------------------------
       
  1760 // CDocDefaultHandler::IsFileWritableL()
       
  1761 // check if the file is read only or in use.
       
  1762 // ---------------------------------------------------------
       
  1763 //       
       
  1764 TBool CDocDefaultHandler::IsFileWritableL( const TDesC& aFileName )
       
  1765     {
       
  1766     TEntry fileEntry;    
       
  1767     TInt error = iFs.Entry( aFileName, fileEntry );
       
  1768     if ( error != KErrNone && error != KErrBadName )
       
  1769         {
       
  1770         User::Leave( error );
       
  1771         }
       
  1772     
       
  1773     if ( fileEntry.IsReadOnly() || IsFileInUse( aFileName ) ) 
       
  1774         {
       
  1775         return EFalse;
       
  1776         }
       
  1777     else
       
  1778         {
       
  1779         return ETrue;
       
  1780         }
       
  1781     }
       
  1782 
       
  1783 // ---------------------------------------------------------
       
  1784 // CDocDefaultHandler::SetAndReturnStatus()
       
  1785 // Set iStatus.
       
  1786 // ---------------------------------------------------------
       
  1787 //       
       
  1788 TInt CDocDefaultHandler::SetAndReturnStatus( TInt aErrorCode )
       
  1789     {
       
  1790     if (aErrorCode == KErrCancel)
       
  1791         {
       
  1792         iStatus = KErrNone;
       
  1793         }
       
  1794     else
       
  1795         {
       
  1796         iStatus = aErrorCode;
       
  1797         }
       
  1798     return iStatus;
       
  1799     }
       
  1800 
       
  1801 // ---------------------------------------------------------
       
  1802 // CDocDefaultHandler::DocOperation() const
       
  1803 // Return iOperation.
       
  1804 // ---------------------------------------------------------
       
  1805 //       
       
  1806 TDocOperation CDocDefaultHandler::DocOperation() const
       
  1807     {
       
  1808     return iDocDispatcher->DocOperation();
       
  1809     }
       
  1810     
       
  1811 // ---------------------------------------------------------
       
  1812 // CDocDefaultHandler::PopulateAppInfo()
       
  1813 // Construct iAppInfo with iUid.
       
  1814 // ---------------------------------------------------------
       
  1815 //       
       
  1816 void CDocDefaultHandler::PopulateAppInfo()
       
  1817     {
       
  1818     PopulateAppInfo( iUid );    
       
  1819     }
       
  1820     
       
  1821 // ---------------------------------------------------------
       
  1822 // CDocDefaultHandler::PopulateAppInfo()
       
  1823 // Construct iAppInfo.
       
  1824 // ---------------------------------------------------------
       
  1825 //      
       
  1826 void CDocDefaultHandler::PopulateAppInfo( const TUid& aUid )
       
  1827     {
       
  1828     TInt error = iApaLs->GetAppInfo( iAppInfo, aUid );    
       
  1829     if ( error != KErrNone )
       
  1830         {
       
  1831         // TODO: What happends if GetAppInfo fails?
       
  1832         }
       
  1833     }
       
  1834     
       
  1835 // ---------------------------------------------------------
       
  1836 // CDocDefaultHandler::MaxNameLen()
       
  1837 // Return max lenght of file name.
       
  1838 // ---------------------------------------------------------
       
  1839 //      
       
  1840 TInt CDocDefaultHandler::MaxNameLen()
       
  1841     {
       
  1842     return KMaxFileName;
       
  1843     }
       
  1844 
       
  1845 // ---------------------------------------------------------
       
  1846 // CDocDefaultHandler::ReverseSlashes()
       
  1847 // Reverses slashes at aString ('/' -> '\').
       
  1848 // ---------------------------------------------------------
       
  1849 //      
       
  1850 void CDocDefaultHandler::ReverseSlashes(TDes& aString)
       
  1851     {
       
  1852     TInt findPos = aString.Locate('/');
       
  1853     while (findPos != KErrNotFound)
       
  1854         {
       
  1855         aString.Replace(findPos, 1, _L("\\"));
       
  1856         findPos = aString.Locate('/');
       
  1857         }
       
  1858     }
       
  1859 
       
  1860 // ---------------------------------------------------------
       
  1861 // CDocDefaultHandler::IsParameterAlreadyInList()
       
  1862 // Check if given parameter is allready on iAiwParams.
       
  1863 // ---------------------------------------------------------
       
  1864 //    
       
  1865 TBool CDocDefaultHandler::IsParameterAlreadyInList(TGenericParamId aId)
       
  1866     {
       
  1867     if ( iAiwParams )
       
  1868         {
       
  1869         TInt index = 0;
       
  1870         iAiwParams->FindFirst(index, aId);
       
  1871         if (index!=KErrNotFound)
       
  1872             {
       
  1873             return ETrue;
       
  1874             }
       
  1875         }
       
  1876     return EFalse;
       
  1877     }
       
  1878 
       
  1879 // ---------------------------------------------------------
       
  1880 // CDocDefaultHandler::WaitNoteTextL
       
  1881 // Resolve wait note text.
       
  1882 // ---------------------------------------------------------
       
  1883 // 
       
  1884 void CDocDefaultHandler::WaitNoteTextL( TPtr& aTextPtr )
       
  1885     {
       
  1886     AddResourcesL();
       
  1887     HBufC* text;
       
  1888 	if(IsInstallerData())
       
  1889        	{
       
  1890        	text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_SAVING_INSTALLS_DIRECTORY );
       
  1891        	}
       
  1892     else if( iUid.iUid == 0 || !iMediaGalleryData )//KWmlcHandler == iUid.iUid ) 
       
  1893         {
       
  1894         text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_SAVING_OTHERS_DIRECTORY );
       
  1895         }
       
  1896     else
       
  1897         {
       
  1898         TApaAppCaption caption;
       
  1899         ResolveCaptionName( caption );
       
  1900         text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_SAVING_FILE_TO, caption );
       
  1901         }
       
  1902     aTextPtr.Copy( text->Des() );
       
  1903     CleanupStack::PopAndDestroy(); // text
       
  1904     RemoveResources();
       
  1905     }
       
  1906     
       
  1907 // ---------------------------------------------------------
       
  1908 // CDocDefaultHandler::ConfirmationNoteTextL
       
  1909 // Resolve confirmation note text.
       
  1910 // ---------------------------------------------------------
       
  1911 // 
       
  1912 void CDocDefaultHandler::ConfirmationNoteTextL( TPtr& aTextPtr  )
       
  1913     {
       
  1914     AddResourcesL();
       
  1915     HBufC* text;
       
  1916     TBuf<100> mime16;
       
  1917     mime16.Copy( iDataType.Des() );
       
  1918     
       
  1919 	if(IsInstallerData())
       
  1920     	{
       
  1921     	text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_SAVED_INSTALLS_DIRECTORY );
       
  1922     	}
       
  1923     else if( mime16.FindF(KMIMETypeSvg) != KErrNotFound 
       
  1924            || iUid.iUid == 0 || !iMediaGalleryData ) // Data type not supported.
       
  1925         {
       
  1926         text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_SAVED_OTHERS_DIRECTORY );
       
  1927         }
       
  1928     else
       
  1929         {
       
  1930         TApaAppCaption caption;
       
  1931         ResolveCaptionName( caption );
       
  1932         text = StringLoader::LoadLC( R_DOCUMENT_HANDLER_FILE_SAVED_TO, caption );
       
  1933         }
       
  1934     aTextPtr.Copy( text->Des() );
       
  1935     CleanupStack::PopAndDestroy(); // text
       
  1936     RemoveResources();
       
  1937     }
       
  1938 
       
  1939 
       
  1940 // ---------------------------------------------------------
       
  1941 // CDocDefaultHandler::ResolveCaptionName
       
  1942 // Resolve confirmation note text.
       
  1943 // ---------------------------------------------------------
       
  1944 // 
       
  1945 void CDocDefaultHandler::ResolveCaptionName( TApaAppCaption& aCaption )
       
  1946     {
       
  1947     if ( iMediaGalleryData || IsInstallerData() )
       
  1948         {
       
  1949         TBuf<100> mime16;
       
  1950         mime16.Copy( iDataType.Des() );
       
  1951         // Get app info for media gallery app or app manager.
       
  1952         TApaAppInfo appInfo;
       
  1953         TUid uid;
       
  1954         if( mime16.FindF( KMIMETypeImage ) != KErrNotFound )
       
  1955             {    	
       
  1956             uid = KPhotosUID3;
       
  1957             }
       
  1958         else if ( mime16.FindF(KMIMETypeVideo)!= KErrNotFound 
       
  1959             || mime16.FindF(KMIMETypeVideoReal)!= KErrNotFound 
       
  1960             || mime16.FindF(KMIMETypeVideoSdp)!= KErrNotFound )
       
  1961             {
       
  1962             uid = KVideoCenterAppUid;
       
  1963             } 
       
  1964         else if( mime16.FindF(KMIMETypeAudioMpeg)!= KErrNotFound 
       
  1965             || mime16.FindF(KMIMETypeAudioMp4)!= KErrNotFound )
       
  1966             {
       
  1967             uid = KMusicPlayerAppUid;
       
  1968             }
       
  1969         else if(mime16.FindF(KMIMETypeAudio)!= KErrNotFound )
       
  1970             {
       
  1971             uid = KFileManagerUID3;
       
  1972             }
       
  1973         else
       
  1974             {
       
  1975             uid = KAppManagerUID3;
       
  1976             }
       
  1977         TInt error = iApaLs->GetAppInfo( appInfo, uid );
       
  1978         if ( error == KErrNone )
       
  1979             {
       
  1980             aCaption = appInfo.iCaption;
       
  1981             }
       
  1982         }
       
  1983     else
       
  1984         {
       
  1985         aCaption = iAppInfo.iCaption;
       
  1986         }          
       
  1987     }
       
  1988 // ---------------------------------------------------------
       
  1989 // CDocDefaultHandler::GetDefaultFolderForDataTypeL()
       
  1990 // Get folder for given datatype. This info is get from
       
  1991 // documenthandlerui.rss file.
       
  1992 // ---------------------------------------------------------
       
  1993 // 
       
  1994 TBool CDocDefaultHandler::GetDefaultFolderForDataTypeL(const TDataType& aDataType, TDes& result)
       
  1995     {
       
  1996     #ifdef _DEBUG        
       
  1997     TPtrC mimetype = aDataType.Des();        
       
  1998     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GetDefaultFolderForDataTypeL: Enter, aDataType =%S"), &mimetype);
       
  1999     #endif 
       
  2000     
       
  2001     TResourceReader resReader;
       
  2002     CreateDocResourceReaderLC(resReader, R_DOCHANDLER_DEFAULT_PATH_ARRAY);
       
  2003 
       
  2004     TBuf<100> mime16;
       
  2005     mime16.Copy( aDataType.Des() );
       
  2006 
       
  2007     result.Zero();
       
  2008 
       
  2009     TInt count = resReader.ReadInt16();
       
  2010 
       
  2011     TBool found = EFalse;   
       
  2012     for (TInt i = 0; i < count; i++)
       
  2013         {
       
  2014         HBufC* mimetype = resReader.ReadHBufCL();
       
  2015         CleanupStack::PushL( mimetype );        
       
  2016         HBufC* path = resReader.ReadHBufCL();
       
  2017         CleanupStack::PushL( path );        
       
  2018 
       
  2019         if (mime16.FindF( *mimetype ) != KErrNotFound)
       
  2020             {
       
  2021             result.Copy( path->Des() );
       
  2022             found = ETrue;
       
  2023             }
       
  2024 
       
  2025         CleanupStack::PopAndDestroy( 2 );  // mimetype, path
       
  2026 
       
  2027         if (found)
       
  2028             {
       
  2029             break;
       
  2030             }
       
  2031         }
       
  2032 
       
  2033     CleanupStack::PopAndDestroy(); // resReader
       
  2034 
       
  2035     #ifdef _DEBUG             
       
  2036     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::GetDefaultFolderForDataTypeL: Finished, returns =%d"), found);
       
  2037     #endif 
       
  2038 
       
  2039     return found;
       
  2040     }
       
  2041 
       
  2042 // ---------------------------------------------------------
       
  2043 // CDocDefaultHandler::IsInstallerData()
       
  2044 // Check if application installer is handler application.
       
  2045 // ---------------------------------------------------------
       
  2046 // 
       
  2047 TBool CDocDefaultHandler::IsInstallerData() const
       
  2048     {
       
  2049     TUid uid;
       
  2050     HandlerAppUid(uid);
       
  2051     if (uid.iUid == KAppInstHandler)
       
  2052         {
       
  2053         return ETrue;
       
  2054         }
       
  2055     else
       
  2056         {
       
  2057         return EFalse;
       
  2058         }  
       
  2059     }
       
  2060 
       
  2061 // ---------------------------------------------------------
       
  2062 // CDocDefaultHandler::SetTemporaryPathL()
       
  2063 // Set temporary path to aPath. First choice to temporary 
       
  2064 // place is 
       
  2065 // -if we prefer private folder (aPrivate = ETrue) -> d:\[process_private_directory] 
       
  2066 // -if not any need where to save -> d:\system\temp, 
       
  2067 // Second choice is to save to c:\system\temp.
       
  2068 // ---------------------------------------------------------
       
  2069 // 
       
  2070 TInt CDocDefaultHandler::SetTemporaryPathL(TInt aDataSize, TDes& aPath, TBool aPrivate)
       
  2071     {    
       
  2072     #ifdef _DEBUG           
       
  2073     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::SetTemporaryPathL: Enter"));
       
  2074     #endif 
       
  2075     
       
  2076     //TDriveUnit unit(KDocDDriveRoot);
       
  2077     TDriveUnit unit(EDriveD);
       
  2078     TInt drive( unit );
       
  2079     TVolumeInfo volumeInfo;
       
  2080     TInt error(iFs.Volume(volumeInfo, drive));
       
  2081 
       
  2082     if (error == KErrNone)
       
  2083         {
       
  2084         if (volumeInfo.iFree >= aDataSize)
       
  2085             {
       
  2086             if (aPrivate)
       
  2087                 {
       
  2088                 // Get process privatepath     
       
  2089                 User::LeaveIfError( iFs.PrivatePath(aPath) );
       
  2090                     
       
  2091                 // Add used memory to beginning 
       
  2092                 aPath.Insert(0,unit.Name());
       
  2093                 }
       
  2094             else
       
  2095                 {
       
  2096                	// Set temp to drive D.
       
  2097                 aPath.Insert(0,KDocTempPath);
       
  2098                 aPath.Insert(0,unit.Name());
       
  2099                 }      
       
  2100             return KErrNone;
       
  2101             }
       
  2102         }  
       
  2103 
       
  2104     // Not enough space in drive D, try drive C instead
       
  2105     if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataSize ) )
       
  2106         {
       
  2107         return KErrDiskFull;
       
  2108         }
       
  2109 
       
  2110     // Set temp to drive C
       
  2111     aPath.Copy(KDocTempPath2);
       
  2112 
       
  2113     return KErrNone;
       
  2114     }
       
  2115 
       
  2116 // ---------------------------------------------------------
       
  2117 // CDocDefaultHandler::UpdateMediaGalleryIfNeededL()
       
  2118 // Calls MediaGallery Update method so that media gallery
       
  2119 // knows update its view.
       
  2120 // ---------------------------------------------------------
       
  2121 // 
       
  2122 void CDocDefaultHandler::UpdateMediaGalleryIfNeededL()
       
  2123     {
       
  2124     if (!iSavedAsTemp)
       
  2125         {  
       
  2126         #ifdef _DEBUG        
       
  2127         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::UpdateMediaGalleryIfNeededL: aFileName=\"%S\""), &iDestFile);
       
  2128         #endif 
       
  2129 #ifdef RD_CONTENTNOTIFICATION            
       
  2130         CContentNotification* notifier = CContentNotification::NewL();
       
  2131         CleanupStack::PushL( notifier );        
       
  2132         CContentNotificationEvent* event = CContentCreatedEvent::NewL( iDestFile );                    
       
  2133         CleanupStack::PushL( event );               
       
  2134         CArrayFixFlat<CContentNotificationEvent*>* eventArray;
       
  2135         eventArray = new CArrayFixFlat<CContentNotificationEvent*>(2);    	        	        
       
  2136         CleanupStack::PushL( eventArray );        
       
  2137         eventArray->AppendL( event );        
       
  2138         User::LeaveIfError( notifier->SendNotification( eventArray->Array() ) );
       
  2139         eventArray->Delete( 0 );
       
  2140         CleanupStack::PopAndDestroy( 3 ); // eventArray, event, notifier.
       
  2141 #endif        
       
  2142         }
       
  2143     }
       
  2144 
       
  2145 // ---------------------------------------------------------
       
  2146 // CDocDefaultHandler::UpdateDCFRepositoryL()
       
  2147 // Update saved file to DCFRepository  
       
  2148 // ---------------------------------------------------------
       
  2149 // 
       
  2150 void CDocDefaultHandler::UpdateDCFRepositoryL()
       
  2151     {
       
  2152 #ifdef ENABLE_DRM
       
  2153     CDcfEntry* dcf = NULL;
       
  2154     dcf = CDcfEntry::NewL();    
       
  2155     CleanupStack::PushL( dcf );
       
  2156     
       
  2157     CDcfRep* dcfRep = NULL;
       
  2158     dcfRep = CDcfRep::NewL();
       
  2159     CleanupStack::PushL( dcfRep );
       
  2160     
       
  2161     dcf->SetLocationL( iDestFile, 0 );    
       
  2162     dcfRep->UpdateL( dcf );
       
  2163     
       
  2164     CleanupStack::PopAndDestroy(2); // dcf, dcfRep
       
  2165 #endif
       
  2166     }
       
  2167 
       
  2168 
       
  2169 // ---------------------------------------------------------
       
  2170 // CDocDefaultHandler::HandlerAppUid()
       
  2171 // Returns handler application Uid.
       
  2172 // ---------------------------------------------------------
       
  2173 // 
       
  2174 void CDocDefaultHandler::HandlerAppUid(TUid& aUid) const
       
  2175     {
       
  2176     aUid = iUid;
       
  2177     }
       
  2178     
       
  2179 // ---------------------------------------------------------
       
  2180 // CDocDefaultHandler::DeleteFile()
       
  2181 // Utility method: Delete file given in parameter if possible.
       
  2182 // ---------------------------------------------------------
       
  2183 //       
       
  2184 void CDocDefaultHandler::DeleteFile(const TDesC& aFileName)
       
  2185     {
       
  2186     #ifdef _DEBUG  
       
  2187     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::DeleteFile: Trying to delete file %S "), &aFileName );
       
  2188     #endif   
       
  2189     
       
  2190     // Delete file, don't care about possible errors
       
  2191     TInt error = iFileManager->Delete( aFileName, 0 );
       
  2192     
       
  2193     if ( error == KErrNone ) 
       
  2194         {      
       
  2195         #ifdef _DEBUG        
       
  2196         RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::DeleteFile: Deleting succesful!"));
       
  2197         #endif      
       
  2198         }
       
  2199     }
       
  2200 
       
  2201 // ---------------------------------------------------------
       
  2202 // CDocDefaultHandler::IsMMCSaveAllowedL()
       
  2203 // Check if we are allowed to save MMC DRM content. Result
       
  2204 // is saved to iMMCSaveAllowed member variable.
       
  2205 // ---------------------------------------------------------
       
  2206 //
       
  2207 void CDocDefaultHandler::IsMMCSaveAllowedL(const TDesC& aSourceFile)
       
  2208     {
       
  2209 #ifndef __KEEP_DRM_CONTENT_ON_PHONE
       
  2210     iMMCSaveAllowed = ETrue;
       
  2211     (void)aSourceFile; // This is because of removing warning
       
  2212 #else
       
  2213     iMMCSaveAllowed = EFalse;   // paranoia
       
  2214     CDistributableChecker* distributableChecker = CDistributableChecker::NewL();
       
  2215     CleanupStack::PushL( distributableChecker );
       
  2216     TBool isProtected( ETrue );
       
  2217     TInt err(KErrNone);
       
  2218 
       
  2219     #ifdef _DEBUG
       
  2220     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::IsMMCSaveAllowedL : (KEEP_DRM) Filename version. Created CDistributableChecker.") );
       
  2221     #endif
       
  2222 
       
  2223     err = distributableChecker->Check( aSourceFile, isProtected );
       
  2224 
       
  2225     #ifdef _DEBUG
       
  2226     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::IsMMCSaveAllowedL : (KEEP_DRM) isProtected =%d, err =%d."), isProtected, err);
       
  2227     #endif
       
  2228 
       
  2229     if ( err == KErrNone && isProtected == EFalse )
       
  2230         {
       
  2231         iMMCSaveAllowed = ETrue;
       
  2232         }
       
  2233 
       
  2234     CleanupStack::PopAndDestroy( distributableChecker );
       
  2235 #endif // __KEEP_DRM_CONTENT_ON_PHONE
       
  2236     }
       
  2237 
       
  2238 // ---------------------------------------------------------
       
  2239 // CDocDefaultHandler::IsMMCSaveAllowedL()
       
  2240 // Check if we are allowed to save MMC DRM content. Result
       
  2241 // is saved to iMMCSaveAllowed member variable.
       
  2242 // ---------------------------------------------------------
       
  2243 //
       
  2244 void CDocDefaultHandler::IsMMCSaveAllowedL(const RFile& aSourceFile)
       
  2245     {
       
  2246 
       
  2247 
       
  2248 #ifndef __KEEP_DRM_CONTENT_ON_PHONE
       
  2249     iMMCSaveAllowed = ETrue;
       
  2250     (void)aSourceFile; // This is because of removing warning
       
  2251 #else
       
  2252     iMMCSaveAllowed = EFalse;   //paranoia
       
  2253     CDistributableChecker* distributableChecker = CDistributableChecker::NewL();
       
  2254     CleanupStack::PushL( distributableChecker );
       
  2255     TBool isProtected( ETrue );
       
  2256     TInt err(KErrNone);
       
  2257 
       
  2258     #ifdef _DEBUG
       
  2259     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::IsMMCSaveAllowedL : (KEEP_DRM) Filehandle version. Created CDistributableChecker.") );
       
  2260     #endif
       
  2261 
       
  2262     RFile& source = const_cast<RFile&>(aSourceFile);    // not nice, but needed to go between APIs
       
  2263     err = distributableChecker->Check( source, isProtected );
       
  2264 
       
  2265     #ifdef _DEBUG
       
  2266     RDebug::Print( _L("DocumentHandler: CDocDefaultHandler::IsMMCSaveAllowedL : (KEEP_DRM) isProtected =%d, err =%d."), isProtected, err);
       
  2267     #endif
       
  2268 
       
  2269     if ( err == KErrNone && isProtected == EFalse )
       
  2270         {
       
  2271         iMMCSaveAllowed = ETrue;
       
  2272         }
       
  2273 
       
  2274     CleanupStack::PopAndDestroy( distributableChecker );
       
  2275 #endif // __KEEP_DRM_CONTENT_ON_PHONE
       
  2276     }
       
  2277 
       
  2278 // ---------------------------------------------------------
       
  2279 // CDocDefaultHandler::CreateDocResourceReaderLC()
       
  2280 // Setup aReader (TResourceReader) for resource reading with 
       
  2281 // aResourceID. This method is because need to use DocumentHandler 
       
  2282 // services from server-side, where CCoeEnv is not available.
       
  2283 // ---------------------------------------------------------
       
  2284 //      
       
  2285 void CDocDefaultHandler::CreateDocResourceReaderLC(TResourceReader& aReader, TInt aResourceID)
       
  2286     {  
       
  2287     TFileName resourceFile(KDocResourceFileName);
       
  2288     BaflUtils::NearestLanguageFile( iFs, resourceFile );
       
  2289     
       
  2290     RResourceFile rfile;
       
  2291     rfile.OpenL( iFs, resourceFile ); 
       
  2292     CleanupClosePushL(rfile);             
       
  2293 
       
  2294     HBufC8* buffer = rfile.AllocReadL( (KRIMask & aResourceID) );
       
  2295     
       
  2296     CleanupStack::PopAndDestroy();  // rfile
       
  2297     CleanupStack::PushL(buffer);
       
  2298         
       
  2299     aReader.SetBuffer(buffer);
       
  2300     }
       
  2301 
       
  2302 // ---------------------------------------------------------
       
  2303 // CDocDefaultHandler::IsMMCLocked()
       
  2304 // Checks if Mmc card is currently locked.
       
  2305 // ---------------------------------------------------------
       
  2306 //  
       
  2307 TBool CDocDefaultHandler::IsMMCLocked()
       
  2308     {
       
  2309     TBool ret = EFalse;
       
  2310    
       
  2311     // Check if MMC mounted, mount if required
       
  2312     TInt err = TryMountMMC();
       
  2313 
       
  2314     if( !err )
       
  2315         {
       
  2316         TDriveInfo driveInfo;    
       
  2317         err = iFs.Drive( driveInfo, EDriveE );
       
  2318         if( !err ) 
       
  2319             {            
       
  2320             if( driveInfo.iMediaAtt & KMediaAttLocked )
       
  2321                 {
       
  2322                 ret = ETrue;  
       
  2323                 }
       
  2324             }
       
  2325         }
       
  2326         
       
  2327     return ret;
       
  2328     }
       
  2329 
       
  2330 // ---------------------------------------------------------
       
  2331 // CDocDefaultHandler::TryMountMMC()
       
  2332 // Mounts Mmc card.
       
  2333 // ---------------------------------------------------------
       
  2334 //      
       
  2335 TInt CDocDefaultHandler::TryMountMMC()
       
  2336     {
       
  2337     // Check if MMC mounted, mount if required
       
  2338 
       
  2339     TFullName fsname;
       
  2340     
       
  2341     // If can't use the drive, returns KErrNotFound
       
  2342     TInt err = iFs.FileSystemName( fsname, EDriveE );
       
  2343 
       
  2344     if ( !err )
       
  2345         {
       
  2346         // MMC found. Checking if it is mounted
       
  2347         if ( fsname.Length( ) == 0 )
       
  2348             {
       
  2349             // Returns KErrLocked, if card locked and password not in store
       
  2350             err = iFs.MountFileSystem( KFSName, EDriveE );                        
       
  2351             }
       
  2352         }
       
  2353     return err;
       
  2354     }    
       
  2355 //  End of File