Example Application Guide

 

geoprofileeditor.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 Editor
00015 *
00016 */
00017 
00018 
00019 // SYSTEM INCLUDES 
00020 #include <geoprofilesui.rsg>
00021 #include <avkon.rsg>
00022 #include <avkon.hrh>
00023 #include <eikedwin.h>
00024 #include <eikmenup.h>
00025 #include <eikenv.h>
00026 #include <stringloader.h>
00027 #include <eikaufty.h>
00028 #include <aknuniteditor.h> 
00029 #include <e32math.h>
00030 #include <barsread.h>       // For TResourceReader
00031 #include <bautils.h> 
00032 #include <eikbtgpc.h>
00033 #include <akndialog.h>
00034 #include <aknlistquerydialog.h>
00035 #include <AknLocationEd.h>
00036 #include <aknnumedwin.h>
00037 #include <Lbs.h>
00038 #include <LbsPosition.h>
00039 #include <e32math.h>
00040 #include <aknnotewrappers.h>
00041 #include <aknpopupfieldtext.h>
00042 #include <aknnotewrappers.h>
00043 
00044 // USER INCLUDES
00045 #include "geoprofileeditor.h"
00046 #include "geoprofile.h"
00047 #include "geoprofiles.hrh"
00048 #include "geoprofileselector.h"
00049 #include "geoplaceselector.h"
00050 #include "geoprofilesdebug.h"
00051 
00052 // CONSTANT DEFINTION
00053 
00054 // ---------------------------------------------------------------------------
00055 // CGeoProfileEditor::CGeoProfileEditor
00056 // ---------------------------------------------------------------------------
00057 //
00058 CGeoProfileEditor::CGeoProfileEditor( CGeoProfile&      aGeoProfile )
00059     :iGeoProfile( aGeoProfile )
00060     {
00061     }
00062 
00063 // ---------------------------------------------------------------------------
00064 // ~CGeoProfileEditor::CGeoProfileEditor
00065 // ---------------------------------------------------------------------------
00066 //
00067 CGeoProfileEditor::~CGeoProfileEditor()
00068     {
00069     delete iNewGeoProfile;
00070     }
00071 
00072 // ---------------------------------------------------------------------------
00073 // CGeoProfileEditor* CGeoProfileEditor::NewL
00074 // ---------------------------------------------------------------------------
00075 //
00076 CGeoProfileEditor* CGeoProfileEditor::NewL( CGeoProfile&      aGeoProfile )
00077     {
00078     GEOPROFILEDEBUG("+ CGeoProfilesEngine::NewL" )
00079     
00080     CGeoProfileEditor* self = new ( ELeave ) CGeoProfileEditor( aGeoProfile );
00081     CleanupStack::PushL( self );
00082     self->ConstructL();
00083     CleanupStack::Pop( self );
00084     
00085     GEOPROFILEDEBUG("- CGeoProfilesEngine::NewL" )
00086     
00087     return self;
00088     }
00089 
00090 // ---------------------------------------------------------------------------
00091 // void CGeoProfileEditor::ConstructL
00092 // ---------------------------------------------------------------------------
00093 //
00094 void CGeoProfileEditor::ConstructL()
00095     {
00096     GEOPROFILEDEBUG("+ CGeoProfilesEngine::ConstructL" )
00097     
00098     CAknForm::ConstructL( R_GEOPROFILES_EDITOR_FORM ); 
00099         
00100     // Copy the contents of Geo Profile with the orignial contents
00101     iNewGeoProfile = CGeoProfile::NewL( iGeoProfile.GeoPlaceName(),
00102                                         iGeoProfile.GeoPositionInfo(),
00103                                         iGeoProfile.GeoProfileId(),
00104                                         iGeoProfile.GeoProfileRadius(),
00105                                         iGeoProfile.TriggerId(),
00106                                         iGeoProfile.TriggerType()
00107                                         );
00108     
00109     GEOPROFILEDEBUG("- CGeoProfilesEngine::ConstructL" )    
00110     }
00111 
00112 // ---------------------------------------------------------------------------
00113 // TInt CGeoProfileEditor::ExecuteLD
00114 // ---------------------------------------------------------------------------
00115 //
00116 TInt CGeoProfileEditor::ExecuteLD()
00117     {
00118     GEOPROFILEDEBUG("CGeoProfilesEngine::ExecuteLD" )
00119     return CAknForm::ExecuteLD( R_GEOPROFILES_EDITOR_DIALOG );         
00120     }
00121 
00122 // ---------------------------------------------------------------------------
00123 // TBool CGeoProfileEditor::OkToExitL
00124 // ---------------------------------------------------------------------------
00125 //    
00126 TBool CGeoProfileEditor::OkToExitL( TInt aButtonId )
00127     {
00128     GEOPROFILEDEBUG("+ CGeoProfilesEngine::OkToExitL" )
00129     
00130     TInt retValue = EFalse;
00131     // Check for the Options Menu.
00132     switch ( aButtonId )
00133         {
00134         case EAknSoftkeyOk:
00135             {          
00136             retValue = ETrue;
00137                         
00138             if ( IsEditable())
00139                 {
00140                 
00141                 if ( !CheckIfSavableL())
00142                     {
00143                     retValue = EFalse;
00144                     }
00145                 else
00146                     {
00147                     iGeoProfile.SetGeoProfileIdL( iNewGeoProfile->GeoProfileId());
00148                     iGeoProfile.SetGeoPositionInfoL( iNewGeoProfile->GeoPlaceName(), 
00149                                                      iNewGeoProfile->GeoPositionInfo());
00150                     iGeoProfile.SetGeoProfileRadius( iNewGeoProfile->GeoProfileRadius());
00151                     iGeoProfile.SetTriggerType( iNewGeoProfile->TriggerType());                          
00152                     }                
00153                 }
00154             break;
00155             }
00156         case EAknSoftkeyCancel:
00157             {                        
00158             retValue = ETrue;
00159             break;
00160             }
00161         case EAknSoftkeyEdit:
00162             {
00163             SetEditableL( ETrue );
00164             
00165             // Set the CBA to Editable
00166             CEikButtonGroupContainer* cba   = CEikButtonGroupContainer::Current();
00167             CleanupStack::PushL( cba );
00168             
00169             TInt focusId = IdOfFocusControl();                        
00170             if ( focusId == EGeoRadius )
00171                 {
00172                 cba->SetCommandSetL ( R_GEOPROFILES_CBA_OK_CANCEL );
00173                 }
00174             else
00175                 {
00176                 cba->SetCommandSetL ( R_GEOPROFILES_CBA_OK_CANCEL_CHANGE );     
00177                 }
00178                       
00179             cba->DrawDeferred();    
00180             CleanupStack::Pop( cba );  
00181                 
00182             break;
00183             } 
00184         case EAknSoftkeyChange:
00185             {
00186             if ( IdOfFocusControl() == EGeoProfileName )
00187                 {
00188                 HandleProfileSelectionL();
00189                 }
00190             else if ( IdOfFocusControl() == EGeoPlace )
00191                 {
00192                 HandlePlaceSelectionL();    
00193                 }
00194             else if ( IdOfFocusControl() == EGeoProfileType )
00195                 {
00196                 
00197                 CAknPopupFieldText* triggerType = static_cast < CAknPopupFieldText* > ( Control( EGeoProfileType ));
00198                 if( triggerType )
00199                     {
00200                     if ( triggerType->CurrentValueIndex() == 0)
00201                         {
00202                         triggerType->SetCurrentValueIndex( 1 );
00203                         }
00204                     else
00205                         {
00206                         triggerType->SetCurrentValueIndex( 0 );    
00207                         }    
00208                     }                                 
00209                 HandleControlStateChangeL( EGeoProfileType );                
00210                 UpdatePageL( ETrue );               
00211                 }
00212             break;
00213             }
00214         case EGeoProfilesNone:
00215         default:
00216             {
00217             break;    
00218             }
00219         }
00220         
00221     GEOPROFILEDEBUG("- CGeoProfilesEngine::OkToExitL" )
00222     return retValue;
00223     }
00224 
00225 // ---------------------------------------------------------------------------
00226 // void CGeoProfileEditor::PreLayoutDynInitL
00227 // ---------------------------------------------------------------------------
00228 // 
00229 void CGeoProfileEditor::PreLayoutDynInitL()
00230     {
00231     GEOPROFILEDEBUG("+ CGeoProfilesEngine::PreLayoutDynInitL" )
00232     
00233     CAknForm::PreLayoutDynInitL();
00234     
00235     // Load the Form values 
00236     LoadFormValuesL();
00237     
00238     GEOPROFILEDEBUG("- CGeoProfilesEngine::PreLayoutDynInitL" )
00239     }
00240     
00241 // ---------------------------------------------------------------------------
00242 // void CGeoProfileEditor::LineChangedL
00243 // ---------------------------------------------------------------------------
00244 //    
00245 void CGeoProfileEditor::LineChangedL( TInt  /* aControlId */)
00246     {
00247     GEOPROFILEDEBUG("+ CGeoProfilesEngine::LineChangedL" )
00248     
00249     if ( IsEditable() )
00250         {
00251         // Set the CBA to Editable
00252         CEikButtonGroupContainer* cba   = CEikButtonGroupContainer::Current();
00253         CleanupStack::PushL( cba );
00254                     
00255         TInt focusId = IdOfFocusControl();                        
00256         if ( focusId == EGeoRadius )
00257             {
00258             cba->SetCommandSetL ( R_GEOPROFILES_CBA_OK_CANCEL );
00259             }
00260         else
00261             {
00262             cba->SetCommandSetL ( R_GEOPROFILES_CBA_OK_CANCEL_CHANGE );     
00263             }
00264                   
00265         cba->DrawDeferred();    
00266         CleanupStack::Pop( cba );         
00267         }
00268     GEOPROFILEDEBUG("- CGeoProfilesEngine::LineChangedL" )    
00269     }
00270 
00271 // ---------------------------------------------------------------------------
00272 // void CGeoProfileEditor::HandleControlStateChangeL
00273 // ---------------------------------------------------------------------------
00274 // 
00275 void CGeoProfileEditor::HandleControlStateChangeL( TInt aControlId )
00276     {
00277     GEOPROFILEDEBUG("+ CGeoProfilesEngine::HandleControlStateChangeL" )
00278     
00279     switch ( aControlId )
00280         {
00281         case EGeoRadius:
00282             {
00283             GEOPROFILEDEBUG("+ Radius" )
00284             
00285             CAknIntegerEdwin* integerEd = static_cast < CAknIntegerEdwin* > ( ControlOrNull( EGeoRadius ));
00286             if ( integerEd )
00287                 {
00288                 TInt radius = 0;
00289                 TInt error = integerEd->GetTextAsInteger( radius );
00290                 if ( CAknIntegerEdwin::EValueValid  == error )
00291                     {
00292                     iNewGeoProfile->SetGeoProfileRadius( radius );    
00293                     }
00294                 }
00295                 
00296             GEOPROFILEDEBUG("- Radius" )
00297             break;    
00298             }
00299         case EGeoProfileType:
00300             {
00301             GEOPROFILEDEBUG("+ TriggerType" )
00302             
00303             CAknPopupFieldText* triggerType = static_cast < CAknPopupFieldText* > ( Control( EGeoProfileType ));
00304             if( triggerType )
00305                 {
00306                 if ( triggerType->CurrentValueIndex() == 0)
00307                     {
00308                     iNewGeoProfile->SetTriggerType( CGeoProfile::EEntryTrigger );
00309                     }
00310                 else
00311                     {
00312                     iNewGeoProfile->SetTriggerType( CGeoProfile::EExitTrigger );    
00313                     }    
00314                 }            
00315             GEOPROFILEDEBUG("- Trigger Type" )
00316             break;    
00317             }
00318         default:
00319             {
00320             break;    
00321             }
00322         }
00323     GEOPROFILEDEBUG("- CGeoProfilesEngine::HandleControlStateChangeL" ) 
00324     }
00325 
00326 // ---------------------------------------------------------------------------
00327 // void CGeoProfileEditor::HandlePointerEventL
00328 // ---------------------------------------------------------------------------
00329 // 
00330 void CGeoProfileEditor::HandlePointerEventL( const TPointerEvent& aPointerEvent )
00331     {
00332     GEOPROFILEDEBUG("+ CGeoProfilesEngine::HandlePointerEventL" )
00333        
00334     if ( IsEditable())
00335         {
00336         CAknForm::HandlePointerEventL( aPointerEvent );         
00337         // Handle the Pointer Event  
00338         if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
00339             {
00340             switch( IdOfFocusControl())
00341                 {
00342                 case EGeoProfileName:
00343                     {
00344                     CAknForm::HandlePointerEventL( aPointerEvent );
00345                     
00346                     CEikEdwin* profile = static_cast < CEikEdwin* > ( ControlOrNull( EGeoProfileName ));
00347                     if ( profile->Rect().Contains( aPointerEvent.iPosition ) )
00348                         {
00349                         HandleProfileSelectionL();
00350                         }                
00351                     break;    
00352                     }
00353                 case EGeoPlace:
00354                     {
00355                     CAknForm::HandlePointerEventL( aPointerEvent );
00356                     CEikEdwin* place = static_cast < CEikEdwin* > ( ControlOrNull( EGeoPlace ));
00357                     if ( place->Rect().Contains( aPointerEvent.iPosition ) )
00358                         {
00359                         HandlePlaceSelectionL();
00360                         }                 
00361                     break;    
00362                     }     
00363                 default:
00364                     {
00365                     break;                    
00366                     }
00367                 }
00368             }            
00369         }
00370     else
00371         {
00372         CAknForm::HandlePointerEventL( aPointerEvent );     
00373         }        
00374     GEOPROFILEDEBUG("- CGeoProfilesEngine::HandlePointerEventL" )
00375     }
00376 
00377 // ---------------------------------------------------------------------------
00378 // void CGeoProfileEditor::LoadFormValuesL
00379 // ---------------------------------------------------------------------------
00380 //    
00381 void CGeoProfileEditor::LoadFormValuesL()
00382     {
00383     GEOPROFILEDEBUG("+ CGeoProfilesEngine::LoadFormValuesL" )
00384     
00385     // Assign the Initial Values
00386     LoadProfileL();
00387     LoadPlaceL();
00388     LoadTriggerTypeL();
00389     GEOPROFILEDEBUG("- CGeoProfilesEngine::LoadFormValuesL" )    
00390     }
00391 
00392 // ---------------------------------------------------------------------------
00393 // void CGeoProfileEditor::LoadProfileL
00394 // ---------------------------------------------------------------------------
00395 //    
00396 void CGeoProfileEditor::LoadProfileL()
00397     {
00398     GEOPROFILEDEBUG("+ CGeoProfilesEngine::LoadProfileL" )
00399     
00400     CEikEdwin* profile = static_cast < CEikEdwin* > ( ControlOrNull( EGeoProfileName ));
00401     if ( profile )
00402         {
00403         TPtrC profileName = iNewGeoProfile->ProfileName();
00404         profile->SetTextL( &profileName ); 
00405         profile->DrawDeferred();
00406         }
00407         
00408     GEOPROFILEDEBUG("- CGeoProfilesEngine::LoadProfileL" )         
00409     }
00410 
00411 // ---------------------------------------------------------------------------
00412 // void CGeoProfileEditor::LoadPlaceL
00413 // ---------------------------------------------------------------------------
00414 //    
00415 void CGeoProfileEditor::LoadPlaceL()
00416     { 
00417     GEOPROFILEDEBUG("+ CGeoProfilesEngine::LoadPlaceL" )
00418     
00419     // Load the Place field name   
00420     CEikEdwin* geoProfile = static_cast < CEikEdwin* > ( ControlOrNull( EGeoPlace ));
00421      if ( geoProfile )
00422          {
00423          TPtrC geoProfileName = iNewGeoProfile->GeoPlaceName();
00424          geoProfile->SetTextL( &geoProfileName );
00425          geoProfile->DrawDeferred();
00426          } 
00427  
00428     // Load the Radius
00429     CAknIntegerEdwin* integerEd = static_cast < CAknIntegerEdwin* > ( ControlOrNull( EGeoRadius ));
00430     if ( integerEd )
00431         {
00432         integerEd->SetValueL( iNewGeoProfile->GeoProfileRadius() );
00433         integerEd->DrawDeferred();
00434         }
00435           
00436     // Check the status of the lines and make them visible or invisible based on the Place
00437     DrawDeferred();
00438     
00439     GEOPROFILEDEBUG("- CGeoProfilesEngine::LoadPlaceL" )
00440     }
00441 
00442 // ---------------------------------------------------------------------------
00443 // void CGeoProfileEditor::LoadTriggerTypeL
00444 // ---------------------------------------------------------------------------
00445 // 
00446 void CGeoProfileEditor::LoadTriggerTypeL()
00447     {
00448     CAknPopupFieldText* triggerType = static_cast < CAknPopupFieldText* > ( Control( EGeoProfileType ));
00449     if( triggerType )
00450         {
00451         if ( iNewGeoProfile->TriggerType() == CGeoProfile::EEntryTrigger )
00452             {
00453             triggerType->SetCurrentValueIndex( 0 );
00454             }
00455         else
00456             {
00457             triggerType->SetCurrentValueIndex( 1 );    
00458             }    
00459         }
00460     DrawDeferred();   
00461     }
00462        
00463 // ---------------------------------------------------------------------------
00464 // void CGeoProfileEditor::HandleProfileSelectionL
00465 // ---------------------------------------------------------------------------
00466 // 
00467 void CGeoProfileEditor::HandleProfileSelectionL()
00468     {
00469     GEOPROFILEDEBUG("+ CGeoProfilesEngine::HandleProfileSelectionL" )
00470     
00471     // Allocate the Profile Selector class
00472     CGeoProfileSelector* profileSelector = CGeoProfileSelector::NewLC();
00473     
00474     // Launch the profile selector
00475     TInt profileId = 0;    
00476     TInt retVal = profileSelector->SelectGeoProfileL( profileId );
00477                                                       
00478     if ( !retVal )
00479         {
00480         // Profile Selection was successful. Update the Profile
00481         iNewGeoProfile->SetGeoProfileIdL( profileId );        
00482         LoadProfileL();
00483         }
00484     
00485     CleanupStack::PopAndDestroy( profileSelector );
00486     
00487     GEOPROFILEDEBUG("- CGeoProfilesEngine::HandleProfileSelectionL" )
00488     }
00489     
00490 // ---------------------------------------------------------------------------
00491 // void CGeoProfileEditor::HandlePlaceSelectionL
00492 // ---------------------------------------------------------------------------
00493 // 
00494 void CGeoProfileEditor::HandlePlaceSelectionL()
00495     {
00496     GEOPROFILEDEBUG("+ CGeoProfilesEngine::HandlePlaceSelectionL" )
00497     
00498     // Allocate the Place Selector class
00499     CGeoPlaceSelector* placeSelector = CGeoPlaceSelector::NewLC();
00500             
00501     // Launch the profile selector
00502     TInt placeType = CGeoProfile::ECoordinate;
00503     TLocality locality;
00504     
00505     // Take a temporary buffer and copy the location   
00506     HBufC* place = HBufC::NewLC( KGeoPlaceNameMaxLength );
00507     place->Des().Zero();
00508     
00509     TPtr name( place->Des());
00510     TInt retVal = KErrCancel;   
00511     TRAPD( error, retVal = placeSelector->SelectGeoPlaceL( placeType,
00512                                                   locality,
00513                                                   name ));
00514     if ( error )
00515         {
00516         // Display error note
00517         HBufC* errorString = StringLoader::LoadLC( R_LBL_GEOPROFILES_LOCATION_FAIL );
00518         CAknErrorNote* note = new( ELeave ) CAknErrorNote;
00519         note->ExecuteLD( errorString->Des());
00520         CleanupStack::PopAndDestroy( errorString );
00521         }
00522     else if ( !retVal )
00523         {
00524         // Profile Selection was successful. Update the Profile
00525         iNewGeoProfile->SetGeoPositionInfoL( place->Des(), locality );               
00526         LoadPlaceL();
00527         }
00528     CleanupStack::PopAndDestroy( place ); 
00529     CleanupStack::PopAndDestroy( placeSelector );    
00530     
00531     LoadPlaceL();
00532      
00533     GEOPROFILEDEBUG("- CGeoProfilesEngine::HandlePlaceSelectionL" )   
00534     }
00535 
00536 // ---------------------------------------------------------------------------
00537 // TInt CGeoProfileEditor::CheckIfSavableL
00538 // ---------------------------------------------------------------------------
00539 //     
00540 TInt CGeoProfileEditor::CheckIfSavableL()
00541     {
00542     GEOPROFILEDEBUG("+ CGeoProfilesEngine::CheckIfSavableL" )
00543     
00544     TInt ret = ETrue;
00545     
00546     // Check if the Name field has been filled and the Location set
00547     if ( iNewGeoProfile->GeoPositionType() == CGeoProfile::EUndefined )
00548         {
00549         HBufC* info = StringLoader::LoadLC( R_LBL_GEOPROFILES_INCOMPLETE );
00550         
00551         iInfoNote = new (ELeave) CAknInformationNote( &iInfoNote );
00552         iInfoNote->ExecuteLD( info->Des());
00553         
00554         CleanupStack::PopAndDestroy( info );
00555         ret = EFalse;
00556         }
00557         
00558     GEOPROFILEDEBUG("- CGeoProfilesEngine::CheckIfSavableL" )
00559     return ret;
00560     }

© Nokia 2009

Back to top