photosgallery/collectionframework/plugins/glxcollectionpluginalbums/src/glxcollectionpluginalbums.cpp
changeset 0 4e91876724a2
child 1 9ba538e329bd
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 #include <e32cmn.h>
       
    23 #include <mpxcollectionpath.h>
       
    24 #include <mpxcollectionpluginobserver.h>
       
    25 #include <mpxcmn.h>
       
    26 #include <mpxcollectionmessagedefs.h>
       
    27 #include <glxcollectionmessagedefs.h>
       
    28 #include <mpxmediageneraldefs.h>
       
    29 #include <mpxmediacontainerdefs.h>
       
    30 #include <mpxmedia.h>
       
    31 #include <mpxmediaarray.h>
       
    32 #include <glxpluginalbums.rsg>
       
    33 #include <StringLoader.h>
       
    34 #include <glxtracer.h>
       
    35 
       
    36 #include "glxcollectionpluginalbums.h"
       
    37 #include "glxcollectionpluginalbums.hrh"
       
    38 #include <glxmediageneraldefs.h>
       
    39 #include <glxmediacollectioninternaldefs.h>
       
    40 #include <glxcollectiongeneraldefs.h>
       
    41 
       
    42 #include <glxpanic.h>
       
    43 #include <mglxdatasource.h>
       
    44 #include <glxrequest.h>
       
    45 #include <glxidlistrequest.h>
       
    46 #include <glxfilterfactory.h>
       
    47 #include <glxlog.h>
       
    48 
       
    49 // CONSTANTS
       
    50 const TInt KFavoriteAlbumId = 1 ;
       
    51 const TInt KCapturedAlbumId = 2 ;
       
    52 
       
    53 
       
    54 /**
       
    55  * @internal reviewed 14/06/2007 by Alex Birkett
       
    56  */
       
    57 
       
    58 
       
    59 // ============================ LOCAL FUNCTIONS ==============================
       
    60 
       
    61 // ============================ MEMBER FUNCTIONS ==============================
       
    62 // ----------------------------------------------------------------------------
       
    63 // Two-phased constructor.
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CGlxCollectionPluginAlbums* CGlxCollectionPluginAlbums::NewL(TAny* aObs)
       
    67     {
       
    68     CGlxCollectionPluginAlbums* self = new (ELeave) CGlxCollectionPluginAlbums(
       
    69                             static_cast<MMPXCollectionPluginObserver*>(aObs));
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CGlxCollectionPluginAlbums::~CGlxCollectionPluginAlbums()
       
    81     {
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // Constructor
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CGlxCollectionPluginAlbums::CGlxCollectionPluginAlbums(
       
    89     MMPXCollectionPluginObserver* aObs)
       
    90     {
       
    91     iObs = aObs;
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // ConstructL
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 void CGlxCollectionPluginAlbums::ConstructL()
       
    99     {
       
   100     iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this);
       
   101     }
       
   102 
       
   103 void CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributes(const TMPXAttribute& aCpiAttribute, RArray<TMPXAttribute>& aAttributeArray)
       
   104     {
       
   105     TRACER("CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributes");
       
   106     // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here as all the others are reading straight from resource files
       
   107     // KGlxMediaCollectionPluginSpecificSubTitle requires a usage count
       
   108     if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle)
       
   109         {
       
   110         // need to add the usage count. but check first if it is already present
       
   111         TInt attrCount = aAttributeArray.Count();
       
   112         TBool found = EFalse;
       
   113         
       
   114         for ( TInt index = 0 ; index < attrCount ; index++)
       
   115             {
       
   116             if ( aAttributeArray[index] == KMPXMediaGeneralCount)
       
   117                 {
       
   118                 found = ETrue;
       
   119                 break;
       
   120                 }
       
   121             }
       
   122             
       
   123         if (!found)
       
   124             {
       
   125             aAttributeArray.Append(KGlxMediaCollectionInternalUsageCount);
       
   126             }
       
   127         }
       
   128     }
       
   129 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> aMediaIds)
       
   130     {
       
   131     TRACER("CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL");
       
   132     const TInt mediaIdCount = aMediaIds.Count();
       
   133     
       
   134     switch (mediaIdCount)
       
   135         {
       
   136     case 0:
       
   137         User::Leave(KErrNotSupported);
       
   138         break;
       
   139     case 1:
       
   140         HandleCpiAttributeResponseL(aResponse, aCpiAttributes, aMediaIds[0]);
       
   141         break;
       
   142     default:
       
   143             {
       
   144             // We have an array of CMPXMedia items
       
   145             
       
   146             if (TGlxMediaId(KGlxCollectionRootId) == aMediaIds[0])
       
   147                 {
       
   148                 User::Leave(KErrNotSupported);
       
   149                 }
       
   150                 
       
   151             CMPXMediaArray* mediaArray = aResponse->ValueCObjectL<CMPXMediaArray>(KMPXMediaArrayContents);
       
   152             CleanupStack::PushL(mediaArray);
       
   153 
       
   154             const TInt arrayCount = mediaArray->Count();
       
   155             
       
   156             // Sanity check
       
   157             if (arrayCount != mediaIdCount)
       
   158                 {
       
   159                 User::Leave(KErrArgument);
       
   160                 }
       
   161             
       
   162             for (TInt index = 0; index < arrayCount; index++)
       
   163                 {
       
   164                 HandleCpiAttributeResponseL((*mediaArray)[index], aCpiAttributes, aMediaIds[index]);
       
   165                 }
       
   166 
       
   167             aResponse->SetCObjectValueL(KMPXMediaArrayContents, mediaArray);
       
   168             CleanupStack::PopAndDestroy(mediaArray);
       
   169             }
       
   170         break;
       
   171         }
       
   172     }
       
   173 
       
   174 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TGlxMediaId aMediaId)
       
   175     {
       
   176     _LIT(KResourceFile, "z:glxpluginalbums.rsc");
       
   177 
       
   178     const TInt attribCount = aCpiAttributes.Count();
       
   179 
       
   180     for (TInt index = 0; index < attribCount ; index++)
       
   181         {
       
   182         const TMPXAttribute attr = aCpiAttributes[index];
       
   183         
       
   184         if (attr == KGlxMediaCollectionPluginSpecificSubTitle)
       
   185             {
       
   186             TInt usageCount = 0;
       
   187             if ( aResponse->IsSupported(KMPXMediaGeneralCount) )
       
   188                 {
       
   189                 usageCount = aResponse->ValueTObjectL<TInt>(KMPXMediaGeneralCount);
       
   190                 }
       
   191             else if ( aResponse->IsSupported(KGlxMediaCollectionInternalUsageCount) )
       
   192                 {
       
   193                 usageCount = aResponse->ValueTObjectL<TInt>(KGlxMediaCollectionInternalUsageCount);
       
   194                 aResponse->Delete(KGlxMediaCollectionInternalUsageCount);
       
   195                 }
       
   196             else
       
   197                 {
       
   198                 User::Leave(KErrNotSupported);
       
   199                 }
       
   200             HBufC* tempTitle = NULL;
       
   201             
       
   202             if (TGlxMediaId(KGlxCollectionRootId) == aMediaId)
       
   203             	{
       
   204                 if (1 == usageCount)
       
   205                 	{
       
   206                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_SUB_TITLE_SINGLE);
       
   207                     aResponse->SetTextValueL(attr, *tempTitle);  
       
   208                     CleanupStack::PopAndDestroy(tempTitle);
       
   209                     continue;                   
       
   210                 	}
       
   211                 else
       
   212                 	{
       
   213                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_SUB_TITLE_MULTI);
       
   214                 	}
       
   215             	}
       
   216             else
       
   217             	{
       
   218             	if(0 == usageCount)
       
   219             		{
       
   220                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_EMPTY);
       
   221                 	
       
   222                 	// Set the title in the response.
       
   223             		aResponse->SetTextValueL(attr, *tempTitle);  
       
   224             		CleanupStack::PopAndDestroy(tempTitle);
       
   225             		continue;                	
       
   226             		}            	
       
   227             	else if (1 == usageCount)
       
   228                 	{
       
   229                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_SINGLE);
       
   230                     aResponse->SetTextValueL(attr, *tempTitle);  
       
   231                     CleanupStack::PopAndDestroy(tempTitle);
       
   232                     continue;                   
       
   233                 	}
       
   234                 else
       
   235                 	{
       
   236                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_MULTI);
       
   237                 	}
       
   238             	}
       
   239             
       
   240             TPtr formatString = tempTitle->Des();
       
   241             
       
   242             // Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   243             HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   244             TPtr ptr = title->Des();
       
   245             StringLoader::Format(ptr, formatString, -1, usageCount);
       
   246             
       
   247             // Set the title in the response.
       
   248             aResponse->SetTextValueL(attr, *title);    
       
   249 
       
   250             CleanupStack::PopAndDestroy(title);
       
   251             CleanupStack::PopAndDestroy(tempTitle);
       
   252             }
       
   253         else if (attr == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle)
       
   254             {
       
   255             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_POPUP_TITLE);
       
   256             aResponse->SetTextValueL(attr, *title);  
       
   257             CleanupStack::PopAndDestroy(title); 
       
   258             }
       
   259         else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle)
       
   260             {
       
   261             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_TITLE);
       
   262             aResponse->SetTextValueL(attr, *title);  
       
   263             CleanupStack::PopAndDestroy(title); 
       
   264             }
       
   265         else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle)
       
   266             {
       
   267             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_DEFAULT_TITLE);
       
   268             aResponse->SetTextValueL(attr, *title);  
       
   269             CleanupStack::PopAndDestroy(title); 
       
   270             }
       
   271         else if (attr == KMPXMediaGeneralTitle)
       
   272             {
       
   273             if( TGlxMediaId(KGlxCollectionRootId) == aMediaId )
       
   274                 {
       
   275                 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_GENERAL_TITLE);
       
   276                 aResponse->SetTextValueL(attr, *title);  
       
   277                 CleanupStack::PopAndDestroy(title); 
       
   278                 }
       
   279             else
       
   280                 {
       
   281                 if( aResponse->IsSupported(KGlxMediaCollectionInternalSystemItemType) )
       
   282 					{
       
   283 					if( TGlxMediaId(KCapturedAlbumId) == aMediaId )
       
   284 						{
       
   285 						HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_CAMERA_TITLE);
       
   286 						aResponse->SetTextValueL(attr, *title);  
       
   287 						CleanupStack::PopAndDestroy(title);						
       
   288 						}
       
   289 					else if (TGlxMediaId(KFavoriteAlbumId) == aMediaId  )
       
   290 						{
       
   291 						HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_FAVORITES_TITLE);
       
   292 						aResponse->SetTextValueL(attr, *title);  
       
   293 						CleanupStack::PopAndDestroy(title);						
       
   294 						}
       
   295 					}                                             
       
   296                  aResponse->Delete(KGlxMediaCollectionInternalSystemItemType);                    
       
   297                 }
       
   298             }
       
   299         }
       
   300     }
       
   301 
       
   302 TBool CGlxCollectionPluginAlbums::IsUpdateMessageIgnored(CMPXMessage& /*aMessage*/)
       
   303     {
       
   304     TBool ignore = EFalse;
       
   305     return ignore;
       
   306     }
       
   307 
       
   308 TGlxFilterProperties CGlxCollectionPluginAlbums::DefaultFilter(TInt aLevel)
       
   309     {
       
   310     __ASSERT_DEBUG(( (aLevel == KGlxCollectionRootLevel) || (aLevel == KGlxCollectionAlbumLevel) 
       
   311     || (aLevel == KGlxCollectionAlbumContentsLevel) || (aLevel == KGlxCollectionAlbumContentsFSLevel)), 
       
   312     Panic(EGlxPanicInvalidPathLevel));
       
   313     TGlxFilterProperties filterProperties;
       
   314     filterProperties.iSortDirection = EGlxFilterSortDirectionAscending;
       
   315     switch(aLevel)
       
   316         {
       
   317         case KGlxCollectionRootLevel:
       
   318         case KGlxCollectionAlbumLevel: 
       
   319             {
       
   320             filterProperties.iPromoteSystemItems = ETrue;
       
   321             filterProperties.iSortOrder = EGlxFilterSortOrderAlphabetical;
       
   322             filterProperties.iItemType = EGlxFilterAlbum;
       
   323             break;
       
   324             }
       
   325         case KGlxCollectionAlbumContentsLevel:
       
   326             {
       
   327             filterProperties.iSortDirection = EGlxFilterSortDirectionDescending;
       
   328             }
       
   329         case KGlxCollectionAlbumContentsFSLevel:
       
   330             {
       
   331             filterProperties.iSortOrder = EGlxFilterSortOrderCaptureDate;
       
   332             break;
       
   333             }
       
   334         }
       
   335     return filterProperties;
       
   336     }
       
   337