328 self->ConstructL(); |
334 self->ConstructL(); |
329 CleanupStack::Pop(); |
335 CleanupStack::Pop(); |
330 return self; |
336 return self; |
331 } |
337 } |
332 |
338 |
333 |
|
334 // -------------------------------------------------------------------------- |
339 // -------------------------------------------------------------------------- |
335 // CPbk2ThumbnailManager::CPbk2ThumbnailManager |
340 // CPbk2ThumbnailManager::CPbk2ThumbnailManager |
336 // -------------------------------------------------------------------------- |
341 // -------------------------------------------------------------------------- |
337 // |
342 // |
338 CPbk2ThumbnailManager::CPbk2ThumbnailManager( |
343 CPbk2ThumbnailManager::CPbk2ThumbnailManager( |
339 CVPbkContactManager& aContactManager ) : |
344 CVPbkContactManager& aContactManager ) : |
340 iState( EIdle ), |
345 iState( EIdle ), |
|
346 iContactThumbnails( KThumbnailArrayGranularity ), |
341 iContactManager( aContactManager ), |
347 iContactManager( aContactManager ), |
342 iDefaultIconIndex( KErrNotFound ) |
348 iDefaultIconIndex( KErrNotFound ) |
343 { |
349 { |
344 } |
350 } |
345 |
|
346 |
351 |
347 // -------------------------------------------------------------------------- |
352 // -------------------------------------------------------------------------- |
348 // CPbk2ThumbnailManager::~CPbk2ThumbnailManager() |
353 // CPbk2ThumbnailManager::~CPbk2ThumbnailManager() |
349 // -------------------------------------------------------------------------- |
354 // -------------------------------------------------------------------------- |
350 // |
355 // |
358 iContactThumbnails.ResetAndDestroy(); |
363 iContactThumbnails.ResetAndDestroy(); |
359 iLoadingQueue.Reset(); |
364 iLoadingQueue.Reset(); |
360 iPriorityArray.Reset(); |
365 iPriorityArray.Reset(); |
361 } |
366 } |
362 |
367 |
363 |
|
364 // -------------------------------------------------------------------------- |
368 // -------------------------------------------------------------------------- |
365 // CPbk2ThumbnailManager::ConstructL() |
369 // CPbk2ThumbnailManager::ConstructL() |
366 // -------------------------------------------------------------------------- |
370 // -------------------------------------------------------------------------- |
367 // |
371 // |
368 void CPbk2ThumbnailManager::ConstructL() |
372 void CPbk2ThumbnailManager::ConstructL() |
369 { |
373 { |
370 // image manager |
374 // image manager |
371 iManager = CPbk2ImageManager::NewL( iContactManager ); |
375 iManager = CPbk2ImageManager::NewL( iContactManager ); |
372 // read file type for thumbnail field |
376 // read file type for thumbnail field |
373 ReadFieldTypeL(); |
377 ReadFieldTypeL(); |
374 //reset thumbnail array |
378 } |
375 iContactThumbnails.Reset(); |
|
376 } |
|
377 |
|
378 |
379 |
379 // -------------------------------------------------------------------------- |
380 // -------------------------------------------------------------------------- |
380 // CPbk2ThumbnailManager::SetObserver() |
381 // CPbk2ThumbnailManager::SetObserver() |
381 // -------------------------------------------------------------------------- |
382 // -------------------------------------------------------------------------- |
382 // |
383 // |
401 TInt CPbk2ThumbnailManager::ThumbnailCount() |
402 TInt CPbk2ThumbnailManager::ThumbnailCount() |
402 { |
403 { |
403 return iContactThumbnails.Count(); |
404 return iContactThumbnails.Count(); |
404 } |
405 } |
405 |
406 |
406 |
407 // -------------------------------------------------------------------------- |
407 // -------------------------------------------------------------------------- |
408 // CPbk2ThumbnailManager::GetPbkIconIndexL() |
408 // CPbk2ThumbnailManager::GetPbkIconIndex() |
409 // -------------------------------------------------------------------------- |
409 // -------------------------------------------------------------------------- |
410 // |
410 // |
411 TInt CPbk2ThumbnailManager::GetPbkIconIndexL( TInt aListboxIndex, const MVPbkBaseContact& aContactLink ) |
411 TInt CPbk2ThumbnailManager::GetPbkIconIndex( TInt aListboxIndex, const MVPbkBaseContact& aContactLink ) |
412 { |
412 { |
|
413 TBool reLoadThumbnail = EFalse; |
|
414 TInt arrIndex = iDefaultIconIndex; |
413 TInt arrIndex = iDefaultIconIndex; |
415 |
414 |
416 // check that requested thumbnail is allready added to thumbnail array |
415 // check that requested thumbnail is allready added to thumbnail array |
417 if( aListboxIndex < iContactThumbnails.Count() ) |
416 if( Rng( 0, aListboxIndex, iContactThumbnails.Count() - 1 ) ) |
418 { |
417 { |
419 CPbk2TmItem* item = iContactThumbnails[ aListboxIndex ]; |
418 CPbk2TmItem* item = iContactThumbnails[ aListboxIndex ]; |
420 |
419 if( !item ) |
421 // This is because when find is in use, the indexes are not mapped |
|
422 // directly to thumbnail managers indexes |
|
423 if( !item->GetLink()->RefersTo( aContactLink ) ) |
|
424 { |
420 { |
425 // try to find correct one from the array based on contact link |
421 item = CPbk2TmItem::NewL( aContactLink.CreateLinkLC(), aListboxIndex ); |
426 item = FindItem( aContactLink ); |
422 CleanupStack::Pop(); // link |
|
423 // set default icon index |
|
424 item->SetIconArrayIndexAndId( iDefaultIconIndex,iDefaultIconId ); |
|
425 item->SetHasThumbnail( ETrue ); |
|
426 iContactThumbnails[ aListboxIndex ] = item; |
427 } |
427 } |
428 |
428 |
429 if( item ) |
429 // if item has a thumbnail image, but it is not loaded yet ( queue ) |
430 { |
430 if( item->HasThumbnail() && !item->GetBitmap() ) |
431 // if item has a thumbnail image, but it is not loaded yet ( queue ) |
431 { |
432 if( item->HasThumbnail() && !item->GetBitmap() ) |
432 TBool reOrderItem = ETrue; |
|
433 TInt res = iLoadingQueue.Find( item ); |
|
434 //remove from array if duplicate |
|
435 if( res != KErrNotFound ) |
433 { |
436 { |
434 reLoadThumbnail = ETrue; |
437 // if item's position is 0 or 1, dont reorder |
|
438 if( res <= 1 ) |
|
439 { |
|
440 reOrderItem = EFalse; |
|
441 } |
|
442 // else remove item from the array for reordering |
|
443 else |
|
444 { |
|
445 iLoadingQueue.Remove( res ); |
|
446 } |
435 } |
447 } |
436 else |
448 |
|
449 // if item is to be reordered |
|
450 if( reOrderItem ) |
437 { |
451 { |
438 arrIndex = item->GetIconArrayIndex(); |
452 // if there are more than 2 items |
|
453 if( iLoadingQueue.Count() > 2 && iState == ELoading ) |
|
454 { |
|
455 // insert to second position, first one is under loading |
|
456 iLoadingQueue.Insert( item, 1 ); |
|
457 } |
|
458 // else append to first or second |
|
459 else |
|
460 { |
|
461 iLoadingQueue.Append( item ); |
|
462 } |
439 } |
463 } |
440 } |
464 |
441 |
465 //if idle, start loading |
442 //if item and thumbnail index was not found ( queue limit ), reload thumbnail |
466 if( iState == EIdle ) |
443 if( reLoadThumbnail ) |
467 { |
444 { |
468 StartLoading(); |
445 TBool reOrderItem = ETrue; |
469 } |
446 TInt res = iLoadingQueue.Find( item ); |
470 } |
447 //remove from array if duplicate |
471 else |
448 if( res != KErrNotFound ) |
472 { |
449 { |
473 arrIndex = item->GetIconArrayIndex(); |
450 // if item's position is 0 or 1, dont reorder |
474 } |
451 if( res <= 1 ) |
|
452 { |
|
453 reOrderItem = EFalse; |
|
454 } |
|
455 // else remove item from the array for reordering |
|
456 else |
|
457 { |
|
458 iLoadingQueue.Remove( res ); |
|
459 } |
|
460 } |
|
461 |
|
462 // if item is to be reordered |
|
463 if( reOrderItem ) |
|
464 { |
|
465 // if there are more than 2 items |
|
466 if( iLoadingQueue.Count() > 2 && iState == ELoading ) |
|
467 { |
|
468 // insert to second position, first one is under loading |
|
469 iLoadingQueue.Insert( item, 1 ); |
|
470 } |
|
471 // else append to first or second |
|
472 else |
|
473 { |
|
474 iLoadingQueue.Append( item ); |
|
475 } |
|
476 } |
|
477 |
|
478 //if idle, start loading |
|
479 if( iState == EIdle ) |
|
480 { |
|
481 StartLoading(); |
|
482 } |
|
483 } |
|
484 } |
475 } |
485 return arrIndex; |
476 return arrIndex; |
486 } |
|
487 |
|
488 // -------------------------------------------------------------------------- |
|
489 // CPbk2ThumbnailManager::FindItem() |
|
490 // -------------------------------------------------------------------------- |
|
491 // |
|
492 CPbk2TmItem* CPbk2ThumbnailManager::FindItem( const MVPbkBaseContact& aContactLink ) |
|
493 { |
|
494 const TInt count = iContactThumbnails.Count(); |
|
495 for( TInt i = 0; i < count; ++i ) |
|
496 { |
|
497 if( iContactThumbnails[ i ]->GetLink()->RefersTo( aContactLink ) ) |
|
498 { |
|
499 return iContactThumbnails[i]; |
|
500 } |
|
501 } |
|
502 // shouldn't come here ever |
|
503 return NULL; |
|
504 } |
477 } |
505 |
478 |
506 // -------------------------------------------------------------------------- |
479 // -------------------------------------------------------------------------- |
507 // CPbk2ThumbnailManager::SetDefaultIconId() |
480 // CPbk2ThumbnailManager::SetDefaultIconId() |
508 // -------------------------------------------------------------------------- |
481 // -------------------------------------------------------------------------- |
514 iDefaultIconIndex = iIconArray->FindIcon( aDefaultIconId ); |
487 iDefaultIconIndex = iIconArray->FindIcon( aDefaultIconId ); |
515 } |
488 } |
516 iDefaultIconId = aDefaultIconId; |
489 iDefaultIconId = aDefaultIconId; |
517 } |
490 } |
518 |
491 |
519 |
|
520 // -------------------------------------------------------------------------- |
492 // -------------------------------------------------------------------------- |
521 // CPbk2ThumbnailManager::GetDefaultIconIndex() |
493 // CPbk2ThumbnailManager::GetDefaultIconIndex() |
522 // -------------------------------------------------------------------------- |
494 // -------------------------------------------------------------------------- |
523 // |
495 // |
524 const TPbk2IconId& CPbk2ThumbnailManager::GetDefaultIconId() |
496 const TPbk2IconId& CPbk2ThumbnailManager::GetDefaultIconId() |
525 { |
497 { |
526 return iDefaultIconId; |
498 return iDefaultIconId; |
527 } |
499 } |
528 |
500 |
529 |
|
530 // -------------------------------------------------------------------------- |
501 // -------------------------------------------------------------------------- |
531 // CPbk2ThumbnailManager::SetPbkIconArray() |
502 // CPbk2ThumbnailManager::SetPbkIconArray() |
532 // -------------------------------------------------------------------------- |
503 // -------------------------------------------------------------------------- |
533 // |
504 // |
534 void CPbk2ThumbnailManager::SetPbkIconArray( CPbk2IconArray* aIconArray ) |
505 void CPbk2ThumbnailManager::SetPbkIconArray( CPbk2IconArray* aIconArray ) |
535 { |
506 { |
536 iIconArray = aIconArray; |
507 iIconArray = aIconArray; |
537 } |
508 } |
538 |
|
539 |
509 |
540 // -------------------------------------------------------------------------- |
510 // -------------------------------------------------------------------------- |
541 // CPbk2ThumbnailManager::RemoveIconArray() |
511 // CPbk2ThumbnailManager::RemoveIconArray() |
542 // -------------------------------------------------------------------------- |
512 // -------------------------------------------------------------------------- |
543 // |
513 // |
548 const TInt count = iContactThumbnails.Count(); |
518 const TInt count = iContactThumbnails.Count(); |
549 |
519 |
550 // set all the indexes to default because there is no items in icon array to refer to |
520 // set all the indexes to default because there is no items in icon array to refer to |
551 for( TInt i = 0; i < count; ++i ) |
521 for( TInt i = 0; i < count; ++i ) |
552 { |
522 { |
553 iContactThumbnails[i]->SetIconArrayIndexAndId( iDefaultIconIndex, iDefaultIconId ); |
523 CPbk2TmItem* item = iContactThumbnails[i]; |
|
524 if( item ) |
|
525 { |
|
526 item->SetIconArrayIndexAndId( iDefaultIconIndex, iDefaultIconId ); |
|
527 } |
554 } |
528 } |
555 iIconIdCounter = 0; |
529 iIconIdCounter = 0; |
556 } |
530 } |
557 |
531 |
558 |
532 // -------------------------------------------------------------------------- |
559 // -------------------------------------------------------------------------- |
533 // CPbk2ThumbnailManager::DecreaseIndexes() |
560 // CPbk2ThumbnailManager::IncreaseIndexes() |
534 // -------------------------------------------------------------------------- |
561 // -------------------------------------------------------------------------- |
535 // |
562 // |
536 void CPbk2ThumbnailManager::ResetIndexes() |
563 void CPbk2ThumbnailManager::IncreaseIndexes( TInt aListboxIndex ) |
537 { |
564 { |
538 // go through items |
565 TInt i; |
|
566 TInt index = 0; |
|
567 const TInt count = iContactThumbnails.Count(); |
539 const TInt count = iContactThumbnails.Count(); |
568 // go through all contacts |
540 for( TInt i = 0; i < count; ++i ) |
569 for( i = 0; i < count; ++i ) |
|
570 { |
541 { |
571 index = iContactThumbnails[i]->GetListboxIndex(); |
542 CPbk2TmItem* item = iContactThumbnails[i]; |
572 // increase by one all the indexes that are bigger than newly added index |
543 if( item ) |
573 if( index >= aListboxIndex ) |
544 { |
574 { |
545 item->SetListboxIndex( i ); |
575 iContactThumbnails[i]->SetListboxIndex( index+1 ); |
546 } |
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 |
|
581 // -------------------------------------------------------------------------- |
|
582 // CPbk2ThumbnailManager::DecreaseIndexes() |
|
583 // -------------------------------------------------------------------------- |
|
584 // |
|
585 void CPbk2ThumbnailManager::DecreaseIndexes( TInt aListboxIndex ) |
|
586 { |
|
587 TInt i; |
|
588 const TInt count = iContactThumbnails.Count(); |
|
589 TInt index = 0; |
|
590 |
|
591 // go through items |
|
592 for( i = 0; i < count; ++i ) |
|
593 { |
|
594 index = iContactThumbnails[i]->GetListboxIndex(); |
|
595 // decrease all indexes that were bigger than removed index |
|
596 if( index > aListboxIndex ) |
|
597 { |
|
598 iContactThumbnails[i]->SetListboxIndex( index-1 ); |
|
599 } |
|
600 } |
547 } |
601 } |
548 } |
602 |
549 |
603 // -------------------------------------------------------------------------- |
550 // -------------------------------------------------------------------------- |
604 // CPbk2ThumbnailManager::Reset() |
551 // CPbk2ThumbnailManager::Reset() |
636 { |
583 { |
637 return iIconSize; |
584 return iIconSize; |
638 } |
585 } |
639 |
586 |
640 // -------------------------------------------------------------------------- |
587 // -------------------------------------------------------------------------- |
641 // CPbk2ThumbnailManager::LoadThumbnailL() |
588 // CPbk2ThumbnailManager::SetContactViewL() |
642 // -------------------------------------------------------------------------- |
589 // -------------------------------------------------------------------------- |
643 // |
590 // |
644 void CPbk2ThumbnailManager::LoadThumbnailL( const MVPbkContactLink& aContactLink, TInt aListboxIndex ) |
591 void CPbk2ThumbnailManager::SetContactViewL( MPbk2FilteredViewStack* aView ) |
645 { |
592 { |
646 // check if the thumbnail is already loaded |
593 iView = aView; |
647 if( aListboxIndex < iContactThumbnails.Count() && |
594 if( iView ) |
648 iContactThumbnails[aListboxIndex]->GetLink()->IsSame( aContactLink ) ) |
595 { |
649 { |
596 iView->AddObserverL( *this ); |
650 CFbsBitmap* tmp = iContactThumbnails[ aListboxIndex ]->GetBitmap(); |
597 iView->AddStackObserverL( *this ); |
651 // if there is icon for the contact allready loaded |
598 } |
652 if( tmp ) |
599 Reset(); |
653 { |
600 } |
654 //inform observer |
|
655 if( iObserver ) |
|
656 { |
|
657 //if icon array exists |
|
658 if( iIconArray ) |
|
659 { |
|
660 //create icon and pass it to the array |
|
661 CGulIcon* icon = CGulIcon::NewL( DuplicateBitmapL( tmp ) ); |
|
662 // counter to add icon ids |
|
663 TPbk2IconId iconID( TUid::Uid(KPbk2UID3 ), |
|
664 KIconIndexOffset + iIconIdCounter ); |
|
665 iIconIdCounter++; |
|
666 iIconArray->AppendIconL( icon, iconID ); |
|
667 // store the index |
|
668 iContactThumbnails[ aListboxIndex ]->SetIconArrayIndexAndId( iIconArray->FindIcon( iconID ), iconID ); |
|
669 iObserver->ThumbnailLoadingComplete( KErrNone,iContactThumbnails[ aListboxIndex]->GetListboxIndex() ); |
|
670 } |
|
671 } |
|
672 } |
|
673 else |
|
674 { |
|
675 // has a default icon |
|
676 iObserver->ThumbnailLoadingComplete( KErrNotFound,iContactThumbnails[ aListboxIndex]->GetListboxIndex() ); |
|
677 } |
|
678 } |
|
679 // new contact, add new CPbk2TmItem to thumbnail array |
|
680 else |
|
681 { |
|
682 // create new contact item. Thumbnail is not yet loaded so it's set to NULL |
|
683 CPbk2TmItem* item = CPbk2TmItem::NewL( aContactLink.CloneLC(), aListboxIndex ); |
|
684 CleanupStack::Pop(); |
|
685 // set default icon index |
|
686 item->SetIconArrayIndexAndId( iDefaultIconIndex,iDefaultIconId ); |
|
687 item->SetHasThumbnail( ETrue ); |
|
688 |
|
689 |
|
690 // if thumbnail to be loaded is added middle of the list (new contact), handle indexes |
|
691 const TInt lastIndex = iContactThumbnails.Count() - 1; |
|
692 if( lastIndex >= 0 && |
|
693 aListboxIndex <= iContactThumbnails[ lastIndex ]->GetListboxIndex() ) |
|
694 { |
|
695 // make room for the new thumbnail. Function does nothing if priority array is not full |
|
696 // This is because we need to get the thumbnail showing right away when new contact is added |
|
697 MakeRoomForNextThumbnail(); |
|
698 // increase indexes after this added index |
|
699 IncreaseIndexes( aListboxIndex ); |
|
700 } |
|
701 |
|
702 // add item |
|
703 TLinearOrder<CPbk2TmItem> sorter( CPbk2TmItem::CompareByListboxIndex ); |
|
704 iContactThumbnails.InsertInOrderL( item, sorter ); |
|
705 |
|
706 // also add item to loading queue. This is because the actual array is sorted between thumbnail loading |
|
707 // list doesn't own the items |
|
708 // if added item's listbox index is smaller than already added, add to start end on loading queue |
|
709 const TInt queueCount = iLoadingQueue.Count(); |
|
710 if( aListboxIndex < queueCount && queueCount > 2 ) |
|
711 { |
|
712 //add to second place, first one is under loading |
|
713 iLoadingQueue.Insert( item, 1 ); |
|
714 } |
|
715 // just add last place on the list |
|
716 else |
|
717 { |
|
718 iLoadingQueue.Append( item ); |
|
719 } |
|
720 |
|
721 //if idle, start loading |
|
722 if( iState == EIdle ) |
|
723 { |
|
724 StartLoading(); |
|
725 } |
|
726 } |
|
727 } |
|
728 |
601 |
729 // -------------------------------------------------------------------------- |
602 // -------------------------------------------------------------------------- |
730 // CPbk2ThumbnailManager::RemoveThumbnail() |
603 // CPbk2ThumbnailManager::RemoveThumbnail() |
731 // -------------------------------------------------------------------------- |
604 // -------------------------------------------------------------------------- |
732 // |
605 // |
733 TInt CPbk2ThumbnailManager::RemoveThumbnail( const MVPbkContactLink& aContactLink, TInt aListboxIndex ) |
606 void CPbk2ThumbnailManager::RemoveThumbnail( |
734 { |
607 const MVPbkContactLink& /*aContactLink*/, TInt aListboxIndex ) |
735 TInt i; |
608 { |
736 const TInt count = iContactThumbnails.Count(); |
609 const TInt count = iContactThumbnails.Count(); |
737 CPbk2TmItem* item = NULL; |
610 if( count > aListboxIndex ) |
738 TInt listBoxIndex = 0; |
611 { |
739 |
612 CPbk2TmItem* item = iContactThumbnails[aListboxIndex]; |
740 for( i = 0; i < count; ++i ) |
613 iContactThumbnails.Remove( aListboxIndex ); |
741 { |
614 ResetIndexes(); |
742 item = iContactThumbnails[i]; |
615 if( item ) |
743 if( item->GetLink()->IsSame( aContactLink ) ) |
616 { |
744 { |
|
745 // store listbox index before updating |
|
746 listBoxIndex = item->GetListboxIndex(); |
|
747 |
|
748 // handle indexes |
|
749 DecreaseIndexes( aListboxIndex ); |
|
750 |
|
751 // remove item from the list |
|
752 iContactThumbnails.Remove( i ); |
|
753 |
|
754 // check that the icon is not a default icon |
617 // check that the icon is not a default icon |
755 if( item->GetIconArrayIndex() != iDefaultIconIndex ) |
618 if( item->GetIconArrayIndex() != iDefaultIconIndex ) |
756 { |
619 { |
757 if( iIconArray ) |
620 if( iIconArray ) |
758 { |
621 { |
761 } |
624 } |
762 //update indexes after that |
625 //update indexes after that |
763 UpdateIconIndexes(); |
626 UpdateIconIndexes(); |
764 } |
627 } |
765 |
628 |
766 //remove item from priority array if in it |
629 // remove from priority list |
767 const TInt index = iPriorityArray.Find( item->GetLink() ); |
630 const TInt priIndex = iPriorityArray.Find( item->GetLink() ); |
768 //remove if found |
631 if( priIndex != KErrNotFound ) |
769 if( index != KErrNotFound ) |
632 { |
770 { |
633 iPriorityArray.Remove( priIndex ); |
771 iPriorityArray.Remove( index ); |
634 } |
772 } |
635 |
773 |
636 // remove from loading queue |
774 //The item might be even in the loading queue |
|
775 //Remove from loading queue |
|
776 //remove item from priority array if in it |
|
777 const TInt loadIndex = iLoadingQueue.Find( item ); |
637 const TInt loadIndex = iLoadingQueue.Find( item ); |
778 //remove if found |
|
779 if( loadIndex != KErrNotFound ) |
638 if( loadIndex != KErrNotFound ) |
780 { |
639 { |
781 iLoadingQueue.Remove( loadIndex ); |
640 iLoadingQueue.Remove( loadIndex ); |
782 } |
641 } |
783 |
642 |
784 // inform observer |
643 // inform observer |
785 if( iObserver ) |
644 if( iObserver ) |
786 { |
645 { |
787 iObserver->ThumbnailRemoved( *item->GetLink(),listBoxIndex ); |
646 iObserver->ThumbnailRemoved( *item->GetLink(), aListboxIndex ); |
788 } |
647 } |
789 |
648 |
790 //The item at 0th position, denotes the current item |
649 //The item at 0th position, denotes the current item |
791 //whose thumbnail load is in progress. |
650 //whose thumbnail load is in progress. |
792 if ( KStartIndex == loadIndex && !iInProgressItemToBeRemoved ) |
651 if ( KStartIndex == loadIndex && !iInProgressItemToBeRemoved ) |
793 { |
652 { |
794 //Remove it when its safe |
653 //Remove it when its safe |
795 iInProgressItemToBeRemoved = item; |
654 iInProgressItemToBeRemoved = item; |
796 } |
655 } |
797 else |
656 else |
798 { |
657 { |
799 //can be safely deleted immediately |
658 //can be safely deleted immediately |
800 delete item; |
659 delete item; |
801 } |
660 } |
802 return KErrNone; |
661 } |
803 } |
662 } |
804 } |
663 } |
805 return KErrNotFound; |
|
806 } |
|
807 |
|
808 |
664 |
809 // -------------------------------------------------------------------------- |
665 // -------------------------------------------------------------------------- |
810 // CPbk2ThumbnailManager::UpdateIconIndexes() |
666 // CPbk2ThumbnailManager::UpdateIconIndexes() |
811 // -------------------------------------------------------------------------- |
667 // -------------------------------------------------------------------------- |
812 // |
668 // |
816 if( iIconArray ) |
672 if( iIconArray ) |
817 { |
673 { |
818 const TInt count = iContactThumbnails.Count(); |
674 const TInt count = iContactThumbnails.Count(); |
819 for( TInt i = 0; i < count; ++i ) |
675 for( TInt i = 0; i < count; ++i ) |
820 { |
676 { |
821 if( !( iDefaultIconId == iContactThumbnails[ i ]->GetIconId() ) ) |
677 CPbk2TmItem* item = iContactThumbnails[ i ]; |
|
678 if( item && !( iDefaultIconId == item->GetIconId() ) ) |
822 { |
679 { |
823 // icon is removed from the CPbk2IconArray, update indexes |
680 // icon is removed from the CPbk2IconArray, update indexes |
824 TPbk2IconId id = iContactThumbnails[ i ]->GetIconId(); |
681 TPbk2IconId id = item->GetIconId(); |
825 iContactThumbnails[ i ]->SetIconArrayIndexAndId( iIconArray->FindIcon( id ), id ); |
682 item->SetIconArrayIndexAndId( iIconArray->FindIcon( id ), id ); |
826 } |
683 } |
827 } |
684 } |
828 } |
685 } |
829 } |
686 } |
830 |
|
831 |
|
832 |
687 |
833 // -------------------------------------------------------------------------- |
688 // -------------------------------------------------------------------------- |
834 // CPbk2ThumbnailManager::DuplicateBitmapL() |
689 // CPbk2ThumbnailManager::DuplicateBitmapL() |
835 // -------------------------------------------------------------------------- |
690 // -------------------------------------------------------------------------- |
836 // |
691 // |
980 // if iconsize is not set |
832 // if iconsize is not set |
981 if( iIconSize.iHeight == 0 && iIconSize.iWidth == 0 ) |
833 if( iIconSize.iHeight == 0 && iIconSize.iWidth == 0 ) |
982 { |
834 { |
983 iIconSize = KDefaultThumbnailSize; |
835 iIconSize = KDefaultThumbnailSize; |
984 } |
836 } |
985 TInt useCropping = 0x0008; |
|
986 // set params |
837 // set params |
987 params.iSize = iIconSize; |
838 params.iSize = iIconSize; |
988 params.iFlags = TPbk2ImageManagerParams::EScaleImage | |
839 params.iFlags = TPbk2ImageManagerParams::EScaleImage | |
989 TPbk2ImageManagerParams::EKeepAspectRatio | |
840 TPbk2ImageManagerParams::EUseSpeedOptimizedScaling | |
990 useCropping; //CROP IMAGE //TODO change value |
841 TPbk2ImageManagerParams::ECropImage ; |
|
842 params.iDisplayMode = EColor16MU; |
991 // fetch the image |
843 // fetch the image |
992 TRAP( err, iThumbOperation = |
844 TRAP( err, iThumbOperation = |
993 iManager->GetImageAsyncL( ¶ms, aContact, *iFieldType, *this ) ); |
845 iManager->GetImageAsyncL( ¶ms, aContact, *iFieldType, *this ) ); |
994 } |
846 } |
995 // no room at this moment |
847 // no room at this moment |
1161 // -------------------------------------------------------------------------- |
1011 // -------------------------------------------------------------------------- |
1162 // |
1012 // |
1163 void CPbk2ThumbnailManager::DoContactViewReadyL( MVPbkContactViewBase& aView ) |
1013 void CPbk2ThumbnailManager::DoContactViewReadyL( MVPbkContactViewBase& aView ) |
1164 { |
1014 { |
1165 // get contact count |
1015 // get contact count |
1166 const TInt contactCount = aView.ContactCountL(); |
|
1167 const TInt thumbnailCount = iContactThumbnails.Count(); |
1016 const TInt thumbnailCount = iContactThumbnails.Count(); |
1168 |
|
1169 if( thumbnailCount == 0 ) |
1017 if( thumbnailCount == 0 ) |
1170 { |
1018 { |
1171 // first time initialization |
1019 PreCreateThumbnailArrayL( aView ); |
1172 for( TInt i = 0; i < contactCount; ++i ) |
|
1173 { |
|
1174 CPbk2TmItem* item = CPbk2TmItem::NewL( aView.CreateLinkLC( i ), i ); |
|
1175 CleanupStack::Pop(); // link |
|
1176 CleanupStack::PushL( item ); |
|
1177 // set default icon index |
|
1178 item->SetIconArrayIndexAndId( iDefaultIconIndex,iDefaultIconId ); |
|
1179 item->SetHasThumbnail( ETrue ); |
|
1180 |
|
1181 // add item |
|
1182 iContactThumbnails.AppendL( item ); |
|
1183 CleanupStack::Pop( item ); |
|
1184 } |
|
1185 } |
1020 } |
1186 else |
1021 else |
1187 { |
1022 { |
1188 // there is items in the listbox that are not loaded yet. If there is favorite contacts, |
1023 // there is items in the listbox that are not loaded yet. If there is favorite contacts, |
1189 // those are added afterwards to the list. normal items are added first. |
1024 // those are added afterwards to the list. normal items are added first. |
1190 const TInt itemCount = contactCount - thumbnailCount; |
1025 const TInt itemCount = aView.ContactCountL() - thumbnailCount; |
1191 for( TInt i = 0; i < itemCount; ++i ) |
1026 for( TInt i = 0; i < itemCount; ++i ) |
1192 { |
1027 { |
1193 MVPbkContactLink* link = aView.CreateLinkLC( i ); |
1028 iContactThumbnails.InsertL( NULL, 0 ); |
1194 // if link exists and some thumbnails are not loaded |
1029 } |
1195 if( link ) |
1030 if( itemCount > 0 ) |
1196 { |
1031 { |
1197 // add to thumb manager and load thumbnail |
1032 ResetIndexes(); |
1198 LoadThumbnailL( *link,i ); |
|
1199 // created link |
|
1200 CleanupStack::PopAndDestroy(); |
|
1201 } |
|
1202 } |
1033 } |
1203 } |
1034 } |
1204 } |
1035 } |
1205 |
1036 |
1206 // -------------------------------------------------------------------------- |
1037 // -------------------------------------------------------------------------- |
1207 // CPbk2ThumbnailManager::ContactAddedToView |
1038 // CPbk2ThumbnailManager::PreCreateThumbnailArrayL |
|
1039 // -------------------------------------------------------------------------- |
|
1040 // |
|
1041 void CPbk2ThumbnailManager::PreCreateThumbnailArrayL( MVPbkContactViewBase& aView ) |
|
1042 { |
|
1043 iContactThumbnails.ResetAndDestroy(); |
|
1044 const TInt contactCount = aView.ContactCountL(); |
|
1045 for( TInt i = 0; i < contactCount; ++i ) |
|
1046 { |
|
1047 iContactThumbnails.AppendL( NULL ); |
|
1048 } |
|
1049 } |
|
1050 |
|
1051 // -------------------------------------------------------------------------- |
|
1052 // CPbk2ThumbnailManager::ContactViewUnavailable |
1208 // -------------------------------------------------------------------------- |
1053 // -------------------------------------------------------------------------- |
1209 // |
1054 // |
1210 void CPbk2ThumbnailManager::ContactViewUnavailable( |
1055 void CPbk2ThumbnailManager::ContactViewUnavailable( |
1211 MVPbkContactViewBase& /*aView*/ ) |
1056 MVPbkContactViewBase& /*aView*/ ) |
1212 { |
1057 { |
1218 // -------------------------------------------------------------------------- |
1063 // -------------------------------------------------------------------------- |
1219 // |
1064 // |
1220 void CPbk2ThumbnailManager::ContactAddedToView( |
1065 void CPbk2ThumbnailManager::ContactAddedToView( |
1221 MVPbkContactViewBase& /*aView*/, |
1066 MVPbkContactViewBase& /*aView*/, |
1222 TInt aIndex, |
1067 TInt aIndex, |
1223 const MVPbkContactLink& aContactLink ) |
1068 const MVPbkContactLink& /*aContactLink*/ ) |
1224 { |
1069 { |
1225 TRAP_IGNORE( LoadThumbnailL( aContactLink, aIndex ) ); |
1070 iContactThumbnails.Insert( NULL, aIndex ); |
1226 } |
1071 ResetIndexes(); |
1227 |
1072 } |
1228 // -------------------------------------------------------------------------- |
1073 |
1229 // CPbk2ThumbnailManager::ContactViewError |
1074 // -------------------------------------------------------------------------- |
|
1075 // CPbk2ThumbnailManager::ContactRemovedFromView |
1230 // -------------------------------------------------------------------------- |
1076 // -------------------------------------------------------------------------- |
1231 // |
1077 // |
1232 void CPbk2ThumbnailManager::ContactRemovedFromView( |
1078 void CPbk2ThumbnailManager::ContactRemovedFromView( |
1233 MVPbkContactViewBase& /*aView*/, |
1079 MVPbkContactViewBase& /*aView*/, |
1234 TInt aIndex, |
1080 TInt aIndex, |
1245 MVPbkContactViewBase& /*aView*/, |
1091 MVPbkContactViewBase& /*aView*/, |
1246 TInt /*aError*/, |
1092 TInt /*aError*/, |
1247 TBool /*aErrorNotified*/ ) |
1093 TBool /*aErrorNotified*/ ) |
1248 { |
1094 { |
1249 // ignored |
1095 // ignored |
|
1096 } |
|
1097 |
|
1098 // -------------------------------------------------------------------------- |
|
1099 // CPbk2ThumbnailManager::TopViewChangedL |
|
1100 // -------------------------------------------------------------------------- |
|
1101 // |
|
1102 void CPbk2ThumbnailManager::TopViewChangedL( MVPbkContactViewBase& /*aOldView*/ ) |
|
1103 { |
|
1104 Reset(); |
|
1105 if( iView ) |
|
1106 { |
|
1107 PreCreateThumbnailArrayL( *iView ); |
|
1108 } |
|
1109 } |
|
1110 |
|
1111 // -------------------------------------------------------------------------- |
|
1112 // CPbk2ThumbnailManager::TopViewUpdatedL |
|
1113 // -------------------------------------------------------------------------- |
|
1114 // |
|
1115 void CPbk2ThumbnailManager::TopViewUpdatedL() |
|
1116 { |
|
1117 } |
|
1118 |
|
1119 // -------------------------------------------------------------------------- |
|
1120 // CPbk2ThumbnailManager::BaseViewChangedL |
|
1121 // -------------------------------------------------------------------------- |
|
1122 // |
|
1123 void CPbk2ThumbnailManager::BaseViewChangedL() |
|
1124 { |
|
1125 } |
|
1126 |
|
1127 // -------------------------------------------------------------------------- |
|
1128 // CPbk2ThumbnailManager::ViewStackError |
|
1129 // -------------------------------------------------------------------------- |
|
1130 // |
|
1131 void CPbk2ThumbnailManager::ViewStackError( TInt /*aError*/ ) |
|
1132 { |
|
1133 } |
|
1134 |
|
1135 // -------------------------------------------------------------------------- |
|
1136 // CPbk2ThumbnailManager::ContactAddedToBaseView |
|
1137 // -------------------------------------------------------------------------- |
|
1138 // |
|
1139 void CPbk2ThumbnailManager::ContactAddedToBaseView( |
|
1140 MVPbkContactViewBase& /*aBaseView*/, |
|
1141 TInt /*aIndex*/, |
|
1142 const MVPbkContactLink& /*aContactLink*/ ) |
|
1143 { |
1250 } |
1144 } |
1251 |
1145 |
1252 // -------------------------------------------------------------------------- |
1146 // -------------------------------------------------------------------------- |
1253 // CPbk2ThumbnailManager::ReadFieldTypeL |
1147 // CPbk2ThumbnailManager::ReadFieldTypeL |
1254 // -------------------------------------------------------------------------- |
1148 // -------------------------------------------------------------------------- |