simpsyconfigurator/src/simpsyfileselectormodel.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 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:  List-box model class for Simulation PSY file selector dialog.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <eikappui.h>
       
    21 #include <eikenv.h>
       
    22 #include <eikapp.h>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "simpsyfileselectormodel.h"
       
    26 
       
    27 // CONSTANT DEFINTION
       
    28 const TInt KSimPsyBufferSize = 128;
       
    29 const TInt KSimPsyFileIconId = 0;
       
    30 _LIT( KNmeaFilePath1,"\\system\\data\\" );
       
    31 _LIT( KNmeaFilePath2,"\\data\\SimFile\\" );
       
    32 _LIT( KSPSFileExtension, ".SPS");
       
    33 _LIT( KNMEAFileExtension, ".NME");
       
    34 
       
    35 // ========================= MEMBER FUNCTIONS ================================
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CSimPsyFileSelectorModel::CSimPsyFileSelectorModel
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CSimPsyFileSelectorModel::CSimPsyFileSelectorModel()
       
    42     {
       
    43     // C++ Default constructor. No allocations or functions which can Leave
       
    44     // should be called from here.
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CSimPsyFileSelectorModel::~CSimPsyFileSelectorModel
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CSimPsyFileSelectorModel::~CSimPsyFileSelectorModel()
       
    52     {
       
    53     // C++ Destructor. Free all resources associated with this class.
       
    54     
       
    55     // Delete the MdcaPoint buffer
       
    56     delete iBuffer;
       
    57     
       
    58     // Reset and close the file name array
       
    59     iFileNameArray.Reset();
       
    60     iFileNameArray.Close();
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // void CSimPsyFileSelectorModel::ConstructL
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CSimPsyFileSelectorModel::ConstructL()
       
    68     {
       
    69     // Create the Buffer for packing the MdcaPoint
       
    70     iBuffer = HBufC16::NewL( KSimPsyBufferSize );
       
    71     
       
    72     TRAP_IGNORE( AppendFileL( KNmeaFilePath2 ));    
       
    73 	TRAP_IGNORE( AppendFileL( KNmeaFilePath1 ));           
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSimPsyFileSelectorModel* CSimPsyFileSelectorModel::NewL
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CSimPsyFileSelectorModel* CSimPsyFileSelectorModel::NewL()
       
    81     {
       
    82     CSimPsyFileSelectorModel* self = new ( ELeave ) CSimPsyFileSelectorModel();
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85     CleanupStack::Pop( self );
       
    86     return self;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // TPtrC CSimPsyFileSelectorModel::SimulationFileNameL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 TPtrC CSimPsyFileSelectorModel::SimulationFileNameL( TInt aIndex )
       
    94 	{   	
       
    95 	if ( aIndex < 0 || aIndex > ( iFileNameArray.Count() - 1 ))
       
    96 	    {
       
    97 	    User::Leave( KErrArgument );
       
    98 	    }
       
    99 	return ( iFileNameArray[ aIndex ]);
       
   100 	}
       
   101 	
       
   102 // ---------------------------------------------------------------------------
       
   103 // TInt CSimPsyFileSelectorModel::MdcaCount
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 TInt CSimPsyFileSelectorModel::MdcaCount() const
       
   107     {
       
   108     return iFileNameArray.Count();    	
       
   109     }
       
   110     
       
   111 // ---------------------------------------------------------------------------
       
   112 // TPtrC16 CSimPsyFileSelectorModel::MdcaPoint
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TPtrC16 CSimPsyFileSelectorModel::MdcaPoint( TInt aIndex ) const
       
   116     {            
       
   117     // Pack the contents into the Buffer. We dont have to re-allocate the buffer
       
   118     // everytime because the length of the name field is restricted in the
       
   119     // Location Centre Registration API
       
   120 		    
       
   121     // Tabulator Defintion
       
   122     _LIT( KTab, "\t" );
       
   123     
       
   124     // Create formatted item string.
       
   125     // list_single_large_pane:
       
   126     // list item string format: "0\tTextLabel"
       
   127     // where 0 is an index to icon array
       
   128 	TPtr16	buf( iBuffer->Des());
       
   129 	buf.Zero();
       
   130 	
       
   131 	// Append the Icon Index
       
   132 	buf.AppendNum( KSimPsyFileIconId );
       
   133 	
       
   134 	// Append the Tab Key
       
   135 	buf.Append( KTab );
       
   136 	
       
   137 	// Append only the file name without the full path.
       
   138     TParsePtrC parsedEntry( iFileNameArray[ aIndex ] );
       
   139     TPtrC fileName( parsedEntry.NameAndExt() );    	        	
       
   140 	buf.Append( fileName );
       
   141 	
       
   142     return buf;
       
   143     }			
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // void CSimPsyFileSelectorModel::GetCorrectPathL
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CSimPsyFileSelectorModel::GetCorrectPathL( TFileName& aFilePath )
       
   150 	{
       
   151     CEikAppUi* appUi = 
       
   152     		static_cast< CEikAppUi* >( CEikonEnv::Static()->AppUi());
       
   153     TFileName* dllDrive = 
       
   154     	new( ELeave ) TFileName( appUi->Application()->AppFullName());
       
   155     CleanupStack::PushL( dllDrive );
       
   156 	
       
   157 	TParse parse;
       
   158 	User::LeaveIfError( parse.Set( *dllDrive, NULL, NULL ));
       
   159     User::LeaveIfError( parse.Set( parse.Drive(), &aFilePath, NULL ));
       
   160 	aFilePath = parse.FullName();
       
   161 	CleanupStack::PopAndDestroy( dllDrive );
       
   162 	}
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 // void CSimPsyFileSelectorModel::AppendFileL
       
   166 // ---------------------------------------------------------------------------
       
   167 //	
       
   168 void CSimPsyFileSelectorModel::AppendFileL( const TDesC&	aDir )
       
   169 	{
       
   170     // Open up a session to the file server
       
   171     RFs	fs;
       
   172     User::LeaveIfError( fs.Connect());
       
   173     CleanupClosePushL( fs );
       
   174         
       
   175     // Obtain a list of entries for the system\data folder
       
   176     TFileName folder( aDir );
       
   177     GetCorrectPathL( folder );        
       
   178     CDir* entryList = NULL;
       
   179     User::LeaveIfError( fs.GetDir( folder, 
       
   180     							   KEntryAttNormal, 
       
   181     							   ESortNone,
       
   182     							   entryList ));
       
   183 	// The scan was successful
       
   184 	CleanupStack::PushL( entryList );
       
   185 	TInt count = entryList->Count();
       
   186 	for ( TInt i = 0; i < count; i++ )
       
   187 		{
       
   188 		TFileName filename ((( *entryList)[i]).iName);
       
   189 		filename.UpperCase();
       
   190 		
       
   191 		// Check for the extension. The extension can be only .sps or
       
   192 		// .nme
       
   193 		TParsePtrC parsedEntry( filename );
       
   194 		TPtrC ext( parsedEntry.Ext());     	
       
   195     	if ( !ext.Compare( KSPSFileExtension ) || 
       
   196     		 !ext.Compare( KNMEAFileExtension ) )
       
   197     		{
       
   198     		// SPS or NMEA file. Append to the File name array.
       
   199     		filename.Zero();
       
   200     		filename.Copy( folder );
       
   201     		filename.Append((( *entryList)[i]).iName );
       
   202     		iFileNameArray.Append( filename );
       
   203     		}
       
   204 		}
       
   205 	CleanupStack::PopAndDestroy( entryList );
       
   206 	
       
   207     // Pop and destroy the file session	
       
   208     CleanupStack::PopAndDestroy();		
       
   209 	}