engine/collectionframework/plugins/glxcollectionplugincamera/src/glxcollectionplugincamera.cpp
changeset 23 74c9f037fd5d
child 71 27f2d7aec52a
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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:   This class browses file system
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "glxcollectionplugincamera.h"
       
    23 
       
    24 #include <e32cmn.h>
       
    25 #include <mpxcollectionpath.h>
       
    26 #include <mpxcollectionpluginobserver.h>
       
    27 #include <mpxcmn.h>
       
    28 #include <mpxcollectionmessagedefs.h>
       
    29 #include <glxcollectionmessagedefs.h>  
       
    30 #include <mpxmediageneraldefs.h>
       
    31 #include <mpxmediacontainerdefs.h>
       
    32 #include <mpxmedia.h>
       
    33 #include <mpxmediaarray.h>
       
    34 #include <glxmediageneraldefs.h>
       
    35 #include <glxcollectiongeneraldefs.h>
       
    36 #include <glxplugincamera.rsg>
       
    37 #include <StringLoader.h>
       
    38 #include <glxmediacollectioninternaldefs.h>
       
    39 #include <glxpanic.h>
       
    40 #include <mglxdatasource.h>
       
    41 #include <glxrequest.h>
       
    42 #include <glxidlistrequest.h>
       
    43 #include <glxfilterfactory.h>
       
    44 #include <glxlog.h>
       
    45 #include <glxtracer.h>
       
    46 
       
    47 #include "glxcollectionplugincamera.hrh"
       
    48 
       
    49 /**
       
    50  * @internal reviewed 14/06/2007 by Alex Birkett
       
    51  */
       
    52 
       
    53 // CONSTANTS
       
    54 
       
    55 // ============================ LOCAL FUNCTIONS ==============================
       
    56     
       
    57 // ============================ MEMBER FUNCTIONS ==============================
       
    58 // ----------------------------------------------------------------------------
       
    59 // Two-phased constructor.
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 CGlxCollectionPluginCamera* CGlxCollectionPluginCamera::NewL(TAny* aObs)
       
    63     {
       
    64     CGlxCollectionPluginCamera* self = new (ELeave) CGlxCollectionPluginCamera(
       
    65                             static_cast<MMPXCollectionPluginObserver*>(aObs));
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL();
       
    68 	CleanupStack::Pop(self);
       
    69 	return self;
       
    70     }
       
    71 
       
    72 // ----------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 CGlxCollectionPluginCamera::~CGlxCollectionPluginCamera()
       
    77     {
       
    78     }
       
    79 
       
    80 // ----------------------------------------------------------------------------
       
    81 // Constructor
       
    82 // ----------------------------------------------------------------------------
       
    83 //
       
    84 CGlxCollectionPluginCamera::CGlxCollectionPluginCamera(
       
    85     MMPXCollectionPluginObserver* aObs)
       
    86     {
       
    87     iObs = aObs;
       
    88     }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // ConstructL
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 void CGlxCollectionPluginCamera::ConstructL()
       
    95     {
       
    96     iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this);
       
    97 	}
       
    98 // ----------------------------------------------------------------------------
       
    99 // CpiAttributeAdditionalAttributes
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 void CGlxCollectionPluginCamera::CpiAttributeAdditionalAttributes(const TMPXAttribute& aCpiAttribute, RArray<TMPXAttribute>& aAttributeArray)
       
   103 	{
       
   104     TRACER("CGlxCollectionPluginCamera::CpiAttributeAdditionalAttributes");
       
   105     // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here as all the other attributes
       
   106     // are reading straight from resource files KGlxMediaCollectionPluginSpecificSubTitle 
       
   107     // requires a image and the Video count in the collection
       
   108     
       
   109 	if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle)
       
   110 		{
       
   111 		// need to add the usage count. but check first if it is already present
       
   112 		TInt attrCount = aAttributeArray.Count();
       
   113 		
       
   114 		TBool found = EFalse;
       
   115 		
       
   116 #ifdef GLX_SUB_TITLE_REL8
       
   117 		
       
   118 		TBool videofound = EFalse;
       
   119 		TBool imagefound = EFalse;		
       
   120 
       
   121 		for ( TInt index = 0 ; index < attrCount ; index++)
       
   122 			{
       
   123 			if (aAttributeArray[index] == KMPXMediaGeneralCount)
       
   124 				{
       
   125 				found = ETrue;	            
       
   126 				}
       
   127 			else if (aAttributeArray[index] == KGlxMediaItemTypeVideo)
       
   128 				{
       
   129 				videofound = ETrue;	            
       
   130 				}
       
   131 			else if(aAttributeArray[index] == KGlxMediaItemTypeImage)	            
       
   132 				{
       
   133 				imagefound = ETrue;
       
   134 				}
       
   135 				
       
   136 		if (!videofound)
       
   137 			{
       
   138 			aAttributeArray.Append(KGlxMediaItemTypeVideo);
       
   139 			}
       
   140 		if (!imagefound)	        
       
   141 			{
       
   142 			aAttributeArray.Append(KGlxMediaItemTypeImage);
       
   143 			}
       
   144 		if (!found)
       
   145 			{
       
   146 			aAttributeArray.Append(KMPXMediaGeneralCount);
       
   147 			}
       
   148 				
       
   149 #else
       
   150 
       
   151 	for ( TInt index = 0 ; index < attrCount ; index++)
       
   152 			{
       
   153 			if (aAttributeArray[index] == KMPXMediaGeneralCount)
       
   154 				{
       
   155 				found = ETrue;	            
       
   156 				}			
       
   157 			}			
       
   158 		if (!found)
       
   159 			{
       
   160 			aAttributeArray.Append(KMPXMediaGeneralCount);
       
   161 			}       
       
   162 #endif						
       
   163 		}
       
   164 	}
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // HandleCpiAttributeResponseL
       
   168 // ----------------------------------------------------------------------------
       
   169 // 
       
   170 void CGlxCollectionPluginCamera::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> /* aMediaIds */)
       
   171 	{
       
   172     TRACER("CGlxCollectionPluginCamera::HandleCpiAttributeResponseL");
       
   173     
       
   174     _LIT(KResourceFile, "z:glxplugincamera.rsc");
       
   175 
       
   176 	TInt count = aCpiAttributes.Count();
       
   177 	
       
   178 	for (TInt index = 0; index < count ; index++)
       
   179 	    {
       
   180 	    const TMPXAttribute attr = aCpiAttributes[index];
       
   181 	    
       
   182 	    if (attr == KGlxMediaCollectionPluginSpecificSubTitle)
       
   183 	        {
       
   184 	        GLX_LOG_INFO("Attribute is :Subtitle");
       
   185 	        
       
   186 	        if (!aResponse->IsSupported(KMPXMediaGeneralCount))
       
   187 	            {
       
   188 	            User::Leave(KErrNotSupported);
       
   189 	            }
       
   190 	                	            
       
   191             else
       
   192 				{
       
   193 				TInt usageCount = aResponse->ValueTObjectL<TInt>(KMPXMediaGeneralCount);
       
   194 				
       
   195 				HBufC* tempTitle = NULL;
       
   196 
       
   197 #ifdef GLX_SUB_TITLE_REL8
       
   198 
       
   199 			if (!aResponse->IsSupported(KGlxMediaItemTypeImage))
       
   200 	            {
       
   201 	            User::Leave(KErrNotSupported);
       
   202 	            }
       
   203 	            
       
   204 			if (!aResponse->IsSupported(KGlxMediaItemTypeVideo))
       
   205 	            {
       
   206 	            User::Leave(KErrNotSupported);
       
   207 	            }
       
   208 
       
   209 				TInt videoCount = aResponse->ValueTObjectL<TInt>(KGlxMediaItemTypeVideo);
       
   210 
       
   211 				TInt imageCount = aResponse->ValueTObjectL<TInt>(KGlxMediaItemTypeImage);
       
   212 
       
   213 				//No Images or Videos
       
   214 				if ((0 == videoCount) && (0 == imageCount ))
       
   215 					{	
       
   216 					GLX_LOG_INFO("ImageCount and VideoCount is 0");
       
   217 									
       
   218 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_NO_IMAGE_NO_VIDEO);
       
   219 					aResponse->SetTextValueL(attr, *tempTitle);	
       
   220 					}
       
   221 
       
   222 				// 1 Image and multi/0 Videos                		
       
   223 				else if (1 == imageCount) 
       
   224 					{
       
   225 					GLX_LOG_INFO1("ImageCount is 0 and VideoCount is %d",videoCount);
       
   226 					
       
   227 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_ONE_IMAGE_MULTI_VIDEO);
       
   228 
       
   229 					TPtr formatString = tempTitle->Des();
       
   230 
       
   231 					// Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   232 					HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   233 					TPtr ptr = title->Des();
       
   234 
       
   235 					StringLoader::Format(ptr, formatString, -1, videoCount);
       
   236 
       
   237 					// Set the title in the response.	
       
   238 					aResponse->SetTextValueL(attr, *title);
       
   239 
       
   240 					CleanupStack::PopAndDestroy(title);
       
   241 					}
       
   242 
       
   243 				// Multi/0 Image and 1 Video					
       
   244 				else if (1 == videoCount)
       
   245 					{
       
   246 					GLX_LOG_INFO1("ImageCount is %d and VideoCount is 0",imageCount);
       
   247 					
       
   248 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_MULTI_IMAGE_ONE_VIDEO);                	
       
   249 
       
   250 					TPtr formatString = tempTitle->Des();
       
   251 
       
   252 					// Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   253 					HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   254 					TPtr ptr = title->Des();
       
   255 
       
   256 					StringLoader::Format(ptr, formatString, -1, imageCount);
       
   257 
       
   258 					// Set the title in the response.	
       
   259 					aResponse->SetTextValueL(attr, *title);
       
   260 
       
   261 					CleanupStack::PopAndDestroy(title);
       
   262 					}
       
   263 
       
   264 				// Multi Image and Multi Video
       
   265 				else 
       
   266 					{
       
   267 					GLX_LOG_INFO2("ImageCount is %d,VideoCount is %d",imageCount,videoCount);
       
   268 					
       
   269 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_MULTI_IMAGE_MULTI_VIDEO);                	
       
   270 					TPtr formatString = tempTitle->Des();	
       
   271 
       
   272 					HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   273 					TPtr ptr = title->Des();
       
   274 
       
   275 					HBufC* title1 = HBufC::NewLC(formatString.Length() + 10);
       
   276 					TPtr ptr1 = title1->Des();
       
   277 
       
   278 					StringLoader::Format(ptr, formatString, 0, imageCount);
       
   279 					StringLoader::Format(ptr1, ptr, 1, videoCount);	
       
   280 
       
   281 					// Set the title in the response.	
       
   282 					aResponse->SetTextValueL(attr, *title1);
       
   283 
       
   284 					CleanupStack::PopAndDestroy(title1);
       
   285 					CleanupStack::PopAndDestroy(title);
       
   286 					}	
       
   287 				CleanupStack::PopAndDestroy(tempTitle);
       
   288 
       
   289 #else
       
   290 				if(0 == usageCount)
       
   291             		{
       
   292                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_NO_IMAGE_NO_VIDEO);                	
       
   293                 	// Set the title in the response.
       
   294             		aResponse->SetTextValueL(attr, *tempTitle);  
       
   295             		CleanupStack::PopAndDestroy(tempTitle);
       
   296             		continue;                	
       
   297             		}
       
   298 				// Get the format string
       
   299 				else if (1 == usageCount)
       
   300                     {
       
   301                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_SINGLE);
       
   302                     }
       
   303                 else
       
   304                     {
       
   305                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_CAMERA_SUB_TITLE_MULTI);
       
   306                     }
       
   307                 TPtr formatString = tempTitle->Des();
       
   308                 
       
   309                 // Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   310                 HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   311                 TPtr ptr = title->Des();
       
   312                 StringLoader::Format(ptr, formatString, -1, usageCount);
       
   313                 
       
   314                 // Set the title in the response.
       
   315                 aResponse->SetTextValueL(attr, *title);    
       
   316 
       
   317                 CleanupStack::PopAndDestroy(title);
       
   318                 CleanupStack::PopAndDestroy(tempTitle);	
       
   319 #endif                			
       
   320 				}
       
   321 	        }
       
   322 	        
       
   323 	    else if (attr == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle)
       
   324 	        {
       
   325 	        GLX_LOG_INFO("Attribute is :MediaPopupTitle");
       
   326 	        
       
   327 	        User::Leave(KErrNotSupported);
       
   328 	        }
       
   329 	    else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle)
       
   330 	        {
       
   331 	        GLX_LOG_INFO("Attribute is :NewMediaItemTitle");
       
   332 	        
       
   333 	        User::Leave(KErrNotSupported);
       
   334 	        }
       
   335 	    else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle)
       
   336 	        {
       
   337 	        GLX_LOG_INFO("Attribute is :DefaultMediaTitle");
       
   338 	        
       
   339 	        User::Leave(KErrNotSupported);
       
   340 	        }
       
   341 	    else if (attr == KMPXMediaGeneralTitle)
       
   342 	        {
       
   343 	        GLX_LOG_INFO("Attribute is :GenrealTitle");
       
   344 	        
       
   345 	        HBufC* title = LoadLocalizedStringLC(KResourceFile, R_CAMERA_GENERAL_TITLE);
       
   346             // Set the title in the response.
       
   347             aResponse->SetTextValueL(attr, *title);  
       
   348             CleanupStack::PopAndDestroy(title); 
       
   349 	        }
       
   350 	    }
       
   351 	aResponse->Delete(KGlxMediaItemTypeImage);
       
   352 	aResponse->Delete(KGlxMediaItemTypeVideo);
       
   353 	    
       
   354 	}
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // IsUpdateMessageIgnoredL
       
   358 // ----------------------------------------------------------------------------
       
   359 // 
       
   360 TBool CGlxCollectionPluginCamera::IsUpdateMessageIgnoredL(CMPXMessage& /*aMessage*/)
       
   361 	{
       
   362 	TRACER("CGlxCollectionPluginCamera::IsUpdateMessageIgnoredL");
       
   363 	
       
   364 	TBool ignore = EFalse;
       
   365 	return ignore;
       
   366 	}
       
   367 	
       
   368 // ----------------------------------------------------------------------------
       
   369 // DefaultFilter
       
   370 // ----------------------------------------------------------------------------
       
   371 // 
       
   372 TGlxFilterProperties CGlxCollectionPluginCamera::DefaultFilter(TInt aLevel)
       
   373     {
       
   374     TRACER("CGlxCollectionPluginDownloads::DefaultFilter");
       
   375     
       
   376     __ASSERT_DEBUG(( (aLevel == KGlxCollectionRootLevel) || (aLevel == KGlxCollectionRootLevel+1) 
       
   377     || (aLevel == KGlxCollectionRootLevel+2) ), Panic(EGlxPanicInvalidPathLevel));
       
   378     TGlxFilterProperties filterProperties;
       
   379     
       
   380     filterProperties.iSortOrder = EGlxFilterSortOrderModifiedDate;
       
   381     filterProperties.iSortDirection = EGlxFilterSortDirectionDescending;
       
   382     
       
   383    filterProperties.iOrigin = EGlxFilterOriginCamera;
       
   384 
       
   385     return filterProperties;
       
   386     }	
       
   387     
       
   388 // End of file