Example Application Guide

 

CGeoPlaceSelector Class Reference

#include <geoplaceselector.h>

Inheritance diagram for CGeoPlaceSelector:

List of all members.

Detailed Description

Geo Profile Place selector

Definition at line 33 of file geoplaceselector.h.

Public Types

enum  EGeoPlaceSelection { EPlaceCurrentLocation, EPlaceLandmark, EPlaceNetworkCell }

Public Member Functions

virtual ~CGeoPlaceSelector ()
TInt SelectGeoPlaceL (TInt &aPlaceType, TLocality &aLocality, TPtr &aPlaceName)

Static Public Member Functions

static CGeoPlaceSelectorNewLC ()

Private Member Functions

 CGeoPlaceSelector ()
void ConstructL ()
void RunL ()
void DoCancel ()
TInt DisplayPlacePopUpL ()
TInt SelectPlaceFromLandmarkL (TLocality &aLocality, TPtr &aPlaceName)
TInt SelectPlaceFromCurrentLocationL (TLocality &aLocality)
void LaunchWaitDialogL ()
void DismissWaitDialog ()

Private Attributes

HBufC * iPlacePopupTitle
CAknWaitDialog * iWaitDialog
TInt iLocAcqState
TInt iDialogState
TBool iMapsAvailable
RPositionServer iServer
RPositioner iPositioner


Member Enumeration Documentation

enum CGeoPlaceSelector::EGeoPlaceSelection
 

Enumeration Defintions

Definition at line 39 of file geoplaceselector.h.

00040         {
00041         EPlaceCurrentLocation,
00042         EPlaceLandmark,
00043         EPlaceNetworkCell    
00044         };


Constructor & Destructor Documentation

CGeoPlaceSelector::~CGeoPlaceSelector  )  [virtual]
 

C++ Destructor. Frees all the resources

Definition at line 52 of file geoplaceselector.cpp.

References iPlacePopupTitle, iPositioner, and iServer.

00053     {
00054     // Cancel any outstanding request
00055     Cancel();
00056     
00057     iPositioner.Close();
00058     iServer.Close();
00059     
00060     delete iPlacePopupTitle;
00061     }

CGeoPlaceSelector::CGeoPlaceSelector  )  [private]
 

C++ Constructor

Definition at line 43 of file geoplaceselector.cpp.

Referenced by NewLC().

00044     :CActive( EPriorityStandard )
00045     {    
00046     }


Member Function Documentation

CGeoPlaceSelector * CGeoPlaceSelector::NewLC  )  [static]
 

Constructs a new instance of CGeoPlaceSelector

Definition at line 67 of file geoplaceselector.cpp.

References CGeoPlaceSelector().

Referenced by CGeoProfileEditor::HandlePlaceSelectionL().

00068     {
00069     CGeoPlaceSelector* self = new ( ELeave ) CGeoPlaceSelector();
00070     CleanupStack::PushL( self );
00071     self->ConstructL();
00072     return self;                                                                  
00073     }

TInt CGeoPlaceSelector::SelectGeoPlaceL TInt &  aPlaceType,
TLocality &  aLocality,
TPtr &  aPlaceName
 

Select Place

Definition at line 96 of file geoplaceselector.cpp.

References DisplayPlacePopUpL(), SelectPlaceFromCurrentLocationL(), and SelectPlaceFromLandmarkL().

Referenced by CGeoProfileEditor::HandlePlaceSelectionL().

