meetingrequest/mrgui/mrfieldbuilderpluginextension/src/resmrpluginextensionstatic.cpp
branchRCL_3
changeset 16 4ce476e64c59
parent 0 8466d47a6819
equal deleted inserted replaced
13:0396474f30f5 16:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 
    17 
    18 #include "emailtrace.h"
    18 #include "emailtrace.h"
    19 #include "resmrpluginextensionstatic.h"
    19 #include "resmrpluginextensionstatic.h"
    20 #include "cmrmailboxutils.h"
    20 #include "cmrmailboxutils.h"
       
    21 #include "esmrhelper.h"
       
    22 #include <ct/rcpointerarray.h>
       
    23 
       
    24 // <cmail> Removed profiling. </cmail>
    21 
    25 
    22 /**
    26 /**
    23  * Storage class for RESMRStatic.
    27  * Storage class for RESMRStatic.
    24  */
    28  */
    25 class TESMRPluginExtensionData
    29 class TESMRPluginExtensionData
    37 const TInt KMailBox = 0x01;
    41 const TInt KMailBox = 0x01;
    38 
    42 
    39 // Definition for equal string
    43 // Definition for equal string
    40 const TInt KEqualString(0);
    44 const TInt KEqualString(0);
    41 
    45 
    42 // ---------------------------------------------------------------------------
       
    43 // Cleanup operation for RPointerArray.
       
    44 // @param aArray Pointer to RPointerArray.
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 void MailboxPointerArrayCleanup( TAny* aArray )
       
    48     {
       
    49     // just to avoid warnings when MR not supported
       
    50     RPointerArray<CFSMailBox>* entryArray =
       
    51         static_cast<RPointerArray<CFSMailBox>*>( aArray );
       
    52 
       
    53     entryArray->ResetAndDestroy();
       
    54     entryArray->Close();
       
    55     }
       
    56 
       
    57 }//namespace
    46 }//namespace
    58 
    47 
    59 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    60 // RESMRPluginExtensionStatic::RESMRPluginExtensionStatic
    49 // RESMRPluginExtensionStatic::RESMRPluginExtensionStatic
    61 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    81 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
    82 //
    71 //
    83 void RESMRPluginExtensionStatic::ConnectL( )
    72 void RESMRPluginExtensionStatic::ConnectL( )
    84     {
    73     {
    85     FUNC_LOG;
    74     FUNC_LOG;
    86     if ( iStaticData )
    75     if (iStaticData )
    87         {
    76         {
    88         return;
    77         return;
    89         }
    78         }
    90 
    79 
    91     // Retrieve Tls pointer
    80     // Retrieve Tls pointer
    92     iStaticData = static_cast<TESMRPluginExtensionData*>( Dll::Tls());
    81     iStaticData = static_cast<TESMRPluginExtensionData*>( Dll::Tls());
    93 
    82 
    94     // If Tls pointer was not set, create new static stuct
    83     // If Tls pointer was not set, create new static stuct
    95     // with NULL values
    84     // with NULL values
    96     if ( !iStaticData )
    85     if (!iStaticData)
    97         {
    86         {
    98         iStaticData = new (ELeave) TESMRPluginExtensionData();
    87         iStaticData = new (ELeave) TESMRPluginExtensionData();
    99         memset ( iStaticData, 0, sizeof( TESMRPluginExtensionData) );
    88         memset ( iStaticData, 0, sizeof( TESMRPluginExtensionData) );
   100         Dll::SetTls ( iStaticData );
    89         Dll::SetTls ( iStaticData );
   101         }
    90         }
   107 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
   108 //
    97 //
   109 void RESMRPluginExtensionStatic::Close( )
    98 void RESMRPluginExtensionStatic::Close( )
   110     {
    99     {
   111     FUNC_LOG;
   100     FUNC_LOG;
   112     if ( iStaticData )
   101     if (iStaticData )
   113         {
   102         {
   114 
   103 
   115         // If FSMailClientL or DefaultFSMailBox was used
   104         // If FSMailClientL or DefaultFSMailBox was used
   116         if ( iUsedTypes & KMailBox )
   105         if (iUsedTypes & KMailBox )
   117             {
   106             {
   118             // Decrease counter
   107             // Decrease counter
   119             --iStaticData->iFSMailBoxCount;
   108             --iStaticData->iFSMailBoxCount;
   120 
   109 
   121             // If this was last instance using pointer
   110             // If this was last instance using pointer
   122             if ( iStaticData->iFSMailBoxCount == 0 )
   111             if (iStaticData->iFSMailBoxCount == 0 )
   123                 {
   112                 {
   124                 // Owned by CFSMailClient
   113                 // Owned by CFSMailClient
   125                 delete iStaticData->iDefaultFSMailBox;
   114                 delete iStaticData->iDefaultFSMailBox;
   126                 iStaticData->iDefaultFSMailBox = NULL;
   115                 iStaticData->iDefaultFSMailBox = NULL;
   127 
   116 
   161 
   150 
   162 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   163 // RESMRPluginExtensionStatic::DefaultFSMailBoxL
   152 // RESMRPluginExtensionStatic::DefaultFSMailBoxL
   164 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   165 //
   154 //
   166 CFSMailBox& RESMRPluginExtensionStatic::DefaultFSMailBoxL( TBool aForceReset )
   155 CFSMailBox& RESMRPluginExtensionStatic::DefaultFSMailBoxL()
   167     {
   156     {
   168     FUNC_LOG;
   157     FUNC_LOG;
   169     
       
   170     if ( aForceReset && iStaticData->iDefaultFSMailBox )
       
   171         {
       
   172         delete iStaticData->iDefaultFSMailBox;
       
   173         iStaticData->iDefaultFSMailBox = NULL;
       
   174         }
       
   175     
       
   176     if ( !iStaticData->iDefaultFSMailBox )
   158     if ( !iStaticData->iDefaultFSMailBox )
   177         {
   159         {
   178         CFSMailClient& fsMailClient = FSMailClientL();
   160         CFSMailClient& fsMailClient = FSMailClientL();
   179 
   161 
   180         CMRMailboxUtils* mbUtils =
   162         CMRMailboxUtils* mbUtils =
   184         CMRMailboxUtils::TMailboxInfo mbInfo;
   166         CMRMailboxUtils::TMailboxInfo mbInfo;
   185         User::LeaveIfError(
   167         User::LeaveIfError(
   186                 mbUtils->GetDefaultMRMailBoxL( mbInfo ) );
   168                 mbUtils->GetDefaultMRMailBoxL( mbInfo ) );
   187 
   169 
   188         // Loop throug all mailboxes in this plug-in
   170         // Loop throug all mailboxes in this plug-in
   189         RPointerArray<CFSMailBox> mailboxes; // codescanner::resourcenotoncleanupstack
   171         RCPointerArray<CFSMailBox> mailboxes;
   190         CleanupStack::PushL(
   172         CleanupClosePushL( mailboxes );
   191                 TCleanupItem(
   173         
   192                         MailboxPointerArrayCleanup,
       
   193                         &mailboxes    ) );
       
   194 
       
   195         // With null uid we get all mailboxes
   174         // With null uid we get all mailboxes
   196         TFSMailMsgId msgId;
   175         TFSMailMsgId msgId;
   197         fsMailClient.ListMailBoxes(
   176         fsMailClient.ListMailBoxes(
   198                 msgId, mailboxes );
   177                 msgId, mailboxes );
   199 
   178 
   210                 iStaticData->iDefaultFSMailBox = mailboxes[j];
   189                 iStaticData->iDefaultFSMailBox = mailboxes[j];
   211                 mailboxes.Remove(j);
   190                 mailboxes.Remove(j);
   212                 }
   191                 }
   213             }
   192             }
   214 
   193 
   215         CleanupStack::PopAndDestroy(); // mailboxes
   194         CleanupStack::PopAndDestroy( 2, mbUtils ); // mailboxes
   216         CleanupStack::PopAndDestroy( mbUtils );
       
   217         mbUtils = NULL;
   195         mbUtils = NULL;
   218 
   196 
   219         if ( !iStaticData->iDefaultFSMailBox )
   197         if ( !iStaticData->iDefaultFSMailBox )
   220             {
   198             {
   221             User::Leave( KErrAbort );
   199             User::Leave( KErrAbort );
   226     ++iStaticData->iFSMailBoxCount;
   204     ++iStaticData->iFSMailBoxCount;
   227     return *iStaticData->iDefaultFSMailBox;
   205     return *iStaticData->iDefaultFSMailBox;
   228     }
   206     }
   229 
   207 
   230 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
       
   209 // RESMRPluginExtensionStatic::MailBoxL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 CFSMailBox* RESMRPluginExtensionStatic::MailBoxL( const TDesC& aEmailAddress )
       
   213     {
       
   214     TPtrC address( ESMRHelper::AddressWithoutMailtoPrefix( aEmailAddress ) );
       
   215     CFSMailClient& fsMailClient = FSMailClientL();
       
   216 
       
   217     // Loop throug all mailboxes in this plug-in
       
   218     RCPointerArray<CFSMailBox> mailboxes;
       
   219     CleanupClosePushL( mailboxes );
       
   220 
       
   221     // With null uid we get all mailboxes
       
   222     TFSMailMsgId msgId;
       
   223     fsMailClient.ListMailBoxes(
       
   224             msgId, mailboxes );
       
   225 
       
   226     TInt mailboxCount( mailboxes.Count() );
       
   227     CFSMailBox* mailBox = NULL;
       
   228     
       
   229     for ( TInt i(0); i < mailboxCount && !mailBox; ++i )
       
   230         {
       
   231         TPtrC mailboxOwnerAddName(
       
   232                 mailboxes[i]->OwnMailAddress().GetEmailAddress() );
       
   233         if ( mailboxOwnerAddName.CompareF( address ) == 0 )
       
   234             {
       
   235             // Correct mailbox is found
       
   236             mailBox = mailboxes[ i ];
       
   237             mailboxes.Remove( i );
       
   238             }
       
   239         }
       
   240     CleanupStack::PopAndDestroy( &mailboxes );
       
   241 
       
   242     if ( !mailBox )
       
   243         {
       
   244         User::Leave( KErrNotFound );
       
   245         }
       
   246     
       
   247     return mailBox;
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
   231 // RESMRPluginExtensionStatic::FSMailClientL
   251 // RESMRPluginExtensionStatic::FSMailClientL
   232 // ---------------------------------------------------------------------------
   252 // ---------------------------------------------------------------------------
   233 //
   253 //
   234 CFSMailClient& RESMRPluginExtensionStatic::FSMailClientL( )
   254 CFSMailClient& RESMRPluginExtensionStatic::FSMailClientL( )
   235     {
   255     {