24 #include <hblistwidgetitem.h> |
24 #include <hblistwidgetitem.h> |
25 #include <hbtoolbar.h> |
25 #include <hbtoolbar.h> |
26 #include <hbmenu.h> |
26 #include <hbmenu.h> |
27 #include <hbdocumentloader.h> |
27 #include <hbdocumentloader.h> |
28 #include <xqconversions.h> |
28 #include <xqconversions.h> |
|
29 #include <hbmessagebox.h> |
29 |
30 |
30 #include "iaupdatemainview.h" |
31 #include "iaupdatemainview.h" |
|
32 #include "iaupdateengine.h" |
31 #include "iaupdateagreement.h" |
33 #include "iaupdateagreement.h" |
|
34 #include "iaupdatedeputils.h" |
32 |
35 |
33 #include "iaupdatedebug.h" |
36 #include "iaupdatedebug.h" |
34 |
37 |
35 const int KKiloByte = 1024; |
38 const int KKiloByte = 1024; |
36 const int KMegaByte = 1024 * 1024; |
39 const int KMegaByte = 1024 * 1024; |
37 const int KMaxShownInKiloBytes = 10 * KMegaByte; |
40 const int KMaxShownInKiloBytes = 10 * KMegaByte; |
38 |
41 |
39 |
42 |
40 IAUpdateMainView::IAUpdateMainView() |
43 IAUpdateMainView::IAUpdateMainView(IAUpdateEngine *engine): |
|
44 mEngine( engine ) |
41 { |
45 { |
42 HbDocumentLoader loader; |
46 HbDocumentLoader loader; |
43 bool ok = false; |
47 bool ok = false; |
44 loader.load(":/xml/iaupdate_mainview.docml", &ok); |
48 loader.load(":/xml/iaupdate_mainview.docml", &ok); |
45 |
49 |
348 CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC(); |
367 CIAUpdateAgreement* agreement = CIAUpdateAgreement::NewLC(); |
349 agreement->ShowAgreementL(); |
368 agreement->ShowAgreementL(); |
350 CleanupStack::PopAndDestroy( agreement); |
369 CleanupStack::PopAndDestroy( agreement); |
351 } |
370 } |
352 |
371 |
353 void IAUpdateMainView::handleSelectionChanged(QItemSelection) |
372 void IAUpdateMainView::handleSelectionChanged(QItemSelection itemSelection) |
354 { |
373 { |
355 |
374 QModelIndexList indexList = itemSelection.indexes(); |
356 } |
375 bool changedItemFound = false; |
357 |
376 for (int i = 0; !changedItemFound && i < mAllNodes.Count(); ++i) |
358 |
377 { |
359 |
378 bool currentlySelected = false; |
|
379 for (int j = 0; !currentlySelected && j < indexList.count(); ++j) |
|
380 { |
|
381 //QModelIndex modelIndex = indexList.at(j); |
|
382 //modelIndex.row(); |
|
383 if (i == indexList.at(j).row()) |
|
384 { |
|
385 currentlySelected = true; |
|
386 } |
|
387 } |
|
388 if (currentlySelected != mAllNodes[i]->Base().IsSelected()) |
|
389 { |
|
390 changedItemFound = true; |
|
391 markListItem(currentlySelected,i); |
|
392 updateSelectionsToList(); |
|
393 } |
|
394 } |
|
395 |
|
396 } |
|
397 |
|
398 void IAUpdateMainView::getSelectedNodes(RPointerArray<MIAUpdateAnyNode> &selectedNodes) const |
|
399 { |
|
400 for (int i = 0; i < mAllNodes.Count(); ++i) |
|
401 { |
|
402 if (mAllNodes[i]->Base().IsSelected()) |
|
403 { |
|
404 selectedNodes.Append(mAllNodes[i]); |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 void IAUpdateMainView::markListItem(bool mark, int index) |
|
410 { |
|
411 if (mark) |
|
412 { |
|
413 //It's Mark Command |
|
414 RPointerArray<MIAUpdateAnyNode> selectedNodes; |
|
415 getSelectedNodes(selectedNodes); |
|
416 |
|
417 //There are selected items already and type are different with the current one |
|
418 if (selectedNodes.Count() > 0 && (mAllNodes[index]->NodeType() != selectedNodes[0]->NodeType())) |
|
419 { |
|
420 // firmware item and normal sis items can't be selected at the same time |
|
421 // unmark the selected nodes. |
|
422 for (int i = 0; i < selectedNodes.Count(); i++) |
|
423 { |
|
424 int index = mAllNodes.Find(selectedNodes[i]); |
|
425 mAllNodes[index]->Base().SetSelected(false); |
|
426 } |
|
427 } |
|
428 selectedNodes.Close(); |
|
429 } |
|
430 |
|
431 //there is no selected items or the type is the same with the current one |
|
432 |
|
433 if (mAllNodes[index]->NodeType() == MIAUpdateAnyNode::ENodeTypeFw ) |
|
434 { |
|
435 mAllNodes[index]->Base().SetSelected(mark); |
|
436 return; |
|
437 } |
|
438 |
|
439 if (mAllNodes[index]->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal ) |
|
440 { |
|
441 bool accepted = false; |
|
442 |
|
443 if(index > -1) |
|
444 { |
|
445 accepted = true; |
|
446 |
|
447 MIAUpdateNode* node = static_cast<MIAUpdateNode*>(mAllNodes[index]); |
|
448 RPointerArray<MIAUpdateAnyNode> mands; |
|
449 RPointerArray<MIAUpdateNode> deps; |
|
450 |
|
451 if (mark) |
|
452 { |
|
453 TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*node, mAllNodes, deps)); |
|
454 if (err != KErrNone) |
|
455 { |
|
456 deps.Close(); |
|
457 return; |
|
458 } |
|
459 if (!getMandatoryNodes(mands)) |
|
460 { |
|
461 // error when creating mandatory node list |
|
462 mands.Close(); |
|
463 return; |
|
464 } |
|
465 } |
|
466 else |
|
467 { |
|
468 //mandatory item is not allowed to be unmarked |
|
469 if (mAllNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory) |
|
470 { |
|
471 //show dialog |
|
472 showUpdateCannotOmitDialog(); |
|
473 return; |
|
474 } |
|
475 |
|
476 //CleanupClosePushL( deps ); |
|
477 TRAPD(err,IAUpdateDepUtils::GetDependantsL(*node, mAllNodes, deps)); |
|
478 if (err != KErrNone) |
|
479 { |
|
480 deps.Close(); |
|
481 return; |
|
482 } |
|
483 // item is not allowed to be unmarked if its dependant is mandatory |
|
484 bool mandatoryDependantFound = false; |
|
485 for(int i = 0; i < deps.Count() && !mandatoryDependantFound; i++) |
|
486 { |
|
487 if (deps[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory) |
|
488 { |
|
489 mandatoryDependantFound = true; |
|
490 } |
|
491 } |
|
492 if (mandatoryDependantFound) |
|
493 { |
|
494 showUpdateCannotOmitDialog(); |
|
495 deps.Close(); |
|
496 return; |
|
497 } |
|
498 } |
|
499 |
|
500 int depCount = deps.Count(); |
|
501 |
|
502 if (depCount > 0) |
|
503 { |
|
504 QString text; |
|
505 QString names; |
|
506 MIAUpdateNode* depNode = NULL; |
|
507 QString separator(","); |
|
508 |
|
509 for(int i = 0; i < depCount; i++) |
|
510 { |
|
511 depNode = deps[i]; |
|
512 if (i > 0) |
|
513 { |
|
514 names.append(separator); |
|
515 names.append(QString(" ")); |
|
516 } |
|
517 names.append(XQConversions::s60DescToQString(depNode->Base().Name())); |
|
518 } |
|
519 |
|
520 |
|
521 if (mark) |
|
522 { |
|
523 if (depCount > 1) |
|
524 { |
|
525 text.append("This update needs also updates "); |
|
526 text.append(names); |
|
527 text.append(" for working"); |
|
528 //resourceId = R_IAUPDATE_DEPENDENCY_MARK_MANY; |
|
529 } |
|
530 else |
|
531 { |
|
532 text.append("This update needs also \""); |
|
533 text.append(names); |
|
534 text.append("\" for working"); |
|
535 //resourceId = R_IAUPDATE_DEPENDENCY_MARK_ONE; |
|
536 } |
|
537 } |
|
538 else |
|
539 { |
|
540 if (depCount > 1) |
|
541 { |
|
542 text.append("Updates "); |
|
543 text.append(names); |
|
544 text.append(" need this update for working"); |
|
545 //resourceId = R_IAUPDATE_DEPENDENCY_UNMARK_MANY; |
|
546 } |
|
547 else |
|
548 { |
|
549 text.append("Update \""); |
|
550 text.append(names); |
|
551 text.append("\" needs this update for working"); |
|
552 //resourceId = R_IAUPDATE_DEPENDENCY_UNMARK_ONE; |
|
553 } |
|
554 } |
|
555 |
|
556 if (mark && mAllNodes[index]->Base().Importance() == MIAUpdateBaseNode::EMandatory) |
|
557 { |
|
558 // depencencies of mandatory update are also selected without showing dialog |
|
559 accepted = true; |
|
560 } |
|
561 else |
|
562 { |
|
563 accepted = showDependenciesFoundDialog(text); |
|
564 } |
|
565 } |
|
566 |
|
567 if (accepted) |
|
568 { |
|
569 for(int j = 0; j < depCount; j++) |
|
570 { |
|
571 int depNodeInd = mAllNodes.Find(deps[j]); |
|
572 mAllNodes[depNodeInd]->Base().SetSelected(mark); |
|
573 } |
|
574 deps.Close(); |
|
575 int nodeInd = mAllNodes.Find(node); |
|
576 mAllNodes[nodeInd]->Base().SetSelected(mark); |
|
577 } |
|
578 else |
|
579 { |
|
580 //user rejects the dependency dialog |
|
581 deps.Close(); |
|
582 if (mark) |
|
583 { |
|
584 mands.Close(); |
|
585 } |
|
586 return; |
|
587 } |
|
588 |
|
589 //mark all of the mandatory items |
|
590 int mandCount = mands.Count(); |
|
591 if (mandCount > 0 && mark) |
|
592 { |
|
593 for(int j = 0; j < mandCount; j++) |
|
594 { |
|
595 int mandNodeInd = mAllNodes.Find(mands[j]); |
|
596 mAllNodes[mandNodeInd]->Base().SetSelected(mark); |
|
597 if (mAllNodes[mandNodeInd]->NodeType() == MIAUpdateAnyNode::ENodeTypeNormal) |
|
598 { |
|
599 // mark also all dependencies of a mandatory item |
|
600 MIAUpdateNode* dependencyNode = static_cast<MIAUpdateNode*>(mAllNodes[mandNodeInd]); |
|
601 RPointerArray<MIAUpdateNode> dependencies; |
|
602 TRAPD(err,IAUpdateDepUtils::GetDependenciesL(*dependencyNode, mAllNodes, dependencies)); |
|
603 if (err) |
|
604 { |
|
605 dependencies.Close(); |
|
606 if (mark) |
|
607 { |
|
608 mands.Close(); |
|
609 } |
|
610 return; |
|
611 } |
|
612 for(int k = 0; k < dependencies.Count(); k++) |
|
613 { |
|
614 int depNodeInd = mAllNodes.Find(dependencies[k]); |
|
615 mAllNodes[depNodeInd]->Base().SetSelected(true); |
|
616 } |
|
617 dependencies.Close(); |
|
618 } |
|
619 } |
|
620 } |
|
621 if (mark) |
|
622 { |
|
623 mands.Close(); |
|
624 } |
|
625 } |
|
626 return; |
|
627 } |
|
628 return; |
|
629 } |
|
630 |
|
631 |
|
632 bool IAUpdateMainView::getMandatoryNodes(RPointerArray<MIAUpdateAnyNode> &mandNodes) const |
|
633 { |
|
634 bool ret = true; |
|
635 for(int i = 0; i < mAllNodes.Count(); ++i) |
|
636 { |
|
637 if (mAllNodes[i]->Base().Importance() == MIAUpdateBaseNode::EMandatory) |
|
638 { |
|
639 if (mandNodes.Append(mAllNodes[i]) != KErrNone) |
|
640 { |
|
641 ret = false; |
|
642 } |
|
643 } |
|
644 } |
|
645 return ret; |
|
646 } |
|
647 |
|
648 void IAUpdateMainView::showUpdateCannotOmitDialog() const |
|
649 { |
|
650 HbMessageBox messageBox(HbMessageBox::MessageTypeInformation); |
|
651 messageBox.setText(QString("This required update cannot be omitted")); |
|
652 HbAction okAction("Ok"); |
|
653 messageBox.setPrimaryAction(&okAction); |
|
654 messageBox.setTimeout(HbPopup::StandardTimeout); |
|
655 messageBox.show(); |
|
656 //messageBox.exec(); |
|
657 } |
|
658 |
|
659 bool IAUpdateMainView::showDependenciesFoundDialog(QString &text) const |
|
660 { |
|
661 bool accepted = false; |
|
662 HbMessageBox messageBox(HbMessageBox::MessageTypeQuestion); |
|
663 messageBox.setText(text); |
|
664 HbAction continueAction("Continue"); |
|
665 messageBox.setPrimaryAction(&continueAction); |
|
666 HbAction cancelAction("Cancel"); |
|
667 messageBox.setSecondaryAction(&cancelAction); |
|
668 messageBox.setTimeout(HbPopup::NoTimeout); |
|
669 messageBox.show(); |
|
670 //HbAction *selectedAction = messageBox.exec(); |
|
671 //if (selectedAction == messageBox.primaryAction()) |
|
672 { |
|
673 accepted = true; |
|
674 } |
|
675 return accepted; |
|
676 } |
|
677 |
|
678 void IAUpdateMainView::updateSelectionsToList() |
|
679 { |
|
680 for(int i = 0; i < mAllNodes.Count(); ++i) |
|
681 { |
|
682 if ( mAllNodes[i]->Base().IsSelected() != mListView->selectionModel()->isSelected(mListView->model()->index(i,0))) |
|
683 { |
|
684 QItemSelectionModel::SelectionFlag selectionFlag; |
|
685 if ( mAllNodes[i]->Base().IsSelected()) |
|
686 { |
|
687 selectionFlag = QItemSelectionModel::Select; |
|
688 } |
|
689 else |
|
690 { |
|
691 selectionFlag = QItemSelectionModel::Deselect; |
|
692 } |
|
693 mListView->selectionModel()->select(mListView->model()->index(i,0),selectionFlag); |
|
694 } |
|
695 } |
|
696 } |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |