|
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 * Description: Manipulate Interface of Internet Radio Database |
|
13 * |
|
14 */ |
|
15 |
|
16 #ifndef IRDB_H_ |
|
17 #define IRDB_H_ |
|
18 |
|
19 #include <QSqlDatabase> |
|
20 |
|
21 typedef unsigned char IRDBCHAR; |
|
22 |
|
23 class QSqlQuery; |
|
24 class QMutex; |
|
25 class IRDBWrapper; |
|
26 |
|
27 class IRDB |
|
28 { |
|
29 |
|
30 public: |
|
31 /* |
|
32 * create singleton instance or increase reference count; |
|
33 */ |
|
34 static IRDB* getInstance(); |
|
35 |
|
36 /* |
|
37 * release instance or decrease reference count; |
|
38 */ |
|
39 void releaseInstance(); |
|
40 |
|
41 public: |
|
42 /* |
|
43 * destory Internet Radio database, |
|
44 * It will remove the IR database file from disk. |
|
45 * this interface is reserved for future use. |
|
46 */ |
|
47 bool destoryIRDB(); |
|
48 |
|
49 /* |
|
50 * create internet Radio database |
|
51 * It will create the IR database file in disk. |
|
52 * If createIRDB return false, the instance point of IRDB will be released and set to null; |
|
53 */ |
|
54 bool createIRDB(); |
|
55 |
|
56 public: |
|
57 /* |
|
58 * action is invoked from view of playHistory or search; |
|
59 * INSERT/UPDATE row; |
|
60 * manipulation for multiple tables; |
|
61 * for row has a channelid value; |
|
62 * First, this function will insert a row in IRBuff table; |
|
63 * then INSERT/UPDATE this row to searchRlt and channelHistory table, |
|
64 * next above operations will trigger other actions for manipulation other tables in IRDB. |
|
65 * channelId is mandatory paramter. |
|
66 */ |
|
67 IRDBCHAR chgRowIRDB(const QString& aInsSqlStr, |
|
68 const QString& aUpdSqlStr, |
|
69 const uint& channelId, |
|
70 const QString& aCondSqlStr, |
|
71 const QList<QByteArray>* apImgList = NULL, |
|
72 bool bPreHandle = false); |
|
73 /* |
|
74 * action is invoked from view of go to station; |
|
75 * INSERT/UPDATE row; |
|
76 * manipulation for multiple tables; |
|
77 * for no channelid |
|
78 * new channelId will be allocated for this row if condStr == NULL; |
|
79 * or |
|
80 * A exist channelId will be used for this row, this exist channelId is gotten according to condStr |
|
81 * AND this channelId isNOT iSDS's channelID; |
|
82 */ |
|
83 IRDBCHAR chgRowIRDB(QString aInsSqlStr, |
|
84 QString aUpdSqlStr, |
|
85 uint* const cidRet = NULL, |
|
86 const QString& condStr = NULL, |
|
87 const QString& condUserCidStr = NULL, |
|
88 const QList<QByteArray>* apImgList = NULL); |
|
89 |
|
90 /* |
|
91 * this fuction is used while synchronization data with iSDS side; |
|
92 * INSERT/UPDATE row; |
|
93 * manipulation for multiple tables; |
|
94 * for row has a channelid value, |
|
95 * update rows that are storged in channelInfo, advertisement, and img tables; |
|
96 * about urls for channelId, |
|
97 * we need to call <EIRDB insertUrlInfo(const QStringList&) const> after this function call if there is urls updated. |
|
98 * TBD |
|
99 */ |
|
100 IRDBCHAR updateChannelDetailsIRDB(const QString& aInsSqlStr, |
|
101 const QString& aUpdSqlStr, |
|
102 const uint& channelId) |
|
103 { |
|
104 Q_UNUSED(aInsSqlStr); |
|
105 Q_UNUSED(aUpdSqlStr); |
|
106 Q_UNUSED(channelId); |
|
107 return (IRDBCHAR)0; |
|
108 }; |
|
109 |
|
110 public: |
|
111 /* |
|
112 * INSERT/UPDATE row; |
|
113 * manipulation for single table, songHistory table; |
|
114 * the song name is used as the criterion. |
|
115 */ |
|
116 IRDBCHAR chgRowSongHistory(const QString& aInsSqlStr, |
|
117 const QString& aUpdSqlStr, |
|
118 const QString& aSongName, |
|
119 const QString& aCondSqlStr = NULL, |
|
120 const uint& channelId = 0); |
|
121 |
|
122 /* |
|
123 * INSERT/UPDATE row; |
|
124 * for change(update/insert) data in favorites, |
|
125 * channelId is used as criterion |
|
126 */ |
|
127 IRDBCHAR chgRowFavorites(const QString& aInsSqlStr, |
|
128 const QString& aUpdSqlStr, |
|
129 const uint& channelId, |
|
130 bool& bNewRow); |
|
131 |
|
132 /* |
|
133 * TBD |
|
134 */ |
|
135 IRDBCHAR chgAdvertisement(const QString& aInsSqlStr, |
|
136 const QString& aUpdSqlStr, |
|
137 const uint& channelId) |
|
138 { |
|
139 Q_UNUSED(aInsSqlStr); |
|
140 Q_UNUSED(aUpdSqlStr); |
|
141 Q_UNUSED(channelId); |
|
142 |
|
143 return (IRDBCHAR)0; |
|
144 } |
|
145 |
|
146 public: |
|
147 /* |
|
148 * INSERT/DELETE row, in urlInfo table; |
|
149 * step: |
|
150 * 1/ first delete all the rows whose channelID equals to input channelId, |
|
151 * 2/ insert all the rows belonged to one channelId to urlinfo |
|
152 */ |
|
153 IRDBCHAR resetUrlInfo(const QStringList& aInsSqlList, |
|
154 const uint& channelId); |
|
155 |
|
156 /* |
|
157 * only update channelLatestplaytime in channelHistory table for recently play |
|
158 */ |
|
159 IRDBCHAR updRowChannelHistory(const uint& channelId); |
|
160 |
|
161 /* |
|
162 * only update imgUrl, imgLocalFile in img table; |
|
163 */ |
|
164 IRDBCHAR updRowImg(const uint& channelId, |
|
165 const QString& updSqlStr, |
|
166 QList<QByteArray>* apImgList = NULL); |
|
167 |
|
168 public: |
|
169 /* |
|
170 * DELETE rows in |
|
171 * channelHistory, searchRlt, songHistory, favorites, advertisement; |
|
172 * rows in img, channelInfo and urlInfo can't be removed directly. |
|
173 */ |
|
174 IRDBCHAR deleteRow(const QString& aDltSqlStr); |
|
175 |
|
176 /* |
|
177 * DELETE rows in |
|
178 * channelHistory, searchRlt, songHistory, favorites, advertisement; |
|
179 * rows in img, channelInfo and urlInfo can't be removed directly. |
|
180 */ |
|
181 IRDBCHAR selectRow(IRDBWrapper* const apWrapper, |
|
182 const QString& aSltSqlStr, |
|
183 QList<QVariant*>* pDataSet); |
|
184 |
|
185 public: |
|
186 /* |
|
187 * SELECT * from IR_VIEW_ALL; |
|
188 * param is used as condition string; |
|
189 */ |
|
190 IRDBCHAR selectRowIRDB(IRDBWrapper* const apWrapper, |
|
191 const QString& aCondStr, |
|
192 bool bIsSrhCid, |
|
193 QList<uint>* pQListCIDSet, |
|
194 QList<QVariant*>* pQLIstIRDataSet); |
|
195 private: |
|
196 /* |
|
197 * default constructor |
|
198 */ |
|
199 IRDB(); |
|
200 |
|
201 /* |
|
202 * forbid copy constructor |
|
203 */ |
|
204 IRDB(IRDB&); |
|
205 |
|
206 /* |
|
207 * destructor |
|
208 */ |
|
209 ~IRDB(); |
|
210 |
|
211 private: |
|
212 /* |
|
213 * here "=" is forbidded |
|
214 */ |
|
215 const IRDB& operator=(const IRDB&); |
|
216 |
|
217 private: |
|
218 /* |
|
219 * create tables and relations in IRDB; |
|
220 */ |
|
221 bool createIRTable(); |
|
222 |
|
223 /* |
|
224 * open IRDB connection; |
|
225 */ |
|
226 bool openIRDBConnection(); |
|
227 |
|
228 /* |
|
229 * search channelid from channelInfo table; |
|
230 */ |
|
231 IRDBCHAR isChannelIdExisted(uint channelId); |
|
232 |
|
233 private: |
|
234 //IRDB Instance |
|
235 QSqlDatabase m_sqlDB; |
|
236 |
|
237 // reference count |
|
238 int m_RefCnt; |
|
239 |
|
240 // Mutex locker |
|
241 static QMutex mMutex; |
|
242 |
|
243 // The static instance |
|
244 static IRDB* mpIRDBInstance; |
|
245 |
|
246 }; |
|
247 |
|
248 |
|
249 #endif /* IRDB_H_ */ |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |