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