IMPSengine/imapi/src/imstatuslistimpl.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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: Implements the CIMStatusFetcher and the MImStatusList interface.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "imstatusimpl.h"
       
    22 #include "apiutils.h"
       
    23 #include "impspresence.h"
       
    24 
       
    25 // CONSTANTS
       
    26 //_LIT( KUserAvailability, "UserAvailability" );
       
    27 _LIT( KOnLineStatus, "OnlineStatus" );
       
    28 _LIT( KCommCaps,     "CommCap" );
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CIMStatusListImpl::CIMStatusListImpl
       
    34 // C++ default constructor can NOT contain any code, that
       
    35 // might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CIMStatusListImpl::CIMStatusListImpl( CImpsPresenceList& aPresList )
       
    39         :   iPresList( aPresList ),
       
    40         iCurrentPresence( NULL ),
       
    41         iCurrentIndex( -1 )
       
    42     {
       
    43     }
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CIMStatusListImpl::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CIMStatusListImpl::ConstructL()
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CIMStatusList::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CIMStatusListImpl* CIMStatusListImpl::NewL( CImpsPresenceList& aPresList )
       
    61     {
       
    62     CIMStatusListImpl* self = new( ELeave ) CIMStatusListImpl( aPresList );
       
    63     CleanupStack::PushL( self );
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 
       
    71 // Destructor
       
    72 CIMStatusListImpl::~CIMStatusListImpl()
       
    73     {
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CIMStatusListImpl::Count
       
    79 // ?implementation_description
       
    80 // (other items were commented in a header).
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 TInt CIMStatusListImpl::Count()
       
    84     {
       
    85     return iPresList.Count();
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CIMStatusListImpl::IMStatusL
       
    90 // ?implementation_description
       
    91 // (other items were commented in a header).
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TIMAttribute CIMStatusListImpl::IMStatusL( TInt aIndex )
       
    95     {
       
    96     if ( iCurrentIndex != aIndex )
       
    97         {
       
    98         iCurrentPresence = &iPresList.PresenceL( aIndex );
       
    99         iCurrentIndex = aIndex;
       
   100         }
       
   101 
       
   102     // get the attribute
       
   103     TIMAttribute imAttr = EIMOffline;
       
   104     CImpsSubsList* subslist = iCurrentPresence->DefaultSubsListL( );
       
   105 //    CImpsUserAvailability* ua = NULL;
       
   106     CImpsOnlineStatus* os = NULL;
       
   107     CImpsCommCap* cc = NULL;
       
   108 
       
   109 
       
   110     if ( subslist )
       
   111         {
       
   112         CImpsPresenceAttr* attr = subslist->FirstAttribute();
       
   113         while ( attr )
       
   114             {
       
   115             /*
       
   116                         if( !attr->Name( ).Compare( KUserAvailability ) )
       
   117                             ua = STATIC_CAST( CImpsUserAvailability*, attr );
       
   118             */
       
   119             if ( !attr->Name( ).Compare( KOnLineStatus ) )
       
   120                 os = STATIC_CAST( CImpsOnlineStatus*, attr );
       
   121             if ( !attr->Name( ).Compare( KCommCaps ) )
       
   122                 cc = STATIC_CAST( CImpsCommCap*, attr );
       
   123             attr = subslist->NextAttribute();
       
   124             }
       
   125         }
       
   126 
       
   127     if ( os->Value() == EImpsTrue && cc->Cap( EImpsCapIM ) == EImpsTrue )
       
   128         {
       
   129         imAttr = EIMOnline;
       
   130         }
       
   131 
       
   132     return imAttr;
       
   133     }
       
   134 // -----------------------------------------------------------------------------
       
   135 // CIMStatusListImpl::OwnerUserIdL
       
   136 // ?implementation_description
       
   137 // (other items were commented in a header).
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 TPtrC CIMStatusListImpl::OwnerUserIdL( TInt aIndex )
       
   141     {
       
   142     if ( iCurrentIndex != aIndex )
       
   143         {
       
   144         iCurrentPresence = &iPresList.PresenceL( aIndex );
       
   145         iCurrentIndex = aIndex;
       
   146         }
       
   147 
       
   148     TImpsPresOwner ownerType;
       
   149     // get the user
       
   150     return iCurrentPresence->Owner( ownerType );
       
   151     }
       
   152 
       
   153 
       
   154 //  End of File