|
1 /* |
|
2 * Copyright (c) 2000 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 <nsmldmconst.h> |
|
19 #include <downloadmanager.h> |
|
20 #include <download.h> |
|
21 #include <e32Property.h> |
|
22 #include <serviceipc.h> |
|
23 #include <hbdialog.h> |
|
24 #include <hblabel.h> |
|
25 #include <HbMessageBox.h> |
|
26 #include <hbapplication.h> |
|
27 #include <hbdevicenotificationdialog.h> |
|
28 #include <hbaction.h> |
|
29 #include <apgtask.h> |
|
30 #include <coemain.h> |
|
31 #include <e32base.h> |
|
32 #include <eikenv.h> |
|
33 #include <Driveinfo.h> |
|
34 #include <e32property.h> |
|
35 #include "ApplicationManagementUtility.h" |
|
36 #include "debug.h" |
|
37 #include "dmcommon.h" |
|
38 #include "amstorage.h" |
|
39 #include "appmgmtnotifier.h" |
|
40 #include "appmgmtdownloadmgr.h" |
|
41 #include "ServicePluginLogger.h" |
|
42 using namespace NApplicationManagement; |
|
43 |
|
44 // ------------------------------------------------------------------------------------------------ |
|
45 // appmgmtdownloadmgr::appmgmtdownloadmgr |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 appmgmtdownloadmgr::appmgmtdownloadmgr(QWidget* parent, |
|
48 MDownloadMgrQTCallback& callback,TRequestStatus& aStatus) : |
|
49 QWidget(parent), m_callback(callback), iStatus(aStatus) |
|
50 { |
|
51 iProgressNote = NULL; |
|
52 iSetFinalValue = 0; |
|
53 iProgressCancelled = 0; |
|
54 iDialogAccepted = 0; |
|
55 mEndReported = 0; |
|
56 mNetworkLoss = 0; |
|
57 } |
|
58 |
|
59 // ------------------------------------------------------------------------------------------------ |
|
60 // appmgmtdownloadmgr::~appmgmtdownloadmgr |
|
61 // ------------------------------------------------------------------------------------------------ |
|
62 appmgmtdownloadmgr::~appmgmtdownloadmgr() |
|
63 { |
|
64 if (iProgressNote) |
|
65 { |
|
66 iProgressNote->closeAMProgDialog(); |
|
67 delete iProgressNote; |
|
68 iProgressNote = 0; |
|
69 } |
|
70 if(mNote) |
|
71 { |
|
72 delete mNote; |
|
73 mNote=0; |
|
74 } |
|
75 |
|
76 delete iFileName; |
|
77 |
|
78 delete iContentType; |
|
79 |
|
80 delete iURI; |
|
81 delete iComp; |
|
82 } |
|
83 |
|
84 // ------------------------------------------------------------------------------------------------ |
|
85 // appmgmtdownloadmgr::startDownload |
|
86 // ------------------------------------------------------------------------------------------------ |
|
87 void appmgmtdownloadmgr::startDownload(CDeploymentComponent *aComponent) |
|
88 { |
|
89 |
|
90 RDEBUG( "appmgmtdownloadmgr::startDownload Start" ); |
|
91 |
|
92 QString m_appName = "ApplicationManagementServer"; |
|
93 |
|
94 iComp = aComponent; |
|
95 iDownloadManager = new DownloadManager(m_appName); |
|
96 // initialise the downloads of the last session |
|
97 |
|
98 connect(iDownloadManager, |
|
99 SIGNAL(downloadManagerEvent(DownloadManagerEvent *)), this, |
|
100 SLOT(downloadMgrEventRecieved(DownloadManagerEvent *))); |
|
101 |
|
102 iDownloadManager->initialize(); |
|
103 |
|
104 DownloadType m_type = Parallel; |
|
105 |
|
106 DownloadPriority m_priority = High; |
|
107 #ifdef __WINS__ |
|
108 iDownloadManager->setProxy("bswebproxy01.americas.nokia.com", 8080); |
|
109 #endif |
|
110 TBuf<KMaxUrlLength> buf; |
|
111 buf.Copy(aComponent->DownloadURI()); |
|
112 |
|
113 QString url((QChar*) buf.Ptr(), buf.Length()); |
|
114 |
|
115 TInt silentsession = 0; |
|
116 RProperty::Get(KPSUidNSmlSOSServerKey,KNSmlDMSilentJob,silentsession); |
|
117 |
|
118 CApplicationManagementUtility::iSilentSession = silentsession; |
|
119 |
|
120 iDl = iDownloadManager->createDownload(url, m_type); |
|
121 |
|
122 bool t = connect(iDl, SIGNAL(downloadEvent(DownloadEvent *)), this, |
|
123 SLOT(downloadEventRecieved(DownloadEvent *))); |
|
124 |
|
125 if (!iDl) |
|
126 return; |
|
127 |
|
128 QString path("c:\\system\\appmgr\\"); |
|
129 |
|
130 iDl->setAttribute(Priority, m_priority); |
|
131 iDl->setAttribute(DestinationPath, path); |
|
132 iDl->start(); |
|
133 |
|
134 iOperationType = aComponent->DownloadTarget(); |
|
135 |
|
136 RDEBUG( "appmgmtdownloadmgr::startDownload End" ); |
|
137 } |
|
138 |
|
139 // ------------------------------------------------------------------------------------------------ |
|
140 // appmgmtdownloadmgr::convertSize |
|
141 // ------------------------------------------------------------------------------------------------ |
|
142 QString appmgmtdownloadmgr::convertSize() |
|
143 { |
|
144 RDEBUG( "appmgmtdownloadmgr::convertSize Start" ); |
|
145 TBuf<64> size; |
|
146 TReal filesize; |
|
147 TRealFormat realFormat; |
|
148 TInt64 fileKBytes; |
|
149 realFormat.iWidth = 6; |
|
150 |
|
151 //converting size to Kb |
|
152 fileKBytes = m_totalSize / KSizeDivisor; |
|
153 filesize = (TReal) m_totalSize / (KSizeDivisor); |
|
154 size.Num(fileKBytes); |
|
155 |
|
156 //get the length of the value in Kb before the decimal point. |
|
157 //Accordingly convert it further. |
|
158 int len = size.Length(); |
|
159 QString text; |
|
160 if (len >= 7) |
|
161 { |
|
162 //in gb |
|
163 TReal mul = (KSizeDivisor * KSizeDivisor); |
|
164 TReal temp = filesize / mul; |
|
165 size.Num(temp, realFormat); |
|
166 mSize = QString::fromUtf16(size.Ptr(), size.Length()); |
|
167 text = hbTrId("txt_deviceupdate_info_size_1_Gb").arg(mSize); |
|
168 mSizeFormat = "gb"; |
|
169 } |
|
170 else if (len >= 4) |
|
171 { |
|
172 //in mb |
|
173 TReal temp = filesize / KSizeDivisor; |
|
174 size.Num(temp, realFormat); |
|
175 mSize = QString::fromUtf16(size.Ptr(), size.Length()); |
|
176 text = hbTrId("txt_deviceupdate_info_size_1_mb").arg(mSize); |
|
177 mSizeFormat = "mb"; |
|
178 } |
|
179 else |
|
180 { |
|
181 mSize = QString::fromUtf16(size.Ptr(), size.Length()); |
|
182 text = hbTrId("txt_deviceupdate_info_size_1_kb").arg(mSize); |
|
183 mSizeFormat = "kb"; |
|
184 } |
|
185 RDEBUG( "appmgmtdownloadmgr::convertSize End" ); |
|
186 return text; |
|
187 } |
|
188 |
|
189 // ------------------------------------------------------------------------------------------------ |
|
190 // appmgmtdownloadmgr::getAvailableDrives() |
|
191 // ------------------------------------------------------------------------------------------------ |
|
192 void appmgmtdownloadmgr::getAvailableDrives() |
|
193 { |
|
194 RDEBUG( "appmgmtdownloadmgr::getAvailableDrives start" ); |
|
195 RFs iFs; |
|
196 qt_symbian_throwIfError(iFs.Connect()); |
|
197 TDriveList driveList; |
|
198 TInt driveCount = 0; |
|
199 TBuf<20> buf; |
|
200 int i = 0; |
|
201 QString val; |
|
202 QStringList list; |
|
203 TDriveInfo info; |
|
204 TVolumeInfo volumeInfo; |
|
205 qt_symbian_throwIfError(DriveInfo::GetUserVisibleDrives(iFs, driveList, |
|
206 driveCount)); |
|
207 TUint driveStatus = 0; |
|
208 for (TInt index(0); index < KMaxDrives; index++) |
|
209 { |
|
210 if (driveList[index]) |
|
211 { |
|
212 TRealFormat realFormat; |
|
213 qt_symbian_throwIfError(DriveInfo::GetDriveStatus(iFs, index, |
|
214 driveStatus)); |
|
215 TFileName path; |
|
216 TDriveUnit driveUnit(index); |
|
217 if (!(driveStatus & DriveInfo::EDriveRemote)) |
|
218 { |
|
219 TBuf<64> freeSpace; |
|
220 TReal free; |
|
221 TInt64 freeKBytes; |
|
222 realFormat.iWidth = 6; |
|
223 iFs.Drive(info, index); |
|
224 if(iFs.Volume(volumeInfo, index)==KErrNone) |
|
225 { |
|
226 RDEBUG_2("free space: (%d)", volumeInfo.iFree ); |
|
227 freeKBytes = 0; |
|
228 freeKBytes = volumeInfo.iFree / KSizeDivisor; |
|
229 free = volumeInfo.iFree / KSizeDivisor; |
|
230 freeSpace.Num(freeKBytes); |
|
231 TInt sizeUnit = EKb; |
|
232 |
|
233 //converting the drive freespace |
|
234 int len = freeSpace.Length(); |
|
235 if (len >= 7) |
|
236 { |
|
237 TReal nul = (KSizeDivisor * KSizeDivisor); |
|
238 TReal temp = free / nul; |
|
239 freeSpace.Num(temp, realFormat); |
|
240 sizeUnit = EGb; |
|
241 } |
|
242 else |
|
243 { |
|
244 TReal temp = free / KSizeDivisor; |
|
245 freeSpace.Num(temp, realFormat); |
|
246 sizeUnit = EMb; |
|
247 } |
|
248 //Getting the drive name in QString |
|
249 path.Zero(); |
|
250 path.Append(driveUnit.Name()); |
|
251 val = QString::fromUtf16(path.Ptr(), path.Length()); |
|
252 drilist.Append(path); |
|
253 //Getting the drive free space in QString |
|
254 path.Zero(); |
|
255 path.Append(freeSpace); |
|
256 QString str1 = QString::fromUtf16(path.Ptr(), path.Length()); |
|
257 QString driv; |
|
258 if (sizeUnit == EKb) |
|
259 { |
|
260 driv |
|
261 = hbTrId( |
|
262 "txt_deviceupdate_setlabel_install_to_val_1_2_kb").arg( |
|
263 val, str1); |
|
264 } |
|
265 else if (sizeUnit == EMb) |
|
266 { |
|
267 driv |
|
268 = hbTrId( |
|
269 "txt_deviceupdate_setlabel_install_to_val_1_2_Mb").arg( |
|
270 val, str1); |
|
271 } |
|
272 else |
|
273 { |
|
274 driv |
|
275 = hbTrId( |
|
276 "txt_deviceupdate_setlabel_install_to_val_1_2_Gb").arg( |
|
277 val, str1); |
|
278 } |
|
279 mDriveBox->insertItem(i++, driv); |
|
280 } |
|
281 } |
|
282 } |
|
283 } |
|
284 RDEBUG( "appmgmtdownloadmgr::getAvailableDrives End" ); |
|
285 } |
|
286 |
|
287 // ------------------------------------------------------------------------------------------------ |
|
288 // appmgmtdownloadmgr::showInstalltoDialog() |
|
289 // ------------------------------------------------------------------------------------------------ |
|
290 void appmgmtdownloadmgr::showInstalltoDialog() |
|
291 { |
|
292 RDEBUG( "appmgmtdownloadmgr::showIntalltoDialog start" ); |
|
293 HbDocumentLoader loader; |
|
294 QString val; |
|
295 bool ok = false; |
|
296 HbLabel* label; |
|
297 |
|
298 loader.load(":/xml/sample.docml", &ok); |
|
299 if (!ok) |
|
300 { |
|
301 return; |
|
302 } |
|
303 Q_ASSERT_X(ok, "Device Manager", "Invalid docml file"); |
|
304 mDialog = qobject_cast<HbDialog*> (loader.findWidget("dialog")); |
|
305 |
|
306 //set title for the dialog |
|
307 label = qobject_cast<HbLabel*> (loader.findWidget( |
|
308 "qtl_dialog_pri_heading")); |
|
309 if (iOperationType == EInstallAndActivate) |
|
310 { |
|
311 val = hbTrId("txt_device_update_title_download_and_install"); |
|
312 label->setPlainText(val); |
|
313 } |
|
314 else |
|
315 { |
|
316 val = hbTrId("txt_device_update_title_install"); |
|
317 label->setPlainText(val); |
|
318 } |
|
319 |
|
320 //set the app name |
|
321 label = qobject_cast<HbLabel*> (loader.findWidget("label")); |
|
322 val = hbTrId("txt_deviceupdate_info_file_1_2").arg(m_appName); |
|
323 label->setPlainText(val); |
|
324 |
|
325 //size |
|
326 label = qobject_cast<HbLabel*> (loader.findWidget("label_1")); |
|
327 if (m_totalSize != 0) |
|
328 { |
|
329 m_sizeStr = convertSize(); |
|
330 label->setPlainText(m_sizeStr); |
|
331 } |
|
332 else |
|
333 { |
|
334 val = hbTrId("txt_device_update_info_details_not_available"); |
|
335 label->setPlainText(val); |
|
336 } |
|
337 |
|
338 //icon |
|
339 label = qobject_cast<HbLabel*> (loader.findWidget("icon")); |
|
340 HbIcon* icon = new HbIcon(":/icon/qgn_prop_sml_http.svg"); |
|
341 label->setIcon(*icon); |
|
342 |
|
343 //"install to" label |
|
344 label = qobject_cast<HbLabel*> (loader.findWidget("qtl_dialog_pri5")); |
|
345 val = hbTrId("txt_device_update_setlabel_install_to"); |
|
346 label->setPlainText(val); |
|
347 |
|
348 //getting the available free space in all drives and adding to combobox |
|
349 |
|
350 mDriveBox = qobject_cast<HbComboBox*> (loader.findWidget("combobox")); |
|
351 int err(KErrNone); |
|
352 TRAP(err,QT_TRYCATCH_LEAVING(getAvailableDrives())); |
|
353 |
|
354 if(err!=KErrNone) |
|
355 { |
|
356 mDriveBox->setVisible(false); |
|
357 } |
|
358 iComp->SetDriveSelectionStatus(true); |
|
359 CDeliveryComponentStorage* iStorage; |
|
360 QT_TRAP_THROWING(iStorage = CDeliveryComponentStorage::NewL()); |
|
361 TRAP( err, QT_TRYCATCH_LEAVING(iStorage->UpdateL(*iComp))); |
|
362 delete iStorage; |
|
363 iStorage = NULL; |
|
364 |
|
365 connect(mDriveBox, SIGNAL(currentIndexChanged(int)), this, |
|
366 SLOT(defaultDriveChanged(int ))); |
|
367 //setting the actions |
|
368 mOkButton = qobject_cast<HbAction*> (loader.findObject( |
|
369 "qtl_dialog_softkey_2_left")); |
|
370 mCancel = qobject_cast<HbAction*> (loader.findObject( |
|
371 "qtl_dialog_softkey_2_right")); |
|
372 val = hbTrId("txt_common_button_ok"); |
|
373 mOkButton->setText(val); |
|
374 val = hbTrId("txt_common_button_cancel"); |
|
375 mCancel->setText(val); |
|
376 RDEBUG( "appmgmtdownloadmgr::showIntalltoDialog End" ); |
|
377 } |
|
378 |
|
379 // ------------------------------------------------------------------------------------------------ |
|
380 // appmgmtdownloadmgr::showDownloadDialog() |
|
381 // ------------------------------------------------------------------------------------------------ |
|
382 void appmgmtdownloadmgr::showDownloadDialog() |
|
383 { |
|
384 RDEBUG( "appmgmtdownloadmgr::showDownloadDialog start" ); |
|
385 HbDocumentLoader loader; |
|
386 QString val; |
|
387 bool ok = false; |
|
388 HbLabel* label; |
|
389 |
|
390 loader.load(":/xml/downloaddialog.docml", &ok); |
|
391 |
|
392 Q_ASSERT_X(ok, "Device Manager", "Invalid docml file"); |
|
393 mDialog = qobject_cast<HbDialog*> (loader.findWidget("dialog")); |
|
394 |
|
395 //set title for the dialog |
|
396 label = qobject_cast<HbLabel*> (loader.findWidget( |
|
397 "qtl_dialog_pri_heading")); |
|
398 val = hbTrId("txt_device_update_title_download"); |
|
399 label->setPlainText(val); |
|
400 |
|
401 //set icon |
|
402 label = qobject_cast<HbLabel*> (loader.findWidget("icon")); |
|
403 HbIcon* icon = new HbIcon(":/icon/qgn_prop_sml_http.svg"); |
|
404 label->setIcon(*icon); |
|
405 |
|
406 label = qobject_cast<HbLabel*> (loader.findWidget("qtl_dialog_pri5")); |
|
407 |
|
408 //set appname |
|
409 val = hbTrId("txt_deviceupdate_info_file_1_2").arg(m_appName); |
|
410 label->setPlainText(val); |
|
411 |
|
412 //size |
|
413 label = qobject_cast<HbLabel*> (loader.findWidget("qtl_dialog_pri5_1")); |
|
414 |
|
415 //size |
|
416 if (m_totalSize != 0) |
|
417 { |
|
418 m_sizeStr = convertSize(); |
|
419 label->setPlainText(m_sizeStr); |
|
420 } |
|
421 else |
|
422 { |
|
423 val = hbTrId("txt_device_update_info_details_not_available"); |
|
424 label->setPlainText(val); |
|
425 } |
|
426 //setting the actions |
|
427 mOkButton = qobject_cast<HbAction*> (loader.findObject( |
|
428 "qtl_dialog_softkey_2_left")); |
|
429 mCancel = qobject_cast<HbAction*> (loader.findObject( |
|
430 "qtl_dialog_softkey_2_right")); |
|
431 val = hbTrId("txt_common_button_ok"); |
|
432 mOkButton->setText(val); |
|
433 val = hbTrId("txt_common_button_cancel"); |
|
434 mCancel->setText(val); |
|
435 RDEBUG( "appmgmtdownloadmgr::showDownloadDialog End" ); |
|
436 } |
|
437 |
|
438 // ------------------------------------------------------------------------------------------------ |
|
439 // appmgmtdownloadmgr::showDialog |
|
440 // ------------------------------------------------------------------------------------------------ |
|
441 void appmgmtdownloadmgr::showDialog(CDeploymentComponent *aComponent) |
|
442 { |
|
443 CCoeEnv* coe = CCoeEnv::Static(); |
|
444 TApaTaskList taskList(coe->WsSession()); |
|
445 TApaTask task1(taskList.FindApp(TUid::Uid(KAppMgmtServerUid))); |
|
446 if (task1.Exists()) |
|
447 { |
|
448 task1.BringToForeground(); |
|
449 } |
|
450 |
|
451 |
|
452 |
|
453 //get the Size of the install package |
|
454 m_totalSize = iDl->attribute(TotalSize).toInt(); |
|
455 |
|
456 //get the name of the install package |
|
457 TDeploymentComponentName name = aComponent->ComponentName(); |
|
458 TBuf<KDeploymentComponentNameMaxLength> nameBuf; |
|
459 nameBuf.Copy(name); |
|
460 m_appName = QString::fromUtf16(nameBuf.Ptr(), nameBuf.Length()); |
|
461 |
|
462 (iOperationType == EInstallAndActivate)?showInstalltoDialog():showDownloadDialog(); |
|
463 |
|
464 mDialog->setTimeout(20000); |
|
465 mNotifierdata = m_appName; |
|
466 QString comma(","); |
|
467 mNotifierdata.append(comma); |
|
468 mNotifierdata.append(mSize); |
|
469 mNotifierdata.append(comma); |
|
470 mNotifierdata.append(mSizeFormat); |
|
471 |
|
472 mDialogData = m_appName; |
|
473 mDialogData.append(comma); |
|
474 mDialogData.append(m_sizeStr); |
|
475 |
|
476 CApplicationManagementUtility::mCurrDlg = mDialog; |
|
477 mDialog->setAttribute(Qt::WA_DeleteOnClose); |
|
478 mDialog->open(this,SLOT(dialogSlot(HbAction*))); |
|
479 } |
|
480 |
|
481 // ------------------------------------------------------------------------------------------------ |
|
482 // appmgmtdownloadmgr::defaultDriveChanged |
|
483 // ------------------------------------------------------------------------------------------------ |
|
484 void appmgmtdownloadmgr::defaultDriveChanged(int i) |
|
485 { |
|
486 TAMInstallOptions opts = iComp->InstallOpts(); |
|
487 int err = KErrNone; |
|
488 TChar drive = drilist[i*2]; |
|
489 drive.LowerCase(); |
|
490 opts.iOptions.iDrive = drive; |
|
491 TPtrC8 buf; |
|
492 TAMInstallOptionsPckg optsb(opts); |
|
493 buf.Set(optsb); |
|
494 TRAP( err, QT_TRYCATCH_LEAVING(iComp->SetInstallOptsL(buf))); |
|
495 CDeliveryComponentStorage* iStorage; |
|
496 TRAP( err, QT_TRYCATCH_LEAVING(iStorage = CDeliveryComponentStorage::NewL())); |
|
497 TRAP( err, QT_TRYCATCH_LEAVING(iStorage->UpdateL(*iComp))); |
|
498 delete iStorage; |
|
499 iStorage = NULL; |
|
500 } |
|
501 |
|
502 // ------------------------------------------------------------------------------------------------ |
|
503 // appmgmtdownloadmgr::dialogSlot |
|
504 // ------------------------------------------------------------------------------------------------ |
|
505 void appmgmtdownloadmgr::dialogSlot(HbAction* recAction) |
|
506 { |
|
507 RDEBUG("dialogslot"); |
|
508 TRequestStatus* stat = &iWait->iStatus; |
|
509 User::RequestComplete(stat,KErrNone); |
|
510 if(recAction == mCancel) |
|
511 { |
|
512 mEndReported = 1; |
|
513 sendSrvToBg(); |
|
514 iWait->Stop(); |
|
515 iDl->cancel(); |
|
516 } |
|
517 else |
|
518 { |
|
519 //visited if ok is selected or after timeout |
|
520 iDialogAccepted = 1; |
|
521 int err = RProperty::Set(TUid::Uid(KOmaDMAppUid), KDownloadActive, iDialogAccepted); |
|
522 RDEBUG_2("RProperty set (%d)", err ); |
|
523 } |
|
524 CApplicationManagementUtility::mCurrDlg = 0; |
|
525 mOkButton=0; |
|
526 mCancel = 0; |
|
527 RDEBUG("dialogslot end"); |
|
528 } |
|
529 |
|
530 // ------------------------------------------------------------------------------------------------ |
|
531 // appmgmtdownloadmgr::downloadMgrEventRecieved( |
|
532 // ------------------------------------------------------------------------------------------------ |
|
533 bool appmgmtdownloadmgr::downloadMgrEventRecieved(DownloadManagerEvent *event) |
|
534 { |
|
535 //DEventType type = (DEventType)event->type(); |
|
536 //bool eventHandled = false; |
|
537 switch (event->type()) |
|
538 |
|
539 { |
|
540 case DownloadManagerEvent::Created: |
|
541 { |
|
542 RDEBUG("DownloadCreated"); |
|
543 return true; |
|
544 } |
|
545 case DownloadManagerEvent::Removed: |
|
546 { |
|
547 RDEBUG("Removed"); |
|
548 return true; |
|
549 } |
|
550 |
|
551 default: |
|
552 { |
|
553 //QWidget::event(event); |
|
554 return false; |
|
555 } |
|
556 } |
|
557 } |
|
558 |
|
559 // ------------------------------------------------------------------------------------------------ |
|
560 // appmgmtdownloadmgr::FileName |
|
561 // ------------------------------------------------------------------------------------------------ |
|
562 void appmgmtdownloadmgr::FileName(QString& filename) |
|
563 { |
|
564 if (iDl) |
|
565 filename = iDl->attribute(WRT::FileName).toString(); |
|
566 } |
|
567 |
|
568 // ------------------------------------------------------------------------------------------------ |
|
569 // appmgmtdownloadmgr::MimeType |
|
570 // ------------------------------------------------------------------------------------------------ |
|
571 void appmgmtdownloadmgr::MimeType(QString& mimetype) |
|
572 { |
|
573 mimetype=m_mimetype; |
|
574 TBuf<1024> buffer(mimetype.utf16()); |
|
575 RDEBUG_2( "appmgmtdownloadmgr::MimeType '%S'", &buffer ); |
|
576 } |
|
577 void appmgmtdownloadmgr::SetMimeType() |
|
578 { |
|
579 if (iDl) |
|
580 m_mimetype = iDl->attribute(ContentType).toString(); |
|
581 TBuf<1024> buffer(m_mimetype.utf16()); |
|
582 RDEBUG_2( "appmgmtdownloadmgr::MimeType SetMimeType '%S'", &buffer ); |
|
583 } |
|
584 |
|
585 // ------------------------------------------------------------------------------------------------ |
|
586 // appmgmtdownloadmgr::downloadEventRecieved |
|
587 // ------------------------------------------------------------------------------------------------ |
|
588 bool appmgmtdownloadmgr::downloadEventRecieved(DownloadEvent *event) |
|
589 { |
|
590 //DEventType type = (DEventType)event->type(); |
|
591 bool eventHandled = true; |
|
592 switch (event->type()) |
|
593 { |
|
594 case DownloadEvent::Started: |
|
595 { |
|
596 RDEBUG("Started"); |
|
597 m_inProgress = false; |
|
598 break; |
|
599 } |
|
600 |
|
601 case DownloadEvent::HeadersReceived: |
|
602 { |
|
603 RDEBUG("HeaderReceived"); |
|
604 m_inProgress = false; |
|
605 SetMimeType(); |
|
606 break; |
|
607 } |
|
608 |
|
609 case DownloadEvent::InProgress: |
|
610 { |
|
611 RDEBUG("Progress"); |
|
612 |
|
613 //HandleAlreadyRunningL(downloadedsize, contentsize, *download, aEvent.iProgressState); |
|
614 if (!iDialogAccepted) |
|
615 { |
|
616 if (!CApplicationManagementUtility::iSilentSession) |
|
617 { |
|
618 showDialog(iComp); |
|
619 int err = KErrNone; |
|
620 TRAP( err, QT_TRYCATCH_LEAVING(iWait = CDialogWait::NewL())); |
|
621 iWait->StartWait(); |
|
622 } |
|
623 } |
|
624 else |
|
625 { |
|
626 m_totalSize = iDl->attribute(TotalSize).toInt(); |
|
627 RDEBUG_2("total size = %d",m_totalSize ); |
|
628 m_currentDownloadedSize |
|
629 = iDl->attribute(DownloadedSize).toInt(); |
|
630 RDEBUG_2("m_currentDownloadedSize = %d",m_currentDownloadedSize ); |
|
631 if (!CApplicationManagementUtility::iSilentSession) |
|
632 updateProgress(m_currentDownloadedSize, m_totalSize); |
|
633 } |
|
634 break; |
|
635 } |
|
636 case DownloadEvent::Paused: |
|
637 { |
|
638 RDEBUG("Paused"); |
|
639 break; |
|
640 } |
|
641 case DownloadEvent::Completed: |
|
642 { |
|
643 RDEBUG("Completed"); |
|
644 m_inProgress = false; |
|
645 closeProgress(); |
|
646 QApplication::processEvents(); |
|
647 if (iOperationType == EDeliver && !CApplicationManagementUtility::iSilentSession) |
|
648 { |
|
649 mNote = new AppMgmtNotifier(m_appName); |
|
650 if(mNote) |
|
651 mNote->showDownloadSuccessNote(); |
|
652 delete mNote; |
|
653 mNote=NULL; |
|
654 } |
|
655 m_callback.DownloadCompleted(); |
|
656 iStatus = KErrNone; |
|
657 break; |
|
658 } |
|
659 |
|
660 case DownloadEvent::Failed: |
|
661 { |
|
662 RDEBUG("Failed"); |
|
663 m_inProgress = false; |
|
664 closeProgress(); |
|
665 if(!CApplicationManagementUtility::iSilentSession) |
|
666 { |
|
667 mNote = new AppMgmtNotifier(m_appName); |
|
668 if(mNote) |
|
669 { |
|
670 bool ret = mNote->showDownloadFailedNote(mNotifierdata); |
|
671 RDEBUG_2( "device dialog : %d", ret ); |
|
672 delete mNote; |
|
673 mNote=NULL; |
|
674 } |
|
675 } |
|
676 |
|
677 break; |
|
678 } |
|
679 case DownloadEvent::Cancelled: |
|
680 { |
|
681 RDEBUG("Cancelled"); |
|
682 m_inProgress = false; |
|
683 |
|
684 closeProgress(); |
|
685 if(!mNetworkLoss) |
|
686 { |
|
687 m_callback.DownloadFailed(KStatusUserCancelled); |
|
688 } |
|
689 else |
|
690 { |
|
691 m_callback.DownloadFailed(KStatusDownloadFailed); |
|
692 } |
|
693 iStatus = KErrNone; |
|
694 break; |
|
695 } |
|
696 case DownloadEvent::ConnectionNeeded: |
|
697 case DownloadEvent::ConnectionDisconnected: |
|
698 case DownloadEvent::NetworkLoss: |
|
699 { |
|
700 RDEBUG("NetworkLoss"); |
|
701 m_inProgress = false; |
|
702 int errornum; |
|
703 int statusdwnld; |
|
704 closeProgress(); |
|
705 if(!mEndReported) |
|
706 { |
|
707 mNetworkLoss = 1; |
|
708 mEndReported = 1; |
|
709 if (!CApplicationManagementUtility::iSilentSession) |
|
710 { |
|
711 mNote = new AppMgmtNotifier(m_appName); |
|
712 if(mNote) |
|
713 mNote->showDownloadFailedNote(mNotifierdata); |
|
714 delete mNote; |
|
715 mNote=NULL; |
|
716 } |
|
717 iDl->cancel(); |
|
718 } |
|
719 break; |
|
720 } |
|
721 |
|
722 case DownloadEvent::Error: |
|
723 { |
|
724 RDEBUG("Error"); |
|
725 m_inProgress = false; |
|
726 |
|
727 int errornum; |
|
728 int statusdwnld; |
|
729 |
|
730 Download::State state = |
|
731 (Download::State) iDl->attribute(State).toInt(); |
|
732 |
|
733 errornum = iDl->attribute(LastError).toInt(); |
|
734 |
|
735 statusdwnld = currDwnldStatForGenericAlert(errornum); |
|
736 closeProgress(); |
|
737 if(!mEndReported) |
|
738 { |
|
739 if (!CApplicationManagementUtility::iSilentSession) |
|
740 { |
|
741 mNote = new AppMgmtNotifier(m_appName); |
|
742 if(mNote) |
|
743 mNote->showDownloadFailedNote(mNotifierdata); |
|
744 delete mNote; |
|
745 mNote=NULL; |
|
746 } |
|
747 m_callback.DownloadFailed(statusdwnld); |
|
748 mEndReported = 1; |
|
749 } |
|
750 iStatus = KErrNone; |
|
751 break; |
|
752 } |
|
753 |
|
754 default: |
|
755 { |
|
756 eventHandled = false; |
|
757 } |
|
758 } |
|
759 return eventHandled; |
|
760 } |
|
761 |
|
762 // ------------------------------------------------------------------------------------------------ |
|
763 // appmgmtdownloadmgr::updateProgress |
|
764 // ------------------------------------------------------------------------------------------------ |
|
765 void appmgmtdownloadmgr::updateProgress(TInt32 aDownloadedSize, |
|
766 TInt32 aContentSize) |
|
767 { |
|
768 if (!iProgressNote) |
|
769 { |
|
770 iProgressNote = new AppMgmtProgDialog(mDialogData,*iDl,mEndReported); |
|
771 iProgressNote->startDialog(aContentSize, aDownloadedSize); |
|
772 } |
|
773 |
|
774 //handles the progress dialog |
|
775 //creating progress dialog and set final val and update |
|
776 if (aContentSize >= 0) |
|
777 { |
|
778 iProgressNote->updateProgress(aDownloadedSize); |
|
779 } |
|
780 } |
|
781 |
|
782 // ------------------------------------------------------------------------------------------------ |
|
783 // appmgmtdownloadmgr::currDwnldStatForGenericAlert |
|
784 // ------------------------------------------------------------------------------------------------ |
|
785 int appmgmtdownloadmgr::currDwnldStatForGenericAlert(int dwnldstatus) |
|
786 { |
|
787 int status; |
|
788 if(dwnldstatus == DiskFull ) |
|
789 status = KStatusDowloadFailedOOM; |
|
790 else if(dwnldstatus == TransactionFailed ||dwnldstatus== HostNotFoundError || dwnldstatus== TimeoutError || dwnldstatus== OperationCanceledError) |
|
791 status = KStatusAltDowldUnavailable; |
|
792 else if (dwnldstatus == AuthenticationRequiredError ) |
|
793 status = KStatusAlternateDownldAuthFail; |
|
794 else |
|
795 status = KStatusDownloadFailed; |
|
796 |
|
797 return status; |
|
798 |
|
799 } |
|
800 |
|
801 // ------------------------------------------------------------------------------------------------ |
|
802 // appmgmtdownloadmgr::closeProgress |
|
803 // ------------------------------------------------------------------------------------------------ |
|
804 void appmgmtdownloadmgr::closeProgress() |
|
805 { |
|
806 if(iProgressNote) |
|
807 { |
|
808 iProgressNote->closeAMProgDialog(); |
|
809 } |
|
810 } |
|
811 |
|
812 // ------------------------------------------------------------------------------------------------ |
|
813 // appmgmtdownloadmgr::sendSrvToBg |
|
814 // ------------------------------------------------------------------------------------------------ |
|
815 void appmgmtdownloadmgr::sendSrvToBg() |
|
816 { |
|
817 { |
|
818 CCoeEnv* coe = CCoeEnv::Static(); |
|
819 TApaTaskList taskList(coe->WsSession()); |
|
820 TApaTask task=taskList.FindApp(TUid::Uid(KAppMgmtServerUid)); |
|
821 if(task.Exists()) |
|
822 { |
|
823 task.SendToBackground(); |
|
824 } |
|
825 } |
|
826 } |
|
827 |
|
828 |
|
829 |
|
830 //--------------------------------------------------------------------------------- |
|
831 // CDialogWait::CDialogWait |
|
832 //--------------------------------------------------------------------------------- |
|
833 CDialogWait::CDialogWait() |
|
834 : CActive(0) |
|
835 { |
|
836 CActiveScheduler::Add(this); |
|
837 } |
|
838 |
|
839 //--------------------------------------------------------------------------------- |
|
840 // CDialogWait::ConstructL |
|
841 //--------------------------------------------------------------------------------- |
|
842 void CDialogWait::ConstructL() |
|
843 { |
|
844 iWait = new( ELeave ) CActiveSchedulerWait; |
|
845 } |
|
846 |
|
847 //--------------------------------------------------------------------------------- |
|
848 // CDialogWait::NewL |
|
849 //--------------------------------------------------------------------------------- |
|
850 CDialogWait* CDialogWait::NewL() |
|
851 { |
|
852 CDialogWait* self = new( ELeave ) CDialogWait(); |
|
853 CleanupStack::PushL( self ); |
|
854 self->ConstructL(); |
|
855 CleanupStack::Pop(); |
|
856 return self; |
|
857 } |
|
858 |
|
859 //--------------------------------------------------------------------------------- |
|
860 // CDialogWait::~CDialogWait |
|
861 // Destructor |
|
862 //--------------------------------------------------------------------------------- |
|
863 CDialogWait::~CDialogWait() |
|
864 { |
|
865 Cancel(); |
|
866 delete iWait; |
|
867 } |
|
868 |
|
869 //--------------------------------------------------------------------------------- |
|
870 // CDialogWait::Stop |
|
871 //--------------------------------------------------------------------------------- |
|
872 void CDialogWait::Stop() |
|
873 { |
|
874 if (iWait && iWait->IsStarted() && iWait->CanStopNow()) |
|
875 { |
|
876 iWait->AsyncStop(); |
|
877 } |
|
878 } |
|
879 |
|
880 //--------------------------------------------------------------------------------- |
|
881 // CDialogWait::WaitOnDialog |
|
882 //--------------------------------------------------------------------------------- |
|
883 void CDialogWait::StartWait() |
|
884 { |
|
885 RDEBUG("startwait start"); |
|
886 if (!IsActive() ) |
|
887 { |
|
888 if(iWait) |
|
889 { |
|
890 if(!iWait->IsStarted()) |
|
891 { |
|
892 iStatus = KRequestPending; |
|
893 SetActive(); |
|
894 iWait->Start(); |
|
895 } |
|
896 } |
|
897 } |
|
898 RDEBUG("startwait end"); |
|
899 } |
|
900 |
|
901 // -------------------------------------------------------------------------- |
|
902 // CDialogWait::DoCancel() |
|
903 // -------------------------------------------------------------------------- |
|
904 // |
|
905 void CDialogWait::DoCancel() |
|
906 { |
|
907 if (iWait && iWait->IsStarted() && iWait->CanStopNow()) |
|
908 { |
|
909 iWait->AsyncStop(); |
|
910 } |
|
911 } |
|
912 |
|
913 // -------------------------------------------------------------------------- |
|
914 // CDialogWait::RunL() |
|
915 // -------------------------------------------------------------------------- |
|
916 // |
|
917 void CDialogWait::RunL() |
|
918 { |
|
919 if (iWait && iWait->IsStarted() && iWait->CanStopNow()) |
|
920 { |
|
921 iWait->AsyncStop(); |
|
922 } |
|
923 } |
|
924 |
|
925 // -------------------------------------------------------------------------- |
|
926 // CDialogWait::RunError() |
|
927 // -------------------------------------------------------------------------- |
|
928 // |
|
929 TInt CDialogWait::RunError(TInt aError) |
|
930 { |
|
931 RDEBUG_2("CDialogWait::RunError %d",aError ); |
|
932 return KErrNone; |
|
933 } |