photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlernewmedia.cpp
branchRCL_3
changeset 75 01504893d9cb
parent 64 34937ec34dac
equal deleted inserted replaced
68:5b238bc8ffb6 75:01504893d9cb
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:    New media command handler
    14 * Description:    Delete command handler
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
       
    20 
       
    21 /**
       
    22  * @internal reviewed 06/06/2007 by Dave Schofield
       
    23  */
    20 
    24 
    21 #include "glxcommandhandlernewmedia.h"
    25 #include "glxcommandhandlernewmedia.h"
    22 
    26 
    23 #include <AknUtils.h>
    27 #include <AknUtils.h>
    24 #include <badesca.h>
    28 #include <badesca.h>
    39 #include <glxuiutilities.rsg>
    43 #include <glxuiutilities.rsg>
    40 #include <mglxmedialist.h>
    44 #include <mglxmedialist.h>
    41 #include <mpxcollectionpath.h>
    45 #include <mpxcollectionpath.h>
    42 #include <mpxcommonframeworkdefs.h>
    46 #include <mpxcommonframeworkdefs.h>
    43 #include <StringLoader.h>
    47 #include <StringLoader.h>
    44 #include <glxmediageneraldefs.h>    // for KMaxMediaPopupTextLength
    48 
    45 #include <data_caging_path_literals.hrh>
    49 #include <data_caging_path_literals.hrh>
    46 #include <glxuiutilities.rsg>
    50 #include <glxuiutilities.rsg>
    47 #include <e32const.h> //For TDigitType
    51 
    48 
    52 const TInt KMaxMediaPopupTitleLength = 0x28;    // Accepts only 40 characters
       
    53 const TInt KMaxNewMediaItemTitleLength = 0x28;  // Accepts only 40 characters
    49 const TInt KMaxNumberLength = 10;
    54 const TInt KMaxNumberLength = 10;
    50 
    55 
    51 _LIT(KOpenBracket, "(");
    56 _LIT(KOpenBracket, "(");
    52 _LIT(KCloseBracket, ")");
    57 _LIT(KCloseBracket, ")");
    53 _LIT(KFileNameFormatString, "(%+02u)");
    58 _LIT(KFileNameFormatString, "(%+02u)");
   185     iOkToExit = ETrue;
   190     iOkToExit = ETrue;
   186     
   191     
   187     CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathParent );
   192     CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathParent );
   188     CMPXCommand* command = NULL;
   193     CMPXCommand* command = NULL;
   189 
   194 
   190     TBuf <KMaxMediaPopupTextLength> defaultNewMediaItemTitle;
   195     TBuf <KMaxNewMediaItemTitleLength> defaultNewMediaItemTitle;
   191     
   196     
   192     TRAPD(error, TitlesL(TGlxMediaId(path->Id(0)), defaultNewMediaItemTitle));
   197     TRAPD(error, TitlesL(TGlxMediaId(path->Id(0)), defaultNewMediaItemTitle));
   193     if(error != KErrNone)
   198     if(error != KErrNone)
   194         {
   199         {
   195         iNewMediaCreationError = KErrCancel;
   200         iNewMediaCreationError = KErrCancel;
   209     	iNewMediaItemTitle = GenerateNewMediaItemTitleL(defaultNewMediaItemTitle, aMediaList);
   214     	iNewMediaItemTitle = GenerateNewMediaItemTitleL(defaultNewMediaItemTitle, aMediaList);
   210 	    }
   215 	    }
   211     TPtr newMediaItemTitleDes = iNewMediaItemTitle->Des();
   216     TPtr newMediaItemTitleDes = iNewMediaItemTitle->Des();
   212     
   217     
   213     CGlxTextEntryPopup* dialog = CGlxTextEntryPopup::NewL(*mediaPopupTitle, newMediaItemTitleDes);
   218     CGlxTextEntryPopup* dialog = CGlxTextEntryPopup::NewL(*mediaPopupTitle, newMediaItemTitleDes);
       
   219     
       
   220     
   214     if(dialog->ExecuteLD() == EEikBidOk)
   221     if(dialog->ExecuteLD() == EEikBidOk)
   215     	{
   222     	{
   216         command = TGlxCommandFactory::AddContainerCommandLC(*iNewMediaItemTitle, path->Id(0));
   223         command = TGlxCommandFactory::AddContainerCommandLC(*iNewMediaItemTitle, path->Id(0));
   217         CleanupStack::Pop(command);
   224         CleanupStack::Pop(command);
   218     	}
   225     	}
   291     CleanupStack::PushL(attributeContext);
   298     CleanupStack::PushL(attributeContext);
   292     attributeContext->AddAttributeL(
   299     attributeContext->AddAttributeL(
   293             KGlxMediaCollectionPluginSpecificDefaultMediaTitle);
   300             KGlxMediaCollectionPluginSpecificDefaultMediaTitle);
   294     rootList->AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   301     rootList->AddContextL(attributeContext, KGlxFetchContextPriorityBlocking);
   295 
   302 
   296     // Media list must not have been deleted when the destructor of 
   303     TGlxFetchContextRemover contextRemover(attributeContext, *rootList);
   297     // TGlxContextRemover is called while going out-of-scope.
   304     // put to cleanupstack as cleanupstack is emptied before stack objects
   298         {
   305     // are deleted
   299         TGlxFetchContextRemover contextRemover(attributeContext, *rootList);
   306     CleanupClosePushL(contextRemover);
   300         // put to cleanupstack as cleanupstack is emptied before stack objects
   307     User::LeaveIfError(GlxAttributeRetriever::RetrieveL(*attributeContext,
   301         // are deleted
   308             *rootList, ETrue));
   302         CleanupClosePushL(contextRemover);
   309     // context off the list
   303         User::LeaveIfError(GlxAttributeRetriever::RetrieveL(
   310     CleanupStack::PopAndDestroy(&contextRemover);
   304                 *attributeContext, *rootList, ETrue));
       
   305         // context off the list
       
   306         CleanupStack::PopAndDestroy(&contextRemover);
       
   307         } // Limiting scope of contextRemover
       
   308 
   311 
   309     TInt index = rootList->Index(KGlxIdSpaceIdRoot, aCollectionId);
   312     TInt index = rootList->Index(KGlxIdSpaceIdRoot, aCollectionId);
   310 
   313 
   311     __ASSERT_DEBUG(index != KErrNotFound, Panic(EGlxPanicRequiredItemNotFound));
   314     __ASSERT_DEBUG(index != KErrNotFound, Panic(EGlxPanicRequiredItemNotFound));
   312 
   315 
   315     const CGlxMedia* media = item.Properties();
   318     const CGlxMedia* media = item.Properties();
   316     if (media)
   319     if (media)
   317         {
   320         {
   318         aDefaultNewMediaItemTitle.Copy(media->ValueText(
   321         aDefaultNewMediaItemTitle.Copy(media->ValueText(
   319                 KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(
   322                 KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(
   320                         KMaxMediaPopupTextLength));
   323                 KMaxMediaPopupTitleLength));
   321         }
   324         }
   322 
   325 
   323     CleanupStack::PopAndDestroy(attributeContext);
   326     CleanupStack::PopAndDestroy(attributeContext);
   324     CleanupStack::PopAndDestroy(rootList);
   327     CleanupStack::PopAndDestroy(rootList);
   325     CleanupStack::PopAndDestroy(path);
   328     CleanupStack::PopAndDestroy(path);
   382                         pos += length;
   385                         pos += length;
   383                         length = title.Length() - pos
   386                         length = title.Length() - pos
   384                                 - KCloseBracket().Length();
   387                                 - KCloseBracket().Length();
   385                         if (length > 0)
   388                         if (length > 0)
   386                             {
   389                             {
   387 							HBufC* num = title.Mid(pos, length).AllocLC();
   390                             TLex lex = title.Mid(pos, length);
   388 							TPtr numPtr = num->Des();
       
   389 							//Change to Western numeric for determining next numeral
       
   390 							AknTextUtils::ConvertDigitsTo(numPtr,EDigitTypeWestern);
       
   391                             TLex lex(numPtr);
       
   392                             TInt val = 0;
   391                             TInt val = 0;
   393                             if (lex.Val(val) == KErrNone)
   392                             if (lex.Val(val) == KErrNone)
   394                                 {
   393                                 {
   395                                 numbers.InsertInOrderL(val);
   394                                 numbers.InsertInOrderL(val);
   396                                 }
   395                                 }
   397                             CleanupStack::PopAndDestroy(num);
       
   398                             }
   396                             }
   399                         }
   397                         }
   400                     }
   398                     }
   401 
   399 
   402                 }
   400                 }
   420     CleanupStack::PopAndDestroy(&numbers);
   418     CleanupStack::PopAndDestroy(&numbers);
   421 
   419 
   422     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length()
   420     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length()
   423             + KFileNameFormatString().Length() + KCloseBracket().Length()
   421             + KFileNameFormatString().Length() + KCloseBracket().Length()
   424             + KMaxNumberLength;
   422             + KMaxNumberLength;
   425     // If the default title length is bigger than KMaxMediaPopupTextLength, 
   423     // If the default title length is bigger than KMaxMediaPopupTitleLength, 
   426     // make sure we allocate enough space for it.
   424     // make sure we allocate enough space for it.
   427     TInt titleLength = defaultTitleLength > KMaxMediaPopupTextLength ? 
   425     TInt titleLength = defaultTitleLength > KMaxMediaPopupTitleLength ? 
   428                                             defaultTitleLength
   426                                             defaultTitleLength
   429                                             : KMaxMediaPopupTextLength;
   427                                             : KMaxMediaPopupTitleLength;
   430     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   428     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   431     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   429     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   432     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   430     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   433 
   431 
   434     if (nextNumber > 0)
   432     if (nextNumber > 0)
   435         {
   433         {
   436 		newMediaItemTitleDes.AppendFormat(KFileNameFormatString, nextNumber);
   434         newMediaItemTitleDes.AppendFormat(KFileNameFormatString, nextNumber);
   437 		//Change numeric according to current input language here
       
   438 		AknTextUtils::ConvertDigitsTo(newMediaItemTitleDes,
       
   439 				AknTextUtils::TextEditorDigitType());
       
   440         }
   435         }
   441     else
   436     else
   442         {
   437         {
   443         // 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)"
   444         }
   439         }