simpsyconfigurator/src/simpsyuilbmodel.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Provides SimPsyUi listbox model that holds the
       
    15 *				          currently selected NMEA File.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32keys.h>
       
    22 #include <f32file.h>
       
    23 #include <StringLoader.h> // StringLoader
       
    24 #include <centralrepository.h>
       
    25 #include <simpsyui.rsg>
       
    26 #include "SimulationPSYInternalCRKeys.h"
       
    27 
       
    28 #include "simpsyuilbmodel.h"
       
    29 
       
    30 const TInt	KTabWidth = 1;
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CSimPsyUiLBModel::NewL()
       
    35 // Static Constuctor that completes the Symbian two-phase 
       
    36 // construction. 
       
    37 // ---------------------------------------------------------
       
    38 CSimPsyUiLBModel* CSimPsyUiLBModel::NewL()
       
    39     {
       
    40     CSimPsyUiLBModel* lbmodel = NewLC();
       
    41     CleanupStack::Pop( lbmodel );
       
    42     return lbmodel;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CSimPsyUiLBModel::NewLC()
       
    47 // Static Constuctor that completes the Symbian two-phase 
       
    48 // construction. It places the created object on the 
       
    49 // Clean-up stack
       
    50 // ---------------------------------------------------------
       
    51 CSimPsyUiLBModel* CSimPsyUiLBModel::NewLC()
       
    52     {
       
    53     CSimPsyUiLBModel* lbmodel = new (ELeave) CSimPsyUiLBModel();
       
    54     CleanupStack::PushL( lbmodel );
       
    55     lbmodel->ConstructL();
       
    56     return lbmodel;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CSimPsyUiLBModel::CSimPsyUiLBModel()
       
    61 // C++ Default Constructor
       
    62 // ---------------------------------------------------------
       
    63 CSimPsyUiLBModel::CSimPsyUiLBModel()
       
    64     {
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CSimPsyUiLBModel::ConstructL()
       
    69 // Symbian two phased constructor
       
    70 // ---------------------------------------------------------
       
    71 void CSimPsyUiLBModel::ConstructL()
       
    72     {
       
    73     iFileNameText = StringLoader::LoadL( R_SIMPSYUI_FILENAME_TEXT );
       
    74     TInt lLength = iFileNameText->Length();
       
    75     
       
    76     /* The length of the buffer is the length needed for 
       
    77      * the File name text, tab keys and the maximum file
       
    78      * name length
       
    79      */
       
    80     iBuffer = HBufC::NewL(KMaxFileName + KTabWidth + KTabWidth + lLength ); 
       
    81     
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CSimPsyUiLBModel::~CSimPsyUiLBModel()
       
    86 // C++ Destructor
       
    87 // ---------------------------------------------------------
       
    88 CSimPsyUiLBModel::~CSimPsyUiLBModel()
       
    89     {
       
    90     delete iBuffer;
       
    91     iBuffer = NULL;
       
    92     
       
    93     delete iFileNameText;
       
    94     iFileNameText = NULL;
       
    95     }
       
    96     
       
    97 // ---------------------------------------------------------
       
    98 // CSimPsyUiLBModel::MdcaCount()
       
    99 // Returns the number of descriptor elements in a descriptor array.
       
   100 
       
   101 // @return The number of descriptor elements in a descriptor array.
       
   102 // ---------------------------------------------------------
       
   103 TInt CSimPsyUiLBModel::MdcaCount() const
       
   104     {
       
   105     return 1;
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CSimPsyUiLBModel::MdcaPoint()
       
   110 // Indexes into a descriptor array.
       
   111 //
       
   112 // @param aIndex The position of the descriptor element within
       
   113 // 				 a descriptor array. The position is relative 
       
   114 //				 to zero; i.e. zero implies the first descriptor
       
   115 //				 element in a descriptor array. 
       
   116 //	@return 	 A 16 bit non-modifiable pointer descriptor 
       
   117 //				 representing the descriptor element located at 
       
   118 //				 position aIndex within a descriptor array. 
       
   119 // ---------------------------------------------------------
       
   120 TPtrC16 CSimPsyUiLBModel::MdcaPoint( TInt aIndex ) const
       
   121     {
       
   122     	TRAP_IGNORE(MdcaPointL(aIndex));
       
   123     	return *iBuffer;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CSimPsyUiLBModel::MdcaPointL()
       
   128 // Indexes into a descriptor array.
       
   129 //
       
   130 // @param aIndex The position of the descriptor element within
       
   131 // 				 a descriptor array. The position is relative 
       
   132 //				 to zero; i.e. zero implies the first descriptor
       
   133 //				 element in a descriptor array. 
       
   134 //	@return 	 A 16 bit non-modifiable pointer descriptor 
       
   135 //				 representing the descriptor element located at 
       
   136 //				 position aIndex within a descriptor array. 
       
   137 // ---------------------------------------------------------
       
   138 TPtrC16 CSimPsyUiLBModel::MdcaPointL( TInt /*aIndex*/ ) const
       
   139 {
       
   140 	TPtr ptr( iBuffer->Des() );
       
   141     ptr.Zero();
       
   142     ptr.Append( EKeyTab );
       
   143     
       
   144     ptr.Append( iFileNameText->Des() );
       
   145 
       
   146     ptr.Append( EKeyTab );
       
   147     
       
   148     TBuf<KMaxFileName> nmeaFileName;
       
   149 	TParse FileParser;
       
   150 	/* The cenrep contains the filename with full path.
       
   151 	 * Hence only the filename is extracted and displayed in the Edwin
       
   152 	 */
       
   153 	CRepository* repository = CRepository::NewLC(KCRUidSimulationPSY);
       
   154 	repository->Get(KCRKeySimPSYSimulationFile, nmeaFileName);
       
   155 	FileParser.Set(nmeaFileName,NULL,NULL);
       
   156 	nmeaFileName.Copy(FileParser.NameAndExt());
       
   157 	CleanupStack::PopAndDestroy(repository);
       
   158 	
       
   159     ptr.Append(nmeaFileName);
       
   160  
       
   161     return *iBuffer;	
       
   162 }
       
   163