voipplugins/ipapputils/src/cipappphoneutils.cpp
branchRCL_3
changeset 22 d38647835c2e
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2010 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:  Utility class to phone functionality
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sysutil.h>
       
    20 #include <f32file.h>
       
    21 #include <pathinfo.h>
       
    22 
       
    23 #include "cipappphoneutils.h"
       
    24 
       
    25 const TUint8 KSVPLineFeed2 = '\n';
       
    26 const TInt KHwVersionIn3rdRow = 4;
       
    27 _LIT8( KSVPSpaceMark, " " );
       
    28 _LIT8( KSVPLineFeed, "\n" );
       
    29 _LIT( KSVPSalesModelFileName, "\\resource\\versions\\model.txt" );
       
    30 _LIT( KSVPCopyright, "©" );
       
    31 _LIT( KSVPCopyright2, "(C)" );
       
    32 _LIT( KSVPCopyright3, "(c)" );
       
    33 _LIT( KSVPSpace2, " " );
       
    34 _LIT( KSVPS60,"S60" );
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Constructor
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CIpAppPhoneUtils::CIpAppPhoneUtils()
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Constructor
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CIpAppPhoneUtils* CIpAppPhoneUtils::NewL()
       
    52     {
       
    53     CIpAppPhoneUtils* self = CIpAppPhoneUtils::NewLC();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Constructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C CIpAppPhoneUtils* CIpAppPhoneUtils::NewLC()
       
    63     {
       
    64     CIpAppPhoneUtils* self = new( ELeave ) CIpAppPhoneUtils;
       
    65     CleanupStack::PushL( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Destructor
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CIpAppPhoneUtils::~CIpAppPhoneUtils()
       
    74     {
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CIpAppPhoneUtils::GetTerminalTypeL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CIpAppPhoneUtils::GetTerminalTypeL( TDes& aTerminalType ) const
       
    82     {
       
    83     RFs fsSession;
       
    84     User::LeaveIfError( fsSession.Connect() );
       
    85     CleanupClosePushL( fsSession );
       
    86     
       
    87     GetTerminalTypeL( aTerminalType, fsSession );
       
    88     
       
    89     CleanupStack::PopAndDestroy( &fsSession );
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CIpAppPhoneUtils::GetTerminalTypeL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CIpAppPhoneUtils::GetTerminalTypeL(
       
    97         TDes& aTerminalType, RFs& aFs ) const
       
    98     {
       
    99     RBuf swVersion;
       
   100     CleanupClosePushL( swVersion );
       
   101     TInt lineFeedCount = 0;
       
   102     TBuf8< KSVPMaxTerminalTypeLength > terminalType;
       
   103 
       
   104     TBuf< KSVPMaxTerminalTypeLength > firstRow;
       
   105     TBuf< KSVPPhoneModelLength > phoneModel;
       
   106     TRAP_IGNORE( GetPhoneModelL( phoneModel, aFs ) );
       
   107 
       
   108     swVersion.CreateL( KSysUtilVersionTextLength );
       
   109     User::LeaveIfError( SysUtil::GetSWVersion( swVersion ) );
       
   110 
       
   111     const TInt swVersionLength( swVersion.Length() );
       
   112     for ( TInt i = 0; i < swVersionLength ; i++ )
       
   113         {
       
   114         if ( !lineFeedCount && ( KSVPLineFeed2 != swVersion[i] ) )
       
   115             {
       
   116             firstRow.Append( swVersion[i] );  // this is 1st row a.k.a SW-version
       
   117             }
       
   118         if ( KSVPLineFeed2 == swVersion[i] )
       
   119             {
       
   120             lineFeedCount++;
       
   121             if( lineFeedCount == 2 )
       
   122                 {
       
   123                 // Delete 1st and 2nd row.
       
   124                 swVersion.Delete( 0, i );
       
   125                 const TInt swVersionLength2( swVersion.Length() );
       
   126 
       
   127                 for ( TInt k = 0; k < swVersionLength2 ; k++ )
       
   128                     {
       
   129                     if ( KSVPLineFeed2 == swVersion[k] )
       
   130                         {
       
   131                         lineFeedCount++;
       
   132                         }
       
   133                     if ( lineFeedCount == KHwVersionIn3rdRow  )
       
   134                         {
       
   135                         // HW version is in 3rd row, delete rest of SWversion
       
   136                         const TInt charsToDelete( swVersionLength2 - k );
       
   137                         swVersion.Delete( k, charsToDelete );
       
   138                         break;
       
   139                         }
       
   140                     }
       
   141                 break;
       
   142                 }
       
   143             }
       
   144         }
       
   145 
       
   146     terminalType.Append( phoneModel );     // Add HW manufacturer, e.g. our company
       
   147     terminalType.Append( swVersion );       // Add HW version
       
   148     terminalType.Append( KSVPSpaceMark );
       
   149     terminalType.Append( firstRow );        // Add SW version
       
   150 
       
   151     // Replace linefeeds with space marks
       
   152     TInt linefeedIndex = 0;
       
   153     for ( ; KErrNotFound != linefeedIndex ; )
       
   154         {
       
   155         linefeedIndex = terminalType.Find( KSVPLineFeed );
       
   156         if ( KErrNotFound != linefeedIndex )
       
   157             {
       
   158             // 1 is the length of KSpaceMark
       
   159             terminalType.Replace( linefeedIndex, 1, KSVPSpaceMark );
       
   160             }
       
   161         }
       
   162     aTerminalType.Copy( terminalType );
       
   163     CleanupStack::PopAndDestroy( &swVersion );
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CIpAppPhoneUtils::GetPhoneModelL
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C void CIpAppPhoneUtils::GetPhoneModelL( TDes& aPhoneModel ) const
       
   172     {
       
   173     RFs fsSession;
       
   174     User::LeaveIfError( fsSession.Connect() );
       
   175     CleanupClosePushL( fsSession );
       
   176     
       
   177     GetPhoneModelL( aPhoneModel, fsSession );
       
   178     
       
   179     CleanupStack::PopAndDestroy( &fsSession );
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CIpAppPhoneUtils::GetPhoneModelL
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C void CIpAppPhoneUtils::GetPhoneModelL( TDes& aPhoneModel,
       
   187     RFs& aFs ) const
       
   188     {
       
   189     RFile file;
       
   190     TParse parse;
       
   191     parse.Set( PathInfo::RomRootPath(), NULL, NULL);
       
   192     TFileName myfile( parse.Drive() );
       
   193     myfile.Append( KSVPSalesModelFileName ); 
       
   194     User::LeaveIfError( file.Open( aFs,
       
   195         myfile, EFileShareReadersOnly | EFileRead ) );
       
   196 
       
   197     CleanupClosePushL( file );
       
   198 
       
   199     HBufC* phoneModel = HBufC::NewLC( KSVPPhoneModelLength );
       
   200     TPtr ptr = phoneModel->Des();
       
   201 
       
   202     // Read the data from file.
       
   203     TFileText reader;
       
   204     reader.Set( file );
       
   205     User::LeaveIfError( reader.Read( ptr ) );
       
   206 
       
   207     // Phone model to aPhoneModel
       
   208     aPhoneModel.Append( *phoneModel );
       
   209 
       
   210     TInt copyrightPosition = aPhoneModel.Find( KSVPCopyright );
       
   211     if ( KErrNotFound != copyrightPosition ) 
       
   212         {
       
   213         // Delete copyright mark.
       
   214         aPhoneModel.Delete( copyrightPosition, 1 );
       
   215         }
       
   216 
       
   217     copyrightPosition = aPhoneModel.Find( KSVPCopyright2 );
       
   218     if ( KErrNotFound != copyrightPosition )
       
   219         {
       
   220         // Delete copyright mark.
       
   221         aPhoneModel.Delete( copyrightPosition, KSVPCopyright2().Length() );
       
   222         }
       
   223     copyrightPosition = aPhoneModel.Find( KSVPCopyright3 );
       
   224     if ( KErrNotFound != copyrightPosition )
       
   225         {
       
   226         // Delete copyright mark.
       
   227         aPhoneModel.Delete( copyrightPosition, KSVPCopyright3().Length() );
       
   228         }
       
   229 
       
   230     TInt spacePosition = aPhoneModel.Find( KSVPSpace2 );
       
   231     TInt modelLength = aPhoneModel.Length();
       
   232 
       
   233     while ( 0 == spacePosition )
       
   234         {
       
   235         // Delete leading space character.
       
   236         aPhoneModel.Delete( 0, 1 );
       
   237         modelLength = aPhoneModel.Length();
       
   238         spacePosition = aPhoneModel.Find( KSVPSpace2 );
       
   239         }
       
   240 
       
   241     if ( ( KErrNotFound != spacePosition ) && ( 0 != spacePosition ) )
       
   242         {
       
   243         // We don't need the whole HW version, just 1st word
       
   244         aPhoneModel.Delete( spacePosition, modelLength - spacePosition );
       
   245         }
       
   246 
       
   247     if ( !modelLength )
       
   248         {
       
   249         // If manufacturer name wasn't found add platform name
       
   250         aPhoneModel.Append( KSVPS60 );
       
   251         }
       
   252 
       
   253     CleanupStack::PopAndDestroy( 2, &file ); // phoneModel, file
       
   254     }
       
   255 
       
   256 // End of file