emailservices/emailcommon/src/CFSMailBoxBase.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  common base mailbox object
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <nmcommonheaders.h>
       
    20 #include "emailtrace.h"
       
    21 #include "CFSMailBoxBase.h"
       
    22 // <qmail>
       
    23 #include "CFSMailAddress.h"
       
    24 #include "mmrinfoprocessor.h"
       
    25 // </qmail>
       
    26 #include "nmmailbox.h"
       
    27 
       
    28 // ================= MEMBER FUNCTIONS ==========================================
       
    29 // -----------------------------------------------------------------------------
       
    30 // CFSMailBoxBase::NewLC
       
    31 // -----------------------------------------------------------------------------
       
    32 EXPORT_C CFSMailBoxBase* CFSMailBoxBase::NewLC( TFSMailMsgId aMailBoxId )
       
    33 {
       
    34     FUNC_LOG;
       
    35     CFSMailBoxBase* api = new (ELeave) CFSMailBoxBase();
       
    36     CleanupStack:: PushL(api);
       
    37     api->ConstructL(aMailBoxId);  
       
    38     return api; 
       
    39 }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CFSMailBoxBase::NewL
       
    43 // -----------------------------------------------------------------------------
       
    44 EXPORT_C CFSMailBoxBase* CFSMailBoxBase::NewL( TFSMailMsgId aMailBoxId )
       
    45 {
       
    46     FUNC_LOG;
       
    47     CFSMailBoxBase* api =  CFSMailBoxBase::NewLC(aMailBoxId);
       
    48     CleanupStack:: Pop(api);
       
    49     return api;
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CFSMailBoxBase::CFSMailBoxBase
       
    54 // -----------------------------------------------------------------------------
       
    55 CFSMailBoxBase::CFSMailBoxBase()
       
    56 {
       
    57     FUNC_LOG;
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CFSMailBoxBase::~CFSMailBoxBase
       
    62 // -----------------------------------------------------------------------------
       
    63 EXPORT_C CFSMailBoxBase::~CFSMailBoxBase()
       
    64 {
       
    65     FUNC_LOG;
       
    66     if( iMailBoxName )
       
    67         {
       
    68         delete iMailBoxName;
       
    69         }
       
    70     iMailBoxName = NULL;
       
    71 
       
    72     if( iBrId )
       
    73         {
       
    74         delete iBrId;
       
    75         }
       
    76     iBrId = NULL;
       
    77 
       
    78     if( iOwnMailAddress )
       
    79         {
       
    80         delete iOwnMailAddress;
       
    81         }
       
    82     iOwnMailAddress = NULL;
       
    83 
       
    84     if( iMRInfoProcessor )
       
    85         {
       
    86         delete iMRInfoProcessor;
       
    87         }
       
    88     iMRInfoProcessor = NULL;
       
    89 }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CFSMailBoxBase::ConstructL
       
    93 // -----------------------------------------------------------------------------
       
    94 void CFSMailBoxBase::ConstructL( const TFSMailMsgId aMailBoxId )
       
    95 {
       
    96     FUNC_LOG;
       
    97 	// <qmail> Removed iMailboxId </qmail>
       
    98     // prepare null empty descriptor
       
    99     iMailBoxName = HBufC::NewL(1);
       
   100     iMailBoxName->Des().Copy(KNullDesC());
       
   101 
       
   102     iBrId = HBufC::NewL(1);
       
   103     iBrId->Des().Copy(KNullDesC());
       
   104 
       
   105     // <qmail>
       
   106     // Creating QT side object of the mailbox class.
       
   107     iNmPrivateMailbox = new NmMailboxPrivate();
       
   108     // Initialize QT data: pluginId and id. These need conversions between QT
       
   109     // and Symbian data types. Name not set here as it is null.
       
   110 
       
   111     // typedef long int TInt32 -> typedef unsigned int quint32
       
   112     // NOTE: This cast will loose negative values: range [0,max] is identical
       
   113     // but range [min,0] is different between these data types.
       
   114     // -> Assumption: iUid should never contain negative value.
       
   115     iNmPrivateMailbox->mId.setId32( aMailBoxId.Id() );
       
   116 
       
   117     // typedef unsigned int TUint -> typedef unsigned int quint32
       
   118     iNmPrivateMailbox->mId.setPluginId32((unsigned int)aMailBoxId.PluginId().iUid);
       
   119     // </qmail>
       
   120 }
       
   121 
       
   122 // <qmail>
       
   123 // -----------------------------------------------------------------------------
       
   124 // CFSMailBoxBase::GetId
       
   125 // -----------------------------------------------------------------------------
       
   126 EXPORT_C TFSMailMsgId CFSMailBoxBase::GetId() const
       
   127 {
       
   128     FUNC_LOG;
       
   129     return TFSMailMsgId(iNmPrivateMailbox->mId);
       
   130 }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CFSMailBoxBase::GetName
       
   134 // -----------------------------------------------------------------------------
       
   135 EXPORT_C TDesC& CFSMailBoxBase::GetName()const
       
   136 {
       
   137     FUNC_LOG;
       
   138     iTextPtr.Set( 
       
   139         reinterpret_cast<const TUint16*> (iNmPrivateMailbox->mName.utf16()),
       
   140         iNmPrivateMailbox->mName.length());
       
   141     return iTextPtr;
       
   142 }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CFSMailBoxBase::SetName
       
   146 // -----------------------------------------------------------------------------
       
   147 EXPORT_C void CFSMailBoxBase::SetName( const TDesC& aMailBoxName )
       
   148 {
       
   149     FUNC_LOG;
       
   150     QString qtName = QString::fromUtf16(aMailBoxName.Ptr(), aMailBoxName.Length());
       
   151     iNmPrivateMailbox->mName = qtName;
       
   152 }
       
   153 // <qmail>
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CFSMailBoxBase::GetStatus
       
   157 // -----------------------------------------------------------------------------
       
   158 EXPORT_C TFSMailBoxStatus CFSMailBoxBase::GetStatus( ) const
       
   159 {
       
   160     FUNC_LOG;
       
   161     return EFSMailBoxOffline;
       
   162 }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CFSMailBoxBase::SetStatus
       
   166 // -----------------------------------------------------------------------------
       
   167 EXPORT_C void CFSMailBoxBase::SetStatus( const TFSMailBoxStatus /*aStatus*/ )
       
   168 {
       
   169     FUNC_LOG;
       
   170 }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CFSMailBoxBase::GetRCLInfo
       
   174 // -----------------------------------------------------------------------------
       
   175 EXPORT_C void CFSMailBoxBase::GetRCLInfo( TUid& aProtocolUid, TUint& aAccountUid )
       
   176 {
       
   177     FUNC_LOG;
       
   178     aProtocolUid = iProtocolUid;
       
   179     aAccountUid = iAccountUid;
       
   180 }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CFSMailBoxBase::SetRCLInfo
       
   184 // -----------------------------------------------------------------------------
       
   185 EXPORT_C void CFSMailBoxBase::SetRCLInfo( const TUid aProtocolUid, const TUint aAccountUid )
       
   186 {
       
   187     FUNC_LOG;
       
   188     iProtocolUid = aProtocolUid;
       
   189     iAccountUid = aAccountUid;
       
   190 }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CFSMailBoxBase::GetSettingsUid
       
   194 // -----------------------------------------------------------------------------
       
   195 EXPORT_C const TUid CFSMailBoxBase::GetSettingsUid()
       
   196   {
       
   197     FUNC_LOG;
       
   198     return iSettingsUid;
       
   199 }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CFSMailBoxBase::SetSettingsUid
       
   203 // -----------------------------------------------------------------------------
       
   204 EXPORT_C void CFSMailBoxBase::SetSettingsUid( const TUid aUid )
       
   205 {
       
   206     FUNC_LOG;
       
   207     iSettingsUid = aUid;
       
   208 }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CFSMailBoxBase::MRInfoProcessorL
       
   212 // -----------------------------------------------------------------------------
       
   213 EXPORT_C MMRInfoProcessor& CFSMailBoxBase::MRInfoProcessorL()
       
   214 {
       
   215     FUNC_LOG;
       
   216     return *iMRInfoProcessor;
       
   217 }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CFSMailBoxBase::IsMRInfoProcessorSet
       
   221 // -----------------------------------------------------------------------------
       
   222 EXPORT_C TBool CFSMailBoxBase::IsMRInfoProcessorSet()
       
   223 {
       
   224     FUNC_LOG;
       
   225     if(iMRInfoProcessor)
       
   226         {
       
   227         return ETrue;
       
   228         }
       
   229     else
       
   230         {
       
   231         return EFalse;
       
   232         }
       
   233 }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CFSMailBoxBase::SetMRInfoProcessorL
       
   237 // -----------------------------------------------------------------------------
       
   238 EXPORT_C void CFSMailBoxBase::SetMRInfoProcessorL( MMRInfoProcessor* aMRInfoProcessor )
       
   239 {
       
   240     FUNC_LOG;
       
   241 
       
   242     if(iMRInfoProcessor)
       
   243         {
       
   244         delete iMRInfoProcessor;
       
   245         }
       
   246     iMRInfoProcessor = aMRInfoProcessor;
       
   247 }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CFSMailBoxBase::OwnMailAddress
       
   251 // -----------------------------------------------------------------------------
       
   252 EXPORT_C CFSMailAddress& CFSMailBoxBase::OwnMailAddress( )
       
   253 {
       
   254     FUNC_LOG;
       
   255     return *iOwnMailAddress;
       
   256 }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CFSMailBoxBase::SetOwnMailAddress
       
   260 // -----------------------------------------------------------------------------
       
   261 EXPORT_C void CFSMailBoxBase::SetOwnMailAddressL( CFSMailAddress* aOwnMailAddress )
       
   262 {
       
   263     FUNC_LOG;
       
   264     if(iOwnMailAddress)
       
   265         {
       
   266         delete iOwnMailAddress;
       
   267         }
       
   268     iOwnMailAddress = aOwnMailAddress;
       
   269 
       
   270     // set also branding id based on domain name
       
   271     TPtrC ptr = OwnMailAddress().GetEmailAddress();
       
   272     TInt index = ptr.Locate('@') + 1;
       
   273     if(index > 0 && ptr.Length() > 0)
       
   274         {
       
   275         if(iBrId)
       
   276             {
       
   277             delete iBrId;
       
   278             iBrId = NULL;
       
   279             }
       
   280         ptr.Set( ptr.Right( ptr.Length() - index ) );
       
   281         iBrId = HBufC::New(ptr.Length());
       
   282         iBrId->Des().Copy(ptr);
       
   283         }
       
   284     iNmPrivateMailbox->mAddress = aOwnMailAddress->GetNmAddress();
       
   285 }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // CFSMailBoxBase::BrandingId
       
   289 // -----------------------------------------------------------------------------
       
   290 TDesC& CFSMailBoxBase::BrandingId( )
       
   291 {
       
   292     FUNC_LOG;
       
   293     return *iBrId;
       
   294 }
       
   295 
       
   296 // <qmail> Removed SetMailBoxId </qmail>
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CFSMailBoxBase::GetNmMailbox
       
   300 // -----------------------------------------------------------------------------
       
   301 // <qmail>
       
   302 EXPORT_C NmMailbox* CFSMailBoxBase::GetNmMailbox()
       
   303 {
       
   304     NmMailbox* nmmailbox = new NmMailbox(iNmPrivateMailbox);
       
   305     return nmmailbox;
       
   306 }
       
   307 // </qmail>