phonebookui/Phonebook2/Commands/src/CPbk2AiwInterestArray.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 array.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2AiwInterestArray.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2AiwInterestItemFactory.h"
       
    24 #include <CPbk2CommandHandler.h>
       
    25 #include "Pbk2InternalCommands.hrh"
       
    26 
       
    27 // Virtual Phonebook
       
    28 #include <MVPbkBaseContactField.h>
       
    29 #include <MVPbkContactLink.h>
       
    30 
       
    31 // System includes
       
    32 #include <AiwServiceHandler.h>
       
    33 
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CPbk2AiwInterestArray::CPbk2AiwInterestArray
       
    37 // --------------------------------------------------------------------------
       
    38 //
       
    39 inline CPbk2AiwInterestArray::CPbk2AiwInterestArray()
       
    40     {
       
    41     }
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CPbk2AiwInterestArray::~CPbk2AiwInterestArray
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CPbk2AiwInterestArray::~CPbk2AiwInterestArray()
       
    48     {
       
    49     iAiwQueue.Close();
       
    50     delete iInterestItemFactory;
       
    51     iInterestItems.ResetAndDestroy();
       
    52     delete iServiceHandler;
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CPbk2AiwInterestArray::ConstructL
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 inline void CPbk2AiwInterestArray::ConstructL()
       
    60     {
       
    61     iServiceHandler = CAiwServiceHandler::NewL();
       
    62     iInterestItemFactory = CPbk2AiwInterestItemFactory::NewL
       
    63         ( *iServiceHandler );
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CPbk2AiwInterestArray::NewL
       
    68 // --------------------------------------------------------------------------
       
    69 //
       
    70 CPbk2AiwInterestArray* CPbk2AiwInterestArray::NewL()
       
    71     {
       
    72     CPbk2AiwInterestArray* self = new ( ELeave ) CPbk2AiwInterestArray();
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // --------------------------------------------------------------------------
       
    80 // CPbk2AiwInterestArray::QueueInterestL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 void CPbk2AiwInterestArray::QueueInterestL
       
    84         ( const TInt aInterestId, const TInt aMenuResourceId,
       
    85           const TInt aInterestResourceId,
       
    86           const TBool aAttachBaseServiceInterest)
       
    87     {
       
    88     // Queue interest item
       
    89     iAiwQueue.Append( TAiwQueueStruct( aInterestId, 
       
    90         aMenuResourceId, aInterestResourceId, aAttachBaseServiceInterest ) );
       
    91     }
       
    92 
       
    93 // --------------------------------------------------------------------------
       
    94 // CPbk2AiwInterestArray::ServiceCmdByMenuCmd
       
    95 // --------------------------------------------------------------------------
       
    96 //
       
    97 TInt CPbk2AiwInterestArray::ServiceCmdByMenuCmd( TInt aMenuCmdId ) const
       
    98     {
       
    99     return iServiceHandler->ServiceCmdByMenuCmd( aMenuCmdId );
       
   100     }
       
   101 
       
   102 // --------------------------------------------------------------------------
       
   103 // CPbk2AiwInterestArray::InterestId
       
   104 // --------------------------------------------------------------------------
       
   105 //
       
   106 TInt CPbk2AiwInterestArray::InterestId() const
       
   107     {
       
   108     return KErrNotSupported;
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CPbk2AiwInterestArray::DynInitMenuPaneL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 TBool CPbk2AiwInterestArray::DynInitMenuPaneL
       
   116         ( TInt aResourceId,  CEikMenuPane& aMenuPane,
       
   117           const MPbk2ContactUiControl& aControl )
       
   118     {
       
   119     // purge aiw interest queue
       
   120     PurgeAiwQueueL();
       
   121 
       
   122     // Offer the menu for AIW framework first
       
   123     TBool ret = iServiceHandler->HandleSubmenuL( aMenuPane );
       
   124 
       
   125     if ( !ret )
       
   126         {
       
   127         // The submenu was not handled by AIW framework,
       
   128         // offer it to interest items
       
   129         for (TInt j = 0; j < iInterestItems.Count(); ++j)
       
   130             {
       
   131             MPbk2AiwInterestItem* interestItem = iInterestItems[j];
       
   132             ret = interestItem->DynInitMenuPaneL
       
   133                 ( aResourceId, aMenuPane, aControl );
       
   134             if ( ret )
       
   135                 {
       
   136                 // Do not continue the loop if menu was handled
       
   137                 break;
       
   138                 }
       
   139             }
       
   140         }
       
   141     return ret;
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CPbk2AiwInterestArray::HandleCommandL
       
   146 // --------------------------------------------------------------------------
       
   147 //
       
   148 TBool CPbk2AiwInterestArray::HandleCommandL
       
   149         ( TInt aMenuCommandId, MPbk2ContactUiControl& aControl,
       
   150           TInt aServiceCommandId /*= KNullHandle*/ )
       
   151     {
       
   152     TBool ret = EFalse;
       
   153 
       
   154     // purge aiw interest queue
       
   155     PurgeAiwQueueL();
       
   156 
       
   157     // Send key is bound to call command or prepend command
       
   158     if ( !aControl.ContactsMarked() && aMenuCommandId == EPbk2CmdCall || 
       
   159          aMenuCommandId == EPbk2CmdPrepend )
       
   160         {
       
   161         aServiceCommandId = KAiwCmdCall;
       
   162         }
       
   163     else if ( aMenuCommandId == EPbk2CmdPoC )
       
   164         {
       
   165         aServiceCommandId = KAiwCmdPoC;
       
   166         }
       
   167     else if ( aMenuCommandId == KOtasAiwCmdSynchronize || 
       
   168             aMenuCommandId == KOtasAiwCmdSettings )
       
   169         {
       
   170         aServiceCommandId = aMenuCommandId;
       
   171         }
       
   172 
       
   173     // If service command parameter was not given, ask it from AIW framework
       
   174     if ( !aServiceCommandId )
       
   175         {
       
   176         aServiceCommandId =
       
   177             iServiceHandler->ServiceCmdByMenuCmd( aMenuCommandId );
       
   178         }
       
   179 
       
   180     // There was a provider
       
   181     if ( aServiceCommandId )
       
   182         {
       
   183         // Offer the command to interest items
       
   184         for ( TInt j = 0; j < iInterestItems.Count(); ++j )
       
   185             {
       
   186             MPbk2AiwInterestItem* interestItem = iInterestItems[j];
       
   187             ret = interestItem->HandleCommandL(
       
   188                 aMenuCommandId, aControl, aServiceCommandId );
       
   189             if ( ret )
       
   190                 {
       
   191                 // Do not continue the loop if command was handled
       
   192                 break;
       
   193                 }
       
   194             }
       
   195         }
       
   196 
       
   197     return ret;
       
   198     }
       
   199 
       
   200 // --------------------------------------------------------------------------
       
   201 // CPbk2AiwInterestArray::AttachL
       
   202 // --------------------------------------------------------------------------
       
   203 //
       
   204 void CPbk2AiwInterestArray::AttachL
       
   205         ( const TInt aMenuResourceId, const TInt aInterestResourceId,
       
   206           const TBool aAttachBaseServiceInterest )
       
   207     {
       
   208     // Attach criteria items to menu
       
   209     iServiceHandler->AttachMenuL( aMenuResourceId, aInterestResourceId );
       
   210 
       
   211     // If wanted, attach also base interest
       
   212     if ( aAttachBaseServiceInterest )
       
   213         {
       
   214         iServiceHandler->AttachL( aInterestResourceId );
       
   215         }
       
   216     }
       
   217 
       
   218 // --------------------------------------------------------------------------
       
   219 // CPbk2AiwInterestArray::PurgeAiwQueueL
       
   220 // --------------------------------------------------------------------------
       
   221 //
       
   222 void CPbk2AiwInterestArray::PurgeAiwQueueL()
       
   223     {
       
   224     for ( TInt i = 0; i < iAiwQueue.Count(); ++i )
       
   225         {
       
   226         TAiwQueueStruct aiwInterest = iAiwQueue[i];
       
   227 
       
   228         // Create the item
       
   229         MPbk2AiwInterestItem* item = CreateInterestItemL
       
   230             ( aiwInterest.iInterestId );
       
   231         // And attach it
       
   232         AttachL( item, aiwInterest.iMenuResourceId, 
       
   233               aiwInterest.iInterestResourceId, 
       
   234               aiwInterest.iAttachBaseServiceInterest );
       
   235         }
       
   236 
       
   237     iAiwQueue.Reset();
       
   238     }
       
   239 
       
   240 // --------------------------------------------------------------------------
       
   241 // CPbk2AiwInterestArray::CreateInterestItemL
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 MPbk2AiwInterestItem* CPbk2AiwInterestArray::CreateInterestItemL
       
   245         ( const TInt aInterestId )
       
   246     {
       
   247     MPbk2AiwInterestItem* interestItem = NULL;
       
   248 
       
   249     TInt count = iInterestItems.Count();
       
   250     TBool found = EFalse;
       
   251     for ( TInt i=0; i<count; ++i )
       
   252         {
       
   253         interestItem = iInterestItems[i];
       
   254         if ( interestItem->InterestId() == aInterestId )
       
   255             {
       
   256             found = ETrue;
       
   257             break;
       
   258             }
       
   259         }
       
   260 
       
   261     if ( !found )
       
   262         {
       
   263         // There is not yet an interest item for the interest, create new
       
   264         interestItem =
       
   265             iInterestItemFactory->CreateInterestItemL( aInterestId );
       
   266         }
       
   267 
       
   268     return interestItem;
       
   269     }
       
   270 
       
   271 // --------------------------------------------------------------------------
       
   272 // CPbk2AiwInterestArray::AttachL
       
   273 // --------------------------------------------------------------------------
       
   274 //
       
   275 void CPbk2AiwInterestArray::AttachL
       
   276         ( MPbk2AiwInterestItem* aInterest, const TInt aMenuResourceId,
       
   277           const TInt aInterestResourceId,
       
   278           const TBool aAttachBaseServiceInterest )
       
   279     {
       
   280     aInterest->AttachL( aMenuResourceId, aInterestResourceId,
       
   281         aAttachBaseServiceInterest );
       
   282 
       
   283     // Append the interest item to the array, if it is not already there
       
   284     TBool found = EFalse;
       
   285     TInt count = iInterestItems.Count();
       
   286     for ( TInt i=0; i<count; ++i )
       
   287         {
       
   288         if ( iInterestItems[i] == aInterest )
       
   289             {
       
   290             found = ETrue;
       
   291             break;
       
   292             }
       
   293 
       
   294         }
       
   295     if ( !found )
       
   296         {
       
   297         User::LeaveIfError( iInterestItems.Append( aInterest ) );
       
   298         }
       
   299     }
       
   300 
       
   301 // End of File