phonebookui/Phonebook2/Commands/src/CPbk2AiwInterestItemBase.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 AIW interest item base.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2AiwInterestItemBase.h"
       
    20 
       
    21 // System includes
       
    22 #include <AiwServiceHandler.h>
       
    23 
       
    24 // Debugging headers
       
    25 #include <Pbk2Debug.h>
       
    26 #include <Pbk2Profile.h>
       
    27 
       
    28 
       
    29 /// Unnamed namespace for local definitions
       
    30 namespace {
       
    31 
       
    32 const TInt KGranularity = 1;
       
    33 
       
    34 } /// namespace
       
    35 
       
    36 
       
    37 // --------------------------------------------------------------------------
       
    38 // CPbk2AiwInterestItemBase::CPbk2AiwInterestItemBase
       
    39 // --------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CPbk2AiwInterestItemBase::CPbk2AiwInterestItemBase
       
    42         ( TInt aInterestId, CAiwServiceHandler& aServiceHandler ) :
       
    43             CActive( EPriorityIdle ),
       
    44             iServiceHandler( aServiceHandler ),
       
    45             iInterestId( aInterestId ),
       
    46             iAttachedResources( KGranularity )
       
    47     {
       
    48     // Do nothing
       
    49     }
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CPbk2AiwInterestItemBase::~CPbk2AiwInterestItemBase
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 //CPbk2AiwInterestItemBase::~CPbk2AiwInterestItemBase()
       
    56 //    {
       
    57     // Do nothing
       
    58 //    }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CPbk2AiwInterestItemBase::IsMenuPaneAttached
       
    62 // --------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C TBool CPbk2AiwInterestItemBase::IsMenuPaneAttached
       
    65         ( TInt aMenuResourceId )
       
    66     {
       
    67     TBool menuFound = EFalse;
       
    68 
       
    69     // Check through attached resources
       
    70     TInt count = iAttachedResources.Count();
       
    71     for( TInt i = 0; i < count && !menuFound; ++i )
       
    72         {
       
    73         if( iAttachedResources[i].iMenuResourceId == aMenuResourceId )
       
    74             {
       
    75             menuFound = ETrue;
       
    76             }
       
    77         }
       
    78 
       
    79     return menuFound;
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // CPbk2AiwInterestItemBase::InterestId
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C TInt CPbk2AiwInterestItemBase::InterestId() const
       
    87     {
       
    88     return iInterestId;
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CPbk2AiwInterestItemBase::AttachL
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CPbk2AiwInterestItemBase::AttachL
       
    96         ( TInt aMenuResourceId, TInt aInterestResourceId,
       
    97           TBool aAttachBaseServiceInterest )
       
    98     {
       
    99     TBool alreadyAttached = EFalse;
       
   100     TBool baseServiceAttached = EFalse;
       
   101     TAttachedResources resource;
       
   102     TInt index = KErrNotFound;
       
   103 
       
   104     TInt count = iAttachedResources.Count();
       
   105 
       
   106     // First check has the resource-interest pair already been attached
       
   107     for (TInt i=0; i<count; ++i)
       
   108         {
       
   109         if ( ( iAttachedResources[i].iMenuResourceId == aMenuResourceId) &&
       
   110             ( iAttachedResources[i].iInterestResourceId
       
   111                 == aInterestResourceId ) )
       
   112             {
       
   113             alreadyAttached = ETrue;
       
   114             if (iAttachedResources[i].iBaseServiceAttached)
       
   115                 {
       
   116                 baseServiceAttached = ETrue;
       
   117                 }
       
   118             // Store the index and break out
       
   119             index = i;
       
   120             break;
       
   121             }
       
   122         }
       
   123 
       
   124     if ( !alreadyAttached )
       
   125         {
       
   126         PBK2_PROFILE_START(Pbk2Profile::EAiwMenuAttach);
       
   127         // Attach criteria items to menu
       
   128         iServiceHandler.AttachMenuL(aMenuResourceId,
       
   129             aInterestResourceId);
       
   130         PBK2_PROFILE_END(Pbk2Profile::EAiwMenuAttach);
       
   131 
       
   132         resource.iInterestResourceId = aInterestResourceId;
       
   133         resource.iMenuResourceId = aMenuResourceId;
       
   134         }
       
   135 
       
   136     // If wanted, attach also base interest...
       
   137     if (aAttachBaseServiceInterest)
       
   138         {
       
   139         // ...if not already done
       
   140         if (!baseServiceAttached)
       
   141             {
       
   142             PBK2_PROFILE_START(Pbk2Profile::EAiwBaseServiceAttach);
       
   143             iServiceHandler.AttachL(aInterestResourceId);
       
   144             PBK2_PROFILE_END(Pbk2Profile::EAiwBaseServiceAttach);
       
   145             resource.iBaseServiceAttached = ETrue;
       
   146             }
       
   147         }
       
   148 
       
   149     if ( !alreadyAttached )
       
   150         {
       
   151         // Append to the array
       
   152         iAttachedResources.AppendL(resource);
       
   153         }
       
   154     else if ( !baseServiceAttached && resource.iBaseServiceAttached )
       
   155         {
       
   156         // We need to modify the base service flag
       
   157         iAttachedResources[index].iBaseServiceAttached = ETrue;
       
   158         }
       
   159     }
       
   160 
       
   161 // End of File