ipsservices/ipssosplugin/src/ipsplgsettingsobserver.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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: This file implements class CIpsPlgSettingsObserver.
       
    15 *
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "emailtrace.h"
       
    24 #include "ipsplgheaders.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // ----------------------------------------------------------------------------
       
    30 CIpsPlgSettingsObserver::CIpsPlgSettingsObserver( 
       
    31     TFSMailMsgId aAccount,
       
    32     CRepository& aCenRep,
       
    33     MIpsPlgSettingsObserverCallback& aIPSCallback )
       
    34     : 
       
    35     CActive( CActive::EPriorityStandard ),
       
    36     iCenRep( aCenRep ),
       
    37     iAccount( aAccount ),
       
    38     iFSObservers( 2 ),
       
    39     iIPSCallback( aIPSCallback )
       
    40     {
       
    41     FUNC_LOG;
       
    42 
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // ----------------------------------------------------------------------------
       
    47 CIpsPlgSettingsObserver* CIpsPlgSettingsObserver::NewL( 
       
    48     TFSMailMsgId aAccount,
       
    49     CRepository& aCenRep,
       
    50     MIpsPlgSettingsObserverCallback& aIPSCallback )
       
    51     {
       
    52     FUNC_LOG;
       
    53     CIpsPlgSettingsObserver* self = 
       
    54         new(ELeave) CIpsPlgSettingsObserver( aAccount, aCenRep, aIPSCallback );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL( );
       
    57     CleanupStack::Pop( self );
       
    58     return self;
       
    59     }
       
    60 // ----------------------------------------------------------------------------
       
    61 // ----------------------------------------------------------------------------
       
    62 void CIpsPlgSettingsObserver::ConstructL( )
       
    63     {
       
    64     FUNC_LOG;
       
    65     CActiveScheduler::Add( this );
       
    66     }
       
    67 
       
    68     
       
    69 // ----------------------------------------------------------------------------
       
    70 // ----------------------------------------------------------------------------
       
    71 CIpsPlgSettingsObserver::~CIpsPlgSettingsObserver()
       
    72     {
       
    73     FUNC_LOG;
       
    74     Cancel();
       
    75     iFSObservers.Close();
       
    76     } 
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // ----------------------------------------------------------------------------
       
    80 void CIpsPlgSettingsObserver::DoCancel()
       
    81     {
       
    82     FUNC_LOG;
       
    83     iCenRep.NotifyCancel( iKey );
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // ----------------------------------------------------------------------------
       
    88 void CIpsPlgSettingsObserver::RunL()
       
    89     {
       
    90     FUNC_LOG;
       
    91     if ( iStatus.Int() == KErrNone )
       
    92         {
       
    93         for ( TInt i = 0; i < iFSObservers.Count(); i++ )
       
    94             {
       
    95             iFSObservers[i]->EventL( 
       
    96                 TFSEventMailboxSettingsChanged, 
       
    97                 iAccount,
       
    98                 NULL,
       
    99                 NULL,
       
   100                 NULL );            
       
   101             iIPSCallback.SettingsChangedL( iAccount );
       
   102             }
       
   103         Activate();//we don't set a new key here
       
   104         }
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // ----------------------------------------------------------------------------
       
   109 TInt CIpsPlgSettingsObserver::RunError( TInt /* aError */ )
       
   110     {
       
   111     FUNC_LOG;
       
   112     // Just ignore any error and continue without
       
   113     // any handling to allow smooth execution. 
       
   114     return KErrNone;            
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // ----------------------------------------------------------------------------
       
   119 void CIpsPlgSettingsObserver::SetKeyAndActivateL( 
       
   120     TUint32 aKey, 
       
   121     const RPointerArray<MFSMailEventObserver>& aObservers )
       
   122     {
       
   123     FUNC_LOG;
       
   124     if ( IsActive() && aKey != iKey )
       
   125         {
       
   126         Cancel();
       
   127         iKey = aKey;
       
   128         Activate();
       
   129         }
       
   130     else if ( !IsActive() )
       
   131         {
       
   132         iKey = aKey;
       
   133         Activate();
       
   134         }
       
   135     iFSObservers.Reset();
       
   136     for ( TInt i = 0; i < aObservers.Count(); i++ )
       
   137         {
       
   138         iFSObservers.AppendL(aObservers[i]);
       
   139         }
       
   140     }
       
   141 // ----------------------------------------------------------------------------
       
   142 // ---------------------------------------------------------------------------- 
       
   143 void CIpsPlgSettingsObserver::Activate()
       
   144     {
       
   145     FUNC_LOG;
       
   146     TInt error = iCenRep.NotifyRequest( iKey, iStatus );
       
   147     if ( error == KErrNone )
       
   148         {
       
   149         SetActive();
       
   150         }
       
   151     }
       
   152 // ----------------------------------------------------------------------------
       
   153 // ----------------------------------------------------------------------------
       
   154 void CIpsPlgSettingsObserver::UnActivate()
       
   155     {
       
   156     FUNC_LOG;
       
   157     // set null, not owned
       
   158     iFSObservers.Reset();
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // ----------------------------------------------------------------------------
       
   163 TFSMailMsgId CIpsPlgSettingsObserver::MailboxId()
       
   164     {
       
   165     FUNC_LOG;
       
   166     return iAccount;
       
   167     }
       
   168 //  End of File  
       
   169