locationcentre/lcservice/src/lclocationappinfo.cpp
branchRCL_3
changeset 16 4721bd00d3da
parent 14 3a25f69541ff
child 21 e15b7f06eba6
equal deleted inserted replaced
14:3a25f69541ff 16: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:  Location Application Information structures.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <gulicon.h>					// Gul Icon
       
    21 #include <fbs.h>                        // Bitmap
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "lclocationappinfo.h"
       
    25 #include "lcnativeapps.hrh"
       
    26 #include "lcerrors.h"
       
    27 #include "lciconloader.h"
       
    28 #include "lcipcparams.h"
       
    29 
       
    30 // CONSTANT DEFINTIONS
       
    31 // Maximum value that the UID field can take in S60
       
    32 const TUint32   KUidMaxValue = 0xFFFFFFFF;
       
    33 
       
    34 // ----- Member funtions for CLcLocationAppInfo ------------------
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CLcLocationAppInfo::CLcLocationAppInfo
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CLcLocationAppInfo::CLcLocationAppInfo( 
       
    41                         const CLcLocationAppInfo&     aLCAppInfo )
       
    42     {
       
    43     // C++ Copy constructor. No allocations or functions which can Leave
       
    44     // should be called from here.
       
    45     
       
    46     // Set only those parameters which dont require memory allocation.
       
    47     iLaunchMode = aLCAppInfo.iLaunchMode;
       
    48     iSystemCharacteristics = aLCAppInfo.iSystemCharacteristics;
       
    49     iAppCharacteristics = aLCAppInfo.iAppCharacteristics;
       
    50     }
       
    51  
       
    52 // ---------------------------------------------------------------------------
       
    53 // CLcLocationAppInfo::CLcLocationAppInfo
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CLcLocationAppInfo::CLcLocationAppInfo()
       
    57     :iLaunchMode( EDefaultMode )
       
    58     {
       
    59     // C++ Default constructor. No allocations or functions which can Leave
       
    60     // should be called from here.
       
    61     }
       
    62                          
       
    63 // ---------------------------------------------------------------------------
       
    64 // CLcLocationAppInfo::~CLcLocationAppInfo
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CLcLocationAppInfo::~CLcLocationAppInfo()
       
    68     {
       
    69     // C++ Destructor. Free all resources associated with this class.
       
    70     
       
    71     // Delete the buffer containing the Identifier
       
    72     delete iId;
       
    73     
       
    74     // Delete the buffer containing the name of the Location application
       
    75     delete iApplicationName;
       
    76     
       
    77     // Delete the Application Icon
       
    78     delete iApplicationIconData;
       
    79     }
       
    80         
       
    81 // ---------------------------------------------------------------------------
       
    82 // CLcLocationAppInfo* CLcLocationAppInfo::NewL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CLcLocationAppInfo* CLcLocationAppInfo::NewL()
       
    86     {
       
    87     CLcLocationAppInfo* self = NewLC();
       
    88     CleanupStack::Pop( self );
       
    89     return self;         
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CLcLocationAppInfo* CLcLocationAppInfo::NewLC
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C CLcLocationAppInfo* CLcLocationAppInfo::NewLC()
       
    97     {
       
    98     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
    99     // stack.
       
   100     CLcLocationAppInfo* self = 
       
   101                 new ( ELeave )CLcLocationAppInfo();
       
   102     CleanupStack::PushL( self );
       
   103     self->ConstructL();
       
   104     return self;         
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CLcLocationAppInfo* CLcLocationAppInfo::NewL
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C CLcLocationAppInfo* CLcLocationAppInfo::NewL(
       
   112                                     const CLcLocationAppInfo&  aLocAppInfo )
       
   113     {
       
   114     CLcLocationAppInfo* self = NewLC( aLocAppInfo );
       
   115     CleanupStack::Pop( self );
       
   116     return self;         
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CLcLocationAppInfo* CLcLocationAppInfo::NewLC
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C CLcLocationAppInfo* CLcLocationAppInfo::NewLC(
       
   124                                     const CLcLocationAppInfo&  aLocAppInfo )
       
   125     {
       
   126     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
   127     // stack.
       
   128     CLcLocationAppInfo* self = 
       
   129                 new ( ELeave )CLcLocationAppInfo( aLocAppInfo );
       
   130     CleanupStack::PushL( self );
       
   131     self->ConstructL( aLocAppInfo );
       
   132     return self;         
       
   133     }
       
   134     
       
   135 // ---------------------------------------------------------------------------
       
   136 // void CLcLocationAppInfo::ConstructL
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 void CLcLocationAppInfo::ConstructL()
       
   140     {
       
   141     }
       
   142  
       
   143 // ---------------------------------------------------------------------------
       
   144 // void CLcLocationAppInfo::ConstructL
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CLcLocationAppInfo::ConstructL( const CLcLocationAppInfo&   aLCAppInfo )
       
   148     {
       
   149     // Copy the Identifier from the Argument Location Application App info.
       
   150     iId = aLCAppInfo.Id().AllocL();
       
   151     
       
   152     // Copy the Name from the Argument Location Application App info.
       
   153     iApplicationName = aLCAppInfo.Name().AllocL();
       
   154     
       
   155     // Create the Icon related objects.
       
   156     if ( aLCAppInfo.iApplicationIconData )
       
   157     	{
       
   158     	iApplicationIconData = aLCAppInfo.iApplicationIconData->Des().Alloc();
       
   159     	}
       
   160     iApplicationIconType = 	aLCAppInfo.iApplicationIconType;
       
   161 	iIconId = aLCAppInfo.iIconId;
       
   162     }
       
   163      
       
   164 // ---------------------------------------------------------------------------
       
   165 // TUint32 CLcLocationAppInfo::IdL
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C TPtrC CLcLocationAppInfo::Id() const
       
   169     {
       
   170     // Check whether the UID exists, incase it doesnt exist then return a
       
   171     // NULL string.
       
   172     if( !iId )
       
   173         {
       
   174         return TPtrC();
       
   175         }
       
   176         
       
   177     // Return the UID.
       
   178     return *iId;
       
   179     }
       
   180  
       
   181 // ---------------------------------------------------------------------------
       
   182 // TDesC& CLcLocationAppInfo::NameL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C TPtrC CLcLocationAppInfo::Name() const
       
   186     {
       
   187     // Check whether the application name exists, incase it doesnt exist then
       
   188     // return a NULL string.
       
   189     if( !iApplicationName )
       
   190         {
       
   191         return TPtrC();
       
   192         }
       
   193     // Return the Application Name.
       
   194     return *iApplicationName;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CGulIcon& CLcLocationAppInfo::IconL
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C CGulIcon* CLcLocationAppInfo::IconL() const
       
   202     {
       
   203     CGulIcon* icon = NULL;
       
   204     // If there is no Icon file present, then we have to load the default
       
   205     // Icon for the Application
       
   206     if ( iApplicationIconData )
       
   207     	{
       
   208     	switch( iApplicationIconType )
       
   209     		{
       
   210     		case CLcAppInfo::EIconfromApp:
       
   211     			{        	      	
       
   212 	            // Since the request is for a Native S60 application, the Identifer
       
   213 	            // contains an UID. Obtain it using Lexer
       
   214 	            TLex lexer( iApplicationIconData->Des());
       
   215 	            TUint32 uidValue;	            
       
   216 	            User::LeaveIfError( lexer.BoundedVal( uidValue, EHex, KUidMaxValue ));
       
   217 	                    	
       
   218 				// Obtain the Location Icon.	                    	
       
   219 	        	icon = LcIconLoader::LoadApplicationIconL( TUid::Uid( uidValue ));
       
   220     			
       
   221     			break;
       
   222     			}
       
   223     		case CLcAppInfo::EMifFile:
       
   224     			{
       
   225     			icon = LcIconLoader::LoadMifFileIconL( iApplicationIconData->Des(),
       
   226     												    iIconId );
       
   227     			break;
       
   228     			}
       
   229     		default:
       
   230     			{
       
   231     			icon = LcIconLoader::LoadDefaultIconL();
       
   232     			break;
       
   233     			}
       
   234     		}
       
   235     	}
       
   236 	else
       
   237 		{
       
   238 		icon = LcIconLoader::LoadDefaultIconL();  
       
   239 		}    	
       
   240   	return icon;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CLcLocationAppInfo::TLcLaunchMode
       
   245 //                  CLcLocationAppInfo::LocationApplicationIconL
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C CLcLocationAppInfo::TLcLaunchMode CLcLocationAppInfo::LaunchMode() const
       
   249     {
       
   250     return iLaunchMode;
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // TUint32 CLcLocationAppInfo::SystemCharacteristics
       
   255 // ---------------------------------------------------------------------------
       
   256 // 
       
   257 EXPORT_C TUint32 CLcLocationAppInfo::SystemCharacteristics() const
       
   258     {
       
   259     return iSystemCharacteristics;
       
   260     }
       
   261  
       
   262 // ---------------------------------------------------------------------------
       
   263 // TUint32 CLcLocationAppInfo::ApplicationCharacteristics
       
   264 // ---------------------------------------------------------------------------
       
   265 // 
       
   266 EXPORT_C TUint32 CLcLocationAppInfo::ApplicationCharacteristics() const
       
   267     {
       
   268     return iAppCharacteristics;
       
   269     }
       
   270                     
       
   271 // ---------------------------------------------------------------------------
       
   272 // TUint32 CLcLocationAppInfo::SetIdL
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CLcLocationAppInfo::SetIdL( const TDesC& aId )
       
   276     {
       
   277     // Incase, the UID already exists then Leave with KErrAlreadyExists
       
   278     if( iId )
       
   279         {
       
   280         User::Leave( KErrAlreadyExists );
       
   281         }
       
   282         
       
   283     // Copy the Identifier from the Argument Location Application App info.
       
   284     iId = aId.AllocL();
       
   285     
       
   286     }
       
   287     
       
   288 // ---------------------------------------------------------------------------
       
   289 // void CLcLocationAppInfo::SetNameL
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CLcLocationAppInfo::SetNameL( const TDesC& aName )
       
   293     {
       
   294     // Incase, the application name exists then Leave with KErrAlreadyExists.
       
   295     if( iApplicationName )
       
   296         {
       
   297         User::Leave( KErrAlreadyExists );
       
   298         }
       
   299         
       
   300     // Copy the Name from the Argument Location Application App info.
       
   301     iApplicationName = aName.AllocL();  
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // void CLcLocationAppInfo::SetIconL
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CLcLocationAppInfo::SetIconL( 		 TInt		aIconType,
       
   309 				   				   const TDesC&		aIconData,
       
   310 				   		 				 TInt		aIconId )
       
   311     {	    
       
   312     // Incase, the application icon exists then Leave with KErrAlreadyExists.
       
   313     if( iApplicationIconData )
       
   314         {
       
   315         User::Leave( KErrAlreadyExists );
       
   316         }
       
   317     
       
   318     if( !aIconData.Length())
       
   319         {
       
   320         User::Leave( KErrArgument );
       
   321         }
       
   322                     
       
   323     // Create the Icon related objects.
       
   324     iApplicationIconData = aIconData.Alloc();
       
   325     iApplicationIconType = 	aIconType;
       
   326 	iIconId = aIconId;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // void CLcLocationAppInfo::SetLocationApplicationLaunchMode
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CLcLocationAppInfo::SetLaunchMode(
       
   334                             CLcLocationAppInfo::TLcLaunchMode aLaunchMode )
       
   335     {
       
   336     iLaunchMode = aLaunchMode;
       
   337     }
       
   338  
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // void CLcLocationAppInfo::SetSystemCharacteristics
       
   342 // ---------------------------------------------------------------------------
       
   343 //    
       
   344 void CLcLocationAppInfo::SetSystemCharacteristics( 
       
   345                             TUint32   aSysCharacteristics )
       
   346     {
       
   347     iSystemCharacteristics = aSysCharacteristics;
       
   348     }                            
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // void CLcLocationAppInfo::SetApplicationCharacteristics
       
   352 // ---------------------------------------------------------------------------
       
   353 //    
       
   354 void CLcLocationAppInfo::SetApplicationCharacteristics( 
       
   355                             TUint32   aAppCharacteristics )
       
   356     {
       
   357     iAppCharacteristics = aAppCharacteristics;
       
   358     } 
       
   359         
       
   360 // ----- Member funtions for CLcLocationAppInfoArray -------------
       
   361  
       
   362 // ---------------------------------------------------------------------------
       
   363 // CLcLocationAppInfoArray::CLcLocationAppInfoArray
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 CLcLocationAppInfoArray::CLcLocationAppInfoArray()
       
   367     {
       
   368     // C++ Default constructor. No allocations or functions which can Leave
       
   369     // should be called from here.
       
   370     }
       
   371       
       
   372 // ---------------------------------------------------------------------------
       
   373 // CLcLocationAppInfoArray::~CLcLocationAppInfoArray
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C CLcLocationAppInfoArray::~CLcLocationAppInfoArray()
       
   377     {
       
   378     // C++ Destructor. Free all resources associated with this class.
       
   379     
       
   380     // Delete all the the associated Location application information objects.
       
   381 	while ( iAppInfoArray.Count() > 0 )
       
   382 		{
       
   383 		// Remove the first item
       
   384 		CLcLocationAppInfo* item = iAppInfoArray[0];
       
   385 		iAppInfoArray.Remove( 0 );
       
   386 		
       
   387 		// Delete the element
       
   388 		delete item;
       
   389 		item = NULL;
       
   390 		}
       
   391 	iAppInfoArray.Reset();
       
   392 	iAppInfoArray.Close();    
       
   393     }
       
   394         
       
   395 // ---------------------------------------------------------------------------
       
   396 // CLcLocationAppInfoArray* 
       
   397 //                      CLcLocationAppInfoArray::NewL
       
   398 // ---------------------------------------------------------------------------
       
   399 //
       
   400 EXPORT_C CLcLocationAppInfoArray* 
       
   401                                 CLcLocationAppInfoArray::NewL()
       
   402     {
       
   403     CLcLocationAppInfoArray* self = NewLC();
       
   404     CleanupStack::Pop( self );
       
   405     return self;         
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CLcLocationAppInfoArray* 
       
   410 //                      CLcLocationAppInfoArray::NewLC
       
   411 // ---------------------------------------------------------------------------
       
   412 //
       
   413 EXPORT_C CLcLocationAppInfoArray* 
       
   414                                 CLcLocationAppInfoArray::NewLC()
       
   415     {
       
   416     // Symbian Two phased constructor. Leaves the object on the Clean-up
       
   417     // stack.
       
   418     CLcLocationAppInfoArray* self = 
       
   419                 new ( ELeave )CLcLocationAppInfoArray();
       
   420     CleanupStack::PushL( self );
       
   421     self->ConstructL();
       
   422     return self;         
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // void CLcLocationAppInfoArray::ConstructL
       
   427 // ---------------------------------------------------------------------------
       
   428 //
       
   429 void CLcLocationAppInfoArray::ConstructL()
       
   430     {
       
   431     // Second phase of the two phase constructor.
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // void CLcLocationAppInfoArray::Count
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 EXPORT_C TInt CLcLocationAppInfoArray::Count() const
       
   439     {
       
   440     // Return the number of elements in the Application information array.
       
   441     return  iAppInfoArray.Count();      
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // void CLcLocationAppInfoArray::AppendL
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 EXPORT_C void CLcLocationAppInfoArray::AppendL( 
       
   449                             CLcLocationAppInfo*     aLCAppInfo )
       
   450     {
       
   451     // Check if the element passed as an argument is NULL. If its NULL, then
       
   452     // Leave with KErrArgument
       
   453     // Not using User::LeaveIfNull because in that case, the leave would happen
       
   454     // with KErrNoMemory which conveys the wrong behaviour.
       
   455     if( !aLCAppInfo )
       
   456         {
       
   457         User::Leave( KErrArgument );
       
   458         }
       
   459     
       
   460     // Append the new element into the array;
       
   461     iAppInfoArray.AppendL( aLCAppInfo );     
       
   462     }
       
   463 
       
   464 // ---------------------------------------------------------------------------
       
   465 // CLcLocationAppInfo* CLcLocationAppInfoArray::RemoveL
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 EXPORT_C CLcLocationAppInfo* CLcLocationAppInfoArray::Remove( TInt  aIndex )
       
   469     {
       
   470     // Check if the element requested is out of array bounds
       
   471     if( aIndex < 0 || aIndex >= iAppInfoArray.Count())
       
   472         {
       
   473         User::Panic( KLcPanicCategory, ELcInvalidIndex );
       
   474         }
       
   475         
       
   476     // Since, the remove method is expected to return back the reference
       
   477     // of the element removed, first store the element at the aIndex
       
   478     // position and return it back                            
       
   479     CLcLocationAppInfo* item = iAppInfoArray[ aIndex ];
       
   480     iAppInfoArray.Remove( aIndex );
       
   481     return item;
       
   482     }
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // CLcLocationAppInfo* CLcLocationAppInfoArray::Reset
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 EXPORT_C void CLcLocationAppInfoArray::Reset()
       
   489     {
       
   490     // Reset the entire array so that its ok for resuse.
       
   491     iAppInfoArray.ResetAndDestroy();
       
   492     }
       
   493     
       
   494 // ---------------------------------------------------------------------------
       
   495 // CLcLocationAppInfo& CLcLocationAppInfoArray::
       
   496 //                            operator[]
       
   497 // ---------------------------------------------------------------------------
       
   498 //     
       
   499 EXPORT_C CLcLocationAppInfo& CLcLocationAppInfoArray::
       
   500                                 operator[]( TInt aIndex ) const
       
   501     {
       
   502     // Check if the element requested is out of array bounds
       
   503     if( aIndex < 0 || aIndex >= iAppInfoArray.Count())
       
   504         {
       
   505         User::Panic( KLcPanicCategory, ELcInvalidIndex );
       
   506         }
       
   507 
       
   508     // Return only a reference of the object. The ownership is not be 
       
   509     // transferred.
       
   510     return *(iAppInfoArray[ aIndex ]);    
       
   511     }
       
   512         
       
   513 // End of File
       
   514