basiclocationinfodisplay/blid/ui/src/CBlidBaseView.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2005 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:  Provides Blid main view class methods.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <aknlists.h>
       
    20 #include <AknQueryDialog.h> 
       
    21 #include <StringLoader.h>
       
    22 #include <eikmenub.h> // CEikMenuBar
       
    23 #include <blid.rsg>
       
    24 #include <EPos_CPosLandmarkDatabase.h>
       
    25 #include <EPos_CPosLmItemIterator.h>
       
    26 #include <e32std.h>
       
    27 #include <CLmkEditorDlg.h>
       
    28 #include <TLmkItemIdDbCombiInfo.h>
       
    29 #include <alf/alfimageloaderutil.h>
       
    30 
       
    31 #include "CBlidBaseView.h"
       
    32 #include "CBlidAppUi.h"
       
    33 #include "CBlidBaseContainer.h"
       
    34 #include "MBlidRouter.h"
       
    35 #include "MBlidSettings.h"
       
    36 #include "MBlidLocation.h"
       
    37 #include "CBlidEng.h"
       
    38 #include "CBlidDocument.h"
       
    39 #include "Blid.hrh"
       
    40 #include "bliduiconsts.h"
       
    41 #include "CBlidCurrentPositionDlg.h"
       
    42 
       
    43 #include <locationvariationdomaincrkeys.h>
       
    44 #include <centralrepository.h>
       
    45 
       
    46 enum TPanicCode
       
    47     {
       
    48     KBlidNullPointer = 1
       
    49     };
       
    50 
       
    51 // Start with the assumption that PSY is not connected
       
    52 TInt CBlidBaseView::iPSYTimeoutCount = 0;
       
    53 TBool CBlidBaseView::iOnline = EFalse;
       
    54 
       
    55 const TInt KMiddleSKId = 3;
       
    56 
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CBlidBaseView::CBlidBaseView
       
    62 // First phase constructor, should not leave
       
    63 // ---------------------------------------------------------
       
    64 //
       
    65 CBlidBaseView::CBlidBaseView( MKeyProcessor& aKeyProcessor )
       
    66         : iKeyProcessor(aKeyProcessor)
       
    67     {
       
    68     StringLoader::Load( iManualWaypointName, R_BLID_DESTINATION_COORDINATES, iCoeEnv );
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CBlidBaseView::BaseConstructL
       
    73 // Symbian 2nd phase constructor can leave.
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 void CBlidBaseView::BaseConstructL( TInt aResId )
       
    77     {
       
    78     FeatureManager::InitializeLibL();
       
    79     CAknView::BaseConstructL( aResId ); 
       
    80 
       
    81     iEngine = static_cast<CBlidDocument*>(AppUi()->Document())->Engine();
       
    82     
       
    83     if( !iEngine->LocationModel() )
       
    84 	    {
       
    85     	iEngine->CreateModelL( CBlidEng::EBlidLocation );	    	
       
    86 	    }
       
    87     iLocation = iEngine->LocationModel();
       
    88     __ASSERT_DEBUG( iLocation, User::Panic(_L("CBlidOwnPosView"),
       
    89         KBlidNullPointer));
       
    90 
       
    91     iRouter = iEngine->RouterModel(); 
       
    92     
       
    93     iImageLoaderUtil = new (ELeave) CAlfImageLoaderUtil();
       
    94     
       
    95 	iConFileName.Zero();
       
    96 	iConFileName.Append( _L("z") );
       
    97 	iConFileName.Append( KBlidSystemIconPath );
       
    98 
       
    99 	iIsSettingsViewActive = EFalse;   
       
   100     
       
   101     __ASSERT_DEBUG( iRouter, User::Panic(_L("CBlidOwnPosView"),
       
   102         KBlidNullPointer));
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CBlidBaseView::~CLocBaseView()
       
   107 // Destructor, frees allocated resources
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 CBlidBaseView::~CBlidBaseView()
       
   111     {
       
   112     FeatureManager::UnInitializeLib();
       
   113     delete iImageLoaderUtil;
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CBlidBaseView::ProcessKeyEventL
       
   118 // Processes the key event
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 TBool CBlidBaseView::ProcessKeyEventL( const TKeyEvent& aKeyEvent,
       
   122                                       TEventCode aType )
       
   123     {
       
   124     return iKeyProcessor.ProcessKeyEventL( aKeyEvent, aType );
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CBlidBaseView::TabObserver()
       
   129 // Returns the tab observer
       
   130 // ---------------------------------------------------------
       
   131 //
       
   132 MAknTabObserver* CBlidBaseView::TabObserver()
       
   133     {
       
   134     return iKeyProcessor.TabObserver();
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CBlidBaseView::DynInitMenuPaneL
       
   139 // Called to initialize the menu pane at run time
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 void CBlidBaseView::DynInitMenuPaneL(
       
   143     TInt aResourceId, CEikMenuPane* aMenuPane )
       
   144     {
       
   145     #ifdef _DEBUG
       
   146     RDebug::Print(_L("CBlidCompassView::DynInitMenuPaneL() called"));
       
   147     #endif
       
   148     switch( aResourceId )
       
   149         { 
       
   150         case R_BLID_VIEW_MENU:
       
   151         {
       
   152             if ( !(iLocation->IsGPSDataAvailable() && 
       
   153                    iLocation->SatelliteCapability()) )
       
   154                 {                
       
   155                 aMenuPane->SetItemDimmed( EBlidCmdSatelliteStatus, ETrue );                
       
   156                 }
       
   157              if ( (!iRouter->Count()) || FeatureManager::FeatureSupported( KFeatureIdLandmarks ) )
       
   158                 {
       
   159                 aMenuPane->SetItemDimmed( EBlidCmdSavedWaypoints, ETrue );
       
   160                 }
       
   161                              
       
   162             // hide the save position.
       
   163             if(!iLocation->IsOnline())
       
   164                 {
       
   165                 aMenuPane->SetItemDimmed( EBlidCmdCurrentLocation, ETrue );
       
   166                 }
       
   167             
       
   168                 
       
   169             
       
   170         }
       
   171                 //-fallthrough
       
   172         case R_BLID_VIEW_OK_MENU:        
       
   173             {      
       
   174             if ( !iRouter->IsAnyPointSet() )
       
   175                 {
       
   176                 aMenuPane->SetItemDimmed( EBlidCmdStopNavigation, ETrue );
       
   177                 }                
       
   178             break;
       
   179             }
       
   180         case R_BLID_MAIN_MENU:
       
   181             {
       
   182             CBlidBaseView::HandleHelpFeatureL( aMenuPane );
       
   183             break;
       
   184             }
       
   185             
       
   186         case R_BLID_SET_DESTINATION_MENU:
       
   187 			{
       
   188 			if ( iRouter->Count() <= 0 )
       
   189 				{
       
   190 				aMenuPane->SetItemDimmed( EBlidCmdWaypoint, ETrue );
       
   191 				}                
       
   192 			else
       
   193 				{
       
   194 				aMenuPane->SetItemDimmed( EBlidCmdWaypoint, EFalse );	
       
   195 				}
       
   196 				
       
   197 			// Features manager checks for waypoint/landmarks variation
       
   198 			if ( FeatureManager::FeatureSupported( KFeatureIdLandmarks ) )
       
   199 				{
       
   200 				aMenuPane->SetItemDimmed( EBlidCmdWaypoint, ETrue );				
       
   201 				}
       
   202 			else
       
   203 				{
       
   204 				aMenuPane->SetItemDimmed( EBlidCmdLmk, ETrue );
       
   205 				}
       
   206 			
       
   207 			if ( FeatureManager::FeatureSupported( KFeatureIdLandmarks ) )
       
   208 			    {
       
   209     			if( IsLmAvailableL() )
       
   210     				{
       
   211     				aMenuPane->SetItemDimmed( EBlidCmdLmk, EFalse );
       
   212     				}
       
   213     			else
       
   214     				{
       
   215     				aMenuPane->SetItemDimmed( EBlidCmdLmk, ETrue );
       
   216     				}		
       
   217     			}
       
   218     			break;
       
   219     	
       
   220 			} 
       
   221         case R_BLID_SAVE_CURRENT_LOCATION_MENU:
       
   222         {
       
   223         	TInt settingsValue = 0;
       
   224             CRepository* repository = CRepository::NewL( TUid::Uid( KCRUidLocLocalVariation) );
       
   225             CleanupStack::PushL( repository );
       
   226             User::LeaveIfError( repository->Get( KLocHideCoordinates,
       
   227                                                       settingsValue ));  
       
   228             CleanupStack::PopAndDestroy( repository );
       
   229             
       
   230             if ( ELocCoordinatesHidden == settingsValue )
       
   231             {
       
   232             	 aMenuPane->SetItemDimmed( EBlidCmdShowDetails, ETrue );
       
   233             }
       
   234             else
       
   235             {
       
   236              	 aMenuPane->SetItemDimmed( EBlidCmdShowDetails, EFalse );
       
   237             }
       
   238             
       
   239             break;
       
   240         } 
       
   241         default:
       
   242             {
       
   243             break;
       
   244             }
       
   245         }
       
   246     }
       
   247 
       
   248 // ----------------------------------------------------------------------------
       
   249 // CBlidBaseView::NotifyL
       
   250 // Called by location model to notify about updates in location
       
   251 // ----------------------------------------------------------------------------
       
   252 //
       
   253 void CBlidBaseView::NotifyL( const TBool /*aOnlineMode*/ )
       
   254     {  
       
   255     if( iPopupDialog )
       
   256 	    {
       
   257 		iPopupDialog->ChangeDlgSoftKey();	    	
       
   258 	    }      
       
   259     // GPS available    
       
   260     CBlidBaseContainer::SetGPSAvailability(ETrue);
       
   261     }
       
   262 
       
   263 // ----------------------------------------------------------------------------
       
   264 // CBlidBaseView::NotifyError
       
   265 // Called by location model to notify about error in location
       
   266 // ----------------------------------------------------------------------------
       
   267 //
       
   268 void CBlidBaseView::NotifyErrorL( TInt /*aErrorCode*/ )
       
   269     {
       
   270     if( iPopupDialog )
       
   271 	    {
       
   272 		iPopupDialog->ChangeDlgSoftKey();	    	
       
   273 	    }
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------
       
   277 // CBlidBaseView::HandleHelpFeatureL
       
   278 // Handles the Help option command
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 void CBlidBaseView::HandleHelpFeatureL( CEikMenuPane* aMenuPane ) const
       
   282     {
       
   283     //implementation for req 406-917. Hide position view based on feature variation flag
       
   284     TInt helpSettingValue = ELocHelpNotHidden;
       
   285     CRepository* repository = CRepository::NewL( TUid::Uid( KCRUidLocLocalVariation) );
       
   286     CleanupStack::PushL( repository );
       
   287      User::LeaveIfError( repository->Get( KLocHideHelp,
       
   288                                               helpSettingValue ));  
       
   289     CleanupStack::PopAndDestroy( repository );
       
   290 	
       
   291 	  
       
   292     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) && !helpSettingValue)
       
   293         {
       
   294         aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse );
       
   295         }
       
   296     else
       
   297         {
       
   298         aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   299         }
       
   300     }
       
   301 
       
   302 // ----------------------------------------------------------------------------
       
   303 // CBlidBaseView::InsertWaypointL
       
   304 // Insers a waypoint
       
   305 // ----------------------------------------------------------------------------
       
   306 //
       
   307 TBool CBlidBaseView::InsertWaypointL()
       
   308     {
       
   309     TBuf<KBlidWaypointNameMaxLen> textData;
       
   310     StringLoader::Load( textData, R_BLID_WAYPOINT_NAME, iCoeEnv );
       
   311     TInt errorCode(KErrNone);	
       
   312     TBool returnValue(ETrue);
       
   313     TInt removedIndex;
       
   314     
       
   315     do
       
   316         {
       
   317         if(errorCode != KErrNone)
       
   318         	{
       
   319         	return EFalse;
       
   320         	}
       
   321         	
       
   322         CAknTextQueryDialog* dlg = new(ELeave) CAknTextQueryDialog(textData,
       
   323                                                     CAknQueryDialog::ENoTone);
       
   324         
       
   325         if (!dlg->ExecuteLD(R_BLID_WAYPOINT_QUERY))
       
   326             {
       
   327             return EFalse;           
       
   328             }
       
   329             
       
   330         }while( CheckIfExistL( textData, errorCode, removedIndex ) );
       
   331         
       
   332 		if(errorCode != KErrNone)
       
   333 				{
       
   334 				return EFalse;
       
   335 				}
       
   336 
       
   337 		/// if KMaxNumberOfWaypoints or more than that is already present
       
   338 		/// display note.
       
   339 		if ( iRouter->Count() >= KMaxNumberOfWaypoints )
       
   340 		    {
       
   341 		    static_cast<CBlidAppUi*>(AppUi()
       
   342 		        )->ShowDialogL( BlidNotes::EBlidOverWriteWaypointNote );            
       
   343 		    return EFalse;            
       
   344 		    }    
       
   345 
       
   346 		TNamedCoordinate* waypoint = new(ELeave)TNamedCoordinate();
       
   347 		CleanupStack::PushL( waypoint );
       
   348 		waypoint->SetName( textData );
       
   349 		TPosition position = iLocation->GetCurrentPosition();
       
   350 		waypoint->SetCoordinate( position.Latitude(),
       
   351 		                         position.Longitude(),
       
   352 		                         position.Altitude() );
       
   353 		position.SetHorizontalAccuracy(position.HorizontalAccuracy());
       
   354 		waypoint->SetAccuracy(position.HorizontalAccuracy());
       
   355 		//iRouter takes waypoint's ownership
       
   356 		TInt retVal = iRouter->AppendL( waypoint, ETrue);
       
   357 		if(retVal == KErrDiskFull)
       
   358 				{
       
   359 				delete waypoint;
       
   360 				BlidNotes::OutOfMemoryNoteL();
       
   361 				returnValue = EFalse;
       
   362 				}
       
   363 		CleanupStack::Pop(); //waypoint
       
   364 
       
   365 		return returnValue;
       
   366 		}
       
   367 
       
   368 // ----------------------------------------------------------------------------
       
   369 // CBlidBaseView::SelectWaypoint
       
   370 // Select a waypoint
       
   371 // ----------------------------------------------------------------------------
       
   372 //
       
   373 TInt CBlidBaseView::SelectWaypointL()
       
   374     {
       
   375     TInt index(KErrCancel);   
       
   376     TInt currentIndex(0);     
       
   377     CEikFormattedCellListBox* listBox = 
       
   378         new(ELeave)CAknSinglePopupMenuStyleListBox;
       
   379     CleanupStack::PushL( listBox );    
       
   380     
       
   381     HBufC* name = NULL;
       
   382     TInt count( iRouter->Count() );
       
   383     TNamedCoordinate* waypoint = iRouter->Waypoint();
       
   384 
       
   385     CDesCArray* array = new(ELeave)CDesCArrayFlat(KMaxNumberOfWaypoints);
       
   386     CleanupStack::PushL( array );
       
   387 
       
   388     TInt waypointAdditionCount = 0;
       
   389 	// fill up the array with waypoint's names from the engine.
       
   390 	for ( TInt i = 0; i < count; i++ )
       
   391         {
       
   392         name = iRouter->At(i).Name();
       
   393         if ( name )
       
   394             {
       
   395             CleanupStack::PushL( name );
       
   396 		    array->AppendL( *name );
       
   397 		    waypointAdditionCount ++;
       
   398 		    CleanupStack::PopAndDestroy(name); //name
       
   399             }
       
   400         else
       
   401         	{
       
   402         	currentIndex = i;
       
   403         	}
       
   404         }
       
   405 
       
   406 
       
   407     CAknPopupList* popupList = CAknPopupList::NewL( listBox,
       
   408         R_AVKON_SOFTKEYS_OK_CANCEL,
       
   409         AknPopupLayouts::EPopupSNotePopupWindow);
       
   410     CleanupStack::PushL(popupList);
       
   411 
       
   412     HBufC* title = iCoeEnv->AllocReadResourceLC( R_BLID_QUERY_WAYPOINT );
       
   413     popupList->SetTitleL( *title );
       
   414     CleanupStack::PopAndDestroy(title); //title    
       
   415     title = NULL;
       
   416     
       
   417     listBox->ConstructL( popupList, 
       
   418         EAknListBoxSelectionList | EAknListBoxLoopScrolling);
       
   419     
       
   420     listBox->CreateScrollBarFrameL(ETrue); 
       
   421     listBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
   422                                 CEikScrollBarFrame::EAuto, 
       
   423                                 CEikScrollBarFrame::EAuto);
       
   424     
       
   425     //listbox's model take ownership of array
       
   426     listBox->Model()->SetItemTextArray(array);
       
   427     
       
   428     CleanupStack::Pop(popupList); // popupList
       
   429     CleanupStack::Pop(array); //array 
       
   430     TBool isEmpty = array->Count() == 0;
       
   431         
       
   432     if ( popupList->ExecuteLD()  ) 
       
   433         {
       
   434         index = listBox->CurrentItemIndex();
       
   435         }
       
   436     CleanupStack::PopAndDestroy(listBox); //listBox
       
   437     
       
   438     if(isEmpty)
       
   439     	{
       
   440     	return KErrCancel;
       
   441     	}
       
   442     
       
   443     if(waypoint && waypointAdditionCount != iRouter->Count())   
       
   444     	{
       
   445     	if(index >= currentIndex)
       
   446     		{
       
   447     		index += 1;    				
       
   448     		}        
       
   449     	}
       
   450     if ( index != KErrCancel )
       
   451     	{
       
   452     	TNamedCoordinate waypoint = iRouter->At(index);
       
   453     	if(waypoint.Accuracy() >= KBlidPoorAccuracy)
       
   454     		{
       
   455     		HBufC* noteText = StringLoader::LoadLC( R_BLID_CONF_DEST_INACCURATE , iCoeEnv );	        		
       
   456     		CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
       
   457     		if(dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY, *noteText))
       
   458     			{
       
   459     			CleanupStack::PopAndDestroy( noteText );
       
   460     			return index;
       
   461     			}
       
   462     		else
       
   463     			{
       
   464     			CleanupStack::PopAndDestroy( noteText );
       
   465     			return KErrCancel;
       
   466     			}
       
   467     		}
       
   468     	}
       
   469     return index;
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------
       
   473 // CBlidBaseView::CheckIfExist
       
   474 // Checks if a waypoint exists
       
   475 // ---------------------------------------------------------
       
   476 //
       
   477 TBool CBlidBaseView::CheckIfExistL( const TDes& aName, TInt& aErrorCode, TInt& aRemovedIndex )
       
   478     {
       
   479     TInt i(0);
       
   480     TInt count( iRouter->Count() );
       
   481     HBufC* name = NULL;
       
   482     TBool retVal;
       
   483 	aRemovedIndex = KErrNotFound;
       
   484 
       
   485     for ( i = 0; i < count; i++ )
       
   486         {
       
   487         name = iRouter->At( i ).Name();
       
   488         if ( name && name->Compare( aName ) == 0 )
       
   489             {
       
   490             CleanupStack::PushL(name);
       
   491             HBufC* text;
       
   492             text = StringLoader::LoadLC(R_BLID_QUERY_WAYPOINT_NAME_EXISTS,
       
   493                                        *name,
       
   494                                        iCoeEnv);
       
   495                                     
       
   496             CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   497             CleanupStack::PushL(dlg);
       
   498             dlg->SetPromptL( *text ); 
       
   499             CleanupStack::Pop( dlg );           
       
   500             retVal = dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY);            
       
   501             
       
   502             if(retVal)
       
   503                 {
       
   504                 TInt retVal = iRouter->RemoveL(i);
       
   505 				aRemovedIndex = i;
       
   506                 if(retVal == KErrDiskFull)
       
   507 		        	{
       
   508 		        	aErrorCode = KErrDiskFull;
       
   509 		        	BlidNotes::OutOfMemoryNoteL();
       
   510 		        	}
       
   511                 }
       
   512             CleanupStack::PopAndDestroy(2); //name and text
       
   513             return !retVal;
       
   514             }
       
   515         delete name;
       
   516         name = NULL;
       
   517         }
       
   518     return EFalse;
       
   519     }
       
   520 
       
   521 // ----------------------------------------------------
       
   522 // CBlidBaseView::LaunchLandmarksDialogL
       
   523 // Launch the landmarks dialog
       
   524 // ----------------------------------------------------
       
   525 //
       
   526 TInt CBlidBaseView::LaunchLandmarksDialogL()
       
   527     {
       
   528     CPosLandmarkDatabase* lDb = NULL;
       
   529     TPosLmItemId selectedItem;
       
   530     iLandmarkInfo = CLmkLandmarkSelectorDlg::NewL();    
       
   531     iLandmarkInfo->SetMopParent(this);
       
   532     TLmkItemIdDbCombiInfo* selected = new (ELeave) TLmkItemIdDbCombiInfo();
       
   533     CleanupStack::PushL(selected);
       
   534     TInt retVal = iLandmarkInfo->ExecuteLD( *selected );
       
   535     if( retVal != KErrNone )
       
   536 	    {	       	
       
   537 	    selectedItem = selected->GetItemId();
       
   538 	    lDb = selected->GetLmDb();
       
   539 	    if(lDb)
       
   540 	    	{
       
   541 	    	CleanupStack::PushL( lDb );
       
   542 	    	CPosLandmark *landmarkInfo = lDb->ReadLandmarkLC(selectedItem);
       
   543 	        CleanupStack::PushL( landmarkInfo );
       
   544 	        CPosLandmark* landMark = CPosLandmark::NewL(*landmarkInfo);
       
   545 	        CleanupStack::Pop( landmarkInfo );
       
   546 	        TLocality lmkPosition;
       
   547 	        TInt error = landMark->GetPosition(lmkPosition);
       
   548 	        if( Math::IsNaN(lmkPosition.Latitude()) || 
       
   549 	        	Math::IsNaN(lmkPosition.Longitude()) )
       
   550 	        	{
       
   551 	        	TPtrC landmarkname;
       
   552 	        	landMark->GetLandmarkName(landmarkname);
       
   553                 // Fix done for TSW error EPZO-75PBW8
       
   554                 HBufC* lmkName = NULL;
       
   555                 lmkName = HBufC::NewL( landmarkname.Length() );
       
   556                 lmkName->Des().Copy( landmarkname );
       
   557                 TPtr lmkActualName( lmkName->Des() );
       
   558                 TBuf<1> charsToRemove;
       
   559                 charsToRemove.Append(TChar(TInt(CEditableText::EParagraphDelimiter)));
       
   560                 AknTextUtils::ReplaceCharacters( lmkActualName, charsToRemove, TChar(TInt(CEditableText::ESpace)));
       
   561 	        	BlidNotes::EmptyLandmarkNoteL( *lmkName );
       
   562 	        	delete lmkName;
       
   563                 // end of error fix.
       
   564 	        	delete landMark;
       
   565 	        	retVal = 0;
       
   566 	        	}
       
   567 	        else
       
   568 	        	{
       
   569 	            TLocality lmkPosition;
       
   570 	        	landMark->GetPosition(lmkPosition);
       
   571 	        	TReal accuracy = lmkPosition.HorizontalAccuracy();
       
   572 	        	if(accuracy >= KBlidPoorAccuracy)
       
   573 	        		{	        		
       
   574 	        		HBufC* noteText = StringLoader::LoadLC( R_BLID_CONF_DEST_INACCURATE , iCoeEnv );	        		
       
   575 	        		CAknQueryDialog* dlg = CAknQueryDialog::NewL(CAknQueryDialog::ENoTone);
       
   576 	        		if(dlg->ExecuteLD(R_BLID_CONFIRMATION_QUERY, *noteText))
       
   577 	        			{
       
   578 	        			iRouter->SetLandmark(landMark);	        			
       
   579 	        			}
       
   580 	        		else
       
   581 	        			{
       
   582 	        			delete landMark;
       
   583 	        			}
       
   584 	        		CleanupStack::PopAndDestroy(noteText);
       
   585 	        		}
       
   586 	        	else
       
   587 	        		{
       
   588 	        		iRouter->SetLandmark(landMark);
       
   589 	        		}	        	
       
   590 
       
   591 	        	}
       
   592 	    	CleanupStack::PopAndDestroy(1); // ReadLandmarkLC
       
   593 	    	landMark = NULL;
       
   594 	    	landmarkInfo = NULL;
       
   595 	    	CleanupStack::PopAndDestroy( lDb );
       
   596 	    	}
       
   597 	    }
       
   598 	CleanupStack::Pop(1); //selectedItem
       
   599 	iLandmarkInfo = NULL;
       
   600 	delete selected;
       
   601 	return retVal;	
       
   602     }
       
   603 
       
   604 // ----------------------------------------------------------------------------
       
   605 // CBlidBaseView::SaveCurrentPositionAsLandmarkL
       
   606 // Called to save the current location as a landmark in landmark database
       
   607 // ----------------------------------------------------------------------------
       
   608 //
       
   609 void CBlidBaseView::SaveCurrentPositionAsLandmarkL()
       
   610     {
       
   611     CLmkEditorDlg::TLmkEditorParams editParams; 
       
   612 	editParams.iAttributes = CLmkEditorDlg::ELmkAll;
       
   613 	editParams.iEditorMode = CLmkEditorDlg::ELmkEditor;
       
   614 	
       
   615 	TPosition position = iLocation->GetCurrentPosition();
       
   616     
       
   617     CPosLandmark* landmark = CPosLandmark::NewLC();
       
   618     TLocality location;
       
   619     location.SetCoordinate(position.Latitude(),
       
   620     					   position.Longitude(),
       
   621     					   position.Altitude());
       
   622     location.SetHorizontalAccuracy(position.HorizontalAccuracy());
       
   623     location.SetVerticalAccuracy(position.VerticalAccuracy());
       
   624     
       
   625     landmark->SetPositionL(location);
       
   626     CPosLandmarkDatabase* db = CPosLandmarkDatabase::OpenL();
       
   627     CleanupStack::PushL(db);
       
   628     
       
   629     CPosLmOperation* operation = db->InitializeL();
       
   630 	CleanupStack::PushL(operation);
       
   631 	operation->ExecuteL();	
       
   632     CLmkEditorDlg *dlg = CLmkEditorDlg::NewL(*db, 
       
   633                                              *landmark, 
       
   634                                              editParams);
       
   635 	dlg->ExecuteLD();
       
   636 	CleanupStack::PopAndDestroy(3); // landmark, operation and db
       
   637     }
       
   638 
       
   639 // ----------------------------------------------------------------------------
       
   640 // CBlidBaseView::LaunchManualWaypointDialogL
       
   641 // Launches the manual waypoint dialog
       
   642 // ----------------------------------------------------------------------------
       
   643 //    
       
   644 TInt CBlidBaseView::LaunchManualWaypointDialogL()
       
   645     {    
       
   646     TInt retVal;    
       
   647     TCoordinate coord(0,0);
       
   648     TLocality loc(coord,0);    
       
   649     TTime time;
       
   650     time.HomeTime();
       
   651     TPosition pos(loc, time); 
       
   652 
       
   653     CAknMultiLineDataQueryDialog* dlg = CAknMultiLineDataQueryDialog::NewL(pos);
       
   654     retVal = dlg->ExecuteLD(R_BLID_MANUAL_LOCATION_QUERY_DIALOG);
       
   655     if( retVal )
       
   656 	    {	    
       
   657 	    iRouter->SetManualWaypoint(pos.Latitude(), pos.Longitude(), iManualWaypointName);	
       
   658 	    }
       
   659     return retVal;
       
   660     }
       
   661 
       
   662 // ----------------------------------------------------------------------------
       
   663 // CBlidBaseView::Update
       
   664 // ----------------------------------------------------------------------------
       
   665 //    
       
   666 void CBlidBaseView::Update(CBlidBaseContainer* aContainer)
       
   667     {
       
   668     aContainer->SetRect(ClientRect());
       
   669     aContainer->DrawNow();
       
   670     }
       
   671 
       
   672 // ----------------------------------------------------------------------------
       
   673 // CBlidBaseView::CBAPtr
       
   674 // Returns the current CBA
       
   675 // ----------------------------------------------------------------------------
       
   676 //    
       
   677 CEikButtonGroupContainer* CBlidBaseView::CBAPtr() const
       
   678     {
       
   679     return (Cba());
       
   680     }
       
   681     
       
   682 // ----------------------------------------------------------------------------
       
   683 // CBlidBaseView::SetMiddleSoftKeyLabelL
       
   684 // Sets the Middle Soft Key label.
       
   685 // ----------------------------------------------------------------------------
       
   686 //    
       
   687 void CBlidBaseView::SetMiddleSoftKeyLabelL(
       
   688     const TInt aResourceId,
       
   689     const TInt aCommandId )   
       
   690     {
       
   691     CEikButtonGroupContainer* cbaGroup = Cba();
       
   692     if ( cbaGroup )
       
   693         {
       
   694         HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
   695         cbaGroup->AddCommandToStackL(KMiddleSKId, 
       
   696                                      aCommandId, 
       
   697                                      *middleSKText );
       
   698         CleanupStack::PopAndDestroy( middleSKText );
       
   699         }
       
   700     }
       
   701 
       
   702 // ----------------------------------------------------------------------------
       
   703 // CBlidBaseView::RemoveMiddleSoftKeyLabel
       
   704 // Remove the Middle Soft Key label.
       
   705 // ----------------------------------------------------------------------------
       
   706 //    
       
   707 void CBlidBaseView::RemoveMiddleSoftKeyLabel( const TInt aCommandId )   
       
   708     {
       
   709     CEikButtonGroupContainer* cbaGroup = Cba();
       
   710     if ( cbaGroup )
       
   711         {
       
   712         cbaGroup->RemoveCommandFromStack(KMiddleSKId, 
       
   713                                      aCommandId );
       
   714         }
       
   715     }
       
   716     
       
   717 // ----------------------------------------------------------------------------
       
   718 // CBlidBaseView::SetMSKDimmed
       
   719 // Sets the Middle Soft Key as not visible.
       
   720 // ----------------------------------------------------------------------------
       
   721 //     
       
   722 void CBlidBaseView::SetMSKNotVisible()    
       
   723     {
       
   724     CEikButtonGroupContainer* cbaGroup = Cba();
       
   725     if ( cbaGroup )
       
   726         {
       
   727         cbaGroup->MakeCommandVisible(EAknSoftkeyContextOptions, EFalse);
       
   728         iMSKVisible = EFalse;
       
   729         }
       
   730     }
       
   731     
       
   732 // ----------------------------------------------------------------------------
       
   733 // CBlidBaseView::SetMSKVisible
       
   734 // Sets the Middle Soft Key as visible.
       
   735 // ----------------------------------------------------------------------------
       
   736 //     
       
   737 void CBlidBaseView::SetMSKVisible()    
       
   738     {
       
   739     CEikButtonGroupContainer* cbaGroup = Cba();
       
   740     if ( cbaGroup )
       
   741         {
       
   742         cbaGroup->MakeCommandVisible(EAknSoftkeyContextOptions, ETrue);
       
   743         iMSKVisible = ETrue;
       
   744         }
       
   745     }   
       
   746 
       
   747 // ----------------------------------------------------------------------------
       
   748 // CBlidBaseView::UpdateMskStateL
       
   749 // Update Middle Soft Key label/Icon.
       
   750 // ----------------------------------------------------------------------------
       
   751 // 
       
   752 void CBlidBaseView::UpdateMskStateL()    
       
   753     {
       
   754     if (!iLocation->IsGPSDataAvailable())        
       
   755         {
       
   756         SetMSKNotVisible();
       
   757         }
       
   758     else
       
   759         {
       
   760         if(!iMSKVisible)
       
   761             {
       
   762             SetMSKVisible(); 
       
   763             MenuBar()->SetContextMenuTitleResourceId(
       
   764                                                      R_BLID_OWN_POS_VIEW_OK_MENUBAR);               
       
   765             }
       
   766         }
       
   767     }
       
   768 
       
   769 #ifdef RD_SCALABLE_UI_V2    
       
   770 // ---------------------------------------------------------------------------
       
   771 // CBlidBaseView::HandleListBoxEventL
       
   772 // Handles listbox item selection
       
   773 // ---------------------------------------------------------------------------
       
   774 //
       
   775 void CBlidBaseView::HandleListBoxEventL(
       
   776     CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   777     {
       
   778     switch ( aEventType )
       
   779         {
       
   780         case EEventEnterKeyPressed:
       
   781         case EEventItemSingleClicked:
       
   782             HandleListBoxSelectionL();
       
   783             break;
       
   784         default:
       
   785            break;
       
   786         }
       
   787     }  
       
   788     
       
   789 #endif //RD_SCALABLE_UI_V2      
       
   790 // ---------------------------------------------------------------------------
       
   791 // CBlidBaseView::IsLmFeatureAvailable
       
   792 // Checks if Landmarks feature i available
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 TBool CBlidBaseView::IsLmFeatureAvailable()    
       
   796     {
       
   797     return FeatureManager::FeatureSupported( KFeatureIdLandmarks );
       
   798     } 
       
   799     
       
   800 // ---------------------------------------------------------------------------
       
   801 // CBlidBaseView::IsLmAvailableL
       
   802 // Checks if there are any landmarks in the default database
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 TBool CBlidBaseView::IsLmAvailableL()    
       
   806     {
       
   807     TBool lResult = ETrue;
       
   808 	// Check if there are any landmarks present. If not the
       
   809 	// dim the landmark item from the set destination menu pane
       
   810 	CPosLandmarkDatabase* lmkDb;
       
   811 	lmkDb = CPosLandmarkDatabase::OpenL();			
       
   812 	CleanupStack::PushL(lmkDb);
       
   813 	// Initialize Landmarks data base if required			
       
   814 	CPosLmOperation* operation = lmkDb->InitializeL();
       
   815 	CleanupStack::PushL(operation);			
       
   816 	operation->ExecuteL();
       
   817 	CPosLmItemIterator* iterator = lmkDb->LandmarkIteratorL();
       
   818 	CleanupStack::PushL(iterator);
       
   819 	
       
   820 	if( iterator->NumOfItemsL() == 0 )
       
   821         {
       
   822         lResult = EFalse;        
       
   823         }
       
   824     else
       
   825         {
       
   826         lResult = ETrue;
       
   827         }
       
   828     CleanupStack::PopAndDestroy(3); //lmkDb, iterator and operation                
       
   829     return lResult;        
       
   830     } 
       
   831     
       
   832 // ---------------------------------------------------------------------------
       
   833 // CBlidBaseView::IsWpAvailable
       
   834 // Checks if waypoints are available
       
   835 // ---------------------------------------------------------------------------
       
   836 //
       
   837 TBool CBlidBaseView::IsWpAvailable()    
       
   838     {
       
   839     if ( iRouter->Count() <= 0 )
       
   840         {
       
   841         return EFalse;        
       
   842         }
       
   843     return ETrue;
       
   844     }         
       
   845        
       
   846 
       
   847 // ----------------------------------------------------------------------------
       
   848 // CBlidBaseView::ActivateCorrectViewL
       
   849 // Activates the view
       
   850 // ----------------------------------------------------------------------------
       
   851 //
       
   852 void CBlidBaseView::ActivateCorrectViewL( TInt aIndex )
       
   853 	{
       
   854     switch( aIndex )
       
   855         {
       
   856         case EBlidNavigationViewId:
       
   857             {
       
   858             AppUi()->ActivateLocalViewL( TUid::Uid( EBlidNavigationView ) );
       
   859             break;
       
   860             }
       
   861         case EBlidTripMeterViewId:
       
   862             {
       
   863             AppUi()->ActivateLocalViewL( TUid::Uid( EBlidTripMeterView ) );
       
   864             break;
       
   865             }
       
   866         default:
       
   867             break;
       
   868         }
       
   869 	}
       
   870 
       
   871 
       
   872 // ----------------------------------------------------------------------------
       
   873 // CBlidBaseView::ShowCurrentPositionInfoL
       
   874 // Launches the current position dialog
       
   875 // ----------------------------------------------------------------------------
       
   876 //
       
   877 void CBlidBaseView::ShowCurrentPositionInfoL()
       
   878 	{
       
   879 	iPopupDialog = CBlidCurrentPositionDlg::NewL( *this, iLocation, iEngine );
       
   880 	iPopupDialog->ExecuteLD();
       
   881 	iPopupDialog = NULL;
       
   882 	}
       
   883 
       
   884 // ----------------------------------------------------------------------------
       
   885 // CBlidBaseView::SaveCurrentPositionL
       
   886 // Saves current position as landmark or as waypoint
       
   887 // ----------------------------------------------------------------------------
       
   888 //
       
   889 void CBlidBaseView::SaveCurrentPositionL()
       
   890 	{
       
   891 	if ( !FeatureManager::FeatureSupported( KFeatureIdLandmarks ) )
       
   892 		{
       
   893 		if ( InsertWaypointL() )
       
   894             {
       
   895             static_cast<CBlidDocument*>(AppUi()->Document())->SaveL();
       
   896             }
       
   897 		}
       
   898 	else
       
   899 		{
       
   900 		SaveCurrentPositionAsLandmarkL();
       
   901 		}
       
   902 	}
       
   903 
       
   904 // ----------------------------------------------------
       
   905 // CBlidBaseView::BlidDocument
       
   906 // Returns the Location document object.
       
   907 // ----------------------------------------------------
       
   908 //
       
   909 CBlidDocument* CBlidBaseView::BlidDocument()
       
   910     {
       
   911     // Explicit cast: the document must always be of type CBlidDocument
       
   912     return static_cast<CBlidDocument*>(AppUi()->Document());
       
   913     }
       
   914 
       
   915 // ----------------------------------------------------------------------------
       
   916 // CBlidBaseView::ActivateSatelliteViewL
       
   917 // Activates the Satellite view
       
   918 // ----------------------------------------------------------------------------
       
   919 //
       
   920 void CBlidBaseView::ActivateSatelliteViewL( )
       
   921 	{
       
   922 	AppUi()->ActivateLocalViewL( TUid::Uid( EBlidMainSatelliteView ) );
       
   923 	}
       
   924 	
       
   925 // ----------------------------------------------------------------------------
       
   926 // CBlidBaseView::IsSatViewActive
       
   927 // Checks if Satellite view is active
       
   928 // ----------------------------------------------------------------------------
       
   929 //
       
   930 TBool CBlidBaseView::IsSatViewActive( )
       
   931 	{
       
   932 	return (static_cast<CBlidAppUi*>(AppUi()))->IsSatelliteViewActive();
       
   933 	}
       
   934 
       
   935 // ----------------------------------------------------------------------------
       
   936 // CBlidBaseView::IsForeGroundApp
       
   937 // Checks if Blid app is in foreground
       
   938 // ----------------------------------------------------------------------------
       
   939 //
       
   940 TBool CBlidBaseView::IsForeGroundApp( )
       
   941 	{
       
   942 	return ( static_cast<CBlidAppUi*>(AppUi())->IsForeground() );
       
   943 	}
       
   944 	
       
   945 // ----------------------------------------------------------------------------
       
   946 // CBlidBaseView::ExitMainApplicationL
       
   947 // Exit the application
       
   948 // ----------------------------------------------------------------------------
       
   949 //
       
   950 void CBlidBaseView::ExitMainApplicationL( TInt aButtonId )
       
   951 	{
       
   952 	static_cast<CBlidAppUi*>(AppUi())->HandleCommandL( aButtonId );
       
   953 	}
       
   954 	
       
   955 // ----------------------------------------------------------------------------
       
   956 // CBlidBaseView::LaunchTripContextMenuL
       
   957 // Launches the context menu for tripmeter view
       
   958 // ----------------------------------------------------------------------------
       
   959 //
       
   960 void CBlidBaseView::LaunchTripContextMenuL()
       
   961 	{
       
   962     CEikMenuBar* menubar = static_cast<CAknViewAppUi*>
       
   963         (iAvkonAppUi)->View(TUid::Uid( EBlidTripMeterView ))->MenuBar();
       
   964     if ( menubar )
       
   965         {
       
   966         menubar->SetContextMenuTitleResourceId(R_BLID_TRIP_METER_VIEW_OK_MENUBAR);
       
   967         menubar->TryDisplayContextMenuBarL();
       
   968         }
       
   969 	}
       
   970 
       
   971 // ----------------------------------------------------------------------------
       
   972 // CBlidBaseView::LaunchNavigationContextMenuL
       
   973 // Launches the context menu for Navigation view
       
   974 // ----------------------------------------------------------------------------
       
   975 //
       
   976 void CBlidBaseView::LaunchNavigationContextMenuL()
       
   977 	{
       
   978     CEikMenuBar* menubar = static_cast<CAknViewAppUi*>
       
   979         (iAvkonAppUi)->View(TUid::Uid( EBlidNavigationView ))->MenuBar();
       
   980         
       
   981     if ( menubar )
       
   982         {
       
   983         menubar->SetContextMenuTitleResourceId(R_BLID_VIEW_OK_MENUBAR);
       
   984         menubar->StopDisplayingMenuBar();
       
   985         menubar->TryDisplayContextMenuBarL();                         
       
   986         }
       
   987 	}
       
   988 
       
   989 // ----------------------------------------------------------------------------
       
   990 // CBlidBaseView::LaunchSatelliteInfoDlgL
       
   991 // Launches the Satellite info dialog
       
   992 // ----------------------------------------------------------------------------
       
   993 //
       
   994 void CBlidBaseView::LaunchSatelliteInfoDlgL()
       
   995 	{
       
   996 	static_cast<CBlidAppUi*>(AppUi())->LaunchSatelliteInfoDlgL( );
       
   997 	}
       
   998 	
       
   999 // ----------------------------------------------------------------------------
       
  1000 // CBlidBaseView::ActivateNavigationViewL
       
  1001 // Activates the navigation view
       
  1002 // ----------------------------------------------------------------------------
       
  1003 //
       
  1004 void CBlidBaseView::ActivateNavigationViewL( )
       
  1005 	{
       
  1006 	AppUi()->ActivateLocalViewL( TUid::Uid( EBlidNavigationView ) );
       
  1007 	}
       
  1008 	
       
  1009 // ----------------------------------------------------------------------------
       
  1010 // CBlidBaseView::ChangeViewSoftKeyL
       
  1011 // Changes the soft key
       
  1012 // ----------------------------------------------------------------------------
       
  1013 //
       
  1014 void CBlidBaseView::ChangeViewSoftKeyL( )
       
  1015 	{
       
  1016 	CBAPtr()->SetCommandSetL( R_BLID_SOFTKEYS_INFO_EXIT );
       
  1017 	CBAPtr()->DrawDeferred();
       
  1018 	}	
       
  1019 
       
  1020 // ----------------------------------------------------------------------------
       
  1021 // CBlidBaseView::ApplicationRect
       
  1022 // Returns the application rect
       
  1023 // ----------------------------------------------------------------------------
       
  1024 //
       
  1025 TRect CBlidBaseView::ApplicationRect( ) const
       
  1026 	{
       
  1027 	return AppUi()->ApplicationRect();
       
  1028 	}	
       
  1029 
       
  1030 // ----------------------------------------------------------------------------
       
  1031 // CBlidBaseView::ImageLoaderUtils
       
  1032 // Returns the image loader utils
       
  1033 // ----------------------------------------------------------------------------
       
  1034 //
       
  1035 CAlfImageLoaderUtil* CBlidBaseView::ImageLoaderUtils( ) const
       
  1036 	{
       
  1037 	return iImageLoaderUtil;
       
  1038 	}
       
  1039 	
       
  1040 // ----------------------------------------------------------------------------
       
  1041 // CBlidBaseView::ImagePathName
       
  1042 // Returns the image path
       
  1043 // ----------------------------------------------------------------------------
       
  1044 //
       
  1045 TFileName CBlidBaseView::ImagePathName( ) const
       
  1046 	{
       
  1047 	return iConFileName;
       
  1048 	}	
       
  1049 
       
  1050 // ----------------------------------------------------------------------------
       
  1051 // CBlidBaseView::IsSettingsViewActive
       
  1052 // Checks if settings view is active
       
  1053 // ----------------------------------------------------------------------------
       
  1054 //
       
  1055 TBool CBlidBaseView::IsSettingsViewActive()
       
  1056 	{
       
  1057 	return iIsSettingsViewActive;
       
  1058 	}
       
  1059 
       
  1060 // ----------------------------------------------------------------------------
       
  1061 // CBlidBaseView::CoeEnv
       
  1062 // Returns the control environment
       
  1063 // ----------------------------------------------------------------------------
       
  1064 //
       
  1065 CCoeEnv* CBlidBaseView::CoeEnv()
       
  1066 	{
       
  1067 	return iCoeEnv;
       
  1068 	}
       
  1069 // End of File
       
  1070