phoneapp/phoneuiview/src/cphonedialercontroller.cpp
branchRCL_3
changeset 25 5266b1f337bd
equal deleted inserted replaced
24:41a7f70b3818 25:5266b1f337bd
       
     1 /*
       
     2 * Copyright (c) 2009, 2010 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:  Handles the updating of dialer buttons
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikappui.h>
       
    20 #include <eikenv.h>
       
    21 #include <eikapp.h>
       
    22 #include <eikcolib.h>
       
    23 #include <gulicon.h>
       
    24 #include <StringLoader.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <phoneui.rsg>
       
    27 #include <phoneui.mbg>
       
    28 #include <pevirtualengine.h>
       
    29 #include <featmgr.h>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 
       
    32 #include "cphonedialercontroller.h"
       
    33 #include "cphoneeasydialingcontroller.h"
       
    34 #include "cphonebubblewrapper.h"
       
    35 #include "phoneui.hrh"
       
    36 #include "tphonecmdparaminteger.h"
       
    37 #include "cphonemainresourceresolver.h"
       
    38 #include "tphonecmdparamcallstatedata.h"
       
    39 #include "tphonecmdparamboolean.h"
       
    40 
       
    41 _LIT ( KPhoneMifFileName, "phoneui.mif" );
       
    42 
       
    43 
       
    44 /** States for Call button. */
       
    45 enum TCallButtonState
       
    46     {
       
    47     ECallButtonCallState = 0,
       
    48     ECallButtonLogState,
       
    49     ECallButtonSendState
       
    50     };
       
    51 static const CPhoneDialerController::TLocalButtonData KCallButtonDataTable[] =
       
    52     {
       
    53         { 
       
    54         EPhoneNumberAcqCmdSendCommand, 
       
    55         EAknsMinorGenericQgnIndiButtonAnswerWhite,
       
    56         EMbmPhoneuiQgn_indi_button_answer_white, 
       
    57         EMbmPhoneuiQgn_indi_button_answer_white_mask,
       
    58         R_PHONEUI_DIALER_TOOLTIP_CALL
       
    59         },
       
    60         { 
       
    61         EPhoneDialerCmdLog,
       
    62         EAknsMinorGenericQgnIndiButtonLogdialerWhite,
       
    63         EMbmPhoneuiQgn_indi_button_logdialer_white,
       
    64         EMbmPhoneuiQgn_indi_button_logdialer_white_mask,
       
    65         R_PHONEUI_DIALER_TOOLTIP_RECENT_CALLS
       
    66         },
       
    67         { 
       
    68         EPhoneNumberAcqCmdSendCommand, 
       
    69         EAknsMinorGenericQgnIndiButtonAnswerWhite,
       
    70         EMbmPhoneuiQgn_indi_button_answer_white, 
       
    71         EMbmPhoneuiQgn_indi_button_answer_white_mask,
       
    72         R_PHONEUI_DIALER_TOOLTIP_SEND
       
    73         }
       
    74     };
       
    75 static const TInt KCallButtonDataTableCount = 
       
    76     sizeof( KCallButtonDataTable ) / sizeof( CPhoneDialerController::TLocalButtonData );
       
    77 
       
    78 /** States for Phonebook button */
       
    79 enum TPhonebookButtonState
       
    80     {
       
    81     EPhonebookButtonContactsState = 0,
       
    82     EPhonebookButtonAddContactState,
       
    83     // Video call button send state
       
    84     EPhonebookButtonVideocallSendState,
       
    85     // Video call button call state
       
    86     EPhonebookButtonVideocallState
       
    87     };
       
    88 static const CPhoneDialerController::TLocalButtonData KPhonebookButtonDataTable[] =
       
    89     {
       
    90         { 
       
    91         EPhoneDialerCmdContacts,
       
    92         EAknsMinorGenericQgnIndiDialerContacts,
       
    93         EMbmPhoneuiQgn_indi_dialer_contacts,
       
    94         EMbmPhoneuiQgn_indi_dialer_contacts_mask,
       
    95         R_PHONEUI_DIALER_TOOLTIP_CONTACTS
       
    96         },
       
    97         { 
       
    98         EPhoneNumberAcqCmdAddToContacts,
       
    99         EAknsMinorGenericQgnIndiDialerAddContacts,      
       
   100         EMbmPhoneuiQgn_indi_dialer_add_contacts,
       
   101         EMbmPhoneuiQgn_indi_dialer_add_contacts_mask,
       
   102         R_PHONEUI_DIALER_TOOLTIP_ADD_TO_CONTACTS
       
   103         },
       
   104         // Video call button 
       
   105         {
       
   106         EPhoneNumberAcqCmdVideoCall,
       
   107         EAknsMinorGenericQgnIndiDialerVideocallSend,
       
   108         EMbmPhoneuiQgn_indi_dialer_videocall_send,
       
   109         EMbmPhoneuiQgn_indi_dialer_videocall_send_mask,
       
   110         R_PHONEUI_DIALER_TOOLTIP_SEND
       
   111         },
       
   112         {
       
   113         EPhoneNumberAcqCmdVideoCall,
       
   114         EAknsMinorGenericQgnIndiDialerVideocallSend,
       
   115         EMbmPhoneuiQgn_indi_dialer_videocall_send,
       
   116         EMbmPhoneuiQgn_indi_dialer_videocall_send_mask,
       
   117         R_PHONEUI_DIALER_TOOLTIP_VIDEO_CALL
       
   118         }
       
   119     };
       
   120 static const TInt KPhonebookButtonDataTableCount = 
       
   121     sizeof( KPhonebookButtonDataTable ) / sizeof( CPhoneDialerController::TLocalButtonData );
       
   122 
       
   123 /** States for Clear button */
       
   124 enum TClearButtonState
       
   125     {
       
   126     EClearButtonClearState = 0
       
   127     };
       
   128 static const CPhoneDialerController::TLocalButtonData KClearButtonDataTable[] =
       
   129     {
       
   130         { 
       
   131         EPhoneDialerCmdClear,
       
   132         EAknsMinorGenericQgnIndiDialerClear,
       
   133         EMbmPhoneuiQgn_indi_dialer_clear,
       
   134         EMbmPhoneuiQgn_indi_dialer_clear_mask,
       
   135         0   //no tooltip for clear key
       
   136         }
       
   137     };
       
   138 static const TInt KClearButtonDataTableCount = 
       
   139     sizeof( KClearButtonDataTable ) / sizeof( CPhoneDialerController::TLocalButtonData );
       
   140 
       
   141 
       
   142 // ======== MEMBER FUNCTIONS ========
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Constructor
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C CPhoneDialerController::CPhoneDialerController( 
       
   149                                         CPhoneBubbleWrapper* aBubbleWrapper,
       
   150                                         CCoeEnv& aCoeEnv ):
       
   151     iCoeEnv( aCoeEnv ),
       
   152     iBubbleWrapper( aBubbleWrapper ),
       
   153     iRestrictedDialer( ETrue )
       
   154     {
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Second phase constructor
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CPhoneDialerController::ConstructL()
       
   162     {
       
   163     }
       
   164     
       
   165 // ---------------------------------------------------------------------------
       
   166 // Static constructor
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 CPhoneDialerController* CPhoneDialerController::NewL( 
       
   170                                     CPhoneBubbleWrapper* aBubbleWrapper,
       
   171                                     CCoeEnv& aCoeEnv )
       
   172     {
       
   173     CPhoneDialerController* self = 
       
   174         new (ELeave) CPhoneDialerController( aBubbleWrapper, aCoeEnv );
       
   175     CleanupStack::PushL( self );
       
   176     self->ConstructL();
       
   177     CleanupStack::Pop( self );
       
   178     return self;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Destructor
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C CPhoneDialerController::~CPhoneDialerController()
       
   186     {
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // SetRestrictedDialerL
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CPhoneDialerController::SetRestrictedDialer( TBool aRestricted )
       
   194     {
       
   195     iRestrictedDialer = aRestricted;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // SetServiceCodeFlagL
       
   200 //
       
   201 // The flag rules wether green key is called "Send" or "Call"
       
   202 // 
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 void CPhoneDialerController::SetServiceCodeFlag( 
       
   206     TPhoneCommandParam* aCommandParam )
       
   207     {
       
   208     // Check is the given parameter valid
       
   209     if ( aCommandParam->ParamId() == TPhoneCommandParam::EPhoneParamIdBoolean )
       
   210         {
       
   211         TPhoneCmdParamBoolean* serviceCodeFlag = 
       
   212             static_cast<TPhoneCmdParamBoolean*>( aCommandParam );
       
   213         iServiceCodeFlag = serviceCodeFlag->Boolean();
       
   214         }
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // SetEasyDialingController
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CPhoneDialerController::SetEasyDialingController( 
       
   222         CPhoneEasyDialingController* aController )
       
   223     {
       
   224     iEasyDialingController = aController;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // CbaResourceId
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 EXPORT_C TInt CPhoneDialerController::CbaResourceId() const
       
   232     {
       
   233     return KErrNotFound;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // MenuResourceId
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 EXPORT_C TInt CPhoneDialerController::MenuResourceId() const
       
   241     {
       
   242     return KErrNotFound;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // NumberEntryPromptTextL
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C const TDesC& CPhoneDialerController::NumberEntryPromptTextL()
       
   250     {
       
   251     return KNullDesC;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // GetButtonData
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 EXPORT_C TInt CPhoneDialerController::GetButtonData( TButtonIndex aIndex, 
       
   259         RPointerArray<CButtonData>& aData ) const
       
   260     {
       
   261     TInt err = KErrNone;
       
   262     
       
   263     const TLocalButtonData* dataTable = NULL;
       
   264     TInt count = 0;
       
   265     
       
   266     // Select correct data table
       
   267     switch ( aIndex )
       
   268         {
       
   269         case ECallButton:
       
   270             dataTable = KCallButtonDataTable;
       
   271             count = KCallButtonDataTableCount;
       
   272             break;
       
   273         case EPhonebookButton:
       
   274             dataTable = KPhonebookButtonDataTable;
       
   275             count = KPhonebookButtonDataTableCount;
       
   276             break;
       
   277         case EClearButton:
       
   278             dataTable = KClearButtonDataTable;
       
   279             count = KClearButtonDataTableCount;
       
   280             break;
       
   281         default:
       
   282             break;
       
   283         }
       
   284     
       
   285     // Create data from the table
       
   286     if ( dataTable )
       
   287         {
       
   288         // Construct MIF file path
       
   289         TFileName mifPath( KDriveZ );
       
   290         mifPath.Append( KDC_APP_BITMAP_DIR );
       
   291         mifPath.Append( KPhoneMifFileName );
       
   292         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   293     
       
   294         for ( TInt i = 0 ; i < count ; ++i )
       
   295             {
       
   296             CButtonData* btnData = NULL;
       
   297             TRAP( err, btnData = CreateButtonDataL( dataTable[i], skin, mifPath ) );
       
   298             if ( !err )
       
   299                 {
       
   300                 err = aData.Append( btnData );
       
   301                 }
       
   302             if ( err )
       
   303                 {
       
   304                 // free all memory and stop here if something went wrong
       
   305                 delete btnData;
       
   306                 aData.ResetAndDestroy();
       
   307                 i = count;
       
   308                 }
       
   309             }
       
   310         }
       
   311     return err;
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // SetNumberEntryEmptyIsEmpty
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 EXPORT_C void CPhoneDialerController::SetNumberEntryIsEmpty( TBool aEmpty )
       
   319     {
       
   320     iNumberAvailable = !aEmpty;
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // ButtonState
       
   325 // ---------------------------------------------------------------------------
       
   326 //
       
   327 EXPORT_C TInt CPhoneDialerController::ButtonState( TButtonIndex aIndex ) const
       
   328     {
       
   329     TInt state( KErrNotFound );
       
   330     // Figure out correct state for each key
       
   331     switch ( aIndex )
       
   332         {
       
   333         case ECallButton:
       
   334             {
       
   335             if ( !iNumberAvailable )
       
   336                 {
       
   337                 // Show "Recent calls" when no number available
       
   338                 state = ECallButtonLogState;
       
   339                 }
       
   340             else if ( iServiceCodeFlag && !EasyDialingFocused() )
       
   341                 {
       
   342                 // Show "Send" if service code entered and contact list
       
   343                 // is not focused.
       
   344                 state = ECallButtonSendState;
       
   345                 }
       
   346             else
       
   347                 {
       
   348                 // Show "Call" in all other cases
       
   349                 state = ECallButtonCallState;
       
   350                 }
       
   351             }
       
   352             break;
       
   353         case EPhonebookButton:
       
   354             {
       
   355             if ( !iNumberAvailable )
       
   356                 {
       
   357                 state = EPhonebookButtonContactsState;
       
   358                 }
       
   359             else if ( FeatureManager::FeatureSupported( KFeatureIdFfTdScdmaVideocallKey ) )
       
   360                 {
       
   361                 if ( iServiceCodeFlag && !EasyDialingFocused() )
       
   362                     {
       
   363                     state = EPhonebookButtonVideocallSendState;
       
   364                     }
       
   365                 else
       
   366                     {
       
   367                     state = EPhonebookButtonVideocallState;
       
   368                     }
       
   369                 }
       
   370             else
       
   371                 {
       
   372                 state = EPhonebookButtonAddContactState;
       
   373                 }
       
   374             }
       
   375             break;
       
   376         case EClearButton:
       
   377             {
       
   378             state = EClearButtonClearState;
       
   379             }
       
   380             break;
       
   381         default:
       
   382             break;
       
   383         }
       
   384     return state;
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // ButtonDimmed
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 EXPORT_C TBool CPhoneDialerController::ButtonDimmed( TButtonIndex aIndex ) const
       
   392     {
       
   393     TBool dimmed = EFalse;
       
   394     // Figure out correct state for each key
       
   395     switch ( aIndex )
       
   396         {
       
   397         case ECallButton:
       
   398 			{
       
   399         	if ( iNumberAvailable )
       
   400         		{
       
   401         		// Dim send key if emergency call is active. 
       
   402         		// Do not dim send key if emergency call is not active,
       
   403         		// user must be able to make an emergency call whether 
       
   404         		// security mode is enabled or disabled.
       
   405         		dimmed = EmergencyCallActive();
       
   406         		}
       
   407         	else
       
   408         		{
       
   409         		// If there's no number available in dialer, we should dim
       
   410         		// send key if security mode is enabled.
       
   411         		// User cannot launch logs application.
       
   412         		dimmed = iRestrictedDialer;
       
   413         		}
       
   414 			}
       
   415         	break;
       
   416             
       
   417         case EPhonebookButton:
       
   418             {
       
   419             dimmed = iRestrictedDialer;
       
   420             // Check if video call button supported
       
   421             TBool videoCallKeySupported = FeatureManager::FeatureSupported( KFeatureIdFfTdScdmaVideocallKey );
       
   422             // Prevent video call but don't prevent opening Contacts during emergency call.
       
   423             if ( !dimmed && videoCallKeySupported && iNumberAvailable )
       
   424                 {
       
   425                 dimmed = EmergencyCallActive();
       
   426                 }
       
   427             }
       
   428             break;
       
   429         case EClearButton:
       
   430             {
       
   431             dimmed = !iNumberAvailable;
       
   432             }
       
   433             break;
       
   434         default:
       
   435             break;
       
   436         }
       
   437     return dimmed;
       
   438     }
       
   439 
       
   440 // ---------------------------------------------------------------------------
       
   441 // EasyDialingAllowed
       
   442 // ---------------------------------------------------------------------------
       
   443 //
       
   444 EXPORT_C TBool CPhoneDialerController::EasyDialingAllowed() const
       
   445     {
       
   446     return !iRestrictedDialer && !EmergencyCallActive();
       
   447     }
       
   448 
       
   449 // ---------------------------------------------------------------------------
       
   450 // EmergencyCallActive
       
   451 // ---------------------------------------------------------------------------
       
   452 //
       
   453 EXPORT_C TBool CPhoneDialerController::EmergencyCallActive() const
       
   454     {
       
   455     TBool ret = EFalse;
       
   456     if ( iBubbleWrapper )
       
   457         {
       
   458         TPhoneCmdParamCallStateData callStateData;
       
   459         callStateData.SetCallState( EPEStateConnected );
       
   460         iBubbleWrapper->GetCallIdByState( &callStateData );
       
   461         TInt connected = callStateData.CallId();
       
   462         ret = ( connected == KEmergencyCallId );
       
   463         }
       
   464     return ret;
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // EasyDialingFocused
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 TBool CPhoneDialerController::EasyDialingFocused() const
       
   472     {
       
   473     TBool edFocused = EFalse;
       
   474     if ( iEasyDialingController )
       
   475         {
       
   476         TInt commandResponse( EPhoneViewResponseFailed );
       
   477         TRAP_IGNORE( commandResponse = iEasyDialingController->HandleCommandL(
       
   478                 EPhoneViewGetEasyDialingInFocusStatus) );
       
   479         edFocused = ( commandResponse == EPhoneViewResponseSuccess );
       
   480         }
       
   481     return edFocused;
       
   482     }
       
   483 
       
   484 // ---------------------------------------------------------------------------
       
   485 // CreateButtonDataL
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 MPhoneDialerController::CButtonData* CPhoneDialerController::CreateButtonDataL( 
       
   489         const TLocalButtonData& aSourceData, 
       
   490         MAknsSkinInstance* aSkin, 
       
   491         const TDesC& aMifFile ) const
       
   492     {
       
   493     // Create tooltip text
       
   494     HBufC* tooltip = NULL;
       
   495     if ( aSourceData.iTooltipResourceId > 0 )
       
   496         {
       
   497         tooltip = StringLoader::LoadLC( aSourceData.iTooltipResourceId );
       
   498         }
       
   499     else
       
   500         {
       
   501         tooltip = HBufC::NewLC(0);
       
   502         }
       
   503     
       
   504     // Create icon
       
   505     TAknsItemID skinId = { EAknsMajorGeneric, aSourceData.iSkinItemIdMinor };
       
   506     CGulIcon* icon = AknsUtils::CreateGulIconL( aSkin, skinId, aMifFile, 
       
   507             aSourceData.iBitmapIndex, aSourceData.iBitmapMaskIndex );
       
   508     CleanupStack::PushL( icon );
       
   509     
       
   510     // Create button data object
       
   511     CButtonData* buttonData =
       
   512         new ( ELeave ) CButtonData( aSourceData.iCommandId, icon, tooltip );
       
   513     CleanupStack::Pop( icon );
       
   514     CleanupStack::Pop( tooltip );
       
   515     
       
   516     return buttonData;
       
   517     }
       
   518 
       
   519 // END