phoneclientserver/callui/src/cauiplugin/cauiplugin.cpp
changeset 51 12bc758d6a02
parent 48 78df25012fda
child 53 25b8d29b7c59
equal deleted inserted replaced
48:78df25012fda 51:12bc758d6a02
     1 /*
       
     2 * Copyright (c) 2004-2005 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:  Implementation of CallUI plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "cauiplugin.h" // This class interface. 
       
    22 #include    "cauieng.h" // CaUiEngine. 
       
    23 #include    <aiwcommon.hrh> // AIW constants. 
       
    24 #include    "caui.hrh" // CallUI constants. 
       
    25 #include    <aiwmenu.h> // AIW Menu pane. 
       
    26 
       
    27 #include    <aiwservicehandler.h> 
       
    28 #include    <phclttypes.h> // PhoneClient types. 
       
    29 #include    "cauilogger.h" // Call Ui Logger 
       
    30 #include    <stringloader.h>
       
    31 #include    <callui.rsg>
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // Empty filename for initialization.
       
    36 _LIT( KCaUiNullResFile, "" );
       
    37 
       
    38 // The library to be loaded.
       
    39 _LIT( KCaUiLoadedLib, "cauiengine.dll" );
       
    40 
       
    41 
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCaUiPlugin::CCaUiPlugin
       
    47 // 
       
    48 // C++ constructor can NOT contain any code, that might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CCaUiPlugin::CCaUiPlugin()
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCaUiPlugin::ConstructL
       
    57 // 
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CCaUiPlugin::ConstructL()
       
    62     {
       
    63     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::ConstructL() Begin");
       
    64     User::LeaveIfError( iLibrary.Load( KCaUiLoadedLib ) );
       
    65 
       
    66     // Call function CreateCaUiEngFactoryL()
       
    67     TInt res = iLibrary.Lookup( 1 )();
       
    68     CCaUiEngFactory* caUiEngFactory = 
       
    69         reinterpret_cast< CCaUiEngFactory* >( res );
       
    70 
       
    71     iCaUiEngine = caUiEngFactory->CCaUiEngApiLD();
       
    72 
       
    73     if( !iCaUiEngine )
       
    74         {
       
    75         // Null returned, so leave.
       
    76         User::Leave( KErrNotSupported );
       
    77         }
       
    78     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::ConstructL() End");
       
    79     }
       
    80 
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CCaUiPlugin::NewL
       
    84 // 
       
    85 // Two-phased constructor.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 CCaUiPlugin* CCaUiPlugin::NewL()
       
    89     {
       
    90     CCaUiPlugin* self = new( ELeave ) CCaUiPlugin;
       
    91     
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop();
       
    95 
       
    96     return self;
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCaUiPlugin::~CCaUiPlugin
       
   102 // 
       
   103 // Destructor.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CCaUiPlugin::~CCaUiPlugin()
       
   107     {
       
   108     delete iCaUiEngine;
       
   109 
       
   110     iLibrary.Close();
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CCaUiPlugin::InitialiseL
       
   116 // 
       
   117 // 
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CCaUiPlugin::InitialiseL(
       
   121     MAiwNotifyCallback& /*aFrameworkCallback*/,
       
   122     const RCriteriaArray& /*aInterest*/)
       
   123     {
       
   124     // Stub. Not used.
       
   125     }
       
   126 
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CCaUiPlugin::HandleServiceCmdL
       
   130 // 
       
   131 // 
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CCaUiPlugin::HandleServiceCmdL(
       
   135     const TInt& aCmdId,
       
   136     const CAiwGenericParamList& aInParamList,
       
   137     CAiwGenericParamList& aOutParamList,
       
   138     TUint aCmdOptions,
       
   139     const MAiwNotifyCallback* aCallback )
       
   140     {
       
   141     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleServiceCmdL() Begin");
       
   142     // Handle only call command.
       
   143     if ( aCmdId == KAiwCmdCall )
       
   144         {
       
   145         if ( aCmdOptions & KAiwOptCancel )
       
   146             {
       
   147             CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleServiceCmdL() Cancel");
       
   148             return;
       
   149             }
       
   150         // Check if there is CallUI Dialdata parameter.
       
   151         TInt index = 0;
       
   152         const TAiwGenericParam* genericParam = NULL; 
       
   153             
       
   154         genericParam = aInParamList.FindFirst( 
       
   155             index,
       
   156             EGenericParamCallDialData,
       
   157             EVariantTypeDesC8 );
       
   158             
       
   159         if ( index >= 0 && genericParam )
       
   160             {
       
   161             // Get the data.
       
   162             TPtrC8 ptr = genericParam->Value().AsData();
       
   163 
       
   164             // If this function was called through HandleMenuCmdL,
       
   165             // iMenuCmdId was set, otherwise it is zero.
       
   166             TCaUiCallType callType = ECaUiCallTypeUnknown;
       
   167 
       
   168             if ( iMenuCmdId == ECallUIVoice )
       
   169                 {
       
   170                 callType = ECaUiCallTypeVoice;
       
   171                 }
       
   172             else if ( iMenuCmdId == ECallUIVideo )
       
   173                 {
       
   174                 callType = ECaUiCallTypeVideo;
       
   175                 }
       
   176             else if ( iMenuCmdId == ECallUIInternet )
       
   177                 {
       
   178                 callType = ECaUiCallTypeInternet;
       
   179                 }
       
   180 
       
   181             iMenuCmdId = 0;
       
   182 
       
   183             // Save the parameters given.
       
   184             iAiwNotifyCallback = aCallback;
       
   185             iInParamList = &aInParamList;
       
   186             iOutParamList = &aOutParamList;
       
   187 
       
   188             // Perform the dial operation.
       
   189             iCaUiEngine->DialL( *this, ptr, callType );
       
   190             }
       
   191         }
       
   192     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleServiceCmdL() End");
       
   193     }
       
   194 
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CCaUiPlugin::InitializeMenuPaneL
       
   199 // 
       
   200 // 
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CCaUiPlugin::InitializeMenuPaneL(
       
   204     CAiwMenuPane& aMenuPane,
       
   205     TInt aIndex,
       
   206     TInt /* aCascadeId */,
       
   207     const CAiwGenericParamList& aInParamList )
       
   208     {
       
   209     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::InitializeMenuPaneL() Begin");
       
   210 
       
   211     // By default we want all internet, voice and video call resources
       
   212     TBool csVoiceMenuItemAvailable( ETrue );
       
   213     TBool csVideoMenuItemAvailable( ETrue );
       
   214     TBool voipMenuItemAvailable( ETrue );
       
   215     
       
   216     // If there is PhoneNumber parameter given, then only voice call 
       
   217     // resource is wanted.
       
   218     TInt count = aInParamList.Count();
       
   219     if ( count )
       
   220         {
       
   221         TInt index = 0;
       
   222         aInParamList.FindFirst(
       
   223             index,
       
   224             EGenericParamPhoneNumber,
       
   225             EVariantTypeAny );
       
   226 
       
   227         if ( index >= 0  )
       
   228             {
       
   229             csVideoMenuItemAvailable = EFalse;
       
   230             voipMenuItemAvailable = EFalse;
       
   231             }
       
   232             
       
   233         if ( index == KErrNotFound )
       
   234             {
       
   235             index = 0;    
       
   236             aInParamList.FindFirst(
       
   237                 index,
       
   238                 EGenericParamSIPAddress,
       
   239                 EVariantTypeAny );
       
   240 
       
   241             if ( index >= 0  )
       
   242                 {
       
   243                 // Internet number parameter was found, 
       
   244                 csVoiceMenuItemAvailable = EFalse;
       
   245                 csVideoMenuItemAvailable = EFalse;
       
   246                 }
       
   247             }
       
   248         }
       
   249 
       
   250     // Add menu items
       
   251 
       
   252     TInt menuIndex = aIndex;
       
   253 
       
   254     if ( csVoiceMenuItemAvailable )
       
   255          {
       
   256          AddAiwMenuItemL( aMenuPane, menuIndex, ECSVoice );
       
   257          menuIndex++;
       
   258          }
       
   259     
       
   260     if ( csVideoMenuItemAvailable )
       
   261         {
       
   262         AddAiwMenuItemL( aMenuPane, menuIndex, ECSVideo );
       
   263         menuIndex++;
       
   264         }
       
   265     
       
   266     if ( voipMenuItemAvailable )
       
   267         {
       
   268         RIdArray voipServiceIds;
       
   269         CleanupClosePushL( voipServiceIds );
       
   270         iCaUiEngine->GetVoIPServiceIdsL( voipServiceIds );
       
   271         TInt numberOfVoipServices = voipServiceIds.Count();
       
   272         
       
   273         if ( 1 == numberOfVoipServices )
       
   274             {
       
   275             // Single VoIP service, use service name in menu item
       
   276              AddAiwMenuItemL( aMenuPane, menuIndex, EInternetWithName, voipServiceIds[0] );
       
   277              menuIndex++;
       
   278             }
       
   279         else if ( numberOfVoipServices > 1 )
       
   280             {
       
   281             // Regular internet call menu
       
   282             AddAiwMenuItemL( aMenuPane, menuIndex, EInternet );
       
   283             menuIndex++;
       
   284             }    
       
   285 
       
   286         CleanupStack::PopAndDestroy( &voipServiceIds );
       
   287         }
       
   288 
       
   289     // Set submenu title
       
   290     if ( csVoiceMenuItemAvailable ||
       
   291          csVideoMenuItemAvailable || 
       
   292          voipMenuItemAvailable )
       
   293         {
       
   294         HBufC* menuTitle = StringLoader::LoadLC( R_CALLUI_CALL_SUBMENU_TITLE );
       
   295         aMenuPane.AddTitleItemL( *menuTitle, aIndex );
       
   296         CleanupStack::PopAndDestroy( menuTitle );
       
   297         }
       
   298 
       
   299     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::InitializeMenuPaneL() End");
       
   300     }
       
   301 
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // CCaUiPlugin::HandleMenuCmdL
       
   305 // 
       
   306 // 
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CCaUiPlugin::HandleMenuCmdL(
       
   310     TInt aMenuCmdId, 
       
   311     const CAiwGenericParamList& aInParamList,
       
   312     CAiwGenericParamList& aOutParamList,
       
   313     TUint aCmdOptions,
       
   314     const MAiwNotifyCallback* aCallback )
       
   315     {
       
   316     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleMenuCmdL() Begin");
       
   317     // Handle only call commands.
       
   318     if ( ( aMenuCmdId == ECallUIVideo ) || 
       
   319          ( aMenuCmdId == ECallUIVoice ) ||
       
   320          ( aMenuCmdId == ECallUIInternet ) )
       
   321         {
       
   322         // Save the menu command.
       
   323         iMenuCmdId = aMenuCmdId;
       
   324 
       
   325         // Menu commands are handled as service commands.
       
   326         HandleServiceCmdL(
       
   327             KAiwCmdCall,
       
   328             aInParamList,
       
   329             aOutParamList,
       
   330             aCmdOptions,
       
   331             aCallback );
       
   332         }
       
   333     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleMenuCmdL() End");
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CCaUiPlugin::HandleDialResultL
       
   339 // 
       
   340 // 
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 void CCaUiPlugin::HandleDialResultL( const TInt aStatus )
       
   344     {
       
   345     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleDialResultL() Start");
       
   346     // If callback exists, inform client of call result.
       
   347     if ( iAiwNotifyCallback )
       
   348         {
       
   349         // Add the call result to the out parameter list.
       
   350         TAiwVariant variant( aStatus );
       
   351         TAiwGenericParam genericParam( EGenericParamError, variant );
       
   352         iOutParamList->AppendL( genericParam);
       
   353 
       
   354         // R&D solution: Remove constness.
       
   355         MAiwNotifyCallback* callback = 
       
   356             const_cast< MAiwNotifyCallback* >( iAiwNotifyCallback );
       
   357 
       
   358         // Notify client.
       
   359         callback->HandleNotifyL(
       
   360             KAiwCmdCall,
       
   361             KAiwEventStarted,
       
   362             *iOutParamList,
       
   363             *iInParamList );
       
   364         }
       
   365 
       
   366     // Callback not active anymore, make clearing.
       
   367     iAiwNotifyCallback = NULL;
       
   368     iInParamList = NULL;
       
   369     iOutParamList = NULL;
       
   370     CAUILOGSTRING("CALLUI: >>>CCaUiPlugin::HandleDialResultL() End");
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // CCaUiPlugin::AddAiwMenuItemL
       
   375 // 
       
   376 // 
       
   377 // -----------------------------------------------------------------------------
       
   378 //
       
   379 void CCaUiPlugin::AddAiwMenuItemL( CAiwMenuPane& aMenuPane, TInt aIndex, EMenuItemType aType, TServiceId aServiceId )
       
   380     {
       
   381     CEikMenuPaneItem::SData data;
       
   382     data.iCascadeId = 0;
       
   383     data.iFlags = 0;
       
   384     data.iExtraText = KNullDesC();
       
   385 
       
   386     HBufC* menuItemText = NULL;
       
   387     
       
   388     switch ( aType )
       
   389         {
       
   390         case ECSVoice:
       
   391             {
       
   392             data.iCommandId = ECallUIVoice;
       
   393             menuItemText = StringLoader::LoadLC( R_CALLUI_CS_VOICE_CALL );
       
   394             data.iText.Copy( *menuItemText );
       
   395             break;
       
   396             }
       
   397 
       
   398         case ECSVideo:
       
   399             {
       
   400             data.iCommandId = ECallUIVideo;
       
   401             menuItemText = StringLoader::LoadLC( R_CALLUI_CS_VIDEO_CALL );
       
   402             data.iText.Copy( *menuItemText );
       
   403             break;
       
   404             }
       
   405 
       
   406         case EInternet:
       
   407             {
       
   408             data.iCommandId = ECallUIInternet;
       
   409             menuItemText = StringLoader::LoadLC( R_CALLUI_INTERNET_CALL );
       
   410             data.iText.Copy( *menuItemText );
       
   411             break;
       
   412             }
       
   413 
       
   414         case EInternetWithName:
       
   415             {
       
   416             data.iCommandId = ECallUIInternet;
       
   417             
       
   418             // Get the service provider name
       
   419             TBuf<100> buf;
       
   420             iCaUiEngine->GetVoipServiceNameL( aServiceId, buf );
       
   421             menuItemText = StringLoader::LoadLC( R_CALLUI_XSP_CALL_WITH_SERVICE_NAME, buf );
       
   422             data.iText.Copy( *menuItemText );
       
   423             break;
       
   424             }
       
   425 
       
   426         default:
       
   427             break;
       
   428         }
       
   429 
       
   430     if ( NULL != menuItemText )
       
   431         {
       
   432         CleanupStack::PopAndDestroy( menuItemText );
       
   433         }
       
   434     
       
   435     aMenuPane.AddMenuItemL(
       
   436        KAiwCmdCall,
       
   437        data,
       
   438        aIndex );
       
   439     }
       
   440 
       
   441 // End of file