00099     {   
00100     TInt retVal = KErrCancel;
00101     retVal = DisplayPlacePopUpL();
00102     switch ( retVal )
00103         {
00104         case EPlaceCurrentLocation:
00105             {
00106             retVal = SelectPlaceFromCurrentLocationL( aLocality );
00107             aPlaceType = CGeoProfile::ECoordinate;
00108             break;    
00109             }
00110         case EPlaceNetworkCell:
00111             {
00112             break;              
00113             }
00114         case EPlaceLandmark:
00115             {
00116             retVal = SelectPlaceFromLandmarkL( aLocality, aPlaceName );
00117             aPlaceType = CGeoProfile::ECoordinate;
00118             }
00119         default:
00120             {
00121             break;
00122             }
00123         }
00124     
00125     if ( !retVal )
00126         {
00127         HBufC* title = StringLoader::LoadLC( R_LBL_GEOPROFILES_LOCATIONNAME );
00128         
00129         // Ask the User to enter a suitable name
00130         CAknTextQueryDialog* nameQuery = CAknTextQueryDialog::NewL( aPlaceName );
00131         retVal = !nameQuery->ExecuteLD( R_GEOPROFILES_NAME_QUERYDIALOG, title->Des());
00132         CleanupStack::PopAndDestroy( title );     
00133         }          
00134     return retVal;
00135     }

void CGeoPlaceSelector::ConstructL  )  [private]
 

Second phase of two phase construction

Definition at line 79 of file geoplaceselector.cpp.

References iMapsAvailable, iPlacePopupTitle, iPositioner, and iServer.

00080     {
00081     // Allocate the Title text
00082     iPlacePopupTitle = NULL;
00083     
00084     iMapsAvailable = EFalse;
00085     
00086     User::LeaveIfError( iServer.Connect());
00087     User::LeaveIfError( iPositioner.Open( iServer ));
00088     
00089     CActiveScheduler::Add( this );
00090     }

void CGeoPlaceSelector::RunL  )  [private]
 

Inherited from CActive

Definition at line 141 of file geoplaceselector.cpp.

References DismissWaitDialog(), and iLocAcqState.

00142     {
00143     iLocAcqState = iStatus.Int();
00144     DismissWaitDialog();
00145     }

void CGeoPlaceSelector::DoCancel  )  [private]
 

Inherited from CActive

Definition at line 151 of file geoplaceselector.cpp.

References DismissWaitDialog(), iLocAcqState, and iPositioner.

00152     {
00153     iPositioner.CancelRequest( EPositionerNotifyPositionUpdate );
00154     iLocAcqState = KErrNotFound;
00155     DismissWaitDialog();       
00156     }

TInt CGeoPlaceSelector::DisplayPlacePopUpL  )  [private]
 

Display Place Dialog

Definition at line 161 of file geoplaceselector.cpp.

Referenced by SelectGeoPlaceL().

00162     {
00163     TInt retVal = KErrCancel;
00164        
00165     // Index for profile selection
00166     TInt index = 0;
00167         
00168     // Load the Title text
00169     HBufC* title = StringLoader::LoadLC( R_LBL_GEOPROFILES_PLACE );
00170         
00171     // Create the list Query Dialog
00172     CAknListQueryDialog* placeQuery = new( ELeave ) CAknListQueryDialog( &index );
00173     placeQuery->PrepareLC( R_GEOPROFILES_LIST_QUERY );
00174           
00175     // Assign Title Text
00176     CAknPopupHeadingPane *  heading = placeQuery->QueryHeading();
00177     if( heading )
00178         {
00179         heading->SetTextL( *title );
00180         }
00181        
00182     // Descriptor array
00183     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 4 );
00184     CleanupStack::PushL( array );
00185     
00186     HBufC* placeName = HBufC::NewLC( 256 );
00187     TPtr placeNamePtr = placeName->Des();
00188    
00189     // Append the Current Place Label
00190     HBufC* currentplace = StringLoader::LoadLC( R_LBL_GEOPROFILES_CURRENTPLACE );
00191     placeNamePtr.Zero();
00192     placeNamePtr.Append( KTab );
00193     placeNamePtr.Append( currentplace->Des());
00194     array->AppendL( *placeName );    
00195     CleanupStack::PopAndDestroy( currentplace );   
00196     
00197     // Append the Landmark Label
00198     HBufC* landmark = StringLoader::LoadLC( R_LBL_GEOPROFILES_LANDMARKS );
00199     placeNamePtr.Zero();
00200     placeNamePtr.Append( KTab );
00201     placeNamePtr.Append( landmark->Des());
00202     array->AppendL( *placeName );
00203     CleanupStack::PopAndDestroy( landmark );
00204                 
00205     // Cleanup the profile Name buffer
00206     CleanupStack::PopAndDestroy( placeName );
00207     
00208     // Assign the Item text array
00209     placeQuery->SetItemTextArray( array );
00210     placeQuery->SetOwnershipType(  ELbmOwnsItemArray );
00211     CleanupStack::Pop( array );
00212       
00213     if ( placeQuery->RunLD())
00214         {
00215         if ( index == 3 && !iMapsAvailable )
00216             {
00217             retVal = index + 1;
00218             }
00219         else
00220             {
00221             retVal = index;    
00222             }        
00223         }
00224         
00225     CleanupStack::PopAndDestroy( title );
00226     return retVal;    
00227 
00228     }

