ccservices/cmsservices/presencetrafficlights/src/presencetrafficlights.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 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:  This class handles branded presence icons for phonebook contacts
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <badesca.h>
       
    21 #include <flogger.h>
       
    22 
       
    23 #include "mpresencetrafficlightsobs.h"
       
    24 #include "cmsonecontactstatus.h"
       
    25 #include "presencetrafficlighticons.h"
       
    26 #include "presencetrafficlights.h"
       
    27 
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // MPresenceTrafficLights::NewL()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C MPresenceTrafficLights* MPresenceTrafficLights::NewL()
       
    35     {
       
    36     return CPresenceTrafficLights::NewL();
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------
       
    40 // CPresenceTrafficLights::NewL
       
    41 // 
       
    42 // ----------------------------------------------------------
       
    43 //
       
    44 CPresenceTrafficLights* CPresenceTrafficLights::NewL()     
       
    45     {
       
    46     CPresenceTrafficLights* self = new CPresenceTrafficLights( );
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( KTrafficLightService, KTrafficOnline, KTrafficOffline );
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ----------------------------------------------------------
       
    54 // CPresenceTrafficLights::New
       
    55 // 
       
    56 // ----------------------------------------------------------
       
    57 //
       
    58 void CPresenceTrafficLights::ConstructL(
       
    59     const TDesC8& aDefaultTrafficLightBrandId, 
       
    60     const TDesC8& aDefaultOnlineElementId, 
       
    61     const TDesC8& aDefaultOfflineElementId )
       
    62     {
       
    63     iDefaultTrafficLightBrandId = aDefaultTrafficLightBrandId.AllocL();
       
    64     iDefaultOnlineElementId = aDefaultOnlineElementId.AllocL();
       
    65     iDefaultOfflineElementId = aDefaultOfflineElementId.AllocL();
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------
       
    69 // CPresenceTrafficLights::CPresenceTrafficLights
       
    70 // 
       
    71 // ----------------------------------------------------------
       
    72 //
       
    73 CPresenceTrafficLights::CPresenceTrafficLights(  )
       
    74     {
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------
       
    78 // CPresenceTrafficLights::~CPresenceTrafficLights
       
    79 // 
       
    80 // ----------------------------------------------------------
       
    81 //
       
    82 CPresenceTrafficLights::~CPresenceTrafficLights()
       
    83     {
       
    84     delete iDefaultTrafficLightBrandId;
       
    85     delete iDefaultOnlineElementId;
       
    86     delete iDefaultOfflineElementId;
       
    87     
       
    88     iStatuses.ResetAndDestroy();
       
    89     iStatuses.Close();
       
    90     }
       
    91 
       
    92 // ----------------------------------------------------------
       
    93 // CPresenceTrafficLights::SubscribeBrandingForContactL
       
    94 // 
       
    95 // ----------------------------------------------------------
       
    96 //
       
    97 void CPresenceTrafficLights::SubscribeBrandingForContactL( 
       
    98     MVPbkContactLink* aContact, MDesC16Array* aIdentities, MPresenceIconNotifier* aCallback,
       
    99     TInt aId )
       
   100     {
       
   101 
       
   102 #ifdef _DEBUG
       
   103     CPresenceTrafficLights::WriteToLog( _L8( "CPresenceTrafficLights::SubscribeBrandingForContactL" ) );
       
   104 #endif    
       
   105         
       
   106     // search first that this does not exist.
       
   107     CCmsOneContactStatus* one = FindOne( aContact, aCallback );
       
   108     if ( !one )
       
   109         {    
       
   110         one = CCmsOneContactStatus::NewL( *aCallback, aContact, 
       
   111             iDefaultTrafficLightBrandId, iDefaultOnlineElementId, iDefaultOfflineElementId, aId );
       
   112     
       
   113         iStatuses.Append( one );
       
   114         
       
   115         one->SubscribeL( aIdentities );        
       
   116         } 
       
   117     else
       
   118         {        
       
   119         }
       
   120     return;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------
       
   124 //
       
   125 void CPresenceTrafficLights::GetAllBrandingsForContactL( 
       
   126     MVPbkContactLink* aContact, MDesC16Array* aIdentities, MPresenceIconNotifier* aCallback,
       
   127     TInt aId )
       
   128     {
       
   129 
       
   130 #ifdef _DEBUG
       
   131     CPresenceTrafficLights::WriteToLog( _L8( "CPresenceTrafficLights::GetAllBrandingsForContactL" ) );
       
   132 #endif    
       
   133         
       
   134     // search first that this does not exist.
       
   135     CCmsOneContactStatus* one = CCmsOneContactStatus::NewL( *aCallback, aContact, 
       
   136             iDefaultTrafficLightBrandId, iDefaultOnlineElementId, iDefaultOfflineElementId, aId );
       
   137     CleanupStack::PushL( one );
       
   138     
       
   139     one->GetAllL( aIdentities );
       
   140     
       
   141     CleanupStack::PopAndDestroy( one );
       
   142     return;
       
   143     }
       
   144 
       
   145 // ----------------------------------------------------------
       
   146 // CPresenceTrafficLights::UnsubscribeBrandingForContact
       
   147 // 
       
   148 // ----------------------------------------------------------
       
   149 //
       
   150 void CPresenceTrafficLights::UnsubscribeBrandingForContact( 
       
   151     MVPbkContactLink* aContact, MPresenceIconNotifier* aCallback )
       
   152     {
       
   153 #ifdef _DEBUG
       
   154     CPresenceTrafficLights::WriteToLog( _L8( "CPresenceTrafficLights::UnsubscribeBrandingForContact" ) );
       
   155 #endif 
       
   156               
       
   157     TInt count = iStatuses.Count();
       
   158     for ( TInt i=0; i < count; i++ )
       
   159         {       
       
   160         if ( iStatuses[i]->IsSameContact( aContact, aCallback ))
       
   161             {
       
   162             delete iStatuses[i];
       
   163             iStatuses.Remove(i);
       
   164             break;
       
   165             }
       
   166         }
       
   167     return;
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------------
       
   171 // CPresenceTrafficLights::FindOne
       
   172 // 
       
   173 // ----------------------------------------------------------
       
   174 //
       
   175 CCmsOneContactStatus* CPresenceTrafficLights::FindOne( MVPbkContactLink* aContact, MPresenceIconNotifier* aCallback )
       
   176     {
       
   177     CCmsOneContactStatus* ret = NULL;
       
   178     
       
   179     if ( !aContact )
       
   180         {
       
   181         return ret;
       
   182         } 
       
   183     
       
   184     TInt count = iStatuses.Count();
       
   185     for ( TInt i=0; i < count; i++ )
       
   186         {
       
   187         if ( iStatuses[i]->IsSameContact( aContact, aCallback ) )
       
   188             {
       
   189             ret = iStatuses[i];
       
   190             break;
       
   191             }
       
   192         }
       
   193     return ret;
       
   194     }
       
   195     
       
   196 #ifdef _DEBUG
       
   197 // ----------------------------------------------------
       
   198 // CPresenceTrafficLights::WriteToLog
       
   199 // 
       
   200 // ----------------------------------------------------
       
   201 //
       
   202 void CPresenceTrafficLights::WriteToLog( TRefByValue<const TDesC8> aFmt,... )
       
   203     {
       
   204     _LIT( KMyLogDir, "CCA");
       
   205     _LIT( KMyLogFile, "trafficlights.txt");
       
   206     const TInt KMyBufferMaxSize = 200;
       
   207     VA_LIST list;
       
   208     VA_START( list, aFmt );
       
   209     TBuf8<KMyBufferMaxSize> buf;
       
   210     buf.FormatList( aFmt, list );
       
   211     RFileLogger::Write( KMyLogDir, KMyLogFile, EFileLoggingModeAppend, buf );
       
   212     // RDebug::RawPrint( buf );
       
   213     }
       
   214 #endif  //_DEBUG    
       
   215 
       
   216