author | teknolog |
Sat, 13 Mar 2010 22:00:39 +0000 | |
changeset 56 | c5cd47bc11ef |
parent 44 | f6f9647922ba |
child 67 | 9c24c921ec35 |
child 96 | a8538f50e2ba |
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(); |
|
79 |
iImageHandler = CImageHandler::NewL(FsSession()); |
|
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; |
|
245 |
iFsSession.PrivatePath(dbFileName); |
|
246 |
dbFileName.Append(KDBFileName); |
|
247 |
DP1("DB is at %S", &dbFileName); |
|
248 |
||
249 |
if (!BaflUtils::FileExists(iFsSession, dbFileName)) { |
|
250 |
TFileName dbTemplate; |
|
251 |
iFsSession.PrivatePath(dbTemplate); |
|
252 |
dbTemplate.Append(KDBTemplateFileName); |
|
253 |
DP1("No DB found, copying template from %S", &dbTemplate); |
|
254 |
BaflUtils::CopyFile(iFsSession, dbTemplate,dbFileName); |
|
255 |
iIsFirstStartup = ETrue; |
|
256 |
} |
|
257 |
||
258 |
TBuf8<KMaxFileName> filename8; |
|
259 |
filename8.Copy(dbFileName); |
|
56 | 260 |
DP("Before sqlite3_open"); |
261 |
int rc = sqlite3_open((const char*) filename8.PtrZ(), &iDB); |
|
2 | 262 |
if( rc != SQLITE_OK){ |
263 |
DP("Error loading DB"); |
|
264 |
User::Panic(_L("Podcatcher"), 10); |
|
265 |
} |
|
266 |
||
267 |
||
268 |
} |
|
56 | 269 |
DP("CPodcastModel::DB END"); |
2 | 270 |
return iDB; |
271 |
} |
|
272 |
||
273 |
void CPodcastModel::SetProxyUsageIfNeededL(RHTTPSession& aSession) |
|
274 |
{ |
|
275 |
TBool useProxy = EFalse; |
|
276 |
HBufC* serverName = NULL; |
|
277 |
TUint32 port = 0; |
|
278 |
||
279 |
TRAPD(err,GetProxyInformationForConnectionL(useProxy, serverName, port)); |
|
280 |
if (err == KErrNone && useProxy) |
|
281 |
{ |
|
282 |
CleanupStack::PushL(serverName); |
|
283 |
TBuf8<128> proxyAddr; |
|
284 |
proxyAddr.Append(*serverName); |
|
285 |
proxyAddr.Append(':'); |
|
286 |
proxyAddr.AppendNum(port); |
|
287 |
||
288 |
RStringF prxAddr = aSession.StringPool().OpenFStringL(proxyAddr); |
|
289 |
CleanupClosePushL(prxAddr); |
|
290 |
THTTPHdrVal prxUsage(aSession.StringPool().StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
291 |
||
292 |
aSession.ConnectionInfo().SetPropertyL( |
|
293 |
aSession.StringPool().StringF(HTTP::EProxyUsage,RHTTPSession::GetTable()), |
|
294 |
aSession.StringPool().StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
295 |
||
296 |
aSession.ConnectionInfo().SetPropertyL(aSession.StringPool().StringF(HTTP::EProxyAddress,RHTTPSession::GetTable()), prxAddr); |
|
297 |
||
298 |
CleanupStack::PopAndDestroy(&prxAddr); |
|
299 |
CleanupStack::PopAndDestroy(serverName); |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
||
304 |
void CPodcastModel::GetProxyInformationForConnectionL(TBool& aIsUsed, HBufC*& aProxyServerName, TUint32& aPort) |
|
305 |
{ |
|
306 |
TInt iapId = GetIapId(); |
|
307 |
CCommsDbTableView* table = iCommDB->OpenViewMatchingUintLC(TPtrC(IAP), TPtrC(COMMDB_ID), iapId); |
|
308 |
||
309 |
TUint32 iapService; |
|
310 |
HBufC* iapServiceType; |
|
311 |
table->ReadUintL(TPtrC(IAP_SERVICE), iapService); |
|
312 |
iapServiceType = table->ReadLongTextLC(TPtrC(IAP_SERVICE_TYPE)); |
|
313 |
||
314 |
CCommsDbTableView* proxyTableView = iCommDB->OpenViewOnProxyRecordLC(iapService, *iapServiceType); |
|
315 |
TInt err = proxyTableView->GotoFirstRecord(); |
|
316 |
if( err != KErrNone) |
|
317 |
{ |
|
318 |
User::Leave(KErrNotFound); |
|
319 |
} |
|
320 |
||
321 |
proxyTableView->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), aIsUsed); |
|
322 |
if(aIsUsed) |
|
323 |
{ |
|
324 |
HBufC* serverName = proxyTableView->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME)); |
|
325 |
proxyTableView->ReadUintL(TPtrC(PROXY_PORT_NUMBER), aPort); |
|
326 |
aProxyServerName = serverName->AllocL(); |
|
327 |
CleanupStack::PopAndDestroy(serverName); |
|
328 |
} |
|
329 |
||
330 |
CleanupStack::PopAndDestroy(proxyTableView); |
|
331 |
CleanupStack::PopAndDestroy(iapServiceType); |
|
332 |
CleanupStack::PopAndDestroy(table); |
|
333 |
} |
|
334 |
||
335 |
||
336 |
TInt CPodcastModel::GetIapId() |
|
337 |
{ |
|
338 |
_LIT(KSetting, "IAP\\Id"); |
|
339 |
TUint32 iapId = 0; |
|
340 |
iConnectionEngine->Connection().GetIntSetting(KSetting, iapId); |
|
341 |
return iapId; |
|
342 |
} |
|
343 |
||
8 | 344 |
EXPORT_C void CPodcastModel::GetAllShowsL() |
2 | 345 |
{ |
346 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 347 |
iShowEngine->GetAllShowsL(iActiveShowList); |
2 | 348 |
} |
349 |
||
8 | 350 |
EXPORT_C void CPodcastModel::GetNewShowsL() |
2 | 351 |
{ |
352 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 353 |
iShowEngine->GetNewShowsL(iActiveShowList); |
2 | 354 |
} |
355 |
||
8 | 356 |
EXPORT_C void CPodcastModel::GetShowsDownloadedL() |
2 | 357 |
{ |
358 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 359 |
iShowEngine->GetShowsDownloadedL(iActiveShowList); |
2 | 360 |
} |
361 |
||
8 | 362 |
EXPORT_C void CPodcastModel::GetShowsDownloadingL() |
2 | 363 |
{ |
364 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 365 |
iShowEngine->GetShowsDownloadingL(iActiveShowList); |
2 | 366 |
} |
367 |
||
8 | 368 |
EXPORT_C void CPodcastModel::GetShowsByFeedL(TUint aFeedUid) |
2 | 369 |
{ |
370 |
iActiveShowList.ResetAndDestroy(); |
|
8 | 371 |
iShowEngine->GetShowsByFeedL(iActiveShowList, aFeedUid); |
2 | 372 |
} |
373 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
8
diff
changeset
|
374 |
EXPORT_C void CPodcastModel::MarkSelectionPlayedL() |
2 | 375 |
{ |
376 |
for (int i=0;i<iActiveShowList.Count();i++) { |
|
377 |
if(iActiveShowList[i]->PlayState() != EPlayed) { |
|
378 |
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
|
379 |
iShowEngine->UpdateShowL(*iActiveShowList[i]); |
2 | 380 |
} |
381 |
} |
|
382 |
} |
|
383 |
||
384 |
TInt CPodcastModel::FindActiveShowByUid(TUint aUid) |
|
385 |
{ |
|
386 |
for (int i=0;i<iActiveShowList.Count();i++) { |
|
387 |
if (iActiveShowList[i]->Uid() == aUid) { |
|
388 |
return i; |
|
389 |
} |
|
390 |
} |
|
391 |
||
392 |
return KErrNotFound; |
|
393 |
} |
|
394 |
||
395 |
EXPORT_C TBool CPodcastModel::IsFirstStartup() |
|
396 |
{ |
|
397 |
return iIsFirstStartup; |
|
398 |
} |
|
399 |
||
400 |
||
32
26a3f2dfba08
Fix for bug where we always load the feed icon a large number of times
teknolog
parents:
8
diff
changeset
|
401 |
void CPodcastModel::ImageOperationCompleteL(TInt /*aError*/, TUint /*aHandle*/) |
2 | 402 |
{ |
403 |
||
404 |
} |
|
405 |
||
406 |
EXPORT_C CImageHandler& CPodcastModel::ImageHandler() |
|
407 |
{ |
|
408 |
return *iImageHandler; |
|
409 |
} |