photosgallery/viewframework/views/gridview/src/glxgridviewcontainer.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
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:    Implementation of Grid view control
       
    15  *
       
    16  */
       
    17 #include <AknUtils.h>                               	// For AknLayoutUtils to calculate rect
       
    18 #include <glxtracer.h>
       
    19 #include <StringLoader.h>
       
    20 #include <AknsBasicBackgroundControlContext.h>
       
    21 #include <caf/caferr.h>
       
    22 #include <featmgr.h>		                            // Feature Manager
       
    23 
       
    24 // Ganes Headers
       
    25 #include <gulicon.h>                                    // Gul Icons
       
    26 #include <ganes/HgItem.h>                               // HG Items
       
    27 #include <ganes/HgGrid.h>                               // Hg Grid Widget
       
    28 
       
    29 // Framework
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include <glxcollectionplugindownloads.hrh>
       
    32 #include <glxcommandhandlers.hrh>                       // For EGlxCmdFullScreenBack
       
    33 #include <glxcollectionpluginall.hrh> 	            	// All item collection plugin id
       
    34 
       
    35 
       
    36 #include <glxnavigationalstate.h>                       // For Navigational State
       
    37 #include <mglxmedialist.h>				            	// MGlxMediaList, CMPXCollectionPath
       
    38 #include <glxuiutility.h>                               // For UiUtility instance
       
    39 #include <glxdrmutility.h>                              // DRM utility class to provide DRM-related functionality
       
    40 #include <glxerrormanager.h>                            // For CGlxErrormanager
       
    41 #include <glxthumbnailattributeinfo.h>                  // KGlxMediaIdThumbnail
       
    42 #include <glxgridviewdata.rsg>                          // Gridview resource
       
    43 #include <glxicons.mbg>                                 // For Corrupted and not created icons
       
    44 
       
    45 #include "glxgridviewcontainer.h"
       
    46 #include "glxgridviewimp.h"
       
    47 #include "glxgridviewmlobserver.h"                      // medialist observer for Hg Grid
       
    48 
       
    49 const TInt KNoOfPages(3);
       
    50 const TInt KBufferTresholdSize(3); 						// in rows
       
    51 const TInt KMaxNoOfSeamlessLinks(2);
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // Two-phased constructor.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CGlxGridViewContainer* CGlxGridViewContainer::NewL(MGlxMediaList *aMediaList,
       
    60 														CGlxUiUtility* aUiUtility,
       
    61 																	MGlxGridEventObserver& aObserver)
       
    62 	{
       
    63 	TRACER("CGlxGridViewContainer::NewL");
       
    64 	CGlxGridViewContainer* self = CGlxGridViewContainer::NewLC(aMediaList,aUiUtility,aObserver) ;
       
    65 	CleanupStack::Pop(self) ;
       
    66 	return self ;
       
    67 	}
       
    68 	
       
    69 // ---------------------------------------------------------------------------
       
    70 // Two-phased constructor.
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CGlxGridViewContainer* CGlxGridViewContainer::NewLC(MGlxMediaList *aMediaList,
       
    74 														CGlxUiUtility* aUiUtility,
       
    75 																	MGlxGridEventObserver& aObserver)
       
    76 	{
       
    77 	TRACER("CGlxGridViewContainer::NewLC");
       
    78 	CGlxGridViewContainer* self = new(ELeave) CGlxGridViewContainer(aMediaList,aUiUtility,aObserver);
       
    79 	CleanupStack::PushL(self ) ;
       
    80 	self->ConstructL() ;
       
    81 	return self ;
       
    82 	}
       
    83 	
       
    84 // ---------------------------------------------------------------------------
       
    85 // Destructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CGlxGridViewContainer::~CGlxGridViewContainer()
       
    89 	{
       
    90 	TRACER("CGlxGridViewContainer::~CGlxGridViewContainer");
       
    91 	if(iBgContext)
       
    92 		{
       
    93 		delete iBgContext;	
       
    94 		}
       
    95 	if(iDRMUtility)
       
    96 		{
       
    97 		iDRMUtility->Close();
       
    98 		}
       
    99 	if (iGlxGridMLObserver)
       
   100 		{
       
   101 		delete iGlxGridMLObserver;
       
   102 		iGlxGridMLObserver = NULL;
       
   103 		}
       
   104 	if (iMediaList)
       
   105 		{
       
   106 		iMediaList->RemoveContext(iThumbnailContext);
       
   107 		delete iThumbnailContext;
       
   108 		}
       
   109 	if(iUiUtility->IsPenSupported())
       
   110 		{
       
   111 		RemoveFSThumbnailContext();
       
   112 		}
       
   113 	if(iNavigationalstate)
       
   114 		{
       
   115 		iNavigationalstate->Close();
       
   116 		}
       
   117 	if (iHgGrid)
       
   118 		{
       
   119 		delete iHgGrid;
       
   120 		iHgGrid = NULL;
       
   121 		}
       
   122 	//reset the flag
       
   123 	iBackwardActivation = EFalse;
       
   124 	}
       
   125 	
       
   126 // ---------------------------------------------------------------------------
       
   127 // C++ default constructor can NOT contain any code, that
       
   128 // might leave.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CGlxGridViewContainer::CGlxGridViewContainer(MGlxMediaList *aMediaList,CGlxUiUtility* aUiUtility,
       
   132 																MGlxGridEventObserver& aObserver)
       
   133 					: iMediaList(aMediaList),iUiUtility(aUiUtility),iGlxGridViewObserver(aObserver)
       
   134 		{
       
   135 		TRACER("CGlxGridViewContainer::CGlxGridViewContainer");
       
   136 		}
       
   137 	
       
   138 // ---------------------------------------------------------------------------
       
   139 // Symbian 2nd phase constructor can leave.
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CGlxGridViewContainer::ConstructL()
       
   143 	{
       
   144 	TRACER("CGlxGridViewContainer::ConstructL()");
       
   145 
       
   146 	//create the container window.
       
   147 	CreateWindowL();
       
   148 
       
   149 	// Making the default FSActivation as false
       
   150 	iFullscreenViewActivated = EFalse;
       
   151 
       
   152 	iNavigationalstate = CGlxNavigationalState::InstanceL();
       
   153 
       
   154 	//check the navigational direction
       
   155 	if (iUiUtility->ViewNavigationDirection ()== EGlxNavigationBackwards)
       
   156 		{
       
   157 		iBackwardActivation = ETrue;
       
   158 		}
       
   159 
       
   160 	// making the default mode of marking as false
       
   161 	iMultipleMarkingActive = EFalse;
       
   162 
       
   163 	iGridIconSize = iUiUtility->GetGridIconSize();
       
   164 
       
   165 	iItemsPerPage = iUiUtility->VisibleItemsInPageGranularityL();
       
   166 
       
   167 	// For DRM Utility
       
   168 	iDRMUtility = CGlxDRMUtility::InstanceL();
       
   169 
       
   170 	// background Skin Context for the skin support
       
   171 	TRect apRect = iEikonEnv->EikAppUi()->ApplicationRect();
       
   172 	iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
   173 			KAknsIIDQsnBgScreen,apRect,ETrue);
       
   174 
       
   175 	iQualityTnAttrib = TMPXAttribute (KGlxMediaIdThumbnail,
       
   176 			GlxFullThumbnailAttributeId( ETrue,  iGridIconSize.iWidth,
       
   177 					iGridIconSize.iHeight ) );
       
   178 
       
   179 	iSpeedTnAttrib = TMPXAttribute (KGlxMediaIdThumbnail,
       
   180 			GlxFullThumbnailAttributeId( EFalse,  iGridIconSize.iWidth,
       
   181 					iGridIconSize.iHeight ) );
       
   182 	CreateGridL();
       
   183 	}
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // From OfferKeyEventL
       
   187 // Default implementation,
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TKeyResponse CGlxGridViewContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
       
   191 	{
       
   192 	TRACER("CGlxGridViewContainer::OfferKeyEventL()");
       
   193 	TKeyResponse response = EKeyWasNotConsumed;
       
   194 	CCoeControl::OfferKeyEventL(aKeyEvent,aType);
       
   195 	if(aType == EEventKey)
       
   196 		{
       
   197 		switch(aKeyEvent.iCode)
       
   198 			{
       
   199 			case EKeyBackspace:
       
   200 				{
       
   201 				iGlxGridViewObserver.HandleGridEventsL(EGlxCmdDelete);
       
   202 				response = EKeyWasConsumed;
       
   203 				break;
       
   204 				}
       
   205 			default:
       
   206 				response = EKeyWasNotConsumed;
       
   207 				break;
       
   208 			}
       
   209 		}
       
   210 	
       
   211 	//send the unconsumed events from grid container to hg-grid to handle related key events
       
   212 	if(response == EKeyWasNotConsumed)
       
   213 		{
       
   214 		response = iHgGrid->OfferKeyEventL(aKeyEvent,aType);
       
   215 		}
       
   216 	return response ;
       
   217 	}
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // Release
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void CGlxGridViewContainer::Release(TInt /*aBufferStart*/, TInt/* aBufferEnd*/)
       
   224 	{
       
   225 	TRACER("CGlxGridViewContainer::Release()");
       
   226 	// This has to do nothing on default
       
   227 	}
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // Request
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CGlxGridViewContainer::Request(TInt aRequestStart, TInt aRequestEnd,
       
   234 		THgScrollDirection /*aDirection*/)
       
   235 	{
       
   236 	TRACER("CGlxGridViewContainer::Request()");
       
   237 	RequestL(aRequestStart, aRequestEnd);
       
   238 	}
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // RequestL
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CGlxGridViewContainer::RequestL(TInt aRequestStart, TInt aRequestEnd)
       
   245 	{
       
   246 	TRACER("CGlxGridViewContainer::RequestL()");
       
   247 	TInt visIndex = 0;
       
   248 	TInt mediaCount = iMediaList->Count();
       
   249 	aRequestStart = (aRequestStart<0 ? 0 : aRequestStart) ;
       
   250 	aRequestEnd = (aRequestEnd>=mediaCount? (mediaCount-1) : aRequestEnd);
       
   251 
       
   252 	GLX_LOG_INFO3("CGlxGridViewContainer::RequestL - aRequestStart(%d), "
       
   253 			"aRequestEnd(%d), FirstIndexOnScreen(%d)", aRequestStart,
       
   254 			aRequestEnd, iHgGrid->FirstIndexOnScreen());
       
   255 	GLX_LOG_INFO1("CGlxGridViewContainer::Request - mediaCount(%d)",mediaCount);
       
   256 
       
   257 	visIndex = iHgGrid->FirstIndexOnScreen();
       
   258 
       
   259 	if(visIndex >= mediaCount )
       
   260 		{
       
   261 		visIndex = mediaCount-1;
       
   262 		}
       
   263 	if(visIndex<0 || mediaCount<=0)
       
   264 		{
       
   265 		visIndex = 0;
       
   266 		}
       
   267 	GLX_LOG_INFO1("CGlxGridViewContainer::Request - SetVisibleWindowIndex"
       
   268 			" visIndex(%d)", visIndex);
       
   269 	iMediaList->SetVisibleWindowIndexL(visIndex);
       
   270 
       
   271 	if(mediaCount>0)
       
   272 		{
       
   273 		//Set the icons and refresh the screen only when the items are present
       
   274 		for (TInt i=aRequestStart; i<= aRequestEnd; i++)
       
   275 			{
       
   276 			SetIconsL(i);
       
   277 			TInt firstIndex = iHgGrid->FirstIndexOnScreen();
       
   278 			firstIndex = (firstIndex<0 ? 0 : firstIndex);
       
   279 			TInt lastOnScreen = firstIndex + iHgGrid->ItemsOnScreen() - 1;
       
   280 			lastOnScreen = (lastOnScreen >mediaCount-1? mediaCount-1:lastOnScreen);
       
   281 			if (i == lastOnScreen || (i == aRequestEnd && i < lastOnScreen))
       
   282 				{
       
   283 				if (HasRelevantThumbnail(i))
       
   284 					{
       
   285 					GLX_LOG_INFO1("CGlxGridViewContainer::Request - RefreshScreen"
       
   286 							"  lastOnScreen / aRequestEnd i(%d)", i);
       
   287 					iHgGrid->RefreshScreen(i);
       
   288 					}
       
   289 				}
       
   290 			}
       
   291 		}
       
   292 
       
   293 	if (iDownloadsPlugin && aRequestStart == KMaxNoOfSeamlessLinks)
       
   294 		{
       
   295 		SetDownloadLinksTimeL();
       
   296 		}
       
   297 	}
       
   298 
       
   299 // ----------------------------------------------------------------------------
       
   300 // HasRelevantThumbnail
       
   301 // ----------------------------------------------------------------------------
       
   302 //
       
   303 TBool CGlxGridViewContainer::HasRelevantThumbnail(TInt aIndex)
       
   304 	{
       
   305 	TRACER("CGlxGridViewContainer::HasRelevantThumbnail()");
       
   306 	const TGlxMedia& item = iMediaList->Item( aIndex );
       
   307 	const CGlxThumbnailAttribute* qualityTn = item.ThumbnailAttribute(
       
   308 			iQualityTnAttrib );
       
   309 	const CGlxThumbnailAttribute* speedTn = item.ThumbnailAttribute(
       
   310 			iSpeedTnAttrib );
       
   311 	if ( qualityTn || speedTn )
       
   312 		{
       
   313 		GLX_LOG_INFO("CGlxGridViewContainer::HasRelevantThumbnail() - TN avail");
       
   314 		return ETrue;
       
   315 		}
       
   316 	return EFalse;
       
   317 	}
       
   318     
       
   319 // ---------------------------------------------------------------------------
       
   320 // HandleSelectL
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 void CGlxGridViewContainer::HandleSelectL( TInt aIndex )
       
   324 	{
       
   325     TRACER("CGlxGridViewContainer::HandleSelectL()");
       
   326 	// Map the index of HG Grid and Medialist
       
   327 	// Make sure that the Selection Index is inside medialist count
       
   328 	if (aIndex <iMediaList->Count() && aIndex >=0)
       
   329 		{
       
   330 		iMediaList->SetFocusL(NGlxListDefs::EAbsolute, aIndex);
       
   331 		}
       
   332 	}
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // HandleOpenL
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 void CGlxGridViewContainer::HandleOpenL( TInt aIndex )
       
   339 	{
       
   340     TRACER("CGlxGridViewContainer::HandleOpenL()");
       
   341 
       
   342 	// Make sure that the Selection Index is inside medialist count
       
   343 	if (aIndex <iMediaList->Count() && aIndex >=0)
       
   344 		{
       
   345 		if (!(iHgGrid->Flags() && CHgScroller::EHgScrollerSelectionMode))
       
   346 			{
       
   347 			// If not in marking mode, then open FS view
       
   348 			iUiUtility->SetViewNavigationDirection(EGlxNavigationForwards);
       
   349 			//Navigate to the next view
       
   350 			//Item is selected, go to next view
       
   351 			HandleEnterKeyEventL((TInt)EAknCmdOpen);
       
   352 			}
       
   353 		}
       
   354 	}
       
   355     
       
   356 // -----------------------------------------------------------------------------
       
   357 // HandleEnterKeyEventL
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CGlxGridViewContainer::HandleEnterKeyEventL(TInt aCommand)
       
   361 	{
       
   362 	TRACER("CGlxGridViewContainer::HandleEnterKeyEventL()");
       
   363 	HandleViewCommandL(aCommand);
       
   364 	}
       
   365     
       
   366 // ---------------------------------------------------------------------------
       
   367 // HandleMarkingL
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CGlxGridViewContainer::HandleMarkingL( TInt aIndex, TBool aMarked )
       
   371 	{
       
   372 	TRACER("CGlxGridViewContainer::HandleMarkingL()");
       
   373 	HandleMultipleMarkingL(aIndex,aMarked);
       
   374 	}
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CreateHgGridWidgetL
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CGlxGridViewContainer::CreateHgGridWidgetL()
       
   381 	{
       
   382 	TRACER("CGlxGridViewContainer::CreateHgGridWidgetL()");
       
   383 
       
   384 	TInt mediaCount = iMediaList->Count();
       
   385 	if (!iHgGrid)
       
   386 		{
       
   387 		TFileName resFile(KDC_APP_BITMAP_DIR);
       
   388 		resFile.Append(KGlxIconsFilename);
       
   389 		CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   390 				EMbmGlxiconsQgn_prop_image_notcreated);
       
   391 		AknIconUtils::SetSize(bitmap, CHgGrid::PreferredImageSize());
       
   392 		TRect rect = iEikonEnv->EikAppUi()->ClientRect();
       
   393 		// Create Hg grid object
       
   394 		iHgGrid = CHgGrid::NewL (rect,mediaCount,CGulIcon::NewL(bitmap));
       
   395 		}
       
   396 	if (mediaCount)
       
   397 		{
       
   398 		// Mediacount would give the no of static items present and
       
   399 		// coz medialist doesnt have all the item at
       
   400 		// this stage, it will focus index for only download icons.
       
   401 		// For other grid views, we have to set focus elsewhere
       
   402 		for (TInt i=0; i<mediaCount; i++)
       
   403 			{
       
   404 			const TGlxMedia& item = iMediaList->Item(i);
       
   405 			TIconInfo icon;
       
   406 			if (item.GetIconInfo(icon) )
       
   407 				{
       
   408 				CFbsBitmap* bitmap = AknIconUtils::CreateIconL(icon.bmpfile, icon.bitmapId);
       
   409 				AknIconUtils::SetSize(bitmap, CHgGrid::PreferredImageSize());
       
   410 				iHgGrid->ItemL(i).SetIcon(CGulIcon::NewL(bitmap));
       
   411 				}
       
   412 			}
       
   413 		// Setting the initial focus
       
   414 		iHgGrid->SetSelectedIndex(iMediaList->FocusIndex());
       
   415 		}
       
   416 	// Setting to MopParent to update background skin
       
   417 	iHgGrid->SetMopParent(this);
       
   418 	// Setting Selction observer for getting callback on key event change
       
   419 	iHgGrid->SetSelectionObserver(*this);
       
   420 
       
   421 	// This Displays the scrollbar at the opening of the Grid view
       
   422 	iHgGrid->SetScrollBarTypeL(CHgScroller::EHgScrollerTimeStrip );
       
   423 
       
   424 	// Enable Buffer support
       
   425 	iHgGrid->EnableScrollBufferL(*this, (KNoOfPages * iItemsPerPage),
       
   426 			KBufferTresholdSize);
       
   427 
       
   428 	// Enable Marking support
       
   429 	iHgGrid->SetMarkingObserver(*this);
       
   430 	iHgGrid->SetFocus(ETrue);
       
   431 	/*
       
   432 	 * note: don't push hggrid to the control stack
       
   433 	 */
       
   434 	}
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 // CreateGridL
       
   438 // ---------------------------------------------------------------------------
       
   439 //
       
   440 void CGlxGridViewContainer::CreateGridL()
       
   441 	{
       
   442 	TRACER("CGlxGridViewContainer::CreateGridL()");
       
   443 	// Set the Grid thumbnail context and iterator
       
   444 	SetGridThumbnailContextL();
       
   445 	// Create HG Grid widget
       
   446 	CreateHgGridWidgetL();
       
   447 	// Create an observer and pass MediaList and HGGrid objects
       
   448 	CreateGridMediaListObserverL();
       
   449 	// Create Grid once again after returning from FS as No calls for handleItem added.
       
   450 	CreateGridAfterFSDeactivatedL();
       
   451 	if (iUiUtility->IsPenSupported())
       
   452 		{
       
   453 		// Fetch fullscreen thumbnails of the focused item with low priority
       
   454 		FetchFSThumbnailL();
       
   455 		}
       
   456 	}
       
   457 	
       
   458 // ---------------------------------------------------------------------------
       
   459 // SetGridThumbnailContextL
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CGlxGridViewContainer::SetGridThumbnailContextL()
       
   463 	{
       
   464 	TRACER("CGlxGridViewContainer::SetGridThumbnailContextL()");
       
   465 	// show static items again
       
   466 	iMediaList->SetStaticItemsEnabled(ETrue);
       
   467 
       
   468 	iThumbnailContext = CGlxThumbnailContext::NewL( &iBlockyIterator ); // set the thumbnail context
       
   469 	iThumbnailContext->SetDefaultSpec( iGridIconSize.iWidth,iGridIconSize.iHeight );
       
   470 	iMediaList->AddContextL(iThumbnailContext, KGlxFetchContextPriorityNormal );
       
   471 
       
   472 	iDownloadsPlugin = EFalse;
       
   473 	CMPXCollectionPath* path = iMediaList->PathLC( NGlxListDefs::EPathParent );
       
   474 	if (path->Id() == KGlxCollectionPluginDownloadsImplementationUid)
       
   475 		{
       
   476 		iDownloadsPlugin = ETrue;
       
   477 		}
       
   478 	CleanupStack::PopAndDestroy(path);
       
   479 	}
       
   480     
       
   481 // ---------------------------------------------------------------------------
       
   482 // CreateGridMediaListObserverL
       
   483 // ---------------------------------------------------------------------------
       
   484 //
       
   485 void CGlxGridViewContainer::CreateGridMediaListObserverL()
       
   486 	{
       
   487 	TRACER("CGlxGridViewContainer::CreateGridMediaListObserverL()");
       
   488 	// Creating the Medialist observer for HG Grid
       
   489 	iGlxGridMLObserver = CGlxGridViewMLObserver::NewL(*iMediaList, iHgGrid);
       
   490 	}
       
   491     
       
   492 // ---------------------------------------------------------------------------
       
   493 // CreateGridAfterFSDeactivatedL
       
   494 // On Returning from the FS View, There is no calls to the handle attribut available,
       
   495 // So repeating the code to view Grid on FS return
       
   496 // ---------------------------------------------------------------------------
       
   497 //
       
   498 void CGlxGridViewContainer::CreateGridAfterFSDeactivatedL()
       
   499 	{
       
   500 	TRACER("CGlxGridViewContainer::CreateGridAfterFSDeactivatedL()");
       
   501 	if (iBackwardActivation)
       
   502 		{
       
   503 		TInt mlCount = iMediaList->Count();
       
   504 		GLX_LOG_INFO1("CreateGridAfterFSDeactivatedL() mlCount=%d", mlCount);
       
   505 
       
   506 		// Setting the Empty Text
       
   507 		HBufC* emptyText =
       
   508 		StringLoader::LoadLC(R_GRID_EMPTY_VIEW_TEXT);
       
   509 		iHgGrid->SetEmptyTextL(*emptyText);
       
   510 		CleanupStack::PopAndDestroy(emptyText);
       
   511 
       
   512 		if (mlCount <= 0)
       
   513 			{
       
   514 			GLX_LOG_INFO("CreateGridAfterFSDeactivatedL() - SetEmptyTextL()");
       
   515 			iHgGrid->DrawNow();
       
   516 			}
       
   517 
       
   518 		TInt focusIndex = iMediaList->FocusIndex();
       
   519 		TSize setSize = CHgGrid::PreferredImageSize();
       
   520 		TFileName resFile(KDC_APP_BITMAP_DIR);
       
   521 		resFile.Append(KGlxIconsFilename);
       
   522 
       
   523 		for (TInt index=0; index<mlCount; index++)
       
   524 			{
       
   525 			SetIconsL(index);
       
   526 			}
       
   527 			
       
   528 		SetDownloadLinksTimeL();
       
   529 
       
   530 		iHgGrid->SetSelectedIndex(focusIndex);
       
   531 		iHgGrid->RefreshScreen(focusIndex);
       
   532 		}
       
   533 	iBackwardActivation = EFalse;
       
   534 	}
       
   535  
       
   536 // ---------------------------------------------------------------------------
       
   537 // SetIconsL
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CGlxGridViewContainer::SetIconsL(TInt index)
       
   541 	{
       
   542 	TRACER("CGlxGridViewContainer::SetIconsL()");
       
   543 	const TGlxMedia& item = iMediaList->Item(index);
       
   544 	TSize setSize = CHgGrid::PreferredImageSize();
       
   545 	TFileName resFile(KDC_APP_BITMAP_DIR);
       
   546 	resFile.Append(KGlxIconsFilename);
       
   547 	TIconInfo icon;
       
   548 	TInt tnError = GlxErrorManager::HasAttributeErrorL(
       
   549 			item.Properties(), KGlxMediaIdThumbnail );
       
   550 
       
   551 	const CGlxThumbnailAttribute* qualityTn = item.ThumbnailAttribute( iQualityTnAttrib );
       
   552 	const CGlxThumbnailAttribute* speedTn = item.ThumbnailAttribute( iSpeedTnAttrib );
       
   553 
       
   554 	if (qualityTn)
       
   555 		{
       
   556 		CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   557 		bitmap->Duplicate( qualityTn->iBitmap->Handle());
       
   558 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   559 		GLX_LOG_INFO1("### CGlxGridViewContainer::SetIconsL qualityTn-Index is %d",index);
       
   560 		}
       
   561 	else if (speedTn)
       
   562 		{
       
   563 		CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   564 		bitmap->Duplicate( speedTn->iBitmap->Handle());
       
   565 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   566 		GLX_LOG_INFO1("### CGlxGridViewContainer::SetIconsL speedTn-Index is %d",index);
       
   567 		}
       
   568 	else if (item.GetIconInfo(icon))
       
   569 		{
       
   570 		GLX_LOG_INFO1("CGlxGridViewContainer::SetIconsL - icon(%d)", index);
       
   571 		CFbsBitmap* bitmap = AknIconUtils::CreateIconL(icon.bmpfile, icon.bitmapId);
       
   572 		AknIconUtils::SetSize(bitmap, setSize);
       
   573 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   574 		GLX_LOG_INFO1("### CGlxGridViewContainer::SetIconsL GetIconInfo-Index is %d",index);
       
   575 		}
       
   576 	else if ( KErrNone != tnError && KErrNotSupported != tnError && KErrCANoRights !=tnError)
       
   577 		{
       
   578 		GLX_LOG_INFO2("CGlxGridViewContainer::SetIconsL - image_corrupted tnError(%d), i(%d)",
       
   579 				tnError, index);
       
   580 		CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   581 				EMbmGlxiconsQgn_prop_image_corrupted);
       
   582 		AknIconUtils::SetSize(bitmap, setSize);
       
   583 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   584 		}
       
   585 	else if (KErrCANoRights ==tnError)
       
   586 		{
       
   587 		/*fix for EABI-7RKHDG
       
   588 		 * this is a safe code added to show default
       
   589 		 * TNM returns -17452 in case SD DRM files
       
   590 		 * this code is added as coming from other view to
       
   591 		 * gridview,it draws broken TN then the callback goes to
       
   592 		 * glxgridviewobserver and redraws a not-created TN.
       
   593 		 * with this part of code that TN swich will not be visible
       
   594 		 */
       
   595 		GLX_LOG_INFO2("CGlxGridViewContainer::SetIconsL - image_defaultthumbnail tnError(%d), i(%d)",
       
   596 				tnError, index);
       
   597 		CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   598 				EMbmGlxiconsQgn_prop_image_notcreated);
       
   599 		AknIconUtils::SetSize(bitmap, setSize);
       
   600 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   601 		}
       
   602 	else if(KErrNotSupported == tnError)
       
   603 		{
       
   604 		GLX_LOG_INFO2("CGlxGridViewContainer::SetIconsL - image_defaultthumbnail tnError(%d), i(%d)",
       
   605 				tnError, index);
       
   606 		CFbsBitmap* bitmap = AknIconUtils::CreateIconL(resFile,
       
   607 				EMbmGlxiconsQgn_prop_image_corrupted);
       
   608 		AknIconUtils::SetSize(bitmap, setSize);
       
   609 		iHgGrid->ItemL(index).SetIcon(CGulIcon::NewL(bitmap));
       
   610 		}
       
   611 
       
   612 	if (item.IsDrmProtected())
       
   613 		{
       
   614 		const TDesC& uri = item.Uri();
       
   615 		if( uri.Length() > 0)
       
   616 			{
       
   617 			if(iDRMUtility->IsForwardLockedL(uri))
       
   618 				{
       
   619 				/*
       
   620 				 * fix for EABI-7RKHDG
       
   621 				 * to show the invalid DRM icon
       
   622 				 */
       
   623 				TMPXGeneralCategory  cat = item.Category();
       
   624 				TBool checkViewRights = (cat==EMPXImage);
       
   625 
       
   626 				if(iDRMUtility->CheckOpenRightsL(uri, checkViewRights))
       
   627 					{
       
   628 					iHgGrid->ItemL(index).SetFlags(CHgItem::EHgItemFlagsDrmRightsValid);
       
   629 					}
       
   630 				else
       
   631 					{
       
   632 					iHgGrid->ItemL(index).SetFlags(CHgItem::EHgItemFlagsDrmRightsExpired);
       
   633 					}
       
   634 				}
       
   635 			else
       
   636 				{
       
   637 				TMPXGeneralCategory  cat = item.Category();
       
   638 				TBool checkViewRights = (cat==EMPXImage);
       
   639 
       
   640 				if(iDRMUtility->CheckOpenRightsL(uri, checkViewRights))
       
   641 					{
       
   642 					iHgGrid->ItemL(index).SetFlags(CHgItem::EHgItemFlagsDrmRightsValid);
       
   643 					}
       
   644 				else
       
   645 					{
       
   646 					iHgGrid->ItemL(index).SetFlags(CHgItem::EHgItemFlagsDrmRightsExpired);
       
   647 					}
       
   648 				}
       
   649 			}
       
   650 		}
       
   651 	TTime time(0);
       
   652 	if (item.GetDate(time))
       
   653 		{
       
   654 		iHgGrid->ItemL(index).SetTime(time);
       
   655 		}
       
   656 
       
   657 	if (item.Category() == EMPXVideo)
       
   658 		{
       
   659 		iHgGrid->ItemL(index).SetFlags(CHgItem::EHgItemFlagsVideo);
       
   660 		}
       
   661 	}
       
   662    
       
   663 // ---------------------------------------------------------------------------
       
   664 // FetchFSThumbnailL
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 void CGlxGridViewContainer::FetchFSThumbnailL()
       
   668 	{
       
   669 	TRACER("CGlxGridViewContainer::FetchFSThumbnailL()");
       
   670 	TSize dispSize = iUiUtility->DisplaySize();
       
   671 	iFsFromFocusOutwardIterator.SetRangeOffsets(0,0);
       
   672 
       
   673 	iFsThumbnailContext = CGlxThumbnailContext::NewL(&iFsFromFocusOutwardIterator);
       
   674 
       
   675 	if (dispSize.iHeight > dispSize.iWidth)
       
   676 		{
       
   677 		iFsThumbnailContext->SetDefaultSpec(dispSize.iHeight, dispSize.iWidth);
       
   678 		}
       
   679 	else
       
   680 		{
       
   681 		iFsThumbnailContext->SetDefaultSpec(dispSize.iWidth, dispSize.iHeight);
       
   682 		}
       
   683 	iMediaList->AddContextL(iFsThumbnailContext, KGlxFetchContextPriorityLow);
       
   684 	}
       
   685 
       
   686 // ---------------------------------------------------------------------------
       
   687 // SetDownloadLinksTimeL
       
   688 // ---------------------------------------------------------------------------
       
   689 //
       
   690 void CGlxGridViewContainer::SetDownloadLinksTimeL()
       
   691 	{
       
   692 	TRACER("CGlxGridViewContainer::SetDownloadLinksTimeL()");
       
   693 	// Sets up TLS, must be done before FeatureManager is used.
       
   694 	FeatureManager::InitializeLibL();
       
   695 	TInt mediaCount = iMediaList->Count();
       
   696 	if (FeatureManager::FeatureSupported(KFeatureIdSeamlessLinks))
       
   697 		{
       
   698 		if (iDownloadsPlugin && mediaCount > iHgGrid->ItemsOnScreen() )
       
   699 			{
       
   700 			TTime time(0);
       
   701 			if (iMediaList->Item(KMaxNoOfSeamlessLinks).GetDate(time))
       
   702 				{
       
   703 				if (iMediaList->Item(0).IsStatic())
       
   704 					{
       
   705 					iHgGrid->ItemL(0).SetTime(time); // Image Downloads link Icon
       
   706 					}
       
   707 				if (iMediaList->Item(1).IsStatic())
       
   708 					{
       
   709 					iHgGrid->ItemL(1).SetTime(time); // Video Downloads link Icon
       
   710 					}
       
   711 				}
       
   712 			}
       
   713 		}
       
   714 	// Frees the TLS. Must be done after FeatureManager is used.
       
   715 	FeatureManager::UnInitializeLib();
       
   716 	}
       
   717     
       
   718 // ---------------------------------------------------------------------------
       
   719 // RemoveFSThumbnailContext
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 void CGlxGridViewContainer::RemoveFSThumbnailContext()
       
   723 	{
       
   724 	TRACER("CGlxGridViewContainer::RemoveFSThumbnailContext()");
       
   725 	if (iMediaList)
       
   726 		{
       
   727 		iMediaList->RemoveContext(iFsThumbnailContext);
       
   728 		delete iFsThumbnailContext;
       
   729 		iFsThumbnailContext = NULL;
       
   730 		}
       
   731 	}
       
   732     
       
   733 // -----------------------------------------------------------------------------
       
   734 // MopSupplyObject
       
   735 // To handle Skin support
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 TTypeUid::Ptr CGlxGridViewContainer::MopSupplyObject(TTypeUid aId)
       
   739 	{
       
   740 	TRACER("CGlxGridViewContainer::MopSupplyObject()");
       
   741 	if (iBgContext)
       
   742 		{
       
   743 		return MAknsControlContext::SupplyMopObject(aId, iBgContext );
       
   744 		}
       
   745 	return CCoeControl::MopSupplyObject( aId );
       
   746 	}
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // HandleMultipleMarkingL
       
   750 // ---------------------------------------------------------------------------
       
   751 //
       
   752 void CGlxGridViewContainer::HandleMultipleMarkingL(TInt aIndex , TBool aMarked )
       
   753 	{
       
   754 	TRACER("CGlxGridViewContainer::HandleMultipleMarkingL()");
       
   755 	//@ fix for EIZU-7RE43S
       
   756 	if(!iMediaList->Item(aIndex).IsStatic() && iHgGrid)
       
   757 		{
       
   758 		if(aMarked)
       
   759 			{
       
   760 			iGlxGridViewObserver.HandleGridEventsL(EAknCmdMark) ;
       
   761 
       
   762 			}
       
   763 		else
       
   764 			{
       
   765 			iGlxGridViewObserver.HandleGridEventsL(EAknCmdUnmark) ;
       
   766 
       
   767 			}
       
   768 		}
       
   769 
       
   770 	// This check is only implicated when multiple marking mode and we mark static items
       
   771 	// As Hg Grid marks the items on the screen, we have to unmark the same.
       
   772 	if (iMediaList->Item(aIndex).IsStatic())
       
   773 		{
       
   774 		iHgGrid->UnMark(aIndex);
       
   775 		}
       
   776 	}
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // HandleViewCommandL
       
   780 // Command handling function.
       
   781 // ---------------------------------------------------------------------------
       
   782 TBool CGlxGridViewContainer::HandleViewCommandL(TInt aCommand)
       
   783 	{
       
   784 	TRACER("CGlxGridViewContainer::HandleViewCommandL()");
       
   785 	GLX_LOG_INFO1( "CGlxGridViewContainer::HandleViewCommandL(%x) entering", aCommand );
       
   786 
       
   787 	TBool retVal = EFalse;
       
   788 	TInt focusIndex = iMediaList->FocusIndex();
       
   789 	switch (aCommand)
       
   790 		{
       
   791 		case EAknCmdOpen:
       
   792 			{
       
   793 			GLX_LOG_INFO( "EAknCmdOpen" );
       
   794 			// Activate Fullscreen
       
   795 			GLX_LOG_INFO("CGlxGridViewContainer::HandleViewCommandL - EAKnCmdOpen received");
       
   796 			if ( !iFullscreenViewActivated && !iMultipleMarkingActive &&
       
   797 					focusIndex != KErrNotFound)
       
   798 				{
       
   799 				const TGlxMedia& item = iMediaList->Item(focusIndex);
       
   800 				const TDesC& uri = item.Uri();
       
   801 
       
   802 				if ( item.IsStatic() )
       
   803 					{
       
   804 					TInt cmd = 0;
       
   805 					if( item.GetStaticItemCommand(cmd) )
       
   806 						{
       
   807 						iGlxGridViewObserver.HandleGridEventsL(cmd) ;
       
   808 						}
       
   809 					}
       
   810 				else if(item.Category() == EMPXVideo)
       
   811 					{
       
   812 					//Fix for ESLM-7U58CG - here since we get
       
   813 					//multiple HandleOpen( ) event on multiple tap
       
   814 					//we need to guard the event by a flag.
       
   815 					if(!iIsFSVideoViewActivating)
       
   816 						{
       
   817 						iIsFSVideoViewActivating = ETrue;
       
   818 						iFullscreenViewActivated = ETrue;
       
   819 						iIsFSVideoViewActivating = EFalse;
       
   820 						iGlxGridViewObserver.HandleGridEventsL(EGlxCmdPlay) ;
       
   821 						}
       
   822 					}
       
   823 				else
       
   824 					{
       
   825 					iFullscreenViewActivated = ETrue;
       
   826 					iNavigationalstate->SetToViewMode();
       
   827 					}
       
   828 				}
       
   829 
       
   830 			//@ fix for EIZU-7RE43S
       
   831 			if(iMultipleMarkingActive)
       
   832 				{
       
   833 				//If in marking mode Mark/Unmark the item
       
   834 				//appropriately.
       
   835 				if(iMediaList->IsSelected(focusIndex))
       
   836 					{
       
   837 					iGlxGridViewObserver.HandleGridEventsL(EAknCmdUnmark) ;
       
   838 					}
       
   839 				else
       
   840 					{
       
   841 					iGlxGridViewObserver.HandleGridEventsL(EAknCmdMark) ;
       
   842 					}
       
   843 				}
       
   844 			retVal = ETrue;
       
   845 			break;
       
   846 			}
       
   847 
       
   848 		case EAknCmdMark:
       
   849 			{
       
   850 			iHgGrid->SetFlags( CHgScroller::EHgScrollerSelectionMode );
       
   851 			//Start Marking mode on grid.
       
   852 			iMultipleMarkingActive = ETrue;
       
   853 			//@ fix for EIZU-7RE43S
       
   854 			iHgGrid->Mark(focusIndex);
       
   855 			iHgGrid->RefreshScreen(focusIndex);
       
   856 			retVal = ETrue;
       
   857 			break;
       
   858 			}
       
   859 
       
   860 		case EAknCmdUnmark:
       
   861 			{
       
   862 			//@ fix for EIZU-7RE43S
       
   863 			iHgGrid->UnMark(focusIndex);
       
   864 			iHgGrid->RefreshScreen(focusIndex);
       
   865 			retVal = ETrue;
       
   866 			break;
       
   867 			}
       
   868 
       
   869 		case EAknMarkAll:
       
   870 			{
       
   871 			//Start Marking mode on grid.
       
   872 			iMultipleMarkingActive = ETrue;
       
   873 			iHgGrid->SetFlags( CHgScroller::EHgScrollerSelectionMode );
       
   874 			iHgGrid->MarkAll();
       
   875 
       
   876 			// If the 0th item is static, then it must be downloads,
       
   877 			// so unmark 0th and 1st item
       
   878 			// corresponding to image and vieo icons
       
   879 			const TGlxMedia& item = iMediaList->Item(0);
       
   880 			if (item.IsStatic())
       
   881 				{
       
   882 				// Assuming that the first two items are static
       
   883 				iHgGrid->UnMark(0);
       
   884 				iHgGrid->UnMark(1);
       
   885 				}
       
   886 			// When mark all after some item is marked using toolbar
       
   887 			// it directly goes to commandhandler, so it returns not
       
   888 			// consumed after marking medialist
       
   889 			// and view marks on the display
       
   890 			// The Check prevents looping from view to mark and vice versa
       
   891 			// @ fix for ESLM-7TQGMP
       
   892 			if (iMediaList->SelectionCount() < 1)
       
   893 				{
       
   894 				iGlxGridViewObserver.HandleGridEventsL(aCommand) ;
       
   895 				}
       
   896 			retVal = ETrue;
       
   897 			break;
       
   898 			}
       
   899 
       
   900 		case EAknUnmarkAll:
       
   901 			{
       
   902 			if(iHgGrid)
       
   903 				{
       
   904 				iHgGrid->UnMarkAll();
       
   905 				iHgGrid->RefreshScreen(iMediaList->Count()-1);
       
   906 				if (!iMultipleMarkingActive)
       
   907 					{
       
   908 					iHgGrid->ClearFlags( CHgScroller::EHgScrollerSelectionMode );
       
   909 					}
       
   910 				}
       
   911 			break;
       
   912 			}
       
   913 
       
   914 		case EGlxCmdEndMultipleMarking:
       
   915 			{
       
   916 			iMultipleMarkingActive = EFalse;
       
   917 			iHgGrid->ClearFlags( CHgScroller::EHgScrollerSelectionMode );
       
   918 			// Turn off the marking mode only if the event is from toolbar marking button.
       
   919 			//Unlatch the mark toolbar button upon exiting the marking mode
       
   920 			if(iEikonEnv->AppUiFactory()->ToolBar())
       
   921 				{
       
   922 				// This will unmark the items after adding an album/tag
       
   923 				// Have to find a better solution and unmark only the items
       
   924 				// marked and not all, might be a perf hit
       
   925 				if(iHgGrid)
       
   926 					{
       
   927 					iHgGrid->UnMarkAll();
       
   928 					}
       
   929 				iGlxGridViewObserver.HandleLatchToolbar();
       
   930 				}
       
   931 			retVal = ETrue;
       
   932 			break;
       
   933 			}
       
   934 
       
   935 		case EGlxCmdStartMultipleMarking:
       
   936 			{
       
   937 			if( iHgGrid->Flags() & CHgScroller::EHgScrollerSelectionMode )
       
   938 				{
       
   939 				iHgGrid->ClearFlags( CHgScroller::EHgScrollerSelectionMode );
       
   940 				// Refreshing the items selected after unmark
       
   941 				for (TInt i= 0;i<iMediaList->SelectionCount();i++)
       
   942 					{
       
   943 					TInt selectedItemIndex = iMediaList->SelectedItemIndex(i);
       
   944 					iHgGrid->UnMark(selectedItemIndex);
       
   945 					iHgGrid->RefreshScreen(selectedItemIndex);
       
   946 					}
       
   947 				iGlxGridViewObserver.HandleGridEventsL(EGlxCmdEndMultipleMarking) ;
       
   948 				}
       
   949 			else
       
   950 				{
       
   951 				//Start Marking mode on grid.
       
   952 				iMultipleMarkingActive = ETrue;
       
   953 				iHgGrid->SetFlags(CHgScroller::EHgScrollerSelectionMode);
       
   954 				}
       
   955 			retVal = ETrue;
       
   956 			break;
       
   957 			}
       
   958 
       
   959 		case EAknSoftkeyCancel:
       
   960 			{
       
   961 			//@ fix for EIZU-7RE43S
       
   962 			if( iHgGrid->Flags() & CHgScroller::EHgScrollerSelectionMode )
       
   963 				{
       
   964 				iGlxGridViewObserver.HandleGridEventsL(EGlxCmdEndMultipleMarking) ;
       
   965 				}
       
   966 			retVal = ETrue;
       
   967 			break;
       
   968 
       
   969 			}
       
   970 		case EGlxCmdResetView:
       
   971 			{
       
   972 			//@ fix for ESLM-7VRGKH
       
   973 			if(iHgGrid)
       
   974 				{
       
   975 				iHgGrid->InitScreenL(iEikonEnv->EikAppUi()->ClientRect());
       
   976 				}
       
   977 			retVal = ETrue;
       
   978 			break;
       
   979 			}
       
   980 		default:
       
   981 			break;
       
   982 		}
       
   983 	GLX_LOG_INFO("CGlxGridViewContainer::HandleViewCommandL() exiting");
       
   984 	return retVal;
       
   985 	}
       
   986 
       
   987 // ---------------------------------------------------------------------------
       
   988 // HandleResourceChange
       
   989 // Handle BG screen context && Hg grid orientaion
       
   990 // ---------------------------------------------------------------------------
       
   991 //
       
   992 void CGlxGridViewContainer::HandleResourceChange(TInt aId)
       
   993 	{
       
   994 	TRACER("CGlxGridViewContainer::HandleResourceChange()");
       
   995 	CCoeControl::HandleResourceChange(aId);
       
   996 	if ( iBgContext )
       
   997 		{
       
   998 		TRect apRect = iEikonEnv->EikAppUi()->ApplicationRect();
       
   999 		iBgContext->SetRect( apRect );
       
  1000 		}
       
  1001 	if(iHgGrid)
       
  1002 		{
       
  1003 		TRAP_IGNORE (iHgGrid->InitScreenL(iEikonEnv->EikAppUi()->ClientRect()); )
       
  1004 		}
       
  1005 	}
       
  1006 //end of file