|
1 /* |
|
2 * Copyright (c) 2002-2004 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 applicationmanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "AMDownloadStore.h" |
|
19 #include "debug.h" |
|
20 #include "ApplicationManagementUtility.h" |
|
21 #include "amsmlhelper.h" |
|
22 |
|
23 using namespace NApplicationManagement; |
|
24 |
|
25 CAMDownloadStore::CAMDownloadStore(MDownloadMngrObserver& aObserver) : |
|
26 CActive(CActive::EPriorityStandard),iObserver(aObserver) |
|
27 { |
|
28 |
|
29 } |
|
30 |
|
31 void CAMDownloadStore::ConstructL() |
|
32 { |
|
33 CActiveScheduler::Add(this); |
|
34 } |
|
35 |
|
36 CAMDownloadStore* CAMDownloadStore::NewL(MDownloadMngrObserver& aObserver) |
|
37 { |
|
38 CAMDownloadStore* self = new (ELeave) CAMDownloadStore(aObserver); |
|
39 |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 CAMDownloadStore::~CAMDownloadStore() |
|
48 { |
|
49 iDwnldStore.ResetAndDestroy(); |
|
50 } |
|
51 |
|
52 void CAMDownloadStore::AddDownloadL(CDeploymentComponent *aComponent) |
|
53 { |
|
54 CAMDwnldQTWrap *download = CAMDwnldQTWrap::NewL(iObserver, aComponent); |
|
55 iDwnldStore.Append(download); |
|
56 StartDownload(); |
|
57 } |
|
58 |
|
59 void CAMDownloadStore::StartDownload() |
|
60 { |
|
61 if (!IsActive()) |
|
62 { |
|
63 |
|
64 iStatus = KRequestPending; |
|
65 |
|
66 TInt downldcount = iDwnldStore.Count(); |
|
67 CAMDwnldQTWrap *download = iDwnldStore[downldcount - 1]; |
|
68 |
|
69 download->StartDownload(download->iComponent, iStatus); |
|
70 |
|
71 SetActive(); |
|
72 } |
|
73 } |
|
74 |
|
75 TInt CAMDownloadStore::DownloadCount() |
|
76 { |
|
77 return iDwnldStore.Count(); |
|
78 } |
|
79 |
|
80 void CAMDownloadStore::RunL() |
|
81 { |
|
82 TInt downldcount = iDwnldStore.Count(); |
|
83 |
|
84 iDwnldStore.Remove(downldcount - 1); |
|
85 |
|
86 if (iDwnldStore.Count() > 0) |
|
87 StartDownload(); |
|
88 } |
|
89 |
|
90 void CAMDownloadStore::DoCancel() |
|
91 { |
|
92 |
|
93 } |
|
94 |
|
95 CAMDwnldQTWrap::CAMDwnldQTWrap(MDownloadMngrObserver& aObserver, |
|
96 CDeploymentComponent *aComponent) : |
|
97 iObserver(aObserver), iComponent(aComponent) |
|
98 { |
|
99 |
|
100 } |
|
101 |
|
102 void CAMDwnldQTWrap::ConstructL() |
|
103 { |
|
104 |
|
105 serverid = SmlHelper::GetCurrentServerIDL(); |
|
106 |
|
107 iap = -1; |
|
108 TRAPD( err, SmlHelper::GetDefaultIAPFromDMProfileL( iap ) ); |
|
109 if (err != KErrNone) |
|
110 { |
|
111 iap = -1; |
|
112 RDEBUG_2("CAMDwnldQTWrap::ConstructL iapid to : %d", err ); |
|
113 } |
|
114 |
|
115 } |
|
116 |
|
117 CAMDwnldQTWrap* CAMDwnldQTWrap::NewL(MDownloadMngrObserver& aObserver, |
|
118 CDeploymentComponent *aComponent) |
|
119 { |
|
120 RDEBUG( "CAMDwnldQTWrap::NewL Start" ); |
|
121 |
|
122 CAMDwnldQTWrap* self = new (ELeave) CAMDwnldQTWrap(aObserver, aComponent); |
|
123 |
|
124 CleanupStack::PushL(self); |
|
125 self->ConstructL(); |
|
126 CleanupStack::Pop(); |
|
127 |
|
128 RDEBUG( "CAMDwnldQTWrap::NewL End" ); |
|
129 |
|
130 return self; |
|
131 } |
|
132 |
|
133 CAMDwnldQTWrap::~CAMDwnldQTWrap() |
|
134 { |
|
135 if (serverid) |
|
136 delete serverid; |
|
137 } |
|
138 |
|
139 void CAMDwnldQTWrap::StartDownload(CDeploymentComponent *aComponent, |
|
140 TRequestStatus& aStatus) |
|
141 { |
|
142 RDEBUG( "CAMDwnldQTWrap::StartDownload Start" ); |
|
143 |
|
144 aComponent->SetCallback(this); |
|
145 appdwnld = new appmgmtdownloadmgr(0, *this, aStatus); |
|
146 appdwnld->startDownload(aComponent); |
|
147 |
|
148 RDEBUG( "CAMDwnldQTWrap::StartDownload End" ); |
|
149 |
|
150 } |
|
151 |
|
152 void CAMDwnldQTWrap::DownloadComplete(CDeploymentComponent *aComponent, |
|
153 TInt aStatus) |
|
154 { |
|
155 |
|
156 TInt err(KErrNone); |
|
157 TRAP( err, DownloadCompleteL( aComponent )); |
|
158 |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------------------- |
|
162 // CAMDownloadManager::DownloadCompleteL |
|
163 // ---------------------------------------------------------------------------------------- |
|
164 void CAMDwnldQTWrap::DownloadCompleteL(CDeploymentComponent *aComponent) |
|
165 { |
|
166 iObserver.ComponentDownloadComplete(aComponent, iap, serverid); |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------------------- |
|
170 // CAMDownloadManager::UidExistsL |
|
171 // ---------------------------------------------------------------------------------------- |
|
172 TBool CAMDwnldQTWrap::UidExistsL(const TUid &aUid, |
|
173 CDeploymentComponent *& aCompo, CDeploymentComponent *aIgnored) |
|
174 { |
|
175 TBool uidExist(EFalse); |
|
176 uidExist = iObserver.HasUidL(aUid, aCompo, aIgnored); |
|
177 return uidExist; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // DownloadCompleted |
|
182 // --------------------------------------------------------------------------- |
|
183 void CAMDwnldQTWrap::DownloadCompleted() |
|
184 { |
|
185 |
|
186 TInt err(KErrNone); |
|
187 QString filename; |
|
188 QString mimetype; |
|
189 |
|
190 QString path("c:\\system\\appmgr\\"); |
|
191 |
|
192 QString filefullpath(path); |
|
193 |
|
194 appdwnld->FileName(filename); |
|
195 appdwnld->MimeType(mimetype); |
|
196 |
|
197 filefullpath.append(filename); |
|
198 |
|
199 TPtrC filenamefullpathptr( |
|
200 reinterpret_cast<const TUint16*> (filefullpath.utf16())); |
|
201 TPtrC8 mimetypeptr( |
|
202 reinterpret_cast<const TUint8*> (mimetype.toUtf8().constData())); |
|
203 |
|
204 CApplicationManagementUtility::SetFileName(filenamefullpathptr); |
|
205 |
|
206 TRAP( err, iComponent->SuccessStatusUpdateL( filenamefullpathptr, mimetypeptr) ); |
|
207 |
|
208 if (err != KErrNone) |
|
209 { |
|
210 RDEBUG_2(" ->iComponent::StatusUpdateL: %d", err ); |
|
211 } |
|
212 RDEBUG_2( "CAMDownload::DownloadCompleted: end Download delete ERROR (%d)", err ); |
|
213 } |
|
214 |
|
215 void CAMDwnldQTWrap::DownloadFailed(TInt aDwnldStatus) |
|
216 { |
|
217 RDEBUG( "CAMDownload::DownloadFailed: start"); |
|
218 //TInt err(KErrNone); |
|
219 //TInt32 errorCode = iDownloader->DownloadStatusCodeL(aDownloadState); |
|
220 TRAPD( err, iComponent->StatusUpdateL( aDwnldStatus ) ); |
|
221 |
|
222 if (err != KErrNone) |
|
223 { |
|
224 RDEBUG_2(" ->iComponent::StatusUpdateL: %d", err ); |
|
225 } |
|
226 RDEBUG_2( "CAMDownload::DownloadFailed: end Download delete ERROR (%d)", err ); |
|
227 } |
|
228 |
|
229 void CAMDwnldQTWrap::SetStatus(TInt aStatus) |
|
230 { |
|
231 TRAPD( err, iComponent->StatusUpdateL( aStatus ) ); |
|
232 if (err != KErrNone) |
|
233 { |
|
234 RDEBUG_2(" ->iComponent::StatusUpdateL: %d", err ); |
|
235 } |
|
236 RDEBUG_2( "CAMDownload::DownloadFailed: end Download delete ERROR (%d)", err ); |
|
237 } |