radioapp/radiopresetstorage/src/radiopresetstorage.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 16 f54ebcfc1b80
parent 33 11b6825f0862
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
    20 #include <presetutility.h>
    19 #include <presetutility.h>
    21 #include <preset.h>
    20 #include <preset.h>
    22 #else
       
    23 #   include <RadioFmPresetUtility.h>
       
    24 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
    25 
       
    26 #include <QString>
    21 #include <QString>
    27 
    22 
    28 // User includes
    23 // User includes
    29 #include "radiopresetstorage.h"
    24 #include "radiopresetstorage.h"
    30 #include "radiopresetstorage_p.h"
    25 #include "radiopresetstorage_p.h"
    33 /*!
    28 /*!
    34  * Converts a symbian descriptor to Qt string
    29  * Converts a symbian descriptor to Qt string
    35  */
    30  */
    36 static QString convertString( const TDesC& aDesc )
    31 static QString convertString( const TDesC& aDesc )
    37 {
    32 {
    38     return QString( (QChar*)aDesc.Ptr(), aDesc.Length() );
    33     return QString::fromUtf16( aDesc.Ptr(), aDesc.Length() );
    39 }
    34 }
    40 
    35 
    41 /*!
    36 /*!
    42  *
    37  *
    43  */
    38  */
    51 /*!
    46 /*!
    52  *
    47  *
    53  */
    48  */
    54 RadioPresetStorage::~RadioPresetStorage()
    49 RadioPresetStorage::~RadioPresetStorage()
    55 {
    50 {
    56     delete d_ptr;
       
    57 }
    51 }
    58 
    52 
    59 /*!
    53 /*!
    60  *
    54  *
    61  */
    55  */
    62 int RadioPresetStorage::maxNumberOfPresets() const
    56 int RadioPresetStorage::maxNumberOfPresets() const
    63 {
    57 {
    64     Q_D( const RadioPresetStorage );
    58     Q_D( const RadioPresetStorage );
    65 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
    66     return d->mPresetUtility->MaxNumberOfPresets();
    59     return d->mPresetUtility->MaxNumberOfPresets();
    67 #else
       
    68     TInt maxPresets = 0;
       
    69     d->mPresetUtility->GetMaxNumberOfPresets( maxPresets );
       
    70     return maxPresets;
       
    71 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
    72 }
    60 }
    73 
    61 
    74 /*!
    62 /*!
    75  *
    63  *
    76  */
    64  */
    77 int RadioPresetStorage::presetCount() const
    65 int RadioPresetStorage::presetCount() const
    78 {
    66 {
    79     Q_D( const RadioPresetStorage );
    67     Q_D( const RadioPresetStorage );
    80 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
    81     return d->mPresetUtility->PresetCount();
    68     return d->mPresetUtility->PresetCount();
    82 #else
       
    83     TInt presetCount = 0;
       
    84     d->mPresetUtility->GetNumberOfPresets( presetCount );
       
    85     return presetCount;
       
    86 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
    87 }
    69 }
    88 
    70 
    89 /*!
    71 /*!
    90  *
    72  *
    91  */
    73  */
    92 int RadioPresetStorage::firstPreset() const
    74 int RadioPresetStorage::firstPreset() const
    93 {
    75 {
    94     Q_D( const RadioPresetStorage );
    76     Q_D( const RadioPresetStorage );
    95 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
    96     return d->mPresetUtility->FirstPreset();
    77     return d->mPresetUtility->FirstPreset();
    97 #else
       
    98     TInt firstIndex = -1;
       
    99     TRAPD( err, d->mPresetUtility->GetFirstPresetL( firstIndex ) );
       
   100     if ( err ) {
       
   101         firstIndex = -1;
       
   102     }
       
   103     return firstIndex;
       
   104 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   105 }
    78 }
   106 
    79 
   107 /*!
    80 /*!
   108  *
    81  *
   109  */
    82  */
   110 int RadioPresetStorage::nextPreset( int fromIndex ) const
    83 int RadioPresetStorage::nextPreset( int fromIndex ) const
   111 {
    84 {
   112     Q_D( const RadioPresetStorage );
    85     Q_D( const RadioPresetStorage );
   113 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
   114     return d->mPresetUtility->NextPreset( fromIndex );
    86     return d->mPresetUtility->NextPreset( fromIndex );
   115 #else
       
   116     TInt nextIndex = -1;
       
   117     TRAPD( err, d->mPresetUtility->GetNextPresetL( fromIndex, nextIndex ) );
       
   118     if ( err ) {
       
   119         nextIndex = -1;
       
   120     }
       
   121     return nextIndex;
       
   122 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   123 }
    87 }
   124 
    88 
   125 /*!
    89 /*!
   126  *
    90  *
   127  */
    91  */
   128 bool RadioPresetStorage::deletePreset( int presetIndex )
    92 bool RadioPresetStorage::deletePreset( int presetIndex )
   129 {
    93 {
   130     Q_D( RadioPresetStorage );
    94     Q_D( RadioPresetStorage );
   131 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
   132     return d->mPresetUtility->DeletePreset( presetIndex ) == KErrNone;
    95     return d->mPresetUtility->DeletePreset( presetIndex ) == KErrNone;
   133 #else
       
   134     TRAPD( err, d->mPresetUtility->DeletePresetL( presetIndex ) );
       
   135     return err;
       
   136 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   137 }
    96 }
   138 
    97 
   139 /*!
    98 /*!
   140  *
    99  *
   141  */
   100  */
   142 bool RadioPresetStorage::savePreset( const RadioStationIf& station )
   101 bool RadioPresetStorage::savePreset( const RadioStationIf& station )
   143 {
   102 {
   144     Q_D( RadioPresetStorage );
   103     Q_D( RadioPresetStorage );
   145 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
   146     TPreset preset;
   104     TPreset preset;
   147     preset.SetFrequency( station.frequency() );
   105     preset.SetFrequency( station.frequency() );
   148     TPresetName name( station.name().utf16() );
   106     TPresetName name( station.name().left( KPresetNameLength ).utf16() );
   149     preset.SetName( name );
   107     preset.SetName( name );
   150     preset.SetRenamedByUser( station.isRenamedByUser() );
   108     preset.SetRenamedByUser( station.isRenamedByUser() );
   151     preset.SetGenre( station.genre() );
   109     preset.SetGenre( station.genre() );
   152     TRadioUrl url( station.url().utf16() );
   110     TRadioUrl url( station.url().left( KUrlMaxLength ).utf16() );
   153     preset.SetUrl( url );
   111     preset.SetUrl( url );
   154     preset.SetPiCode( station.piCode() );
   112     preset.SetPiCode( station.piCode() );
   155     preset.SetFavorite( station.isFavorite() );
   113     preset.SetFavorite( station.isFavorite() );
   156     preset.SetLocalStation( station.isLocalStation() );
   114     preset.SetLocalStation( station.isLocalStation() );
   157 
   115 
   158     TRAPD( err, d->mPresetUtility->SavePresetL( preset, station.presetIndex() ) );
   116     TRAPD( err, d->mPresetUtility->SavePresetL( preset, station.presetIndex() ) );
   159     return err == KErrNone;
   117     return err == KErrNone;
   160 #else
       
   161     TFmPresetName name( station.name().utf16() );
       
   162     TRAPD( err, d->mPresetUtility->SetPresetL( station.presetIndex(), name, station.frequency() ) );
       
   163     return err == KErrNone;
       
   164 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   165 }
   118 }
   166 
   119 
   167 /*!
   120 /*!
   168  *
   121  *
   169  */
   122  */
   170 bool RadioPresetStorage::readPreset( int index, RadioStationIf& station )
   123 bool RadioPresetStorage::readPreset( int index, RadioStationIf& station )
   171 {
   124 {
   172     Q_D( RadioPresetStorage );
   125     Q_D( RadioPresetStorage );
   173 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
   174     TPreset preset;
   126     TPreset preset;
   175     TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
   127     TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
   176     if ( !err ) {
   128     if ( !err ) {
   177 
   129 
   178         station.setPresetIndex( index );
   130         station.setPresetIndex( index );
   186         station.setLocalStation( preset.LocalStation() );
   138         station.setLocalStation( preset.LocalStation() );
   187 
   139 
   188         return true;
   140         return true;
   189     }
   141     }
   190     return false;
   142     return false;
   191 #else
   143 }
   192     TFmPresetName nameDesc;
   144 
   193     TInt frequency = 0;
   145 /*!
   194     TRAPD( err, d->mPresetUtility->GetPresetL( index, nameDesc, frequency ) );
   146  *
   195     if ( !err )
   147  */
   196     {
   148 void RadioPresetStorage::readFrequencies( QList<uint>& frequencyList )
   197         station.setPresetIndex( index );
   149 {
   198         station.setName( convertString( nameDesc ) );
   150     Q_D( RadioPresetStorage );
   199         station.setFrequency( static_cast<TUint>( frequency ) );
   151 
   200         station.setLocalStation( true );
   152     TPreset preset;
       
   153     int index = firstPreset();
       
   154     while ( index >= 0 ) {
       
   155         TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
       
   156         if ( !err ) {
       
   157             frequencyList.append( preset.Frequency() );
       
   158         }
       
   159 
       
   160         index = nextPreset( index );
   201     }
   161     }
   202     return err == KErrNone;
       
   203 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   204 }
   162 }
   205 
   163 
   206 /*!
   164 /*!
   207  *
   165  *
   208  */
   166  */
   220 /*!
   178 /*!
   221  *
   179  *
   222  */
   180  */
   223 bool RadioPresetStoragePrivate::init()
   181 bool RadioPresetStoragePrivate::init()
   224 {
   182 {
   225 #ifdef COMPILE_WITH_NEW_PRESET_UTILITY
       
   226     TRAPD( err, mPresetUtility.reset( CPresetUtility::NewL() ) );
   183     TRAPD( err, mPresetUtility.reset( CPresetUtility::NewL() ) );
   227     
       
   228 #else
       
   229     TRAPD( err, mPresetUtility.reset( CRadioFmPresetUtility::NewL( *this ) ) );
       
   230 #endif // COMPILE_WITH_NEW_PRESET_UTILITY
       
   231     return err == KErrNone;
   184     return err == KErrNone;
   232 }
   185 }