author | teknolog |
Wed, 31 Mar 2010 16:09:11 +0100 | |
changeset 96 | a8538f50e2ba |
parent 56 | c5cd47bc11ef |
parent 93 | bbf5c5204844 |
child 109 | 223f270fa7ff |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include <commdb.h> |
|
20 |
#include "PodcastModel.h" |
|
21 |
#include "FeedEngine.h" |
|
22 |
#include "SettingsEngine.h" |
|
23 |
#include "ShowEngine.h" |
|
24 |
#include "connectionengine.h" |
|
25 |
||
26 |
#include <cmdestination.h> |
|
27 |
#include <cmmanager.h> |
|
28 |
#include <bautils.h> |
|
29 |
||
30 |
const TInt KDefaultGranu = 5; |
|
31 |
_LIT(KDBFileName, "podcatcher.sqlite"); |
|
32 |
_LIT(KDBTemplateFileName, "podcatcher.sqlite.template"); |
|
33 |
||
34 |
EXPORT_C CPodcastModel* CPodcastModel::NewL() |
|
35 |
{ |
|
36 |
CPodcastModel* self = new (ELeave) CPodcastModel; |
|
37 |
CleanupStack::PushL(self); |
|
38 |
self->ConstructL(); |
|
39 |
CleanupStack::Pop(self); |
|
40 |
return self; |
|
41 |
} |
|
42 |
||
43 |
CPodcastModel::~CPodcastModel() |
|
44 |
{ |
|
45 |
||
46 |
delete iFeedEngine; |
|
47 |
delete iSettingsEngine; |
|
48 |
delete iShowEngine; |
|
49 |
||
50 |
delete iIapNameArray; |
|
51 |
iIapIdArray.Close(); |
|
52 |
||
53 |
delete iSNAPNameArray; |
|
54 |
iSNAPIdArray.Close(); |
|
55 |
delete iCommDB; |
|
56 |
sqlite3_close(iDB); |
|
57 |
iFsSession.Close(); |
|
58 |
iActiveShowList.ResetAndDestroy(); |
|
59 |
iActiveShowList.Close(); |
|
60 |
delete iConnectionEngine; |
|
61 |
iCmManager.Close(); |
|
62 |
delete iImageHandler; |
|
63 |
} |
|
64 |
||
65 |
CPodcastModel::CPodcastModel() |
|
66 |
{ |
|
67 |
} |
|
68 |
||
69 |
void CPodcastModel::ConstructL() |
|
70 |
{ |
|
71 |
DP("CPodcastModel::ConstructL BEGIN"); |
|
72 |
User::LeaveIfError(iFsSession.Connect()); |
|
73 |
||
74 |
iCommDB = CCommsDatabase::NewL (EDatabaseTypeUnspecified); |
|
75 |
//iCommDB ->ShowHiddenRecords(); // magic |
|
76 |
iIapNameArray = new (ELeave) CDesCArrayFlat(KDefaultGranu); |
|
77 |
iSNAPNameArray = new (ELeave) CDesCArrayFlat(KDefaultGranu); |
|
78 |
iCmManager.OpenL(); |
|
93
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
91
diff
changeset
|
79 |
iImageHandler = CImageHandler::NewL(FsSession(), *this); |
2 | 80 |
|
81 |
UpdateIAPListL(); |
|
82 |
UpdateSNAPListL(); |
|
83 |
||
84 |
iSettingsEngine = CSettingsEngine::NewL(*this); |
|
85 |
iConnectionEngine = CConnectionEngine::NewL(*this); |
|
86 |
||
87 |
iFeedEngine = CFeedEngine::NewL(*this); |
|
88 |
iShowEngine = CShowEngine::NewL(*this); |
|
89 |
||
90 |
DP("CPodcastModel::ConstructL END"); |
|
91 |
} |
|
92 |
||
93 |
||
94 |
||
95 |
EXPORT_C void CPodcastModel::UpdateIAPListL() |
|
96 |
{ |
|
97 |
iIapNameArray->Reset(); |
|
98 |
iIapIdArray.Reset(); |
|
99 |
||
100 |
CCommsDbTableView* table = iCommDB->OpenTableLC (TPtrC (IAP)); |
|
101 |
TInt ret = table->GotoFirstRecord (); |
|
102 |
TPodcastIAPItem IAPItem; |
|
103 |
TBuf <KCommsDbSvrMaxFieldLength> bufName; |
|
104 |
while (ret == KErrNone) // There was a first record |
|
105 |
{ |
|
106 |
table->ReadUintL(TPtrC(COMMDB_ID), IAPItem.iIapId); |
|
107 |
table->ReadTextL (TPtrC(COMMDB_NAME), bufName); |
|
108 |
table->ReadTextL (TPtrC(IAP_BEARER_TYPE), IAPItem.iBearerType); |
|
109 |
table->ReadTextL (TPtrC(IAP_SERVICE_TYPE), IAPItem.iServiceType); |
|
110 |
||
111 |
iIapIdArray.Append(IAPItem); |
|
112 |
iIapNameArray->AppendL(bufName); |
|
113 |
ret = table->GotoNextRecord(); |
|
114 |
} |
|
115 |
CleanupStack::PopAndDestroy(); // Close table |
|
116 |
} |
|
117 |
||
118 |
EXPORT_C void CPodcastModel::UpdateSNAPListL() |
|
119 |
{ |
|
120 |
DP("CPodcastModel::UpdateSNAPListL BEGIN"); |
|
121 |
iSNAPNameArray->Reset(); |
|
122 |
iSNAPIdArray.Reset(); |
|
123 |
||
124 |
RCmDestination destination; |
|
125 |
TPodcastIAPItem IAPItem; |
|
126 |
||
127 |
RArray<TUint32> destArray; |
|
128 |
CleanupClosePushL(destArray); |
|
129 |
iCmManager.AllDestinationsL(destArray); |
|
130 |
||
131 |
TInt cnt = destArray.Count(); |
|
132 |
DP1("destArray.Count==%d", cnt); |
|
133 |
for(TInt loop = 0;loop<cnt;loop++) |
|
134 |
{ |
|
135 |
destination = iCmManager.DestinationL (destArray[loop]); |
|
136 |
CleanupClosePushL(destination); |
|
137 |
if(!destination.IsHidden()) |
|
138 |
{ |
|
139 |
IAPItem.iIapId = destArray[loop]; |
|
140 |
HBufC* name = destination.NameLC(); |
|
141 |
DP1(" destination.NameLC==%S", name); |
|
142 |
iSNAPNameArray->AppendL(*name); |
|
143 |
CleanupStack::PopAndDestroy(name); |
|
144 |
iSNAPIdArray.Append(IAPItem); |
|
145 |
} |
|
146 |
CleanupStack::PopAndDestroy();//close destination |
|
147 |
} |
|
148 |
CleanupStack::PopAndDestroy();// close destArray |
|
149 |
||
150 |
DP("CPodcastModel::UpdateSNAPListL END"); |
|
151 |
} |
|
152 |
||
153 |
EXPORT_C CDesCArrayFlat* CPodcastModel::IAPNames() |
|
154 |
{ |
|
155 |
return iIapNameArray; |
|
156 |
} |
|
157 |
||
158 |
EXPORT_C RArray<TPodcastIAPItem>& CPodcastModel::IAPIds() |
|
159 |
{ |
|
160 |
return iIapIdArray; |
|
161 |
} |
|
162 |
||
163 |
EXPORT_C CDesCArrayFlat* CPodcastModel::SNAPNames() |
|
164 |
{ |
|
165 |
return iSNAPNameArray; |
|
166 |
} |
|
167 |
||
168 |
EXPORT_C RArray<TPodcastIAPItem>& CPodcastModel::SNAPIds() |
|
169 |
{ |
|
170 |
return iSNAPIdArray; |
|
171 |
} |
|
172 |
||
173 |
||
174 |
RFs& CPodcastModel::FsSession() |
|
175 |
{ |
|
176 |
return iFsSession; |
|
177 |
} |
|
178 |
||
179 |
EXPORT_C void CPodcastModel::SetPlayingPodcast(CShowInfo* aPodcast) |
|
180 |
{ |
|
181 |
iPlayingPodcast = aPodcast; |
|
182 |
} |
|
183 |
||
184 |
EXPORT_C CShowInfo* CPodcastModel::PlayingPodcast() |
|
185 |
{ |
|
186 |
return iPlayingPodcast; |
|
187 |
} |
|
188 |
||
189 |
EXPORT_C CFeedEngine& CPodcastModel::FeedEngine() |
|
190 |
{ |
|
191 |
return *iFeedEngine; |
|
192 |
} |
|
193 |
||
194 |
EXPORT_C CShowEngine& CPodcastModel::ShowEngine() |
|
195 |
{ |
|
196 |
return *iShowEngine; |
|
197 |
} |
|
198 |
||
199 |
EXPORT_C CSettingsEngine& CPodcastModel::SettingsEngine() |
|
200 |
{ |
|
201 |
return *iSettingsEngine; |
|
202 |
} |
|
203 |
||
204 |
EXPORT_C CConnectionEngine& CPodcastModel::ConnectionEngine() |
|
205 |
{ |
|
206 |
return *iConnectionEngine; |
|
207 |
} |
|
208 |
||
209 |
EXPORT_C void CPodcastModel::PlayPausePodcastL(CShowInfo* aPodcast, TBool aPlayOnInit) |
|
210 |
{ |
|
44 | 211 |
// TODO: interact with MPX |
2 | 212 |
} |
213 |
||
214 |
EXPORT_C CFeedInfo* CPodcastModel::ActiveFeedInfo() |
|
215 |
{ |
|
216 |
return iActiveFeed; |
|
217 |
} |
|
218 |
||
219 |
EXPORT_C void CPodcastModel::SetActiveFeedInfo(CFeedInfo* aFeedInfo) |
|
220 |
{ |
|
221 |
iActiveFeed = aFeedInfo; |
|
222 |
} |
|
223 |
||
224 |
EXPORT_C RShowInfoArray& CPodcastModel::ActiveShowList() |
|
225 |
{ |
|
226 |
return iActiveShowList; |
|
227 |
} |
|
228 |
||
229 |
void CPodcastModel::SetActiveShowList(RShowInfoArray& aShowArray) |
|
230 |
{ |
|
231 |
iActiveShowList.ResetAndDestroy(); |
|
232 |
TInt cnt = aShowArray.Count(); |
|
233 |
||
234 |
for(TInt loop = 0;loop < cnt; loop++) |
|
235 |
{ |
|
236 |
iActiveShowList.Append(aShowArray[loop]); |
|
237 |
} |
|
238 |
} |
|
239 |
||
240 |
sqlite3* CPodcastModel::DB() |
|
241 |
{ |
|
56 | 242 |
DP("CPodcastModel::DB BEGIN"); |
2 | 243 |
if (iDB == NULL) { |
244 |
TFileName dbFileName; |
|
91
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
245 |
dbFileName.Copy(iSettingsEngine->PrivatePath()); |
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
246 |
//iFsSession.PrivatePath(dbFileName); |
2 | 247 |
dbFileName.Append(KDBFileName); |
248 |
DP1("DB is at %S", &dbFileName); |
|
249 |
||
250 |
if (!BaflUtils::FileExists(iFsSession, dbFileName)) { |
|
251 |
TFileName dbTemplate; |
|
91
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
252 |
dbTemplate.Copy(iSettingsEngine->PrivatePath()); |
87cb33beeae2
Remove icon index. Start caching icons as mbms.
Lars Persson <lars.persson@embeddev.se>
parents:
32
diff
changeset
|
253 |
//iFsSession.PrivatePath(dbTemplate); |
2 | 254 |
dbTemplate.Append(KDBTemplateFileName); |
255 |
DP1("No DB found, copying template from %S", &dbTemplate); |
|
256 |
BaflUtils::CopyFile(iFsSession, dbTemplate,dbFileName); |
|
257 |
iIsFirstStartup = ETrue; |
|
258 |
} |
|
259 |
||
260 |
TBuf8<KMaxFileName> filename8; |
|
261 |
filename8.Copy(dbFileName); |
|
56 | 262 |
DP("Before sqlite3_open"); |
263 |
int rc = sqlite3_open((const char*) filename8.PtrZ(), &iDB); |
|
2 | 264 |
if( rc != SQLITE_OK){ |
265 |
DP("Error loading DB"); |
|
266 |
User::Panic(_L("Podcatcher"), 10); |
|
267 |
} |
|
268 |
||
269 |
||
270 |
} |
|
56 | 271 |
DP("CPodcastModel::DB END"); |
2 | 272 |
return iDB; |
273 |
} |
|
274 |
||
275 |
void CPodcastModel::SetProxyUsageIfNeededL(RHTTPSession& aSession) |
|
276 |
{ |
|
277 |
TBool useProxy = EFalse; |
|
278 |
HBufC* serverName = NULL; |
|
279 |
TUint32 port = 0; |
|
280 |
||
281 |
TRAPD(err,GetProxyInformationForConnectionL(useProxy, serverName, port)); |
|
282 |
if (err == KErrNone && useProxy) |
|
283 |
{ |
|
284 |
CleanupStack::PushL(serverName); |
|
285 |
TBuf8<128> proxyAddr; |
|
286 |
proxyAddr.Append(*serverName); |
|
287 |
proxyAddr.Append(':'); |
|
288 |
proxyAddr.AppendNum(port); |
|
289 |
||
290 |
RStringF prxAddr = aSession.StringPool().OpenFStringL(proxyAddr); |
|
291 |
CleanupClosePushL(prxAddr); |
|
292 |
THTTPHdrVal prxUsage(aSession.StringPool().StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
293 |
||
294 |
aSession.ConnectionInfo().SetPropertyL( |
|
295 |
aSession.StringPool().StringF(HTTP::EProxyUsage,RHTTPSession::GetTable()), |
|
296 |
aSession.StringPool().StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
297 |
||
298 |
aSession.ConnectionInfo().SetPropertyL(aSession.StringPool().StringF(HTTP::EProxyAddress,RHTTPSession::GetTable()), prxAddr); |
|
299 |
||
300 |
CleanupStack::PopAndDestroy(&prxAddr); |
|
301 |
CleanupStack::PopAndDestroy(serverName); |
|
302 |
} |
|
303 |
} |
|
304 |
||
305 |
||
306 |
void CPodcastModel::GetProxyInformationForConnectionL(TBool& aIsUsed, HBufC*& aProxyServerName, TUint32& aPort) |
|
307 |
{ |
|
308 |
TInt iapId = GetIapId(); |
|
309 |
CCommsDbTableView* table = iCommDB->OpenViewMatchingUintLC(TPtrC(IAP), TPtrC(COMMDB_ID), iapId); |
|
310 |
||
311 |
TUint32 iapService; |
|
312 |
HBufC* iapServiceType; |
|
313 |
table->ReadUintL(TPtrC(IAP_SERVICE), iapService); |
|
314 |
iapServiceType = table->ReadLongTextLC(TPtrC(IAP_SERVICE_TYPE)); |
|
315 |
||
316 |
CCommsDbTableView* proxyTableView = iCommDB->OpenViewOnProxyRecordLC(iapService, *iapServiceType); |
|
317 |
TInt err = proxyTableView->GotoFirstRecord(); |
|
318 |
if( err != KErrNone) |
|
319 |
{ |
|
320 |
User::Leave(KErrNotFound); |
|
321 |
} |
|
322 |
||
323 |
proxyTableView->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), aIsUsed); |
|
324 |
if(aIsUsed) |
|
325 |
{ |
|
326 |
HBufC* serverName = proxyTableView->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME)); |
|
327 |
proxyTableView->ReadUintL(TPtrC(PROXY_PORT_NUMBER), aPort); |
|
328 |
aProxyServerName = serverName->AllocL(); |
|
329 |
CleanupStack::PopAndDestroy(serverName); |
|
330 |
} |
|
331 |
||
332 |
CleanupStack::PopAndDestroy(proxyTableView); |
|
333 |
CleanupStack::PopAndDestroy(iapServiceType); |
|
334 |
CleanupStack::PopAndDestroy(table); |
|
335 |
} |
|
336 |
||
337 |
||
338 |
TInt CPodcastModel::GetIapId() |
|
339 |
{ |
|
340 |
_LIT(KSetting, "IAP\\Id"); |
|
341 |
TUint32 iapId = 0; |
|
342 |
iConnectionEngine->Connection().GetIntSetting(KSetting, iapId); |
|
343 |
return iapId; |
|
344 |
} |
|
345 |
||
8 | 346 |
EXPORT_C void CPodcastModel::GetAllShowsL() |
2 | 347 |
{ |
348 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 349 |
iShowEngine->GetAllShowsL(iActiveShowList); |
2 | 350 |
} |
351 |
||
8 | 352 |
EXPORT_C void CPodcastModel::GetNewShowsL() |
2 | 353 |
{ |
354 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 355 |
iShowEngine->GetNewShowsL(iActiveShowList); |
2 | 356 |
} |
357 |
||
8 | 358 |
EXPORT_C void CPodcastModel::GetShowsDownloadedL() |
2 | 359 |
{ |
360 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 361 |
iShowEngine->GetShowsDownloadedL(iActiveShowList); |
2 | 362 |
} |
363 |
||
8 | 364 |
EXPORT_C void CPodcastModel::GetShowsDownloadingL() |
2 | 365 |
{ |
366 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 367 |
iShowEngine->GetShowsDownloadingL(iActiveShowList); |
2 | 368 |
} |
369 |
||
8 | 370 |
EXPORT_C void CPodcastModel::GetShowsByFeedL(TUint aFeedUid) |
2 | 371 |
{ |
372 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 373 |
iShowEngine->GetShowsByFeedL(iActiveShowList, aFeedUid); |
2 | 374 |
} |
375 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
376 |
EXPORT_C void CPodcastModel::MarkSelectionPlayedL() |
2 | 377 |
{ |
378 |
for (int i=0;i<iActiveShowList.Count();i++) { |
|
379 |
if(iActiveShowList[i]->PlayState() != EPlayed) { |
|
380 |
iActiveShowList[i]->SetPlayState(EPlayed); |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
381 |
iShowEngine->UpdateShowL(*iActiveShowList[i]); |
2 | 382 |
} |
383 |
} |
|
384 |
} |
|
385 |
||
386 |
TInt CPodcastModel::FindActiveShowByUid(TUint aUid) |
|
387 |
{ |
|
388 |
for (int i=0;i<iActiveShowList.Count();i++) { |
|
389 |
if (iActiveShowList[i]->Uid() == aUid) { |
|
390 |
return i; |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
return KErrNotFound; |
|
395 |
} |
|
396 |
||
397 |
EXPORT_C TBool CPodcastModel::IsFirstStartup() |
|
398 |
{ |
|
399 |
return iIsFirstStartup; |
|
400 |
} |
|
401 |
||
402 |
||
93
bbf5c5204844
We always build the static version of sqlite for now. Further improvements for signaling when icons has been generated so these can be used in the feedview
Lars Persson <lars.persson@embeddev.se>
parents:
91
diff
changeset
|
403 |
void CPodcastModel::ImageOperationCompleteL(TInt /*aError*/, TUint /*aHandle*/, CPodcastModel& /*aPodcastModel*/) |
2 | 404 |
{ |
405 |
||
406 |
} |
|
407 |
||
408 |
EXPORT_C CImageHandler& CPodcastModel::ImageHandler() |
|
409 |
{ |
|
410 |
return *iImageHandler; |
|
411 |
} |