email/mail/ViewerSrc/Msgmailcharactersethandler.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Character set handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "Msgmailcharactersethandler.h"
       
    22 #include    <featmgr.h>
       
    23 #include    <bldvariant.hrh>
       
    24 #include    <charconv.h>
       
    25 #include    <eikmenup.h>
       
    26 #include    <coemain.h>
       
    27 
       
    28 #include    <StringLoader.h>
       
    29 #include    <MsgMailViewer.rsg>
       
    30 #include    <msgmailviewer.hrh>
       
    31 
       
    32 // CONSTANTS
       
    33 enum TVariationFlag 
       
    34     {
       
    35     EDefault,
       
    36     EJapaneseVariant,
       
    37     EChineseVariant
       
    38     };
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CMsgMailCharacterSetHandler::CMsgMailCharacterSetHandler
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CMsgMailCharacterSetHandler::CMsgMailCharacterSetHandler()
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CMsgMailCharacterSetHandler::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CMsgMailCharacterSetHandler::ConstructL()
       
    57     {
       
    58     if( FeatureManager::FeatureSupported( KFeatureIdJapanese ) )
       
    59         {
       
    60         iVariationFlag = EJapaneseVariant;
       
    61         }
       
    62     else if( FeatureManager::FeatureSupported( KFeatureIdChinese ) )
       
    63         {
       
    64         iVariationFlag = EChineseVariant;
       
    65         }
       
    66     else
       
    67         {
       
    68         iVariationFlag = EDefault;
       
    69         }
       
    70 
       
    71     iFirstFreeCommandId = 0;
       
    72     AppendItemsToItemArrayL();
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CMsgMailCharacterSetHandler::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CMsgMailCharacterSetHandler* CMsgMailCharacterSetHandler::NewL( 
       
    81     TInt aFirstFreeCommandId )
       
    82     {
       
    83     CMsgMailCharacterSetHandler* self = new( 
       
    84         ELeave ) CMsgMailCharacterSetHandler;
       
    85     
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     self->iFirstFreeCommandId = aFirstFreeCommandId;
       
    89     CleanupStack::Pop(); // self
       
    90     return self;
       
    91     }
       
    92 
       
    93     
       
    94 // Destructor
       
    95 CMsgMailCharacterSetHandler::~CMsgMailCharacterSetHandler()
       
    96     {
       
    97     iItems.Close();
       
    98     }
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMsgMailCharacterSetHandler::SetCharacterSetSubMenuItemsL
       
   103 // Set filtered list of available characterset to menupane
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CMsgMailCharacterSetHandler::SetCharacterSetSubMenuItemsL(
       
   107     CEikMenuPane& aMenuPane, TUint aActiveCharacterSet)
       
   108     {
       
   109     for (TInt i=0; i<iItems.Count(); i++)
       
   110         {
       
   111         // Hide active characterset from options
       
   112         if (iItems[i].iCharacterSetId != aActiveCharacterSet)
       
   113             {
       
   114             CEikMenuPaneItem::SData data;
       
   115             
       
   116             data.iCommandId = iFirstFreeCommandId + iItems[i].iCommandId;
       
   117             data.iCascadeId = NULL;
       
   118             data.iFlags = NULL;         
       
   119             data.iText = iItems[i].iText;           
       
   120             data.iExtraText = KNullDesC;           
       
   121             
       
   122             aMenuPane.AddMenuItemL(data);            
       
   123             }
       
   124         }  
       
   125     
       
   126     }
       
   127 // -----------------------------------------------------------------------------
       
   128 // CMsgMailCharacterSetHandler::GetCharacterSetId
       
   129 // Get character set id
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TBool CMsgMailCharacterSetHandler::GetCharacterSetId(
       
   133     TInt aCommandId, TUint& aCharacterSetId)
       
   134     {
       
   135     TBool retVal(EFalse);
       
   136     aCharacterSetId = 0;
       
   137     for (TInt i=0; i<iItems.Count(); i++)
       
   138         {
       
   139         if (aCommandId == iItems[i].iCommandId + iFirstFreeCommandId)
       
   140             {
       
   141             aCharacterSetId = iItems[i].iCharacterSetId;
       
   142             retVal = ETrue;
       
   143             }
       
   144         }
       
   145     return retVal;
       
   146     }
       
   147 // -----------------------------------------------------------------------------
       
   148 // CMsgMailCharacterSetHandler::CharacterSetCount
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CMsgMailCharacterSetHandler::SetCharacterSetMenuItemL(
       
   152     CEikMenuPane& aMenuPane)
       
   153     {
       
   154     if ( iItems.Count() )
       
   155         {        
       
   156         if ( iVariationFlag == EJapaneseVariant )
       
   157             {
       
   158             CEikMenuPaneItem::SData& charecterSetItem = 
       
   159                 aMenuPane.ItemData(EMsgMailViewerCmdCharSet);
       
   160             
       
   161             HBufC* text = StringLoader::LoadLC(R_QTN_JPN_MAIL_OM_CHARSET);
       
   162             charecterSetItem.iText =  
       
   163                 (*text).Left(charecterSetItem.ENominalTextLength);
       
   164             CleanupStack::PopAndDestroy(); // text
       
   165             }
       
   166         aMenuPane.SetItemDimmed(EMsgMailViewerCmdCharSet, EFalse);
       
   167         }
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CMsgMailCharacterSetHandler::IsAcceptedCharacterSet
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TBool CMsgMailCharacterSetHandler::IsAcceptedCharacterSet(
       
   175     TUint aCharacterSetId)
       
   176     {    
       
   177     switch(aCharacterSetId)
       
   178         {
       
   179         // For China variant
       
   180         case KCharacterSetIdentifierBig5:   // FALLTHROUGH
       
   181         case KCharacterSetIdentifierGb2312:
       
   182             return (iVariationFlag == EChineseVariant);
       
   183         // For Japan variant
       
   184         case KCharacterSetIdentifierShiftJis:   // FALLTHROUGH
       
   185         case KCharacterSetIdentifierEucJpPacked:// FALLTHROUGH
       
   186         case KCharacterSetIdentifierIso2022Jp:
       
   187             return (iVariationFlag == EJapaneseVariant);
       
   188 
       
   189         default:
       
   190             return EFalse;
       
   191         }
       
   192     
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CMsgMailCharacterSetHandler::AppendItemsToItemArrayL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CMsgMailCharacterSetHandler::AppendItemsToItemArrayL()
       
   200     {
       
   201     RFs& fs = CCoeEnv::Static()->FsSession();
       
   202 
       
   203     CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* charSets = 
       
   204         CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC( fs );
       
   205     
       
   206     for (TInt i=0; i<charSets->Count(); i++)
       
   207         {
       
   208         const TUint identifier = (*charSets)[i].Identifier();
       
   209         if ( IsAcceptedCharacterSet( identifier ) )
       
   210             {
       
   211             TData data;            
       
   212             data.iCommandId = i;
       
   213             data.iCharacterSetId = identifier;
       
   214             
       
   215             HBufC* buf = NULL;
       
   216             // China
       
   217             if ( identifier == KCharacterSetIdentifierGb2312 )
       
   218                 {
       
   219                 buf = StringLoader::LoadL(R_QTN_CHI_MAIL_SM_GB2312);
       
   220                 }
       
   221             else if ( identifier == KCharacterSetIdentifierBig5 )
       
   222                 {
       
   223                 buf = StringLoader::LoadL(R_QTN_CHI_MAIL_SM_BIG5);
       
   224                 }
       
   225             // Japanice
       
   226             else if ( identifier == KCharacterSetIdentifierIso2022Jp )
       
   227                 {
       
   228                 buf = StringLoader::LoadL(R_QTN_JPN_MAIL_SM_CHARSET_ISO2022JP);
       
   229                 }
       
   230             else if ( identifier == KCharacterSetIdentifierEucJpPacked )
       
   231                 {
       
   232                 buf = StringLoader::LoadL(R_QTN_JPN_MAIL_SM_CHARSET_EUCJP);
       
   233                 }
       
   234             else if ( identifier == KCharacterSetIdentifierShiftJis )
       
   235                 {
       
   236                 buf = StringLoader::LoadL(R_QTN_JPN_MAIL_SM_CHARSET_SHIFTJIS);
       
   237                 }
       
   238             else
       
   239                 {
       
   240                 // Ask name from charconv
       
   241                 CCnvCharacterSetConverter* charConv = 
       
   242                     CCnvCharacterSetConverter::NewLC();
       
   243                 HBufC8* name = charConv->
       
   244                     ConvertCharacterSetIdentifierToStandardNameL(
       
   245                     identifier, fs);
       
   246                 if ( name )
       
   247                     {
       
   248                     CleanupStack::PushL( name );
       
   249                     // cleanupstack is not needed here since
       
   250                     // the code cannot leave before deleting this buffer
       
   251                     buf = HBufC::NewL( name->Length() ); // CSI: 35 # see comment above
       
   252                     buf->Des().Copy( *name );
       
   253                     CleanupStack::PopAndDestroy(); // name
       
   254                     }
       
   255                 CleanupStack::PopAndDestroy(); // charConv
       
   256                 }
       
   257             
       
   258             if (!buf)
       
   259                 {
       
   260                 buf = KNullDesC().AllocL();
       
   261                 }
       
   262             data.iText.Copy(buf->Left(data.ENominalTextLength));
       
   263             delete buf;
       
   264             buf = NULL;
       
   265             
       
   266             User::LeaveIfError( iItems.Append(data) );
       
   267             }
       
   268         }
       
   269     CleanupStack::PopAndDestroy(); // charSets
       
   270     }
       
   271 
       
   272 //  End of File