phonebookui/Phonebook/App/src/CPbkAiwInterestItemCall.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
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 Call AIW interest item functionality.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkAiwInterestItemCall.h"
       
    22 
       
    23 #include <CPbkContactEngine.h>
       
    24 #include <CPbkSendKeyAddressSelect.h>
       
    25 #include <Phonebook.hrh>
       
    26 #include <CPbkAppGlobalsBase.h>
       
    27 #include <MPbkCommand.h>
       
    28 #include <MPbkCommandFactory.h>
       
    29 #include <MenuFilteringFlags.h>
       
    30 #include <MPbkAiwCommandObserver.h>
       
    31 #include "CPbkCallTypeSelector.h"
       
    32 #include <Phonebook.rsg>
       
    33 
       
    34 #include <cntdef.h>
       
    35 #include <AiwServiceHandler.h>
       
    36 #include <AiwCommon.hrh>
       
    37 #include <eikmenup.h>
       
    38 #include <FeatMgr.h>
       
    39 
       
    40 
       
    41 /// Unnamed namespace for local definitions
       
    42 namespace {
       
    43 
       
    44     /**
       
    45      * Sets parameter object's focused field and
       
    46      * default usage values.
       
    47      * @param aParams the parameter object to modify
       
    48      * @param aFocusedField the field to use as focused field
       
    49      */
       
    50     void SetParams(
       
    51         CPbkAddressSelect::TBaseParams& aParams,
       
    52         const TPbkContactItemField* aFocusedField)
       
    53         {
       
    54         if (aFocusedField)
       
    55             {
       
    56             aParams.SetFocusedField(aFocusedField);
       
    57             }
       
    58         else
       
    59             {
       
    60             aParams.SetUseDefaultDirectly(ETrue);
       
    61             }
       
    62         }
       
    63         
       
    64 } // namespace
       
    65 
       
    66 
       
    67 // ================= MEMBER FUNCTIONS =======================
       
    68 
       
    69 inline CPbkAiwInterestItemCall::CPbkAiwInterestItemCall
       
    70         (CAiwServiceHandler& aServiceHandler,
       
    71         CPbkContactEngine& aEngine) : 
       
    72             CPbkAiwInterestItemBase(aServiceHandler),
       
    73             iEngine(aEngine)
       
    74     {
       
    75     }
       
    76 
       
    77 
       
    78 CPbkAiwInterestItemCall* CPbkAiwInterestItemCall::NewL(
       
    79         CAiwServiceHandler& aServiceHandler,
       
    80         CPbkContactEngine& aEngine)
       
    81     {
       
    82     CPbkAiwInterestItemCall* self =
       
    83         new (ELeave) CPbkAiwInterestItemCall(aServiceHandler, aEngine);
       
    84     CleanupStack::PushL(self);
       
    85     self->ConstructL();
       
    86     CleanupStack::Pop(self);
       
    87     return self;
       
    88     }
       
    89     
       
    90 void CPbkAiwInterestItemCall::ConstructL()
       
    91     {
       
    92     iSelector = CPbkCallTypeSelector::NewL(iEngine);
       
    93     }
       
    94 
       
    95 CPbkAiwInterestItemCall::~CPbkAiwInterestItemCall()
       
    96     {
       
    97     delete iSelector;
       
    98     }
       
    99 
       
   100 TBool CPbkAiwInterestItemCall::InitMenuPaneL(
       
   101         TInt aResourceId,
       
   102         CEikMenuPane& aMenuPane,
       
   103         TUint aFlags)
       
   104     {
       
   105     TBool ret = EFalse;
       
   106 
       
   107     // Normal menu
       
   108     if (aResourceId == R_PHONEBOOK_CALL_MENU)
       
   109         {
       
   110         ret = ETrue;
       
   111            
       
   112 	    // If the list is empty or it has marked items, hide call option
       
   113         if (!(aFlags & KPbkControlEmpty)
       
   114             && !(aFlags & KPbkItemsMarked))
       
   115             {
       
   116             // Let provider add its menu items to the menu
       
   117             iServiceHandler.InitializeMenuPaneL(
       
   118                 aMenuPane,
       
   119                 aResourceId,
       
   120                 EPbkCmdLast,
       
   121                 iServiceHandler.InParamListL());
       
   122             }
       
   123         else
       
   124             {
       
   125             aMenuPane.SetItemDimmed(KAiwCmdCall, ETrue);
       
   126             }
       
   127         }
       
   128 
       
   129     // Context menu
       
   130     else if (aResourceId == R_PHONEBOOK_CALL_CONTEXT_MENU)
       
   131         {
       
   132         ret = ETrue;
       
   133         // Hide the item by default
       
   134         aMenuPane.SetItemDimmed(KAiwCmdCall, ETrue);
       
   135 
       
   136         // Get empty parameter list
       
   137         CAiwGenericParamList& paramList =
       
   138             iServiceHandler.InParamListL();
       
   139 
       
   140         if (!(aFlags & KPbkControlEmpty))
       
   141             {
       
   142             if (aFlags & KPbkCurrentFieldPhoneNumber)
       
   143                 {
       
   144                 aMenuPane.SetItemDimmed(KAiwCmdCall, EFalse);
       
   145                 }
       
   146             else if (aFlags & KPbkCurrentFieldVoipAddress)
       
   147                 {
       
   148                 // If we are on a Internet telephony field,
       
   149                 // the Call UI must show only the VoIP option
       
   150                 TAiwVariant variant;
       
   151                 TAiwGenericParam param(EGenericParamSIPAddress, variant);
       
   152                 paramList.AppendL(param);
       
   153                 }
       
   154                                 
       
   155             // Let provider add its menu items to the menu
       
   156             iServiceHandler.InitializeMenuPaneL(
       
   157                 aMenuPane,
       
   158                 aResourceId,
       
   159                 EPbkCmdLast,
       
   160                 paramList);
       
   161             }
       
   162         }
       
   163 
       
   164     return ret;
       
   165     }
       
   166 
       
   167 
       
   168 TBool CPbkAiwInterestItemCall::HandleCommandL(
       
   169         TInt aMenuCommandId,
       
   170         const CContactIdArray& aContacts,
       
   171         const TPbkContactItemField* aFocusedField /* =NULL */,
       
   172         TInt aServiceCommandId /* =KNullHandle */,
       
   173         MPbkAiwCommandObserver* aObserver /*= NULL*/)
       
   174     {
       
   175     TBool ret = EFalse;
       
   176     
       
   177     // Only handle this command if service command is call,
       
   178     // note that this section is accessed also when the send key
       
   179     // is pressed and the initiated command object can then be POC
       
   180     // call also
       
   181     if (aServiceCommandId == KAiwCmdCall)
       
   182         {
       
   183         MPbkCommand* cmd = NULL;
       
   184         
       
   185         // Read the first contact of the array
       
   186         const CPbkContactItem* item =
       
   187             iEngine.ReadMinimalContactLC(aContacts[0]);
       
   188         
       
   189         // Because send key is used also to launch POC calls
       
   190         // we have to verify what was the selection and is
       
   191         // it ok to launch a telephony call
       
   192         if (iSelector->OkToLaunchTelephonyCall(aFocusedField))
       
   193             {
       
   194             cmd = CreateCallCmdObjectL
       
   195                 (aMenuCommandId, *item, aContacts, aFocusedField);
       
   196             }
       
   197         else
       
   198             {
       
   199             cmd = CreatePocCmdObjectL
       
   200                 (aMenuCommandId, aContacts, aFocusedField);
       
   201             }
       
   202             
       
   203         if (cmd)
       
   204             {
       
   205 		    // Execute the command
       
   206 		    cmd->ExecuteLD();
       
   207 
       
   208             // Inform observer
       
   209             if (aObserver)
       
   210                 {
       
   211                 aObserver->AiwCommandHandledL(aMenuCommandId,
       
   212                    aServiceCommandId, KErrNone);
       
   213                 }
       
   214             }
       
   215         CleanupStack::PopAndDestroy(); // item
       
   216         ret = ETrue;
       
   217         }
       
   218 
       
   219     return ret;
       
   220     }
       
   221 
       
   222 void CPbkAiwInterestItemCall::AttachL(
       
   223         TInt aMenuResourceId,
       
   224         TInt aInterestResourceId,
       
   225         TBool aAttachBaseServiceInterest)
       
   226     {
       
   227     // Always delegate to base class!
       
   228     CPbkAiwInterestItemBase::AttachL(aMenuResourceId,
       
   229         aInterestResourceId,
       
   230         aAttachBaseServiceInterest);
       
   231     }
       
   232 
       
   233 MPbkCommand* CPbkAiwInterestItemCall::CreateCallCmdObjectL
       
   234         (TInt aMenuCommandId, const CPbkContactItem& aContact,
       
   235         const CContactIdArray& aContacts,
       
   236         const TPbkContactItemField* aFocusedField)
       
   237     {
       
   238     // We need a bunch of pre-initialized variables    
       
   239     MPbkCommand* cmd = NULL;
       
   240     TBool selectAccepted = ETrue;
       
   241     TBool okToLaunchTelephonyCall = ETrue;
       
   242 	const TPbkContactItemField* selectedField = NULL;
       
   243     
       
   244     if (aMenuCommandId == EPbkCmdCall)
       
   245         {
       
   246         // Call launched with send key, before creating the address select
       
   247         // object, we have to spend some time to select which default to use
       
   248         const TPbkContactItemField* defaultField =
       
   249             iSelector->SelectDefaultToUse(aContact);
       
   250         CPbkSendKeyAddressSelect* phoneNumberSelect =
       
   251             new (ELeave) CPbkSendKeyAddressSelect(iEngine);
       
   252         CPbkSendKeyAddressSelect::TParams params(aContact, defaultField);
       
   253         SetParams(params, aFocusedField);
       
   254         selectAccepted = phoneNumberSelect->ExecuteLD(params);
       
   255 
       
   256         if (selectAccepted)
       
   257             {
       
   258             selectedField = params.SelectedField();
       
   259 
       
   260             // Because send key is used also to launch POC calls
       
   261             // we have to verify what was the selection and is
       
   262             // it ok to launch a telephony call
       
   263             okToLaunchTelephonyCall = iSelector->OkToLaunchTelephonyCall
       
   264                 (selectedField);
       
   265             }
       
   266         }
       
   267         
       
   268     if (selectAccepted && okToLaunchTelephonyCall)
       
   269         {
       
   270         // Select was either accepted, or we are calling from
       
   271         // CallUI menus. In the latter case, the address select
       
   272         // will be shown later. Next, create the call command object.
       
   273 	    cmd = CPbkAppGlobalsBase::InstanceL()->
       
   274 		    CommandFactory().CreateCallCmdL(
       
   275 		    aContact,
       
   276 		    selectedField,
       
   277 		    aFocusedField,
       
   278             aMenuCommandId,
       
   279 		    iServiceHandler,
       
   280 		    *iSelector);
       
   281         }
       
   282     else if (selectAccepted && !okToLaunchTelephonyCall)
       
   283         {
       
   284         // Select was accepted, but the selection indicates
       
   285         // we have to create a POC call
       
   286         cmd = CreatePocCmdObjectL
       
   287             (aMenuCommandId, aContacts, aFocusedField);
       
   288         }
       
   289     
       
   290     return cmd;
       
   291     }
       
   292 
       
   293     
       
   294 MPbkCommand* CPbkAiwInterestItemCall::CreatePocCmdObjectL
       
   295         (TInt aMenuCommandId, const CContactIdArray& aContacts,
       
   296         const TPbkContactItemField* aFocusedField)
       
   297     {
       
   298     MPbkCommand* cmd = NULL;
       
   299     
       
   300     // We have to deduct the control flags for the POC cmd
       
   301     TUint controlFlags = 0;
       
   302     if (aFocusedField)
       
   303         {
       
   304         controlFlags |= KPbkInfoView;
       
   305         }
       
   306     
       
   307     // Create the POC call command object
       
   308     cmd = CPbkAppGlobalsBase::InstanceL()->
       
   309 	    CommandFactory().CreatePocCmdL(aMenuCommandId,
       
   310         aContacts,
       
   311         controlFlags,
       
   312 	    iServiceHandler,
       
   313 	    *iSelector);
       
   314 	    
       
   315     return cmd;
       
   316     }
       
   317     
       
   318 //  End of File