TInt CGeoPlaceSelector::SelectPlaceFromLandmarkL TLocality &  aLocality,
TPtr &  aPlaceName
[private]
 

Select place from Landmark

Definition at line 234 of file geoplaceselector.cpp.

Referenced by SelectGeoPlaceL().

00236     {
00237     TInt retVal = KErrCancel;
00238     
00239     TLmkItemIdDbCombiInfo lmkInfo;
00240     
00241     // Create a Landmarks object
00242     CLmkLandmarkSelectorDlg* dlg =  CLmkLandmarkSelectorDlg::NewL();
00243     if ( dlg->ExecuteLD( lmkInfo ) )
00244         {        
00245         CPosLandmarkDatabase* lmkDb = lmkInfo.GetLmDb();
00246         CleanupStack::PushL( lmkDb );
00247         CPosLandmark* lmk = lmkDb->ReadLandmarkLC( lmkInfo.GetItemId() );
00248         
00249         //retrieve lat long info
00250         TLocality locality;
00251         lmk->GetPosition( locality );
00252         if( !Math::IsNaN( locality.Latitude() ) && 
00253             !Math::IsNaN( locality.Longitude()))
00254             {
00255             aLocality = locality;
00256             
00257             // Store the name if it exists
00258             TPtrC landmarkName;
00259             lmk->GetLandmarkName( landmarkName );
00260             
00261             if ( landmarkName.Length() && landmarkName.Length() < KGeoPlaceNameMaxLength )
00262                 {
00263                 aPlaceName.Copy( landmarkName );
00264                 }
00265             retVal = KErrNone;
00266             }
00267         else
00268             {
00269             User::Leave( KErrNotFound );    
00270             }
00271         CleanupStack::PopAndDestroy( 2, lmkDb );       
00272         }
00273     return retVal;
00274     }

TInt CGeoPlaceSelector::SelectPlaceFromCurrentLocationL TLocality &  aLocality  )  [private]
 

Select place from current Location

Definition at line 280 of file geoplaceselector.cpp.

References iDialogState, iLocAcqState, iPositioner, and LaunchWaitDialogL().

Referenced by SelectGeoPlaceL().

