Example Application Guide

 

geoprofilesview.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:  View class for Geo Profiles Application
00015 *
00016 */
00017 
00018 
00019 // SYSTEM INCLUDES
00020 #include <geoprofilesui.rsg>
00021 #include <eikmenup.h>
00022 #include <eikbtgpc.h>
00023 #include <Lbs.h>
00024 #include <s32mem.h>
00025 #include <aknnotewrappers.h>
00026 #include <stringloader.h>
00027 
00028 // USER INCLUDES
00029 #include "geoprofilesview.h"
00030 #include "geoprofilescontainer.h"
00031 #include "geoprofilesappui.h"
00032 #include "geoprofiles.hrh"
00033 #include "geoprofileslbmodel.h"
00034 #include "geoprofile.h"
00035 #include "geoprofileeditor.h"
00036   
00037 // CONSTANT DEFINTIONS
00038 const TUid      KGeoProfilesViewId = TUid::Uid( 1 );
00039 
00040 // ----------------- Member funtions for CGeoProfilesView class -----------------------
00041 
00042 // ---------------------------------------------------------------------------
00043 // CGeoProfilesView::CGeoProfilesView
00044 // ---------------------------------------------------------------------------
00045 //  
00046 CGeoProfilesView::CGeoProfilesView()
00047     {
00048     }
00049 
00050 // ---------------------------------------------------------------------------
00051 // CGeoProfilesView::~CGeoProfilesView
00052 // ---------------------------------------------------------------------------
00053 //  
00054 CGeoProfilesView::~CGeoProfilesView()
00055     {
00056     // Delete the container resource
00057     if ( iContainer )
00058         {
00059         AppUi()->RemoveFromViewStack( *this, iContainer );
00060         }
00061     delete iContainer;
00062     
00063     // Delete the list box model
00064     delete iLBModel;
00065     
00066     delete iEngine;
00067     
00068     // Reset And Destroy the buffer
00069     iGeoProfiles.ResetAndDestroy();
00070     iGeoProfiles.Close();
00071     
00072     }
00073 
00074 // ---------------------------------------------------------------------------
00075 // CGeoProfilesView* CGeoProfilesView::NewL
00076 // ---------------------------------------------------------------------------
00077 //        
00078 CGeoProfilesView* CGeoProfilesView::NewL()
00079     {   
00080     CGeoProfilesView* self = CGeoProfilesView::NewLC();
00081     CleanupStack::Pop( self );
00082     return self;
00083     }
00084 
00085 // ---------------------------------------------------------------------------
00086 // CGeoProfilesView* CGeoProfilesView::NewLC
00087 // ---------------------------------------------------------------------------
00088 //   
00089 CGeoProfilesView* CGeoProfilesView::NewLC()
00090     {   
00091     CGeoProfilesView* self = new ( ELeave ) CGeoProfilesView();
00092     CleanupStack::PushL( self );
00093     self->ConstructL();
00094     return self;
00095     }
00096 
00097 // ---------------------------------------------------------------------------
00098 // void CGeoProfilesView::ConstructL
00099 // ---------------------------------------------------------------------------
00100 //  
00101 void CGeoProfilesView::ConstructL()
00102     {
00103     BaseConstructL( R_GEOPROFILES_VIEW );
00104   
00105     iEngine = CGeoProfilesEngine::NewL( *this );
00106     
00107     // Fetch the list of currently available profiles
00108     iEngine->ListProfilesL( iGeoProfiles );
00109     
00110     // Allocate the List box view
00111     iLBModel = CGeoProfilesLBModel::NewL( &iGeoProfiles );
00112     
00113     // Set the Correct CBA
00114     SetCbaL();   
00115     }
00116 
00117 // ---------------------------------------------------------------------------
00118 // void CGeoProfilesView::ContainerCommandL
00119 // ---------------------------------------------------------------------------
00120 //
00121 void CGeoProfilesView::ContainerCommandL( TInt aCommand )
00122     {
00123     switch ( aCommand )
00124         {
00125         case KEikDynamicLayoutVariantSwitch:
00126             {
00127             ScreenSizeChanged();
00128             break;
00129             }
00130         case EGeoProfilesOpen:
00131             {
00132             // Get the focussed item
00133             TInt index = iContainer->GetFocussedItem();
00134             
00135             if ( index >= 0 && index < iGeoProfiles.Count())
00136                 {
00137                 CGeoProfile* profile = iGeoProfiles[ index ];
00138                 if ( profile )
00139                     {
00140                     // Launch the editor
00141                     CGeoProfileEditor* editor = CGeoProfileEditor::NewL( *profile );
00142                     if ( editor->ExecuteLD())
00143                         {
00144                         TRAPD( error, iEngine->UpdateProfileL( *profile ));
00145                         if ( error )
00146                             {
00147                             // Display error note
00148                             HBufC* errorString = StringLoader::LoadLC( R_LBL_GEOPROFILES_OPERATION_FAIL );
00149                             CAknErrorNote* note = new( ELeave ) CAknErrorNote;
00150                             note->ExecuteLD( errorString->Des());
00151                             CleanupStack::PopAndDestroy( errorString );
00152                             }                           
00153                             }                                       
00154                     }              
00155                 }                                           
00156             break;    
00157             }            
00158         default:
00159             {
00160             break;    
00161             }
00162         }
00163     }
00164 
00165 // ---------------------------------------------------------------------------
00166 // void CGeoProfilesView::ScreenSizeChanged
00167 // ---------------------------------------------------------------------------
00168 //  
00169 void CGeoProfilesView::ScreenSizeChanged()
00170         {
00171         // Request the Client container to change its rect to a new Rect
00172         if( iContainer )
00173         {
00174         iContainer->SetRect( ClientRect());     
00175         }       
00176         }
00177                         
00178 // ---------------------------------------------------------------------------
00179 // void CGeoProfilesView::DoActivateL
00180 // ---------------------------------------------------------------------------
00181 //      
00182 void CGeoProfilesView::DoActivateL( const TVwsViewId&  /* PrevViewId*/,
00183                                  TUid         /* aCustomMessageId*/,
00184                            const TDesC8&      /* aCustomMessage */)
00185     {
00186     // Destroy the existing container if it exists
00187     if( iContainer )
00188         {
00189         AppUi()->RemoveFromViewStack( *this, iContainer );
00190         delete iContainer;
00191         iContainer=NULL;
00192         }                       
00193     
00194     // Create new Container 
00195     iContainer = CGeoProfilesContainer::NewL( ClientRect(), *iLBModel, *this );
00196     iContainer->SetMopParent( this );
00197     AppUi()->AddToViewStackL( *this, iContainer );
00198     SetCbaL();          
00199     }
00200     
00201 // ---------------------------------------------------------------------------
00202 // void CGeoProfilesView::DoDeactivate
00203 // ---------------------------------------------------------------------------
00204 //           
00205 void CGeoProfilesView::DoDeactivate()
00206     {
00207     // Destroy Container
00208     if ( iContainer )
00209         {
00210         AppUi()->RemoveFromViewStack( *this, iContainer );
00211         delete iContainer;
00212         iContainer = NULL;
00213         }
00214     }
00215     
00216 // ---------------------------------------------------------------------------
00217 // TUid CGeoProfilesView::Id
00218 // ---------------------------------------------------------------------------
00219 //   
00220 TUid CGeoProfilesView::Id() const
00221     {
00222     return KGeoProfilesViewId;
00223     }
00224 
00225 // ---------------------------------------------------------------------------
00226 // void CGeoProfilesView::HandleCommandL
00227 // ---------------------------------------------------------------------------
00228 //       
00229 void CGeoProfilesView::HandleCommandL( TInt aCommand )   
00230     {
00231     // This Class only handles the Help feature. All the other events are handled
00232     // by the App UI class.
00233     switch( aCommand )
00234         {
00235         case EGeoProfilesAdd:
00236             {
00237             // Launch an empty Geo-Profile structure
00238             CGeoProfile* geoProfile = CGeoProfile::NewL();
00239             CleanupStack::PushL( geoProfile );
00240             
00241             // Launch the Editor
00242             CGeoProfileEditor* editor = CGeoProfileEditor::NewL( *geoProfile );
00243             if ( editor->ExecuteLD())
00244                 {
00245                 TRAPD( error, iEngine->AddProfileL( *geoProfile ));
00246                 if ( error )
00247                     {
00248                     // Display error note
00249                     HBufC* errorString = StringLoader::LoadLC( R_LBL_GEOPROFILES_OPERATION_FAIL );
00250                     CAknErrorNote* note = new( ELeave ) CAknErrorNote;
00251                     note->ExecuteLD( errorString->Des());
00252                     CleanupStack::PopAndDestroy( errorString );
00253                     }                   
00254                 }           
00255             // Delete the Geo-Profile object
00256             CleanupStack::PopAndDestroy( geoProfile );
00257             
00258             break;    
00259             }
00260         case EGeoProfilesOpen:
00261             {
00262             // Get the focussed item
00263             TInt index = iContainer->GetFocussedItem();
00264             
00265             if ( index >= 0 && index < iGeoProfiles.Count())
00266                 {
00267                 CGeoProfile* profile = iGeoProfiles[ index ];
00268                 if ( profile )
00269                     {
00270                     // Launch the editor
00271                     CGeoProfileEditor* editor = CGeoProfileEditor::NewL( *profile );
00272                     if ( editor->ExecuteLD())
00273                         {
00274                         TRAPD( error, iEngine->UpdateProfileL( *profile ));
00275                         if ( error )
00276                             {
00277                             // Display error note
00278                             HBufC* errorString = StringLoader::LoadLC( R_LBL_GEOPROFILES_OPERATION_FAIL );
00279                             CAknErrorNote* note = new( ELeave ) CAknErrorNote;
00280                             note->ExecuteLD( errorString->Des());
00281                             CleanupStack::PopAndDestroy( errorString );
00282                             } 
00283                             }                                       
00284                     }              
00285                 }                                           
00286             break;    
00287             }
00288         case EGeoProfilesDelete:
00289             {
00290             // Removing a profile from the list
00291             TInt index = iContainer->GetFocussedItem();
00292             if ( index >= 0 && index < iGeoProfiles.Count())
00293                 {
00294                 CGeoProfile* profile = iGeoProfiles[ index ];
00295                 if ( profile )
00296                     {
00297                     // Remove it from the Engine
00298                     TRAPD( error, iEngine->RemoveProfileL( *profile ));
00299                     if ( error )
00300                         {
00301                         // Display error note
00302                         HBufC* errorString = StringLoader::LoadLC( R_LBL_GEOPROFILES_OPERATION_FAIL );
00303                         CAknErrorNote* note = new( ELeave ) CAknErrorNote;
00304                         note->ExecuteLD( errorString->Des());
00305                         CleanupStack::PopAndDestroy( errorString );
00306                         }                                                   
00307                     }               
00308                 }           
00309             break;    
00310             }                                                               
00311         default:
00312                 {
00313                         AppUi()->HandleCommandL( aCommand );
00314                         break;          
00315                 }
00316         }
00317     }
00318 
00319 // ---------------------------------------------------------------------------
00320 // void CGeoProfilesView::DynInitMenuPaneL
00321 // ---------------------------------------------------------------------------
00322 //  
00323 void CGeoProfilesView::DynInitMenuPaneL( 
00324                                 TInt          aResourceId, 
00325                                 CEikMenuPane* aMenuPane )
00326     {
00327     switch ( aResourceId )
00328         {
00329         case R_GEOPROFILES_MENU:
00330             {
00331             if ( !iGeoProfiles.Count())
00332                 {
00333                 aMenuPane->SetItemDimmed( EGeoProfilesOpen, ETrue );
00334                 aMenuPane->SetItemDimmed( EGeoProfilesDelete, ETrue );
00335                 }
00336             break;
00337             }
00338         default:
00339             {
00340             break;    
00341             }
00342         }
00343     }
00344 
00345 // ---------------------------------------------------------------------------
00346 // void CGeoProfilesView::ProfileStatusChangedL
00347 // ---------------------------------------------------------------------------
00348 //     
00349 void CGeoProfilesView::ProfileStatusChangedL()
00350     {
00351     // Reload the profiles array
00352     iEngine->ListProfilesL( iGeoProfiles );
00353     iLBModel->UpdateModel( &iGeoProfiles );
00354     iContainer->UpdateL( *iLBModel );
00355     SetCbaL();
00356     }
00357 
00358 // ---------------------------------------------------------------------------
00359 // void CGeoProfilesView::SetCbaL
00360 // ---------------------------------------------------------------------------
00361 // 
00362 void CGeoProfilesView::SetCbaL()
00363     {
00364         if( Cba() )
00365             {
00366             if ( iGeoProfiles.Count())
00367                 {
00368                 Cba()->SetCommandSetL( R_GEOPROFILES_CBA );    
00369                 }
00370                 else
00371                     {
00372                     Cba()->SetCommandSetL( R_GEOPROFILES_CBA_EMPTY );        
00373                     }
00374                 Cba()->DrawDeferred();
00375             }       
00376     }

© Nokia 2009

Back to top