12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
|
17 #include <QVariant> |
|
18 |
17 #include "irqfavoritesdb.h" |
19 #include "irqfavoritesdb.h" |
18 #include "irqfavoritesdb_p.h" |
20 #include "favoriteswrapper.h" |
19 |
21 #include "channelhistorywrapper.h" |
20 IRQFavoritesDB::IRQFavoritesDB() : d_ptr(new IRQFavoritesDBPrivate(this)) |
22 #include "urlinfowrapper.h" |
21 { |
23 #include "irqisdsdatastructure.h" |
22 d_ptr->init(); |
24 #include "irqenums.h" |
|
25 |
|
26 IRQFavoritesDB::IRQFavoritesDB() |
|
27 { |
|
28 iFavoritesWrapper = new favoritesWrapper; |
|
29 iHistoryWrapper = new channelHistoryWrapper; |
|
30 iUrlWrapper = new urlInfoWrapper; |
23 } |
31 } |
24 |
32 |
25 IRQFavoritesDB::~IRQFavoritesDB() |
33 IRQFavoritesDB::~IRQFavoritesDB() |
26 { |
34 { |
27 delete d_ptr; |
35 delete iFavoritesWrapper; |
28 } |
36 delete iHistoryWrapper; |
29 |
37 delete iUrlWrapper; |
30 //add a preset |
38 } |
|
39 |
|
40 //add a preset to favorites |
31 //@param IRQPreset& the preset |
41 //@param IRQPreset& the preset |
32 //@return errcode |
42 //@return errcode |
33 int IRQFavoritesDB::addPreset(const IRQPreset& aPreset) |
43 int IRQFavoritesDB::addPreset(const IRQPreset& aPreset) |
34 { |
44 { |
35 return d_ptr->addPreset(aPreset); |
45 bool ret = false; |
36 } |
46 bool newRow = false; |
37 |
47 |
38 //add a preset manually |
48 columnMap map; |
39 //@return errcode |
49 map.insert(channelId, QString::number(aPreset.presetId)); |
40 //@param |
50 ret = iFavoritesWrapper->putFavorites(&map, newRow); |
41 // |
51 |
42 int IRQFavoritesDB::addPreset(const QString& aName, const QString& aURL) |
52 if (!ret) |
43 { |
53 { |
44 return d_ptr->addPreset(aName, aURL); |
54 return EIRQErrorNotFound; //presetId is not found |
45 } |
55 } |
46 |
56 |
47 //get a preset uniq id |
57 if (newRow) |
|
58 { |
|
59 return EIRQErrorNone; |
|
60 } |
|
61 else |
|
62 { |
|
63 return EIRQErrorAlreadyExist; |
|
64 } |
|
65 } |
|
66 |
|
67 //delete a preset |
48 //@return errcode |
68 //@return errcode |
49 //@param |
69 //@param |
50 // |
70 // |
51 int IRQFavoritesDB::getUniqId(int aNum) const |
71 int IRQFavoritesDB::deletePreset(const IRQPreset& aPreset) |
52 { |
72 { |
53 return d_ptr->getUniqId(aNum); |
73 columnMap map; |
54 } |
74 map.insert(channelId, QString::number(aPreset.presetId)); |
55 |
75 bool ret = iFavoritesWrapper->deleteFavorites(&map, NULL); |
56 //delete a preset by uniq id |
76 |
57 //@return errcode |
77 if (ret) |
58 //@param |
78 { |
59 // |
79 return EIRQErrorNone; |
60 int IRQFavoritesDB::deletePreset(int aUniqId) |
80 } |
61 { |
81 else |
62 return d_ptr->deletePreset(aUniqId); |
82 { |
63 } |
83 return EIRQErrorNotFound; |
64 |
84 } |
65 //search a preset by uniqpresetId / isdspresetid |
85 } |
66 //warning: the function needs further checking |
86 |
67 //@return errcode |
|
68 // |
|
69 int IRQFavoritesDB::searchPreset(int aUniqPresetId, int aIsdsPresetId) |
|
70 { |
|
71 return d_ptr->searchPreset(aUniqPresetId, aIsdsPresetId); |
|
72 } |
|
73 |
|
74 // |
|
75 //get the previouse preset index in the internal list |
|
76 //@return the index |
|
77 // |
|
78 int IRQFavoritesDB::getPreviousPreset(int aIndex) |
|
79 { |
|
80 return d_ptr->getPreviousPreset(aIndex); |
|
81 } |
|
82 |
|
83 // |
|
84 //get the next preset index |
|
85 //@return the index |
|
86 // |
|
87 int IRQFavoritesDB::getNextPreset(int aIndex) |
|
88 { |
|
89 return d_ptr->getNextPreset(aIndex); |
|
90 } |
|
91 |
|
92 //replace with new preset |
87 //replace with new preset |
93 //@return errcode |
88 //@return errcode |
94 // |
89 // |
95 int IRQFavoritesDB::replacePreset(const IRQPreset& aNewPreset) |
90 void IRQFavoritesDB::replacePreset(const IRQPreset& aNewPreset) |
96 { |
91 { |
97 return d_ptr->replacePreset(aNewPreset); |
92 //write the preset data to database |
98 } |
93 columnMap map; |
99 |
94 QString url; |
100 //@return errcode |
95 |
101 // |
96 if (IRQPreset::EIsds == aNewPreset.type) |
102 int IRQFavoritesDB::replaceUserDefinedPreset(const IRQPreset& aNewPreset) |
97 { |
103 { |
98 map.insert(channelId, QString::number(aNewPreset.presetId)); |
104 return d_ptr->replaceUserDefinedPreset(aNewPreset); |
99 } |
|
100 map.insert(channelName, aNewPreset.name); |
|
101 map.insert(languageCode, aNewPreset.languageCode); |
|
102 map.insert(languageName, aNewPreset.languageName); |
|
103 map.insert(countryCode, aNewPreset.countryCode); |
|
104 map.insert(countryName, aNewPreset.countryName); |
|
105 map.insert(lastModified, aNewPreset.lastModified); |
|
106 map.insert(musicStoreStatus, aNewPreset.musicStoreStatus); |
|
107 map.insert(description, aNewPreset.description); |
|
108 map.insert(shortDesc, aNewPreset.shortDesc); |
|
109 map.insert(genreId, aNewPreset.genreId); |
|
110 map.insert(genreName, aNewPreset.genreName); |
|
111 map.insert(advertisementUrl, aNewPreset.advertisementUrl); |
|
112 map.insert(advertisementInUse, aNewPreset.advertisementInUse); |
|
113 map.insert(imgUrl, aNewPreset.imgUrl); |
|
114 |
|
115 uint cIdResult = 0; |
|
116 if (IRQPreset::EIsds == aNewPreset.type) |
|
117 { |
|
118 cIdResult = aNewPreset.presetId; |
|
119 columnMap condAnd; |
|
120 condAnd.insert(channelId, QString::number(aNewPreset.presetId)); |
|
121 iHistoryWrapper->putChannelHistory(&map, NULL, NULL, &condAnd); |
|
122 } |
|
123 else |
|
124 { |
|
125 columnMap condAnd; |
|
126 condAnd.insert(channelType, QString::number(aNewPreset.type)); |
|
127 aNewPreset.getChannelUrlAt(0, url); |
|
128 condAnd.insert(channelUrl, url); |
|
129 condAnd.insert(channelName, aNewPreset.name); |
|
130 QList<uint> *ids = iHistoryWrapper->getChannelId(&condAnd); |
|
131 if (ids && ids->count() > 0) |
|
132 { |
|
133 //the user-defined preset is already in database |
|
134 cIdResult = ids->at(0); |
|
135 condAnd.clear(); |
|
136 condAnd.insert(channelId, QString::number(cIdResult)); |
|
137 iHistoryWrapper->putChannelHistory(&map, NULL, NULL, &condAnd); |
|
138 } |
|
139 else |
|
140 { |
|
141 //the user-defined preset is not in database |
|
142 iHistoryWrapper->putChannelHistory(&map, &cIdResult); |
|
143 } |
|
144 |
|
145 delete ids; |
|
146 } |
|
147 |
|
148 //write url info to database |
|
149 columnUrlInfoInsertMap urlmap; |
|
150 |
|
151 unsigned int bitrate = 0; |
|
152 for (int i = 0; i < aNewPreset.getChannelURLCount(); i++) |
|
153 { |
|
154 aNewPreset.getChannelBitrate(i, bitrate); |
|
155 aNewPreset.getChannelUrlAt(i, url); |
|
156 urlmap.insert(url, bitrate); |
|
157 } |
|
158 |
|
159 iUrlWrapper->resetUrlInfo(&urlmap, cIdResult); |
105 } |
160 } |
106 |
161 |
107 //change the preset type to user defined |
162 //change the preset type to user defined |
108 //@return errcode |
163 //@return errcode |
109 // |
164 // |
110 int IRQFavoritesDB::makePresetUserDefined(int aChannelId, int aUserDefinedChannelId) |
165 int IRQFavoritesDB::makePresetUserDefined(int /*aChannelId*/, int /*aUserDefinedChannelId*/) |
111 { |
166 { |
112 return d_ptr->makePresetUserDefined(aChannelId, aUserDefinedChannelId); |
167 return 0; |
113 } |
|
114 |
|
115 //get the empty preset left count |
|
116 //@return the count of empty presets left |
|
117 // |
|
118 int IRQFavoritesDB::emptyPresetCount() const |
|
119 { |
|
120 return d_ptr->emptyPresetCount(); |
|
121 } |
|
122 |
|
123 //get the max preset count supported now |
|
124 //@return errcode |
|
125 // |
|
126 int IRQFavoritesDB::maxPresetCount() |
|
127 { |
|
128 return d_ptr->maxPresetCount(); |
|
129 } |
|
130 |
|
131 //the interface is not used currently. |
|
132 // |
|
133 void IRQFavoritesDB::setMoveStatus(bool aStatus) |
|
134 { |
|
135 d_ptr->setMoveStatus(aStatus); |
|
136 } |
|
137 |
|
138 //the interface is not used currently |
|
139 // |
|
140 bool IRQFavoritesDB::getMoveStatus() |
|
141 { |
|
142 return d_ptr->getMoveStatus(); |
|
143 } |
168 } |
144 |
169 |
145 //for CIRPreset is just an interface so we can wrapper it into the IRQPreset. |
170 //for CIRPreset is just an interface so we can wrapper it into the IRQPreset. |
146 //the interface get the IRQPreset list. The upper layer will free all the items |
171 //the interface get the IRQPreset list. The upper layer will free all the items |
147 //in the list and the list self |
172 //in the list and the list self |
148 // |
173 // |
149 QList<IRQPreset*>* IRQFavoritesDB::getPresets() const |
174 QList<IRQPreset*>* IRQFavoritesDB::getPresets() const |
150 { |
175 { |
151 return d_ptr->getPresets(); |
176 favoritesWrapper favorites; |
152 } |
177 QList<QVariant*> *dataSet = favorites.getFavorites(); |
153 |
178 if (NULL == dataSet) |
154 /* |
179 { |
155 * Increase the played times of the preset if it's in the favorites |
180 return NULL; |
156 */ |
181 } |
157 void IRQFavoritesDB::increasePlayedTimes(const IRQPreset &aPreset) |
182 |
158 { |
183 QList<IRQPreset*> *presetList = NULL; |
159 d_ptr->increasePlayedTimes(aPreset); |
184 if (dataSet->count() > 0) |
|
185 { |
|
186 presetList = new QList<IRQPreset*>; |
|
187 int dataSize = dataSet->count(); |
|
188 for (int i = 0; i < dataSize; ++i) |
|
189 { |
|
190 IRQPreset *preset = new IRQPreset; |
|
191 bool ok = false; |
|
192 QVariant *row = dataSet->at(i); |
|
193 preset->type = row[channelType].toInt(&ok); |
|
194 preset->presetId = row[channelId].toUInt(&ok); |
|
195 preset->name = row[channelName].toString(); |
|
196 preset->nickName = row[channelNickName].toString(); |
|
197 preset->languageCode = row[languageCode].toString(); |
|
198 preset->languageName = row[languageName].toString(); |
|
199 preset->countryCode = row[countryCode].toString(); |
|
200 preset->countryName = row[countryName].toString(); |
|
201 preset->lastModified = row[lastModified].toString(); |
|
202 preset->musicStoreStatus = row[musicStoreStatus].toString(); |
|
203 preset->description = row[description].toString(); |
|
204 preset->shortDesc = row[shortDesc].toString(); |
|
205 preset->genreName = row[genreName].toString(); |
|
206 preset->genreId = row[genreId].toString(); |
|
207 preset->advertisementInUse = row[advertisementInUse].toString(); |
|
208 preset->advertisementUrl = row[advertisementUrl].toString(); |
|
209 preset->imgUrl = row[imgUrl].toString(); |
|
210 |
|
211 delete []row; |
|
212 |
|
213 //get url info and write to preset |
|
214 urlInfoWrapper urlInfo; |
|
215 columnMap cond; |
|
216 cond.insert(channelId, QString::number(preset->presetId)); |
|
217 QList<QVariant*> *urlDataSet = urlInfo.getUrlInfo(&cond, NULL, i, dataSize-1); |
|
218 int urlSize = urlDataSet->count(); |
|
219 for (int j = 0; j < urlSize; ++j) |
|
220 { |
|
221 IRQChannelServerURL url; |
|
222 url.url = urlDataSet->at(j)[channelUrl_URL].toString(); |
|
223 url.bitrate = urlDataSet->at(j)[bitRate_URL].toInt(); |
|
224 preset->insertChannelServer(url); |
|
225 delete []urlDataSet->at(j); |
|
226 } |
|
227 delete urlDataSet; |
|
228 |
|
229 presetList->append(preset); |
|
230 } |
|
231 } |
|
232 |
|
233 delete dataSet; |
|
234 |
|
235 return presetList; |
160 } |
236 } |
161 |
237 |
162 int IRQFavoritesDB::renamePreset(const IRQPreset &aPreset, const QString &aNewName) |
238 int IRQFavoritesDB::renamePreset(const IRQPreset &aPreset, const QString &aNewName) |
163 { |
239 { |
164 return d_ptr->renamePreset(aPreset, aNewName); |
240 channelHistoryWrapper wrapper; |
165 } |
241 columnMap map; |
|
242 |
|
243 map.insert(channelNickName, aNewName); |
|
244 columnMap condAND; |
|
245 condAND.insert(channelId, QString::number(aPreset.presetId)); |
|
246 bool ret = wrapper.putChannelHistory(&map, NULL, NULL, &condAND); |
|
247 |
|
248 if (ret) |
|
249 { |
|
250 return EIRQErrorNone; |
|
251 } |
|
252 else |
|
253 { |
|
254 return EIRQErrorGeneral; |
|
255 } |
|
256 } |