author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 09:49:03 +0300 | |
changeset 41 | 3a6b55c6390c |
parent 33 | 11b6825f0862 |
child 37 | 451b2e1545b2 |
permissions | -rw-r--r-- |
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 |
#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 |
{ |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
33 |
return QString::fromUtf16( aDesc.Ptr(), aDesc.Length() ); |
24 | 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() ); |
|
33
11b6825f0862
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
106 |
TPresetName name( station.name().left( KPresetNameLength ).utf16() ); |
24 | 107 |
preset.SetName( name ); |
108 |
preset.SetRenamedByUser( station.isRenamedByUser() ); |
|
109 |
preset.SetGenre( station.genre() ); |
|
33
11b6825f0862
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
32
diff
changeset
|
110 |
TRadioUrl url( station.url().left( KUrlMaxLength ).utf16() ); |
24 | 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; |
|
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
143 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
144 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
145 |
/*! |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
146 |
* |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
147 |
*/ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
148 |
void RadioPresetStorage::readFrequencies( QList<uint>& frequencyList ) |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
149 |
{ |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
150 |
Q_D( RadioPresetStorage ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
151 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
152 |
TPreset preset; |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
153 |
int index = firstPreset(); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
154 |
while ( index >= 0 ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
155 |
TRAPD( err, d->mPresetUtility->ReadPresetL( index, preset ) ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
156 |
if ( !err ) { |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
157 |
frequencyList.append( preset.Frequency() ); |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
158 |
} |
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
159 |
|
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
160 |
index = nextPreset( index ); |
24 | 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 |
} |