photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlernewmedia.cpp
branchRCL_3
changeset 47 f9e827349359
parent 25 191387a8b767
child 57 ea65f74e6de4
equal deleted inserted replaced
35:420f6808bf21 47:f9e827349359
   274     // if iSchedulerWait exists then we know the command is being executed from
   274     // if iSchedulerWait exists then we know the command is being executed from
   275     // the ExecuteLD() method and filtering is not required.
   275     // the ExecuteLD() method and filtering is not required.
   276     return iSchedulerWait != NULL;
   276     return iSchedulerWait != NULL;
   277     }
   277     }
   278     
   278     
       
   279 
   279 // ---------------------------------------------------------------------------
   280 // ---------------------------------------------------------------------------
   280 // TitlesL fetches the 'media popup title' and 'default new media item title'
   281 // TitlesL fetches the 'media popup title' and 'default new media item title'
   281 // from the collection.
   282 // from the collection.
   282 // ---------------------------------------------------------------------------
   283 // ---------------------------------------------------------------------------
   283 //
   284 //
   284 
   285 
   285 void CGlxCommandHandlerNewMedia::TitlesL(const TGlxMediaId aCollectionId, TDes& aDefaultNewMediaItemTitle) const
   286 void CGlxCommandHandlerNewMedia::TitlesL(const TGlxMediaId aCollectionId,
   286 	{
   287         TDes& aDefaultNewMediaItemTitle) const
       
   288     {
   287     TRACER("CGlxCommandHandlerNewMedia::TitlesL");
   289     TRACER("CGlxCommandHandlerNewMedia::TitlesL");
   288     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
   290     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
   289     CleanupStack::PushL(path);
   291     CleanupStack::PushL(path);
   290     MGlxMediaList* rootList = MGlxMediaList::InstanceL(*path);
   292     MGlxMediaList* rootList = MGlxMediaList::InstanceL(*path);
   291     CleanupClosePushL(*rootList);
   293     CleanupClosePushL(*rootList);
   292 
   294 
   293     TGlxSpecificIdIterator iter(KGlxIdSpaceIdRoot, aCollectionId);
   295     TGlxSpecificIdIterator iter(KGlxIdSpaceIdRoot, aCollectionId);
   294     CGlxAttributeContext* attributeContext = new (ELeave) CGlxAttributeContext(&iter);
   296     CGlxAttributeContext* attributeContext =
       
   297             new (ELeave) CGlxAttributeContext(&iter);
   295     CleanupStack::PushL(attributeContext);
   298     CleanupStack::PushL(attributeContext);
   296     attributeContext->AddAttributeL(KGlxMediaCollectionPluginSpecificDefaultMediaTitle);
   299     attributeContext->AddAttributeL(
       
   300             KGlxMediaCollectionPluginSpecificDefaultMediaTitle);
   297     rootList->AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   301     rootList->AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   298     
   302 
   299     TGlxFetchContextRemover contextRemover(attributeContext, *rootList);
   303     TGlxFetchContextRemover contextRemover(attributeContext, *rootList);
   300     // put to cleanupstack as cleanupstack is emptied before stack objects
   304     // put to cleanupstack as cleanupstack is emptied before stack objects
   301     // are deleted
   305     // are deleted
   302     CleanupClosePushL( contextRemover );
   306     CleanupClosePushL(contextRemover);
   303     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, *rootList, ETrue));
   307     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext,
       
   308             *rootList, ETrue));
   304     // context off the list
   309     // context off the list
   305     CleanupStack::PopAndDestroy( &contextRemover );
   310     CleanupStack::PopAndDestroy(&contextRemover);
   306     	
   311 
   307         TInt index =  rootList->Index(KGlxIdSpaceIdRoot, aCollectionId);
   312     TInt index = rootList->Index(KGlxIdSpaceIdRoot, aCollectionId);
   308         
   313 
   309         __ASSERT_DEBUG(index != KErrNotFound, Panic(EGlxPanicRequiredItemNotFound));
   314     __ASSERT_DEBUG(index != KErrNotFound, Panic(EGlxPanicRequiredItemNotFound));
   310         
   315 
   311     	TGlxMedia  item =  rootList->Item(index);
   316     TGlxMedia item = rootList->Item(index);
   312     	
   317 
   313     	const CGlxMedia* media = item.Properties();
   318     const CGlxMedia* media = item.Properties();
   314     	if (media)
   319     if (media)
   315     		{
   320         {
   316     		aDefaultNewMediaItemTitle.Copy(media->ValueText(KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(KMaxMediaPopupTitleLength));
   321         aDefaultNewMediaItemTitle.Copy(media->ValueText(
   317     		}
   322                 KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(
   318 
   323                 KMaxMediaPopupTitleLength));
   319 	CleanupStack::PopAndDestroy(attributeContext);
   324         }
   320 	CleanupStack::PopAndDestroy(rootList);
   325 
       
   326     CleanupStack::PopAndDestroy(attributeContext);
       
   327     CleanupStack::PopAndDestroy(rootList);
   321     CleanupStack::PopAndDestroy(path);
   328     CleanupStack::PopAndDestroy(path);
   322 	}
   329     }
   323 
   330 
   324 // ---------------------------------------------------------------------------
   331 // ---------------------------------------------------------------------------
   325 // TitlesL fetches the 'media popup title' and 'default new media item title'
   332 // TitlesL fetches the 'media popup title' and 'default new media item title'
   326 // from the collection.
   333 // from the collection.
   327 // ---------------------------------------------------------------------------
   334 // ---------------------------------------------------------------------------
   328 //
   335 //
   329 HBufC* CGlxCommandHandlerNewMedia::GenerateNewMediaItemTitleL
   336 HBufC* CGlxCommandHandlerNewMedia::GenerateNewMediaItemTitleL(
   330                                    (const TDesC& aDefaultNewMediaItemTitle, MGlxMediaList& aList) const
   337         const TDesC& aDefaultNewMediaItemTitle, MGlxMediaList& aList) const
   331     {        
   338     {
   332     TRACER("CGlxCommandHandlerNewMedia::GenerateNewMediaItemTitleL");
   339     TRACER("CGlxCommandHandlerNewMedia::GenerateNewMediaItemTitleL");
   333     TGlxSequentialIterator iter;
   340     TGlxSequentialIterator iter;
   334     CGlxAttributeContext* attributeContext = new (ELeave) CGlxAttributeContext(&iter);
   341     CGlxAttributeContext* attributeContext =
       
   342             new (ELeave) CGlxAttributeContext(&iter);
   335     CleanupStack::PushL(attributeContext);
   343     CleanupStack::PushL(attributeContext);
   336     attributeContext->AddAttributeL(KMPXMediaGeneralTitle);
   344     attributeContext->AddAttributeL(KMPXMediaGeneralTitle);
   337     aList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   345     aList.AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   338     TGlxFetchContextRemover contextRemover(attributeContext, aList);
   346     TGlxFetchContextRemover contextRemover(attributeContext, aList);
   339     // put to cleanupstack as cleanupstack is emptied before stack objects
   347     // put to cleanupstack as cleanupstack is emptied before stack objects
   340     // are deleted
   348     // are deleted
   341     CleanupClosePushL( contextRemover );
   349     CleanupClosePushL(contextRemover);
   342     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext, aList, EFalse));
   350     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext,
       
   351             aList, EFalse));
   343     // context off the list
   352     // context off the list
   344     CleanupStack::PopAndDestroy( &contextRemover );
   353     CleanupStack::PopAndDestroy(&contextRemover);
   345     CleanupStack::PopAndDestroy(attributeContext);
   354     CleanupStack::PopAndDestroy(attributeContext);
   346     
   355 
   347     RArray<TInt> numbers;
   356     RArray<TInt> numbers;
   348     CleanupClosePushL(numbers);
   357     CleanupClosePushL(numbers);
   349     
   358 
   350     TInt count = aList.Count();
   359     TInt count = aList.Count();
   351     for (TInt i = 0; i < count; i++)
   360     for (TInt i = 0; i < count; i++)
   352         {
   361         {
   353         TGlxMedia  item =  aList.Item(i);    
   362         TGlxMedia item = aList.Item(i);
   354         const CGlxMedia* media = item.Properties();
   363         const CGlxMedia* media = item.Properties();
   355         if (media)
   364         if (media)
   356             {
   365             {
   357             const TDesC& title = media->ValueText(KMPXMediaGeneralTitle);
   366             const TDesC& title = media->ValueText(KMPXMediaGeneralTitle);
   358             
   367 
   359             TInt length = aDefaultNewMediaItemTitle.Length();
   368             TInt length = aDefaultNewMediaItemTitle.Length();
   360             if (title.Left(length).Compare(aDefaultNewMediaItemTitle) == 0)
   369             if (title.Left(length).Compare(aDefaultNewMediaItemTitle) == 0)
   361                 {
   370                 {
   362                 if (length == title.Length())
   371                 if (length == title.Length())
   363                     {
   372                     {
   364                     numbers.InsertInOrder(0); // special case
   373                     numbers.InsertInOrderL(0); // special case
   365                     }
   374                     }
   366                 else if(title.Length() > length + KOpenBracket().Length() + KCloseBracket().Length())
   375                 else if (title.Length() > length + KOpenBracket().Length()
       
   376                         + KCloseBracket().Length())
   367                     {
   377                     {
   368                     TInt pos = length;
   378                     TInt pos = length;
   369                     length = KOpenBracket().Length();
   379                     length = KOpenBracket().Length();
   370                     
   380 
   371                     if (title.Mid(pos, length).Compare(KOpenBracket) == 0 && 
   381                     if (title.Mid(pos, length).Compare(KOpenBracket) == 0
   372                         title.Right(KCloseBracket().Length()).Compare(KCloseBracket) == 0)
   382                             && title.Right(KCloseBracket().Length()).Compare(
       
   383                                     KCloseBracket) == 0)
   373                         {
   384                         {
   374                         pos += length;
   385                         pos += length;
   375                         length = title.Length() - pos - KCloseBracket().Length();
   386                         length = title.Length() - pos
       
   387                                 - KCloseBracket().Length();
   376                         if (length > 0)
   388                         if (length > 0)
   377                             {
   389                             {
   378                             TLex lex = title.Mid(pos, length);
   390                             TLex lex = title.Mid(pos, length);
   379                             TInt val = 0;
   391                             TInt val = 0;
   380                             if (lex.Val(val) == KErrNone)
   392                             if (lex.Val(val) == KErrNone)
   381                                 {
   393                                 {
   382                                 numbers.InsertInOrder(val);
   394                                 numbers.InsertInOrderL(val);
   383                                 }
   395                                 }
   384                             }
   396                             }
   385                         }
   397                         }
   386                     }
   398                     }
   387                
   399 
   388                 }
   400                 }
   389             }
   401             }
   390         }
   402         }
   391     
   403 
   392     TInt nextNumber = 0;
   404     TInt nextNumber = 0;
   393     count = numbers.Count();
   405     count = numbers.Count();
   394     for (TInt i = 0; i < count; i++)
   406     for (TInt i = 0; i < count; i++)
   395         {
   407         {
   396         if (numbers[i] == nextNumber)
   408         if (numbers[i] == nextNumber)
   400         else
   412         else
   401             {
   413             {
   402             break;
   414             break;
   403             }
   415             }
   404         }
   416         }
   405     
   417 
   406     CleanupStack::PopAndDestroy(&numbers);
   418     CleanupStack::PopAndDestroy(&numbers);
   407     
   419 
   408     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length() + KFileNameFormatString().Length() + KCloseBracket().Length() + KMaxNumberLength;
   420     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length()
   409     // If the default title length is bigger than KMaxMediaPopupTitleLength, make sure we allocate enough space for it.
   421             + KFileNameFormatString().Length() + KCloseBracket().Length()
   410     TInt titleLength  = defaultTitleLength > KMaxMediaPopupTitleLength ? defaultTitleLength : KMaxMediaPopupTitleLength;
   422             + KMaxNumberLength;
       
   423     // If the default title length is bigger than KMaxMediaPopupTitleLength, 
       
   424     // make sure we allocate enough space for it.
       
   425     TInt titleLength = defaultTitleLength > KMaxMediaPopupTitleLength ? 
       
   426                                             defaultTitleLength
       
   427                                             : KMaxMediaPopupTitleLength;
   411     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   428     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   412     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   429     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   413     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   430     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   414     
   431 
   415     if (nextNumber > 0)
   432     if (nextNumber > 0)
   416         {
   433         {
   417         newMediaItemTitleDes.AppendFormat(KFileNameFormatString,nextNumber);
   434         newMediaItemTitleDes.AppendFormat(KFileNameFormatString, nextNumber);
   418         }
   435         }
   419     else
   436     else
   420         {
   437         {
   421         // 0 is a special case, return "New Media", not "New Media (0)"
   438         // 0 is a special case, return "New Media", not "New Media (0)"
   422         }
   439         }
   423     
   440 
   424     return newMediaItemTitle;
   441     return newMediaItemTitle;
   425     }
   442     }
   426 
   443 
   427 // -----------------------------------------------------------------------------
   444 // -----------------------------------------------------------------------------
   428 // SetFocusL()
   445 // SetFocusL()
   438 
   455 
   439 // -----------------------------------------------------------------------------
   456 // -----------------------------------------------------------------------------
   440 // HandleItemAddedL
   457 // HandleItemAddedL
   441 // -----------------------------------------------------------------------------
   458 // -----------------------------------------------------------------------------
   442 //  
   459 //  
   443 EXPORT_C void CGlxCommandHandlerNewMedia::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex, MGlxMediaList* aList)
   460 EXPORT_C void CGlxCommandHandlerNewMedia::HandleItemAddedL(TInt aStartIndex,
       
   461         TInt aEndIndex, MGlxMediaList* aList)
   444     {
   462     {
   445     TRACER("CGlxCommandHandlerNewMedia::HandleItemAddedL");
   463     TRACER("CGlxCommandHandlerNewMedia::HandleItemAddedL");
   446     if(aList == &MediaList() && iNewMediaId != KGlxCollectionRootId)
   464     if (aList == &MediaList() && iNewMediaId != KGlxCollectionRootId)
   447         {
   465         {
   448         for (TInt i = aStartIndex; i <= aEndIndex; i++)
   466         for (TInt i = aStartIndex; i <= aEndIndex; i++)
   449             {
   467             {
   450             if (aList->Item(i).Id() == iNewMediaId)
   468             if (aList->Item(i).Id() == iNewMediaId)
   451                 {
   469                 {
   452                 iAsyncFocuser->SetFocus(i); // calls CGlxCommandHandlerNewMedia::SetFocusL asynchronously
   470                 // calls CGlxCommandHandlerNewMedia::SetFocusL asynchronously
       
   471                 iAsyncFocuser->SetFocus(i);
   453                 break;
   472                 break;
   454                 }
   473                 }
   455             }
   474             }
   456         }
   475         }
   457     }
   476     }
   461 // -----------------------------------------------------------------------------
   480 // -----------------------------------------------------------------------------
   462 //  
   481 //  
   463 CGlxCommandHandlerNewMedia::CGlxAsyncFocuser::
   482 CGlxCommandHandlerNewMedia::CGlxAsyncFocuser::
   464     CGlxAsyncFocuser(CGlxCommandHandlerNewMedia* aGlxCommandHandlerNewMedia)
   483     CGlxAsyncFocuser(CGlxCommandHandlerNewMedia* aGlxCommandHandlerNewMedia)
   465     : CActive(KMaxTInt), iGlxCommandHandlerNewMedia(aGlxCommandHandlerNewMedia)
   484     : CActive(KMaxTInt), iGlxCommandHandlerNewMedia(aGlxCommandHandlerNewMedia)
   466     // The active object has the maximum possible priority to prevent other active objects
   485     // The active object has the maximum possible priority to prevent 
   467     // running before it. (Unless they too are scheduled to run and have the maximum
   486     // other active objects running before it. (Unless they too are 
   468     // possible priority
   487     // scheduled to run and have the maximum possible priority
   469     {
   488     {
   470     TRACER("CGlxCommandHandlerNewMedia::CGlxAsyncFocuser::CGlxAsyncFocuser");
   489     TRACER("CGlxCommandHandlerNewMedia::CGlxAsyncFocuser::CGlxAsyncFocuser");
   471     __ASSERT_DEBUG(aGlxCommandHandlerNewMedia, Panic(EGlxPanicNullPointer));
   490     __ASSERT_DEBUG(aGlxCommandHandlerNewMedia, Panic(EGlxPanicNullPointer));
   472     CActiveScheduler::Add(this);
   491     CActiveScheduler::Add(this);
   473     }
   492     }