basiclocationinfodisplay/blid/ui/src/CBlidOwnPosLBModel.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 OwnPosView's details.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <StringLoader.h> 
       
    21 #include <AknUtils.h>
       
    22 #include <blid.rsg>
       
    23 #include <aknlocationed.h>
       
    24 
       
    25 #include "CBlidOwnPosLBModel.h"
       
    26 #include "CBlidBaseContainer.h"
       
    27 #include "MBlidLocation.h"
       
    28 #include "MBlidSettings.h"
       
    29 #include "bliduiconsts.h"
       
    30 #include "Blid.hrh"
       
    31 #include "Blidutils.h"
       
    32 #include "lbscommon.h"
       
    33 
       
    34 
       
    35 //CONSTANTS
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 // ----------------------------------------------------------------------------
       
    39 // CBlidOwnPosLBModel::NewLC
       
    40 // Two-phased constructor.
       
    41 // ----------------------------------------------------------------------------
       
    42 //
       
    43 CBlidOwnPosLBModel* CBlidOwnPosLBModel::NewLC( MBlidLocation* aLocationModel,
       
    44                                                MBlidSettings* aSettings )
       
    45     {
       
    46     CBlidOwnPosLBModel* ptr =
       
    47 		new (ELeave) CBlidOwnPosLBModel( aLocationModel, aSettings );
       
    48 	CleanupStack::PushL(ptr);
       
    49 	ptr->ConstructL();
       
    50 	return ptr;
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CBlidOwnPosLBModel::CBlidOwnPosLBModel
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // ----------------------------------------------------------------------------
       
    58 //
       
    59 CBlidOwnPosLBModel::CBlidOwnPosLBModel(MBlidLocation* aLocationModel,
       
    60                                        MBlidSettings* aSettings ):
       
    61     iLocationModel( aLocationModel ), iSettingsModel( aSettings )
       
    62     {
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // CBlidOwnPosLBModel::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 void CBlidOwnPosLBModel::ConstructL()
       
    71     {
       
    72     CEikonEnv* env = CEikonEnv::Static();
       
    73     iBuffer = HBufC::NewL( KBlidLBLineMaxLen );
       
    74 
       
    75     iLocale = new(ELeave)TLocale();
       
    76 
       
    77     /// titles  
       
    78     iBlidLatitude = StringLoader::LoadL( R_BLID_POSITION_LATITUDE, env);
       
    79     iBlidLongitude = StringLoader::LoadL( R_BLID_POSITION_LONGITUDE, env);
       
    80     iBlidAccuracy = StringLoader::LoadL( R_BLID_POSITION_ACCURACY, env);
       
    81     iBlidAltAccuracy = StringLoader::LoadL( R_BLID_POSITION_ALTITUDE_ACCURACY, env);
       
    82     //iBlidSpeed = StringLoader::LoadL( R_BLID_POSITION_SPEED, env);
       
    83     iBlidAltitude = StringLoader::LoadL( R_BLID_POSITION_ALTITUDE, env);
       
    84 
       
    85     iAccuraryFormatM = env->AllocReadResourceL( R_BLID_METRIC_METER );
       
    86     iAccuraryFormatFt = env->AllocReadResourceL( R_BLID_IMPERIAL_FOOT);
       
    87     iSpeedFormatKmph = env->AllocReadResourceL( R_BLID_METRIC_SPEED );
       
    88     iSpeedFormatMph = env->AllocReadResourceL( R_BLID_IMPERIAL_SPEED );
       
    89     iAltitudeFormatM = env->AllocReadResourceL( R_BLID_METRIC_METER );
       
    90     iAltitudeFormatFt = env->AllocReadResourceL( R_BLID_IMPERIAL_FOOT );
       
    91     iDataBeingCalculated = StringLoader::LoadL( R_BLID_CALCULATING_LIST, env);
       
    92     iConnectGPS = StringLoader::LoadL( R_BLID_CONNECT_GPS_LIST, env);
       
    93     iNotAvailable = env->AllocReadResourceL( R_BLID_NOT_AVAILABLE );
       
    94     iDataBlank = StringLoader::LoadL( R_BLID_BLANK, env);
       
    95     iWaitingGpsData = StringLoader::LoadL( R_BLID_WAITING_GPS_LIST, env);
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CBlidOwnPosLBModel::~CBlidOwnPosLBModel
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 CBlidOwnPosLBModel::~CBlidOwnPosLBModel()
       
   103     {
       
   104     delete iLocale;
       
   105 
       
   106     delete iBlidLatitude;
       
   107     delete iBlidLongitude;
       
   108     delete iBlidAltitude;
       
   109     delete iBlidAltAccuracy;
       
   110     //delete iBlidSpeed;
       
   111     delete iBlidAccuracy;
       
   112 
       
   113     delete iBuffer;
       
   114     
       
   115     delete iAccuraryFormatM;
       
   116     delete iAccuraryFormatFt;
       
   117     delete iSpeedFormatKmph;
       
   118     delete iSpeedFormatMph;
       
   119     delete iAltitudeFormatM;
       
   120     delete iAltitudeFormatFt;
       
   121     delete iDataBeingCalculated;
       
   122     delete iConnectGPS;
       
   123     delete iNotAvailable;
       
   124     delete iDataBlank;
       
   125     delete iWaitingGpsData;
       
   126     }
       
   127 
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // CBlidOwnPosLBModel::MdcaCount
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 TInt CBlidOwnPosLBModel::MdcaCount() const
       
   134     {
       
   135     return 5;
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CBlidOwnPosLBModel::MdcaPoint
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 TPtrC16 CBlidOwnPosLBModel::MdcaPoint(TInt aIndex) const
       
   143     {
       
   144     TPtr ptr( iBuffer->Des() );
       
   145     ptr.Zero();
       
   146     const TPosition position = iLocationModel->GetCurrentPosition();
       
   147     const TCourse course = iLocationModel->GetCourse();
       
   148      
       
   149     switch ( aIndex )
       
   150         {
       
   151         case ELocLatitudeItemId:
       
   152             {            
       
   153             TBuf<KBlidLBItemMaxLen> latitudeString;
       
   154             LatitudeFormat( latitudeString, position );
       
   155 
       
   156             ptr.Append( *iBlidLatitude );
       
   157             ptr.Append( EKeyTab ); 
       
   158             ptr.Append( latitudeString );
       
   159             break;
       
   160             }
       
   161         case ELocLongitudeItemId:
       
   162             {
       
   163             TBuf<KBlidLBItemMaxLen> longitudeString;
       
   164             LongitudeFormat( longitudeString, position );
       
   165 
       
   166             ptr.Append( *iBlidLongitude );
       
   167             ptr.Append( EKeyTab );
       
   168             ptr.Append( longitudeString );
       
   169             break;
       
   170             }
       
   171         case ELocAccuracyItemId:
       
   172             {
       
   173             TBuf<KBlidLBItemMaxLen> accuracyString;
       
   174             AccuracyFormat( accuracyString, position );
       
   175 
       
   176             ptr.Append( *iBlidAccuracy );
       
   177             ptr.Append( EKeyTab );
       
   178             ptr.Append( accuracyString );
       
   179             break;
       
   180             }
       
   181         case ELocAltAccuracyItemId:
       
   182             {
       
   183             TBuf<KBlidLBItemMaxLen> altAccuracyString;
       
   184             altAccuracyFormat( altAccuracyString );
       
   185                         
       
   186             ptr.Append( *iBlidAltAccuracy );
       
   187             ptr.Append( EKeyTab );
       
   188             ptr.Append( altAccuracyString );
       
   189             break;
       
   190             }
       
   191         case ELocAltitudeItemId:
       
   192             {
       
   193             TBuf<KBlidLBItemMaxLen> altitudeString;
       
   194             AltitudeFormat( altitudeString, position );
       
   195 
       
   196             ptr.Append( *iBlidAltitude );
       
   197             ptr.Append( EKeyTab );
       
   198             ptr.Append( altitudeString );
       
   199             break;
       
   200             }
       
   201         default:
       
   202             {
       
   203             break;
       
   204             }
       
   205         } //switch
       
   206 
       
   207     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
   208     return iBuffer->Des();
       
   209     }
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // CBlidOwnPosLBModel::LatitudeFormat
       
   213 // ----------------------------------------------------------------------------
       
   214 //
       
   215 void CBlidOwnPosLBModel::LatitudeFormat( TDes& aLatitudeString,
       
   216                                          TPosition aPosition ) const
       
   217     {
       
   218     TReal latitude = aPosition.Latitude();
       
   219 
       
   220     if(!CBlidBaseContainer::IsGPSAvailable() || 
       
   221        !iLocationModel->IsGPSDataAvailable() )
       
   222         {
       
   223         if(iLocationModel->WaitingGPSData())
       
   224         	{
       
   225         	aLatitudeString = *iWaitingGpsData;
       
   226         	}
       
   227         else
       
   228         	{
       
   229         	aLatitudeString = *iConnectGPS;
       
   230         	}	 	
       
   231 	 	}
       
   232 	else if ( !Math::IsNaN(latitude) )
       
   233         {    
       
   234         HBufC* formatter = NULL;                     
       
   235         TRAP_IGNORE(formatter = 
       
   236                            CAknLocationEditor::DisplayableLocationL(aPosition,CAknLocationEditor::ELatitudeOnly));
       
   237         if(formatter)  
       
   238             {
       
   239             aLatitudeString.Copy(formatter->Des());             
       
   240             delete formatter;
       
   241             }
       
   242         formatter = NULL;
       
   243         }
       
   244     else
       
   245         {   
       
   246     	aLatitudeString = *iDataBeingCalculated;
       
   247     	}    	
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // CBlidOwnPosLBModel::LongitudeFormat
       
   252 // ----------------------------------------------------------------------------
       
   253 //
       
   254 void CBlidOwnPosLBModel::LongitudeFormat( TDes& aLongitudeString,
       
   255                                           TPosition aPosition ) const
       
   256     {
       
   257     TReal longitude = aPosition.Longitude();
       
   258     
       
   259     if(!CBlidBaseContainer::IsGPSAvailable() ||
       
   260        !iLocationModel->IsGPSDataAvailable() )
       
   261         {
       
   262         aLongitudeString = *iDataBlank;
       
   263         }
       
   264     else if ( !Math::IsNaN(longitude) )
       
   265         {  
       
   266         HBufC* formatter = NULL;             
       
   267         TRAP_IGNORE(formatter = 
       
   268                            CAknLocationEditor::DisplayableLocationL(aPosition,CAknLocationEditor::ELongitudeOnly));
       
   269 
       
   270         if(formatter)  
       
   271             {
       
   272             aLongitudeString.Copy(formatter->Des());             
       
   273             delete formatter;
       
   274             }                           
       
   275         formatter = NULL;
       
   276         }
       
   277     else
       
   278     	{
       
   279    		aLongitudeString = *iDataBeingCalculated;
       
   280     	}
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // CBlidOwnPosLBModel::AccuracyFormat
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void CBlidOwnPosLBModel::AccuracyFormat( TDes& aAccuracyString,
       
   288                                          TPosition aPosition ) const
       
   289     {
       
   290     TReal accuracy = aPosition.HorizontalAccuracy();
       
   291     TInt result(0);
       
   292     
       
   293     if(!CBlidBaseContainer::IsGPSAvailable() ||
       
   294        !iLocationModel->IsGPSDataAvailable() )
       
   295         {
       
   296         aAccuracyString = *iDataBlank;
       
   297         }
       
   298     else if ( !Math::IsNaN(accuracy) &&
       
   299          BlidUtils::TRealToTInt( accuracy, result) == KErrNone )
       
   300         {        
       
   301         if ( iSettingsModel->UnitOfMeasurement() == EUnitsMetric )
       
   302             {
       
   303             StringLoader::Format( aAccuracyString, *iAccuraryFormatM,
       
   304                                   0, result );
       
   305             }
       
   306         else
       
   307             {
       
   308             if ( BlidUtils::TRealToTInt((accuracy*KMetreToFoot), 
       
   309                 result) != KErrNone )
       
   310                 {
       
   311                 aAccuracyString = *iDataBlank;
       
   312                 } 
       
   313             else
       
   314                 {
       
   315                 StringLoader::Format( aAccuracyString, *iAccuraryFormatFt, 
       
   316                                   0, result );
       
   317                 }
       
   318             }
       
   319         }
       
   320     else
       
   321     	{
       
   322       	aAccuracyString = *iDataBeingCalculated;
       
   323     	}
       
   324     }
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CBlidOwnPosLBModel::altAccuracyFormat
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 void CBlidOwnPosLBModel::altAccuracyFormat( TDes& aAltAccuracyString ) const
       
   331     {
       
   332     const TPosition position = iLocationModel->GetCurrentPosition();    
       
   333     const TReal32 altAccuracy = position.VerticalAccuracy();
       
   334     TInt result(0);
       
   335     TBuf<KBlidLBItemMaxLen> altitudeAccString;    
       
   336     AltitudeFormat(altitudeAccString, iLocationModel->GetCurrentPosition());
       
   337     
       
   338     if(!CBlidBaseContainer::IsGPSAvailable() ||
       
   339        !iLocationModel->IsGPSDataAvailable() ||
       
   340        altitudeAccString == *iDataBlank)
       
   341         {
       
   342         aAltAccuracyString = *iDataBlank;
       
   343         }    
       
   344     else if ( !Math::IsNaN(altAccuracy) &&
       
   345          BlidUtils::TRealToTInt( altAccuracy, result) == KErrNone )
       
   346         {        
       
   347         if ( iSettingsModel->UnitOfMeasurement() == EUnitsMetric )
       
   348             {
       
   349             StringLoader::Format( aAltAccuracyString, *iAccuraryFormatM,
       
   350                                   0, result );
       
   351             }
       
   352         else
       
   353             {
       
   354             if ( BlidUtils::TRealToTInt((altAccuracy*KMetreToFoot), 
       
   355                 result) != KErrNone )
       
   356                 {
       
   357                 aAltAccuracyString = *iDataBlank;
       
   358                 } 
       
   359             else
       
   360                 {
       
   361                 StringLoader::Format( aAltAccuracyString, *iAccuraryFormatFt, 
       
   362                                   0, result );
       
   363                 }
       
   364             }
       
   365         }
       
   366     else
       
   367         {
       
   368         aAltAccuracyString = *iDataBeingCalculated;
       
   369         }
       
   370     }
       
   371 
       
   372 
       
   373 // ----------------------------------------------------------------------------
       
   374 // CBlidOwnPosLBModel::AltitudeFormat
       
   375 // ----------------------------------------------------------------------------
       
   376 //
       
   377 void CBlidOwnPosLBModel::AltitudeFormat( TDes& aAltitudeString,
       
   378                                          TPosition aPosition ) const
       
   379     {
       
   380     TReal altitude = aPosition.Altitude();
       
   381     TInt result(0);
       
   382     
       
   383     if(!CBlidBaseContainer::IsGPSAvailable() || 
       
   384        !iLocationModel->IsGPSDataAvailable() )
       
   385         {
       
   386         aAltitudeString = *iDataBlank;
       
   387         }    
       
   388     else if ( !Math::IsNaN(altitude) &&
       
   389          BlidUtils::TRealToTInt((altitude - iSettingsModel->AltCalibration()),
       
   390          result) == KErrNone )
       
   391         {
       
   392         if ( iSettingsModel->UnitOfMeasurement() == EUnitsMetric )
       
   393             {
       
   394         
       
   395             StringLoader::Format( aAltitudeString, *iAltitudeFormatM, 
       
   396                                   0, result );
       
   397             }
       
   398         else
       
   399             {
       
   400             TInt imperialAlt(0);
       
   401             if ( BlidUtils::TRealToTInt((result*KMetreToFoot),
       
   402                 imperialAlt) != KErrNone )
       
   403                 {
       
   404                 aAltitudeString = *iDataBlank;
       
   405                 }
       
   406             else
       
   407                 {
       
   408                 StringLoader::Format( aAltitudeString, *iAltitudeFormatFt,
       
   409                                   0, imperialAlt );
       
   410                 }
       
   411             }
       
   412         }
       
   413     else
       
   414         {
       
   415         aAltitudeString = *iDataBlank;
       
   416         }
       
   417 
       
   418     }
       
   419 
       
   420 // End of File