photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlersend.cpp
changeset 0 4e91876724a2
child 3 9a9c174934f5
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:    Send commmand handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "glxcommandhandlersend.h"
       
    23 
       
    24 
       
    25 //  EXTERNAL INCLUDES
       
    26 #include <utf.h>							// for CnvUtfConverter
       
    27 #include <sendui.h>							// for CSendui
       
    28 #include <Sendnorm.rsg>						// for CSendui resources
       
    29 #include <SendUiConsts.h>					// for CSendui plugin type constants
       
    30 #include <CMessageData.h>					// for CMessageData
       
    31 #include <coemain.h>						// for CCoeEnv
       
    32 #include <StringLoader.h>					// for CStringLoader
       
    33 #include <bautils.h>						// for BaflUtils
       
    34 #include <data_caging_path_literals.hrh> 	// for directory and file names
       
    35 
       
    36 //  INTERNAL INCLUDES
       
    37 #include <glxcommandhandlers.hrh>			// for EGlxCmdUpload
       
    38 #include <mglxmedialistprovider.h>
       
    39 #include <mglxmedialist.h>
       
    40 #include <glxscreenfurniture.h>             // for ScreenFurniture toolbar
       
    41 #include <glxuistd.h>						// for KGlxUiUtilitiesResource
       
    42 #include <glxuiutility.h>					// for HuiUtility
       
    43 #include <glxlog.h>							// for debug logging
       
    44 #include <glxattributecontext.h>			// for CGlxDefaultAttributeContext
       
    45 #include <glxattributeretriever.h>			// for GlxAttributeRetriever
       
    46 #include <glxuiutilities.rsg>				// for R_GLX_TOOLTIP_SEND
       
    47 #include <glxfetchcontextremover.h>         // for TGlxFetchContextRemover 
       
    48 #include <glxresourceutilities.h>           // for CGlxResourceUtilities
       
    49 #include <glxicons.mbg>
       
    50 
       
    51 // LOCAL FUNCTIONS AND CONSTANTS
       
    52 namespace
       
    53 	{
       
    54 	const TInt KSendMsgBodySz = 0;
       
    55 	const TInt KSendMsgOverallSz = 1024; // KMaxStringLength from SendUi.h
       
    56 	// defined locally in the original code... @todo find a definition
       
    57 	const TUid KSendAsPostcardUID = { 0x101FF961 };	
       
    58 	}
       
    59 
       
    60 
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // Two-phased constructor.
       
    64 // ----------------------------------------------------------------------------
       
    65 EXPORT_C CGlxCommandHandlerSend* CGlxCommandHandlerSend::NewL(
       
    66 										MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem)
       
    67 	{
       
    68 	GLX_FUNC("CGlxCommandHandlerSend::NewL");
       
    69 	CGlxCommandHandlerSend* self = 
       
    70 			new (ELeave) CGlxCommandHandlerSend(aMediaListProvider, aHasToolbarItem);
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL();
       
    73 	CleanupStack::Pop(self);
       
    74 	return self;
       
    75 	}
       
    76 
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // C++ default constructor 
       
    80 // ----------------------------------------------------------------------------
       
    81 CGlxCommandHandlerSend::CGlxCommandHandlerSend(MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem )
       
    82 					   :CGlxMediaListCommandHandler(aMediaListProvider, aHasToolbarItem)
       
    83 	{
       
    84 	// nothing to do
       
    85 	}			
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // Symbian 2nd phase constructor can leave.
       
    89 // ----------------------------------------------------------------------------
       
    90 void CGlxCommandHandlerSend::ConstructL()
       
    91 	{
       
    92 	GLX_FUNC("CGlxCommandHandlerSend::ConstructL");
       
    93 	
       
    94 	iUiUtility = CGlxUiUtility::UtilityL();
       
    95 	iSendUi = CSendUi::NewL();
       
    96 	
       
    97 	LoadRscFileL();
       
    98 	
       
    99 	// add the Send command
       
   100    	TCommandInfo info(EGlxCmdSend);
       
   101     info.iMinSelectionLength = 1;
       
   102     info.iMaxSelectionLength = KMaxTInt;
       
   103    	AddCommandL(info);
       
   104 	}	
       
   105 	
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // Destructor
       
   109 // ----------------------------------------------------------------------------
       
   110 EXPORT_C CGlxCommandHandlerSend::~CGlxCommandHandlerSend()
       
   111 	{
       
   112 	GLX_FUNC("CGlxCommandHandlerSend::~CGlxCommandHandlerSend");
       
   113 	if (iResourceOffset)
       
   114         {
       
   115         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
   116         }
       
   117 	
       
   118 	if (iUiUtility)
       
   119         {
       
   120         iUiUtility->Close();
       
   121         }
       
   122     delete iSendUi;    
       
   123 	}
       
   124 	
       
   125 	
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // ExecuteL
       
   129 // ----------------------------------------------------------------------------
       
   130 TBool CGlxCommandHandlerSend::DoExecuteL(TInt aCommandId, 
       
   131 													MGlxMediaList& /*aList*/)
       
   132 	{
       
   133     GLX_FUNC("CGlxCommandHandlerSend::DoExecuteL");
       
   134 	
       
   135     if (aCommandId == EGlxCmdSend)
       
   136         {
       
   137         SendSelectedItemsL();
       
   138         return ETrue;
       
   139         }
       
   140     return EFalse;
       
   141 	}
       
   142 
       
   143 
       
   144 
       
   145 // ----------------------------------------------------------------------------
       
   146 // DoActivateL
       
   147 // ----------------------------------------------------------------------------
       
   148 void CGlxCommandHandlerSend::DoActivateL(TInt aViewId)
       
   149 	{
       
   150     GLX_FUNC("CGlxCommandHandlerSend::DoActivateL");
       
   151 
       
   152     iViewId = aViewId;
       
   153 	MGlxMediaList& mediaList = MediaList();
       
   154                   
       
   155                      // TAP2GenericPluginParams::EGenericStdIconSend,
       
   156    //                 TAP2GenericPluginParams::EGenericStdIconSendMask);
       
   157 
       
   158 	// need to check the category attribute for image or video
       
   159     iAttributeContext = CGlxDefaultAttributeContext::NewL();
       
   160     iAttributeContext->AddAttributeL(TMPXAttribute(KMPXMediaGeneralCategory));
       
   161     iAttributeContext->AddAttributeL(TMPXAttribute(KMPXMediaGeneralUri));
       
   162     mediaList.AddContextL( iAttributeContext, KGlxFetchContextPriorityLow );
       
   163     
       
   164     mediaList.AddMediaListObserverL(this);
       
   165 	}
       
   166 
       
   167 
       
   168 
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // Deactivate
       
   172 // ----------------------------------------------------------------------------
       
   173 void CGlxCommandHandlerSend::Deactivate()
       
   174     {
       
   175     GLX_FUNC("CGlxCommandHandlerSend::Deactivate");
       
   176     if (iAttributeContext)
       
   177         {
       
   178         MediaList().RemoveContext(iAttributeContext);
       
   179         delete iAttributeContext;
       
   180         iAttributeContext = NULL;
       
   181         }
       
   182         
       
   183     MediaList().RemoveMediaListObserver(this);    
       
   184     }	
       
   185 	
       
   186 
       
   187 
       
   188 // ----------------------------------------------------------------------------
       
   189 // OfferKeyEventL
       
   190 // ----------------------------------------------------------------------------
       
   191 TKeyResponse CGlxCommandHandlerSend::OfferKeyEventL(const TKeyEvent& aKeyEvent, 
       
   192 															TEventCode aType)
       
   193 	{
       
   194     // Handle the send key
       
   195 	if (aKeyEvent.iCode == EKeyYes && aType == EEventKey)
       
   196 		{
       
   197 		SendSelectedItemsL();
       
   198 		return EKeyWasConsumed;
       
   199 		}
       
   200 	return EKeyWasNotConsumed;		
       
   201 	}
       
   202 
       
   203 
       
   204 // ----------------------------------------------------------------------------
       
   205 // HandleFocusChangedL
       
   206 // ----------------------------------------------------------------------------
       
   207 void CGlxCommandHandlerSend::HandleFocusChangedL(
       
   208                     NGlxListDefs::TFocusChangeType /*aType*/, 
       
   209 					TInt aNewIndex, TInt /*aOldIndex*/, MGlxMediaList* aList)
       
   210 	{
       
   211 	GLX_FUNC("CGlxCommandHandlerSend::HandleFocusChangedL");
       
   212 	if ( aList && aNewIndex >= 0 )
       
   213 		{
       
   214 		const CGlxMedia* media = aList->Item(aNewIndex).Properties();  
       
   215 		if (media)
       
   216 			{// show the active palette send item
       
   217 		//    iUiUtility->ScreenFurniture().ShowActivePaletteItemL(iViewId, 
       
   218 		//				EGlxCmdSend, IsValidTypeL(*media));	
       
   219 			}
       
   220 		}	
       
   221 	}
       
   222 
       
   223             
       
   224 
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // SelectedFilesLC
       
   228 // ----------------------------------------------------------------------------
       
   229 CMessageData* CGlxCommandHandlerSend::SelectedFilesLC()
       
   230 	{
       
   231 	GLX_FUNC("CGlxCommandHandlerSend::SelectedFilesLC");
       
   232 
       
   233 	// get the focused item from the media list
       
   234 	MGlxMediaList& mediaList = MediaList();
       
   235 	
       
   236 	CMessageData* messageData = CMessageData::NewLC();    
       
   237 	
       
   238 	// retrieve the file name and path
       
   239 	CGlxDefaultAttributeContext* attributeContext = 
       
   240 										CGlxDefaultAttributeContext::NewL();
       
   241     CleanupStack::PushL(attributeContext);
       
   242     attributeContext->AddAttributeL(TMPXAttribute(KMPXMediaGeneralUri));
       
   243     mediaList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
       
   244     
       
   245     // TGlxContextRemover will remove the context when it goes out of scope
       
   246     // Used here to avoid a trap and still have safe cleanup   
       
   247     TGlxFetchContextRemover contextRemover (attributeContext, mediaList);
       
   248     CleanupClosePushL( contextRemover );
       
   249     
       
   250 	User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, 
       
   251 															mediaList, ETrue));															
       
   252 	// context off the list
       
   253     CleanupStack::PopAndDestroy( &contextRemover );														
       
   254 
       
   255 	// if there are multiple media items, filter the postcard plugin
       
   256 	iFilterOutPlugin = (mediaList.SelectionCount() > 1);
       
   257 	
       
   258 	// extract the filename from selected items in the media list and add it 
       
   259 	// to the messageData to be returned
       
   260     TGlxSelectionIterator iterator;
       
   261     iterator.SetToFirst(&mediaList);
       
   262 	TInt index = KErrNotFound;
       
   263 
       
   264 	while ((index = iterator++) != KErrNotFound)
       
   265 		{
       
   266 		// does not return ownership.
       
   267 	   	const CGlxMedia* media = mediaList.Item(index).Properties();
       
   268 	   	if(media)
       
   269 	   		{
       
   270 	   		if(media->IsSupported(KMPXMediaGeneralUri) && IsValidTypeL(*media))
       
   271 	    		{
       
   272 	    		messageData->AppendAttachmentL(
       
   273 	    								media->ValueText(KMPXMediaGeneralUri));
       
   274 	   			}
       
   275 	   		}
       
   276 	   	else
       
   277 	   		{
       
   278 		    User::Leave(KErrNotReady);
       
   279 		    }	
       
   280 		}
       
   281 
       
   282 	CleanupStack::PopAndDestroy(attributeContext);
       
   283 	return messageData;
       
   284 	}// contextRemover goes out of scope and removes the context from media list
       
   285 
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // IsValidTypeL
       
   289 // ----------------------------------------------------------------------------
       
   290 TBool CGlxCommandHandlerSend::IsValidTypeL(const CGlxMedia& aMedia) 
       
   291 	{
       
   292 	GLX_FUNC("CGlxCommandHandlerSend::IsValidTypeL");
       
   293 	// ensure the category attribute is supported by the current media item
       
   294     if (aMedia.IsSupported(KMPXMediaGeneralCategory))
       
   295         {
       
   296         switch(aMedia.ValueTObject<TInt>(KMPXMediaGeneralCategory))
       
   297         	{
       
   298     		case EMPXVideo:
       
   299     			{
       
   300     			// don't use the postcard plugin to send video
       
   301     			iFilterOutPlugin = ETrue;
       
   302     			return ETrue;
       
   303     			}
       
   304     		case EMPXImage:
       
   305     			{
       
   306 	            return ETrue;
       
   307     	        }
       
   308     	    default:    
       
   309     	    	{
       
   310             	return EFalse;
       
   311             	}
       
   312         	}
       
   313         }
       
   314 	return EFalse;
       
   315 	}
       
   316 	
       
   317 
       
   318 // ----------------------------------------------------------------------------
       
   319 // SendSelectedItemsL
       
   320 // ----------------------------------------------------------------------------
       
   321 void CGlxCommandHandlerSend::SendSelectedItemsL()
       
   322 	{
       
   323 	GLX_FUNC("CGlxCommandHandlerSend::SendSelectedItemsL");
       
   324     // retrieve the current files name and location
       
   325     CMessageData* msgData = SelectedFilesLC();
       
   326     HBufC* title = StringLoader::LoadLC(R_QTN_LGAL_POPUP_SEND);
       
   327 	
       
   328 	// filterOutPlugins is a list of component uids that should NOT be used to 
       
   329 	// send the media file. if a video file was selected or multiple files 
       
   330 	// were selected, filter out the option to send as a postcard
       
   331     CArrayFix<TUid>* filterOutPlugins =new (ELeave) CArrayFixFlat<TUid>(1);
       
   332     CleanupStack::PushL(filterOutPlugins);
       
   333 
       
   334 	if(iFilterOutPlugin)
       
   335 		{
       
   336 		filterOutPlugins->AppendL(KSendAsPostcardUID);
       
   337 		}
       
   338 		
       
   339 	// If Device supports text-entry mode only in portrait,
       
   340 	// then the orientation has to be forced to EGlxOrientationTextEntry 
       
   341 	// before launching the Send pop-up.   
       
   342 	
       
   343  	if(iUiUtility->IsPenSupported())
       
   344 		{
       
   345 		iUiUtility->SetAppOrientationL( EGlxOrientationDefault );
       
   346 		}
       
   347 	// Trap the send call to ensure the orientation is reverted
       
   348 	TRAP_IGNORE( iSendUi->ShowQueryAndSendL( msgData, Capabilities(),
       
   349 	                filterOutPlugins, KNullUid, ETrue, *title ) );
       
   350 		
       
   351 	CleanupStack::PopAndDestroy(filterOutPlugins);
       
   352 	CleanupStack::PopAndDestroy(title);
       
   353 	CleanupStack::PopAndDestroy(msgData);
       
   354 	}
       
   355 	
       
   356 
       
   357 
       
   358 // ----------------------------------------------------------------------------
       
   359 // LoadRscFileL
       
   360 // ----------------------------------------------------------------------------
       
   361 void CGlxCommandHandlerSend::LoadRscFileL()
       
   362 	{
       
   363 	GLX_FUNC("CGlxCommandHandlerSend::LoadRscFileL");
       
   364 
       
   365 	TParse parse;
       
   366     parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL);
       
   367     TFileName resourceFile;
       
   368     resourceFile.Append(parse.FullName());
       
   369     CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
       
   370     CCoeEnv* env = CCoeEnv::Static(); 
       
   371    	iResourceOffset = env->AddResourceFileL(resourceFile);
       
   372 	}
       
   373 
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // Capabilities
       
   377 // ----------------------------------------------------------------------------
       
   378 TSendingCapabilities CGlxCommandHandlerSend::Capabilities()
       
   379 	{
       
   380 	GLX_FUNC("CGlxCommandHandlerSend::Capabilities");
       
   381 	return TSendingCapabilities (KSendMsgBodySz, KSendMsgOverallSz,
       
   382         						TSendingCapabilities::ESupportsAttachments);
       
   383 	}
       
   384 
       
   385 	
       
   386 // ----------------------------------------------------------------------------
       
   387 // PopulateToolbar
       
   388 // ----------------------------------------------------------------------------
       
   389 //
       
   390 void CGlxCommandHandlerSend::PopulateToolbarL()
       
   391 	{
       
   392 	GLX_FUNC("CGlxCommandHandlerSend::PopulateToolbar");
       
   393 	
       
   394 	iUiUtility->ScreenFurniture()->SetTooltipL( EGlxCmdSend, CAknButton::EPositionLeft );
       
   395 	}
       
   396 // End of file