|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Implementation of NcdPurchaseHistoryUtils |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdpurchasehistoryutils.h" |
|
20 |
|
21 #include "ncdpurchasedetails.h" |
|
22 #include "ncdpurchasedownloadinfo.h" |
|
23 #include "ncdpurchasehistorydbimpl.h" |
|
24 #include "ncdpurchaseinstallinfo.h" |
|
25 #include "ncdutils.h" |
|
26 #include "ncdnodeidentifier.h" |
|
27 #include "ncderrors.h" |
|
28 #include "catalogsutils.h" |
|
29 #include "ncddownloadinfo.h" |
|
30 |
|
31 #include "catalogsdebug.h" |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // Purchase details getter |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CNcdPurchaseDetails* NcdPurchaseHistoryUtils::PurchaseDetailsLC( |
|
38 CNcdPurchaseHistoryDb& aPurchaseHistory, |
|
39 const TUid& aClientUid, |
|
40 const CNcdNodeIdentifier& aMetadataId, |
|
41 TBool aLoadIcon ) |
|
42 { |
|
43 DLTRACEIN(("")) |
|
44 |
|
45 RArray<TUid> clientUid; |
|
46 CleanupClosePushL( clientUid ); |
|
47 clientUid.AppendL( aClientUid ); |
|
48 |
|
49 // Create a filter |
|
50 CNcdPurchaseHistoryFilter* filter = CNcdPurchaseHistoryFilter::NewL( |
|
51 clientUid.Array(), |
|
52 aMetadataId.NodeNameSpace(), |
|
53 aMetadataId.NodeId(), |
|
54 0 ); |
|
55 |
|
56 CleanupStack::PopAndDestroy( &clientUid ); |
|
57 CleanupStack::PushL( filter ); |
|
58 |
|
59 // Get purchase ids |
|
60 RArray<TUint> purchaseIds = aPurchaseHistory.PurchaseIdsL( *filter, |
|
61 CNcdPurchaseHistoryDb::ENewestFirst ); |
|
62 |
|
63 CleanupStack::PopAndDestroy( filter ); |
|
64 CleanupClosePushL( purchaseIds ); |
|
65 |
|
66 // Check that there's at least one purchase |
|
67 if ( !purchaseIds.Count() ) |
|
68 { |
|
69 DLERROR(("No matching purchases found")); |
|
70 User::Leave( KNcdErrorNoPurchaseInformation ); |
|
71 } |
|
72 |
|
73 // Choose the newest purchase |
|
74 CNcdPurchaseDetails* purchase = |
|
75 aPurchaseHistory.PurchaseL( purchaseIds[0], aLoadIcon ); |
|
76 |
|
77 CleanupStack::PopAndDestroy( &purchaseIds ); |
|
78 CleanupStack::PushL( purchase ); |
|
79 return purchase; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Returns true if the given info is a dependency |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 TBool NcdPurchaseHistoryUtils::IsDependency( |
|
87 const MNcdPurchaseDownloadInfo& aInfo ) |
|
88 { |
|
89 DLTRACEIN(("")); |
|
90 return IsOneOf( aInfo.ContentUsage(), |
|
91 MNcdPurchaseDownloadInfo::EDependency, |
|
92 MNcdPurchaseDownloadInfo::ELauncher, |
|
93 MNcdPurchaseDownloadInfo::ELauncherOpen ); |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void NcdPurchaseHistoryUtils::RemoveDependenciesL( |
|
102 CNcdPurchaseDetails& aDetails ) |
|
103 { |
|
104 DLTRACEIN(("")); |
|
105 TInt count = aDetails.DownloadInfoCount(); |
|
106 TInt i = 0; |
|
107 |
|
108 while ( i < count && IsDependency( aDetails.DownloadInfo( i ) ) ) |
|
109 { |
|
110 i++; |
|
111 } |
|
112 |
|
113 DLTRACE(("Deps: %d", i)); |
|
114 while ( i-- ) |
|
115 { |
|
116 aDetails.RemoveDownloadInfo( i ); |
|
117 aDetails.RemoveDownloadedFile( i ); |
|
118 aDetails.RemoveInstallInfo( i ); |
|
119 } |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void NcdPurchaseHistoryUtils::UpdateDependenciesL( |
|
129 CNcdPurchaseDetails& aDetails, |
|
130 const RPointerArray<CNcdDownloadInfo>& aNewDependencies ) |
|
131 { |
|
132 DLTRACEIN(("")); |
|
133 |
|
134 RemoveDependenciesL( aDetails ); |
|
135 |
|
136 CNcdPurchaseDownloadInfo* downloadInfo( NULL ); |
|
137 CNcdPurchaseInstallInfo* installInfo( NULL ); |
|
138 TInt count = aNewDependencies.Count(); |
|
139 |
|
140 // Insert new dependencies to the beginning of the arrays |
|
141 while ( count-- ) |
|
142 { |
|
143 downloadInfo = |
|
144 CNcdPurchaseDownloadInfo::NewLC( |
|
145 *aNewDependencies[ count ] ); |
|
146 aDetails.InsertDownloadInfoL( downloadInfo, 0 ); |
|
147 CleanupStack::Pop( downloadInfo ); |
|
148 |
|
149 DLTRACE(( _L("Adding install info, uid: %x, version: %S"), |
|
150 aNewDependencies[ count ]->ContentId(), |
|
151 &aNewDependencies[ count ]->ContentVersion() )); |
|
152 |
|
153 installInfo = CNcdPurchaseInstallInfo::NewLC(); |
|
154 installInfo->SetApplicationUid( |
|
155 aNewDependencies[ count ]->ContentId() ); |
|
156 installInfo->SetApplicationVersionL( |
|
157 aNewDependencies[ count ]->ContentVersion() ); |
|
158 aDetails.InsertInstallInfoL( installInfo, 0 ); |
|
159 CleanupStack::Pop( installInfo ); |
|
160 |
|
161 aDetails.InsertDownloadedFileL( KNullDesC, 0 ); |
|
162 } |
|
163 |
|
164 DLTRACEOUT(("Download infos added successfully")); |
|
165 } |