photosgallery/collectionframework/plugins/glxcollectionpluginalbums/src/glxcollectionpluginalbums.cpp
branchRCL_3
changeset 47 f9e827349359
parent 35 420f6808bf21
equal deleted inserted replaced
35:420f6808bf21 47:f9e827349359
    98 void CGlxCollectionPluginAlbums::ConstructL()
    98 void CGlxCollectionPluginAlbums::ConstructL()
    99     {
    99     {
   100     iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this);
   100     iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this);
   101     }
   101     }
   102 
   102 
   103 void CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributes(const TMPXAttribute& aCpiAttribute, RArray<TMPXAttribute>& aAttributeArray)
   103 void CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributesL(
   104     {
   104         const TMPXAttribute& aCpiAttribute,
   105     TRACER("CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributes");
   105         RArray<TMPXAttribute>& aAttributeArray)
   106     // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here as all the others are reading straight from resource files
   106     {
       
   107     TRACER("CGlxCollectionPluginAlbums::CpiAttributeAdditionalAttributesL");
       
   108     // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here 
       
   109     // as all the others are reading straight from resource files
   107     // KGlxMediaCollectionPluginSpecificSubTitle requires a usage count
   110     // KGlxMediaCollectionPluginSpecificSubTitle requires a usage count
   108     if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle)
   111     if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle)
   109         {
   112         {
   110         // need to add the usage count. but check first if it is already present
   113         // need to add the usage count. but check first if it is already present
   111         TInt attrCount = aAttributeArray.Count();
   114         TInt attrCount = aAttributeArray.Count();
   112         TBool found = EFalse;
   115         TBool found = EFalse;
   113         
   116 
   114         for ( TInt index = 0 ; index < attrCount ; index++)
   117         for (TInt index = 0; index < attrCount; index++)
   115             {
   118             {
   116             if ( aAttributeArray[index] == KMPXMediaGeneralCount)
   119             if (aAttributeArray[index] == KMPXMediaGeneralCount)
   117                 {
   120                 {
   118                 found = ETrue;
   121                 found = ETrue;
   119                 break;
   122                 break;
   120                 }
   123                 }
   121             }
   124             }
   122             
   125 
   123         if (!found)
   126         if (!found)
   124             {
   127             {
   125             aAttributeArray.Append(KGlxMediaCollectionInternalUsageCount);
   128             aAttributeArray.AppendL(KGlxMediaCollectionInternalUsageCount);
   126             }
   129             }
   127         }
   130         }
   128     }
   131     }
   129 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> aMediaIds)
   132 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(
       
   133         CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, 
       
   134         TArray<TGlxMediaId> aMediaIds)
   130     {
   135     {
   131     TRACER("CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL");
   136     TRACER("CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL");
   132     const TInt mediaIdCount = aMediaIds.Count();
   137     const TInt mediaIdCount = aMediaIds.Count();
   133     
   138 
   134     switch (mediaIdCount)
   139     switch (mediaIdCount)
   135         {
   140         {
   136     case 0:
   141         case 0:
   137         User::Leave(KErrNotSupported);
   142             User::Leave(KErrNotSupported);
   138         break;
   143             break;
   139     case 1:
   144         case 1:
   140         HandleCpiAttributeResponseL(aResponse, aCpiAttributes, aMediaIds[0]);
   145             HandleCpiAttributeResponseL(aResponse, aCpiAttributes,
   141         break;
   146                     aMediaIds[0]);
   142     default:
   147             break;
       
   148         default:
   143             {
   149             {
   144             // We have an array of CMPXMedia items
   150             // We have an array of CMPXMedia items
   145             
   151 
   146             if (TGlxMediaId(KGlxCollectionRootId) == aMediaIds[0])
   152             if (TGlxMediaId(KGlxCollectionRootId) == aMediaIds[0])
   147                 {
   153                 {
   148                 User::Leave(KErrNotSupported);
   154                 User::Leave(KErrNotSupported);
   149                 }
   155                 }
   150                 
   156 
   151             CMPXMediaArray* mediaArray = aResponse->ValueCObjectL<CMPXMediaArray>(KMPXMediaArrayContents);
   157             CMPXMediaArray* mediaArray = aResponse->ValueCObjectL<
       
   158                     CMPXMediaArray> (KMPXMediaArrayContents);
   152             CleanupStack::PushL(mediaArray);
   159             CleanupStack::PushL(mediaArray);
   153 
   160 
   154             const TInt arrayCount = mediaArray->Count();
   161             const TInt arrayCount = mediaArray->Count();
   155             
   162 
   156             // Sanity check
   163             // Sanity check
   157             if (arrayCount != mediaIdCount)
   164             if (arrayCount != mediaIdCount)
   158                 {
   165                 {
   159                 User::Leave(KErrArgument);
   166                 User::Leave(KErrArgument);
   160                 }
   167                 }
   161             
   168 
   162             for (TInt index = 0; index < arrayCount; index++)
   169             for (TInt index = 0; index < arrayCount; index++)
   163                 {
   170                 {
   164                 HandleCpiAttributeResponseL((*mediaArray)[index], aCpiAttributes, aMediaIds[index]);
   171                 HandleCpiAttributeResponseL((*mediaArray)[index],
       
   172                         aCpiAttributes, aMediaIds[index]);
   165                 }
   173                 }
   166 
   174 
   167             aResponse->SetCObjectValueL(KMPXMediaArrayContents, mediaArray);
   175             aResponse->SetCObjectValueL(KMPXMediaArrayContents, mediaArray);
   168             CleanupStack::PopAndDestroy(mediaArray);
   176             CleanupStack::PopAndDestroy(mediaArray);
   169             }
   177             }
   170         break;
   178             break;
   171         }
   179         }
   172     }
   180     }
   173 
   181 
   174 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TGlxMediaId aMediaId)
   182 void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(
       
   183         CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes,
       
   184         TGlxMediaId aMediaId)
   175     {
   185     {
   176     _LIT(KResourceFile, "z:glxpluginalbums.rsc");
   186     _LIT(KResourceFile, "z:glxpluginalbums.rsc");
   177 
   187 
   178     const TInt attribCount = aCpiAttributes.Count();
   188     const TInt attribCount = aCpiAttributes.Count();
   179 
   189 
   180     for (TInt index = 0; index < attribCount ; index++)
   190     for (TInt index = 0; index < attribCount; index++)
   181         {
   191         {
   182         const TMPXAttribute attr = aCpiAttributes[index];
   192         const TMPXAttribute attr = aCpiAttributes[index];
   183         
   193 
   184         if (attr == KGlxMediaCollectionPluginSpecificSubTitle)
   194         if (attr == KGlxMediaCollectionPluginSpecificSubTitle)
   185             {
   195             {
   186             TInt usageCount = 0;
   196             TInt usageCount = 0;
   187             if ( aResponse->IsSupported(KMPXMediaGeneralCount) )
   197             if (aResponse->IsSupported(KMPXMediaGeneralCount))
   188                 {
   198                 {
   189                 usageCount = aResponse->ValueTObjectL<TInt>(KMPXMediaGeneralCount);
   199                 usageCount = aResponse->ValueTObjectL<TInt> (
   190                 }
   200                         KMPXMediaGeneralCount);
   191             else if ( aResponse->IsSupported(KGlxMediaCollectionInternalUsageCount) )
   201                 }
   192                 {
   202             else if (aResponse->IsSupported(
   193                 usageCount = aResponse->ValueTObjectL<TInt>(KGlxMediaCollectionInternalUsageCount);
   203                     KGlxMediaCollectionInternalUsageCount))
       
   204                 {
       
   205                 usageCount = aResponse->ValueTObjectL<TInt> (
       
   206                         KGlxMediaCollectionInternalUsageCount);
   194                 aResponse->Delete(KGlxMediaCollectionInternalUsageCount);
   207                 aResponse->Delete(KGlxMediaCollectionInternalUsageCount);
   195                 }
   208                 }
   196             else
   209             else
   197                 {
   210                 {
   198                 User::Leave(KErrNotSupported);
   211                 User::Leave(KErrNotSupported);
   199                 }
   212                 }
   200             HBufC* tempTitle = NULL;
   213             HBufC* tempTitle = NULL;
   201             
   214 
   202             if (TGlxMediaId(KGlxCollectionRootId) == aMediaId)
   215             if (TGlxMediaId(KGlxCollectionRootId) == aMediaId)
   203             	{
   216                 {
   204                 if (1 == usageCount)
   217                 if (1 == usageCount)
   205                 	{
   218                     {
   206                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_SUB_TITLE_SINGLE);
   219                     tempTitle = LoadLocalizedStringLC(KResourceFile,
   207                     aResponse->SetTextValueL(attr, *tempTitle);  
   220                             R_ALBUM_SUB_TITLE_SINGLE);
       
   221                     aResponse->SetTextValueL(attr, *tempTitle);
   208                     CleanupStack::PopAndDestroy(tempTitle);
   222                     CleanupStack::PopAndDestroy(tempTitle);
   209                     continue;                   
   223                     continue;
   210                 	}
   224                     }
   211                 else
   225                 else
   212                 	{
   226                     {
   213                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_SUB_TITLE_MULTI);
   227                     tempTitle = LoadLocalizedStringLC(KResourceFile,
   214                 	}
   228                             R_ALBUM_SUB_TITLE_MULTI);
   215             	}
   229                     }
       
   230                 }
   216             else
   231             else
   217             	{
   232                 {
   218             	if(0 == usageCount)
   233                 if (0 == usageCount)
   219             		{
   234                     {
   220                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_EMPTY);
   235                     tempTitle = LoadLocalizedStringLC(KResourceFile,
   221                 	
   236                             R_ALBUM_ITEM_SUB_TITLE_EMPTY);
   222                 	// Set the title in the response.
   237 
   223             		aResponse->SetTextValueL(attr, *tempTitle);  
   238                     // Set the title in the response.
   224             		CleanupStack::PopAndDestroy(tempTitle);
   239                     aResponse->SetTextValueL(attr, *tempTitle);
   225 					
       
   226             		// Set the count in the response.
       
   227             		aResponse->SetTObjectValueL(KMPXMediaGeneralCount, usageCount); 
       
   228 					
       
   229             		continue;                	
       
   230             		}            	
       
   231             	else if (1 == usageCount)
       
   232                 	{
       
   233                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_SINGLE);
       
   234                     aResponse->SetTextValueL(attr, *tempTitle);  
       
   235                     CleanupStack::PopAndDestroy(tempTitle);
   240                     CleanupStack::PopAndDestroy(tempTitle);
   236 					
   241 
   237             		// Set the count in the response.
   242                     // Set the count in the response.
   238             		aResponse->SetTObjectValueL(KMPXMediaGeneralCount, usageCount);    
   243                     aResponse->SetTObjectValueL(KMPXMediaGeneralCount,
   239 
   244                             usageCount);
   240                     continue;                   
   245 
   241                 	}
   246                     continue;
       
   247                     }
       
   248                 else if (1 == usageCount)
       
   249                     {
       
   250                     tempTitle = LoadLocalizedStringLC(KResourceFile,
       
   251                             R_ALBUM_ITEM_SUB_TITLE_SINGLE);
       
   252                     aResponse->SetTextValueL(attr, *tempTitle);
       
   253                     CleanupStack::PopAndDestroy(tempTitle);
       
   254 
       
   255                     // Set the count in the response.
       
   256                     aResponse->SetTObjectValueL(KMPXMediaGeneralCount,
       
   257                             usageCount);
       
   258 
       
   259                     continue;
       
   260                     }
   242                 else
   261                 else
   243                 	{
   262                     {
   244                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_SUB_TITLE_MULTI);
   263                     tempTitle = LoadLocalizedStringLC(KResourceFile,
   245                 	}
   264                             R_ALBUM_ITEM_SUB_TITLE_MULTI);
   246             	}
   265                     }
   247             
   266                 }
       
   267 
   248             TPtr formatString = tempTitle->Des();
   268             TPtr formatString = tempTitle->Des();
   249             
   269 
   250             // Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
   270             // Now create a buffer that will contain the result. needs to be 
       
   271             // length of format string plus a few extra for the number
   251             HBufC* title = HBufC::NewLC(formatString.Length() + 10);
   272             HBufC* title = HBufC::NewLC(formatString.Length() + 10);
   252             TPtr ptr = title->Des();
   273             TPtr ptr = title->Des();
   253             StringLoader::Format(ptr, formatString, -1, usageCount);
   274             StringLoader::Format(ptr, formatString, -1, usageCount);
   254             
   275 
   255             // Set the title in the response.
   276             // Set the title in the response.
   256             aResponse->SetTextValueL(attr, *title);    
   277             aResponse->SetTextValueL(attr, *title);
   257 
   278 
   258             // Set the count in the response.
   279             // Set the count in the response.
   259             aResponse->SetTObjectValueL(KMPXMediaGeneralCount, usageCount);    
   280             aResponse->SetTObjectValueL(KMPXMediaGeneralCount, usageCount);
   260 
   281 
   261             CleanupStack::PopAndDestroy(title);
   282             CleanupStack::PopAndDestroy(title);
   262             CleanupStack::PopAndDestroy(tempTitle);
   283             CleanupStack::PopAndDestroy(tempTitle);
   263             }
   284             }
   264         else if (attr == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle)
   285         else if (attr
   265             {
   286                 == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle)
   266             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_POPUP_TITLE);
   287             {
   267             aResponse->SetTextValueL(attr, *title);  
   288             HBufC* title = LoadLocalizedStringLC(KResourceFile,
   268             CleanupStack::PopAndDestroy(title); 
   289                     R_ALBUM_POPUP_TITLE);
       
   290             aResponse->SetTextValueL(attr, *title);
       
   291             CleanupStack::PopAndDestroy(title);
   269             }
   292             }
   270         else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle)
   293         else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle)
   271             {
   294             {
   272             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_ITEM_TITLE);
   295             HBufC* title = LoadLocalizedStringLC(KResourceFile,
   273             aResponse->SetTextValueL(attr, *title);  
   296                     R_ALBUM_ITEM_TITLE);
   274             CleanupStack::PopAndDestroy(title); 
   297             aResponse->SetTextValueL(attr, *title);
       
   298             CleanupStack::PopAndDestroy(title);
   275             }
   299             }
   276         else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle)
   300         else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle)
   277             {
   301             {
   278             HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_DEFAULT_TITLE);
   302             HBufC* title = LoadLocalizedStringLC(KResourceFile,
   279             aResponse->SetTextValueL(attr, *title);  
   303                     R_ALBUM_DEFAULT_TITLE);
   280             CleanupStack::PopAndDestroy(title); 
   304             aResponse->SetTextValueL(attr, *title);
       
   305             CleanupStack::PopAndDestroy(title);
   281             }
   306             }
   282         else if (attr == KMPXMediaGeneralTitle)
   307         else if (attr == KMPXMediaGeneralTitle)
   283             {
   308             {
   284             if( TGlxMediaId(KGlxCollectionRootId) == aMediaId )
   309             if (TGlxMediaId(KGlxCollectionRootId) == aMediaId)
   285                 {
   310                 {
   286                 HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_GENERAL_TITLE);
   311                 HBufC* title = LoadLocalizedStringLC(KResourceFile,
   287                 aResponse->SetTextValueL(attr, *title);  
   312                         R_ALBUM_GENERAL_TITLE);
   288                 CleanupStack::PopAndDestroy(title); 
   313                 aResponse->SetTextValueL(attr, *title);
       
   314                 CleanupStack::PopAndDestroy(title);
   289                 }
   315                 }
   290             else
   316             else
   291                 {
   317                 {
   292                 if( aResponse->IsSupported(KGlxMediaCollectionInternalSystemItemType) )
   318                 if (aResponse->IsSupported(
   293 					{
   319                         KGlxMediaCollectionInternalSystemItemType))
   294 					TGlxMediaId responseMediaid ((TUint32)aResponse->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId));
   320                     {
   295 					// Set the text value based on the Media ID in aResponse
   321                     TGlxMediaId responseMediaid(
   296 					if( TGlxMediaId(KCapturedAlbumId) == responseMediaid )
   322                             (TUint32) aResponse->ValueTObjectL<TMPXItemId> (
   297 						{
   323                                     KMPXMediaGeneralId));
   298 						HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_CAMERA_TITLE);
   324                     // Set the text value based on the Media ID in aResponse
   299 						aResponse->SetTextValueL(attr, *title);  
   325                     if (TGlxMediaId(KCapturedAlbumId) == responseMediaid)
   300 						CleanupStack::PopAndDestroy(title);						
   326                         {
   301 						}
   327                         HBufC* title = LoadLocalizedStringLC(KResourceFile,
   302 					else if (TGlxMediaId(KFavoriteAlbumId) == responseMediaid  )
   328                                 R_ALBUM_CAMERA_TITLE);
   303 						{
   329                         aResponse->SetTextValueL(attr, *title);
   304 						HBufC* title = LoadLocalizedStringLC(KResourceFile, R_ALBUM_FAVORITES_TITLE);
   330                         CleanupStack::PopAndDestroy(title);
   305 						aResponse->SetTextValueL(attr, *title);  
   331                         }
   306 						CleanupStack::PopAndDestroy(title);						
   332                     else if (TGlxMediaId(KFavoriteAlbumId) == responseMediaid)
   307 						}
   333                         {
   308 					}                                             
   334                         HBufC* title = LoadLocalizedStringLC(KResourceFile,
   309                  aResponse->Delete(KGlxMediaCollectionInternalSystemItemType);                    
   335                                 R_ALBUM_FAVORITES_TITLE);
       
   336                         aResponse->SetTextValueL(attr, *title);
       
   337                         CleanupStack::PopAndDestroy(title);
       
   338                         }
       
   339                     }
       
   340                 aResponse->Delete(KGlxMediaCollectionInternalSystemItemType);
   310                 }
   341                 }
   311             }
   342             }
   312         }
   343         }
   313     }
   344     }
   314 
   345