Example Application Guide

 

geoprofile.cpp

00001 /*
00002 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
00003 * All rights reserved.
00004 * This component and the accompanying materials are made available
00005 * under the terms of the License "Eclipse Public License v1.0"
00006 * which accompanies this distribution, and is available
00007 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 *
00009 * Initial Contributors:
00010 * Nokia Corporation - initial contribution.
00011 *
00012 * Contributors:
00013 *
00014 * Description:  Geo Profile Structure
00015 *
00016 */
00017 
00018 
00019 // SYSTEM INCLUDES
00020 #include <ProEngFactory.h>
00021 #include <mproengengine.h>
00022 #include <mproengprofilenamearray.h>
00023 #include <e32math.h> 
00024 #include <geoprofilesui.rsg>
00025 #include <stringloader.h>
00026 
00027 // USER INCLUDES
00028 #include "geoprofile.h"
00029 #include "geoprofilesdebug.h"
00030 #include "geoprofiles.hrh"
00031 
00032 // CONSTANT DEFINTION
00033 const TInt KMinGeoProfileRadius = 100;
00034 _LIT( KDeliminator, ":");
00035 
00036 // ============== MEMBER FUNCTIONS FOR GEOPROFILE ============================
00037 
00038 // ---------------------------------------------------------------------------
00039 // CGeoProfile::CGeoProfile
00040 // ---------------------------------------------------------------------------
00041 //
00042 CGeoProfile::CGeoProfile()
00043     :iPositionType( EUndefined ),
00044     iProfileRadius( KMinGeoProfileRadius ),
00045     iTriggerId( 0xFFFFFFF ),
00046     iTriggerType( EEntryTrigger )    
00047     {    
00048     }
00049     
00050 // ---------------------------------------------------------------------------
00051 // CGeoProfile::~CGeoProfile
00052 // ---------------------------------------------------------------------------
00053 // 
00054 CGeoProfile::~CGeoProfile()
00055     {
00056     GEOPROFILEDEBUG("+ CGeoProfile::~CGeoProfile" )
00057     
00058     // Delete the member variables
00059     delete iGeoPlaceName;
00060     
00061     delete iProfileName;  
00062     
00063     GEOPROFILEDEBUG("- CGeoProfile::~CGeoProfile" )
00064     }   
00065 
00066 // ---------------------------------------------------------------------------
00067 // CGeoProfile::NewL
00068 // ---------------------------------------------------------------------------
00069 // 
00070 CGeoProfile* CGeoProfile::NewL()
00071     {
00072     TLocality locality;    
00073     return NewL( KNullDesC(), locality, KErrNotFound, EUndefined );                                                                  
00074     }
00075     
00076 // ---------------------------------------------------------------------------
00077 // CGeoProfile::NewL
00078 // ---------------------------------------------------------------------------
00079 // 
00080 CGeoProfile* CGeoProfile::NewL( const TDesC&       aGeoPlaceName,
00081                                 TLocality&         aPositionInfo,
00082                                 TInt               aGeoProfileId,
00083                                 TInt               aProfileRadius,
00084                                 TInt               aTriggerId,
00085                                 TInt               aTriggerType )
00086     {
00087     GEOPROFILEDEBUG("+ CGeoProfile::NewL" ) 
00088     
00089     CGeoProfile* self = new ( ELeave ) CGeoProfile();
00090     CleanupStack::PushL( self );
00091     self->ConstructL( aGeoPlaceName, 
00092                       aGeoProfileId, 
00093                       aPositionInfo, 
00094                       aProfileRadius, 
00095                       aTriggerId, 
00096                       aTriggerType );
00097     CleanupStack::Pop( self );
00098     
00099     GEOPROFILEDEBUG("- CGeoProfile::NewL" ) 
00100     return self;                                                                  
00101     }
00102     
00103 // ---------------------------------------------------------------------------
00104 // CGeoProfile::ConstructL
00105 // ---------------------------------------------------------------------------
00106 //
00107 void CGeoProfile::ConstructL(  const TDesC&       aGeoPlaceName,
00108                                      TInt         aGeoProfileId,
00109                                      TLocality&   aPositionInfo,
00110                                      TInt         aProfileRadius,
00111                                      TInt         aTriggerId,
00112                                      TInt         aTriggerType )
00113     {
00114     GEOPROFILEDEBUG("+ CGeoProfile::ConstructL" ) 
00115     
00116     // Create all member variables
00117     iGeoPlaceName = HBufC::NewL( KGeoPlaceNameMaxLength );    
00118     
00119     iProfileName = HBufC::NewL( KGeoProfileNameMaxLength );
00120     iProfileName->Des().Zero();
00121     
00122     SetGeoPlaceNameL( KNullDesC());
00123         
00124     // Copy the Item Id
00125     SetGeoProfileIdL( aGeoProfileId );
00126     
00127     // Copy the Location information contents
00128     SetGeoPositionInfoL( aGeoPlaceName, aPositionInfo );
00129     
00130     // Set the profile Radius
00131     SetGeoProfileRadius( aProfileRadius );
00132     
00133     // Set the Trigger id
00134     iTriggerId = aTriggerId; 
00135     
00136     // Set Trigger Type
00137     SetTriggerType( aTriggerType );
00138     
00139     GEOPROFILEDEBUG("- CGeoProfile::ConstructL" )    
00140     }
00141     
00142 // ---------------------------------------------------------------------------
00143 // CGeoProfile::GeoPlaceName
00144 // ---------------------------------------------------------------------------
00145 // 
00146 TPtrC CGeoProfile::GeoPlaceName()
00147     {
00148     return iGeoPlaceName->Des();
00149     }
00150 
00151 // ---------------------------------------------------------------------------
00152 // CGeoProfile::ProfileName
00153 // ---------------------------------------------------------------------------
00154 //     
00155 TPtrC CGeoProfile::ProfileName()
00156     {
00157     return iProfileName->Des();
00158     }
00159 
00160 // ---------------------------------------------------------------------------
00161 // void CGeoProfile::SetProfileNameL
00162 // ---------------------------------------------------------------------------
00163 //     
00164 void CGeoProfile::SetProfileNameL( const TDesC&       aProfileName )
00165     {
00166     if ( aProfileName.Length() > KGeoProfileNameMaxLength )
00167         {
00168         User::Leave( KErrOverflow );
00169         }
00170         
00171     // Copy the corresponding profile name
00172     iProfileName->Des().Copy( aProfileName );    
00173     }
00174     
00175 // ---------------------------------------------------------------------------
00176 // TInt CGeoProfile::ItemId
00177 // ---------------------------------------------------------------------------
00178 // 
00179 TInt CGeoProfile::GeoProfileId()
00180     {
00181     return iGeoProfileId;
00182     }
00183 
00184 // ---------------------------------------------------------------------------
00185 //void CGeoProfile::SetGeoProfileId
00186 // ---------------------------------------------------------------------------
00187 //    
00188 void CGeoProfile::SetGeoProfileIdL( TInt               aGeoProfileId )
00189     {
00190     GEOPROFILEDEBUG("+ CGeoProfile::SetGeoProfileIdL" ) 
00191     
00192     // Obtain the list of profiles
00193     MProEngEngine* profileEng = ProEngFactory::NewEngineL();
00194     CleanupReleasePushL( *profileEng );
00195 
00196     MProEngProfileNameArray* profileNames = profileEng->ProfileNameArrayLC();
00197     TInt index = 0;
00198     index = profileNames->FindById( aGeoProfileId );
00199     if ( KErrNotFound == index )
00200         {
00201         // Setting the Default Value of index back to 0
00202         iGeoProfileId = profileEng->ActiveProfileId();
00203         index = profileNames->FindById( iGeoProfileId );
00204         }
00205     else
00206         {
00207         iGeoProfileId = profileNames->ProfileId( index );      
00208         }      
00209     SetProfileNameL( profileNames->MdcaPoint( index ));
00210     CleanupStack::PopAndDestroy( 2 );
00211     
00212     GEOPROFILEDEBUG("- CGeoProfile::SetGeoProfileIdL" ) 
00213     }
00214 
00215 // ---------------------------------------------------------------------------
00216 // TInt CGeoProfile::GeoPositionType
00217 // ---------------------------------------------------------------------------
00218 //  
00219 TInt CGeoProfile::GeoPositionType() 
00220     {
00221     return iPositionType;
00222     }
00223 
00224 // ---------------------------------------------------------------------------
00225 // TInt CGeoProfile::GeoPositionType
00226 // ---------------------------------------------------------------------------
00227 //  
00228 void CGeoProfile::SetGeoPositionType(  TInt         aPositionType ) 
00229     {
00230     iPositionType = aPositionType;
00231     }
00232     
00233 // ---------------------------------------------------------------------------
00234 // TLocality& CGeoProfile::GeoPositionInfo
00235 // ---------------------------------------------------------------------------
00236 //    
00237 TLocality& CGeoProfile::GeoPositionInfo()
00238     {
00239     return iPositionInfo;
00240     }
00241 
00242 // ---------------------------------------------------------------------------
00243 // void CGeoProfile::SetGeoPositionInfo
00244 // ---------------------------------------------------------------------------
00245 //
00246 void CGeoProfile::SetGeoPositionInfoL( const TDesC&      aGeoPlaceName,
00247                                              TLocality&  aPositionInfo )
00248     {    
00249     if ( !Math::IsNaN( aPositionInfo.Latitude()) && 
00250          !Math::IsNaN( aPositionInfo.Longitude()))
00251         {
00252         SetGeoPositionType( ECoordinate );
00253         iPositionInfo = aPositionInfo;
00254         SetGeoPlaceNameL( aGeoPlaceName );      
00255         }    
00256     }
00257 
00258 // ---------------------------------------------------------------------------
00259 // void CGeoProfile::GeoProfileRadius
00260 // ---------------------------------------------------------------------------
00261 //    
00262 TInt CGeoProfile::GeoProfileRadius()
00263     {
00264     return iProfileRadius;
00265     }
00266 
00267 // ---------------------------------------------------------------------------
00268 // void CGeoProfile::SetGeoProfileRadius
00269 // ---------------------------------------------------------------------------
00270 //
00271 void CGeoProfile::SetTriggerId( TInt  aTriggerId )
00272     {
00273     iTriggerId = aTriggerId;
00274     }
00275 
00276 // ---------------------------------------------------------------------------
00277 // TInt CGeoProfile::TriggerId
00278 // ---------------------------------------------------------------------------
00279 //    
00280 TInt CGeoProfile::TriggerId()
00281     {
00282     return iTriggerId;
00283     }
00284 
00285 // ---------------------------------------------------------------------------
00286 // void CGeoProfile::SetGeoProfileRadius
00287 // ---------------------------------------------------------------------------
00288 //
00289 void CGeoProfile::SetGeoProfileRadius( TInt  aRadius )
00290     {
00291     if ( aRadius < KMinGeoProfileRadius )
00292         {
00293         iProfileRadius = KMinGeoProfileRadius; 
00294         }
00295     else
00296         {
00297         iProfileRadius = aRadius;  
00298         }
00299     }
00300 
00301 // ---------------------------------------------------------------------------
00302 // TInt CGeoProfile::TriggerType
00303 // ---------------------------------------------------------------------------
00304 //
00305 TInt CGeoProfile::TriggerType()
00306     {
00307     return iTriggerType;    
00308     }
00309 
00310 // ---------------------------------------------------------------------------
00311 // void CGeoProfile::SetTriggerType
00312 // ---------------------------------------------------------------------------
00313 //
00314 void CGeoProfile::SetTriggerType( TInt  aTriggerType )
00315     {
00316     iTriggerType = aTriggerType;
00317     }
00318 
00319 // ---------------------------------------------------------------------------
00320 // void CGeoProfile::SetGeoProfileNameL
00321 // ---------------------------------------------------------------------------
00322 //
00323 void CGeoProfile::SetGeoPlaceNameL( const TDesC&   aGeoPlaceName )
00324     {    
00325     if ( aGeoPlaceName.Length() > KGeoPlaceNameMaxLength )
00326         {
00327         User::Leave( KErrOverflow );
00328         }
00329     
00330     if ( !aGeoPlaceName.Length())
00331         {
00332         HBufC* placeName = StringLoader::LoadLC( R_LBL_GEOPROFILES_DEFINE );    
00333         iGeoPlaceName->Des().Copy( placeName->Des());    
00334         CleanupStack::PopAndDestroy( placeName );
00335         SetGeoPositionType( EUndefined );       
00336         }
00337     else
00338         {
00339         // Copy the corresponding profile name
00340         iGeoPlaceName->Des().Copy( aGeoPlaceName );             
00341         }  
00342     }
00343 
00344 // ---------------------------------------------------------------------------
00345 // void CGeoProfile::PartialInternalizeL
00346 // ---------------------------------------------------------------------------
00347 //    
00348 void CGeoProfile::PartialInternalizeL( const TDesC&   aInputBuffer )
00349     {
00350     GEOPROFILEDEBUG("+ CGeoProfile::PartialInternalizeL" ) 
00351     
00352     TInt32 value = 0;
00353     TLex lexer( aInputBuffer );
00354     
00355     // Read Profile Id   
00356     User::LeaveIfError( lexer.Val( value ));
00357     SetGeoProfileIdL( value );
00358     lexer.Inc();
00359     
00360     // Read the Position Type Info
00361     User::LeaveIfError( lexer.Val( value ));
00362     SetGeoPositionType( value );
00363     lexer.Inc();    
00364     
00365     // Write the Horizontal Accuracy
00366     User::LeaveIfError( lexer.Val( value ));
00367     if ( value == -1 )
00368         {
00369         TRealX nan;
00370         nan.SetNaN();
00371         iPositionInfo.SetHorizontalAccuracy( nan );        
00372         }
00373     else
00374         {
00375         iPositionInfo.SetHorizontalAccuracy( value );      
00376         }
00377     lexer.Inc();        
00378         
00379     // Set the profile radius
00380     User::LeaveIfError( lexer.Val( value ));
00381     SetGeoProfileRadius( value );
00382     lexer.Inc();
00383     
00384     GEOPROFILEDEBUG("- CGeoProfile::PartialInternalizeL" )     
00385     }
00386 
00387 // ---------------------------------------------------------------------------
00388 // HBufC* CGeoProfile::PartialExternalizeL
00389 // ---------------------------------------------------------------------------
00390 //     
00391 HBufC* CGeoProfile::PartialExternalizeLC()
00392     {
00393     GEOPROFILEDEBUG("+ CGeoProfile::PartialExternalizeLC" ) 
00394     
00395     HBufC* buffer = HBufC::NewLC( 256 );
00396     TPtr bufferPtr = buffer->Des();
00397 
00398     // Write Geo Profile Id
00399     bufferPtr.AppendNum( iGeoProfileId );
00400     bufferPtr.Append( KDeliminator );
00401     
00402     // Write Position Type
00403     bufferPtr.AppendNum( iPositionType );
00404     bufferPtr.Append( KDeliminator );
00405         
00406     // Write the Horizontal Accuracy
00407     if ( Math::IsNaN( iPositionInfo.HorizontalAccuracy()))
00408         {
00409         bufferPtr.AppendNum( -1 );    
00410         }
00411     else
00412         {
00413        bufferPtr.AppendNum( iPositionInfo.HorizontalAccuracy());
00414         }
00415     bufferPtr.Append( KDeliminator );
00416         
00417     // Write the Radius
00418     bufferPtr.AppendNum( iProfileRadius ); 
00419     bufferPtr.Append( KDeliminator );
00420     
00421     GEOPROFILEDEBUG("- CGeoProfile::PartialExternalizeLC" ) 
00422     
00423     return buffer;
00424     }

© Nokia 2009

Back to top