00281     {
00282     if ( IsActive())
00283         {
00284         User::Leave( KErrInUse );
00285         }
00286         
00287     // Initialize the server options
00288     _LIT(KRequestorName, "Geo Profiles ");    
00289         User::LeaveIfError( iPositioner.SetRequestor( 
00290                             CRequestor::ERequestorService,
00291                             CRequestor::EFormatApplication,
00292                             KRequestorName ));
00293                             
00294     // Issue a Location Request
00295     TPositionInfo posInfo;
00296     iPositioner.NotifyPositionUpdate( posInfo, iStatus );
00297     SetActive();    
00298     
00299     iLocAcqState = KErrNotFound;
00300     iDialogState = KErrNone;
00301     
00302     // Launch the Wait Dialog which will block the thread
00303     LaunchWaitDialogL();
00304     
00305     if( iLocAcqState )
00306         {
00307         // If Location Acquistion Failed, leave with the corresponding error code.
00308         User::Leave( iLocAcqState );
00309         }
00310         
00311     if ( !iDialogState )
00312         {
00313         // Now Copy the Location Information
00314         TPosition position;
00315         posInfo.GetPosition( position );
00316         
00317         if( !Math::IsNaN( position.Latitude() ) && 
00318             !Math::IsNaN( position.Longitude()))
00319             {
00320             aLocality = position;
00321             }
00322         else
00323             {
00324             User::Leave( KErrNotFound );   
00325             }                
00326         }                            
00327     return iDialogState;
00328     }

void CGeoPlaceSelector::LaunchWaitDialogL  )  [private]
 

Launches the Wait dialog

Definition at line 334 of file geoplaceselector.cpp.

References iDialogState, and iWaitDialog.

Referenced by SelectPlaceFromCurrentLocationL().

00335     {
00336     iWaitDialog = new ( ELeave ) CAknWaitDialog (( REINTERPRET_CAST( CEikDialog**, &iWaitDialog )), ETrue );          
00337     if( !( iWaitDialog->ExecuteLD( R_LBL_GEOPROFILES_WAITDLG_CURRENTLOCATION )))
00338         {
00339         iWaitDialog = NULL;
00340         iDialogState = KErrAbort;
00341         Cancel();    
00342         }
00343     iWaitDialog = NULL;
00344     }

void CGeoPlaceSelector::DismissWaitDialog  )  [private]
 

Dismisses the Wait dialog

Definition at line 350 of file geoplaceselector.cpp.

References iWaitDialog.

Referenced by DoCancel(), and RunL().

00351     {
00352     if ( iWaitDialog )
00353         {               
00354         TRAPD( err, iWaitDialog->ProcessFinishedL());
00355         if ( err )
00356                 {
00357                     delete iWaitDialog;                      
00358                 }
00359             iWaitDialog = NULL;
00360         } 
00361     }


Member Data Documentation

HBufC* CGeoPlaceSelector::iPlacePopupTitle [private]
 

Title text for pop-up dialog Owns

Definition at line 117 of file geoplaceselector.h.

Referenced by ConstructL(), and ~CGeoPlaceSelector().

CAknWaitDialog* CGeoPlaceSelector::iWaitDialog [private]
 

Wait dialog for obtaining current position

Definition at line 122 of file geoplaceselector.h.

Referenced by DismissWaitDialog(), and LaunchWaitDialogL().

TInt CGeoPlaceSelector::iLocAcqState [private]
 

Location Acquistion Request status

Definition at line 127 of file geoplaceselector.h.

Referenced by DoCancel(), RunL(), and SelectPlaceFromCurrentLocationL().

TInt CGeoPlaceSelector::iDialogState [private]
 

Dialog Dismissal State

Definition at line 132 of file geoplaceselector.h.

Referenced by LaunchWaitDialogL(), and SelectPlaceFromCurrentLocationL().

TBool CGeoPlaceSelector::iMapsAvailable [private]
 

Boolean variable to check whether Maps is present

Definition at line 137 of file geoplaceselector.h.

Referenced by ConstructL().

RPositionServer CGeoPlaceSelector::iServer [private]
 

Handle to Location Server

Definition at line 142 of file geoplaceselector.h.

Referenced by ConstructL(), and ~CGeoPlaceSelector().

RPositioner CGeoPlaceSelector::iPositioner [private]
 

Handle to Server session

Definition at line 147 of file geoplaceselector.h.

Referenced by ConstructL(), DoCancel(), SelectPlaceFromCurrentLocationL(), and ~CGeoPlaceSelector().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top