locationcentre/lcapp/src/lclistboxmodel.cpp
branchRCL_3
changeset 9 4721bd00d3da
parent 8 3a25f69541ff
child 11 e15b7f06eba6
equal deleted inserted replaced
8:3a25f69541ff 9:4721bd00d3da
     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 for the list-box used to display the Location
       
    15 *                Centre Application
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // SYSTEM INCLUDES 
       
    21 
       
    22 // USER INCLUDES
       
    23 #include "lclistboxmodel.h"
       
    24 #include "lclocationappinfo.h"
       
    25 #include "lcerrors.h"
       
    26 
       
    27 // CONSTANT DEFINTION
       
    28 const TInt KLcBufferSize = 128;
       
    29 
       
    30 // ========================= MEMBER FUNCTIONS ================================
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CLcListBoxModel::CLcListBoxModel
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CLcListBoxModel::CLcListBoxModel( CLcLocationAppInfoArray*	aAppArray )
       
    37 	:iAppArray( aAppArray )
       
    38     {
       
    39     // C++ Default constructor. No allocations or functions which can Leave
       
    40     // should be called from here.
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CLcListBoxModel::~CLcListBoxModel
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CLcListBoxModel::~CLcListBoxModel()
       
    48     {
       
    49     // C++ Destructor. Free all resources associated with this class.
       
    50     
       
    51     // Delete the MdcaPoint buffer
       
    52     delete iBuffer;
       
    53     
       
    54     // Delete the Application information array
       
    55     delete iAppArray;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // void CLcListBoxModel::ConstructL
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CLcListBoxModel::ConstructL()
       
    63     {
       
    64     // Create the Buffer for packing the MdcaPoint
       
    65     iBuffer = HBufC16::NewL( KLcBufferSize );
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CLcListBoxModel* CLcListBoxModel::NewL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CLcListBoxModel* CLcListBoxModel::NewL( CLcLocationAppInfoArray*	aAppArray )
       
    73     {
       
    74     CLcListBoxModel* self = new ( ELeave ) CLcListBoxModel( aAppArray );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // void CLcListBoxModel::UpdateModel
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CLcListBoxModel::UpdateModel( CLcLocationAppInfoArray*	aAppArray )
       
    86 	{
       
    87 	// The model contents have changed. We have to remove the old App array
       
    88 	// and assign the new one.
       
    89 	
       
    90 	delete iAppArray;
       
    91 	
       
    92 	// Now assign the new one
       
    93 	iAppArray = aAppArray;
       
    94 	}
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CLcLocationAppInfoArray& CLcListBoxModel::AppArray
       
    98 // ---------------------------------------------------------------------------
       
    99 // 
       
   100 CLcLocationAppInfoArray& CLcListBoxModel::AppArray()
       
   101 	{
       
   102     // If the Array is not set then there is a programming error from which
       
   103     // we cannot recover. So Panic the Application
       
   104     if( !iAppArray )
       
   105         {
       
   106         User::Panic( KLcPanicCategory, ELcInvalidIndex );
       
   107         }
       
   108 	return *iAppArray;
       
   109 	}
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // TInt CLcListBoxModel::AppInfoId
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TPtrC CLcListBoxModel::AppInfoId( TInt aIndex ) const
       
   116 	{
       
   117     // Check if the element requested is out of array bounds
       
   118     if( aIndex < 0 || aIndex >= iAppArray->Count())
       
   119         {
       
   120         User::Panic( KLcPanicCategory, ELcInvalidIndex );
       
   121         }
       
   122         	
       
   123 	return (*iAppArray)[ aIndex ].Id();
       
   124 	}
       
   125 	           
       
   126 // ---------------------------------------------------------------------------
       
   127 // TInt CLcListBoxModel::MdcaCount
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 TInt CLcListBoxModel::MdcaCount() const
       
   131     {
       
   132     if ( iAppArray )
       
   133     	{
       
   134     	return iAppArray->Count();    	
       
   135     	}
       
   136 	else
       
   137 		{
       
   138 		return 0;
       
   139 		}    	
       
   140     }
       
   141     
       
   142 // ---------------------------------------------------------------------------
       
   143 // TPtrC16 CLcListBoxModel::MdcaPoint
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 TPtrC16 CLcListBoxModel::MdcaPoint(  TInt aIndex  ) const
       
   147     {
       
   148     // If the Array is not set then there is a programming error from which
       
   149     // we cannot recover. So Panic the Application
       
   150     if( !iAppArray )
       
   151         {
       
   152         User::Panic( KLcPanicCategory, ELcInvalidIndex );
       
   153         }
       
   154             
       
   155     // Pack the contents into the Buffer. We dont have to re-allocate the buffer
       
   156     // everytime because the length of the name field is restricted in the
       
   157     // Location Centre Registration API
       
   158 		    
       
   159     // Tabulator Defintion
       
   160     _LIT( KTab, "\t" );
       
   161     
       
   162     // Create formatted item string.
       
   163     // list_single_large_pane:
       
   164     // list item string format: "1\tTextLabel\t0\t0"
       
   165     // where 0 is an index to icon array
       
   166 	TPtr16	buf( iBuffer->Des());
       
   167 	buf.Zero();
       
   168 	
       
   169 	// Append the Icon Index
       
   170 	buf.AppendNum( aIndex );
       
   171 	
       
   172 	// Append the Tab Key
       
   173 	buf.Append( KTab );
       
   174 	
       
   175 	// Append the Application Information
       
   176 	buf.Append( (*iAppArray)[aIndex].Name());
       
   177 	
       
   178 	// Append the Tab Key
       
   179 	buf.Append( KTab );
       
   180 	
       
   181 	// Append the Tab Key
       
   182 	buf.Append( KTab );   
       
   183     return buf;
       
   184     }