photosgallery/controllers/fetcher/src/glxfetchercontainer.cpp
changeset 0 4e91876724a2
child 1 9ba538e329bd
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Container for Fecther Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // System includes
       
    22 #include <avkon.rsg>                    
       
    23 #include <AknUtils.h>                               // For AknLayoutUtils to calculate rect
       
    24 #include <data_caging_path_literals.hrh>            // KDC_APP_RESOURCE_DIR			
       
    25 #include <StringLoader.h>                           // For Empty text reading from resource
       
    26 #include <akntitle.h>                               // Title Pane 
       
    27 
       
    28 #include <mpxcollectionutility.h>                   // Mpx Collection path for medialist craetion
       
    29 #include <gulicon.h>                                // Gul Icon 
       
    30 #include <ganes/HgItem.h>                           // HG Item 
       
    31 #include <ganes/HgGrid.h>                           // Hg Grid Widget
       
    32 #include <AknsBasicBackgroundControlContext.h>      // Background Context
       
    33 
       
    34 #include <glxuistd.h>                               // KGlxFetchontextPriorityNormal and KGlxIconsFilename           
       
    35 #include <glxcollectionpluginall.hrh> 	            // All item collection plugin id
       
    36 #include <glxfilterfactory.h>                       // For Filters required in Medilaits
       
    37 #include <glxresourceutilities.h>                   // for CGlxResourceUtilities
       
    38 #include <glxfetcherdialog.rsg>                     // FOR GETTING Dialog ID AND RESOURCE ID
       
    39 #include <glxattributecontext.h>                    // TMPXAttribute
       
    40 #include <glxattributeretriever.h>  	            // CGlxAttributeRetriever
       
    41 #include <glxfetchcontextremover.h>                 // TGlxfetchContextRemover
       
    42 #include <glxuiutility.h>                           // AknIconUtils and EikStatusPane
       
    43 #include <glxtracer.h>                              // For Tracer logs
       
    44 #include <glxlog.h>                                 // Glx Logger
       
    45 #include <glxgridviewmlobserver.h>                  // Medialistobserver for HgGrid
       
    46 #include <glxthumbnailcontext.h>                    // Thumbnailcontext for HgGrid
       
    47 #include <glxicons.mbg>                             // Glx Icons for HgGrid                     
       
    48 #include <mglxmedialist.h>				            // MGlxMediaList, CMPXCollectionPath
       
    49 #include <glxcommandhandlers.hrh>                   // For EGlxCmdEndMultiplemarking and EGlxCmdStartMultiplemarking 
       
    50 #include <glxthumbnailattributeinfo.h>              // KGlxMediaIdThumbnail
       
    51 #include <glxerrormanager.h>
       
    52 #include <glxdrmutility.h>                          // DRM utility class to provide DRM-related functionality
       
    53 
       
    54 // User includes
       
    55 #include "glxfetchercontainer.h"
       
    56 #include "mglxeventobserver.h"
       
    57 #include "glxfetcher.hrh"
       
    58 #include "glxfetchercommandhandler.h"
       
    59 
       
    60 const TInt KPadding(7);
       
    61 const TInt KNoOfPages(4);
       
    62 const TInt KBufferTreshold(1);
       
    63 const TInt KItemsPerPage(18);
       
    64 const TInt KBufferSize(KNoOfPages * KItemsPerPage);
       
    65 const TInt KBufferTresholdSize(KBufferTreshold * KItemsPerPage);
       
    66 
       
    67 //-----------------------------------------------------------------------------
       
    68 // Two-phased constructor.
       
    69 //-----------------------------------------------------------------------------
       
    70 CGlxFetcherContainer* CGlxFetcherContainer::NewL(
       
    71         TGlxFilterItemType aFilterType, const TDesC& aTitle, 
       
    72         MGlxEventObserver& aEventObserver, TBool aMultiSelectionEnabled ) 
       
    73 	{
       
    74 	TRACER("CGlxFetcherContainer::NewL");
       
    75 	CGlxFetcherContainer* self = 
       
    76 	    new( ELeave ) CGlxFetcherContainer( aFilterType ,aTitle, 
       
    77 	            aEventObserver, aMultiSelectionEnabled);
       
    78 	CleanupStack::PushL( self );
       
    79 	self->ConstructL();
       
    80 	CleanupStack::Pop( self ); 
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 //-----------------------------------------------------------------------------
       
    85 // C++ default constructor.
       
    86 //-----------------------------------------------------------------------------
       
    87 CGlxFetcherContainer::CGlxFetcherContainer(
       
    88         TGlxFilterItemType aFilterType ,const TDesC& aTitle,
       
    89         MGlxEventObserver& aEventObserver, TBool aMultiSelectionEnabled )
       
    90     : iFilterType( aFilterType ),
       
    91     iTitle( aTitle ),iEventObserver(aEventObserver),
       
    92     iMultiSelectionEnabled(aMultiSelectionEnabled)      
       
    93     {
       
    94     TRACER("CGlxFetcherContainer::CGlxFetcherContainer");
       
    95     // No implementation required
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // ConstructL()
       
   100 // ---------------------------------------------------------------------------
       
   101 void CGlxFetcherContainer::ConstructL()
       
   102     {
       
   103     TRACER("CGlxFetcherContainer::ConstructL");
       
   104     iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
   105             KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
   106     iUiUtility = CGlxUiUtility::UtilityL();
       
   107     iGridIconSize = iUiUtility->GetGridIconSize();
       
   108 
       
   109     // For DRM Utility
       
   110     iDRMUtility = CGlxDRMUtility::InstanceL();
       
   111     iIsFileAttached = EFalse;
       
   112     }
       
   113 
       
   114 //-----------------------------------------------------------------------------
       
   115 // Destructor
       
   116 //-----------------------------------------------------------------------------
       
   117 CGlxFetcherContainer::~CGlxFetcherContainer()
       
   118     {
       
   119     TRACER("CGlxFetcherContainer::~CGlxFetcherContainer");
       
   120     if (iDRMUtility)
       
   121         {
       
   122         iDRMUtility->Close();
       
   123         }            
       
   124     delete iBgContext;
       
   125     delete iPreviousTitle;
       
   126     delete iFetcherCommandHandler;
       
   127     delete iGlxGridMLObserver;  
       
   128     if (iHgGrid)
       
   129         {
       
   130         iHgGrid->SetFocus(EFalse);
       
   131         delete iHgGrid;
       
   132         iHgGrid = NULL;
       
   133         }
       
   134     if (iMediaList)
       
   135         {
       
   136         iMediaList->RemoveContext(iThumbnailContext);
       
   137         delete iThumbnailContext;
       
   138         iMediaList->Close();
       
   139         }
       
   140     if (iUiUtility)
       
   141         {
       
   142         iUiUtility->Close() ;
       
   143         }
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CreateAndDisplayGridL
       
   149 // ---------------------------------------------------------------------------
       
   150 //  
       
   151 void CGlxFetcherContainer::CreateAndDisplayGridL()
       
   152 	{
       
   153 	TRACER("CGlxFetcherContainer::CreateAndDisplayGridL");
       
   154     //Create Medialist
       
   155     CreateMediaListL();
       
   156     
       
   157 	// Create the control here
       
   158     CreateHgGridWidgetL();
       
   159     
       
   160     CreateGridMediaListObserverL();
       
   161 	
       
   162     CreateEmptyDisplayL( iFilterType );
       
   163 	
       
   164 	// If multiple image selection is allowed, then set marking flag on grid widget.
       
   165 	if(iMultiSelectionEnabled)
       
   166 	    {
       
   167 	    // Fetcher CommandHandler must be created after creating the medialist
       
   168 	    iFetcherCommandHandler = CGlxFetcherCommandHandler::NewL( this , this );
       
   169 	    
       
   170 	    iHgGrid->SetFlags( CHgScroller::EHgScrollerSelectionMode );
       
   171 	    iMultipleMarkNotStarted = EFalse;
       
   172 	    }
       
   173 	}
       
   174 // ---------------------------------------------------------------------------
       
   175 // CreateEmptyDisplayL
       
   176 // Displays the empty string if no items in grid with respect to item selected.
       
   177 // ---------------------------------------------------------------------------
       
   178 //  
       
   179 void CGlxFetcherContainer::CreateEmptyDisplayL( TGlxFilterItemType aFilterType )
       
   180 	{
       
   181 	TRACER("CGlxFetcherContainer::CreateEmptyDisplayL");
       
   182     if (aFilterType == EGlxFilterImage)
       
   183         {
       
   184         HBufC* emptyText = 
       
   185                   StringLoader::LoadLC(R_FETCHER_EMPTY_VIEW_TEXT_IMAGE);
       
   186         iHgGrid->SetEmptyTextL(*emptyText);
       
   187         CleanupStack::PopAndDestroy(emptyText);
       
   188         }
       
   189     else if (aFilterType == EGlxFilterVideo)
       
   190         {
       
   191         HBufC* emptyText = 
       
   192                   StringLoader::LoadLC(R_FETCHER_EMPTY_VIEW_TEXT_VIDEO);
       
   193         iHgGrid->SetEmptyTextL(*emptyText);
       
   194         CleanupStack::PopAndDestroy(emptyText);
       
   195         }
       
   196 	}
       
   197 // ---------------------------------------------------------------------------
       
   198 // CreateMediaListL()
       
   199 // Creates a collection path
       
   200 // Create a filter as requested filtertype
       
   201 // Creates the medialist
       
   202 // ---------------------------------------------------------------------------
       
   203 void CGlxFetcherContainer::CreateMediaListL() 
       
   204 	{
       
   205 	TRACER("CGlxFetcherContainer::CreateMediaListL");
       
   206    		
       
   207 	// Create path to the list of images and videos
       
   208 	CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   209 	CleanupStack::PushL( path );
       
   210 	path->AppendL(KGlxCollectionPluginAllImplementationUid);	// All item collection plugin  
       
   211 	
       
   212 	// Create filter to filter out either images or videos
       
   213 	GLX_LOG_INFO1("CGlxFetcherContainer::MediaListL  - Filter Type = %d",iFilterType);
       
   214 	CMPXFilter* filter = TGlxFilterFactory::CreateItemTypeFilterL(iFilterType);  
       
   215 	CleanupStack::PushL(filter);
       
   216 	
       
   217 	// Create the media list
       
   218 	iMediaList =  MGlxMediaList::InstanceL( *path, 
       
   219 	                  TGlxHierarchyId(KGlxFetcherDllUid), filter );
       
   220 	CleanupStack::PopAndDestroy( filter );
       
   221 	
       
   222 	GLX_LOG_INFO1("CGlxFetcherContainer::MediaListL  - Path level = %d",
       
   223 	                                                     path->Levels());
       
   224 	
       
   225 	CleanupStack::PopAndDestroy( path );
       
   226 	}
       
   227 // ---------------------------------------------------------------------------
       
   228 // CreateHgGridWidgetL
       
   229 // ---------------------------------------------------------------------------
       
   230 //  
       
   231 void CGlxFetcherContainer::CreateHgGridWidgetL()
       
   232 	{
       
   233     TRACER("CGlxFetcherContainer::CreateHgGridWidgetL");
       
   234     //Setting the Title
       
   235     SetTitleL( iTitle);
       
   236 
       
   237     iThumbnailContext = CGlxThumbnailContext::NewL( &iBlockyIterator ); // set the thumbnail context
       
   238     iThumbnailContext->SetDefaultSpec( iUiUtility->GetGridIconSize().iWidth,
       
   239             iUiUtility->GetGridIconSize().iHeight );
       
   240 
       
   241     CGlxDefaultAttributeContext* attrContext = CGlxDefaultAttributeContext::NewL();
       
   242     CleanupStack::PushL(attrContext);
       
   243     attrContext->AddAttributeL(KMPXMediaGeneralCount);
       
   244     attrContext->SetRangeOffsets(KItemsPerPage, KItemsPerPage);
       
   245     iMediaList->AddContextL(attrContext, KGlxFetchContextPriorityGridViewVisibleThumbnail);
       
   246     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attrContext,*iMediaList,EFalse));
       
   247     iMediaList->RemoveContext(attrContext);
       
   248     CleanupStack::PopAndDestroy( attrContext );
       
   249     iMediaList->AddContextL(iThumbnailContext, KGlxFetchContextPriorityNormal );
       
   250 
       
   251     if (!iHgGrid)
       
   252         {
       
   253         TRect rect;
       
   254         AknLayoutUtils::LayoutMetricsRect (AknLayoutUtils::EMainPane, rect);
       
   255         TSize iconSize (iUiUtility->GetGridIconSize().iWidth - (2*KPadding),
       
   256                 iUiUtility->GetGridIconSize().iHeight -(2*KPadding));
       
   257         TFileName resFile(KDC_APP_BITMAP_DIR);
       
   258         resFile.Append(KGlxIconsFilename);
       
   259         CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   260                 EMbmGlxiconsQgn_prop_image_notcreated);
       
   261         AknIconUtils::SetSize(bitmap, iconSize);
       
   262 
       
   263         // Create Hg grid object
       
   264         iHgGrid = CHgGrid::NewL ( 
       
   265                 rect, 
       
   266                 iMediaList->Count(), 
       
   267                 CGulIcon::NewL(bitmap) );
       
   268         }
       
   269     iHgGrid->SetSelectedIndex(iMediaList->FocusIndex());
       
   270     // Setting to MopParent to update background skin
       
   271     iHgGrid->SetMopParent(this);
       
   272     // Setting Selction observer for getting callback on key event change
       
   273     iHgGrid->SetSelectionObserver(*this);
       
   274     // This Displays the scrollbar at the opening of the Grid view
       
   275     iHgGrid->SetScrollBarTypeL(CHgScroller::EHgScrollerTimeStrip );
       
   276     // Enable Buffer support
       
   277     iHgGrid->EnableScrollBufferL(*this, KBufferSize, KBufferTresholdSize);
       
   278     // Enable Marking support
       
   279     iHgGrid->SetMarkingObserver(*this);
       
   280 
       
   281 	iHgGrid->SetFocus(ETrue);
       
   282 	}
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CreateGridMediaListObserverL
       
   286 // ---------------------------------------------------------------------------
       
   287 //  
       
   288 void CGlxFetcherContainer::CreateGridMediaListObserverL()
       
   289     {
       
   290     iGlxGridMLObserver = CGlxGridViewMLObserver::NewL(*iMediaList , iHgGrid);
       
   291     }
       
   292     
       
   293 // ---------------------------------------------------------------------------
       
   294 // BufferPositionChanged
       
   295 // ---------------------------------------------------------------------------
       
   296 //  
       
   297 void CGlxFetcherContainer::Request(TInt aRequestStart, TInt aRequestEnd,
       
   298         THgScrollDirection /*aDirection*/)
       
   299     {
       
   300     TRACER("CGlxFetcherContainer::Request()");
       
   301     RequestL(aRequestStart, aRequestEnd);
       
   302     }
       
   303 // ---------------------------------------------------------------------------
       
   304 // RequestL
       
   305 // ---------------------------------------------------------------------------
       
   306 //  
       
   307 void CGlxFetcherContainer::RequestL(TInt aRequestStart, TInt aRequestEnd)
       
   308     {
       
   309     TRACER("CGlxFetcherContainer::RequestL()");
       
   310     TInt mediaCount = iMediaList->Count();
       
   311 
       
   312     aRequestStart = (aRequestStart<0 ? 0 : aRequestStart) ;
       
   313     aRequestEnd = (aRequestEnd>=mediaCount? mediaCount : aRequestEnd);
       
   314 
       
   315     if (aRequestEnd - aRequestStart)
       
   316         {
       
   317         TInt visIndex = iHgGrid->FirstIndexOnScreen();
       
   318         if (visIndex < 0)
       
   319             {
       
   320             visIndex = 0;
       
   321             }
       
   322 
       
   323         else if (visIndex >= mediaCount)
       
   324             {
       
   325             visIndex = mediaCount-1;
       
   326             }
       
   327 
       
   328         GLX_LOG_INFO1("CGlxGridViewImp::Request - SetVisibleWindowIndex "
       
   329                 "visIndex(%d)", visIndex);
       
   330         iMediaList->SetVisibleWindowIndexL(visIndex);
       
   331         }
       
   332     for (TInt i=aRequestStart; i<= aRequestEnd; i++)
       
   333         {
       
   334         SetIconsL(i);
       
   335         TInt firstIndex = iHgGrid->FirstIndexOnScreen();
       
   336         TInt lastOnScreen = firstIndex + iHgGrid->ItemsOnScreen() - 1;
       
   337         if (i >= firstIndex && i <= lastOnScreen)
       
   338             {
       
   339             GLX_LOG_INFO1("CGlxGridViewImp::Request - RefreshScreen i(%d)", i);
       
   340             iHgGrid->RefreshScreen(i);
       
   341             }
       
   342         }
       
   343     }
       
   344 // ---------------------------------------------------------------------------
       
   345 // SetIcons
       
   346 // ---------------------------------------------------------------------------
       
   347 //  
       
   348 void CGlxFetcherContainer::SetIconsL(TInt aIndex)
       
   349     {
       
   350     TRACER("CGlxFetcherContainer::SetIconsL()");
       
   351     const TGlxMedia& item = iMediaList->Item(aIndex);
       
   352     TMPXAttribute thumbnailAttribute(KGlxMediaIdThumbnail, 
       
   353             GlxFullThumbnailAttributeId( ETrue,  iGridIconSize.iWidth, 
       
   354                     iGridIconSize.iHeight ) );
       
   355 
       
   356     TFileName resFile(KDC_APP_BITMAP_DIR);
       
   357     resFile.Append(KGlxIconsFilename);
       
   358     TIconInfo icon;
       
   359     TInt tnError = GlxErrorManager::HasAttributeErrorL(
       
   360             item.Properties(), KGlxMediaIdThumbnail );
       
   361 
       
   362     const CGlxThumbnailAttribute* value = item.ThumbnailAttribute( thumbnailAttribute );
       
   363     if (value)
       
   364         {
       
   365         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   366         bitmap->Duplicate( value->iBitmap->Handle());
       
   367         iHgGrid->ItemL(aIndex).SetIcon(CGulIcon::NewL(bitmap));
       
   368         GLX_LOG_INFO1("### CGlxGridViewImp::Request value-Index is %d",aIndex);
       
   369         }
       
   370     else if (item.GetIconInfo(icon))
       
   371         {
       
   372         GLX_LOG_INFO1("CGlxGridViewImp::Request - icon(%d)", aIndex);
       
   373         CFbsBitmap* bitmap = AknIconUtils::CreateIconL(icon.bmpfile, icon.bitmapId);
       
   374         AknIconUtils::SetSize(bitmap, CHgGrid::PreferredImageSize());
       
   375         iHgGrid->ItemL(aIndex).SetIcon(CGulIcon::NewL(bitmap));
       
   376         GLX_LOG_INFO1("### CGlxGridViewImp::Request GetIconInfo-Index is %d",aIndex);
       
   377         }
       
   378     else if ( KErrNone != tnError && KErrNotSupported != tnError )
       
   379         {
       
   380         GLX_LOG_INFO2("CGlxGridViewImp::Request - image_corrupted tnError(%d), "
       
   381                 "i(%d)", tnError, aIndex);
       
   382         CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   383                 EMbmGlxiconsQgn_prop_image_corrupted);
       
   384         AknIconUtils::SetSize(bitmap, CHgGrid::PreferredImageSize());
       
   385         iHgGrid->ItemL(aIndex).SetIcon(CGulIcon::NewL(bitmap));
       
   386         }
       
   387 
       
   388     if (item.IsDrmProtected())
       
   389         {
       
   390         const TDesC& uri = item.Uri();
       
   391         if( uri.Length() > 0)
       
   392             {
       
   393             if(iDRMUtility->IsForwardLockedL(uri))
       
   394                 {
       
   395                 iHgGrid->ItemL(aIndex).SetFlags(
       
   396                         CHgItem::EHgItemFlagsDrmRightsValid);
       
   397                 }
       
   398             else 
       
   399                 {
       
   400                 TMPXGeneralCategory  cat = item.Category();                  
       
   401                 TBool checkViewRights = (cat==EMPXImage);
       
   402 
       
   403                 if(iDRMUtility->CheckOpenRightsL(uri, checkViewRights))
       
   404                     {
       
   405                     iHgGrid->ItemL(aIndex).SetFlags(
       
   406                             CHgItem::EHgItemFlagsDrmRightsValid);
       
   407                     }
       
   408                 else
       
   409                     {
       
   410                     iHgGrid->ItemL(aIndex).SetFlags(
       
   411                             CHgItem::EHgItemFlagsDrmRightsExpired);
       
   412                     }
       
   413                 }
       
   414             }
       
   415         }
       
   416     TTime time(0);
       
   417     if (item.GetDate(time))
       
   418         {
       
   419         iHgGrid->ItemL(aIndex).SetTime(time);
       
   420         }
       
   421 
       
   422     if (item.Category() == EMPXVideo)
       
   423         {
       
   424         iHgGrid->ItemL(aIndex).SetFlags(CHgItem::EHgItemFlagsVideo);
       
   425         }
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // Release
       
   430 // ---------------------------------------------------------------------------
       
   431 //  
       
   432 void CGlxFetcherContainer::Release(TInt /*aReleaseStart*/, TInt /*aReleaseEnd*/)
       
   433     {
       
   434     TRACER("CGlxFetcherContainer::Release()");
       
   435     // This has to do nothing on default
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // HandleSelect
       
   440 // ---------------------------------------------------------------------------
       
   441 //  
       
   442 void CGlxFetcherContainer::HandleSelectL( TInt aIndex )
       
   443     {
       
   444     TRACER("CGlxGridViewImp::HandleSelect()");
       
   445     // Make sure that the Selection Index is inside medialist count
       
   446     if (aIndex <iMediaList->Count() && aIndex >=0)
       
   447         {
       
   448         // Setting the focus of the medialist
       
   449         iMediaList->SetFocusL(NGlxListDefs::EAbsolute, aIndex);        
       
   450         }
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // HandleOpen
       
   455 // ---------------------------------------------------------------------------
       
   456 //  
       
   457 void CGlxFetcherContainer::HandleOpenL( TInt aIndex )
       
   458     {
       
   459     TRACER("CGlxGridViewImp::HandleOpen()");
       
   460     // Make sure that the Selection Index is inside medialist count
       
   461     if (aIndex <iMediaList->Count() && aIndex >=0)
       
   462         {
       
   463         //ignore multiple tap events for single selection cases
       
   464         //if file has already been selected
       
   465         if(!iMultiSelectionEnabled && !iIsFileAttached)
       
   466 	        {
       
   467 	        iEventObserver.HandleDoubleTapEventL(EAknSoftkeySelect);
       
   468 	        }
       
   469         }
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // HandleMarkingL
       
   474 // ---------------------------------------------------------------------------
       
   475 //  
       
   476 void CGlxFetcherContainer::HandleMarkingL( TInt aIndex, TBool/* aMarked*/ )
       
   477     {
       
   478     TRACER("CGlxGridViewImp::HandleMarkingL()");
       
   479     HandleMultipleMarkingL(aIndex);
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------------------------
       
   483 // HandleMultipleMarkingL
       
   484 // ---------------------------------------------------------------------------
       
   485 //  
       
   486 void CGlxFetcherContainer::HandleMultipleMarkingL(TInt aIndex )
       
   487     {
       
   488     TRACER("CGlxGridViewImp::HandleMultipleMarkingL()");
       
   489     if(iMediaList->IsSelected(aIndex))
       
   490         {
       
   491         if(iHgGrid)
       
   492             {
       
   493             if(iMultiSelectionEnabled)
       
   494 	            {
       
   495 	            iFetcherCommandHandler->DoExecuteL(EAknCmdUnmark, MediaList());	
       
   496 	            }
       
   497             }
       
   498         }
       
   499     else
       
   500         {
       
   501         if(iHgGrid)
       
   502             {
       
   503             if(iUiUtility->IsPenSupported())
       
   504                 {
       
   505                 //This is required for the touch because here when we select
       
   506                 //we do not get the event for mark in processcommandL 
       
   507                 //of FetcherDialog. So we explicitly send the event to ourselves 
       
   508                 //to mark the item.
       
   509                 if (!iMultipleMarkNotStarted)
       
   510                     {
       
   511                     DoExecuteL(EAknCmdMark);
       
   512                     }
       
   513                 }
       
   514             if(iMultiSelectionEnabled)
       
   515 	            {
       
   516 	            iFetcherCommandHandler->DoExecuteL(EAknCmdMark, MediaList());	
       
   517 	            }            	
       
   518             }
       
   519         }
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // DoExecuteL()
       
   524 // ---------------------------------------------------------------------------
       
   525 TBool CGlxFetcherContainer::DoExecuteL(TInt aCommandId)
       
   526     {
       
   527     TRACER("CGlxFetcherContainer::DoExecuteL");
       
   528 
       
   529     TBool retVal = EFalse;
       
   530     /*
       
   531     * fix for  EBYU-7UV4MW-- when user presses selection key
       
   532     * very fast that time if hggrid is not created and we are trying to 
       
   533     * access hghgrid for marking it is giving crash. So need to chk if 
       
   534     * hggrid id created or not.same will also happen if media list is 
       
   535     * not created
       
   536     */
       
   537     if(!iHgGrid || !iMediaList)
       
   538     	{
       
   539     	return retVal;
       
   540     	}
       
   541     	
       
   542     TInt focusIndex = iMediaList->FocusIndex();
       
   543     
       
   544     switch(aCommandId)
       
   545         {
       
   546         case EAknCmdMark:
       
   547         case EAknMarkAll:
       
   548         case EGlxCmdStartMultipleMarking:
       
   549             {
       
   550             //@ fix for ELWU-7RA7NX 
       
   551             if (iMultiSelectionEnabled )
       
   552                 {
       
   553                 if (!iMultipleMarkNotStarted)
       
   554                 	{
       
   555                 	//This will start multiple marking and not mark any items
       
   556 					iFetcherCommandHandler->DoExecuteL(EAknCmdMark, MediaList());
       
   557                 	iMultipleMarkNotStarted = ETrue ;
       
   558                 	}
       
   559 	    		//@ Mark in HG Grid
       
   560 				iHgGrid->Mark(focusIndex);
       
   561 				iHgGrid->RefreshScreen(focusIndex);
       
   562 				
       
   563                 }
       
   564             retVal = ETrue;
       
   565             break;
       
   566             }
       
   567         case EAknCmdUnmark:            
       
   568         case EAknUnmarkAll:   
       
   569             {
       
   570             //@ fix for ELWU-7RA7NX 
       
   571             if (iMultiSelectionEnabled)
       
   572                 {
       
   573                 //@ UnMark in HG Grid
       
   574                 iHgGrid->UnMark(focusIndex);
       
   575                 iHgGrid->RefreshScreen(focusIndex);
       
   576                 }
       
   577 
       
   578             if( iMediaList->SelectionCount() <= 0 )
       
   579                 {
       
   580                 iMultipleMarkNotStarted = EFalse;
       
   581                 }            
       
   582             retVal = ETrue;
       
   583             break;
       
   584             }
       
   585         case EGlxCmdEndMultipleMarking:
       
   586             {
       
   587             iHgGrid->ClearFlags( CHgScroller::EHgScrollerSelectionMode );                
       
   588             iFetcherCommandHandler->DoExecuteL(aCommandId, MediaList());              
       
   589             } 
       
   590             retVal = ETrue;
       
   591             break;
       
   592         default:
       
   593             break;
       
   594         }    
       
   595     return retVal;
       
   596     }
       
   597 
       
   598 
       
   599 // -----------------------------------------------------------------------------
       
   600 // Retrieve Uris
       
   601 // -----------------------------------------------------------------------------
       
   602 TBool CGlxFetcherContainer::RetrieveUrisL( CDesCArray& aSelectedFiles, TBool& aFetchUri)
       
   603     {
       
   604     TRACER("CGlxFetcherContainer::RetrieveUrisL");
       
   605     // check that the medialist is really constructed
       
   606     // we can get this call while MGlxMediaList::InstanceL has not yet returned
       
   607     // as it starts a new asynch wait loop and during that it is possible 
       
   608     // to send key events to the dialog.
       
   609     if( !iMediaList || !iHgGrid )
       
   610         {
       
   611         aFetchUri = EFalse;
       
   612 		iIsFileAttached = EFalse;
       
   613         return iIsFileAttached;
       
   614         }
       
   615     //To Block call to HandleDoubleTapEventL() when control is in RetrieveUrisL()
       
   616     iIsFileAttached = ETrue;
       
   617     GLX_LOG_INFO1("CGlxFetcherContainer::RetrieveUrisL() Medialist count is %d",
       
   618                 iMediaList->Count());
       
   619     TGlxSelectionIterator iterator;
       
   620 	CGlxAttributeContext* context = new (ELeave) CGlxAttributeContext( &iterator );
       
   621 	CleanupStack::PushL( context );
       
   622 	
       
   623 	// Configure the context to retrieve the URI attribute
       
   624 	context->AddAttributeL( KMPXMediaGeneralUri );
       
   625 	
       
   626 	iMediaList->AddContextL( context, KGlxFetchContextPriorityBlocking );
       
   627 
       
   628 	// Create remover object to remove the context from the list
       
   629 	// even if a leave occurs
       
   630 	TGlxFetchContextRemover remover( context, *iMediaList );
       
   631 	// put to cleanupstack as cleanupstack is emptied before stack objects
       
   632 	// are deleted
       
   633 	CleanupClosePushL( remover );
       
   634     // block until all content retrieved (shows progress note)
       
   635     TInt error = GlxAttributeRetriever::RetrieveL( *context, 
       
   636             *iMediaList, ETrue ) ;
       
   637     GLX_LOG_INFO1("CGlxFetcherContainer::RetrieveUrisL() Error %d", error);
       
   638     // context off the list
       
   639     CleanupStack::PopAndDestroy( &remover );
       
   640     GLX_LOG_INFO1("CGlxFetcherContainer::RetrieveUrisL() Medialist count after GlxAttributeRetriever is %d",
       
   641                 iMediaList->Count());
       
   642     
       
   643     // if error or if medialist count is 0 then do not proceed further with the iterator.
       
   644     if (error == KErrNone && iMediaList->Count() !=0)
       
   645         {
       
   646         GLX_LOG_INFO1("CGlxFetcherContainer::RetrieveUrisL() inside loop and medialist count is %d",
       
   647                 iMediaList->Count());
       
   648         // Add all selected items to client's array
       
   649         iterator.SetToFirst( iMediaList );
       
   650         TInt index = KErrNotFound;
       
   651         while ( KErrNotFound != (index = iterator++) )
       
   652             {
       
   653             const TDesC& uri = iMediaList->Item( index ).Uri();
       
   654             if( uri != KNullDesC )
       
   655                 {
       
   656                 aSelectedFiles.AppendL( uri );
       
   657                 iIsFileAttached = ETrue;
       
   658                 }   
       
   659             else
       
   660                 {
       
   661                 iIsFileAttached = EFalse;
       
   662                 }
       
   663             }
       
   664         }
       
   665     CleanupStack::PopAndDestroy( context );
       
   666     // Set the Fetch uri value as false, as it could be a drm image and calling 
       
   667     // application might not allow that to be selected, thus fetcher could be launched again.
       
   668     aFetchUri = EFalse;
       
   669 	return iIsFileAttached;
       
   670     }
       
   671 
       
   672 //-----------------------------------------------------------------------------
       
   673 // CGlxFetcherContainer::OfferKeyEventL
       
   674 //-----------------------------------------------------------------------------
       
   675 TKeyResponse CGlxFetcherContainer::OfferKeyEventL(
       
   676         const TKeyEvent& aKeyEvent,TEventCode aType )
       
   677     {
       
   678     TRACER("CGlxFetcherContainer::OfferKeyEventL");
       
   679 	return iHgGrid->OfferKeyEventL(aKeyEvent,aType);
       
   680     }
       
   681     
       
   682 // ---------------------------------------------------------------------------
       
   683 // SetTitleL()
       
   684 // ---------------------------------------------------------------------------
       
   685 void CGlxFetcherContainer::SetTitleL(const TDesC& aTitleText)
       
   686     {
       
   687     TRACER("CGlxFetcherContainer::SetTitleL");
       
   688     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   689     CleanupStack::PushL(statusPane);
       
   690     CAknTitlePane* titlePane = ( CAknTitlePane* )statusPane->ControlL(
       
   691             TUid::Uid( EEikStatusPaneUidTitle ));       
       
   692     CleanupStack::PushL(titlePane);
       
   693     // To Store Title and to make sure, Previous Title is only stored once
       
   694     if (!iPreviousTitle)
       
   695         {
       
   696         iPreviousTitle = titlePane->Text()->AllocL();    
       
   697         }
       
   698     
       
   699     // Set the required Title
       
   700     titlePane->SetTextL( aTitleText );
       
   701     CleanupStack::Pop(titlePane);
       
   702     CleanupStack::Pop(statusPane);
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------------------------
       
   706 // SetPreviousTitleL()
       
   707 // ---------------------------------------------------------------------------
       
   708 void CGlxFetcherContainer::SetPreviousTitleL()
       
   709     {
       
   710     TRACER("CGlxFetcherContainer::SetPreviousTitleL");
       
   711     CEikStatusPane* prevStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   712     CleanupStack::PushL(prevStatusPane);
       
   713     CAknTitlePane* prevTitlePane = ( CAknTitlePane* )prevStatusPane->ControlL(
       
   714             TUid::Uid( EEikStatusPaneUidTitle ));       
       
   715     CleanupStack::PushL(prevTitlePane);
       
   716     
       
   717     // Restore the Title back of the Calling Application
       
   718     prevTitlePane->SetTextL( *iPreviousTitle );
       
   719     CleanupStack::Pop(prevTitlePane);
       
   720     CleanupStack::Pop(prevStatusPane);
       
   721     }
       
   722 
       
   723 // -----------------------------------------------------------------------------
       
   724 // UpdateTitle
       
   725 // -----------------------------------------------------------------------------
       
   726 //
       
   727 void CGlxFetcherContainer::UpdateTitleL()
       
   728     {
       
   729     TRACER("CGlxFetcherContainer::UpdateTitleL");
       
   730     SetTitleL( iTitle);
       
   731     }
       
   732  
       
   733 // -----------------------------------------------------------------------------
       
   734 // MediaList
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 MGlxMediaList& CGlxFetcherContainer::MediaList()
       
   738     {
       
   739     TRACER("CGlxFetcherContainer::MediaList");
       
   740     return *iMediaList;
       
   741     }
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // HandleSizeChange
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 void CGlxFetcherContainer::HandleSizeChangeL ( )
       
   748     {
       
   749     TRACER("CGlxFetcherContainer::HandleSizeChangeL");
       
   750     SetTitleL(iTitle);
       
   751     TRect rect;
       
   752     if(iHgGrid)
       
   753         {
       
   754         AknLayoutUtils::LayoutMetricsRect (AknLayoutUtils::EMainPane, rect);
       
   755         iHgGrid->InitScreenL(rect);
       
   756         }
       
   757     if ( iBgContext )
       
   758         {
       
   759         AknLayoutUtils::LayoutMetricsRect (AknLayoutUtils::EApplicationWindow, rect);
       
   760         iBgContext->SetRect( rect );
       
   761         }
       
   762     }
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // MopSupplyObject
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 TTypeUid::Ptr CGlxFetcherContainer::MopSupplyObject(TTypeUid aId)
       
   769     {
       
   770     TRACER("CGlxFetcherContainer::MopSupplyObject");
       
   771     if (iBgContext)
       
   772         {
       
   773         return MAknsControlContext::SupplyMopObject(aId, iBgContext );
       
   774         }
       
   775     return CCoeControl::MopSupplyObject(aId);
       
   776     }
       
   777 
       
   778 //END OF FILE