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