photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlernewmedia.cpp
branchRCL_3
changeset 24 ea65f74e6de4
parent 21 f9e827349359
equal deleted inserted replaced
23:b023a8d2866a 24:ea65f74e6de4
    43 #include <glxuiutilities.rsg>
    43 #include <glxuiutilities.rsg>
    44 #include <mglxmedialist.h>
    44 #include <mglxmedialist.h>
    45 #include <mpxcollectionpath.h>
    45 #include <mpxcollectionpath.h>
    46 #include <mpxcommonframeworkdefs.h>
    46 #include <mpxcommonframeworkdefs.h>
    47 #include <StringLoader.h>
    47 #include <StringLoader.h>
    48 
    48 #include <glxmediageneraldefs.h>    // for KMaxMediaPopupTextLength
    49 #include <data_caging_path_literals.hrh>
    49 #include <data_caging_path_literals.hrh>
    50 #include <glxuiutilities.rsg>
    50 #include <glxuiutilities.rsg>
    51 
    51 #include <e32const.h> //For TDigitType
    52 const TInt KMaxMediaPopupTitleLength = 0x28;    // Accepts only 40 characters
    52 
    53 const TInt KMaxNewMediaItemTitleLength = 0x28;  // Accepts only 40 characters
       
    54 const TInt KMaxNumberLength = 10;
    53 const TInt KMaxNumberLength = 10;
    55 
    54 
    56 _LIT(KOpenBracket, "(");
    55 _LIT(KOpenBracket, "(");
    57 _LIT(KCloseBracket, ")");
    56 _LIT(KCloseBracket, ")");
    58 _LIT(KFileNameFormatString, "(%+02u)");
    57 _LIT(KFileNameFormatString, "(%+02u)");
   190     iOkToExit = ETrue;
   189     iOkToExit = ETrue;
   191     
   190     
   192     CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathParent );
   191     CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathParent );
   193     CMPXCommand* command = NULL;
   192     CMPXCommand* command = NULL;
   194 
   193 
   195     TBuf <KMaxNewMediaItemTitleLength> defaultNewMediaItemTitle;
   194     TBuf <KMaxMediaPopupTextLength> defaultNewMediaItemTitle;
   196     
   195     
   197     TRAPD(error, TitlesL(TGlxMediaId(path->Id(0)), defaultNewMediaItemTitle));
   196     TRAPD(error, TitlesL(TGlxMediaId(path->Id(0)), defaultNewMediaItemTitle));
   198     if(error != KErrNone)
   197     if(error != KErrNone)
   199         {
   198         {
   200         iNewMediaCreationError = KErrCancel;
   199         iNewMediaCreationError = KErrCancel;
   214     	iNewMediaItemTitle = GenerateNewMediaItemTitleL(defaultNewMediaItemTitle, aMediaList);
   213     	iNewMediaItemTitle = GenerateNewMediaItemTitleL(defaultNewMediaItemTitle, aMediaList);
   215 	    }
   214 	    }
   216     TPtr newMediaItemTitleDes = iNewMediaItemTitle->Des();
   215     TPtr newMediaItemTitleDes = iNewMediaItemTitle->Des();
   217     
   216     
   218     CGlxTextEntryPopup* dialog = CGlxTextEntryPopup::NewL(*mediaPopupTitle, newMediaItemTitleDes);
   217     CGlxTextEntryPopup* dialog = CGlxTextEntryPopup::NewL(*mediaPopupTitle, newMediaItemTitleDes);
   219     
       
   220     
       
   221     if(dialog->ExecuteLD() == EEikBidOk)
   218     if(dialog->ExecuteLD() == EEikBidOk)
   222     	{
   219     	{
   223         command = TGlxCommandFactory::AddContainerCommandLC(*iNewMediaItemTitle, path->Id(0));
   220         command = TGlxCommandFactory::AddContainerCommandLC(*iNewMediaItemTitle, path->Id(0));
   224         CleanupStack::Pop(command);
   221         CleanupStack::Pop(command);
   225     	}
   222     	}
   318     const CGlxMedia* media = item.Properties();
   315     const CGlxMedia* media = item.Properties();
   319     if (media)
   316     if (media)
   320         {
   317         {
   321         aDefaultNewMediaItemTitle.Copy(media->ValueText(
   318         aDefaultNewMediaItemTitle.Copy(media->ValueText(
   322                 KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(
   319                 KGlxMediaCollectionPluginSpecificDefaultMediaTitle).Left(
   323                 KMaxMediaPopupTitleLength));
   320                         KMaxMediaPopupTextLength));
   324         }
   321         }
   325 
   322 
   326     CleanupStack::PopAndDestroy(attributeContext);
   323     CleanupStack::PopAndDestroy(attributeContext);
   327     CleanupStack::PopAndDestroy(rootList);
   324     CleanupStack::PopAndDestroy(rootList);
   328     CleanupStack::PopAndDestroy(path);
   325     CleanupStack::PopAndDestroy(path);
   385                         pos += length;
   382                         pos += length;
   386                         length = title.Length() - pos
   383                         length = title.Length() - pos
   387                                 - KCloseBracket().Length();
   384                                 - KCloseBracket().Length();
   388                         if (length > 0)
   385                         if (length > 0)
   389                             {
   386                             {
   390                             TLex lex = title.Mid(pos, length);
   387 							HBufC* num = title.Mid(pos, length).AllocLC();
       
   388 							TPtr numPtr = num->Des();
       
   389 							//Change to Western numeric for determining next numeral
       
   390 							AknTextUtils::ConvertDigitsTo(numPtr,EDigitTypeWestern);
       
   391                             TLex lex(numPtr);
   391                             TInt val = 0;
   392                             TInt val = 0;
   392                             if (lex.Val(val) == KErrNone)
   393                             if (lex.Val(val) == KErrNone)
   393                                 {
   394                                 {
   394                                 numbers.InsertInOrderL(val);
   395                                 numbers.InsertInOrderL(val);
   395                                 }
   396                                 }
       
   397                             CleanupStack::PopAndDestroy(num);
   396                             }
   398                             }
   397                         }
   399                         }
   398                     }
   400                     }
   399 
   401 
   400                 }
   402                 }
   418     CleanupStack::PopAndDestroy(&numbers);
   420     CleanupStack::PopAndDestroy(&numbers);
   419 
   421 
   420     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length()
   422     TInt defaultTitleLength = aDefaultNewMediaItemTitle.Length()
   421             + KFileNameFormatString().Length() + KCloseBracket().Length()
   423             + KFileNameFormatString().Length() + KCloseBracket().Length()
   422             + KMaxNumberLength;
   424             + KMaxNumberLength;
   423     // If the default title length is bigger than KMaxMediaPopupTitleLength, 
   425     // If the default title length is bigger than KMaxMediaPopupTextLength, 
   424     // make sure we allocate enough space for it.
   426     // make sure we allocate enough space for it.
   425     TInt titleLength = defaultTitleLength > KMaxMediaPopupTitleLength ? 
   427     TInt titleLength = defaultTitleLength > KMaxMediaPopupTextLength ? 
   426                                             defaultTitleLength
   428                                             defaultTitleLength
   427                                             : KMaxMediaPopupTitleLength;
   429                                             : KMaxMediaPopupTextLength;
   428     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   430     HBufC* newMediaItemTitle = HBufC::NewL(titleLength);
   429     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   431     TPtr newMediaItemTitleDes = newMediaItemTitle->Des();
   430     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   432     newMediaItemTitleDes.Append(aDefaultNewMediaItemTitle);
   431 
   433 
   432     if (nextNumber > 0)
   434     if (nextNumber > 0)
   433         {
   435         {
   434         newMediaItemTitleDes.AppendFormat(KFileNameFormatString, nextNumber);
   436 		newMediaItemTitleDes.AppendFormat(KFileNameFormatString, nextNumber);
       
   437 		//Change numeric according to current input language here
       
   438 		AknTextUtils::ConvertDigitsTo(newMediaItemTitleDes,
       
   439 				AknTextUtils::TextEditorDigitType());
   435         }
   440         }
   436     else
   441     else
   437         {
   442         {
   438         // 0 is a special case, return "New Media", not "New Media (0)"
   443         // 0 is a special case, return "New Media", not "New Media (0)"
   439         }
   444         }