photosgallery/viewframework/views/metadataview/src/glxmetadataviewimp.cpp
changeset 0 4e91876724a2
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 Metadataview
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include 	"glxmetadataviewimp.h"
       
    22 
       
    23 #include 	<aknviewappui.h>
       
    24 #include 	<data_caging_path_literals.hrh>
       
    25 #include 	<avkon.rsg>
       
    26 
       
    27 #include 	<alf/ialfviewwidget.h>
       
    28 #include 	<alf/alfdisplay.h>
       
    29 #include    <alf/alfwidgetenvextension.h>
       
    30 #include    <alf/alfwidgetcontrol.h>
       
    31 
       
    32 #include 	<glxmedialist.h>
       
    33 #include	<glxtracer.h>
       
    34 #include	<glxlog.h>
       
    35 #include 	<glxresourceutilities.h>       // for CGlxResourceUtilities
       
    36 #include	<glxsetappstate.h>             // set app state in PCFW key
       
    37 
       
    38 #include 	<glxfilterfactory.h>               // for TGlxFilterFactory
       
    39 #include	<glxdetailsmulmodelprovider.h>	//Details data provider
       
    40 #include    "glxmetadatabindingsetfactory.h" //for Binding list entries 
       
    41 #include    <glxdetailsboundcommand.hrh>
       
    42 
       
    43 #include 	"glxmetadataview.h"
       
    44 #include 	<glxmetadataview.rsg>
       
    45 
       
    46 #include <glxuiutilities.rsg>
       
    47 
       
    48 #include <glxcommandhandleraiwshowmap.h>
       
    49 
       
    50 //CONSTANTS
       
    51 const TInt  KViewId = 0x200071B0;
       
    52 const TInt  KMainMediaListId = 0x2000D248;
       
    53 const TInt  KDetialsDataWindowSize = 5;
       
    54 _LIT( KGlxStrETrue, "\x0001");
       
    55 
       
    56 // ============================== MEMBER FUNCTIONS ===========================
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Two-phased constructor.
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CGlxMetadataViewImp* CGlxMetadataViewImp::NewL
       
    63 									( MGlxMediaListFactory* aMediaListFactory )
       
    64     {
       
    65 	TRACER("CGlxMetadataViewImp::NewL");
       
    66     
       
    67     CGlxMetadataViewImp* self = CGlxMetadataViewImp::NewLC( aMediaListFactory );
       
    68     CleanupStack::Pop(self);
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // Two-phased constructor.
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CGlxMetadataViewImp* CGlxMetadataViewImp::NewLC
       
    77 									( MGlxMediaListFactory* aMediaListFactory )
       
    78     {
       
    79     TRACER("CGlxMetadataViewImp::NewLC");
       
    80 
       
    81     CGlxMetadataViewImp* self = new (ELeave) CGlxMetadataViewImp();
       
    82     CleanupStack::PushL(self);
       
    83     self->ConstructL( aMediaListFactory );
       
    84     return self;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // C++ default constructor can NOT contain any code, that
       
    89 // might leave.
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CGlxMetadataViewImp::CGlxMetadataViewImp()
       
    93     {
       
    94     //No implementation
       
    95     }
       
    96     
       
    97 // ---------------------------------------------------------------------------
       
    98 // Destructor
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 CGlxMetadataViewImp::~CGlxMetadataViewImp()
       
   102     {
       
   103 	TRACER("CGlxMetadataViewImp::~CGlxMetadataViewImp");
       
   104 	
       
   105 	
       
   106     if ( iResourceOffset )
       
   107        {
       
   108         CCoeEnv::Static()->DeleteResourceFile( iResourceOffset );
       
   109        }    
       
   110     }
       
   111     
       
   112 // ---------------------------------------------------------------------------
       
   113 // Symbian 2nd phase constructor can leave.
       
   114 // ---------------------------------------------------------------------------
       
   115 //    
       
   116 void CGlxMetadataViewImp::ConstructL( MGlxMediaListFactory* /*aMediaListFactory*/ )
       
   117     {
       
   118     TRACER("CGlxMetadataViewImp::ConstructL");
       
   119     
       
   120 	_LIT(KGlxMetadataViewResource,"glxmetadataview.rsc");
       
   121 
       
   122 	//add resource file
       
   123     TParse parse;
       
   124     parse.Set(KGlxMetadataViewResource, &KDC_APP_RESOURCE_DIR, NULL);
       
   125     TFileName resourceFile;
       
   126     resourceFile.Append(parse.FullName()); 
       
   127     CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
       
   128     iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile);
       
   129 	
       
   130 	//call base class's consructor
       
   131     BaseConstructL(R_GLX_METADATA_VIEW);
       
   132     ViewBaseConstructL();
       
   133     
       
   134    	HBufC* title = iEikonEnv->AllocReadResourceLC(R_GLX_METADATA_VIEW_TITLE_DETAILS);
       
   135 	MLViewBaseConstructL(NULL,*title);   	 	
       
   136 	CleanupStack::PopAndDestroy(title);
       
   137 	
       
   138     // ShowMap commandhandler                         
       
   139     GLX_LOG_INFO("Adding CGlxCommandHandlerAiwShowMap");
       
   140     this->AddCommandHandlerL(CGlxCommandHandlerAiwShowMap::
       
   141                                 NewL(this, R_METADATA_MENU));
       
   142 	
       
   143 	// Creating the Alf Environment
       
   144     ConstructAlfEnvL();
       
   145 	}
       
   146 	
       
   147 // ---------------------------------------------------------------------------
       
   148 // DynInitMenuPaneL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CGlxMetadataViewImp::ViewDynInitMenuPaneL(TInt /*aResourceId*/, CEikMenuPane *aMenuPane)
       
   152     {
       
   153 	TRACER("CGlxMetadataViewImp::DynInitMenuPaneL");
       
   154     
       
   155     iDetailsMulModelProvider->InitMenuL(*aMenuPane);
       
   156     }
       
   157     
       
   158 // ---------------------------------------------------------------------------
       
   159 // HandleViewCommandL
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TBool CGlxMetadataViewImp::HandleViewCommandL(TInt aCommand)
       
   163     {
       
   164 	TRACER("CGlxMetadataViewImp::HandleViewCommandL");
       
   165         
       
   166     if( aCommand )
       
   167     	{
       
   168     	return iDetailsMulModelProvider->OfferCommandL( aCommand );
       
   169     	}
       
   170     return EFalse;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // From CGlxViewBase
       
   175 // return menuresource id
       
   176 // ---------------------------------------------------------------------------
       
   177 //    
       
   178 TInt CGlxMetadataViewImp::MenuResourceId()
       
   179 	{
       
   180 	return R_METADATA_MENU;
       
   181 	}
       
   182 	
       
   183 // ---------------------------------------------------------------------------
       
   184 // From CAknView
       
   185 // Returns views id.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 TUid CGlxMetadataViewImp::Id() const
       
   189     {
       
   190     return TUid::Uid(KViewId);
       
   191     }
       
   192     
       
   193 // ---------------------------------------------------------------------------
       
   194 // From CAknView
       
   195 // Handles a view activation.
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CGlxMetadataViewImp::DoMLViewActivateL( const TVwsViewId& /* aPrevViewId */, 
       
   199     TUid /* aCustomMessageId */, const TDesC8&  aCustomMessage )
       
   200 	{
       
   201 	TRACER("CGlxMetadataViewImp::DoMLViewActivateL");
       
   202 	CreateMediaListL( aCustomMessage );
       
   203 	
       
   204 	StatusPane()->MakeVisible(ETrue);
       
   205 	
       
   206 	// Construct the application's default view i.e., listview widget
       
   207 	ConstructInitialViewL();
       
   208 	GlxSetAppState::SetState( EGlxInListView );
       
   209 	}
       
   210 	
       
   211 // ---------------------------------------------------------------------------
       
   212 // From CAknView
       
   213 // View deactivation function.
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CGlxMetadataViewImp::DoMLViewDeactivate()
       
   217     {
       
   218 	TRACER("CGlxMetadataViewImp::DoMLViewDeactivate");
       
   219 	
       
   220 	
       
   221 		
       
   222     DestroyListViewWidget();
       
   223 	if( iItemMediaList ) 
       
   224 		{
       
   225 		iItemMediaList->Close();
       
   226 		iItemMediaList = NULL;	
       
   227 		} 
       
   228 	if( iItemURI )
       
   229 		{
       
   230 		delete iItemURI;
       
   231 		iItemURI = NULL;
       
   232 		}
       
   233    }
       
   234    
       
   235 // ---------------------------------------------------------------------------
       
   236 // ConstructAlfEnvL
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 void CGlxMetadataViewImp::ConstructAlfEnvL()
       
   240     {
       
   241 	TRACER("CGlxMetadataViewImp::ConstructAlfEnvL");
       
   242     
       
   243 	
       
   244 	// Creating the Alf Environment
       
   245 	// Should be the first thing to be done before widgets can be created
       
   246 	iEnv = iUiUtility->Env();
       
   247 
       
   248 	// Creating the Alf display    
       
   249 	// display is need to show anything related to Alf
       
   250 	// Avkon perceives the Alf display as one CoeControl, 
       
   251 	// it can't see widgets inside the display
       
   252 	iDisp = iUiUtility->Display();
       
   253 	
       
   254 	// Use the Avkon skin background as the display background.
       
   255 	iDisp->SetClearBackgroundL (CAlfDisplay::EClearWithSkinBackground);
       
   256    }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // ConstructInitialViewL
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CGlxMetadataViewImp::ConstructInitialViewL()
       
   263     {
       
   264     TRACER("CGlxMetadataViewImp::ConstructInitialViewL");
       
   265     
       
   266     const char* KLoadName("mullistwidget");
       
   267     const char* KWidgetLoadName("ListWidget");
       
   268     
       
   269     iControlGroupId = reinterpret_cast < TInt > (this);
       
   270     
       
   271     try
       
   272         {
       
   273         // Get widget factory from CAlfEnv
       
   274         // Factory is then used to create the individual widgets & data model
       
   275 
       
   276         IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*iEnv); 
       
   277 
       
   278         
       
   279         iViewWidget = widgetFactory.createViewWidget("detaillistviewwidget", iControlGroupId); 
       
   280         
       
   281         //Enable status pane
       
   282         iViewWidget->enableStatusPane(true);
       
   283         iViewWidget->setRect( ClientRect() );
       
   284         iViewWidget->show(true);
       
   285         
       
   286         // Create List widget. CAlfEnv owns widget
       
   287         iListWidget = widgetFactory.createWidget<IMulListWidget>( KLoadName, 
       
   288                                         KWidgetLoadName, *iViewWidget, NULL);
       
   289         
       
   290         // Disable marking for list, need to remove this flag when widget  
       
   291         // construction has no marking flag set by default
       
   292         iListWidget->ClearFlags( IMulMultiItemWidget::EMulWidgetMarkingMode ); 
       
   293         
       
   294         //Sets the default text for the List View when empty
       
   295         CreateEmptyText();
       
   296     
       
   297         if ( iListWidget )
       
   298             {
       
   299             // Widget takes the ownership
       
   300             iListWidget->AddEventHandler (*this);
       
   301             iListWidget->ShowWidget(true);
       
   302             iListWidget->control()->AcquireFocus();
       
   303             } 
       
   304         
       
   305         AddListEntryL();
       
   306                
       
   307     	}
       
   308     catch(...)
       
   309         {
       
   310         User::Leave(KErrGeneral);
       
   311         }
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Destroys the Widget
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CGlxMetadataViewImp::DestroyListViewWidget()
       
   319     {
       
   320     if( iDetailsMulModelProvider )
       
   321         {
       
   322         delete iDetailsMulModelProvider;
       
   323         iDetailsMulModelProvider = NULL;
       
   324         }
       
   325       if( iListWidget )
       
   326         {
       
   327         iListWidget->RemoveEventHandler (*this);
       
   328         iListWidget->ShowWidget(false);
       
   329         iViewWidget->show(false);
       
   330         }
       
   331 
       
   332     IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*iEnv); 
       
   333     widgetFactory.destroyWidget(iViewWidget);
       
   334       
       
   335     iListWidget = NULL;  
       
   336     iViewWidget = NULL;
       
   337     }
       
   338 	
       
   339 // ---------------------------------------------------------------------------
       
   340 // From AddListEntryL
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CGlxMetadataViewImp::AddListEntryL()
       
   344 	{
       
   345 	TRACER("CGlxMetadataViewImp::AddListEntryL");
       
   346 	
       
   347 	iDetailsMulModelProvider = CGlxDetailsMulModelProvider::NewL( *iEnv,
       
   348 										*iListWidget,
       
   349 										*iItemMediaList, 
       
   350 										mulwidget::KTemplate5, KDetialsDataWindowSize );
       
   351 										
       
   352 	iDetailsMulModelProvider->AddEntryL(TGlxMulTitleDetailsBindingSetFactory() );
       
   353 	iDetailsMulModelProvider->AddEntryL(TGlxMulDateAndTimeDetailsBindingSetFactory() );
       
   354 	iDetailsMulModelProvider->AddEntryL(TGlxMulDescriptionDetailsBindingSetFactory() );
       
   355 	iDetailsMulModelProvider->AddEntryL(TGlxMulTagsDetailsBindingSetFactory() ); 
       
   356 	iDetailsMulModelProvider->AddEntryL(TGlxMulAlbumsDetailsBindingSetFactory() ); 
       
   357 	iDetailsMulModelProvider->AddEntryL(TGlxMulLocationDetailsBindingSetFactory() ); 
       
   358 	iDetailsMulModelProvider->AddEntryL(TGlxMulFileSizeDetailsBindingSetFactory() );
       
   359 	iDetailsMulModelProvider->AddEntryL(TGlxMulResolutionDetailsBindingSetFactory() );
       
   360 	if( iIsVideo)
       
   361 	    {
       
   362 	    iDetailsMulModelProvider->AddEntryL(TGlxMulDurationDetailsBindingSetFactory() );
       
   363 	    }
       
   364 	if( iIsDrm )
       
   365 		{
       
   366 		iDetailsMulModelProvider->AddEntryL(TGlxMulUsageRightsDetailsBindingSetFactory() );
       
   367 		}
       
   368 	}
       
   369 	
       
   370 // ---------------------------------------------------------
       
   371 // CreateEmptyText
       
   372 // ---------------------------------------------------------
       
   373 //	
       
   374 void CGlxMetadataViewImp::CreateEmptyText()
       
   375 	{
       
   376 	TRACER("CGlxMetadataViewImp::CreateEmptyText");
       
   377 	
       
   378 	// The listwidget can set an empty text on the display
       
   379 	// If there are no data items in the associated data model,
       
   380 	// then the empty text is shown on the widget
       
   381 	// If the empty text is not set, then widget won't shown any text by default
       
   382 	UString* defaultText = new UString("No Items Present");
       
   383 	iListWidget->SetEmptyText (*defaultText); // Widget takes the ownership
       
   384 	delete defaultText;
       
   385 	}
       
   386 	
       
   387 // ---------------------------------------------------------------------------
       
   388 // CreateMediaListL
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void CGlxMetadataViewImp::CreateMediaListL( const TDesC8& aURI )
       
   392 	{
       
   393 	TRACER("CGlxMetadataViewImp::CreateMediaListL");
       
   394 	
       
   395 	CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   396 	CleanupStack::PushL( path );
       
   397 	
       
   398 	path->AppendL(KGlxCollectionPluginAllImplementationUid);
       
   399 	
       
   400 	//convert uri from 8 bit to unicode
       
   401 	iItemURI = HBufC::NewL( aURI.Length() );
       
   402 	iItemURI->Des().Copy( aURI );
       
   403 	
       
   404 	//Get last two characters for checking drm or video and reset the length for uri
       
   405     TPtr uriPtr (iItemURI->Des());
       
   406     
       
   407     TPtr isVideo = uriPtr.MidTPtr(uriPtr.Length()-1,1);
       
   408     if( !isVideo.Compare(KGlxStrETrue ))
       
   409 	    {
       
   410 	    iIsVideo = ETrue;	
       
   411 	    }
       
   412 	    
       
   413     TPtr isDrm = uriPtr.MidTPtr(uriPtr.Length()-2,1);
       
   414     if( !isDrm.Compare(KGlxStrETrue))
       
   415 	    {
       
   416 	    iIsDrm = ETrue;	
       
   417 	    }
       
   418     
       
   419     uriPtr.SetLength(uriPtr.Length()-2);
       
   420 
       
   421 	CMPXFilter* filter  = TGlxFilterFactory::CreateURIFilterL( *iItemURI );  
       
   422 	CleanupStack::PushL( filter );	
       
   423 	
       
   424 	//@TODO remove magic no - allocate uid from uid list
       
   425 	iItemMediaList = MGlxMediaList::InstanceL(*path, TGlxHierarchyId(KMainMediaListId), filter);
       
   426     
       
   427 	CleanupStack::PopAndDestroy( filter );	
       
   428     CleanupStack::PopAndDestroy( path ); 
       
   429 	}
       
   430 	
       
   431 // ---------------------------------------------------------------------------
       
   432 // MediaList.
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 MGlxMediaList& CGlxMetadataViewImp::MediaList()
       
   436 	{
       
   437 	return *iItemMediaList;
       
   438 	}
       
   439 	
       
   440 // ---------------------------------------------------------
       
   441 // offerEvent
       
   442 // ---------------------------------------------------------
       
   443 //	
       
   444 AlfEventStatus CGlxMetadataViewImp::offerEvent( CAlfWidgetControl& /*aControl*/, const TAlfEvent& aEvent )
       
   445 	{
       
   446 	    
       
   447 	//Check if its a Custom Event else return
       
   448 	if(!aEvent.IsCustomEvent())
       
   449 		{   
       
   450 		GLX_LOG_INFO("Event Not Handled");     		
       
   451 		return EEventNotHandled;
       
   452 		}
       
   453     TInt eventId = aEvent.CustomParameter();
       
   454     switch(eventId)
       
   455         {
       
   456         case KAlfActionIdDeviceLayoutChanged:
       
   457           {
       
   458           iViewWidget->setRect( ClientRect() ); 
       
   459           return EEventNotHandled;
       
   460           }
       
   461         case ETypeSelect:
       
   462             {
       
   463             TRAP_IGNORE(HandleViewCommandL((TInt)KGlxEditBoundMenuCommandId));
       
   464             }
       
   465         }
       
   466  
       
   467 	return EEventConsumed;	
       
   468 	}
       
   469 
       
   470 //----------------------------------------------------------------------------------
       
   471 // eventHandlerType
       
   472 //----------------------------------------------------------------------------------
       
   473 //
       
   474 IAlfWidgetEventHandler::AlfEventHandlerType CGlxMetadataViewImp::eventHandlerType() 
       
   475 	{
       
   476 	return IAlfWidgetEventHandler::EPresentationEventHandler;
       
   477 	}
       
   478 
       
   479 //----------------------------------------------------------------------------------
       
   480 // eventExecutionPhase
       
   481 //----------------------------------------------------------------------------------
       
   482 //
       
   483 IAlfWidgetEventHandler::AlfEventHandlerExecutionPhase CGlxMetadataViewImp::eventExecutionPhase()
       
   484 	{
       
   485 		return EBubblingPhaseEventHandler;
       
   486 	}  
       
   487 // ---------------------------------------------------------
       
   488 // accept
       
   489 // ---------------------------------------------------------
       
   490 //	
       
   491 
       
   492 bool CGlxMetadataViewImp::accept( CAlfWidgetControl& /*aControl*/, const TAlfEvent& /*aEvent*/ ) const
       
   493     {
       
   494     return ETrue;
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // setActiveStates
       
   499 // ---------------------------------------------------------
       
   500 //	
       
   501     
       
   502  void CGlxMetadataViewImp::setActiveStates( unsigned int /*aStates*/ )
       
   503     {
       
   504     
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------
       
   508 // makeInterface
       
   509 // ---------------------------------------------------------
       
   510 //	
       
   511 
       
   512 IAlfInterfaceBase* CGlxMetadataViewImp::makeInterface( const IfId& /*aType*/ )
       
   513     {
       
   514     return NULL; 
       
   515     }
       
   516 
       
   517 // ---------------------------------------------------------
       
   518 // setEventHandlerData
       
   519 // ---------------------------------------------------------
       
   520 //	
       
   521     
       
   522 void CGlxMetadataViewImp::setEventHandlerData(const AlfWidgetEventHandlerInitData& /*aData*/ )
       
   523     {
       
   524     
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------
       
   528 // eventHandlerData
       
   529 // ---------------------------------------------------------
       
   530 //	
       
   531     
       
   532 AlfWidgetEventHandlerInitData* CGlxMetadataViewImp::eventHandlerData()	  
       
   533    {
       
   534    return NULL;
       
   535    }
       
   536    
       
   537 //  End of File