phonebookui/Phonebook/PbkUI/src/CPbkAiwInterestArray.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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: 
       
    15 *     Implements AIW interest array for views.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <CPbkAiwInterestArray.h>
       
    22 
       
    23 #include <CPbkAppGlobalsBase.h>
       
    24 #include "MPbkAiwInterestItemFactory.h"
       
    25 #include <MPbkAiwCommandObserver.h>
       
    26 
       
    27 #include <AiwServiceHandler.h>
       
    28 
       
    29 
       
    30 // ================= MEMBER FUNCTIONS =======================
       
    31 
       
    32 inline CPbkAiwInterestArray::CPbkAiwInterestArray
       
    33         (CPbkContactEngine& aEngine):
       
    34             iEngine(aEngine)
       
    35     {
       
    36     }
       
    37 
       
    38 CPbkAiwInterestArray::~CPbkAiwInterestArray()
       
    39     {
       
    40     iInterestItems.Close();
       
    41 
       
    42     delete iServiceHandler;
       
    43     }
       
    44 
       
    45 inline void CPbkAiwInterestArray::ConstructL()
       
    46     {
       
    47     // Create AIW handler
       
    48     iServiceHandler = CAiwServiceHandler::NewL();  
       
    49     }
       
    50 
       
    51 EXPORT_C CPbkAiwInterestArray* CPbkAiwInterestArray::NewL
       
    52         (CPbkContactEngine& aEngine)
       
    53     {
       
    54     CPbkAiwInterestArray* self =
       
    55         new (ELeave) CPbkAiwInterestArray(aEngine);
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop(self);
       
    59     return self;
       
    60     }
       
    61 
       
    62 
       
    63 void CPbkAiwInterestArray::CreateInterestItemAndAttachL(
       
    64             TInt aInterestId,
       
    65             TInt aMenuResourceId,
       
    66             TInt aInterestResourceId,
       
    67             TBool aAttachBaseServiceInterest)
       
    68     {
       
    69     MPbkAiwInterestItem* aiwInterest = CPbkAppGlobalsBase::InstanceL()->
       
    70 		AiwInterestItemFactory().CreateInterestItemL(
       
    71             aInterestId, *iServiceHandler, iEngine);
       
    72 
       
    73     if (aiwInterest)
       
    74         {
       
    75         aiwInterest->AttachL(
       
    76             aMenuResourceId, 
       
    77             aInterestResourceId, 
       
    78             aAttachBaseServiceInterest);
       
    79 
       
    80         // Append the interest item to the array, if it is not
       
    81         // already there
       
    82         TBool found(EFalse);
       
    83         TInt count = iInterestItems.Count();
       
    84         for (TInt i=0; i<count; ++i)
       
    85             {
       
    86             if (iInterestItems[i] == aiwInterest)
       
    87                 {
       
    88                 found = ETrue;
       
    89                 break;
       
    90                 }
       
    91             }
       
    92         if (!found)
       
    93             {
       
    94             User::LeaveIfError(iInterestItems.Append(aiwInterest));
       
    95             }
       
    96         }
       
    97     }
       
    98 
       
    99 
       
   100 void CPbkAiwInterestArray::AttachL(
       
   101         TInt aMenuResourceId,
       
   102         TInt aInterestResourceId,
       
   103         TBool aAttachBaseServiceInterest)
       
   104     {
       
   105     // Attach criteria items to menu
       
   106     iServiceHandler->AttachMenuL(aMenuResourceId,
       
   107         aInterestResourceId);
       
   108 
       
   109     // If wanted, attach also base interest
       
   110     if (aAttachBaseServiceInterest)
       
   111         {
       
   112         iServiceHandler->AttachL(aInterestResourceId);
       
   113         }
       
   114     }
       
   115 
       
   116 TBool CPbkAiwInterestArray::InitMenuPaneL(
       
   117         TInt aResourceId,
       
   118         CEikMenuPane& aMenuPane,
       
   119         TUint aFlags)
       
   120     {
       
   121     // Offer the menu for AIW framework first
       
   122     TBool ret = iServiceHandler->HandleSubmenuL(aMenuPane);
       
   123 
       
   124 	if (!ret)
       
   125 		{
       
   126         // The submenu was not handled by AIW framework,
       
   127         // offer it to interest items
       
   128         for (TInt j = 0; j < iInterestItems.Count(); ++j)
       
   129             {
       
   130             MPbkAiwInterestItem* interestItem = iInterestItems[j];
       
   131             ret = interestItem->InitMenuPaneL(aResourceId, aMenuPane, aFlags);
       
   132             if (ret)
       
   133                 {
       
   134                 // Do not continue the loop if menu was handled
       
   135                 break;
       
   136                 }
       
   137             }
       
   138 		}
       
   139     return ret;
       
   140     }
       
   141 
       
   142 TBool CPbkAiwInterestArray::HandleCommandL(
       
   143         TInt aMenuCommandId,
       
   144         const CContactIdArray& aContacts,
       
   145         const TPbkContactItemField* aFocusedField /* =NULL */,
       
   146         TInt aServiceCommandId /* =KNullHandle */,
       
   147         MPbkAiwCommandObserver* aObserver /*= NULL*/)
       
   148     {
       
   149     TBool ret = EFalse;
       
   150 
       
   151     // If service command parameter was not given,
       
   152     // ask it from AIW framework
       
   153     if (!aServiceCommandId)
       
   154         {
       
   155         aServiceCommandId =
       
   156             iServiceHandler->ServiceCmdByMenuCmd(aMenuCommandId);
       
   157         }
       
   158 
       
   159     // There was a provider
       
   160     if (aServiceCommandId)
       
   161         {
       
   162         // Offer the command to interest items
       
   163         for (TInt j = 0; j < iInterestItems.Count(); ++j)
       
   164             {
       
   165             MPbkAiwInterestItem* interestItem = iInterestItems[j];
       
   166             ret = interestItem->HandleCommandL(
       
   167                 aMenuCommandId,
       
   168                 aContacts,
       
   169                 aFocusedField,
       
   170                 aServiceCommandId,
       
   171                 aObserver);
       
   172             if (ret)
       
   173                 {
       
   174                 // Do not continue the loop if command was handled
       
   175                 break;
       
   176                 }
       
   177             }
       
   178 		}
       
   179     return ret;
       
   180     }
       
   181 
       
   182 //  End of File