photosgallery/collectionframework/plugins/glxcollectionplugindownloads/src/glxcollectionplugindownloads.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 #include "glxcollectionplugindownloads.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 <glxplugindownloads.rsg>
       
    37 #include <stringloader.h>
       
    38 #include <glxpanic.h>
       
    39 #include <mglxdatasource.h>
       
    40 #include <glxrequest.h>
       
    41 #include <glxidlistrequest.h>
       
    42 #include <glxfilterfactory.h>
       
    43 #include <glxlog.h>
       
    44 #include <glxtracer.h>
       
    45 
       
    46 #include "glxcollectionplugindownloads.hrh"
       
    47 /**
       
    48  * @internal reviewed 14/06/2007 by Alex Birkett
       
    49  */
       
    50 
       
    51 // CONSTANTS
       
    52 
       
    53 // ============================ LOCAL FUNCTIONS ==============================
       
    54     
       
    55 // ============================ MEMBER FUNCTIONS ==============================
       
    56 // ----------------------------------------------------------------------------
       
    57 // Two-phased constructor.
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 CGlxCollectionPluginDownloads* CGlxCollectionPluginDownloads::NewL(TAny* aObs)
       
    61     {
       
    62     CGlxCollectionPluginDownloads* self = new (ELeave) CGlxCollectionPluginDownloads(
       
    63                             static_cast<MMPXCollectionPluginObserver*>(aObs));
       
    64 	CleanupStack::PushL(self);
       
    65 	self->ConstructL();
       
    66 	CleanupStack::Pop(self);
       
    67 	return self;
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // Destructor
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CGlxCollectionPluginDownloads::~CGlxCollectionPluginDownloads()
       
    75     {
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // Constructor
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 CGlxCollectionPluginDownloads::CGlxCollectionPluginDownloads(
       
    83     MMPXCollectionPluginObserver* aObs)
       
    84     {
       
    85     iObs = aObs;
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // ConstructL
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 void CGlxCollectionPluginDownloads::ConstructL()
       
    93     {
       
    94     iDataSource = MGlxDataSource::OpenDataSourceL(KGlxDefaultDataSourceUid, *this);
       
    95 	}
       
    96 // ----------------------------------------------------------------------------
       
    97 // CpiAttributeAdditionalAttributes
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 void CGlxCollectionPluginDownloads::CpiAttributeAdditionalAttributes(const TMPXAttribute& aCpiAttribute, RArray<TMPXAttribute>& aAttributeArray)
       
   101 	{
       
   102     TRACER("CGlxCollectionPluginDownloads::CpiAttributeAdditionalAttributes");
       
   103     // Only need to process KGlxMediaCollectionPluginSpecificSubTitle here as all the others are reading straight from resource files
       
   104     // KGlxMediaCollectionPluginSpecificSubTitle requires a usage count
       
   105 	if (aCpiAttribute == KGlxMediaCollectionPluginSpecificSubTitle)
       
   106 	    {
       
   107 	    // need to add the usage count. but check first if it is already present
       
   108 	    TInt attrCount = aAttributeArray.Count();
       
   109 	    TBool found = EFalse;
       
   110 	    
       
   111 	    for ( TInt index = 0 ; index < attrCount ; index++)
       
   112 	        {
       
   113 	        if (aAttributeArray[index] == KMPXMediaGeneralCount)
       
   114 	            {
       
   115 	            found = ETrue;
       
   116 	            break;
       
   117 	            }
       
   118 	        }
       
   119 	        
       
   120 	    if (!found)
       
   121 	        {
       
   122 	        aAttributeArray.Append(KMPXMediaGeneralCount);
       
   123 	        }
       
   124 	    }
       
   125 	}
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // HandleCpiAttributeResponseL
       
   129 // ----------------------------------------------------------------------------
       
   130 // 
       
   131 void CGlxCollectionPluginDownloads::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> /* aMediaIds */)
       
   132 	{
       
   133     TRACER("CGlxCollectionPluginDownloads::HandleCpiAttributeResponseL");
       
   134     
       
   135     _LIT(KResourceFile, "z:glxplugindownloads.rsc");
       
   136     
       
   137 	TInt count = aCpiAttributes.Count();
       
   138 	
       
   139 	for (TInt index = 0; index < count ; index++)
       
   140 	    {
       
   141 	    const TMPXAttribute attr = aCpiAttributes[index];
       
   142 	    
       
   143 	    if (attr == KGlxMediaCollectionPluginSpecificSubTitle)
       
   144 	        {
       
   145 	        GLX_LOG_INFO("Attribute : Sub Title");
       
   146 	        
       
   147 	        if (!aResponse->IsSupported(KMPXMediaGeneralCount))
       
   148 	            {
       
   149 	            User::Leave(KErrNotSupported);
       
   150 	            }
       
   151             else
       
   152                 {
       
   153                 TInt usageCount = aResponse->ValueTObjectL<TInt>(KMPXMediaGeneralCount);
       
   154                 
       
   155                 // Get the format string
       
   156                 HBufC* tempTitle = NULL;
       
   157                 
       
   158 #ifdef GLX_SUB_TITLE_REL8
       
   159 
       
   160 				if(0 == usageCount)
       
   161 					{
       
   162 					GLX_LOG_INFO("Count is 0 items");
       
   163 					
       
   164 					tempTitle = LoadLocalizedStringLC(KResourceFile,R_DOWNLOADS_SUB_TITLE_NO_IMG_NO_VID);
       
   165 					aResponse->SetTextValueL(attr, *tempTitle); 
       
   166 					}
       
   167 					
       
   168 				else if (1 == usageCount)
       
   169 					{
       
   170 					GLX_LOG_INFO("Count is 1 item");
       
   171 						                    
       
   172 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_SUB_TITLE_SINGLE);
       
   173 					aResponse->SetTextValueL(attr, *tempTitle); 
       
   174 					}
       
   175 				else
       
   176 					{
       
   177 					GLX_LOG_INFO1("Count is %d items",usageCount);
       
   178 					
       
   179 					tempTitle = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_SUB_TITLE_MULTI);
       
   180 					//Format the string
       
   181 					TPtr formatString = tempTitle->Des();
       
   182 
       
   183 					// Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   184 					HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   185 					TPtr ptr = title->Des();
       
   186 					StringLoader::Format(ptr, formatString, -1, usageCount);
       
   187 
       
   188 					// Set the title in the response.
       
   189 					aResponse->SetTextValueL(attr, *title);  
       
   190 					CleanupStack::PopAndDestroy(title);
       
   191 					}
       
   192                 CleanupStack::PopAndDestroy(tempTitle);
       
   193 #else
       
   194             	if(0 == usageCount)
       
   195             		{
       
   196                 	tempTitle = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_SUB_TITLE_NO_IMG_NO_VID);                	
       
   197                 	// Set the title in the response.
       
   198             		aResponse->SetTextValueL(attr, *tempTitle);  
       
   199             		CleanupStack::PopAndDestroy(tempTitle);
       
   200             		continue;                	
       
   201             		}  
       
   202 				// Get the format string
       
   203             	else if (1 == usageCount)
       
   204                     {
       
   205                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_SUB_TITLE_SINGLE);
       
   206                     aResponse->SetTextValueL(attr, *tempTitle);  
       
   207                     CleanupStack::PopAndDestroy(tempTitle);
       
   208                     continue; 
       
   209                     }
       
   210                 else
       
   211                     {
       
   212                     tempTitle = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_SUB_TITLE_MULTI);
       
   213                     }
       
   214                 TPtr formatString = tempTitle->Des();
       
   215                 
       
   216                 // Now create a buffer that will contain the result. needs to be length of format string plus a few extra for the number
       
   217                 HBufC* title = HBufC::NewLC(formatString.Length() + 10);
       
   218                 TPtr ptr = title->Des();
       
   219                 StringLoader::Format(ptr, formatString, -1, usageCount);
       
   220                 
       
   221                 // Set the title in the response.
       
   222                 aResponse->SetTextValueL(attr, *title);    
       
   223 
       
   224                 CleanupStack::PopAndDestroy(title);
       
   225                 CleanupStack::PopAndDestroy(tempTitle);                
       
   226 #endif                
       
   227                 }
       
   228 	        }
       
   229 	    else if (attr == KGlxMediaCollectionPluginSpecificSelectMediaPopupTitle)
       
   230 	        {
       
   231 	        GLX_LOG_INFO("Attribute : MediaPopupTitle");
       
   232 	        
       
   233 	        User::Leave(KErrNotSupported);
       
   234 	        }
       
   235 	    else if (attr == KGlxMediaCollectionPluginSpecificNewMediaItemTitle)
       
   236 	        {
       
   237 	        GLX_LOG_INFO("Attribute : NewMediaItemTitle");
       
   238 	        
       
   239 	        User::Leave(KErrNotSupported);
       
   240 	        }
       
   241 	    else if (attr == KGlxMediaCollectionPluginSpecificDefaultMediaTitle)
       
   242 	        {
       
   243 	        GLX_LOG_INFO("Attribute : DefaultMediaTitle");
       
   244 	        
       
   245 	        User::Leave(KErrNotSupported);
       
   246 	        }
       
   247 	    else if (attr == KMPXMediaGeneralTitle)
       
   248 	        {
       
   249 	        GLX_LOG_INFO("Attribute : GeneralTitle");
       
   250 	        
       
   251 	        HBufC* title = LoadLocalizedStringLC(KResourceFile, R_DOWNLOADS_GENERAL_TITLE);
       
   252             // Set the title in the response.
       
   253             aResponse->SetTextValueL(attr, *title);  
       
   254             CleanupStack::PopAndDestroy(title); 
       
   255 	        }
       
   256 	    }
       
   257 	    
       
   258 	}
       
   259 
       
   260  
       
   261 // ----------------------------------------------------------------------------
       
   262 // IsUpdateMessageIgnoredL
       
   263 // ----------------------------------------------------------------------------
       
   264 // 
       
   265 TBool CGlxCollectionPluginDownloads::IsUpdateMessageIgnoredL(CMPXMessage& /*aMessage*/)
       
   266 	{
       
   267 	TRACER("CGlxCollectionPluginDownloads::IsUpdateMessageIgnoredL");	
       
   268 	/// @todo origin could be passed up to allow downloads to ignore irrelevant adds, wait until inheritance is resolved
       
   269 	TBool ignore = EFalse;
       
   270 	return ignore;
       
   271 	}
       
   272 
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // DefaultFilter
       
   276 // ----------------------------------------------------------------------------
       
   277 // 
       
   278 TGlxFilterProperties CGlxCollectionPluginDownloads::DefaultFilter(TInt aLevel)
       
   279     {
       
   280     TRACER("CGlxCollectionPluginDownloads::DefaultFilter");
       
   281     
       
   282     __ASSERT_DEBUG(( (aLevel == KGlxCollectionRootLevel) || (aLevel == KGlxCollectionRootLevel+1) 
       
   283     || (aLevel == KGlxCollectionRootLevel+2) ), Panic(EGlxPanicInvalidPathLevel));
       
   284     TGlxFilterProperties filterProperties;
       
   285 	filterProperties.iSortOrder = EGlxFilterSortOrderCaptureDate;
       
   286     filterProperties.iSortDirection = EGlxFilterSortDirectionDescending;
       
   287 #ifdef RD_MDS_2_5
       
   288     filterProperties.iOrigin = EGlxFilterOriginDownload;
       
   289 #endif
       
   290 
       
   291     return filterProperties;
       
   292     }
       
   293 
       
   294 // End of file