|
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 #include <e32err.h> |
|
18 #include "irqfavoritesdb.h" |
|
19 #include "irqenums.h" |
|
20 #include "irqutility.h" |
|
21 #include "irqisdsdatastructure.h" |
|
22 #include "irisdspreset.h" |
|
23 #include "irpreset.h" |
|
24 #include "irfavoritesdb.h" |
|
25 |
|
26 EXPORT_C IRQFavoritesDB::IRQFavoritesDB() |
|
27 { |
|
28 TRAPD(err, iIRFavoritesDb = CIRFavoritesDb::NewL()); |
|
29 if( KErrNone != err) |
|
30 return; |
|
31 |
|
32 /* add self to the observers of the CIRFavoritesDb. When the call back function |
|
33 * is called, it means that preset is changed and we send a signal to the uper layer*/ |
|
34 iIRFavoritesDb->AddObserver(*this); |
|
35 } |
|
36 IRQFavoritesDB::~IRQFavoritesDB() |
|
37 { |
|
38 delete iIRFavoritesDb; |
|
39 } |
|
40 |
|
41 //add a preset |
|
42 //@param CIRIsdsPreset& the isds preset |
|
43 //@return errcode |
|
44 EXPORT_C int IRQFavoritesDB::addPreset(const IRQPreset& aPreset) |
|
45 { |
|
46 int returnCode = 0; |
|
47 TRAPD(err, addPresetL(aPreset, returnCode)); |
|
48 RETURN_IF_ERR(err); |
|
49 |
|
50 int result = 0; |
|
51 IRQUtility::convertSError2QError(returnCode, result); |
|
52 return result; |
|
53 } |
|
54 |
|
55 //add a preset manually |
|
56 //@return errcode |
|
57 //@param |
|
58 // |
|
59 EXPORT_C int IRQFavoritesDB::addPreset(const QString& aName, |
|
60 const QString& aURL) |
|
61 { |
|
62 |
|
63 if( 0 == aName.size() || 0 == aURL.size()) |
|
64 return EIRQErrorBadParameter; |
|
65 |
|
66 TPtrC16 nameptr(reinterpret_cast<const TUint16*> (aName.utf16())); |
|
67 TPtrC16 urlptr(reinterpret_cast<const TUint16*> (aURL.utf16())); |
|
68 int returnCode = 0; |
|
69 TRAPD(err, (iIRFavoritesDb->AddPresetL(nameptr, urlptr, returnCode))); |
|
70 RETURN_IF_ERR(err); |
|
71 |
|
72 int result = 0; |
|
73 IRQUtility::convertSError2QError(returnCode, result); |
|
74 return result; |
|
75 } |
|
76 |
|
77 //get a preset uniq id |
|
78 //@return errcode |
|
79 //@param |
|
80 // |
|
81 EXPORT_C int IRQFavoritesDB::getUniqId(int aNum) |
|
82 { |
|
83 if( aNum < 0 || aNum >= iIRFavoritesDb->iFavPresetList.Count()) |
|
84 return EIRQErrorBadParameter; |
|
85 |
|
86 return iIRFavoritesDb->iFavPresetList[aNum]->Id(); |
|
87 } |
|
88 |
|
89 //delete a preset by uniq id |
|
90 //@return errcode |
|
91 //@param |
|
92 // |
|
93 EXPORT_C int IRQFavoritesDB::deletePreset(int aUniqId) |
|
94 { |
|
95 TRAPD( err, (iIRFavoritesDb->DeletePresetL(aUniqId))); |
|
96 RETURN_IF_ERR(err); |
|
97 return EIRQErrorNone; |
|
98 } |
|
99 |
|
100 //search a preset by uniqpresetId / isdspresetid |
|
101 //warning: the function needs further checking |
|
102 //@return errcode |
|
103 // |
|
104 EXPORT_C int IRQFavoritesDB::searchPreset(int aUniqPresetId, int aIsdsPresetId) |
|
105 { |
|
106 int returnCode = 0; |
|
107 int result = 0; //for QT |
|
108 returnCode = iIRFavoritesDb->SearchPreset(aUniqPresetId, aIsdsPresetId); |
|
109 IRQUtility::convertSError2QError(returnCode, result); |
|
110 return result; |
|
111 } |
|
112 |
|
113 // |
|
114 //get the previouse preset index in the internal list |
|
115 //@return the index |
|
116 // |
|
117 EXPORT_C int IRQFavoritesDB::getPreviousPreset(int aIndex) |
|
118 { |
|
119 return iIRFavoritesDb->GetPreviousPreset(aIndex); |
|
120 } |
|
121 |
|
122 // |
|
123 //get the next preset index |
|
124 //@return the index |
|
125 // |
|
126 EXPORT_C int IRQFavoritesDB::getNextPreset(int aIndex) |
|
127 { |
|
128 return iIRFavoritesDb->GetNextPreset(aIndex); |
|
129 } |
|
130 |
|
131 |
|
132 //replace with new preset |
|
133 //@return errcode |
|
134 // |
|
135 EXPORT_C int IRQFavoritesDB::replacePreset(const IRQPreset& aNewPreset) |
|
136 { |
|
137 TRAPD(err, replacePresetL(aNewPreset)); |
|
138 RETURN_IF_ERR(err); |
|
139 return EIRQErrorNone; |
|
140 } |
|
141 |
|
142 //@return errcode |
|
143 // |
|
144 EXPORT_C int IRQFavoritesDB::replaceUserDefinedPreset(const IRQPreset& aNewPreset) |
|
145 { |
|
146 TRAPD(err, replaceUserDefinedPresetL(aNewPreset)); |
|
147 RETURN_IF_ERR(err); |
|
148 return EIRQErrorNone; |
|
149 } |
|
150 |
|
151 //change the preset type to user defined |
|
152 //@return errcode |
|
153 // |
|
154 EXPORT_C int IRQFavoritesDB::makePresetUserDefined(int aChannelId, |
|
155 int aUserDefinedChannelId) |
|
156 { |
|
157 TRAPD(err, (iIRFavoritesDb->MakePresetUserDefinedL(aChannelId, aUserDefinedChannelId))); |
|
158 RETURN_IF_ERR(err); |
|
159 return EIRQErrorNone; |
|
160 } |
|
161 |
|
162 //get the empty preset left count |
|
163 //@return the count of empty presets left |
|
164 // |
|
165 EXPORT_C int IRQFavoritesDB::emptyPresetCount() const |
|
166 { |
|
167 return iIRFavoritesDb->EmptyPresetCount(); |
|
168 } |
|
169 |
|
170 //get the max preset count supported now |
|
171 //@return errcode |
|
172 // |
|
173 EXPORT_C int IRQFavoritesDB::maxPresetCount() |
|
174 { |
|
175 return iIRFavoritesDb->MaxPresetCount(); |
|
176 } |
|
177 |
|
178 //the interface is not used currently. |
|
179 // |
|
180 EXPORT_C void IRQFavoritesDB::setMoveStatus(bool aStatus) |
|
181 { |
|
182 iIRFavoritesDb->SetMoveStatus(aStatus); |
|
183 } |
|
184 |
|
185 //the interface is not used currently |
|
186 // |
|
187 EXPORT_C bool IRQFavoritesDB::getMoveStatus() |
|
188 { |
|
189 return iIRFavoritesDb->GetMoveStatus(); |
|
190 } |
|
191 |
|
192 //for CIRPreset is just an interface so we can wrapper it into the IRQPreset. |
|
193 //the interface get the IRQPreset list. The upper layer will free all the items |
|
194 //in the list and the list self |
|
195 // |
|
196 EXPORT_C QList<IRQPreset*>* IRQFavoritesDB::getPresets() const |
|
197 { |
|
198 QList<IRQPreset*> * presetList = new QList<IRQPreset*> (); |
|
199 const RIRPresetArray& cirPresetList = iIRFavoritesDb->GetAllSortedPresets(); |
|
200 int counts = cirPresetList.Count(); |
|
201 for (int i = 0; i < counts; i++) |
|
202 { |
|
203 IRQPreset *irqPreset = new IRQPreset(); |
|
204 IRQUtility::convertCIRPreset2IRQPreset(*(cirPresetList[i]), *irqPreset); |
|
205 presetList->append(irqPreset); |
|
206 } |
|
207 return presetList; |
|
208 } |
|
209 |
|
210 /* |
|
211 * Increase the played times of the preset if it's in the favorites |
|
212 */ |
|
213 EXPORT_C void IRQFavoritesDB::increasePlayedTimes(const IRQPreset &aPreset) |
|
214 { |
|
215 TRAP_IGNORE(increasePlayedTimesL(aPreset)); |
|
216 } |
|
217 |
|
218 EXPORT_C CIRFavoritesDb * IRQFavoritesDB::getCIRFavoriteDB() const |
|
219 { |
|
220 return iIRFavoritesDb; |
|
221 } |
|
222 |
|
223 /* None export functions */ |
|
224 |
|
225 void IRQFavoritesDB::HandlePresetChangedL(TInt aId, TUid aDataHandler, |
|
226 MPSPresetObserver::TPSReason aType) |
|
227 { |
|
228 emit presetChanged(aId, aDataHandler, aType); |
|
229 } |
|
230 |
|
231 void IRQFavoritesDB::addPresetL(const IRQPreset& aPreset, int& aRetValue) |
|
232 { |
|
233 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
234 IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset); |
|
235 iIRFavoritesDb->AddPresetL(*cirPreset, aRetValue); |
|
236 CleanupStack::PopAndDestroy(cirPreset); |
|
237 } |
|
238 |
|
239 void IRQFavoritesDB::replacePresetL(const IRQPreset& aNewPreset) |
|
240 { |
|
241 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
242 IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset); |
|
243 iIRFavoritesDb->ReplacePresetL(*cirPreset); |
|
244 CleanupStack::PopAndDestroy(cirPreset); |
|
245 } |
|
246 |
|
247 void IRQFavoritesDB::replaceUserDefinedPresetL(const IRQPreset& aNewPreset) |
|
248 { |
|
249 CIRIsdsPreset *cirPreset = CIRIsdsPreset::NewLC(); |
|
250 IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset); |
|
251 iIRFavoritesDb->ReplaceUserDefinedPresetL(*cirPreset); |
|
252 CleanupStack::PopAndDestroy(cirPreset); |
|
253 } |
|
254 |
|
255 void IRQFavoritesDB::increasePlayedTimesL(const IRQPreset &aPreset) |
|
256 { |
|
257 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
258 IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset); |
|
259 iIRFavoritesDb->IncreasePlayedTimesL(*cirPreset); |
|
260 CleanupStack::PopAndDestroy(cirPreset); |
|
261 } |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |