radioapp/radiopresetstorage/src/radiopresetstorage.cpp
changeset 28 075425b8d9a4
parent 24 6df133bd92e1
child 32 189d20c34778
child 34 bc10a61bd7d3
--- a/radioapp/radiopresetstorage/src/radiopresetstorage.cpp	Fri Jun 04 10:21:36 2010 +0100
+++ b/radioapp/radiopresetstorage/src/radiopresetstorage.cpp	Fri Jun 11 13:38:32 2010 +0300
@@ -16,13 +16,8 @@
 */
 
 // System includes
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
 #include <presetutility.h>
 #include <preset.h>
-#else
-#   include <RadioFmPresetUtility.h>
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
-
 #include <QString>
 
 // User includes
@@ -35,7 +30,7 @@
  */
 static QString convertString( const TDesC& aDesc )
 {
-    return QString( (QChar*)aDesc.Ptr(), aDesc.Length() );
+    return QString::fromUtf16( aDesc.Ptr(), aDesc.Length() );
 }
 
 /*!
@@ -62,13 +57,7 @@
 int RadioPresetStorage::maxNumberOfPresets() const
 {
     Q_D( const RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     return d->mPresetUtility->MaxNumberOfPresets();
-#else
-    TInt maxPresets = 0;
-    d->mPresetUtility->GetMaxNumberOfPresets( maxPresets );
-    return maxPresets;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -77,13 +66,7 @@
 int RadioPresetStorage::presetCount() const
 {
     Q_D( const RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     return d->mPresetUtility->PresetCount();
-#else
-    TInt presetCount = 0;
-    d->mPresetUtility->GetNumberOfPresets( presetCount );
-    return presetCount;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -92,16 +75,7 @@
 int RadioPresetStorage::firstPreset() const
 {
     Q_D( const RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     return d->mPresetUtility->FirstPreset();
-#else
-    TInt firstIndex = -1;
-    TRAPD( err, d->mPresetUtility->GetFirstPresetL( firstIndex ) );
-    if ( err ) {
-        firstIndex = -1;
-    }
-    return firstIndex;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -110,16 +84,7 @@
 int RadioPresetStorage::nextPreset( int fromIndex ) const
 {
     Q_D( const RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     return d->mPresetUtility->NextPreset( fromIndex );
-#else
-    TInt nextIndex = -1;
-    TRAPD( err, d->mPresetUtility->GetNextPresetL( fromIndex, nextIndex ) );
-    if ( err ) {
-        nextIndex = -1;
-    }
-    return nextIndex;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -128,12 +93,7 @@
 bool RadioPresetStorage::deletePreset( int presetIndex )
 {
     Q_D( RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     return d->mPresetUtility->DeletePreset( presetIndex ) == KErrNone;
-#else
-    TRAPD( err, d->mPresetUtility->DeletePresetL( presetIndex ) );
-    return err;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -142,7 +102,6 @@
 bool RadioPresetStorage::savePreset( const RadioStationIf& station )
 {
     Q_D( RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     TPreset preset;
     preset.SetFrequency( station.frequency() );
     TPresetName name( station.name().utf16() );
@@ -157,11 +116,6 @@
 
     TRAPD( err, d->mPresetUtility->SavePresetL( preset, station.presetIndex() ) );
     return err == KErrNone;
-#else
-    TFmPresetName name( station.name().utf16() );
-    TRAPD( err, d->mPresetUtility->SetPresetL( station.presetIndex(), name, station.frequency() ) );
-    return err == KErrNone;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -170,7 +124,6 @@
 bool RadioPresetStorage::readPreset( int index, RadioStationIf& station )
 {
     Q_D( RadioPresetStorage );
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     TPreset preset;
     TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
     if ( !err ) {
@@ -188,19 +141,25 @@
         return true;
     }
     return false;
-#else
-    TFmPresetName nameDesc;
-    TInt frequency = 0;
-    TRAPD( err, d->mPresetUtility->GetPresetL( index, nameDesc, frequency ) );
-    if ( !err )
-    {
-        station.setPresetIndex( index );
-        station.setName( convertString( nameDesc ) );
-        station.setFrequency( static_cast<TUint>( frequency ) );
-        station.setLocalStation( true );
+}
+
+/*!
+ *
+ */
+void RadioPresetStorage::readFrequencies( QList<uint>& frequencyList )
+{
+    Q_D( RadioPresetStorage );
+
+    TPreset preset;
+    int index = firstPreset();
+    while ( index >= 0 ) {
+        TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
+        if ( !err ) {
+            frequencyList.append( preset.Frequency() );
+        }
+
+        index = nextPreset( index );
     }
-    return err == KErrNone;
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
 }
 
 /*!
@@ -222,11 +181,6 @@
  */
 bool RadioPresetStoragePrivate::init()
 {
-#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
     TRAPD( err, mPresetUtility.reset( CPresetUtility::NewL() ) );
-    
-#else
-    TRAPD( err, mPresetUtility.reset( CRadioFmPresetUtility::NewL( *this ) ) );
-#endif // COMPILE_WITH_NEW_PRESET_UTILITY
     return err == KErrNone;
 }