radioengine/utils/src/radioengineutils.cpp
changeset 38 f8c3d4e6102c
parent 28 075425b8d9a4
equal deleted inserted replaced
36:ba22309243a1 38:f8c3d4e6102c
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <StringLoader.h>
    19 #include <StringLoader.h>
    20 #include <utf.h>
       
    21 
    20 
    22 // User includes
    21 // User includes
    23 #include "radioengineutils.h"
    22 #include "radioengineutils.h"
    24 #include "cradioenginetls.h"
    23 #include "cradioenginetls.h"
    25 
    24 
    57 //
    56 //
    58 EXPORT_C RFs& RadioEngineUtils::FsSession()
    57 EXPORT_C RFs& RadioEngineUtils::FsSession()
    59     {
    58     {
    60     return CRadioEngineTls::Instance().FsSession();
    59     return CRadioEngineTls::Instance().FsSession();
    61     }
    60     }
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Utility method for frequency formatting.
       
    65 // Frequency is assumed to be in kilohertz format.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C HBufC* RadioEngineUtils::ReadFrequencyStringLC( TUint32 aFreq,
       
    69                                                          TInt aDecimalCount,
       
    70                                                          TInt aResourceId )
       
    71     {
       
    72     TBuf<KDefaultRealWidth> freqText;
       
    73     freqText.AppendNum( static_cast<TReal>( aFreq ) / 1000.0f, TRealFormat( KDefaultRealWidth, aDecimalCount ) ); // Converts kilohertz to megahertz.
       
    74 
       
    75     // Converts the numbers to the proper display mode.
       
    76 
       
    77     HBufC* channelFreq = NULL;
       
    78 
       
    79     if ( aResourceId == KErrNotFound ) // No resource string.
       
    80         {
       
    81         channelFreq = freqText.AllocLC();
       
    82         }
       
    83     else
       
    84         {
       
    85         channelFreq = StringLoader::LoadLC( aResourceId, freqText );
       
    86         }
       
    87 
       
    88     return channelFreq;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void RadioEngineUtils::FormatFrequencyString( TDes& aDest,
       
    96                                                        TUint32 aFreq,
       
    97                                                        TInt aDecimalCount,
       
    98                                                        TDesC& aFormat )
       
    99     {
       
   100     TBuf<KDefaultRealWidth> freqText;
       
   101     freqText.AppendNum( static_cast<TReal>( aFreq ) / 1000.0f, TRealFormat( KDefaultRealWidth, aDecimalCount ) ); // Converts kilohertz to megahertz.
       
   102 
       
   103     // Converts the numbers to the proper display mode.
       
   104 
       
   105     if ( aFormat.Length() <= 0 || freqText.Length() > aDest.MaxLength() ) // No format.
       
   106         {
       
   107         aDest.Copy( freqText.Left( aDest.Length() ) );
       
   108         }
       
   109     else
       
   110         {
       
   111         StringLoader::Format( aDest, aFormat, KErrNotFound, freqText );
       
   112         }
       
   113     }
       
   114