photosgallery/viewframework/views/cloudview/src/glxcloudviewimp.cpp
changeset 0 4e91876724a2
child 9 6b87b143d312
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 Cloud view
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "glxcloudviewimp.h" //header file
       
    23 
       
    24 //ALF headers
       
    25 #include <alf/alfcontrolgroup.h> //for Alfcontrolgroup
       
    26 #include <alf/alfwidgetcontrol.h> //for alfwidget controls
       
    27 #include <alf/alfgridlayout.h> // For CAlfGridLayout
       
    28 #include <alf/ialflayoutmanager.h> // For CAlfLAyoutManager
       
    29 #include <alf/ialfscrollbarmodel.h> // For CAlfScrollBarModel
       
    30 #include <alf/ialfscrollbardefaultbaseelement.h> // For CAlfScrollBarDefaultBaseelement
       
    31 #include <alf/alfwidgetenvextension.h>
       
    32 #include <glxuiutility.h>
       
    33 #include <glxresourceutilities.h>  // for CGlxResourceUtilities
       
    34 
       
    35 #include <mpxcollectionutility.h>
       
    36 #include <mpxcollectionpath.h>
       
    37 #include <glxtracer.h>	
       
    38 #include <glxlog.h>					// For Logs
       
    39 #include <glxsetappstate.h> // For view state
       
    40 #include <mglxmedialist.h> //medialist
       
    41 #include <data_caging_path_literals.hrh> // For directory paths 
       
    42 
       
    43 #include <aknlayoutscalable_uiaccel.cdl.h>
       
    44 
       
    45 #include "glxcloudviewcontrol.h"//cloud view control
       
    46     
       
    47 const TInt KViewId = 0x200071B7;
       
    48 
       
    49 using namespace Alf;
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Two-phased constructor.
       
    54 // ---------------------------------------------------------------------------
       
    55 // 
       
    56 EXPORT_C CGlxCloudViewImp *CGlxCloudViewImp::NewL(MGlxMediaListFactory
       
    57 		*aMediaListFactory, const TDesC &aFileName, TInt aViewResId, 
       
    58 		TInt aEmptyListResId, TInt aSoftKeyResId, TInt aSoftkeyMskDisabledId)
       
    59 	{
       
    60 	TRACER("GLX_CLOUD::CGlxCloudViewImp::NewL");
       
    61 	CGlxCloudViewImp *self = CGlxCloudViewImp::NewLC(aMediaListFactory,
       
    62 		aFileName, aViewResId, aEmptyListResId, aSoftKeyResId
       
    63 		, aSoftkeyMskDisabledId);
       
    64 	CleanupStack::Pop(self);
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Two-phased constructor.
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C CGlxCloudViewImp *CGlxCloudViewImp::NewLC(MGlxMediaListFactory
       
    73 		*aMediaListFactory, const TDesC &aFileName, TInt aViewResId,
       
    74 		TInt aEmptyListResId, TInt aSoftKeyResId, TInt aSoftkeyMskDisabledId)
       
    75     {
       
    76     TRACER("GLX_CLOUD::CGlxCloudViewImp::NewLC");
       
    77     CGlxCloudViewImp *self = new(ELeave)CGlxCloudViewImp(aSoftKeyResId,aSoftkeyMskDisabledId);
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL(aMediaListFactory, aFileName, aViewResId, aEmptyListResId, aSoftKeyResId);
       
    80     return self;
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // C++ default constructor can NOT contain any code, that
       
    85 // might leave.
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CGlxCloudViewImp::CGlxCloudViewImp(TInt aSoftKeyResId,
       
    89 		TInt aSoftkeyMskDisabledId) :
       
    90 	         iSoftKeyResId(aSoftKeyResId), iSoftkeyMskDisabledId(aSoftkeyMskDisabledId)
       
    91 	{
       
    92 	TRACER("GLX_CLOUD::CGlxCloudViewImp::CGlxCloudViewImp");
       
    93 	}
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // Symbian 2nd phase constructor can leave.
       
    97 // ---------------------------------------------------------------------------
       
    98 // 
       
    99 void CGlxCloudViewImp::ConstructL(MGlxMediaListFactory *aMediaListFactory,
       
   100 		const TDesC &aFileName, TInt aViewResId, TInt aEmptyListResId,
       
   101 		TInt /*aSoftKeyResId*/)
       
   102 
       
   103 	{
       
   104 	TRACER("GLX_CLOUD::CGlxCloudViewImp::ConstructL");
       
   105 	TFileName resourceFile(KDC_APP_RESOURCE_DIR);
       
   106 	resourceFile.Append (aFileName);
       
   107 	CGlxResourceUtilities::GetResourceFilenameL (resourceFile);
       
   108 	iResourceOffset = iCoeEnv->AddResourceFileL (resourceFile);
       
   109 	BaseConstructL (aViewResId);
       
   110 	ViewBaseConstructL ();
       
   111 	MLViewBaseConstructL (aMediaListFactory);
       
   112 	
       
   113 	//Register the view to recieve toolbar events. ViewBase handles the events    
       
   114 	SetToolbarObserver(this);
       
   115 	ShowToolbarOnViewActivation(ETrue);
       
   116 	
       
   117 	iEmptyListText = iEikonEnv->AllocReadResourceL(aEmptyListResId);
       
   118 	iDisplay = iUiUtility->Display ();
       
   119 	CAknToolbar* toolbar = Toolbar();
       
   120 	if(toolbar)
       
   121         {
       
   122         toolbar->DisableToolbarL(ETrue);  
       
   123         }
       
   124 //	SetSoftkeysFromResourceIdL (iSoftkeyMskDisabledId); //initially load empty msk
       
   125 	}
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Destructor
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CGlxCloudViewImp::~CGlxCloudViewImp()
       
   132     {
       
   133     TRACER("GLX_CLOUD::CGlxCloudViewImp::~CGlxCloudViewImp");
       
   134     CleanupVisuals ();
       
   135     delete iEmptyListText;
       
   136     if ( iResourceOffset )
       
   137         {
       
   138         CCoeEnv::Static()->DeleteResourceFile (iResourceOffset);
       
   139         }
       
   140     delete iTitletext;
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // From CAknView
       
   145 // Returns views id.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 TUid CGlxCloudViewImp::Id()const
       
   149 	{
       
   150 	TRACER("GLX_CLOUD::CGlxCloudViewImp::Id()");
       
   151 	return TUid::Uid (KViewId);
       
   152 	}
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // HandleViewCommandL
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 TBool CGlxCloudViewImp::HandleViewCommandL(TInt aCommand)
       
   159 	{
       
   160 	TRACER("GLX_CLOUD::CGlxCloudViewImp::HandleViewCommandL");
       
   161 	TBool consumed = EFalse;
       
   162 
       
   163 	switch (aCommand)
       
   164 		{
       
   165 		case EAknCmdOpen:
       
   166 		case EKeyEnter:
       
   167 			{
       
   168 			// Processing of this Command depends on Medialist Count ( > 0 tags Available) 
       
   169 			if(iMediaList->Count())
       
   170 			    {
       
   171 			// There can be no selection in cloud view, so assume that path contains focused item
       
   172 		        iUiUtility->SetViewNavigationDirection(EGlxNavigationForwards);
       
   173 			CMPXCollectionPath* path = iMediaList->PathLC( NGlxListDefs::EPathFocusOrSelection );
       
   174 			iCollectionUtility->Collection().OpenL (*path);
       
   175 			CleanupStack::PopAndDestroy (path);
       
   176 			consumed= ETrue;
       
   177 			    }
       
   178 			break;
       
   179 			}
       
   180 		}
       
   181 		
       
   182 	return consumed;
       
   183 	}
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // From CAknView
       
   188 // Handles a view activation.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CGlxCloudViewImp::DoMLViewActivateL(const TVwsViewId & /* aPrevViewId */,
       
   192 		TUid /* aCustomMessageId */, const TDesC8 & /* aCustomMessage */)
       
   193     {
       
   194     TRACER("GLX_CLOUD::CGlxCloudViewImp::DoMLViewActivateL");
       
   195     if(StatusPane())
       
   196         {
       
   197         StatusPane()->MakeVisible(ETrue);
       
   198         CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   199         CAknTitlePane* titlePane = ( CAknTitlePane* )statusPane->ControlL(
       
   200                 TUid::Uid( EEikStatusPaneUidTitle ));     
       
   201             if( iTitletext )
       
   202                 {
       
   203                 // Set the required Title
       
   204                 titlePane->SetTextL( *iTitletext );
       
   205                 }
       
   206         }
       
   207     ConstructCloudControlL();
       
   208     GLX_LOG_INFO("CGlxCloudViewImp::DoMLViewActivateL Cloud View Control Created" );  
       
   209     // set app state to tag-browser view
       
   210     GlxSetAppState::SetState (EGlxInTagBrowserView);
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // From CAknView
       
   215 // View deactivation function.
       
   216 // ---------------------------------------------------------------------------
       
   217 //
       
   218 void CGlxCloudViewImp::DoMLViewDeactivate()
       
   219 	{
       
   220 	TRACER("GLX_CLOUD::CGlxCloudViewImp::DoMLViewDeactivate");
       
   221 	if(StatusPane())
       
   222         {
       
   223         if(iTitletext)
       
   224            {
       
   225            delete iTitletext;
       
   226            iTitletext = NULL;
       
   227            }
       
   228         CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   229         TRAP_IGNORE(CAknTitlePane* titlePane = ( CAknTitlePane* )statusPane->ControlL(
       
   230                 TUid::Uid( EEikStatusPaneUidTitle ));        
       
   231         iTitletext = titlePane->Text()->AllocL());
       
   232         }
       
   233 	//Hide softkeys and toolbar upon view de-activation.
       
   234 	iViewWidget->enableControlPane(EFalse);
       
   235 	if ( EGlxNavigationForwards == iUiUtility->ViewNavigationDirection() )
       
   236         {
       
   237         iViewWidget->enableStatusPane(EFalse);    
       
   238         }
       
   239 	CleanupVisuals ();
       
   240 	}
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // HandleMskChangedL().
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CGlxCloudViewImp::HandleMskChangedL(TBool aMskEnabled)
       
   247     {
       
   248     TRACER("GLX_CLOUD ::CGlxCloudViewImp::HandleMskChangedL");
       
   249     GLX_LOG_INFO1("GLX_CLOUD ::GLX_CLOUD ::CGlxCloudViewImp::HandleMskChangedL MSk State  %d ",
       
   250         aMskEnabled);
       
   251     //iViewWidget->setRect( ClientRect() );
       
   252 	 }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // HandleLayoutChanged().
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CGlxCloudViewImp::HandleLayoutChanged()
       
   259     {	
       
   260     iViewWidget->setRect( ClientRect() );
       
   261     SetScrollBarRect();   
       
   262     }
       
   263 
       
   264 // --------------------------------------------------------------------------- 
       
   265 //ControlGroupId()
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 TInt CGlxCloudViewImp::ControlGroupId()const
       
   269 	{
       
   270 	TRACER("GLX_CLOUD::CGlxCloudViewImp::ControlGroupId");
       
   271 	return reinterpret_cast < TInt > (this);
       
   272 	}
       
   273 	
       
   274 // ---------------------------------------------------------------------------
       
   275 // CleanupVisuals
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CGlxCloudViewImp::CleanupVisuals()
       
   279     {
       
   280     TRACER("GLX_CLOUD::CGlxCloudViewImp::CleanupVisuals()");
       
   281     if( iViewWidget )
       
   282         {        
       
   283         iViewWidget->show(false); 
       
   284         }  
       
   285 
       
   286     if(iScrollWidget)
       
   287         {
       
   288         iScrollWidget->control()->removeEventHandler(*iCloudControl);
       
   289         iScrollWidget =  NULL;
       
   290         }
       
   291     if( iUiUtility )
       
   292         {
       
   293 
       
   294 		IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*(iUiUtility->Env ())); 
       
   295         widgetFactory.destroyWidget(iViewWidget);
       
   296     
       
   297         }
       
   298     iViewWidget = NULL; 
       
   299     // delete iCloudControl;
       
   300     //  iCloudControl = NULL;  
       
   301     iScrollbarDefaultBaseElement = NULL;
       
   302     }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // HandleEnterKeyEventL
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CGlxCloudViewImp::HandleEnterKeyEventL(TInt aCommand)
       
   309     {
       
   310     HandleViewCommandL(aCommand);
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // HandleEnterKeyEventL
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 void CGlxCloudViewImp::ConstructCloudControlL()
       
   318     {
       
   319    	const char* KScrollBarWidget("scrollbarwidget");
       
   320 	const char* KVerScrollbarWidgetName("alfscrollbarwidget_ver");
       
   321 	const char* KScrollBarModel(/*"mulmodel"*/"scrollbarmodel");
       
   322 
       
   323 	IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*(iUiUtility->Env ())); 
       
   324 
       
   325     iViewWidget = widgetFactory.createViewWidget("viewwidget", 0,0,iDisplay);
       
   326     
       
   327     iViewWidget->setRect( ClientRect() );
       
   328    iViewWidget->show(true); 
       
   329     
       
   330     IAlfLayoutManager* layoutmanager = IAlfInterfaceBase::makeInterface<IAlfLayoutManager>(iViewWidget->control());
       
   331     iViewWidget->setRect(ClientRect());
       
   332    
       
   333     // parent layout handle for scrollbar
       
   334     iScrollPaneHandle = AknLayoutScalable_UiAccel::aa_scroll_pane(0).LayoutLine();
       
   335 
       
   336     iAnchorlayout = &((CAlfAnchorLayout&)layoutmanager->getLayout());
       
   337 
       
   338     iAnchorlayout->SetFlag(EAlfVisualFlagLayoutUpdateNotification);
       
   339     iAnchorlayout->SetFlag(EAlfVisualFlagAutomaticLocaleMirroringEnabled);
       
   340 
       
   341     iCloudControl = CGlxCloudViewControl::NewL (*iDisplay, *iUiUtility->Env (), *iMediaList,
       
   342             *iEmptyListText, *this,*this,iAnchorlayout,*this); 
       
   343     
       
   344     CAlfControlGroup * ctrlGroup = iUiUtility->Env ()->FindControlGroup(0);
       
   345     if(ctrlGroup)
       
   346         {
       
   347         ctrlGroup->AppendL(iCloudControl);
       
   348         }
       
   349    iScrollWidget = widgetFactory.createWidget<IAlfScrollBarWidget>
       
   350     	( KScrollBarWidget, KVerScrollbarWidgetName, *iViewWidget, 0 );
       
   351     	
       
   352     IAlfScrollBarModel* verScrollModel = widgetFactory.createModel<IAlfScrollBarModel> (KScrollBarModel);
       
   353         
       
   354     iScrollWidget->setModel( verScrollModel );
       
   355     
       
   356     IAlfElement* vertBaseElement =(iScrollWidget->control()->findElement ("BaseElement"));
       
   357 
       
   358     iScrollbarDefaultBaseElement=static_cast<IAlfScrollBarDefaultBaseElement*> (
       
   359         vertBaseElement->makeInterface (IAlfScrollBarDefaultBaseElement::type() ) );
       
   360   
       
   361 	if(iScrollWidget) 
       
   362 		{		
       
   363         if(iScrollbarDefaultBaseElement)
       
   364 	        {
       
   365 			iCloudControl->InitializeScrollBar(iScrollWidget);    
       
   366 	        }
       
   367         (iScrollWidget->control())->addEventHandler (iCloudControl);
       
   368 		}		
       
   369 
       
   370     SetScrollBarRect();
       
   371     
       
   372      //acquire the focus so as to get events to your control instead of widgets
       
   373     iCloudControl->AcquireFocus();
       
   374     }
       
   375 // ---------------------------------------------------------------------------
       
   376 // SetScrollBarRect()
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CGlxCloudViewImp::SetScrollBarRect()
       
   380     {
       
   381     TRect rct  = ClientRect();
       
   382     rct.iBr.iX = rct.iBr.iX - iScrollPaneHandle.iW;
       
   383     // anchor points for cloud control
       
   384     iAnchorlayout->SetAnchor(
       
   385             EAlfAnchorTopLeft, 
       
   386             0,
       
   387             EAlfAnchorOriginLeft,
       
   388             EAlfAnchorOriginTop,
       
   389             EAlfAnchorMetricAbsolute,
       
   390             EAlfAnchorMetricAbsolute,
       
   391             TAlfTimedPoint(0,0));
       
   392 
       
   393     iAnchorlayout->SetAnchor(
       
   394             EAlfAnchorBottomRight, 
       
   395             0,
       
   396             EAlfAnchorOriginLeft,
       
   397             EAlfAnchorOriginTop,
       
   398             EAlfAnchorMetricAbsolute,
       
   399             EAlfAnchorMetricAbsolute,
       
   400             TAlfTimedPoint(ClientRect().iBr.iX - iScrollPaneHandle.iW,(ClientRect().iBr.iY  - ClientRect().iTl.iY)));
       
   401 
       
   402     // anchor points for scrollbar widget
       
   403     iAnchorlayout->SetAnchor(
       
   404             EAlfAnchorTopLeft, 
       
   405             1,
       
   406             EAlfAnchorOriginLeft,
       
   407             EAlfAnchorOriginTop,
       
   408             EAlfAnchorMetricAbsolute,
       
   409             EAlfAnchorMetricAbsolute,
       
   410             TAlfTimedPoint(ClientRect().iBr.iX - iScrollPaneHandle.iW,0));
       
   411 
       
   412     iAnchorlayout->SetAnchor(
       
   413             EAlfAnchorBottomRight, 
       
   414             1,
       
   415             EAlfAnchorOriginLeft,
       
   416             EAlfAnchorOriginTop,
       
   417             EAlfAnchorMetricAbsolute,
       
   418             EAlfAnchorMetricAbsolute,
       
   419             TAlfTimedPoint(ClientRect().iBr.iX ,(ClientRect().iBr.iY  - ClientRect().iTl.iY)));
       
   420 
       
   421     iAnchorlayout->UpdateChildrenLayout(0);
       
   422     }
       
   423