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