mobilemessaging/unieditor/utils/src/UniBaseHeader.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  
       
    15 *       Defines implementation of CUniBaseHeader class methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "UniBaseHeader.h"
       
    23 
       
    24 #include <eikrted.h>
       
    25 #include <txtrich.h>                // CRichText
       
    26 #include <mtclbase.h>
       
    27 
       
    28 #include <centralrepository.h>    // link against centralrepository.lib
       
    29 #include <messaginginternalcrkeys.h> // for Central Repository keys
       
    30 
       
    31 #include <mmsgenutils.h>
       
    32 
       
    33 #include <messagingvariant.hrh>
       
    34 
       
    35 #include <MsgExpandableControl.h>
       
    36 #include <MsgAddressControl.h>
       
    37 
       
    38 #include <uniaddresshandler.h>
       
    39 #include <uniobjectlist.h>
       
    40 
       
    41 
       
    42 // ==========================================================
       
    43 
       
    44 // EXTERNAL DATA STRUCTURES
       
    45 
       
    46 // EXTERNAL FUNCTION PROTOTYPES
       
    47 
       
    48 // CONSTANTS
       
    49 
       
    50 // MACROS
       
    51 
       
    52 // LOCAL CONSTANTS AND MACROS
       
    53 
       
    54 // MODULE DATA STRUCTURES
       
    55 
       
    56 // LOCAL FUNCTION PROTOTYPES
       
    57 
       
    58 // ================= MEMBER FUNCTIONS =======================
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CUniBaseHeader::CUniBaseHeader
       
    62 //
       
    63 // Constructor.
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CUniBaseHeader::CUniBaseHeader( CBaseMtm& aMtm,
       
    67                                          CMsgEditorView& aView,
       
    68                                          RFs& aFs ) : 
       
    69     iMtm( aMtm ),
       
    70     iView( aView ),
       
    71     iFs( aFs )
       
    72     {
       
    73     iHeaders[EHeaderAddressFrom].iControlType = EMsgComponentIdFrom;
       
    74     iHeaders[EHeaderAddressTo].iControlType = EMsgComponentIdTo;
       
    75     iHeaders[EHeaderAddressCc].iControlType = EMsgComponentIdCc;
       
    76     iHeaders[EHeaderAddressBcc].iControlType = EMsgComponentIdBcc;
       
    77     iHeaders[EHeaderSubject].iControlType = EMsgComponentIdSubject;
       
    78     iHeaders[EHeaderAttachment].iControlType = EMsgComponentIdAttachment;
       
    79     iHeaders[EHeaderAddressTo].iRecipientTypeValue = EMsvRecipientTo;
       
    80     iHeaders[EHeaderAddressCc].iRecipientTypeValue = EMsvRecipientCc;
       
    81     iHeaders[EHeaderAddressBcc].iRecipientTypeValue = EMsvRecipientBcc;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // CUniBaseHeader::~CUniBaseHeader
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 EXPORT_C CUniBaseHeader::~CUniBaseHeader()
       
    89     {
       
    90     for (TInt i = EHeaderAddressFrom; i <= EHeaderAttachment; i++ )
       
    91         {
       
    92         if ( iHeaders[i].iOwned )
       
    93             {
       
    94             delete iHeaders[i].iControl;
       
    95             }
       
    96         delete iHeaders[i].iAddressHandler;
       
    97         }
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CUniBaseHeader::AddToViewL
       
   102 //
       
   103 // Assumes that slide is automatically correct. Caller's responsibility
       
   104 // ---------------------------------------------------------
       
   105 // 
       
   106 EXPORT_C void CUniBaseHeader::AddToViewL()
       
   107     {    
       
   108     DoAddToViewL( EFalse ); // do not read data
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------
       
   112 // CUniBaseHeader::DoAddToViewL
       
   113 // ---------------------------------------------------------
       
   114 // 
       
   115 EXPORT_C void CUniBaseHeader::DoAddToViewL( TBool aReadContent )
       
   116     {
       
   117     TInt flag = EUniFeatureFrom;
       
   118     
       
   119     // Headers must be in right order. Remove additional first
       
   120     RemoveFromViewL( EUniFeatureCc | EUniFeatureBcc | EUniFeatureSubject | EUniFeatureAttachment );
       
   121     
       
   122     for ( TInt i = EHeaderAddressFrom; i <= EHeaderAttachment; i++ )
       
   123         {
       
   124         if ( i == EHeaderAddressTo )
       
   125             {
       
   126             flag = EUniFeatureTo;
       
   127             }
       
   128         else if ( i == EHeaderAddressCc )
       
   129             {
       
   130             flag = EUniFeatureCc;
       
   131             }
       
   132         else  if ( i == EHeaderAddressBcc )
       
   133             {
       
   134             flag = EUniFeatureBcc;
       
   135             }
       
   136         else  if ( i == EHeaderSubject )
       
   137             {
       
   138             flag = EUniFeatureSubject;
       
   139             }
       
   140         else if ( i == EHeaderAttachment )
       
   141             {
       
   142             flag = EUniFeatureAttachment;
       
   143             }
       
   144             
       
   145         if ( iHeaders[i].iControl &&  
       
   146              !iView.ControlById( iHeaders[i].iControlType ) )
       
   147             {
       
   148             iView.AddControlL( iHeaders[i].iControl,
       
   149                                iHeaders[i].iControlType,
       
   150                                EMsgAppendControl,
       
   151                                EMsgHeader );
       
   152             iHeaders[i].iOwned = EFalse;
       
   153             }
       
   154         else if ( iAddDelayed & EUniFeatureFrom &&  
       
   155                   i == EHeaderAddressFrom )
       
   156             {
       
   157             InsertFromL( aReadContent );          // read from MTM
       
   158             iAddDelayed &= ( ~EUniFeatureFrom );
       
   159             }
       
   160         else if ( iAddDelayed & EUniFeatureSubject &&  
       
   161                   i == EHeaderSubject )
       
   162             {
       
   163             InsertSubjectL( aReadContent );
       
   164             iAddDelayed &= ( ~EUniFeatureSubject );
       
   165             }
       
   166         else if ( iAddDelayed & EUniFeatureAttachment &&
       
   167                   i == EHeaderAttachment )
       
   168             {
       
   169             InsertAttachmentL( aReadContent );
       
   170             iAddDelayed &= ( ~EUniFeatureAttachment );
       
   171             }
       
   172         else if ( iAddDelayed & flag &&  
       
   173                   ( i == EHeaderAddressTo ||  
       
   174                     i == EHeaderAddressCc ||  
       
   175                     i == EHeaderAddressBcc ) )
       
   176             {
       
   177             InsertRecipientL( iHeaders[i],
       
   178                               static_cast<THeaderFields> ( i ),
       
   179                               aReadContent);          // read from MTM
       
   180             iAddDelayed &= ( ~flag );
       
   181             }
       
   182         }
       
   183     iAddDelayed = 0;
       
   184     }
       
   185     
       
   186 // ---------------------------------------------------------
       
   187 // CUniBaseHeader::InsertFromL
       
   188 // ---------------------------------------------------------
       
   189 // 
       
   190 EXPORT_C void CUniBaseHeader::InsertFromL( TBool /*aReadContent*/) // read from MTM
       
   191     {
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // CUniBaseHeader::RemoveFromViewL
       
   196 //
       
   197 // Assumes that slide is automatically correct. Caller's responsibility
       
   198 // ---------------------------------------------------------
       
   199 // 
       
   200 EXPORT_C void CUniBaseHeader::RemoveFromViewL( TInt aFlags )
       
   201     {
       
   202     for ( TInt i = EHeaderAddressFrom; i <= EHeaderAttachment; i++ )
       
   203         {      
       
   204         TInt flag( EUniFeatureTo );
       
   205         if ( i == EHeaderAddressFrom )
       
   206             {
       
   207             flag = EUniFeatureFrom; 
       
   208             }
       
   209         else if ( i == EHeaderAddressCc )
       
   210             {
       
   211             flag = EUniFeatureCc; 
       
   212             }
       
   213         else if ( i == EHeaderAddressBcc )
       
   214             {
       
   215             flag = EUniFeatureBcc; 
       
   216             }
       
   217         else if ( i == EHeaderSubject )
       
   218             {
       
   219             flag = EUniFeatureSubject; 
       
   220             }
       
   221         else if ( i == EHeaderAttachment )
       
   222             {
       
   223             flag = EUniFeatureAttachment;
       
   224             }
       
   225             
       
   226         if ( aFlags & flag &&  
       
   227              iHeaders[i].iControl )
       
   228             {   
       
   229             if ( iView.RemoveControlL( iHeaders[i].iControlType ) )
       
   230                 {
       
   231                 iHeaders[i].iOwned = ETrue;
       
   232                 }
       
   233             // else - not removed
       
   234             }
       
   235         }        
       
   236     }
       
   237     
       
   238 // ---------------------------------------------------------
       
   239 // MtmAddressTypes
       
   240 // ---------------------------------------------------------
       
   241 //
       
   242 EXPORT_C TInt CUniBaseHeader::MtmAddressTypes()
       
   243     {
       
   244     TInt ret(0);
       
   245     const CMsvRecipientList& addresses = iMtm.AddresseeList();
       
   246 
       
   247     TInt addrCnt = addresses.Count();        
       
   248     for ( TInt i = 0; i < addrCnt; i++ )
       
   249         {          
       
   250         if ( addresses.Type(i) == EMsvRecipientTo )
       
   251             {
       
   252             ret |= EUniFeatureTo;
       
   253             }
       
   254         else if ( addresses.Type(i) == EMsvRecipientCc )
       
   255             {
       
   256             ret |= EUniFeatureCc;
       
   257             }
       
   258         else if ( addresses.Type(i) == EMsvRecipientBcc )
       
   259             {
       
   260             ret |= EUniFeatureBcc;
       
   261             }
       
   262         }
       
   263     return ret;
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------
       
   267 // CUniBaseHeader::FocusedAddressField
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 EXPORT_C TInt CUniBaseHeader::FocusedAddressField( CMsgBaseControl* aFocusedControl )
       
   271     {
       
   272     TInt ret = KErrNotFound;
       
   273     for ( TInt i = EHeaderAddressFrom; i <= EHeaderAttachment ; i++ )
       
   274         {    
       
   275         if ( iHeaders[i].iControl == aFocusedControl )
       
   276             {
       
   277             return iHeaders[i].iControlType;
       
   278             }
       
   279         }
       
   280     return ret;
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CUniBaseHeader::AddHeadersVariation
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 EXPORT_C void CUniBaseHeader::AddHeadersVariationL( TBool aIsUpload )
       
   288     {
       
   289     TInt featureBitmask = 0;
       
   290     
       
   291     CRepository* repository = CRepository::NewL( KCRUidMuiuVariation );
       
   292     repository->Get( KMuiuMmsFeatures, featureBitmask );
       
   293     delete repository;
       
   294     
       
   295     // bit 0x2
       
   296     if ( featureBitmask & KMmsFeatureIdEditorSubjectField )
       
   297         { // Subject is supported
       
   298         iAddHeadersVariation |= EUniFeatureSubject;
       
   299         if( featureBitmask & KMmsFeatureIdEditorSubjectConfigurable )
       
   300             { // It is also configurable
       
   301             iAddHeadersVariation |= EUniFeatureSubjectConfigurable;
       
   302             }
       
   303         }
       
   304     // bit 0x400
       
   305     // do not show for upload messages
       
   306     if ( featureBitmask & KMmsFeatureIdEditorCcField && 
       
   307          !aIsUpload )
       
   308         {
       
   309         iAddHeadersVariation |= EUniFeatureCc;
       
   310         }
       
   311     // bit 0x800
       
   312     // do not show for upload messages
       
   313     if ( featureBitmask & KMmsFeatureIdEditorBccField &&  
       
   314          !aIsUpload )
       
   315         {
       
   316         iAddHeadersVariation |= EUniFeatureBcc;
       
   317         }        
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CUniBaseHeader::AddHeadersConfig
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 EXPORT_C TInt CUniBaseHeader::AddHeadersConfigL()
       
   325     {
       
   326     TInt featureBitmask = 0;
       
   327     TInt ret = 0;
       
   328     CRepository* repository = CRepository::NewL( KCRUidMmsui );
       
   329     repository->Get( KMmsuiAdditionalHeaders, featureBitmask );
       
   330     delete repository;
       
   331 
       
   332     // set bit to null if variation is OFF
       
   333     if ( featureBitmask & KMmsuiHeaderSubject &&  
       
   334          iAddHeadersVariation & EUniFeatureSubjectConfigurable )
       
   335         {
       
   336         ret |= EUniFeatureSubject;
       
   337         }
       
   338     if ( featureBitmask & KMmsuiHeaderCC &&  
       
   339          iAddHeadersVariation & EUniFeatureCc )
       
   340         {
       
   341         ret |= EUniFeatureCc;
       
   342         }
       
   343     if ( featureBitmask & KMmsuiHeaderBCC &&  
       
   344          iAddHeadersVariation & EUniFeatureBcc )
       
   345         {
       
   346         ret |= EUniFeatureBcc;
       
   347         }
       
   348     iAddHeadersConfig = ret;
       
   349     return ret;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // CUniBaseHeader::SaveAddHeadersConfigL
       
   354 // ---------------------------------------------------------
       
   355 //
       
   356 EXPORT_C void CUniBaseHeader::SaveAddHeadersConfigL(TInt aFlags)
       
   357     {
       
   358     TInt featureBitmask = 0;    
       
   359     CRepository* repository = CRepository::NewL( KCRUidMmsui  );
       
   360     
       
   361     // Do not set bit if variation is OFF
       
   362     if ( aFlags & EUniFeatureSubject &&  
       
   363          iAddHeadersVariation & EUniFeatureSubjectConfigurable )
       
   364         {
       
   365         featureBitmask |= KMmsuiHeaderSubject;
       
   366         }
       
   367     if ( aFlags & EUniFeatureCc &&  
       
   368          iAddHeadersVariation & EUniFeatureCc )
       
   369         {
       
   370         featureBitmask |= KMmsuiHeaderCC;
       
   371         }
       
   372     if ( aFlags & EUniFeatureBcc &&  
       
   373          iAddHeadersVariation & EUniFeatureBcc )
       
   374         {
       
   375         featureBitmask |= KMmsuiHeaderBCC;
       
   376         }
       
   377     
       
   378     // Don't save anything, which is variated off
       
   379     repository->Set( KMmsuiAdditionalHeaders, featureBitmask );
       
   380     delete repository;
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------
       
   384 // CUniBaseHeader::HasRecipients
       
   385 // ---------------------------------------------------------
       
   386 //
       
   387 EXPORT_C TBool CUniBaseHeader::HasRecipients( )
       
   388     {
       
   389     TBool result( EFalse );
       
   390     
       
   391     for ( TInt i = EHeaderAddressTo; i <= EHeaderAddressBcc ; i++ )
       
   392         {    
       
   393         if ( iHeaders[i].iControl )
       
   394             {
       
   395             CMsgRecipientArray* recipients = NULL;
       
   396             TRAP_IGNORE( recipients = 
       
   397                             static_cast<CMsgAddressControl*>( iHeaders[i].iControl )->GetRecipientsL() );
       
   398             if ( recipients &&  
       
   399                  recipients->Count() > 0 )
       
   400                 {
       
   401                 result = ETrue;
       
   402                 break;
       
   403                 }
       
   404             }
       
   405         }
       
   406         
       
   407     return result;
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------
       
   411 // CUniBaseHeader::IsAddressControl
       
   412 // ---------------------------------------------------------
       
   413 //
       
   414 EXPORT_C TBool CUniBaseHeader::IsAddressControl (TInt aId )
       
   415     {
       
   416     TBool result( EFalse );
       
   417     
       
   418     for ( TInt i = EHeaderAddressTo; i <= EHeaderAddressBcc ; i++ )
       
   419         {    
       
   420         if ( iHeaders[i].iControl &&  
       
   421              iHeaders[i].iControlType == aId )
       
   422             {
       
   423             result = ETrue;
       
   424             break;
       
   425             }
       
   426         }
       
   427         
       
   428     return result;
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------
       
   432 // CUniBaseHeader::HandleResourceChange
       
   433 // ---------------------------------------------------------
       
   434 //
       
   435 EXPORT_C void CUniBaseHeader::HandleResourceChange( TInt aType )
       
   436     {
       
   437     for ( TInt i = EHeaderAddressFrom; i <= EHeaderAttachment ; i++ )
       
   438         {    
       
   439         if ( iHeaders[i].iControl &&  
       
   440              iHeaders[i].iOwned )
       
   441             {
       
   442             iHeaders[i].iControl->HandleResourceChange( aType );
       
   443             }
       
   444         }
       
   445 
       
   446     }
       
   447 
       
   448 
       
   449 //  End of File