|
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 #include "irfavoritesdb.h" |
|
19 #include "irqfavoritesdb.h" |
|
20 #include "irqfavoritesdb_p.h" |
|
21 #include "irqenums.h" |
|
22 #include "irqutility.h" |
|
23 #include "irqisdsdatastructure.h" |
|
24 #include "irpreset.h" |
|
25 #include "irisdspreset.h" |
|
26 |
|
27 IRQFavoritesDBPrivate::IRQFavoritesDBPrivate(IRQFavoritesDB *aIRQFavorites) : q_ptr(aIRQFavorites), |
|
28 mIRFavoritesDb(NULL) |
|
29 { |
|
30 } |
|
31 |
|
32 IRQFavoritesDBPrivate::~IRQFavoritesDBPrivate() |
|
33 { |
|
34 delete mIRFavoritesDb; |
|
35 mIRFavoritesDb = NULL; |
|
36 } |
|
37 |
|
38 void IRQFavoritesDBPrivate::init() |
|
39 { |
|
40 TRAPD(err, mIRFavoritesDb = CIRFavoritesDb::NewL()); |
|
41 if (KErrNone != err) |
|
42 { |
|
43 return; |
|
44 } |
|
45 |
|
46 /* add self to the observers of the CIRFavoritesDb. When the call back function |
|
47 * is called, it means that preset is changed and we send a signal to the uper layer*/ |
|
48 mIRFavoritesDb->AddObserver(*this); |
|
49 } |
|
50 |
|
51 int IRQFavoritesDBPrivate::addPreset(const IRQPreset& aPreset) |
|
52 { |
|
53 int returnCode = 0; |
|
54 TRAPD(err, addPresetL(aPreset, returnCode)); |
|
55 |
|
56 int result = 0; |
|
57 if (KErrNone != err) |
|
58 { |
|
59 IRQUtility::convertSError2QError(err, result); |
|
60 } |
|
61 else |
|
62 { |
|
63 IRQUtility::convertSError2QError(returnCode, result); |
|
64 } |
|
65 return result; |
|
66 } |
|
67 |
|
68 int IRQFavoritesDBPrivate::addPreset(const QString& aName, const QString& aURL) |
|
69 { |
|
70 if (0 == aName.size() || 0 == aURL.size()) |
|
71 { |
|
72 return EIRQErrorBadParameter; |
|
73 } |
|
74 |
|
75 TPtrC16 nameptr(reinterpret_cast<const TUint16*> (aName.utf16())); |
|
76 TPtrC16 urlptr(reinterpret_cast<const TUint16*> (aURL.utf16())); |
|
77 int returnCode = 0; |
|
78 TRAPD(err, mIRFavoritesDb->AddPresetL(nameptr, urlptr, returnCode)); |
|
79 |
|
80 int result = 0; |
|
81 if (KErrNone != err) |
|
82 { |
|
83 IRQUtility::convertSError2QError(err, result); |
|
84 } |
|
85 else |
|
86 { |
|
87 IRQUtility::convertSError2QError(returnCode, result); |
|
88 } |
|
89 return result; |
|
90 } |
|
91 |
|
92 int IRQFavoritesDBPrivate::getUniqId(int aNum) const |
|
93 { |
|
94 if ( aNum < 0 || aNum >= mIRFavoritesDb->iFavPresetList.Count()) |
|
95 { |
|
96 return EIRQErrorBadParameter; |
|
97 } |
|
98 |
|
99 //the preset's uniqid is equal to the CIRPreset's id |
|
100 return mIRFavoritesDb->iFavPresetList[aNum]->Id(); |
|
101 } |
|
102 |
|
103 int IRQFavoritesDBPrivate::deletePreset(int aUniqId) |
|
104 { |
|
105 TRAPD(err, (mIRFavoritesDb->DeletePresetL(aUniqId))); |
|
106 int result = 0; |
|
107 IRQUtility::convertSError2QError(err, result); |
|
108 return result; |
|
109 } |
|
110 |
|
111 int IRQFavoritesDBPrivate::searchPreset(int aUniqPresetId, int aIsdsPresetId) |
|
112 { |
|
113 int returnCode = 0; |
|
114 int result = 0; //for QT |
|
115 returnCode = mIRFavoritesDb->SearchPreset(aUniqPresetId, aIsdsPresetId); |
|
116 IRQUtility::convertSError2QError(returnCode, result); |
|
117 return result; |
|
118 } |
|
119 |
|
120 int IRQFavoritesDBPrivate::getPreviousPreset(int aIndex) |
|
121 { |
|
122 return mIRFavoritesDb->GetPreviousPreset(aIndex); |
|
123 } |
|
124 |
|
125 int IRQFavoritesDBPrivate::getNextPreset(int aIndex) |
|
126 { |
|
127 return mIRFavoritesDb->GetNextPreset(aIndex); |
|
128 } |
|
129 |
|
130 int IRQFavoritesDBPrivate::replacePreset(const IRQPreset& aNewPreset) |
|
131 { |
|
132 TRAPD(err, replacePresetL(aNewPreset)); |
|
133 int result = 0; |
|
134 IRQUtility::convertSError2QError(err, result); |
|
135 return result; |
|
136 } |
|
137 |
|
138 int IRQFavoritesDBPrivate::replaceUserDefinedPreset(const IRQPreset& aNewPreset) |
|
139 { |
|
140 TRAPD(err, replaceUserDefinedPresetL(aNewPreset)); |
|
141 int result = 0; |
|
142 IRQUtility::convertSError2QError(err, result); |
|
143 return result; |
|
144 } |
|
145 |
|
146 int IRQFavoritesDBPrivate::makePresetUserDefined(int aChannelId, int aUserDefinedChannelId) |
|
147 { |
|
148 TRAPD(err, mIRFavoritesDb->MakePresetUserDefinedL(aChannelId, aUserDefinedChannelId)); |
|
149 int result = 0; |
|
150 IRQUtility::convertSError2QError(err, result); |
|
151 return result; |
|
152 } |
|
153 |
|
154 int IRQFavoritesDBPrivate::emptyPresetCount() const |
|
155 { |
|
156 return mIRFavoritesDb->EmptyPresetCount(); |
|
157 } |
|
158 |
|
159 int IRQFavoritesDBPrivate::maxPresetCount() |
|
160 { |
|
161 return mIRFavoritesDb->MaxPresetCount(); |
|
162 } |
|
163 |
|
164 void IRQFavoritesDBPrivate::setMoveStatus(bool aStatus) |
|
165 { |
|
166 mIRFavoritesDb->SetMoveStatus(aStatus); |
|
167 } |
|
168 |
|
169 bool IRQFavoritesDBPrivate::getMoveStatus() |
|
170 { |
|
171 if (mIRFavoritesDb->GetMoveStatus()) |
|
172 { |
|
173 return true; |
|
174 } |
|
175 else |
|
176 { |
|
177 return false; |
|
178 } |
|
179 } |
|
180 |
|
181 QList<IRQPreset*>* IRQFavoritesDBPrivate::getPresets() const |
|
182 { |
|
183 QList<IRQPreset*> * presetList = new QList<IRQPreset*> (); |
|
184 const RIRPresetArray& cirPresetList = mIRFavoritesDb->GetAllSortedPresets(); |
|
185 int counts = cirPresetList.Count(); |
|
186 for (int i = 0; i < counts; i++) |
|
187 { |
|
188 IRQPreset *irqPreset = new IRQPreset(); |
|
189 IRQUtility::convertCIRPreset2IRQPreset(*(cirPresetList[i]), *irqPreset); |
|
190 presetList->append(irqPreset); |
|
191 } |
|
192 return presetList; |
|
193 } |
|
194 |
|
195 void IRQFavoritesDBPrivate::increasePlayedTimes(const IRQPreset &aPreset) |
|
196 { |
|
197 TRAP_IGNORE(increasePlayedTimesL(aPreset)); |
|
198 } |
|
199 |
|
200 /* from MPSPresetObserver */ |
|
201 void IRQFavoritesDBPrivate::HandlePresetChangedL(TInt aId, TUid aDataHandler, MPSPresetObserver::TPSReason aType) |
|
202 { |
|
203 IRQFavoritesDB::PSReason reason = IRQFavoritesDB::PSCreated; |
|
204 switch (aType) |
|
205 { |
|
206 case EPSCreated: |
|
207 reason = IRQFavoritesDB::PSCreated; |
|
208 break; |
|
209 |
|
210 case EPSDeleted: |
|
211 reason = IRQFavoritesDB::PSDeleted; |
|
212 break; |
|
213 |
|
214 case EPSModified: |
|
215 reason = IRQFavoritesDB::PSModified; |
|
216 break; |
|
217 |
|
218 default: |
|
219 Q_ASSERT(false); |
|
220 break; |
|
221 } |
|
222 |
|
223 emit q_ptr->presetChanged(aId, aDataHandler.iUid, reason); |
|
224 } |
|
225 |
|
226 void IRQFavoritesDBPrivate::addPresetL(const IRQPreset& aPreset, int& aRetValue) |
|
227 { |
|
228 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
229 IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset); |
|
230 mIRFavoritesDb->AddPresetL(*cirPreset, aRetValue); |
|
231 CleanupStack::PopAndDestroy(cirPreset); |
|
232 } |
|
233 |
|
234 void IRQFavoritesDBPrivate::replacePresetL(const IRQPreset& aNewPreset) |
|
235 { |
|
236 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
237 IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset); |
|
238 mIRFavoritesDb->ReplacePresetL(*cirPreset); |
|
239 CleanupStack::PopAndDestroy(cirPreset); |
|
240 } |
|
241 |
|
242 void IRQFavoritesDBPrivate::replaceUserDefinedPresetL(const IRQPreset& aNewPreset) |
|
243 { |
|
244 CIRIsdsPreset *cirPreset = CIRIsdsPreset::NewLC(); |
|
245 IRQUtility::convertIRQPreset2CIRIsdsPreset(aNewPreset, *cirPreset); |
|
246 mIRFavoritesDb->ReplaceUserDefinedPresetL(*cirPreset); |
|
247 CleanupStack::PopAndDestroy(cirPreset); |
|
248 } |
|
249 |
|
250 void IRQFavoritesDBPrivate::increasePlayedTimesL(const IRQPreset &aPreset) |
|
251 { |
|
252 CIRIsdsPreset * cirPreset = CIRIsdsPreset::NewLC(); |
|
253 IRQUtility::convertIRQPreset2CIRIsdsPreset(aPreset, *cirPreset); |
|
254 mIRFavoritesDb->IncreasePlayedTimesL(*cirPreset); |
|
255 CleanupStack::PopAndDestroy(cirPreset); |
|
256 } |