|
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 #include <presetutility.h> |
|
20 #include <preset.h> |
|
21 #include <QString> |
|
22 |
|
23 // User includes |
|
24 #include "radiopresetstorage.h" |
|
25 #include "radiopresetstorage_p.h" |
|
26 #include "radiostationif.h" |
|
27 |
|
28 /*! |
|
29 * Converts a symbian descriptor to Qt string |
|
30 */ |
|
31 static QString convertString( const TDesC& aDesc ) |
|
32 { |
|
33 return QString::fromUtf16( aDesc.Ptr(), aDesc.Length() ); |
|
34 } |
|
35 |
|
36 /*! |
|
37 * |
|
38 */ |
|
39 RadioPresetStorage::RadioPresetStorage() : |
|
40 d_ptr( new RadioPresetStoragePrivate() ) |
|
41 { |
|
42 Q_D( RadioPresetStorage ); |
|
43 d->init(); |
|
44 } |
|
45 |
|
46 /*! |
|
47 * |
|
48 */ |
|
49 RadioPresetStorage::~RadioPresetStorage() |
|
50 { |
|
51 } |
|
52 |
|
53 /*! |
|
54 * |
|
55 */ |
|
56 int RadioPresetStorage::maxNumberOfPresets() const |
|
57 { |
|
58 Q_D( const RadioPresetStorage ); |
|
59 return d->mPresetUtility->MaxNumberOfPresets(); |
|
60 } |
|
61 |
|
62 /*! |
|
63 * |
|
64 */ |
|
65 int RadioPresetStorage::presetCount() const |
|
66 { |
|
67 Q_D( const RadioPresetStorage ); |
|
68 return d->mPresetUtility->PresetCount(); |
|
69 } |
|
70 |
|
71 /*! |
|
72 * |
|
73 */ |
|
74 int RadioPresetStorage::firstPreset() const |
|
75 { |
|
76 Q_D( const RadioPresetStorage ); |
|
77 return d->mPresetUtility->FirstPreset(); |
|
78 } |
|
79 |
|
80 /*! |
|
81 * |
|
82 */ |
|
83 int RadioPresetStorage::nextPreset( int fromIndex ) const |
|
84 { |
|
85 Q_D( const RadioPresetStorage ); |
|
86 return d->mPresetUtility->NextPreset( fromIndex ); |
|
87 } |
|
88 |
|
89 /*! |
|
90 * |
|
91 */ |
|
92 bool RadioPresetStorage::deletePreset( int presetIndex ) |
|
93 { |
|
94 Q_D( RadioPresetStorage ); |
|
95 return d->mPresetUtility->DeletePreset( presetIndex ) == KErrNone; |
|
96 } |
|
97 |
|
98 /*! |
|
99 * |
|
100 */ |
|
101 bool RadioPresetStorage::savePreset( const RadioStationIf& station ) |
|
102 { |
|
103 Q_D( RadioPresetStorage ); |
|
104 TPreset preset; |
|
105 preset.SetFrequency( station.frequency() ); |
|
106 TPresetName name( station.name().left( KPresetNameLength ).utf16() ); |
|
107 preset.SetName( name ); |
|
108 preset.SetRenamedByUser( station.isRenamedByUser() ); |
|
109 preset.SetGenre( station.genre() ); |
|
110 TRadioUrl url( station.url().left( KUrlMaxLength ).utf16() ); |
|
111 preset.SetUrl( url ); |
|
112 preset.SetPiCode( station.piCode() ); |
|
113 preset.SetFavorite( station.isFavorite() ); |
|
114 preset.SetLocalStation( station.isLocalStation() ); |
|
115 |
|
116 TRAPD( err, d->mPresetUtility->SavePresetL( preset, station.presetIndex() ) ); |
|
117 return err == KErrNone; |
|
118 } |
|
119 |
|
120 /*! |
|
121 * |
|
122 */ |
|
123 bool RadioPresetStorage::readPreset( int index, RadioStationIf& station ) |
|
124 { |
|
125 Q_D( RadioPresetStorage ); |
|
126 TPreset preset; |
|
127 TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) ); |
|
128 if ( !err ) { |
|
129 |
|
130 station.setPresetIndex( index ); |
|
131 station.setFrequency( preset.Frequency() ); |
|
132 station.setName( convertString( preset.Name() ) ); |
|
133 station.setRenamedByUser( preset.RenamedByUser() ); |
|
134 station.setGenre( preset.Genre() ); |
|
135 station.setUrl( convertString( preset.Url() ) ); |
|
136 station.setPiCode( preset.PiCode() ); |
|
137 station.setFavorite( preset.Favorite() ); |
|
138 station.setLocalStation( preset.LocalStation() ); |
|
139 |
|
140 return true; |
|
141 } |
|
142 return false; |
|
143 } |
|
144 |
|
145 /*! |
|
146 * |
|
147 */ |
|
148 void RadioPresetStorage::readFrequencies( QList<uint>& frequencyList ) |
|
149 { |
|
150 Q_D( RadioPresetStorage ); |
|
151 |
|
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 ); |
|
161 } |
|
162 } |
|
163 |
|
164 /*! |
|
165 * |
|
166 */ |
|
167 RadioPresetStoragePrivate::RadioPresetStoragePrivate() |
|
168 { |
|
169 } |
|
170 |
|
171 /*! |
|
172 * |
|
173 */ |
|
174 RadioPresetStoragePrivate::~RadioPresetStoragePrivate() |
|
175 { |
|
176 } |
|
177 |
|
178 /*! |
|
179 * |
|
180 */ |
|
181 bool RadioPresetStoragePrivate::init() |
|
182 { |
|
183 TRAPD( err, mPresetUtility.reset( CPresetUtility::NewL() ) ); |
|
184 return err == KErrNone; |
|
185 } |