commonuis/CommonUi/src/DocGameHandler.cpp
changeset 0 2f259fa3e83a
child 67 5f6e7f84c9d1
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of game data handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <s32mem.h>
       
    21 #include <s32file.h>
       
    22 #include "DocGameHandler.h"
       
    23 #include "pathinfo.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES  
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // ==================== LOCAL FUNCTIONS ====================
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 //
       
    46 CDocGameHandler::CDocGameHandler(
       
    47     const TDataType& aDataType,
       
    48     const TUid& aUid,
       
    49     CDocumentHandler* aDocDispatcher,
       
    50     TDocServiceMode aServiceMode ): 
       
    51         CDocDefaultHandler( aDataType, aUid, 
       
    52                             aDocDispatcher, aServiceMode )
       
    53     {
       
    54     }
       
    55 
       
    56 
       
    57 
       
    58 // EPOC default constructor can leave.
       
    59 void CDocGameHandler::ConstructL()
       
    60     {
       
    61     BaseConstructL();
       
    62     iGameId = KGameEngineUID;
       
    63     }
       
    64 
       
    65 // Two-phased constructor.
       
    66 CDocGameHandler* CDocGameHandler::NewL(    
       
    67     const TDataType& aDataType,
       
    68     const TUid& aUid,
       
    69     CDocumentHandler* aDocDispatcher,
       
    70     TDocServiceMode aServiceMode )
       
    71     {
       
    72     CDocGameHandler* self = new (ELeave) CDocGameHandler( aDataType, 
       
    73                                            aUid, aDocDispatcher, 
       
    74                                            aServiceMode );
       
    75        
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     CleanupStack::Pop();
       
    79 
       
    80     return self;
       
    81     }
       
    82     
       
    83 // Destructor
       
    84 CDocGameHandler::~CDocGameHandler()
       
    85     {
       
    86     
       
    87     } 
       
    88 
       
    89 void CDocGameHandler::ParseGameInfoFromFileL( const TDesC& aFilename )
       
    90     {
       
    91     RFile file;
       
    92     User::LeaveIfError( file.Open( iFs, aFilename, EFileRead ) );
       
    93     RFileReadStream reader( file );    
       
    94     iGameId = reader.ReadInt32L();
       
    95     reader.ReadInt8L();             // Data Type
       
    96     reader.ReadInt32L();            // Data Length
       
    97     TInt size = reader.ReadInt8L();// Size of Name String
       
    98     if ( size > 0 )
       
    99         {
       
   100         reader.ReadL( iDestFile, size );// Name String
       
   101         }
       
   102     reader.Close();
       
   103     file.Close();
       
   104     }
       
   105     
       
   106 // TODO: Does this method work, how to test this?    
       
   107 void CDocGameHandler::ParseGameInfoFromFileL( const RFile& aFile )
       
   108     {
       
   109     RFileReadStream reader( const_cast<RFile&>(aFile) );    
       
   110     iGameId = reader.ReadInt32L();
       
   111     reader.ReadInt8L();             // Data Type
       
   112     reader.ReadInt32L();            // Data Length
       
   113     TInt size = reader.ReadInt8L();// Size of Name String
       
   114     if ( size > 0 )
       
   115         {
       
   116         reader.ReadL( iDestFile, size );// Name String
       
   117         }
       
   118     reader.Close();
       
   119     }    
       
   120 
       
   121 void CDocGameHandler::ParseGameInfoFromBufL( const TDesC8& aBuffer )
       
   122     {   
       
   123     RDesReadStream reader( aBuffer );
       
   124     iGameId = reader.ReadInt32L();  // GameId
       
   125     reader.ReadInt8L();             // Data Type
       
   126     reader.ReadInt32L();            // Data Length
       
   127     TInt size = reader.ReadInt8L(); // Size of Name String
       
   128     if ( size > 0 )
       
   129         {
       
   130         reader.ReadL( iDestFile, size );// Name String
       
   131         }
       
   132     reader.Close();  
       
   133     }
       
   134 
       
   135 //
       
   136 // Changes iUid to "real". Changes iDataType to "real" value.
       
   137 //
       
   138 TInt CDocGameHandler::CheckGameDataTypeL( TInt32 aGameId )
       
   139     {
       
   140     TInt error = KErrNone;
       
   141     if ( aGameId > KMaxGameEngineDataID )
       
   142         {
       
   143         TBuf8<256> completedType = iDataType.Des8();                
       
   144         completedType.Append( _L("-") );
       
   145         completedType.AppendNumFixedWidth( aGameId, EHex, 8 );      
       
   146         iDataType = TDataType( completedType );
       
   147         }
       
   148     error = iApaLs->AppForDataType( iDataType, iUid );
       
   149     if ( error != KErrNone )
       
   150         {
       
   151         User::Leave( error );
       
   152         }
       
   153 
       
   154     if ( iUid.iUid == 0)
       
   155         {
       
   156         iUid.iUid = KGameEngineUID;
       
   157         }
       
   158 
       
   159     PopulateAppInfo();
       
   160     if ( iAppInfo.iFullName.Length() == 0 )
       
   161         {
       
   162         User::Leave( KMimeNotSupported );
       
   163         }
       
   164     return error;
       
   165     }
       
   166 
       
   167   
       
   168 void CDocGameHandler::PopulateAppInfo()
       
   169     {    
       
   170     CDocDefaultHandler::PopulateAppInfo( iUid );    
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CDocDefaultHandler::GetDataDirL( 
       
   175 //    const TDataType& aDataType, 
       
   176 //    const TUid& aUid, 
       
   177 //    TDes& aPath 
       
   178 //    TDes& aDataSize)
       
   179 // Get the data directory for the mime type
       
   180 // ---------------------------------------------------------
       
   181 //        
       
   182 TInt CDocGameHandler::GetDataDirL( 
       
   183     const TDataType& aDataType, 
       
   184     const TUid& aUid, 
       
   185     TDes& aPath,
       
   186     TInt aDataSize)
       
   187     {    
       
   188     if ( iUid.iUid != 0 )
       
   189         {
       
   190         if (CDocDefaultHandler::GetDataDirL( aDataType, aUid, aPath, aDataSize ) == KErrCancel)
       
   191             {
       
   192             return KErrCancel;
       
   193             }
       
   194         }
       
   195   
       
   196     if ( iSavedAsTemp )
       
   197         User::Leave( KMimeNotSupported );
       
   198 
       
   199     if ( iUid.iUid != KGameEngineUID )
       
   200         {
       
   201         aPath.Insert( 0,  PathInfo::GamesPath() );
       
   202         }
       
   203     TParsePtr parse( aPath );
       
   204     if ( parse.NamePresent() )                  // There is no '\' in the end.
       
   205         {
       
   206         aPath.Append( _L( "\\" ) );              // Append it. We need it!
       
   207         }
       
   208 
       
   209     return SetAndReturnStatus( KErrNone );
       
   210     }
       
   211 
       
   212 TInt CDocGameHandler::CopyOrMoveL( const TUint aAttr )
       
   213     {
       
   214     ParseGameInfoFromFileL( iSourceFile );
       
   215     User::LeaveIfError( CheckGameDataTypeL( iGameId ) );
       
   216     TInt error = CDocDefaultHandler::CopyOrMoveL( aAttr );
       
   217     if ( iUid.iUid == KGameEngineUID )
       
   218         {
       
   219         NotifyGameEngine( iUid );
       
   220         }
       
   221     HandleServerAppExit(0);
       
   222     return SetAndReturnStatus( error );
       
   223     }
       
   224     
       
   225 TInt CDocGameHandler::CopyHandleL( const RFile& aSourceFile, const TUint aAttr  )
       
   226     {
       
   227     ParseGameInfoFromFileL( aSourceFile );
       
   228     User::LeaveIfError( CheckGameDataTypeL( iGameId ) );
       
   229     TInt error = CDocDefaultHandler::CopyHandleL( aSourceFile, aAttr );
       
   230     if ( iUid.iUid == KGameEngineUID )
       
   231         {
       
   232         NotifyGameEngine( iUid );
       
   233         }
       
   234     HandleServerAppExit(0);
       
   235     return SetAndReturnStatus( error );
       
   236     }    
       
   237 
       
   238 TBool CDocGameHandler::IsViewerOperation( TDocOperation /*aOperation*/ )
       
   239     {
       
   240     return EFalse;
       
   241     }
       
   242 
       
   243     
       
   244 TInt CDocGameHandler::NotifyGameEngine( const TUid& /*aUid*/ )
       
   245     {
       
   246 
       
   247     // TODO: Is there needed some notify?
       
   248     return 0;
       
   249     }
       
   250     
       
   251 //  End of File