24
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
20 |
#include <presetutility.h>
|
|
21 |
#include <preset.h>
|
|
22 |
#else
|
|
23 |
# include <RadioFmPresetUtility.h>
|
|
24 |
#endif // COMPILE_WITH_NEW_PRESET_UTILITY
|
|
25 |
|
|
26 |
#include <QString>
|
|
27 |
|
|
28 |
// User includes
|
|
29 |
#include "radiopresetstorage.h"
|
|
30 |
#include "radiopresetstorage_p.h"
|
|
31 |
#include "radiostationif.h"
|
|
32 |
|
|
33 |
/*!
|
|
34 |
* Converts a symbian descriptor to Qt string
|
|
35 |
*/
|
|
36 |
static QString convertString( const TDesC& aDesc )
|
|
37 |
{
|
|
38 |
return QString( (QChar*)aDesc.Ptr(), aDesc.Length() );
|
|
39 |
}
|
|
40 |
|
|
41 |
/*!
|
|
42 |
*
|
|
43 |
*/
|
|
44 |
RadioPresetStorage::RadioPresetStorage() :
|
|
45 |
d_ptr( new RadioPresetStoragePrivate() )
|
|
46 |
{
|
|
47 |
Q_D( RadioPresetStorage );
|
|
48 |
d->init();
|
|
49 |
}
|
|
50 |
|
|
51 |
/*!
|
|
52 |
*
|
|
53 |
*/
|
|
54 |
RadioPresetStorage::~RadioPresetStorage()
|
|
55 |
{
|
|
56 |
delete d_ptr;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
*
|
|
61 |
*/
|
|
62 |
int RadioPresetStorage::maxNumberOfPresets() const
|
|
63 |
{
|
|
64 |
Q_D( const RadioPresetStorage );
|
|
65 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
66 |
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 |
}
|
|
73 |
|
|
74 |
/*!
|
|
75 |
*
|
|
76 |
*/
|
|
77 |
int RadioPresetStorage::presetCount() const
|
|
78 |
{
|
|
79 |
Q_D( const RadioPresetStorage );
|
|
80 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
81 |
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 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
*
|
|
91 |
*/
|
|
92 |
int RadioPresetStorage::firstPreset() const
|
|
93 |
{
|
|
94 |
Q_D( const RadioPresetStorage );
|
|
95 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
96 |
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 |
}
|
|
106 |
|
|
107 |
/*!
|
|
108 |
*
|
|
109 |
*/
|
|
110 |
int RadioPresetStorage::nextPreset( int fromIndex ) const
|
|
111 |
{
|
|
112 |
Q_D( const RadioPresetStorage );
|
|
113 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
114 |
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 |
}
|
|
124 |
|
|
125 |
/*!
|
|
126 |
*
|
|
127 |
*/
|
|
128 |
bool RadioPresetStorage::deletePreset( int presetIndex )
|
|
129 |
{
|
|
130 |
Q_D( RadioPresetStorage );
|
|
131 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
132 |
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 |
}
|
|
138 |
|
|
139 |
/*!
|
|
140 |
*
|
|
141 |
*/
|
|
142 |
bool RadioPresetStorage::savePreset( const RadioStationIf& station )
|
|
143 |
{
|
|
144 |
Q_D( RadioPresetStorage );
|
|
145 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
146 |
TPreset preset;
|
|
147 |
preset.SetFrequency( station.frequency() );
|
|
148 |
TPresetName name( station.name().utf16() );
|
|
149 |
preset.SetName( name );
|
|
150 |
preset.SetRenamedByUser( station.isRenamedByUser() );
|
|
151 |
preset.SetGenre( station.genre() );
|
|
152 |
TRadioUrl url( station.url().utf16() );
|
|
153 |
preset.SetUrl( url );
|
|
154 |
preset.SetPiCode( station.piCode() );
|
|
155 |
preset.SetFavorite( station.isFavorite() );
|
|
156 |
preset.SetLocalStation( station.isLocalStation() );
|
|
157 |
|
|
158 |
TRAPD( err, d->mPresetUtility->SavePresetL( preset, station.presetIndex() ) );
|
|
159 |
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 |
}
|
|
166 |
|
|
167 |
/*!
|
|
168 |
*
|
|
169 |
*/
|
|
170 |
bool RadioPresetStorage::readPreset( int index, RadioStationIf& station )
|
|
171 |
{
|
|
172 |
Q_D( RadioPresetStorage );
|
|
173 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
174 |
TPreset preset;
|
|
175 |
TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) );
|
|
176 |
if ( !err ) {
|
|
177 |
|
|
178 |
station.setPresetIndex( index );
|
|
179 |
station.setFrequency( preset.Frequency() );
|
|
180 |
station.setName( convertString( preset.Name() ) );
|
|
181 |
station.setRenamedByUser( preset.RenamedByUser() );
|
|
182 |
station.setGenre( preset.Genre() );
|
|
183 |
station.setUrl( convertString( preset.Url() ) );
|
|
184 |
station.setPiCode( preset.PiCode() );
|
|
185 |
station.setFavorite( preset.Favorite() );
|
|
186 |
station.setLocalStation( preset.LocalStation() );
|
|
187 |
|
|
188 |
return true;
|
|
189 |
}
|
|
190 |
return false;
|
|
191 |
#else
|
|
192 |
TFmPresetName nameDesc;
|
|
193 |
TInt frequency = 0;
|
|
194 |
TRAPD( err, d->mPresetUtility->GetPresetL( index, nameDesc, frequency ) );
|
|
195 |
if ( !err )
|
|
196 |
{
|
|
197 |
station.setPresetIndex( index );
|
|
198 |
station.setName( convertString( nameDesc ) );
|
|
199 |
station.setFrequency( static_cast<TUint>( frequency ) );
|
|
200 |
station.setLocalStation( true );
|
|
201 |
}
|
|
202 |
return err == KErrNone;
|
|
203 |
#endif // COMPILE_WITH_NEW_PRESET_UTILITY
|
|
204 |
}
|
|
205 |
|
|
206 |
/*!
|
|
207 |
*
|
|
208 |
*/
|
|
209 |
RadioPresetStoragePrivate::RadioPresetStoragePrivate()
|
|
210 |
{
|
|
211 |
}
|
|
212 |
|
|
213 |
/*!
|
|
214 |
*
|
|
215 |
*/
|
|
216 |
RadioPresetStoragePrivate::~RadioPresetStoragePrivate()
|
|
217 |
{
|
|
218 |
}
|
|
219 |
|
|
220 |
/*!
|
|
221 |
*
|
|
222 |
*/
|
|
223 |
bool RadioPresetStoragePrivate::init()
|
|
224 |
{
|
|
225 |
#ifdef COMPILE_WITH_NEW_PRESET_UTILITY
|
|
226 |
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;
|
|
232 |
}
|